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 
21 //Filename    : ONEWS.H
22 //Description : Object News
23 
24 #ifndef __ONEWS_H
25 #define __ONEWS_H
26 
27 #include <stdint.h>
28 
29 #include <OBUTTON.h>
30 #include <ODYNARRB.h>
31 #include <OVBROWSE.h>
32 
33 //----- Maximum no. of news ---------//
34 
35 enum { MAX_NEWS=2000 };
36 
37 //--------- Define constant --------------//
38 
39 #define DISP_NEWS_DAYS	60       // how long a news should stay on the screen before it disappears
40 #define DISP_NEWS_COUNT 5			// maximum no. of news message displayed on the screen at a time
41 
42 //-------- Define news type ---------//
43 
44 enum { NEWS_TYPE_NUM=1 };
45 enum { NEWS_NORMAL=0 };
46 
47 enum { NEWS_WHO_NUM=4 };
48 enum { NEWS_DISP_ALL=0, NEWS_DISP_FRIENDLY, NEWS_DISP_PLAYER, NEWS_DISP_NONE };
49 
50 //------- Define other constant -------//
51 
52 enum { DESTROYER_NATION=1, DESTROYER_REBEL, DESTROYER_MONSTER, DESTROYER_UNKNOWN };
53 
54 enum { NEWS_LOC_TOWN=1, NEWS_LOC_FIRM, NEWS_LOC_UNIT, NEWS_LOC_ANY };		// for News::loc_type
55 
56 //--------- Define news id. ----------//
57 
58 enum { NEWS_DIPLOMACY=1,
59 		 NEWS_TOWN_REBEL,
60 		 NEWS_MIGRATE,
61 		 NEWS_NEW_NATION,
62 		 NEWS_NATION_DESTROYED,
63 		 NEWS_NATION_SURRENDER,
64 		 NEWS_KING_DIE,
65 		 NEWS_NEW_KING,
66 		 NEWS_FIRM_DESTROYED,		// when your firm is destroyed
67 		 NEWS_FIRM_CAPTURED,			// when your firm is taken over by another nation or you take over the firm of another nation
68 		 NEWS_TOWN_DESTROYED,		// when the last unit in the town is killed by an enemy
69 		 NEWS_TOWN_ABANDONED, 		// when all villagers have left the village
70 		 NEWS_TOWN_SURRENDERED,		// A town surrenders to another natino
71 		 NEWS_MONSTER_KING_KILLED,
72 		 NEWS_MONSTER_FIRM_DESTROYED,
73 		 NEWS_SCROLL_ACQUIRED,
74 		 NEWS_MONSTER_GOLD_ACQUIRED,
75 		 NEWS_YOUR_SPY_KILLED,
76 		 NEWS_ENEMY_SPY_KILLED,
77 		 NEWS_UNIT_BETRAY, 			// your unit betray or other nation's betray and turn towards you
78 		 NEWS_UNIT_ASSASSINATED,
79 		 NEWS_ASSASSINATOR_CAUGHT,
80 		 NEWS_GENERAL_DIE,
81 		 NEWS_RAW_EXHAUST,
82 		 NEWS_TECH_RESEARCHED,
83 		 NEWS_LIGHTNING_DAMAGE,
84 		 NEWS_EARTHQUAKE_DAMAGE,
85 		 NEWS_GOAL_DEADLINE,
86 		 NEWS_WEAPON_SHIP_WORN_OUT,
87 		 NEWS_FIRM_WORN_OUT,
88 		 NEWS_CHAT_MSG,
89 		 NEWS_MULTI_RETIRE,
90 		 NEWS_MULTI_QUIT_GAME,
91 		 NEWS_MULTI_SAVE_GAME,
92 		 NEWS_MULTI_CONNECTION_LOST,
93 	  };
94 
95 //------- Define struct News ---------//
96 
97 #pragma pack(1)
98 struct News
99 {
100 public:
101 	char  id;             // id. of the news, NEWS_???
102 
103 	char  type;           // news type   // type may be > NEWS_TYPE_NUM, for indicating that the news has been displayed in the stock window, do display it on the newspaper again
news_typeNews104 	char  news_type()     { return type%NEWS_TYPE_NUM; }
105 
106 	int32_t news_date;    // date of the news
107 
108 	char  nation_color1;     // nation color, can't use nation_recno directly, because it may bankrupt one day
109 	char  nation_color2;
110 	char	nation_race_id1;
111 	char	nation_race_id2;
112 	int   nation_name_id1;   // nation res. id of the nation that generate the news
113 	int   nation_name_id2;   // if the news is related to two nations (e.g. one nation buys the stock of another nation)
114 
115 	char* nation_name1();
116 	char* nation_name2();
117 
118 	char* king_name1(int addColor=0);
119 	char* king_name2(int addColor=0);
120 
121 	char* nation_color_str1();
122 	char* nation_color_str2();
123 
124 	short short_para1;
125 	short short_para2;
126 	short short_para3;
127 	short short_para4;
128 	short short_para5;
129 
130 	char  loc_type;
131 	short loc_type_para;
132 	uint16_t  loc_type_para2;	// must use uint16_t as it will be used to store unit name id.
133 	short loc_x, loc_y;		// location where the news happens
134 
135 public:
136 	int 	put(int y, int detectAction, int& newsHeight);
137 	char* msg();         // return the news msg
138 	int	is_major();
139 
140 	void 	set_loc(int xLoc, int yLoc, int locType, int locTypePara=0, int locTypePara2=0);
141 	int	is_loc_valid();
142 
143 	//---- functions for return news string ----//
144 
145 	void  diplomacy();
146 	void  town_rebel();
147 	void  migrate();
148 	void  new_nation();
149 	void 	nation_destroyed();
150 	void 	nation_surrender();
151 	void  king_die();
152 	void  new_king();
153 	void  firm_destroyed();
154 	void  firm_captured();
155 	void  town_destroyed();
156 	void  town_abandoned();
157 	void	town_surrendered();
158 	void  monster_king_killed();
159 	void  monster_firm_destroyed();
160 	void  scroll_acquired();
161 	void	monster_gold_acquired();
162 	void  your_spy_killed();
163 	void  enemy_spy_killed();
164 	void  unit_betray();
165 	void  unit_assassinated();
166 	void	assassinator_caught();
167 	void  general_die();
168 	void  raw_exhaust();
169 	void  tech_researched();
170 	void  lightning_damage();
171 	void  earthquake_damage();
172 	void	goal_deadline();
173 	void	weapon_ship_worn_out();
174 	void	firm_worn_out();
175 	void	chat_msg();
176 	void  multi_retire();
177 	void  multi_quit_game();
178 	void  multi_save_game();
179 	void  multi_connection_lost();
180 };
181 #pragma pack()
182 
183 //-------- Define class NewsArray ----------//
184 
185 class Unit;
186 class Font;
187 
188 class NewsArray : public DynArray
189 {
190 public:
191 	//------ display options ------//
192 
193 	char  news_type_option[NEWS_TYPE_NUM];
194 	char  news_who_option;
195 	char	news_add_flag;
196 
197 	int	last_clear_recno;
198 
199 public:
200 	NewsArray();
201 
202 	void  init();
203 	void  deinit();
204 
enable()205 	void 	enable()      	{ news_add_flag = 1; }
disable()206 	void	disable()		{ news_add_flag = 0; }
207 
208 	void  reset();
209 	void  default_setting();
210 	void	set_font(Font*);
211 
212 	int	detect();
213 	int view_first_diplomatic();
214 	void	disp();
215 	int   put(int detectAction);
216 
217 	void	clear_news_disp();
218 
219 	News* add_news(int newsId, int newsType, int nationRecno=0, int nationRecno2=0, int forceAdd=0);
220 	void 	remove(int newsId, int shortPara1);
221 
222 	//------ functions for adding news -------//
223 
224 	void	diplomacy(int talkMsgRecno);
225 	void 	town_rebel(int townRecno, int rebelCount);
226 	void	migrate(int srcTownRecno, int desTownRecno, int raceId, int migratedCount, int firmRecno=0);
227 	void 	new_nation(int kingUnitRecno);
228 	void	nation_destroyed(int nationRecno);
229 	void	nation_surrender(int nationRecno, int toNationRecno);
230 	void  king_die(int nationRecno);
231 	void  new_king(int nationRecno, int kingUnitRecno);
232 	void  firm_destroyed(int firmRecno, Unit* attackUnit, short destroyerNationRecno);
233 	void  firm_captured(int firmRecno, int takeoverNationRecno, int spyTakeover);
234 	void  town_destroyed(int townNameId, int xLoc, int yLoc, Unit* attackUnit, short destroyerNationRecno);
235 	void  town_abandoned(int townRecno);
236 	void	town_surrendered(int townRecno, int toNationRecno);
237 	void  monster_king_killed(int monsterId, int xLoc, int yLoc);
238 	void  monster_firm_destroyed(int monsterId, int xLoc, int yLoc);
239 	void 	scroll_acquired(int acquireNationRecno, int scrollRaceId);
240 	void	monster_gold_acquired(int goldAmt);
241 	void  spy_killed(int spyRecno);
242 	void  unit_betray(int unitRecno, int betrayToNationRecno);
243 	void  unit_assassinated(int unitRecno, int spyKilled);
244 	void  assassinator_caught(int spyRecno, int targetRankId);
245 	void  general_die(int unitRecno);
246 	void  raw_exhaust(int rawId, int xLoc, int yLoc);
247 	void  tech_researched(int techId, int techVersion);
248 	void  lightning_damage(int xLoc, int yLoc, int objectId, int recno, int objectDie);
249 	void  earthquake_damage(int unitDamage, int unitDie, int townDamage, int firmDamage, int firmDie);
250 	void	goal_deadline(int yearLeft, int monthLeft);
251 	void 	weapon_ship_worn_out(int unitId, int weaponLevel);
252 	void 	firm_worn_out(int firmRecno);
253 	void 	chat_msg(int nationRecno, char* chatStr);
254 	void  multi_retire(int nationRecno);
255 	void  multi_quit_game(int nationRecno);
256 	void  multi_save_game();
257 	void  multi_connection_lost(int nationRecno);
258 
259 	//--------------------------------------------//
260 
261 	int   write_file(File*);
262 	int   read_file(File*);
263 
264 	News* operator[](int recNo);
265 };
266 
267 extern NewsArray news_array;
268 
269 //-------------------------------------------//
270 
271 #endif
272