File: ONATIONB.h

package info (click to toggle)
7kaa 2.15.6%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 131,312 kB
  • sloc: cpp: 134,790; asm: 3,523; ansic: 1,949; perl: 1,665; makefile: 1,181; sh: 126; pascal: 27
file content (449 lines) | stat: -rw-r--r-- 14,286 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
/*
 * Seven Kingdoms: Ancient Adversaries
 *
 * Copyright 1997,1998 Enlight Software Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

//Filename    : ONATIONB.H
//Description : class NationBase

#ifndef __ONATIONB_H
#define __ONATIONB_H

#ifndef __OINFO_H
#include <OINFO.h>
#endif

#ifndef __ORAWRES_H
#include <ORAWRES.h>
#endif

#ifndef __OTALKMSG_H
#include <OTALKMSG.h>
#endif

//---------- Define constant -----------//

enum { NATION_OWN=1, NATION_REMOTE, NATION_AI };       // NATION_MISC=Government

enum { NATION_HOSTILE=0, NATION_TENSE, NATION_NEUTRAL, NATION_FRIENDLY, NATION_ALLIANCE };

enum { RELATION_LEVEL_PER_STATUS = 20 };		// relation_level = status * NATION_LEVEL_PER_STATUS

//---------- import type ----------//

enum { IMPORT_TYPE_COUNT = 3 };

enum { IMPORT_RAW,
		 IMPORT_PRODUCT,
		 IMPORT_TOTAL
	  };

//--------- income types --------//

enum { INCOME_TYPE_COUNT = 8 };

enum { INCOME_SELL_GOODS,
		 INCOME_EXPORTS,
		 INCOME_TAX,
		 INCOME_TREASURE,
		 INCOME_FOREIGN_WORKER,
		 INCOME_SELL_FIRM,
		 INCOME_TRIBUTE,
		 INCOME_CHEAT,
	  };

//--------- expense types --------//

enum { EXPENSE_TYPE_COUNT = 16 };

enum { EXPENSE_GENERAL,
		 EXPENSE_SPY,
		 EXPENSE_MOBILE_UNIT,
		 EXPENSE_CARAVAN,
		 EXPENSE_WEAPON,
		 EXPENSE_SHIP,
		 EXPENSE_FIRM,
		 EXPENSE_TRAIN_UNIT,
		 EXPENSE_HIRE_UNIT,
		 EXPENSE_REWARD_UNIT,
		 EXPENSE_FOREIGN_WORKER,
		 EXPENSE_GRANT_OWN_TOWN,
		 EXPENSE_GRANT_OTHER_TOWN,
		 EXPENSE_IMPORTS,
		 EXPENSE_TRIBUTE,
		 EXPENSE_BRIBE,
	  };

//----- Define struct NationRelation -------//

#pragma pack(1)
struct NationRelation			// many-to-many relationships between nations
{
	char  has_contact;			// whether this nation has been contacted or not
	char	should_attack;			// whether units should automatically attack units/firms of this nation when the relationship is hostile

	char	trade_treaty;			// whether allow trading with this nation

	char  status;
	const char* status_str();
	const char* duration_of_status_str();

	int	last_change_status_date;
   char* status_duration_str();

	char  ai_relation_level;		// AI's subjectively relation levels towards the others, the opposite nation's relation level is not the same as this
	char	ai_secret_attack;
	char	ai_demand_trade_treaty;

	float good_relation_duration_rating;		// a rating indicate how long does a good relation (friendly/alliance) lasts
	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.

	float cur_year_import[IMPORT_TYPE_COUNT];
	float last_year_import[IMPORT_TYPE_COUNT];
	float lifetime_import[IMPORT_TYPE_COUNT];

	float import_365days(int importType)	{ return last_year_import[importType]*(365-info.year_day)/365 +
															cur_year_import[importType]; }

	int	last_talk_reject_date_array[MAX_TALK_TYPE];	// the date which the last diplomatic request was rejected.
	int	last_military_aid_date;

	int	last_give_gift_date;				// the last date which the current nation give tribute, aid or technology to this nation
	short total_given_gift_amount;		// the total amount of gift the current nation has given to this nation

	char	contact_msg_flag;										// used only in multiplayer

	static const char* relation_status_str_array[5];
	static const char* duration_of_status_str_array[5];
};
#pragma pack()

//---------- Define class Nation -----------//

class Unit;
class Firm;

#pragma pack(1)
class NationBase
{
public:
	enum { NATION_NAME_LEN=50 };

	short	nation_recno;
	char  nation_type;

	char  race_id;
	char  color_scheme_id;
	char	nation_color;				// main color of the nation, based on from color_scheme_id

	short	king_unit_recno;			// recno of the king
	char	king_leadership;

	int 	nation_name_id;			// name of the king/nation
	char  nation_name_str[NATION_NAME_LEN+1];		// for nation_name()'s use
	char* nation_name();
	const char* king_name(int firstWordOnly=0);

	uint32_t player_id;				   // player id for multiplayer game

	char  next_frame_ready;				// for indicating whether the next frame is ready or not
	short last_caravan_id;				// id. of the nation's caravan.

	short	nation_firm_count;			// total no. of firms the nation has built
	int   last_build_firm_date;

	char	know_base_array[MAX_RACE];		// whether the unit knows how to constructure seat of power or not
	char	base_count_array[MAX_RACE];   // no. of seat of power this nation has

	char	is_at_war_today;
	char	is_at_war_yesterday;
	int	last_war_date;
	short last_attacker_unit_recno;
	int	last_independent_unit_join_date;

	int	peaceful_days()			{ return info.game_date - last_war_date; }
	char*	peace_duration_str();

	void	set_at_war_today(int attackerUnitRecno=0)
			{ is_at_war_today=1; if(attackerUnitRecno) last_attacker_unit_recno=attackerUnitRecno; }

	int	is_at_war()					{ return is_at_war_today || is_at_war_yesterday; }

	char  cheat_enabled_flag;

	//----------------------------------//

	float		 cash;
	float		 food;

	char*		 cash_str();
	char*		 food_str();

	int		 yearly_food_consumption() { return PERSON_FOOD_YEAR_CONSUMPTION * all_population(); }
	int		 yearly_food_production() 	{ return PEASANT_FOOD_YEAR_PRODUCTION * total_jobless_population; }
	int       yearly_food_change() 	   { return yearly_food_production() - yearly_food_consumption(); }

	float		 reputation;				// can be negative, means bad reputation
	float		 kill_monster_score;

	//------- town auto policy -------------//

	short		 auto_collect_tax_loyalty;		// auto collect tax if the loyalty reaches this level
	short		 auto_grant_loyalty;				// auto grant if the loyalty drop below this level

	//----- yearly income, expense and profit ------//

	float		 cur_year_profit;
	float		 last_year_profit;
	float		 profit_365days()				{ return last_year_profit*(365-info.year_day)/365 +
													  cur_year_profit; }
	float		 cur_year_fixed_income;
	float		 last_year_fixed_income;
	float		 fixed_income_365days()		{ return last_year_fixed_income*(365-info.year_day)/365 +
													  cur_year_fixed_income; }
	float		 cur_year_fixed_expense;
	float		 last_year_fixed_expense;
	float		 fixed_expense_365days()	{ return last_year_fixed_expense*(365-info.year_day)/365 +
													  cur_year_fixed_expense; }

	float		 fixed_profit_365days()		{ return fixed_income_365days() - fixed_expense_365days(); }

	//------- yearly income ------//

	float		 cur_year_income_array[INCOME_TYPE_COUNT];
	float		 last_year_income_array[INCOME_TYPE_COUNT];

	float		 cur_year_income;		// total income
	float		 last_year_income;

	float		 income_365days()				{ return last_year_income*(365-info.year_day)/365 + cur_year_income; }

	float 	 income_365days(int incomeType)	{ return last_year_income_array[incomeType] * (365-info.year_day) / 365 +
																  cur_year_income_array[incomeType]; }
	float		 true_income_365days();		// total income, excluding cheats

	//------- yearly expense ------//

	float		 cur_year_expense_array[EXPENSE_TYPE_COUNT];
	float		 last_year_expense_array[EXPENSE_TYPE_COUNT];

	float		 cur_year_expense;		// total expense
	float		 last_year_expense;

	float		 expense_365days()				{ return last_year_expense*(365-info.year_day)/365 + cur_year_expense; }

	float 	 expense_365days(int expenseType)	{ return last_year_expense_array[expenseType] * (365-info.year_day) / 365 +
																  cur_year_expense_array[expenseType]; }
	//------- yearly expense ------//

	float		 cur_year_cheat;		// total cheat
	float		 last_year_cheat;

	float 	 cheat_365days()			{ return last_year_cheat*(365-info.year_day)/365 + cur_year_cheat; }

	float		 true_profit_365days() 	{ return profit_365days() - cheat_365days(); }

	//----- yearly food in, out and change ------//

	float		 cur_year_food_in;
	float		 last_year_food_in;

	float		 cur_year_food_out;
	float		 last_year_food_out;

	float		 cur_year_food_change;
	float		 last_year_food_change;
	float		 food_change_365days()		{ return last_year_food_change*(365-info.year_day)/365 +
													  cur_year_food_change; }
	//----- yearly reputatino change ------//

	float     cur_year_reputation_change;
	float     last_year_reputation_change;

	float		 reputation_change_365days() { return last_year_reputation_change*(365-info.year_day)/365 +
														 cur_year_reputation_change; }

	//--------- inter-nation relationship -----------//

	NationRelation relation_array[MAX_NATION];				// inter-relationship with other nations
	char		 relation_status_array[MAX_NATION];				// replace status in struct NationRelation
	char		 relation_passable_array[MAX_NATION]; 			// for seeking to indicate whether passing other nation region
	char		 relation_should_attack_array[MAX_NATION];
	char		 is_allied_with_player;								// for fast access in visiting world functions

	void		 set_relation_status(short nationRecno, char newStatus, char recursiveCall=0);
	char		 get_relation_status(short nationRecno);
	void		 set_relation_passable(short nationRecno, char status);
	char		 get_relation_passable(short nationRecno);
	void		 set_relation_should_attack(short nationRecno, char newValue, char remoteAction);
	char		 get_relation_should_attack(short nationRecno);

	void		 set_trade_treaty(int nationRecno, char allowFlag);
	void		 establish_contact(int nationRecno);
	void		 change_ai_relation_level(short nationRecno, int levelChange);

	#ifdef DEBUG
		NationRelation* get_relation(int nationRecno);
	#else
		NationRelation* get_relation(int nationRecno) { return relation_array+nationRecno-1; }
	#endif

	//--------- total yearly trade amount --------//

	float		 total_year_trade(int nationRecno);
	int 		 trade_rating(int nationRecno);

	//---------- statistic ------------//

	int  		 total_population;
	int		 total_jobless_population;
	int		 all_population()				{ return total_population + total_human_count; }

	int		 total_unit_count;
	int		 total_human_count;
	int		 total_general_count;
	int		 total_weapon_count;
	int		 total_ship_count;
	int		 total_firm_count;
	int		 total_spy_count;
	int		 total_ship_combat_level;

	short		 largest_town_recno;		// the recno of the biggest town of this nation
	short		 largest_town_pop;

	int 		 total_tech_level(int unitClass=0);
	int 		 base_town_count_in_region(int regionId);

	short		 raw_count_array[MAX_RAW];		// no. of natural resources site this nation possesses

	uint16_t     last_unit_name_id_array[MAX_UNIT_TYPE];

	//--------- rank ratings ---------//

	int		 population_rating;
	int		 military_rating;
	int		 economic_rating;
   int		 overall_rating;

	void		 update_nation_rating();

	int		 get_population_rating();
	int		 get_economic_rating();
	int		 get_overall_rating();

	int		 population_rank_rating();
	int		 military_rank_rating();
	int		 economic_rank_rating();
	int		 reputation_rank_rating();
	int		 kill_monster_rank_rating();
	int		 overall_rank_rating();

	//------ additional statistic ------//

	int		 enemy_soldier_killed;
	int		 own_soldier_killed;
	int		 enemy_civilian_killed;
	int		 own_civilian_killed;
	int		 enemy_weapon_destroyed;
	int		 own_weapon_destroyed;
	int		 enemy_ship_destroyed;
	int		 own_ship_destroyed;
	int		 enemy_firm_destroyed;
	int		 own_firm_destroyed;

	//---------- functions -------------//

	int			goal_destroy_nation_achieved();
	int			goal_destroy_monster_achieved();
	int			goal_population_achieved();
	int			goal_economic_score_achieved();
	int			goal_total_score_achieved();

	int			is_own()    	{ return nation_type==NATION_OWN;    }
	int			is_ai()			{ return nation_type==NATION_AI;		 }
	int			is_remote() 	{ return nation_type==NATION_REMOTE; }

public:
	NationBase();
	~NationBase();

	virtual	void init(int nationType, int raceId, int colorSchemeId, uint32_t playerId=0);
   virtual  void deinit();

	void 		init_relation(int relationNationRecno);

	void 		close_all_firm();
	void		deinit_all_unit();
	void 		succeed_king(int kingUnitRecno);
	void 		set_king(int kingUnitRecno, int firstKing);
	void 		hand_over_to(int handoverNationRecno);

	void 		disp_nation_color(int x, int y);

	void 		next_day();
	void 		next_month();
	void 		next_year();

	void		add_income(int incomeType, float incomeAmt, int fixedIncome=0);
	void		add_expense(int expenseType, float expenseAmt, int fixedExpense=0);
	void		add_cheat(float cheatAmt);
	void		change_reputation(float);

	void		add_food(float);
	void		consume_food(float);
	void		import_goods(int importType, int nationRecno, float importAmt);
	void 		give_tribute(int toNationRecno, int tributeAmt);
	void 		give_tech(int toNationRecno, int techId, int techVersion);

	void 		set_auto_collect_tax_loyalty(int loyaltyLevel);
	void 		set_auto_grant_loyalty(int loyaltyLevel);

	int		has_people();		// whether the nation has any people (but not counting the king). If no, then the nation is going to end.

	void		being_attacked(int attackNationRecno);
	void		civilian_killed(int civilianRaceId, int isAttacker, int penaltyType);
	void 		change_all_people_loyalty(float loyaltyChange, int raceId=0);

	void 		form_friendly_treaty(int nationRecno);
	void 		form_alliance_treaty(int nationRecno);
	void 		end_treaty(int endTreatyNationRecno, int newStatus);

	void		surrender(int toNationRecno);
	void		defeated();
	void		check_win();
	void		check_lose();

	int		revealed_by_phoenix(int xLoc, int yLoc);

	//--------- file functions -----------//

	int 		write_file(File* filePtr);
	int		read_file(File* filePtr);

	//-------------- multiplayer checking codes ---------------//
	virtual	uint8_t crc8();
	virtual	void	clear_ptr();
};
#pragma pack()

//--------------------------------------//

//### begin alex 12/8 ###//
extern short nation_hand_over_flag; // 0 for no nation hand over, 1-MAX_NATION for nation hand over
//#### end alex 12/8 ####//
#endif