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    : OSPY.H
22 //Description : class Spy
23 
24 #ifndef __OSPY_H
25 #define __OSPY_H
26 
27 #ifndef __ODYNARRB_H
28 #include <ODYNARRB.h>
29 #endif
30 
31 //------- define constant -------//
32 
33 #define MAX_BRIBE_AMOUNT	 4000
34 
35 #define SPY_ENEMY_RANGE  	 5    	// only allow changing spy cloak if there are no enemy units within 5 locations from the unit
36 
37 #define MIN_VIEW_SECRET_SPYING_SKILL	20		// the minimum spying skill required for viewing secret reports
38 
39 //------- action mode definitions --------//
40 
41 enum { SPY_UNDEFINED,
42 		 SPY_MOBILE,
43 		 SPY_TOWN,
44 		 SPY_FIRM,
45 	  };
46 
47 enum { SPY_IDLE,
48 		 SPY_SOW_DISSENT,
49 		 SPY_SABOTAGE,
50 	  };
51 
52 //---------- Define class Spy ---------//
53 
54 #pragma pack(1)
55 class Spy
56 {
57 public:
58 	short spy_recno;
59 	char  spy_place;   			// either SPY_TOWN or SPY_FIRM
60 	short	spy_place_para;		// it can be town_recno, firm_recno or unit_recno depending on what spy_place is
61 
62 	char  spy_skill;
63 	char  spy_loyalty;			// the spy's loyalty to his true home nation
64 
65 	char  true_nation_recno;
66 	char	cloaked_nation_recno;
67 
68 	char	notify_cloaked_nation_flag;		// whether the spy will send a surrendering message to the cloaked nation when it changes its cloak to the nation
69 	char  exposed_flag;							// this is set to 1 when the spy finished stealing the secret of a nation.
70 
71 	char  race_id;
72 	uint16_t name_id;
73 	char  action_mode;
74 	const char* action_str();
75 
76 	int 	cloaked_rank_id();
77 	int 	cloaked_skill_id();
78 
79 public:
80 	Spy();
81 
82 	void  deinit();
83 
84 	void	next_day();
85 
86 	void	process_town_action();
87 	void	process_firm_action();
88 	void	pay_expense();
89 
90 	int 	think_betray();
91 	void	drop_spy_identity();
92 
93 	void  change_true_nation(int newNationRecno);
94 	void  change_cloaked_nation(int newNationRecno);
95 	int   can_change_cloaked_nation(int newNationRecno);
96 
97 	int	capture_firm();
98 
99 	void	reward(int remoteAction);
100 	void 	set_exposed(int remoteAction);
101 
102 	void 	think_become_king();
103 
104 	int	mobilize_spy();
105 	int 	mobilize_town_spy(int decPop=1);
106 	int 	mobilize_firm_spy();
107 
108 	void	set_action_mode(int actionMode);
109 	void	set_next_action_mode();
110 	void  change_loyalty(int loyaltyChange);
111 	void  update_loyalty();
112 
113 	int 	can_sabotage();
114 
115 	void	set_place(int spyPlace, int spyPlacePara);
116 	int 	spy_place_nation_recno();
117 	int 	get_loc(int& xLoc, int& yLoc);
118 
119 	int 	assassinate(int targetUnitRecno, int remoteAction);
120 	int 	get_assassinate_rating(int targetUnitRecno, int& attackRating, int& defenseRating, int& defenderCount);
121 
122 	void	get_killed(int dispNews=1);
123 
124 	//------- AI functions -------//
125 
126 	int 	ai_spy_being_attacked(int attackerUnitRecno);
127 
128 	// #### patch begin Gilbert 20/1 ######//
129 	uint8_t crc8();
130 	void	clear_ptr();
131 	// #### patch end Gilbert 20/1 ######//
132 };
133 #pragma pack()
134 
135 //-------- Define class SpyArray -------//
136 
137 class SpyArray : public DynArrayB
138 {
139 public:
140 	SpyArray();
141 	~SpyArray();
142 
143 	void		init();
144 	void		deinit();
145 
146 	int 		add_spy(int unitRecno, int spySkill);
147 	int		add_spy();
148 	void 		del_spy(int spyRecno);
149 
150 	void		next_day();
151 
152 	int 		find_town_spy(int townRecno, int raceId, int spySeq);
153 	void		process_sabotage();
154 	void 		mobilize_all_spy(int spyPlace, int spyPlacePara, int nationRecno);
155 
156 	void 		update_firm_spy_count(int firmRecno);
157 	void 		change_cloaked_nation(int spyPlace, int spyPlacePara, int fromNationRecno, int toNationRecno);
158 	void 		set_action_mode(int spyPlace, int spyPlacePara, int actionMode);
159 
160 	int 		catch_spy(int spyPlace, int spyPlacePara);
161 	int 		total_spy_skill_level(int spyPlace, int spyPlacePara, int spyNationRecno, int& spyCount);
162 
163 	void 		disp_view_secret_menu(int spyRecno, int refreshFlag);
164 	int  		detect_view_secret_menu(int spyRecno, int nationRecno);
165 
166 	int 		needed_view_secret_skill(int viewMode);
167 
168 	void 		ai_spy_town_rebel(int townRecno);
169 
170 	//--------- file functions -----------//
171 
172 	int 		write_file(File* filePtr);
173 	int		read_file(File* filePtr);
174 
175 	//--------------------------------------//
176 
177 	#ifdef DYNARRAY_DEBUG_ELEMENT_ACCESS
178 		Spy* operator[](int recNo);
179 	#else
180 		Spy* operator[](int recNo)	  { return (Spy*) get(recNo); }
181 	#endif
182 
is_deleted(int recNo)183 	int     is_deleted(int recNo)   { return ((Spy*)get(recNo))->spy_recno==0; }
184 };
185 
186 
187 extern SpyArray spy_array;
188 
189 class SpyArrayLock
190 {
191 public:
SpyArrayLock()192 	SpyArrayLock() { spy_array.lock_body(); }
~SpyArrayLock()193 	~SpyArrayLock() { spy_array.unlock_body(); }
194 };
195 
196 //----------------------------------------//
197 
198 class SpyProcess
199 {
200 private:
201 	short spy_recno;
202 
203 public:
SpyProcess(short recno)204 	SpyProcess(short recno) { spy_recno = recno; };
205 
206 	//------- AI functions -------//
207 
208 	void	process_ai();
209 	void	think_town_spy();
210 	void	think_firm_spy();
211 	int 	think_mobile_spy();
212 
213 	int 	think_bribe();
214 	int 	think_assassinate();
215 	int	think_reward();
216 
217 	int 	think_mobile_spy_new_action();
218 	int 	add_assign_spy_action(int destXLoc, int destYLoc, int cloakedNationRecno);
219 
220 private:
ptr()221 	Spy *ptr() { return spy_array[spy_recno]; };
222 
223 };
224 
225 //----------------------------------------//
226 
227 #endif
228