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    : OR_SPY.CPP
22 //Description : Spy Report
23 
24 #include <OVGA.h>
25 #include <OFONT.h>
26 #include <OFIRMRES.h>
27 #include <ONATION.h>
28 #include <ORACERES.h>
29 #include <OIMGRES.h>
30 #include <OVBROWIF.h>
31 #include <OSPY.h>
32 #include <OINFO.h>
33 #include "gettext.h"
34 
35 //------------- Define coordinations -----------//
36 
37 enum { SPY_BROWSE_X1 = ZOOM_X1+6,
38 		 SPY_BROWSE_Y1 = ZOOM_Y1+6,
39 		 SPY_BROWSE_X2 = ZOOM_X2-6,
40 		 SPY_BROWSE_Y2 = ZOOM_Y2-6,
41 	  };
42 
43 //----------- Define static variables ----------//
44 
45 static VBrowseIF browse_spy;
46 
47 //----------- Define static functions ----------//
48 
49 static void put_spy_rec(int recNo, int x, int y, int refreshFlag);
50 static int  spy_filter(int recNo=0);
51 static void	disp_total();
52 
53 //--------- Begin of function Info::disp_spy ---------//
54 //
disp_spy(int refreshFlag)55 void Info::disp_spy(int refreshFlag)
56 {
57 	//------- Display the spy report -------//
58 
59 	int x=SPY_BROWSE_X1+9;
60 	int y=SPY_BROWSE_Y1+4;
61 
62 	vga_back.d3_panel_up(SPY_BROWSE_X1, SPY_BROWSE_Y1, SPY_BROWSE_X2, SPY_BROWSE_Y1+20 );
63 
64 #if(defined(FRENCH))
65 	font_san.put( x	 , y, "Spy Name" );
66 	font_san.put( x+155, y, "Cloak" );
67 	font_san.put( x+205, y, "Location" );
68 	font_san.put( x+320, y, "Skill" );
69 	font_san.put( x+384, y, "Loyalty" );
70 	font_san.put( x+448, y, "Action" );
71 #else
72 	// German and US
73 	font_san.put( x	 , y, _("Spy Name") );
74 	font_san.put( x+155, y, _("Cloak") );
75 	font_san.put( x+205, y, _("Location") );
76 	font_san.put( x+330, y, _("Skill") );
77 	font_san.put( x+370, y, _("Loyalty") );
78 	font_san.put( x+435, y, _("Action") );
79 #endif
80 
81 	if( refreshFlag == INFO_REPAINT )
82 	{
83 		browse_spy.init( SPY_BROWSE_X1, SPY_BROWSE_Y1+22, SPY_BROWSE_X2, SPY_BROWSE_Y2-20,
84 								 0, 21, spy_filter(), put_spy_rec, 1 );
85 
86 		browse_spy.open(browse_spy_recno);
87 	}
88 	else
89 	{
90 		browse_spy.paint();
91 		browse_spy.open(browse_spy_recno, spy_filter());
92 	}
93 
94 	//--------- Display total ------------//
95 
96 	disp_total();
97 }
98 //----------- End of function Info::disp_spy -----------//
99 
100 
101 //--------- Begin of function Info::detect_spy ---------//
102 //
detect_spy()103 void Info::detect_spy()
104 {
105 	//------- detect the spy browser -------//
106 
107 	if( browse_spy.detect() )
108 	{
109 		browse_spy_recno = browse_spy.recno();
110 
111 		if( browse_spy.double_click )
112 		{
113 			Spy* spyPtr = spy_array[ spy_filter(browse_spy_recno) ];
114 			int  xLoc, yLoc;
115 
116 			if( spyPtr->get_loc(xLoc, yLoc) )
117 				world.go_loc( xLoc, yLoc, 1 );
118 		}
119 	}
120 }
121 //----------- End of function Info::detect_spy -----------//
122 
123 
124 //-------- Begin of static function disp_total --------//
125 
disp_total()126 static void disp_total()
127 {
128 	int x = SPY_BROWSE_X1+9;
129 	int y = SPY_BROWSE_Y2-16;
130 
131 	vga_back.d3_panel_up(SPY_BROWSE_X1, SPY_BROWSE_Y2-18, SPY_BROWSE_X2, SPY_BROWSE_Y2 );
132 
133 	String str;
134 
135 	snprintf( str, MAX_STR_LEN+1, _( "Total Spies: %s"), misc.format(browse_spy.total_rec()) );
136 
137 	font_san.put( x, y, str );
138 }
139 //----------- End of static function disp_total -----------//
140 
141 
142 //-------- Begin of static function spy_filter --------//
143 //
144 // This function has dual purpose :
145 //
146 // 1. when <int> recNo is not given :
147 //    - return the total no. of firms of this nation
148 //
149 // 2. when <int> recNo is given :
150 //    - return the firm recno in firm_array of the given recno.
151 //
spy_filter(int recNo)152 static int spy_filter(int recNo)
153 {
154 	int  totalSpy = spy_array.size();
155 	int  spyCount=0;
156 	Spy* spyPtr;
157 
158 	for( int spyRecno=1 ; spyRecno<=totalSpy ; spyRecno++ )
159 	{
160 		if( spy_array.is_deleted(spyRecno) )
161 			continue;
162 
163 		spyPtr = spy_array[spyRecno];
164 
165 		if( spyPtr->true_nation_recno==info.viewing_nation_recno )
166 			spyCount++;
167 
168 		if( recNo && spyCount==recNo )
169 			return spyRecno;
170 	}
171 
172 	err_when( recNo );   // the recNo is not found, it is out of range
173 
174 	return spyCount;
175 }
176 //----------- End of static function spy_filter -----------//
177 
178 
179 //-------- Begin of static function put_spy_rec --------//
180 //
put_spy_rec(int recNo,int x,int y,int refreshFlag)181 static void put_spy_rec(int recNo, int x, int y, int refreshFlag)
182 {
183 	int  spyRecno = spy_filter(recNo);
184 	Spy* spyPtr   = spy_array[spyRecno];
185 
186 	x+=3;
187 	y+=5;
188 
189 	//------ display rank/skill icon -------//
190 
191 	int 	 cloakedRankId  = spyPtr->cloaked_rank_id();
192 	int 	 cloakedSkillId = spyPtr->cloaked_skill_id();
193 	String str;
194 
195 	switch( cloakedRankId )
196 	{
197 		case RANK_KING:
198 			str = "U_KING";
199 			break;
200 
201 		case RANK_GENERAL:
202 			str = "U_GENE";
203 			break;
204 
205 		case RANK_SOLDIER:
206 			if( cloakedSkillId )
207 			{
208 				str  = "U_";
209 				str += Skill::skill_code_array[cloakedSkillId-1];
210 			}
211 			else
212 			{
213 				str = "";
214 			}
215 			break;
216 	}
217 
218 	if( str.len() > 0 )
219 		image_icon.put_back(x, y+1, str);
220 
221 	//------ display race icon -------------//
222 
223 	vga_back.put_bitmap( x+13, y-4, race_res[spyPtr->race_id]->icon_bitmap_ptr );
224 
225 	//----------- display name -----------//
226 
227 	font_san.put( x+39, y, race_res[spyPtr->race_id]->get_name(spyPtr->name_id), 0, 185 );
228 
229 	//------- display cloaked nation color ------//
230 
231 	int tx = x+170;
232 
233 	if( spyPtr->cloaked_nation_recno==0 )		// independent nation
234 	{
235 		vga_back.bar( tx, y, tx+12, y+12, V_WHITE );
236 		vga_back.rect( tx, y, tx+12, y+12, 1, VGA_GRAY+8 );
237 	}
238 	else
239 	{
240 		nation_array[spyPtr->cloaked_nation_recno]->disp_nation_color(tx, y+2);
241 	}
242 
243 	//---------- display other info ----------//
244 
245 	switch( spyPtr->spy_place )
246 	{
247 		case SPY_FIRM:
248 			str = _(firm_res[firm_array[spyPtr->spy_place_para]->firm_id]->name);
249 			break;
250 
251 		case SPY_TOWN:
252 			str = town_array[spyPtr->spy_place_para]->town_name();
253 			break;
254 
255 		case SPY_MOBILE:
256 		{
257 			Unit* unitPtr = unit_array[spyPtr->spy_place_para];
258 
259 			switch( unitPtr->unit_mode )
260 			{
261 				case UNIT_MODE_CONSTRUCT:
262 					str = _(firm_res[firm_array[unitPtr->unit_mode_para]->firm_id]->name);
263 					break;
264 
265 				case UNIT_MODE_ON_SHIP:
266 					str = _("On Ship");
267 					break;
268 
269 				default:
270 					str = _("Mobile");
271 			}
272 			break;
273 		}
274 
275 		default:
276 			str = "";
277 	}
278 
279 	font_san.put( x+205, y, str );
280 
281 	font_san.put( x+335, y, spyPtr->spy_skill );
282 	font_san.put( x+385, y, spyPtr->spy_loyalty );
283 	font_san.put( x+435, y, spyPtr->action_str() );
284 }
285 //----------- End of static function put_spy_rec -----------//
286 
287 
288