#ifndef __GLOBALS_H__
#define __GLOBALS_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <pthread.h>

#define INITIAL_TRIBES 25
////  internal DEM dimensions (Don't edit !)
#define HEIGHT 1800
#define WIDTH 3600
#define GLHEIGHT 1200
#define GLWIDTH 1200

// 1 in x chance new life will be new species
#define CHANCE_OF_EVOLUTION 500
//initial values for first tribes 1-255
//count as % of 256 ie: 127 = 50%
#define INTELLIGENCE 16
#define STRENGTH 16
#define SPEED 16
// values with degrees C
#define TEMP_L 14
#define TEMP_H 32

#define REPRODUCTIVE_RATE 1  //no effect
//in years
#define MAX_AGE 36
#define CUR_AGE 0

//count as % of 256 ie: 127 = 50%
#define IMUNITY 245
#define FIGHT_FLIGHT_BALANCE 31
#define INTERSPECIES_VIOLENCE 15
#define MIGRATION_FACTOR 63
#define SOCIAL_FACTOR 245  //essentially reproductive rate for now

//C temperature lapse rates: degrees C of temp change per 1K meters from sea level
#define TEMP_PER_1000M 6.49
//#define TEMP_11K_TO_20K 
//#define TEMP_ABOVE_20K  



//DON"T EDIT BELOW HERE

/*
#define INTERSPECIES_A_RANGE 8192  //lower = more chance of attacking friends
#define INTERSPECIES_M_RANGE 8192   //lower = more chance of mating
#define ENEMY_A_RANGE 4096  		   //lower = more chance of fighting with enemies
#define IMUNITY_RANGE 8192         //lower = more chance to die from desease
#define MIGRATION_RANGE 4096        //lower = more chance to migrate
*/
#define WATER_MIGRATION_RANGE 34 // higher = more chance of water migrating 1-256
#define WATER_MIGRATION_T_MAX 255   //12 = 144KM max range, max "turns" to allow water migration

#define CLIMATE_YEARS 1000  //values depend on 1000 to maintain approximate changes known from history
#define DEM_SCALE 12     //don't change
//1px = 12x 30 arc-second  = 2/5 of 1deg
////
//y: lower/upper 2695 2705
//x: lower/upper 895 905
//
#define INITIAL_TRIBE_X 2200
#define INITIAL_TRIBE_Y (uint32_t)floor(HEIGHT/2)
#define TRIBE_SQ (uint32_t)floor( sqrt(INITIAL_TRIBES) )
//const int w = floor(WIDTH/2 + WIDTH/4);
//const int h = floor(HEIGHT/2);

struct Moves{
	uint32_t x; 
	uint32_t y; 
	uint32_t valid; 
	int rating;
};

struct Species{
	unsigned char alive;
	unsigned char intelligence;
    unsigned char strength;
    unsigned char speed;
    unsigned char imunity; //each time contact with another tribe doesn't kill them this goes up
	unsigned char temp_l;
	unsigned char temp_h;
	//char ideal_temp; //ideal temperature for this tribe  celcius  -128 to 127   26 to 33 ?
	//intelligence must account for tolerance outside this range
	//The coldest natural temperature ever recorded on Earth was -89.2 °C (-128.6 °F)
	//The hottest 57.8 °C (136.0 °F)
	//hottest inhabited place, average daily maximum (over 6yrs) 41.1 °C (106.0 °F).
	//coldest inhabited place, daily average in January -46 °C (-51 °F)
	// human tolerance 35-48 ? 32.3 to 40 degrees C effective temperature-basic
    //unsigned char temp_high;
	//unsigned char temp_low;
    //unsigned char food_type;
    //unsigned char food_amount_req;
    //unsigned char water_amount_req;
    unsigned char reproductive_rate;  //range between ... fixed to 1 for now
    unsigned char fight_flight_balance; //chance to run or fight if contact with hostile tribe  0=fight everytime 255=run everytime
	unsigned char interspecies_violence;
    unsigned char migration_factor; //propensity to migrate  0=don't move ever  255=move every cycle
    unsigned char social_factor; //likelyhood to want to mate/mingle with compatible tribe 0=don't like others 255=likes everybody that is compat
    unsigned char max_age;  //dies at this age if not killed otherwise
	unsigned char cur_age;
	unsigned char water_turns;
	unsigned char water_direction;
    //unsigned char gender;
	//unsigned char fought;
	//unsigned char mated;
};

struct image_attr{
    int16_t **dem; //elevation 
    unsigned char *image; //rgb
};

struct Stats{
	uint32_t disease;
	uint32_t drown;
	uint32_t exposure; //died exposure to elements
	uint32_t old_age;
	uint32_t died_attacking;
	uint32_t died_defending;
	uint32_t new_life;
	uint32_t new_species;
	//uint32_t total_living;
};

struct Stats_T{
	uint64_t disease;
	uint64_t drown;
	uint64_t exposure;
	uint64_t old_age;
	uint64_t died_attacking;
	uint64_t died_defending;
	uint64_t new_life;
	uint64_t new_species;
	uint64_t total_living;
	double total_runtime; //64-bit double == 292471208678 yrs total
	uint32_t year;
	float cur_temp;
	int16_t cur_sealevel;
	char sea_rising;
	char temp_rising;
};

struct Thread_I{
	uint32_t start_h;
	uint32_t end_h;
	//char row_synch;
};

#endif