ONATIONB.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : ONATIONB.H
  21. //Description : class NationBase
  22. #ifndef __ONATIONB_H
  23. #define __ONATIONB_H
  24. #ifndef __OINFO_H
  25. #include <OINFO.h>
  26. #endif
  27. #ifndef __ORAWRES_H
  28. #include <ORAWRES.h>
  29. #endif
  30. #ifndef __OTALKMSG_H
  31. #include <OTALKMSG.h>
  32. #endif
  33. //---------- Define constant -----------//
  34. enum { NATION_OWN=1, NATION_REMOTE, NATION_AI }; // NATION_MISC=Government
  35. enum { NATION_HOSTILE=0, NATION_TENSE, NATION_NEUTRAL, NATION_FRIENDLY, NATION_ALLIANCE };
  36. enum { RELATION_LEVEL_PER_STATUS = 20 }; // relation_level = status * NATION_LEVEL_PER_STATUS
  37. //---------- import type ----------//
  38. enum { IMPORT_TYPE_COUNT = 3 };
  39. enum { IMPORT_RAW,
  40. IMPORT_PRODUCT,
  41. IMPORT_TOTAL
  42. };
  43. //--------- income types --------//
  44. enum { INCOME_TYPE_COUNT = 8 };
  45. enum { INCOME_SELL_GOODS,
  46. INCOME_EXPORTS,
  47. INCOME_TAX,
  48. INCOME_TREASURE,
  49. INCOME_FOREIGN_WORKER,
  50. INCOME_SELL_FIRM,
  51. INCOME_TRIBUTE,
  52. INCOME_CHEAT,
  53. };
  54. //--------- expense types --------//
  55. enum { EXPENSE_TYPE_COUNT = 16 };
  56. enum { EXPENSE_GENERAL,
  57. EXPENSE_SPY,
  58. EXPENSE_MOBILE_UNIT,
  59. EXPENSE_CARAVAN,
  60. EXPENSE_WEAPON,
  61. EXPENSE_SHIP,
  62. EXPENSE_FIRM,
  63. EXPENSE_TRAIN_UNIT,
  64. EXPENSE_HIRE_UNIT,
  65. EXPENSE_REWARD_UNIT,
  66. EXPENSE_FOREIGN_WORKER,
  67. EXPENSE_GRANT_OWN_TOWN,
  68. EXPENSE_GRANT_OTHER_TOWN,
  69. EXPENSE_IMPORTS,
  70. EXPENSE_TRIBUTE,
  71. EXPENSE_BRIBE,
  72. };
  73. //----- Define struct NationRelation -------//
  74. #pragma pack(1)
  75. struct NationRelation // many-to-many relationships between nations
  76. {
  77. char has_contact; // whether this nation has been contacted or not
  78. char should_attack; // whether units should automatically attack units/firms of this nation when the relationship is hostile
  79. char trade_treaty; // whether allow trading with this nation
  80. char status;
  81. char* status_str() { return relation_status_str_array[status]; }
  82. int last_change_status_date;
  83. char* status_duration_str();
  84. char ai_relation_level; // AI's subjectively relation levels towards the others, the opposite nation's relation level is not the same as this
  85. char ai_secret_attack;
  86. char ai_demand_trade_treaty;
  87. float good_relation_duration_rating; // a rating indicate how long does a good relation (friendly/alliance) lasts
  88. short started_war_on_us_count; // how many times this nation has started a war with us, the more the times the worse this nation is.
  89. float cur_year_import[IMPORT_TYPE_COUNT];
  90. float last_year_import[IMPORT_TYPE_COUNT];
  91. float lifetime_import[IMPORT_TYPE_COUNT];
  92. float import_365days(int importType) { return last_year_import[importType]*(365-info.year_day)/365 +
  93. cur_year_import[importType]; }
  94. int last_talk_reject_date_array[MAX_TALK_TYPE]; // the date which the last diplomatic request was rejected.
  95. int last_military_aid_date;
  96. int last_give_gift_date; // the last date which the current nation give tribute, aid or technology to this nation
  97. short total_given_gift_amount; // the total amount of gift the current nation has given to this nation
  98. char contact_msg_flag; // used only in multiplayer
  99. static char* relation_status_str_array[5];
  100. };
  101. #pragma pack()
  102. //---------- Define class Nation -----------//
  103. class Unit;
  104. class Firm;
  105. #pragma pack(1)
  106. class NationBase
  107. {
  108. public:
  109. enum { NATION_NAME_LEN=50 };
  110. short nation_recno;
  111. char nation_type;
  112. char race_id;
  113. char color_scheme_id;
  114. char nation_color; // main color of the nation, based on from color_scheme_id
  115. short king_unit_recno; // recno of the king
  116. char king_leadership;
  117. int nation_name_id; // name of the king/nation
  118. char nation_name_str[NATION_NAME_LEN+1]; // for nation_name()'s use
  119. char* nation_name();
  120. char* king_name(int firstWordOnly=0);
  121. DWORD player_id; // player id for multiplayer game
  122. char next_frame_ready; // for indicating whether the next frame is ready or not
  123. short last_caravan_id; // id. of the nation's caravan.
  124. short nation_firm_count; // total no. of firms the nation has built
  125. int last_build_firm_date;
  126. char know_base_array[MAX_RACE]; // whether the unit knows how to constructure seat of power or not
  127. char base_count_array[MAX_RACE]; // no. of seat of power this nation has
  128. char is_at_war_today;
  129. char is_at_war_yesterday;
  130. int last_war_date;
  131. short last_attacker_unit_recno;
  132. int last_independent_unit_join_date;
  133. int peaceful_days() { return info.game_date - last_war_date; }
  134. char* peace_duration_str();
  135. void set_at_war_today(int attackerUnitRecno=0)
  136. { is_at_war_today=1; if(attackerUnitRecno) last_attacker_unit_recno=attackerUnitRecno; }
  137. int is_at_war() { return is_at_war_today || is_at_war_yesterday; }
  138. char cheat_enabled_flag;
  139. //----------------------------------//
  140. float cash;
  141. float food;
  142. char* cash_str();
  143. char* food_str();
  144. int yearly_food_consumption() { return PERSON_FOOD_YEAR_CONSUMPTION * all_population(); }
  145. int yearly_food_production() { return PEASANT_FOOD_YEAR_PRODUCTION * total_jobless_population; }
  146. int yearly_food_change() { return yearly_food_production() - yearly_food_consumption(); }
  147. float reputation; // can be negative, means bad reputation
  148. float kill_monster_score;
  149. //------- town auto policy -------------//
  150. short auto_collect_tax_loyalty; // auto collect tax if the loyalty reaches this level
  151. short auto_grant_loyalty; // auto grant if the loyalty drop below this level
  152. //----- yearly income, expense and profit ------//
  153. float cur_year_profit;
  154. float last_year_profit;
  155. float profit_365days() { return last_year_profit*(365-info.year_day)/365 +
  156. cur_year_profit; }
  157. float cur_year_fixed_income;
  158. float last_year_fixed_income;
  159. float fixed_income_365days() { return last_year_fixed_income*(365-info.year_day)/365 +
  160. cur_year_fixed_income; }
  161. float cur_year_fixed_expense;
  162. float last_year_fixed_expense;
  163. float fixed_expense_365days() { return last_year_fixed_expense*(365-info.year_day)/365 +
  164. cur_year_fixed_expense; }
  165. float fixed_profit_365days() { return fixed_income_365days() - fixed_expense_365days(); }
  166. //------- yearly income ------//
  167. float cur_year_income_array[INCOME_TYPE_COUNT];
  168. float last_year_income_array[INCOME_TYPE_COUNT];
  169. float cur_year_income; // total income
  170. float last_year_income;
  171. float income_365days() { return last_year_income*(365-info.year_day)/365 + cur_year_income; }
  172. float income_365days(int incomeType) { return last_year_income_array[incomeType] * (365-info.year_day) / 365 +
  173. cur_year_income_array[incomeType]; }
  174. float true_income_365days(); // total income, excluding cheats
  175. //------- yearly expense ------//
  176. float cur_year_expense_array[EXPENSE_TYPE_COUNT];
  177. float last_year_expense_array[EXPENSE_TYPE_COUNT];
  178. float cur_year_expense; // total expense
  179. float last_year_expense;
  180. float expense_365days() { return last_year_expense*(365-info.year_day)/365 + cur_year_expense; }
  181. float expense_365days(int expenseType) { return last_year_expense_array[expenseType] * (365-info.year_day) / 365 +
  182. cur_year_expense_array[expenseType]; }
  183. //------- yearly expense ------//
  184. float cur_year_cheat; // total cheat
  185. float last_year_cheat;
  186. float cheat_365days() { return last_year_cheat*(365-info.year_day)/365 + cur_year_cheat; }
  187. float true_profit_365days() { return profit_365days() - cheat_365days(); }
  188. //----- yearly food in, out and change ------//
  189. float cur_year_food_in;
  190. float last_year_food_in;
  191. float cur_year_food_out;
  192. float last_year_food_out;
  193. float cur_year_food_change;
  194. float last_year_food_change;
  195. float food_change_365days() { return last_year_food_change*(365-info.year_day)/365 +
  196. cur_year_food_change; }
  197. //----- yearly reputatino change ------//
  198. float cur_year_reputation_change;
  199. float last_year_reputation_change;
  200. float reputation_change_365days() { return last_year_reputation_change*(365-info.year_day)/365 +
  201. cur_year_reputation_change; }
  202. //--------- inter-nation relationship -----------//
  203. NationRelation relation_array[MAX_NATION]; // inter-relationship with other nations
  204. char relation_status_array[MAX_NATION]; // replace status in struct NationRelation
  205. char relation_passable_array[MAX_NATION]; // for seeking to indicate whether passing other nation region
  206. char relation_should_attack_array[MAX_NATION];
  207. char is_allied_with_player; // for fast access in visiting world functions
  208. void set_relation_status(short nationRecno, char newStatus, char recursiveCall=0);
  209. char get_relation_status(short nationRecno);
  210. void set_relation_passable(short nationRecno, char status);
  211. char get_relation_passable(short nationRecno);
  212. void set_relation_should_attack(short nationRecno, char newValue, char remoteAction);
  213. char get_relation_should_attack(short nationRecno);
  214. void set_trade_treaty(int nationRecno, char allowFlag);
  215. void establish_contact(int nationRecno);
  216. void change_ai_relation_level(short nationRecno, int levelChange);
  217. #ifdef DEBUG
  218. NationRelation* get_relation(int nationRecno);
  219. #else
  220. NationRelation* get_relation(int nationRecno) { return relation_array+nationRecno-1; }
  221. #endif
  222. //--------- total yearly trade amount --------//
  223. float total_year_trade(int nationRecno);
  224. int trade_rating(int nationRecno);
  225. //---------- statistic ------------//
  226. int total_population;
  227. int total_jobless_population;
  228. int all_population() { return total_population + total_human_count; }
  229. int total_unit_count;
  230. int total_human_count;
  231. int total_general_count;
  232. int total_weapon_count;
  233. int total_ship_count;
  234. int total_firm_count;
  235. int total_spy_count;
  236. int total_ship_combat_level;
  237. short largest_town_recno; // the recno of the biggest town of this nation
  238. short largest_town_pop;
  239. int total_tech_level(int unitClass=0);
  240. int base_town_count_in_region(int regionId);
  241. short raw_count_array[MAX_RAW]; // no. of natural resources site this nation possesses
  242. short last_unit_name_id_array[MAX_UNIT_TYPE];
  243. //--------- rank ratings ---------//
  244. int population_rating;
  245. int military_rating;
  246. int economic_rating;
  247. int overall_rating;
  248. void update_nation_rating();
  249. int get_population_rating();
  250. int get_economic_rating();
  251. int get_overall_rating();
  252. int population_rank_rating();
  253. int military_rank_rating();
  254. int economic_rank_rating();
  255. int reputation_rank_rating();
  256. int kill_monster_rank_rating();
  257. int overall_rank_rating();
  258. //------ additional statistic ------//
  259. int enemy_soldier_killed;
  260. int own_soldier_killed;
  261. int enemy_civilian_killed;
  262. int own_civilian_killed;
  263. int enemy_weapon_destroyed;
  264. int own_weapon_destroyed;
  265. int enemy_ship_destroyed;
  266. int own_ship_destroyed;
  267. int enemy_firm_destroyed;
  268. int own_firm_destroyed;
  269. //---------- functions -------------//
  270. int goal_destroy_nation_achieved();
  271. int goal_destroy_monster_achieved();
  272. int goal_population_achieved();
  273. int goal_economic_score_achieved();
  274. int goal_total_score_achieved();
  275. int is_own() { return nation_type==NATION_OWN; }
  276. int is_ai() { return nation_type==NATION_AI; }
  277. int is_remote() { return nation_type==NATION_REMOTE; }
  278. public:
  279. NationBase();
  280. ~NationBase();
  281. virtual void init(int nationType, int raceId, int colorSchemeId, DWORD playerId=0);
  282. virtual void deinit();
  283. void init_relation(int relationNationRecno);
  284. void close_all_firm();
  285. void deinit_all_unit();
  286. void succeed_king(int kingUnitRecno);
  287. void set_king(int kingUnitRecno, int firstKing);
  288. void hand_over_to(int handoverNationRecno);
  289. void disp_nation_color(int x, int y);
  290. void next_day();
  291. void next_month();
  292. void next_year();
  293. void add_income(int incomeType, float incomeAmt, int fixedIncome=0);
  294. void add_expense(int expenseType, float expenseAmt, int fixedExpense=0);
  295. void add_cheat(float cheatAmt);
  296. void change_reputation(float);
  297. void add_food(float);
  298. void consume_food(float);
  299. void import_goods(int importType, int nationRecno, float importAmt);
  300. void give_tribute(int toNationRecno, int tributeAmt);
  301. void give_tech(int toNationRecno, int techId, int techVersion);
  302. void set_auto_collect_tax_loyalty(int loyaltyLevel);
  303. void set_auto_grant_loyalty(int loyaltyLevel);
  304. int has_people(); // whether the nation has any people (but not counting the king). If no, then the nation is going to end.
  305. void being_attacked(int attackNationRecno);
  306. void civilian_killed(int civilianRaceId, int isAttacker);
  307. void change_all_people_loyalty(int loyaltyChange, int raceId=0);
  308. void form_friendly_treaty(int nationRecno);
  309. void form_alliance_treaty(int nationRecno);
  310. void end_treaty(int endTreatyNationRecno, int newStatus);
  311. void surrender(int toNationRecno);
  312. void defeated();
  313. void check_win();
  314. void check_lose();
  315. int revealed_by_phoenix(int xLoc, int yLoc);
  316. //--------- file functions -----------//
  317. int write_file(File* filePtr);
  318. int read_file(File* filePtr);
  319. //-------------- multiplayer checking codes ---------------//
  320. virtual UCHAR crc8();
  321. virtual void clear_ptr();
  322. };
  323. #pragma pack()
  324. //--------------------------------------//
  325. //### begin alex 12/8 ###//
  326. extern short nation_hand_over_flag; // 0 for no nation hand over, 1-MAX_NATION for nation hand over
  327. //#### end alex 12/8 ####//
  328. #endif