diff options
author | Franklin Wei <frankhwei536@gmail.com> | 2014-08-26 20:11:53 -0400 |
---|---|---|
committer | Michael Giacomelli <giac2000@hotmail.com> | 2014-09-14 03:48:44 +0200 |
commit | a231754af930a36f9b4452ab52ce0e3d702b40dd (patch) | |
tree | c297860463eb5548240a4027edf5acffd2ed49b5 /apps | |
parent | e47ed2a534d78e98711ff3b0296959df6ffd3bb9 (diff) | |
download | rockbox-a231754af930a36f9b4452ab52ce0e3d702b40dd.tar.gz rockbox-a231754af930a36f9b4452ab52ce0e3d702b40dd.zip |
Superdom: code cleanup
Change-Id: I3285238cfc098546307862f7d2e51e3b8e456a98
Reviewed-on: http://gerrit.rockbox.org/931
Reviewed-by: Michael Giacomelli <giac2000@hotmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/superdom.c | 1169 |
1 files changed, 644 insertions, 525 deletions
diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index b9c18abec4..91747edb80 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c | |||
@@ -18,9 +18,17 @@ | |||
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | /* TODO list: | ||
22 | - don't hardcode board size | ||
23 | - improve AI (move, use nukes, etc.) | ||
24 | - allow for configurable AI | ||
25 | */ | ||
26 | |||
27 | |||
21 | #include "plugin.h" | 28 | #include "plugin.h" |
22 | #include "lib/playback_control.h" | ||
23 | #include "lib/display_text.h" | 29 | #include "lib/display_text.h" |
30 | #include "lib/playback_control.h" | ||
31 | #include "lib/pluginlib_actions.h" | ||
24 | #include "pluginbitmaps/superdom_boarditems.h" | 32 | #include "pluginbitmaps/superdom_boarditems.h" |
25 | 33 | ||
26 | char buf[255]; | 34 | char buf[255]; |
@@ -64,195 +72,37 @@ char buf[255]; | |||
64 | #define ICON_HEIGHT (BMPHEIGHT_superdom_boarditems/6) | 72 | #define ICON_HEIGHT (BMPHEIGHT_superdom_boarditems/6) |
65 | #define ICON_WIDTH (BMPWIDTH_superdom_boarditems/2) | 73 | #define ICON_WIDTH (BMPWIDTH_superdom_boarditems/2) |
66 | 74 | ||
67 | #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ | 75 | #define SUPERDOM_OK PLA_SELECT |
68 | (CONFIG_KEYPAD == IPOD_1G2G_PAD) | 76 | #define SUPERDOM_CANCEL PLA_CANCEL |
69 | #define SUPERDOM_OK BUTTON_SELECT | 77 | #define SUPERDOM_RIGHT PLA_RIGHT |
70 | #define SUPERDOM_CANCEL BUTTON_MENU | 78 | #define SUPERDOM_LEFT PLA_LEFT |
71 | #define SUPERDOM_LEFT BUTTON_LEFT | 79 | #define SUPERDOM_UP PLA_UP |
72 | #define SUPERDOM_RIGHT BUTTON_RIGHT | 80 | #define SUPERDOM_DOWN PLA_DOWN |
73 | #define IPOD_STYLE | 81 | |
74 | 82 | #define SUPERDOM_RIGHT_REPEAT PLA_RIGHT_REPEAT | |
75 | #elif CONFIG_KEYPAD == IRIVER_H300_PAD || CONFIG_KEYPAD == IRIVER_H100_PAD | 83 | #define SUPERDOM_LEFT_REPEAT PLA_LEFT_REPEAT |
76 | #define SUPERDOM_OK BUTTON_SELECT | 84 | #define SUPERDOM_UP_REPEAT PLA_UP_REPEAT |
77 | #define SUPERDOM_LEFT BUTTON_LEFT | 85 | #define SUPERDOM_DOWN_REPEAT PLA_DOWN_REPEAT |
78 | #define SUPERDOM_RIGHT BUTTON_RIGHT | 86 | |
79 | #define SUPERDOM_UP BUTTON_UP | 87 | /* Some defines for the prices */ |
80 | #define SUPERDOM_DOWN BUTTON_DOWN | 88 | #define PRICE_MEN 1 |
81 | #define SUPERDOM_CANCEL BUTTON_OFF | 89 | #define PRICE_MOVE 100 |
82 | 90 | #define PRICE_TANK 300 | |
83 | #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD | 91 | #define PRICE_PLANE 600 |
84 | #define SUPERDOM_OK BUTTON_SELECT | 92 | #define PRICE_FARM 1150 |
85 | #define SUPERDOM_LEFT BUTTON_LEFT | 93 | #define PRICE_FACTORY 1300 |
86 | #define SUPERDOM_RIGHT BUTTON_RIGHT | 94 | #define PRICE_NUKE 2000 |
87 | #define SUPERDOM_UP BUTTON_UP | 95 | |
88 | #define SUPERDOM_DOWN BUTTON_DOWN | 96 | #define STRINGIZE_2(X) #X |
89 | #define SUPERDOM_CANCEL BUTTON_REC | 97 | #define STRINGIZE(X) STRINGIZE_2(X) |
90 | 98 | ||
91 | #elif CONFIG_KEYPAD == IRIVER_H10_PAD | 99 | #define PRICE_MEN_STR STRINGIZE(PRICE_MEN) |
92 | #define SUPERDOM_OK BUTTON_RIGHT | 100 | #define PRICE_MOVE_STR STRINGIZE(PRICE_MOVE) |
93 | #define SUPERDOM_UP BUTTON_SCROLL_UP | 101 | #define PRICE_TANK_STR STRINGIZE(PRICE_TANK) |
94 | #define SUPERDOM_DOWN BUTTON_SCROLL_DOWN | 102 | #define PRICE_PLANE_STR STRINGIZE(PRICE_PLANE) |
95 | #define SUPERDOM_CANCEL BUTTON_LEFT | 103 | #define PRICE_FARM_STR STRINGIZE(PRICE_FARM) |
96 | 104 | #define PRICE_FACTORY_STR STRINGIZE(PRICE_FACTORY) | |
97 | #elif CONFIG_KEYPAD == GIGABEAT_PAD | 105 | #define PRICE_NUKE_STR STRINGIZE(PRICE_NUKE) |
98 | #define SUPERDOM_OK BUTTON_SELECT | ||
99 | #define SUPERDOM_UP BUTTON_UP | ||
100 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
101 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
102 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
103 | #define SUPERDOM_CANCEL BUTTON_POWER | ||
104 | |||
105 | #elif CONFIG_KEYPAD == SANSA_E200_PAD | ||
106 | #define SUPERDOM_OK BUTTON_SELECT | ||
107 | #define SUPERDOM_UP BUTTON_SCROLL_BACK | ||
108 | #define SUPERDOM_DOWN BUTTON_SCROLL_FWD | ||
109 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
110 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
111 | #define SUPERDOM_CANCEL BUTTON_POWER | ||
112 | |||
113 | #elif CONFIG_KEYPAD == SANSA_FUZE_PAD | ||
114 | #define SUPERDOM_OK BUTTON_SELECT | ||
115 | #define SUPERDOM_UP BUTTON_SCROLL_BACK | ||
116 | #define SUPERDOM_DOWN BUTTON_SCROLL_FWD | ||
117 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
118 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
119 | #define SUPERDOM_CANCEL (BUTTON_HOME|BUTTON_REPEAT) | ||
120 | |||
121 | #elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \ | ||
122 | CONFIG_KEYPAD == SAMSUNG_YPR0_PAD | ||
123 | #define SUPERDOM_OK BUTTON_SELECT | ||
124 | #define SUPERDOM_UP BUTTON_UP | ||
125 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
126 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
127 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
128 | #define SUPERDOM_CANCEL BUTTON_BACK | ||
129 | |||
130 | #elif CONFIG_KEYPAD == COWON_D2_PAD | ||
131 | #define SUPERDOM_CANCEL BUTTON_POWER | ||
132 | |||
133 | #elif CONFIG_KEYPAD == CREATIVEZVM_PAD | ||
134 | #define SUPERDOM_OK BUTTON_SELECT | ||
135 | #define SUPERDOM_UP BUTTON_UP | ||
136 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
137 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
138 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
139 | #define SUPERDOM_CANCEL BUTTON_BACK | ||
140 | |||
141 | #elif CONFIG_KEYPAD == CREATIVE_ZENXFI3_PAD | ||
142 | #define SUPERDOM_OK (BUTTON_PLAY|BUTTON_REL) | ||
143 | #define SUPERDOM_UP BUTTON_UP | ||
144 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
145 | #define SUPERDOM_LEFT BUTTON_BACK | ||
146 | #define SUPERDOM_RIGHT BUTTON_MENU | ||
147 | #define SUPERDOM_CANCEL (BUTTON_PLAY|BUTTON_REPEAT) | ||
148 | |||
149 | #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD | ||
150 | #define SUPERDOM_OK BUTTON_PLAY | ||
151 | #define SUPERDOM_UP BUTTON_UP | ||
152 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
153 | #define SUPERDOM_LEFT BUTTON_PREV | ||
154 | #define SUPERDOM_RIGHT BUTTON_NEXT | ||
155 | #define SUPERDOM_CANCEL BUTTON_LEFT | ||
156 | |||
157 | #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD | ||
158 | #define SUPERDOM_OK BUTTON_PLAY | ||
159 | #define SUPERDOM_UP BUTTON_UP | ||
160 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
161 | #define SUPERDOM_LEFT BUTTON_PREV | ||
162 | #define SUPERDOM_RIGHT BUTTON_NEXT | ||
163 | #define SUPERDOM_CANCEL BUTTON_LEFT | ||
164 | |||
165 | #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || (CONFIG_KEYPAD == MROBE500_PAD) | ||
166 | #define SUPERDOM_CANCEL BUTTON_POWER | ||
167 | |||
168 | #elif (CONFIG_KEYPAD == SAMSUNG_YH820_PAD) || \ | ||
169 | (CONFIG_KEYPAD == SAMSUNG_YH920_PAD) | ||
170 | #define SUPERDOM_OK BUTTON_PLAY | ||
171 | #define SUPERDOM_UP BUTTON_UP | ||
172 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
173 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
174 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
175 | #define SUPERDOM_CANCEL BUTTON_REW | ||
176 | |||
177 | #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD | ||
178 | #define SUPERDOM_OK BUTTON_OK | ||
179 | #define SUPERDOM_UP BUTTON_UP | ||
180 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
181 | #define SUPERDOM_LEFT BUTTON_PREV | ||
182 | #define SUPERDOM_RIGHT BUTTON_NEXT | ||
183 | #define SUPERDOM_CANCEL BUTTON_CANCEL | ||
184 | |||
185 | #elif CONFIG_KEYPAD == MPIO_HD300_PAD | ||
186 | #define SUPERDOM_OK BUTTON_ENTER | ||
187 | #define SUPERDOM_UP BUTTON_UP | ||
188 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
189 | #define SUPERDOM_LEFT BUTTON_REW | ||
190 | #define SUPERDOM_RIGHT BUTTON_FF | ||
191 | #define SUPERDOM_CANCEL BUTTON_MENU | ||
192 | |||
193 | #elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD | ||
194 | #define SUPERDOM_OK BUTTON_SELECT | ||
195 | #define SUPERDOM_UP BUTTON_UP | ||
196 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
197 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
198 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
199 | #define SUPERDOM_CANCEL BUTTON_BACK | ||
200 | |||
201 | #elif CONFIG_KEYPAD == SONY_NWZ_PAD | ||
202 | #define SUPERDOM_OK BUTTON_PLAY | ||
203 | #define SUPERDOM_UP BUTTON_UP | ||
204 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
205 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
206 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
207 | #define SUPERDOM_CANCEL BUTTON_BACK | ||
208 | |||
209 | #elif CONFIG_KEYPAD == CREATIVE_ZEN_PAD | ||
210 | #define SUPERDOM_OK BUTTON_SELECT | ||
211 | #define SUPERDOM_UP BUTTON_UP | ||
212 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
213 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
214 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
215 | #define SUPERDOM_CANCEL BUTTON_BACK | ||
216 | |||
217 | #elif CONFIG_KEYPAD == SANSA_CONNECT_PAD | ||
218 | #define SUPERDOM_OK BUTTON_SELECT | ||
219 | #define SUPERDOM_UP BUTTON_UP | ||
220 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
221 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
222 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
223 | #define SUPERDOM_CANCEL BUTTON_POWER | ||
224 | |||
225 | #elif (CONFIG_KEYPAD == HM60X_PAD) || \ | ||
226 | (CONFIG_KEYPAD == HM801_PAD) | ||
227 | #define SUPERDOM_OK BUTTON_SELECT | ||
228 | #define SUPERDOM_UP BUTTON_UP | ||
229 | #define SUPERDOM_DOWN BUTTON_DOWN | ||
230 | #define SUPERDOM_LEFT BUTTON_LEFT | ||
231 | #define SUPERDOM_RIGHT BUTTON_RIGHT | ||
232 | #define SUPERDOM_CANCEL BUTTON_POWER | ||
233 | |||
234 | #endif | ||
235 | |||
236 | #ifdef HAVE_TOUCHSCREEN | ||
237 | #ifndef SUPERDOM_OK | ||
238 | #define SUPERDOM_OK BUTTON_CENTER | ||
239 | #endif | ||
240 | #ifndef SUPERDOM_UP | ||
241 | #define SUPERDOM_UP BUTTON_TOPMIDDLE | ||
242 | #endif | ||
243 | #ifndef SUPERDOM_LEFT | ||
244 | #define SUPERDOM_LEFT BUTTON_MIDLEFT | ||
245 | #endif | ||
246 | #ifndef SUPERDOM_RIGHT | ||
247 | #define SUPERDOM_RIGHT BUTTON_MIDRIGHT | ||
248 | #endif | ||
249 | #ifndef SUPERDOM_DOWN | ||
250 | #define SUPERDOM_DOWN BUTTON_BOTTOMMIDDLE | ||
251 | #endif | ||
252 | #ifndef SUPERDOM_CANCEL | ||
253 | #define SUPERDOM_CANCEL BUTTON_TOPLEFT | ||
254 | #endif | ||
255 | #endif | ||
256 | 106 | ||
257 | enum { | 107 | enum { |
258 | RET_VAL_OK, | 108 | RET_VAL_OK, |
@@ -268,7 +118,7 @@ static void gen_resources(void); | |||
268 | static void draw_cursor(void); | 118 | static void draw_cursor(void); |
269 | static void draw_board(void); | 119 | static void draw_board(void); |
270 | 120 | ||
271 | struct tile{ | 121 | struct tile { |
272 | signed int colour; /* -1 = Unset */ | 122 | signed int colour; /* -1 = Unset */ |
273 | bool tank; | 123 | bool tank; |
274 | bool plane; | 124 | bool plane; |
@@ -306,18 +156,23 @@ static struct resources compres; | |||
306 | enum { GS_PROD, GS_MOVE, GS_WAR }; | 156 | enum { GS_PROD, GS_MOVE, GS_WAR }; |
307 | static int gamestate; | 157 | static int gamestate; |
308 | 158 | ||
309 | static struct cursor{ | 159 | static struct cursor { |
310 | int x; | 160 | int x; |
311 | int y; | 161 | int y; |
312 | } cursor; | 162 | } cursor; |
313 | 163 | ||
314 | static struct tile board[12][12]; | 164 | static struct tile board[12][12]; |
315 | 165 | ||
316 | static void init_board(void) { | 166 | static const struct button_mapping *plugin_contexts[] = { pla_main_ctx }; |
167 | |||
168 | static void init_board(void) | ||
169 | { | ||
317 | int i,j; | 170 | int i,j; |
318 | rb->srand(*rb->current_tick); | 171 | rb->srand(*rb->current_tick); |
319 | for(i=0;i<12;i++) { /* Hopefully about 50% each colour */ | 172 | for(i=0;i<12;i++) |
320 | for(j=0;j<12;j++) { | 173 | { /* Hopefully about 50% each colour */ |
174 | for(j=0;j<12;j++) | ||
175 | { | ||
321 | if((i<1)||(j<1)||(i>10)||(j>10)) | 176 | if((i<1)||(j<1)||(i>10)||(j>10)) |
322 | board[i][j].colour = -1; /* Unset */ | 177 | board[i][j].colour = -1; /* Unset */ |
323 | else | 178 | else |
@@ -331,48 +186,62 @@ static void init_board(void) { | |||
331 | } | 186 | } |
332 | } | 187 | } |
333 | 188 | ||
334 | while(compres.farms < superdom_settings.compstartfarms) { | 189 | while(compres.farms < superdom_settings.compstartfarms) |
190 | { | ||
335 | i = rb->rand()%10 + 1; | 191 | i = rb->rand()%10 + 1; |
336 | j = rb->rand()%10 + 1; | 192 | j = rb->rand()%10 + 1; |
337 | if((board[i][j].colour == COLOUR_DARK) && (board[i][j].farm == false)) { | 193 | if((board[i][j].colour == COLOUR_DARK) && (board[i][j].farm == false)) |
194 | { | ||
338 | board[i][j].farm = true; | 195 | board[i][j].farm = true; |
339 | compres.farms++; | 196 | compres.farms++; |
340 | } | 197 | } |
341 | } | 198 | } |
342 | while(compres.inds < superdom_settings.compstartinds) { | 199 | while(compres.inds < superdom_settings.compstartinds) |
200 | { | ||
343 | i = rb->rand()%10 + 1; | 201 | i = rb->rand()%10 + 1; |
344 | j = rb->rand()%10 + 1; | 202 | j = rb->rand()%10 + 1; |
345 | if((board[i][j].colour == COLOUR_DARK) && (board[i][j].ind == false)) { | 203 | if((board[i][j].colour == COLOUR_DARK) && (board[i][j].ind == false)) |
204 | { | ||
346 | board[i][j].ind = true; | 205 | board[i][j].ind = true; |
347 | compres.inds++; | 206 | compres.inds++; |
348 | } | 207 | } |
349 | } | 208 | } |
350 | while(humanres.farms < superdom_settings.humanstartfarms) { | 209 | while(humanres.farms < superdom_settings.humanstartfarms) |
210 | { | ||
351 | i = rb->rand()%10 + 1; | 211 | i = rb->rand()%10 + 1; |
352 | j = rb->rand()%10 + 1; | 212 | j = rb->rand()%10 + 1; |
353 | if((board[i][j].colour == COLOUR_LIGHT)&&(board[i][j].farm == false)) { | 213 | if((board[i][j].colour == COLOUR_LIGHT)&&(board[i][j].farm == false)) |
214 | { | ||
354 | board[i][j].farm = true; | 215 | board[i][j].farm = true; |
355 | humanres.farms++; | 216 | humanres.farms++; |
356 | } | 217 | } |
357 | } | 218 | } |
358 | while(humanres.inds < superdom_settings.humanstartinds) { | 219 | while(humanres.inds < superdom_settings.humanstartinds) |
220 | { | ||
359 | i = rb->rand()%10 + 1; | 221 | i = rb->rand()%10 + 1; |
360 | j = rb->rand()%10 + 1; | 222 | j = rb->rand()%10 + 1; |
361 | if((board[i][j].colour == COLOUR_LIGHT) && (board[i][j].ind == false)) { | 223 | if((board[i][j].colour == COLOUR_LIGHT) && (board[i][j].ind == false)) |
224 | { | ||
362 | board[i][j].ind = true; | 225 | board[i][j].ind = true; |
363 | humanres.inds++; | 226 | humanres.inds++; |
364 | } | 227 | } |
365 | } | 228 | } |
366 | } | 229 | } |
367 | 230 | ||
368 | void draw_board(void) { | 231 | void draw_board(void) |
232 | { | ||
369 | int i,j; | 233 | int i,j; |
370 | rb->lcd_clear_display(); | 234 | rb->lcd_clear_display(); |
371 | for(i=1;i<11;i++) { | 235 | for(i=1;i<11;i++) |
372 | for(j=1;j<11;j++) { | 236 | { |
373 | if(board[i][j].colour == COLOUR_DARK) { | 237 | for(j=1;j<11;j++) |
238 | { | ||
239 | if(board[i][j].colour == COLOUR_DARK) | ||
240 | { | ||
374 | rb->lcd_set_foreground(LCD_DARKGRAY); | 241 | rb->lcd_set_foreground(LCD_DARKGRAY); |
375 | } else { | 242 | } |
243 | else | ||
244 | { | ||
376 | rb->lcd_set_foreground(LCD_LIGHTGRAY); | 245 | rb->lcd_set_foreground(LCD_LIGHTGRAY); |
377 | } | 246 | } |
378 | rb->lcd_fillrect(MARGIN+(BOX_WIDTH*(i-1)), | 247 | rb->lcd_fillrect(MARGIN+(BOX_WIDTH*(i-1)), |
@@ -381,7 +250,8 @@ void draw_board(void) { | |||
381 | #if LCD_DEPTH != 16 | 250 | #if LCD_DEPTH != 16 |
382 | rb->lcd_set_drawmode(DRMODE_BG | DRMODE_INVERSEVID); | 251 | rb->lcd_set_drawmode(DRMODE_BG | DRMODE_INVERSEVID); |
383 | #endif | 252 | #endif |
384 | if(board[i][j].ind) { | 253 | if(board[i][j].ind) |
254 | { | ||
385 | MY_BITMAP_PART(superdom_boarditems, | 255 | MY_BITMAP_PART(superdom_boarditems, |
386 | board[i][j].colour?ICON_WIDTH:0, 0, ICON_STRIDE, | 256 | board[i][j].colour?ICON_WIDTH:0, 0, ICON_STRIDE, |
387 | #if LCD_WIDTH > LCD_HEIGHT | 257 | #if LCD_WIDTH > LCD_HEIGHT |
@@ -393,21 +263,24 @@ void draw_board(void) { | |||
393 | #endif | 263 | #endif |
394 | ICON_WIDTH, ICON_HEIGHT); | 264 | ICON_WIDTH, ICON_HEIGHT); |
395 | } | 265 | } |
396 | if(board[i][j].farm) { | 266 | if(board[i][j].farm) |
267 | { | ||
397 | MY_BITMAP_PART(superdom_boarditems, | 268 | MY_BITMAP_PART(superdom_boarditems, |
398 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT, | 269 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT, |
399 | ICON_STRIDE, MARGIN+(BOX_WIDTH*(i-1))+1, | 270 | ICON_STRIDE, MARGIN+(BOX_WIDTH*(i-1))+1, |
400 | MARGIN+(BOX_HEIGHT*(j-1))+1, | 271 | MARGIN+(BOX_HEIGHT*(j-1))+1, |
401 | ICON_WIDTH, ICON_HEIGHT); | 272 | ICON_WIDTH, ICON_HEIGHT); |
402 | } | 273 | } |
403 | if(board[i][j].tank) { | 274 | if(board[i][j].tank) |
275 | { | ||
404 | MY_BITMAP_PART(superdom_boarditems, | 276 | MY_BITMAP_PART(superdom_boarditems, |
405 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*2, | 277 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*2, |
406 | ICON_STRIDE, MARGIN+(BOX_WIDTH*(i-1))+ICON_WIDTH+1, | 278 | ICON_STRIDE, MARGIN+(BOX_WIDTH*(i-1))+ICON_WIDTH+1, |
407 | MARGIN+(BOX_HEIGHT*(j-1))+ICON_HEIGHT+1, | 279 | MARGIN+(BOX_HEIGHT*(j-1))+ICON_HEIGHT+1, |
408 | ICON_WIDTH, ICON_HEIGHT); | 280 | ICON_WIDTH, ICON_HEIGHT); |
409 | } | 281 | } |
410 | if(board[i][j].men) { | 282 | if(board[i][j].men) |
283 | { | ||
411 | MY_BITMAP_PART(superdom_boarditems, | 284 | MY_BITMAP_PART(superdom_boarditems, |
412 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*3, | 285 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*3, |
413 | #if LCD_WIDTH > LCD_HEIGHT | 286 | #if LCD_WIDTH > LCD_HEIGHT |
@@ -419,7 +292,8 @@ void draw_board(void) { | |||
419 | #endif | 292 | #endif |
420 | ICON_WIDTH, ICON_HEIGHT); | 293 | ICON_WIDTH, ICON_HEIGHT); |
421 | } | 294 | } |
422 | if(board[i][j].plane) { | 295 | if(board[i][j].plane) |
296 | { | ||
423 | MY_BITMAP_PART(superdom_boarditems, | 297 | MY_BITMAP_PART(superdom_boarditems, |
424 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*4, | 298 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*4, |
425 | #if LCD_WIDTH > LCD_HEIGHT | 299 | #if LCD_WIDTH > LCD_HEIGHT |
@@ -431,7 +305,8 @@ void draw_board(void) { | |||
431 | #endif | 305 | #endif |
432 | ICON_WIDTH, ICON_HEIGHT); | 306 | ICON_WIDTH, ICON_HEIGHT); |
433 | } | 307 | } |
434 | if(board[i][j].nuke) { | 308 | if(board[i][j].nuke) |
309 | { | ||
435 | MY_BITMAP_PART(superdom_boarditems, | 310 | MY_BITMAP_PART(superdom_boarditems, |
436 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*5, | 311 | board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*5, |
437 | #if LCD_WIDTH > LCD_HEIGHT | 312 | #if LCD_WIDTH > LCD_HEIGHT |
@@ -449,21 +324,28 @@ void draw_board(void) { | |||
449 | } | 324 | } |
450 | } | 325 | } |
451 | rb->lcd_set_foreground(LCD_BLACK); | 326 | rb->lcd_set_foreground(LCD_BLACK); |
452 | for(i=0;i<=10;i++) { /* Draw Horizontal lines */ | 327 | /* Draw Horizontal lines */ |
328 | for(i=0;i<=10;i++) | ||
329 | { | ||
453 | rb->lcd_hline(MARGIN, MARGIN+(BOX_WIDTH*10), MARGIN+(BOX_HEIGHT*i)); | 330 | rb->lcd_hline(MARGIN, MARGIN+(BOX_WIDTH*10), MARGIN+(BOX_HEIGHT*i)); |
454 | } | 331 | } |
455 | for(i=0;i<=10;i++) { /* Draw Vertical lines */ | 332 | /* Draw Vertical lines */ |
333 | for(i=0;i<=10;i++) | ||
334 | { | ||
456 | rb->lcd_vline(MARGIN+(BOX_WIDTH*i), MARGIN, MARGIN+(BOX_HEIGHT*10)); | 335 | rb->lcd_vline(MARGIN+(BOX_WIDTH*i), MARGIN, MARGIN+(BOX_HEIGHT*10)); |
457 | } | 336 | } |
458 | rb->lcd_update(); | 337 | rb->lcd_update(); |
459 | } | 338 | } |
460 | 339 | ||
461 | static int calc_strength(int colour, int x, int y) { | 340 | static int calc_strength(int colour, int x, int y) |
341 | { | ||
462 | int a, b, score=0; | 342 | int a, b, score=0; |
463 | for (a = -1; a < 2; a++) { | 343 | for (a = -1; a < 2; a++) |
464 | for (b = -1; b < 2; b++) { | 344 | { |
465 | if ((b == 0 || a == 0) && | 345 | for (b = -1; b < 2; b++) |
466 | (board[x + a][y + b].colour == colour)) { | 346 | { |
347 | if(board[x+a][y+b].colour==colour) | ||
348 | { | ||
467 | score += 10; | 349 | score += 10; |
468 | if(board[x + a][y + b].tank || board[x + a][y + b].farm) | 350 | if(board[x + a][y + b].tank || board[x + a][y + b].farm) |
469 | score += 30; | 351 | score += 30; |
@@ -479,15 +361,18 @@ static int calc_strength(int colour, int x, int y) { | |||
479 | return score; | 361 | return score; |
480 | } | 362 | } |
481 | 363 | ||
482 | void gen_interest(void) { | 364 | void gen_interest(void) |
365 | { | ||
483 | /* Interest should be around 10% */ | 366 | /* Interest should be around 10% */ |
484 | rb->srand(*rb->current_tick); | ||
485 | int interest = 7+rb->rand()%6; | 367 | int interest = 7+rb->rand()%6; |
486 | humanres.bank = humanres.bank+(interest*humanres.bank/100); | 368 | humanres.bank = humanres.bank+(interest*humanres.bank/100); |
369 | /* Different interest for AI player */ | ||
370 | interest = 7+rb->rand()%6; | ||
487 | compres.bank = compres.bank+(interest*compres.bank/100); | 371 | compres.bank = compres.bank+(interest*compres.bank/100); |
488 | } | 372 | } |
489 | 373 | ||
490 | void draw_cursor(void) { | 374 | void draw_cursor(void) |
375 | { | ||
491 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | 376 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); |
492 | rb->lcd_fillrect(MARGIN+((cursor.x-1)*BOX_WIDTH), | 377 | rb->lcd_fillrect(MARGIN+((cursor.x-1)*BOX_WIDTH), |
493 | MARGIN+((cursor.y-1)*BOX_HEIGHT), BOX_WIDTH+1, BOX_HEIGHT+1); | 378 | MARGIN+((cursor.y-1)*BOX_HEIGHT), BOX_WIDTH+1, BOX_HEIGHT+1); |
@@ -495,49 +380,69 @@ void draw_cursor(void) { | |||
495 | rb->lcd_update(); | 380 | rb->lcd_update(); |
496 | } | 381 | } |
497 | 382 | ||
498 | void gen_resources(void) { | 383 | void gen_resources(void) |
384 | { | ||
499 | int inccash = 0; | 385 | int inccash = 0; |
500 | int incfood = 0; | 386 | int incfood = 0; |
501 | int ratecash = 0; | 387 | int ratecash = 0; |
502 | int ratefood = 0; | 388 | int ratefood = 0; |
503 | int i; | 389 | int i; |
504 | gen_interest(); | 390 | gen_interest(); |
505 | rb->srand(*rb->current_tick); | ||
506 | /* Generate Human's resources */ | 391 | /* Generate Human's resources */ |
507 | for(i=0;i<humanres.inds;i++) { | 392 | for(i=0;i<humanres.inds;i++) |
393 | { | ||
508 | inccash += (300+rb->rand()%200); | 394 | inccash += (300+rb->rand()%200); |
509 | } | 395 | } |
510 | for(i=0;i<humanres.farms;i++) { | 396 | for(i=0;i<humanres.farms;i++) |
397 | { | ||
511 | incfood += (200+rb->rand()%200); | 398 | incfood += (200+rb->rand()%200); |
512 | } | 399 | } |
513 | if(humanres.inds) | 400 | if(humanres.inds) |
514 | ratecash = inccash/humanres.inds; | 401 | ratecash = inccash/humanres.inds; |
515 | if(humanres.farms) | 402 | if(humanres.farms) |
516 | ratefood = incfood/humanres.farms; | 403 | ratefood = incfood/humanres.farms; |
517 | if(ratecash > 450) { | 404 | if(ratecash > 450) |
518 | if(ratefood > 350) { | 405 | { |
406 | if(ratefood > 350) | ||
407 | { | ||
519 | rb->splash(HZ*2, "Patriotism sweeps the land, all production" | 408 | rb->splash(HZ*2, "Patriotism sweeps the land, all production" |
520 | " is up this year!"); | 409 | " is up this year!"); |
521 | } else { | 410 | } |
411 | else | ||
412 | { | ||
522 | rb->splash(HZ*2, "Factories working at maximum efficiency," | 413 | rb->splash(HZ*2, "Factories working at maximum efficiency," |
523 | " cash production up this year!"); | 414 | " cash production up this year!"); |
524 | } | 415 | } |
525 | } else if(ratecash > 350) { | 416 | } |
526 | if(ratefood > 350) { | 417 | else if(ratecash > 350) |
418 | { | ||
419 | if(ratefood > 350) | ||
420 | { | ||
527 | rb->splash(HZ*2, "Record crop harvest this year!"); | 421 | rb->splash(HZ*2, "Record crop harvest this year!"); |
528 | } else if(ratefood > 250) { | 422 | } |
423 | else if(ratefood > 250) | ||
424 | { | ||
529 | rb->splash(HZ*2, "Production continues as normal"); | 425 | rb->splash(HZ*2, "Production continues as normal"); |
530 | } else { | 426 | } |
427 | else | ||
428 | { | ||
531 | rb->splash(HZ*2, "Spoilage of crops leads to reduced farm" | 429 | rb->splash(HZ*2, "Spoilage of crops leads to reduced farm" |
532 | " output this year"); | 430 | " output this year"); |
533 | } | 431 | } |
534 | } else { | 432 | } |
535 | if(ratefood > 350) { | 433 | else |
434 | { | ||
435 | if(ratefood > 350) | ||
436 | { | ||
536 | rb->splash(HZ*2, "Record crop harvest this year!"); | 437 | rb->splash(HZ*2, "Record crop harvest this year!"); |
537 | } else if(ratefood > 250) { | 438 | } |
439 | else if(ratefood > 250) | ||
440 | { | ||
538 | rb->splash(HZ*2, "Factory unions introduced. Industrial" | 441 | rb->splash(HZ*2, "Factory unions introduced. Industrial" |
539 | " production is down this year."); | 442 | " production is down this year."); |
540 | } else { | 443 | } |
444 | else | ||
445 | { | ||
541 | rb->splash(HZ*2, "Internet created. All production is down" | 446 | rb->splash(HZ*2, "Internet created. All production is down" |
542 | " due to time wasted."); | 447 | " due to time wasted."); |
543 | } | 448 | } |
@@ -548,17 +453,20 @@ void gen_resources(void) { | |||
548 | /* Generate Computer's resources */ | 453 | /* Generate Computer's resources */ |
549 | inccash = 0; | 454 | inccash = 0; |
550 | incfood = 0; | 455 | incfood = 0; |
551 | for(i=0;i<compres.inds;i++) { | 456 | for(i=0;i<compres.inds;i++) |
457 | { | ||
552 | inccash += (300+rb->rand()%200); | 458 | inccash += (300+rb->rand()%200); |
553 | } | 459 | } |
554 | for(i=0;i<compres.farms;i++) { | 460 | for(i=0;i<compres.farms;i++) |
461 | { | ||
555 | incfood += (200+rb->rand()%200); | 462 | incfood += (200+rb->rand()%200); |
556 | } | 463 | } |
557 | compres.cash += inccash; | 464 | compres.cash += inccash; |
558 | compres.food += incfood; | 465 | compres.food += incfood; |
559 | } | 466 | } |
560 | 467 | ||
561 | static void update_score(void) { | 468 | static void update_score(void) |
469 | { | ||
562 | int strength; | 470 | int strength; |
563 | rb->lcd_setfont(FONT_SYSFIXED); | 471 | rb->lcd_setfont(FONT_SYSFIXED); |
564 | rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID); | 472 | rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID); |
@@ -571,7 +479,8 @@ static void update_score(void) { | |||
571 | rb->lcd_setfont(FONT_UI); | 479 | rb->lcd_setfont(FONT_UI); |
572 | } | 480 | } |
573 | 481 | ||
574 | static int settings_menu(void) { | 482 | static int settings_menu(void) |
483 | { | ||
575 | int selection = 0; | 484 | int selection = 0; |
576 | 485 | ||
577 | MENUITEM_STRINGLIST(menu, "Super Domination Settings", NULL, | 486 | MENUITEM_STRINGLIST(menu, "Super Domination Settings", NULL, |
@@ -579,8 +488,10 @@ static int settings_menu(void) { | |||
579 | "Human starting farms", "Human starting factories", | 488 | "Human starting farms", "Human starting factories", |
580 | "Starting cash", "Starting food", "Moves per turn"); | 489 | "Starting cash", "Starting food", "Moves per turn"); |
581 | 490 | ||
582 | while(1) { | 491 | while(1) |
583 | switch(rb->do_menu(&menu, &selection, NULL, false)) { | 492 | { |
493 | switch(rb->do_menu(&menu, &selection, NULL, false)) | ||
494 | { | ||
584 | case 0: | 495 | case 0: |
585 | rb->set_int("Computer starting farms", "", UNIT_INT, | 496 | rb->set_int("Computer starting farms", "", UNIT_INT, |
586 | &superdom_settings.compstartfarms, NULL, | 497 | &superdom_settings.compstartfarms, NULL, |
@@ -627,34 +538,41 @@ static int settings_menu(void) { | |||
627 | return RET_VAL_OK; | 538 | return RET_VAL_OK; |
628 | } | 539 | } |
629 | 540 | ||
630 | static int superdom_help(void) { | 541 | static int superdom_help(void) |
542 | { | ||
631 | static char* help_text[] = { | 543 | static char* help_text[] = { |
632 | "Super", "domination", "is", "a", "turn", "based", "strategy", "game,", | 544 | "Super", "Domination", "is", "a", "turn-based", "strategy", "game,", |
633 | "where", "the", "aim", "is", "to", "overpower", "the", "computer", | 545 | "where", "the", "aim", "is", "to", "overpower", "the", "computer", |
634 | "player", "by", "taking", "their", "territory.", "", | 546 | "player", "by", "taking", "their", "territory.", "", |
635 | "Each", "year", "you", "are", "allocated", "an", "amount", "of", "cash", | 547 | "Each", "year", "you", "are", "allocated", "an", "amount", "of", "cash", |
636 | "and", "food,", "depending", "on", "how", "many", "farms", "and", | 548 | "and", "food,", "depending", "on", "how", "many", "farms", "and", |
637 | "factories", "you", "control.", "", | 549 | "factories", "you", "control.", "", |
638 | "Use", "this", "cash", "and", "food", "to", "buy", "and", "feed", "your", | 550 | "Use", "this", "cash", "and", "food", "to", "build", "and", "feed", "your", |
639 | "army.", "Each", "tile", "has", "a", "strength,", "calculated", "by", | 551 | "army.", "Each", "tile", "has", "a", "strength,", "calculated", "by", |
640 | "the", "ownership", "of", "adjacent", "tiles,", "and", "the", "type", | 552 | "the", "ownership", "of", "surrounding", "tiles,", "and", "the", "type", |
641 | "and", "number", "of", "troops", "on", "them.", | 553 | "and", "number", "of", "troops", "on", "them.", |
642 | }; | 554 | }; |
643 | 555 | #ifdef HAVE_LCD_COLOR | |
556 | rb->lcd_set_foreground(LCD_WHITE); | ||
557 | rb->lcd_set_background(LCD_BLACK); | ||
558 | #endif | ||
644 | if (display_text(ARRAYLEN(help_text), help_text, NULL, NULL, true)) | 559 | if (display_text(ARRAYLEN(help_text), help_text, NULL, NULL, true)) |
645 | return RET_VAL_USB; | 560 | return RET_VAL_USB; |
646 | return RET_VAL_OK; | 561 | return RET_VAL_OK; |
647 | } | 562 | } |
648 | 563 | ||
649 | static int start_menu(void) { | 564 | static int start_menu(void) |
565 | { | ||
650 | int selection = 0; | 566 | int selection = 0; |
651 | 567 | ||
652 | MENUITEM_STRINGLIST(menu, "Super Domination Menu", NULL, | 568 | MENUITEM_STRINGLIST(menu, "Super Domination Menu", NULL, |
653 | "Play Super Domination", "Settings", | 569 | "Play Super Domination", "Settings", |
654 | "Help", "Playback Control", "Quit"); | 570 | "Help", "Playback Control", "Quit"); |
655 | 571 | ||
656 | while(1) { | 572 | while(1) |
657 | switch(rb->do_menu(&menu, &selection, NULL, false)) { | 573 | { |
574 | switch(rb->do_menu(&menu, &selection, NULL, false)) | ||
575 | { | ||
658 | case 0: | 576 | case 0: |
659 | return RET_VAL_OK; /* start playing */ | 577 | return RET_VAL_OK; /* start playing */ |
660 | break; | 578 | break; |
@@ -678,19 +596,22 @@ static int start_menu(void) { | |||
678 | return RET_VAL_QUIT_ERR; | 596 | return RET_VAL_QUIT_ERR; |
679 | } | 597 | } |
680 | 598 | ||
681 | static int save_game(void) { | 599 | static int save_game(void) |
600 | { | ||
682 | int fd; | 601 | int fd; |
683 | char savepath[MAX_PATH]; | 602 | char savepath[MAX_PATH]; |
684 | 603 | ||
685 | rb->snprintf(savepath, sizeof(savepath), "/Savegame.ssg"); | 604 | rb->snprintf(savepath, sizeof(savepath), "/Savegame.ssg"); |
686 | if(rb->kbd_input(savepath, MAX_PATH)) { | 605 | if(rb->kbd_input(savepath, MAX_PATH)) |
606 | { | ||
687 | DEBUGF("Keyboard input failed\n"); | 607 | DEBUGF("Keyboard input failed\n"); |
688 | return -1; | 608 | return -1; |
689 | } | 609 | } |
690 | 610 | ||
691 | fd = rb->open(savepath, O_WRONLY|O_CREAT, 0666); | 611 | fd = rb->open(savepath, O_WRONLY|O_CREAT, 0666); |
692 | DEBUGF("savepath: %s\n", savepath); | 612 | DEBUGF("savepath: %s\n", savepath); |
693 | if(fd < 0) { | 613 | if(fd < 0) |
614 | { | ||
694 | DEBUGF("Couldn't create/open file\n"); | 615 | DEBUGF("Couldn't create/open file\n"); |
695 | return -1; | 616 | return -1; |
696 | } | 617 | } |
@@ -729,12 +650,14 @@ static int save_game(void) { | |||
729 | return 0; | 650 | return 0; |
730 | } | 651 | } |
731 | 652 | ||
732 | static int ingame_menu(void) { | 653 | static int ingame_menu(void) |
654 | { | ||
733 | MENUITEM_STRINGLIST(menu, "Super Domination Menu", NULL, | 655 | MENUITEM_STRINGLIST(menu, "Super Domination Menu", NULL, |
734 | "Return to game", "Save Game", | 656 | "Return to game", "Save Game", |
735 | "Playback Control", "Quit"); | 657 | "Playback Control", "Quit"); |
736 | 658 | ||
737 | switch(rb->do_menu(&menu, NULL, NULL, false)) { | 659 | switch(rb->do_menu(&menu, NULL, NULL, false)) |
660 | { | ||
738 | case 0: | 661 | case 0: |
739 | return RET_VAL_OK; | 662 | return RET_VAL_OK; |
740 | break; | 663 | break; |
@@ -761,37 +684,42 @@ static int ingame_menu(void) { | |||
761 | return RET_VAL_OK; | 684 | return RET_VAL_OK; |
762 | } | 685 | } |
763 | 686 | ||
764 | static int get_number(char* param, int* value, int max) { | 687 | static int get_number(char* param, int* value, int max) |
688 | { | ||
765 | static const char *button_labels[4][3] = { | 689 | static const char *button_labels[4][3] = { |
766 | { "1", "2", "3" }, | 690 | { "1", "2", "3" }, |
767 | { "4", "5", "6" }, | 691 | { "4", "5", "6" }, |
768 | { "7", "8", "9" }, | 692 | { "7", "8", "9" }, |
769 | { "CLR", "0", "OK" } | 693 | { "DEL", "0", "OK" } |
770 | }; | 694 | }; |
771 | int i,j,x=0,y=0; | 695 | int i,j,x=0,y=0; |
772 | int height, width; | 696 | int height, width; |
773 | int button = 0, ret = RET_VAL_OK; | 697 | int button = 0, ret = RET_VAL_OK; |
774 | bool done = false; | 698 | bool done = false; |
775 | rb->lcd_clear_display(); | 699 | rb->lcd_clear_display(); |
776 | rb->lcd_getstringsize("CLR", &width, &height); | 700 | rb->lcd_getstringsize("DEL", &width, &height); |
777 | if(width > NUM_BOX_WIDTH || height > NUM_BOX_HEIGHT) | 701 | if(width > NUM_BOX_WIDTH || height > NUM_BOX_HEIGHT) |
778 | rb->lcd_setfont(FONT_SYSFIXED); | 702 | rb->lcd_setfont(FONT_SYSFIXED); |
779 | /* Draw a 3x4 grid */ | 703 | /* Draw a 3x4 grid */ |
780 | for(i=0;i<=3;i++) { /* Vertical lines */ | 704 | for(i=0;i<=3;i++) |
705 | { /* Vertical lines */ | ||
781 | rb->lcd_vline(NUM_MARGIN_X+(NUM_BOX_WIDTH*i), NUM_MARGIN_Y, | 706 | rb->lcd_vline(NUM_MARGIN_X+(NUM_BOX_WIDTH*i), NUM_MARGIN_Y, |
782 | NUM_MARGIN_Y+(4*NUM_BOX_HEIGHT)); | 707 | NUM_MARGIN_Y+(4*NUM_BOX_HEIGHT)); |
783 | } | 708 | } |
784 | for(i=0;i<=4;i++) { /* Horizontal lines */ | 709 | /* Horizontal lines */ |
710 | for(i=0;i<=4;i++) | ||
711 | { | ||
785 | rb->lcd_hline(NUM_MARGIN_X, NUM_MARGIN_X+(3*NUM_BOX_WIDTH), | 712 | rb->lcd_hline(NUM_MARGIN_X, NUM_MARGIN_X+(3*NUM_BOX_WIDTH), |
786 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*i)); | 713 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*i)); |
787 | } | 714 | } |
788 | for(i=0;i<4;i++) { | 715 | for(i=0;i<4;i++) |
789 | for(j=0;j<3;j++) { | 716 | { |
717 | for(j=0;j<3;j++) | ||
718 | { | ||
790 | rb->lcd_getstringsize(button_labels[i][j], &width, &height); | 719 | rb->lcd_getstringsize(button_labels[i][j], &width, &height); |
791 | rb->lcd_putsxy( | 720 | rb->lcd_putsxy(NUM_MARGIN_X+(j*NUM_BOX_WIDTH)+NUM_BOX_WIDTH/2-width/2, |
792 | NUM_MARGIN_X+(j*NUM_BOX_WIDTH)+NUM_BOX_WIDTH/2-width/2, | 721 | NUM_MARGIN_Y+(i*NUM_BOX_HEIGHT)+NUM_BOX_HEIGHT/2-height/2, |
793 | NUM_MARGIN_Y+(i*NUM_BOX_HEIGHT)+NUM_BOX_HEIGHT/2-height/2, | 722 | button_labels[i][j]); |
794 | button_labels[i][j]); | ||
795 | } | 723 | } |
796 | } | 724 | } |
797 | rb->lcd_putsxyf(NUM_MARGIN_X+10, NUM_MARGIN_Y+4*NUM_BOX_HEIGHT+10,"%d",*value); | 725 | rb->lcd_putsxyf(NUM_MARGIN_X+10, NUM_MARGIN_Y+4*NUM_BOX_HEIGHT+10,"%d",*value); |
@@ -800,29 +728,40 @@ static int get_number(char* param, int* value, int max) { | |||
800 | rb->lcd_putsxy((LCD_WIDTH-width)/2, (NUM_MARGIN_Y-height)/2, param); | 728 | rb->lcd_putsxy((LCD_WIDTH-width)/2, (NUM_MARGIN_Y-height)/2, param); |
801 | else | 729 | else |
802 | rb->lcd_puts_scroll(0, (NUM_MARGIN_Y/height-1)/2, param); | 730 | rb->lcd_puts_scroll(0, (NUM_MARGIN_Y/height-1)/2, param); |
731 | |||
803 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | 732 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); |
804 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | 733 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), |
805 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | 734 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), |
806 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | 735 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); |
807 | rb->lcd_set_drawmode(DRMODE_SOLID); | 736 | rb->lcd_set_drawmode(DRMODE_SOLID); |
808 | rb->lcd_update(); | 737 | rb->lcd_update(); |
809 | while(!done) { | 738 | |
810 | button = rb->button_get(true); | 739 | while(!done) |
740 | { | ||
741 | button=pluginlib_getaction(-1, plugin_contexts, ARRAYLEN(plugin_contexts)); | ||
811 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | 742 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); |
812 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | 743 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), |
813 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | 744 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), |
814 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | 745 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); |
815 | rb->lcd_set_drawmode(DRMODE_SOLID); | 746 | rb->lcd_set_drawmode(DRMODE_SOLID); |
816 | switch(button) { | 747 | switch(button) |
748 | { | ||
817 | case SUPERDOM_OK: | 749 | case SUPERDOM_OK: |
818 | if(y!=3) { | 750 | if(y!=3) |
751 | { | ||
819 | *value *= 10; | 752 | *value *= 10; |
820 | *value += button_labels[y][x][0] - '0'; | 753 | *value += button_labels[y][x][0] - '0'; |
821 | } else if(x==0) { | 754 | } |
755 | else if(x==0) | ||
756 | { | ||
822 | *value /= 10; | 757 | *value /= 10; |
823 | } else if(x==1) { | 758 | } |
759 | else if(x==1) | ||
760 | { | ||
824 | *value *= 10; | 761 | *value *= 10; |
825 | } else if(x==2) { | 762 | } |
763 | else if(x==2) | ||
764 | { | ||
826 | done = true; | 765 | done = true; |
827 | break; | 766 | break; |
828 | } | 767 | } |
@@ -842,35 +781,29 @@ static int get_number(char* param, int* value, int max) { | |||
842 | break; | 781 | break; |
843 | #if CONFIG_KEYPAD != IRIVER_H10_PAD | 782 | #if CONFIG_KEYPAD != IRIVER_H10_PAD |
844 | case SUPERDOM_LEFT: | 783 | case SUPERDOM_LEFT: |
845 | if(x==0) { | 784 | if(x==0) |
846 | #ifdef IPOD_STYLE | 785 | { |
847 | if(y>0) | ||
848 | y--; | ||
849 | else | ||
850 | y=3; | ||
851 | #endif | ||
852 | x=2; | 786 | x=2; |
853 | } else { | 787 | } |
788 | else | ||
789 | { | ||
854 | x--; | 790 | x--; |
855 | } | 791 | } |
856 | break; | 792 | break; |
857 | case SUPERDOM_RIGHT: | 793 | case SUPERDOM_RIGHT: |
858 | if(x==2) { | 794 | if(x==2) |
859 | #ifdef IPOD_STYLE | 795 | { |
860 | if(y==3) | ||
861 | y=0; | ||
862 | else | ||
863 | y++; | ||
864 | #endif | ||
865 | x=0; | 796 | x=0; |
866 | } else { | 797 | } |
798 | else | ||
799 | { | ||
867 | x++; | 800 | x++; |
868 | } | 801 | } |
869 | break; | 802 | break; |
870 | #endif | 803 | #endif |
871 | #ifndef IPOD_STYLE | ||
872 | case SUPERDOM_UP: | 804 | case SUPERDOM_UP: |
873 | if(y==0) { | 805 | if(y==0) |
806 | { | ||
874 | #if CONFIG_KEYPAD == IRIVER_H10_PAD | 807 | #if CONFIG_KEYPAD == IRIVER_H10_PAD |
875 | if(x > 0) | 808 | if(x > 0) |
876 | x--; | 809 | x--; |
@@ -878,26 +811,30 @@ static int get_number(char* param, int* value, int max) { | |||
878 | x=2; | 811 | x=2; |
879 | #endif | 812 | #endif |
880 | y=3; | 813 | y=3; |
881 | } else { | 814 | } |
815 | else | ||
816 | { | ||
882 | y--; | 817 | y--; |
883 | } | 818 | } |
884 | break; | 819 | break; |
885 | case SUPERDOM_DOWN: | 820 | case SUPERDOM_DOWN: |
886 | if(y==3) { | 821 | if(y==3) |
822 | { | ||
887 | #if CONFIG_KEYPAD == IRIVER_H10_PAD | 823 | #if CONFIG_KEYPAD == IRIVER_H10_PAD |
888 | if(x < 2) | 824 | if(x < 2) |
889 | x++; | 825 | x++; |
890 | else | 826 | else |
891 | x=0; | 827 | x=0; |
892 | #endif | 828 | #endif /* CONFIG_KEYPAD == IRIVER_H10_PAD */ |
893 | y=0; | 829 | y=0; |
894 | } else { | 830 | } |
831 | else | ||
832 | { | ||
895 | y++; | 833 | y++; |
896 | } | 834 | } |
897 | break; | 835 | break; |
898 | #endif | ||
899 | default: | 836 | default: |
900 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | 837 | if(rb->default_event_handler(button) == SYS_USB_CONNECTED) |
901 | { | 838 | { |
902 | done = true; | 839 | done = true; |
903 | ret = RET_VAL_USB; | 840 | ret = RET_VAL_USB; |
@@ -918,8 +855,10 @@ static int get_number(char* param, int* value, int max) { | |||
918 | return ret; | 855 | return ret; |
919 | } | 856 | } |
920 | 857 | ||
921 | static bool tile_has_item(int type, int x, int y) { | 858 | static bool tile_has_item(int type, int x, int y) |
922 | switch(type) { | 859 | { |
860 | switch(type) | ||
861 | { | ||
923 | case 0: | 862 | case 0: |
924 | return (board[x][y].men > 0); | 863 | return (board[x][y].men > 0); |
925 | break; | 864 | break; |
@@ -942,7 +881,8 @@ static bool tile_has_item(int type, int x, int y) { | |||
942 | return false; | 881 | return false; |
943 | } | 882 | } |
944 | 883 | ||
945 | static int buy_resources(int colour, int type, int x, int y, int nummen) { | 884 | static int buy_resources(int colour, int type, int x, int y, int nummen) |
885 | { | ||
946 | const char *itemnames[][6] = { | 886 | const char *itemnames[][6] = { |
947 | { | 887 | { |
948 | "them", | 888 | "them", |
@@ -951,14 +891,16 @@ static int buy_resources(int colour, int type, int x, int y, int nummen) { | |||
951 | "the farm", | 891 | "the farm", |
952 | "the industrial plant", | 892 | "the industrial plant", |
953 | "the nuke", | 893 | "the nuke", |
954 | }, { | 894 | }, |
895 | { | ||
955 | "place men", | 896 | "place men", |
956 | "place a tank", | 897 | "place a tank", |
957 | "place a plane", | 898 | "place a plane", |
958 | "build a farm", | 899 | "build a farm", |
959 | "build an industrial plant", | 900 | "build an industrial plant", |
960 | "place a nuke", | 901 | "place a nuke", |
961 | }, { | 902 | }, |
903 | { | ||
962 | NULL, | 904 | NULL, |
963 | "a tank", | 905 | "a tank", |
964 | "a plane", | 906 | "a plane", |
@@ -973,54 +915,63 @@ static int buy_resources(int colour, int type, int x, int y, int nummen) { | |||
973 | int temp; | 915 | int temp; |
974 | struct resources *res; | 916 | struct resources *res; |
975 | 917 | ||
976 | if(human) { | 918 | if(human) |
919 | { | ||
977 | res = &humanres; | 920 | res = &humanres; |
978 | } else { | 921 | } |
922 | else | ||
923 | { | ||
979 | res = &compres; | 924 | res = &compres; |
980 | } | 925 | } |
981 | switch(type) { | 926 | switch(type) |
927 | { | ||
982 | case 0: /* men */ | 928 | case 0: /* men */ |
983 | price = 1*nummen; | 929 | price = PRICE_MEN*nummen; |
984 | break; | 930 | break; |
985 | case 1: /* tank */ | 931 | case 1: /* tank */ |
986 | price = 300; | 932 | price = PRICE_TANK; |
987 | break; | 933 | break; |
988 | case 2: /* plane */ | 934 | case 2: /* plane */ |
989 | price = 600; | 935 | price = PRICE_PLANE; |
990 | break; | 936 | break; |
991 | case 3: /* Farm */ | 937 | case 3: /* Farm */ |
992 | price = 1150; | 938 | price = PRICE_FARM; |
993 | break; | 939 | break; |
994 | case 4: /* Factory */ | 940 | case 4: /* Factory */ |
995 | price = 1300; | 941 | price = PRICE_FACTORY; |
996 | break; | 942 | break; |
997 | case 5: /* nuke */ | 943 | case 5: /* nuke */ |
998 | price = 2000; | 944 | price = PRICE_NUKE; |
999 | break; | 945 | break; |
1000 | } | 946 | } |
1001 | if(res->cash < price) { | 947 | if(res->cash < price) |
948 | { | ||
1002 | if(human) | 949 | if(human) |
1003 | rb->splash(HZ, "Not enough money!"); | 950 | rb->splash(HZ, "Not enough money!"); |
1004 | return RET_VAL_QUIT_ERR; | 951 | return RET_VAL_QUIT_ERR; |
1005 | } | 952 | } |
1006 | if(human) { | 953 | if(human) |
954 | { | ||
1007 | rb->splashf(HZ, "Where do you want to place %s?", itemnames[0][type]); | 955 | rb->splashf(HZ, "Where do you want to place %s?", itemnames[0][type]); |
1008 | if((temp = select_square()) != RET_VAL_OK) | 956 | if((temp = select_square()) != RET_VAL_OK) |
1009 | return temp; | 957 | return temp; |
1010 | x = cursor.x; | 958 | x = cursor.x; |
1011 | y = cursor.y; | 959 | y = cursor.y; |
1012 | } | 960 | } |
1013 | if(board[x][y].colour != colour) { | 961 | if(board[x][y].colour != colour) |
962 | { | ||
1014 | if(human) | 963 | if(human) |
1015 | rb->splashf(HZ, "Can't %s on enemy territory", itemnames[1][type]); | 964 | rb->splashf(HZ, "Can't %s on enemy territory", itemnames[1][type]); |
1016 | return RET_VAL_QUIT_ERR; | 965 | return RET_VAL_QUIT_ERR; |
1017 | } | 966 | } |
1018 | if(type != 0 && tile_has_item(type, x, y)) { | 967 | if(type != 0 && tile_has_item(type, x, y)) |
968 | { | ||
1019 | if(human) | 969 | if(human) |
1020 | rb->splashf(HZ, "There is already %s there", itemnames[2][type]); | 970 | rb->splashf(HZ, "There is already %s there", itemnames[2][type]); |
1021 | return RET_VAL_QUIT_ERR; | 971 | return RET_VAL_QUIT_ERR; |
1022 | } | 972 | } |
1023 | switch(type) { | 973 | switch(type) |
974 | { | ||
1024 | case 0: | 975 | case 0: |
1025 | board[x][y].men += nummen; | 976 | board[x][y].men += nummen; |
1026 | res->men += nummen; | 977 | res->men += nummen; |
@@ -1054,13 +1005,14 @@ static int buy_resources(int colour, int type, int x, int y, int nummen) { | |||
1054 | return RET_VAL_OK; | 1005 | return RET_VAL_OK; |
1055 | } | 1006 | } |
1056 | 1007 | ||
1057 | static int buy_resources_menu(void) { | 1008 | static int buy_resources_menu(void) |
1009 | { | ||
1058 | int selection = 0,nummen; | 1010 | int selection = 0,nummen; |
1059 | 1011 | ||
1060 | MENUITEM_STRINGLIST(menu, "Buy Resources", NULL, | 1012 | MENUITEM_STRINGLIST(menu, "Buy Resources", NULL, |
1061 | "Buy men ($1)", "Buy tank ($300)", "Buy plane ($600)", | 1013 | "Buy men ($" PRICE_MEN_STR ")", "Buy tank ($" PRICE_TANK_STR ")", "Buy plane ($" PRICE_PLANE_STR ")", |
1062 | "Buy Farm ($1150)", "Buy Factory ($1300)", | 1014 | "Buy Farm ($" PRICE_FARM_STR ")", "Buy Factory ($" PRICE_FACTORY_STR ")", |
1063 | "Buy Nuke ($2000)", | 1015 | "Buy Nuke ($" PRICE_NUKE_STR ")", |
1064 | "Finish buying"); | 1016 | "Finish buying"); |
1065 | 1017 | ||
1066 | while(1) { | 1018 | while(1) { |
@@ -1078,8 +1030,7 @@ static int buy_resources_menu(void) { | |||
1078 | case 3: | 1030 | case 3: |
1079 | case 4: | 1031 | case 4: |
1080 | case 5: | 1032 | case 5: |
1081 | if(buy_resources(COLOUR_LIGHT, selection, 0, 0, nummen) | 1033 | if(buy_resources(COLOUR_LIGHT, selection, 0, 0, nummen)== RET_VAL_USB) |
1082 | == RET_VAL_USB) | ||
1083 | return RET_VAL_USB; | 1034 | return RET_VAL_USB; |
1084 | break; | 1035 | break; |
1085 | case 6: | 1036 | case 6: |
@@ -1097,17 +1048,20 @@ static int buy_resources_menu(void) { | |||
1097 | } | 1048 | } |
1098 | 1049 | ||
1099 | static int move_unit(int colour, int type, int fromx, int fromy, | 1050 | static int move_unit(int colour, int type, int fromx, int fromy, |
1100 | int tox, int toy, int nummen) { | 1051 | int tox, int toy, int nummen) |
1052 | { | ||
1101 | const char *itemnames[][3] = { | 1053 | const char *itemnames[][3] = { |
1102 | { | 1054 | { |
1103 | "troops", | 1055 | "troops", |
1104 | "the tank", | 1056 | "the tank", |
1105 | "the plane", | 1057 | "the plane", |
1106 | }, { | 1058 | }, |
1059 | { | ||
1107 | "any troops", | 1060 | "any troops", |
1108 | "a tank", | 1061 | "a tank", |
1109 | "a plane", | 1062 | "a plane", |
1110 | }, { | 1063 | }, |
1064 | { | ||
1111 | "the troops", | 1065 | "the troops", |
1112 | "the tank", | 1066 | "the tank", |
1113 | "the plane", | 1067 | "the plane", |
@@ -1116,7 +1070,8 @@ static int move_unit(int colour, int type, int fromx, int fromy, | |||
1116 | bool human = (colour == COLOUR_LIGHT); | 1070 | bool human = (colour == COLOUR_LIGHT); |
1117 | int temp; | 1071 | int temp; |
1118 | 1072 | ||
1119 | if(human) { | 1073 | if(human) |
1074 | { | ||
1120 | rb->splashf(HZ, "Select where you want to move %s from", | 1075 | rb->splashf(HZ, "Select where you want to move %s from", |
1121 | itemnames[0][type]); | 1076 | itemnames[0][type]); |
1122 | if((temp = select_square()) != RET_VAL_OK) | 1077 | if((temp = select_square()) != RET_VAL_OK) |
@@ -1124,30 +1079,36 @@ static int move_unit(int colour, int type, int fromx, int fromy, | |||
1124 | fromx = cursor.x; | 1079 | fromx = cursor.x; |
1125 | fromy = cursor.y; | 1080 | fromy = cursor.y; |
1126 | } | 1081 | } |
1127 | if(board[fromx][fromy].colour != colour) { | 1082 | if(board[fromx][fromy].colour != colour) |
1083 | { | ||
1128 | if(human) | 1084 | if(human) |
1129 | rb->splash(HZ, "That isn't your territory"); | 1085 | rb->splash(HZ, "That isn't your territory"); |
1130 | return RET_VAL_QUIT_ERR; | 1086 | return RET_VAL_QUIT_ERR; |
1131 | } | 1087 | } |
1132 | if(!tile_has_item(type, fromx, fromy)) { | 1088 | if(!tile_has_item(type, fromx, fromy)) |
1089 | { | ||
1133 | if(human) | 1090 | if(human) |
1134 | rb->splashf(HZ, "You don't have %s there", itemnames[1][type]); | 1091 | rb->splashf(HZ, "You don't have %s there", itemnames[1][type]); |
1135 | return RET_VAL_QUIT_ERR; | 1092 | return RET_VAL_QUIT_ERR; |
1136 | } | 1093 | } |
1137 | if(type == 0) { | 1094 | if(type == 0) |
1138 | if(human) { | 1095 | { |
1096 | if(human) | ||
1097 | { | ||
1139 | nummen = board[fromx][fromy].men; | 1098 | nummen = board[fromx][fromy].men; |
1140 | if((temp = get_number("How many men do you want to move?", &nummen, | 1099 | if((temp = get_number("How many men do you want to move?", &nummen, |
1141 | nummen)) != RET_VAL_OK) | 1100 | nummen)) != RET_VAL_OK) |
1142 | return temp; | 1101 | return temp; |
1143 | } | 1102 | } |
1144 | if(nummen > board[fromx][fromy].men) { | 1103 | if(nummen > board[fromx][fromy].men) |
1104 | { | ||
1145 | if(human) | 1105 | if(human) |
1146 | rb->splash(HZ, "You don't have that many troops."); | 1106 | rb->splash(HZ, "You don't have that many troops."); |
1147 | return RET_VAL_QUIT_ERR; | 1107 | return RET_VAL_QUIT_ERR; |
1148 | } | 1108 | } |
1149 | } | 1109 | } |
1150 | if(human) { | 1110 | if(human) |
1111 | { | ||
1151 | rb->splashf(HZ, "Select where you want to move %s to", | 1112 | rb->splashf(HZ, "Select where you want to move %s to", |
1152 | itemnames[2][type]); | 1113 | itemnames[2][type]); |
1153 | if((temp = select_square()) != RET_VAL_OK) | 1114 | if((temp = select_square()) != RET_VAL_OK) |
@@ -1155,19 +1116,23 @@ static int move_unit(int colour, int type, int fromx, int fromy, | |||
1155 | tox = cursor.x; | 1116 | tox = cursor.x; |
1156 | toy = cursor.y; | 1117 | toy = cursor.y; |
1157 | } | 1118 | } |
1158 | if((tox == fromx && toy == fromy) || | 1119 | if((tox == fromx && toy == fromy) || |
1159 | board[tox][toy].colour != colour || | 1120 | board[tox][toy].colour != colour || |
1160 | (type != 2 && (abs(tox - fromx) > 1 || abs(toy - fromy) > 1))) { | 1121 | (type != 2 && (abs(tox - fromx) > 1 || |
1122 | abs(toy - fromy) > 1))) | ||
1123 | { | ||
1161 | if(human) | 1124 | if(human) |
1162 | rb->splash(HZ, "Invalid move"); | 1125 | rb->splash(HZ, "Invalid move"); |
1163 | return RET_VAL_QUIT_ERR; | 1126 | return RET_VAL_QUIT_ERR; |
1164 | } | 1127 | } |
1165 | if(type != 0 && tile_has_item(type, tox, toy)) { | 1128 | if(type != 0 && tile_has_item(type, tox, toy)) |
1129 | { | ||
1166 | if(human) | 1130 | if(human) |
1167 | rb->splashf(HZ, "There is already %s there", itemnames[1][type]); | 1131 | rb->splashf(HZ, "There is already %s there", itemnames[1][type]); |
1168 | return RET_VAL_QUIT_ERR; | 1132 | return RET_VAL_QUIT_ERR; |
1169 | } | 1133 | } |
1170 | switch(type) { | 1134 | switch(type) |
1135 | { | ||
1171 | case 0: | 1136 | case 0: |
1172 | board[fromx][fromy].men -= nummen; | 1137 | board[fromx][fromy].men -= nummen; |
1173 | board[tox][toy].men += nummen; | 1138 | board[tox][toy].men += nummen; |
@@ -1184,16 +1149,19 @@ static int move_unit(int colour, int type, int fromx, int fromy, | |||
1184 | return RET_VAL_OK; | 1149 | return RET_VAL_OK; |
1185 | } | 1150 | } |
1186 | 1151 | ||
1187 | static int move_unit_menu(void) { | 1152 | static int move_unit_menu(void) |
1153 | { | ||
1188 | int selection = 0; | 1154 | int selection = 0; |
1189 | 1155 | ||
1190 | MENUITEM_STRINGLIST(menu, "Move unit", NULL, | 1156 | MENUITEM_STRINGLIST(menu, "Move unit", NULL, |
1191 | "Move men", "Move tank", "Move plane"); | 1157 | "Move men", "Move tank", "Move plane"); |
1192 | switch(rb->do_menu(&menu, &selection, NULL, false)) { | 1158 | switch(rb->do_menu(&menu, &selection, NULL, false)) |
1159 | { | ||
1193 | case 0: | 1160 | case 0: |
1194 | case 1: | 1161 | case 1: |
1195 | case 2: | 1162 | case 2: |
1196 | switch(move_unit(COLOUR_LIGHT, selection, 0, 0, 0, 0, 0)) { | 1163 | switch(move_unit(COLOUR_LIGHT, selection, 0, 0, 0, 0, 0)) |
1164 | { | ||
1197 | case RET_VAL_OK: | 1165 | case RET_VAL_OK: |
1198 | humanres.moves--; | 1166 | humanres.moves--; |
1199 | break; | 1167 | break; |
@@ -1208,38 +1176,48 @@ static int move_unit_menu(void) { | |||
1208 | return RET_VAL_OK; | 1176 | return RET_VAL_OK; |
1209 | } | 1177 | } |
1210 | 1178 | ||
1211 | static int launch_nuke(int colour, int nukex, int nukey, int targetx, int targety) { | 1179 | static int launch_nuke(int colour, int nukex, int nukey, int targetx, int targety) |
1180 | { | ||
1212 | bool human = (colour == COLOUR_LIGHT); | 1181 | bool human = (colour == COLOUR_LIGHT); |
1213 | int temp; | 1182 | int temp; |
1214 | struct resources *res; | 1183 | struct resources *res; |
1215 | 1184 | ||
1216 | if(board[nukex][nukey].colour != colour) { | 1185 | if(board[nukex][nukey].colour != colour) |
1186 | { | ||
1217 | if(human) | 1187 | if(human) |
1218 | rb->splash(HZ, "That isn't your territory"); | 1188 | rb->splash(HZ, "That isn't your territory"); |
1219 | return RET_VAL_QUIT_ERR; | 1189 | return RET_VAL_QUIT_ERR; |
1220 | } | 1190 | } |
1221 | if(! board[nukex][nukey].nuke) { | 1191 | if(! board[nukex][nukey].nuke) |
1192 | { | ||
1222 | if(human) | 1193 | if(human) |
1223 | rb->splashf(HZ, "You don't have %s there", "a nuke"); | 1194 | rb->splashf(HZ, "You don't have a nuke there"); |
1224 | return RET_VAL_QUIT_ERR; | 1195 | return RET_VAL_QUIT_ERR; |
1225 | } | 1196 | } |
1226 | if(human) { | 1197 | if(human) |
1198 | { | ||
1227 | rb->splash(HZ, "Select place to target with nuke"); | 1199 | rb->splash(HZ, "Select place to target with nuke"); |
1228 | if((temp = select_square()) != RET_VAL_OK) | 1200 | if((temp = select_square()) != RET_VAL_OK) |
1229 | return temp; | 1201 | return temp; |
1230 | targetx = cursor.x; | 1202 | targetx = cursor.x; |
1231 | targety = cursor.y; | 1203 | targety = cursor.y; |
1232 | } | 1204 | } |
1233 | if(human) { | 1205 | if(human) |
1206 | { | ||
1234 | humanres.nukes--; | 1207 | humanres.nukes--; |
1235 | } else { | 1208 | } |
1209 | else | ||
1210 | { | ||
1236 | compres.nukes--; | 1211 | compres.nukes--; |
1237 | } | 1212 | } |
1238 | board[nukex][nukey].nuke = false; | 1213 | board[nukex][nukey].nuke = false; |
1239 | 1214 | ||
1240 | if(board[targetx][targety].colour == COLOUR_LIGHT) { | 1215 | if(board[targetx][targety].colour == COLOUR_LIGHT) |
1216 | { | ||
1241 | res = &humanres; | 1217 | res = &humanres; |
1242 | } else { | 1218 | } |
1219 | else | ||
1220 | { | ||
1243 | res = &compres; | 1221 | res = &compres; |
1244 | } | 1222 | } |
1245 | res->men -= board[targetx][targety].men; | 1223 | res->men -= board[targetx][targety].men; |
@@ -1259,40 +1237,55 @@ static int launch_nuke(int colour, int nukex, int nukey, int targetx, int target | |||
1259 | return RET_VAL_OK; | 1237 | return RET_VAL_OK; |
1260 | } | 1238 | } |
1261 | 1239 | ||
1262 | static int movement_menu(void) { | 1240 | static int movement_menu(void) |
1241 | { | ||
1263 | int selection = 0, temp; | 1242 | int selection = 0, temp; |
1264 | 1243 | ||
1265 | MENUITEM_STRINGLIST(menu, "Movement", NULL, | 1244 | MENUITEM_STRINGLIST(menu, "Movement", NULL, |
1266 | "Move unit", "Buy additional moves ($100)", | 1245 | "Move unit", "Buy additional moves ($" PRICE_MOVE_STR ")", |
1267 | "Launch nuclear missile", "Check map", | 1246 | "Launch nuclear missile", "Check map", |
1268 | "Finish moving", "Game menu"); | 1247 | "Finish moving", "Game menu"); |
1269 | 1248 | ||
1270 | while(1) { | 1249 | while(1) |
1271 | switch(rb->do_menu(&menu, &selection, NULL, false)) { | 1250 | { |
1251 | switch(rb->do_menu(&menu, &selection, NULL, false)) | ||
1252 | { | ||
1272 | case 0: | 1253 | case 0: |
1273 | if(humanres.moves) { | 1254 | if(humanres.moves) |
1255 | { | ||
1274 | if(move_unit_menu()==RET_VAL_USB) | 1256 | if(move_unit_menu()==RET_VAL_USB) |
1275 | return RET_VAL_USB; | 1257 | return RET_VAL_USB; |
1276 | } else { | 1258 | } |
1259 | else | ||
1260 | { | ||
1277 | rb->splash(HZ, "You have no more moves left." | 1261 | rb->splash(HZ, "You have no more moves left." |
1278 | " You can buy more for $100 each."); | 1262 | " You can buy more for $" PRICE_MOVE_STR " each."); |
1279 | } | 1263 | } |
1280 | break; | 1264 | break; |
1281 | case 1: | 1265 | case 1: |
1282 | if(humanres.cash > 100) { | 1266 | if(humanres.cash > PRICE_MOVE) |
1267 | { | ||
1283 | humanres.moves++; | 1268 | humanres.moves++; |
1284 | humanres.cash -= 100; | 1269 | humanres.cash -= PRICE_MOVE; |
1285 | rb->snprintf(buf, sizeof(buf), "You now have %d moves", | 1270 | rb->snprintf(buf, sizeof(buf), "You now have %d moves", |
1286 | humanres.moves); | 1271 | humanres.moves); |
1287 | rb->splash(HZ, buf); | 1272 | rb->splash(HZ, buf); |
1288 | } | 1273 | } |
1274 | else | ||
1275 | { | ||
1276 | rb->splash(HZ, "Not enough money!"); | ||
1277 | } | ||
1289 | break; | 1278 | break; |
1290 | case 2: | 1279 | case 2: |
1291 | if(humanres.nukes==0) { | 1280 | if(humanres.nukes==0) |
1281 | { | ||
1292 | rb->splash(HZ, "You do not have any nukes to launch"); | 1282 | rb->splash(HZ, "You do not have any nukes to launch"); |
1293 | } else { | 1283 | } |
1284 | else | ||
1285 | { | ||
1294 | rb->splash(HZ, "Select place to launch nuke from"); | 1286 | rb->splash(HZ, "Select place to launch nuke from"); |
1295 | switch(select_square()) { | 1287 | switch(select_square()) |
1288 | { | ||
1296 | case RET_VAL_OK: | 1289 | case RET_VAL_OK: |
1297 | if(launch_nuke(COLOUR_LIGHT, cursor.x, cursor.y, | 1290 | if(launch_nuke(COLOUR_LIGHT, cursor.x, cursor.y, |
1298 | 0, 0) == RET_VAL_USB) | 1291 | 0, 0) == RET_VAL_USB) |
@@ -1324,9 +1317,11 @@ static int movement_menu(void) { | |||
1324 | } | 1317 | } |
1325 | 1318 | ||
1326 | static const char* inventory_data(int selected_item, void * data, | 1319 | static const char* inventory_data(int selected_item, void * data, |
1327 | char * buffer, size_t buffer_len) { | 1320 | char * buffer, size_t buffer_len) |
1321 | { | ||
1328 | (void)data; | 1322 | (void)data; |
1329 | switch(selected_item) { | 1323 | switch(selected_item) |
1324 | { | ||
1330 | case 0: | 1325 | case 0: |
1331 | rb->snprintf(buffer,buffer_len,"Men: %d", humanres.men); | 1326 | rb->snprintf(buffer,buffer_len,"Men: %d", humanres.men); |
1332 | break; | 1327 | break; |
@@ -1360,19 +1355,24 @@ static const char* inventory_data(int selected_item, void * data, | |||
1360 | return buffer; | 1355 | return buffer; |
1361 | } | 1356 | } |
1362 | 1357 | ||
1363 | static int show_inventory(void) { | 1358 | static int show_inventory(void) |
1359 | { | ||
1364 | struct simplelist_info info; | 1360 | struct simplelist_info info; |
1365 | rb->simplelist_info_init(&info, "Inventory", 9, NULL); | 1361 | rb->simplelist_info_init(&info, "Inventory", 9, NULL); |
1366 | info.hide_selection = true; | 1362 | info.hide_selection = true; |
1367 | info.get_name = inventory_data; | 1363 | info.get_name = inventory_data; |
1368 | if(rb->simplelist_show_list(&info)) { | 1364 | if(rb->simplelist_show_list(&info)) |
1365 | { | ||
1369 | return RET_VAL_USB; | 1366 | return RET_VAL_USB; |
1370 | } else { | 1367 | } |
1368 | else | ||
1369 | { | ||
1371 | return RET_VAL_OK; | 1370 | return RET_VAL_OK; |
1372 | } | 1371 | } |
1373 | } | 1372 | } |
1374 | 1373 | ||
1375 | static int production_menu(void) { | 1374 | static int production_menu(void) |
1375 | { | ||
1376 | int selection = 0, temp; | 1376 | int selection = 0, temp; |
1377 | 1377 | ||
1378 | MENUITEM_STRINGLIST(menu, "Production", NULL, | 1378 | MENUITEM_STRINGLIST(menu, "Production", NULL, |
@@ -1380,8 +1380,10 @@ static int production_menu(void) { | |||
1380 | "Invest money", "Withdraw money", | 1380 | "Invest money", "Withdraw money", |
1381 | "Finish turn", "Game menu"); | 1381 | "Finish turn", "Game menu"); |
1382 | 1382 | ||
1383 | while(1) { | 1383 | while(1) |
1384 | switch(rb->do_menu(&menu, &selection, NULL, false)) { | 1384 | { |
1385 | switch(rb->do_menu(&menu, &selection, NULL, false)) | ||
1386 | { | ||
1385 | case 0: | 1387 | case 0: |
1386 | if(buy_resources_menu() == RET_VAL_USB) | 1388 | if(buy_resources_menu() == RET_VAL_USB) |
1387 | return RET_VAL_USB; | 1389 | return RET_VAL_USB; |
@@ -1399,9 +1401,12 @@ static int production_menu(void) { | |||
1399 | if(get_number("How much do you want to invest?", &temp, | 1401 | if(get_number("How much do you want to invest?", &temp, |
1400 | humanres.cash) == RET_VAL_USB) | 1402 | humanres.cash) == RET_VAL_USB) |
1401 | return RET_VAL_USB; | 1403 | return RET_VAL_USB; |
1402 | if(temp > humanres.cash) { | 1404 | if(temp > humanres.cash) |
1405 | { | ||
1403 | rb->splash(HZ, "You don't have that much cash to invest"); | 1406 | rb->splash(HZ, "You don't have that much cash to invest"); |
1404 | } else { | 1407 | } |
1408 | else | ||
1409 | { | ||
1405 | humanres.cash -= temp; | 1410 | humanres.cash -= temp; |
1406 | humanres.bank += temp; | 1411 | humanres.bank += temp; |
1407 | } | 1412 | } |
@@ -1411,9 +1416,12 @@ static int production_menu(void) { | |||
1411 | if(get_number("How much do you want to withdraw?", &temp, | 1416 | if(get_number("How much do you want to withdraw?", &temp, |
1412 | humanres.bank) == RET_VAL_USB) | 1417 | humanres.bank) == RET_VAL_USB) |
1413 | return RET_VAL_USB; | 1418 | return RET_VAL_USB; |
1414 | if(temp > humanres.bank) { | 1419 | if(temp > humanres.bank) |
1420 | { | ||
1415 | rb->splash(HZ, "You don't have that much cash to withdraw"); | 1421 | rb->splash(HZ, "You don't have that much cash to withdraw"); |
1416 | } else { | 1422 | } |
1423 | else | ||
1424 | { | ||
1417 | humanres.cash += temp; | 1425 | humanres.cash += temp; |
1418 | humanres.bank -= temp; | 1426 | humanres.bank -= temp; |
1419 | } | 1427 | } |
@@ -1433,7 +1441,8 @@ static int production_menu(void) { | |||
1433 | return RET_VAL_OK; | 1441 | return RET_VAL_OK; |
1434 | } | 1442 | } |
1435 | 1443 | ||
1436 | static void init_resources(void) { | 1444 | static void init_resources(void) |
1445 | { | ||
1437 | humanres.cash = superdom_settings.startcash; | 1446 | humanres.cash = superdom_settings.startcash; |
1438 | humanres.food = superdom_settings.startfood; | 1447 | humanres.food = superdom_settings.startfood; |
1439 | humanres.tanks = 0; | 1448 | humanres.tanks = 0; |
@@ -1456,7 +1465,8 @@ static void init_resources(void) { | |||
1456 | compres.moves = 0; | 1465 | compres.moves = 0; |
1457 | } | 1466 | } |
1458 | 1467 | ||
1459 | static int select_square(void) { | 1468 | static int select_square(void) |
1469 | { | ||
1460 | int button = 0; | 1470 | int button = 0; |
1461 | draw_board(); | 1471 | draw_board(); |
1462 | draw_cursor(); | 1472 | draw_cursor(); |
@@ -1468,9 +1478,11 @@ static int select_square(void) { | |||
1468 | rb->lcd_setfont(FONT_UI); | 1478 | rb->lcd_setfont(FONT_UI); |
1469 | #endif | 1479 | #endif |
1470 | rb->lcd_update(); | 1480 | rb->lcd_update(); |
1471 | while(1) { | 1481 | while(1) |
1472 | button = rb->button_get(true); | 1482 | { |
1473 | switch(button) { | 1483 | button=pluginlib_getaction(-1, plugin_contexts, ARRAYLEN(plugin_contexts)); |
1484 | switch(button) | ||
1485 | { | ||
1474 | case SUPERDOM_CANCEL: | 1486 | case SUPERDOM_CANCEL: |
1475 | rb->splash(HZ, "Cancelled"); | 1487 | rb->splash(HZ, "Cancelled"); |
1476 | return RET_VAL_QUIT_ERR; | 1488 | return RET_VAL_QUIT_ERR; |
@@ -1478,49 +1490,43 @@ static int select_square(void) { | |||
1478 | case SUPERDOM_OK: | 1490 | case SUPERDOM_OK: |
1479 | return RET_VAL_OK; | 1491 | return RET_VAL_OK; |
1480 | break; | 1492 | break; |
1481 | #if CONFIG_KEYPAD != IRIVER_H10_PAD | ||
1482 | case SUPERDOM_LEFT: | 1493 | case SUPERDOM_LEFT: |
1483 | case (SUPERDOM_LEFT|BUTTON_REPEAT): | 1494 | case SUPERDOM_LEFT_REPEAT: |
1484 | draw_cursor(); /* Deselect the current tile */ | 1495 | draw_cursor(); /* Deselect the current tile */ |
1485 | if(cursor.x>1) { | 1496 | if(cursor.x>1) |
1497 | { | ||
1486 | cursor.x--; | 1498 | cursor.x--; |
1487 | } else { | 1499 | } |
1488 | #ifdef IPOD_STYLE | 1500 | else |
1489 | if(cursor.y>1) | 1501 | { |
1490 | cursor.y--; | ||
1491 | else | ||
1492 | cursor.y = 10; | ||
1493 | #endif | ||
1494 | cursor.x = 10; | 1502 | cursor.x = 10; |
1495 | } | 1503 | } |
1496 | update_score(); | 1504 | update_score(); |
1497 | draw_cursor(); | 1505 | draw_cursor(); |
1498 | break; | 1506 | break; |
1499 | case SUPERDOM_RIGHT: | 1507 | case SUPERDOM_RIGHT: |
1500 | case (SUPERDOM_RIGHT|BUTTON_REPEAT): | 1508 | case SUPERDOM_RIGHT_REPEAT: |
1501 | draw_cursor(); /* Deselect the current tile */ | 1509 | draw_cursor(); /* Deselect the current tile */ |
1502 | if(cursor.x<10) { | 1510 | if(cursor.x<10) |
1511 | { | ||
1503 | cursor.x++; | 1512 | cursor.x++; |
1504 | } else { | 1513 | } |
1505 | #ifdef IPOD_STYLE | 1514 | else |
1506 | if(cursor.y<10) | 1515 | { |
1507 | cursor.y++; | ||
1508 | else | ||
1509 | cursor.y = 1; | ||
1510 | #endif | ||
1511 | cursor.x = 1; | 1516 | cursor.x = 1; |
1512 | } | 1517 | } |
1513 | update_score(); | 1518 | update_score(); |
1514 | draw_cursor(); | 1519 | draw_cursor(); |
1515 | break; | 1520 | break; |
1516 | #endif | ||
1517 | #ifndef IPOD_STYLE | ||
1518 | case SUPERDOM_UP: | 1521 | case SUPERDOM_UP: |
1519 | case (SUPERDOM_UP|BUTTON_REPEAT): | 1522 | case SUPERDOM_UP_REPEAT: |
1520 | draw_cursor(); /* Deselect the current tile */ | 1523 | draw_cursor(); /* Deselect the current tile */ |
1521 | if(cursor.y>1) { | 1524 | if(cursor.y>1) |
1525 | { | ||
1522 | cursor.y--; | 1526 | cursor.y--; |
1523 | } else { | 1527 | } |
1528 | else | ||
1529 | { | ||
1524 | #if CONFIG_KEYPAD == IRIVER_H10_PAD | 1530 | #if CONFIG_KEYPAD == IRIVER_H10_PAD |
1525 | if(cursor.x > 1) | 1531 | if(cursor.x > 1) |
1526 | cursor.x--; | 1532 | cursor.x--; |
@@ -1533,11 +1539,14 @@ static int select_square(void) { | |||
1533 | draw_cursor(); | 1539 | draw_cursor(); |
1534 | break; | 1540 | break; |
1535 | case SUPERDOM_DOWN: | 1541 | case SUPERDOM_DOWN: |
1536 | case (SUPERDOM_DOWN|BUTTON_REPEAT): | 1542 | case SUPERDOM_DOWN_REPEAT: |
1537 | draw_cursor(); /* Deselect the current tile */ | 1543 | draw_cursor(); /* Deselect the current tile */ |
1538 | if(cursor.y<10) { | 1544 | if(cursor.y<10) |
1545 | { | ||
1539 | cursor.y++; | 1546 | cursor.y++; |
1540 | } else { | 1547 | } |
1548 | else | ||
1549 | { | ||
1541 | #if CONFIG_KEYPAD == IRIVER_H10_PAD | 1550 | #if CONFIG_KEYPAD == IRIVER_H10_PAD |
1542 | if(cursor.x < 10) | 1551 | if(cursor.x < 10) |
1543 | cursor.x++; | 1552 | cursor.x++; |
@@ -1549,7 +1558,6 @@ static int select_square(void) { | |||
1549 | update_score(); | 1558 | update_score(); |
1550 | draw_cursor(); | 1559 | draw_cursor(); |
1551 | break; | 1560 | break; |
1552 | #endif | ||
1553 | default: | 1561 | default: |
1554 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | 1562 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) |
1555 | { | 1563 | { |
@@ -1559,21 +1567,28 @@ static int select_square(void) { | |||
1559 | } | 1567 | } |
1560 | } | 1568 | } |
1561 | 1569 | ||
1562 | static int killmen(int colour) { | 1570 | static int killmen(int colour) |
1571 | { | ||
1563 | bool human = (colour == COLOUR_LIGHT); | 1572 | bool human = (colour == COLOUR_LIGHT); |
1564 | int menkilled,i,j; | 1573 | int menkilled,i,j; |
1565 | int percent; | 1574 | int percent; |
1566 | if(human) { | 1575 | if(human) |
1576 | { | ||
1567 | percent = (humanres.food*1000)/humanres.men; | 1577 | percent = (humanres.food*1000)/humanres.men; |
1568 | humanres.food = 0; | 1578 | humanres.food = 0; |
1569 | } else { | 1579 | } |
1580 | else | ||
1581 | { | ||
1570 | percent = (compres.food*1000)/compres.men; | 1582 | percent = (compres.food*1000)/compres.men; |
1571 | compres.food = 0; | 1583 | compres.food = 0; |
1572 | } | 1584 | } |
1573 | menkilled = 0; | 1585 | menkilled = 0; |
1574 | for(i=1;i<11;i++) { | 1586 | for(i=1;i<11;i++) |
1575 | for(j=1;j<11;j++) { | 1587 | { |
1576 | if(board[i][j].colour == colour) { | 1588 | for(j=1;j<11;j++) |
1589 | { | ||
1590 | if(board[i][j].colour == colour) | ||
1591 | { | ||
1577 | int nummen = ((board[i][j].men * percent)/1000); | 1592 | int nummen = ((board[i][j].men * percent)/1000); |
1578 | menkilled += board[i][j].men - nummen; | 1593 | menkilled += board[i][j].men - nummen; |
1579 | board[i][j].men = nummen; | 1594 | board[i][j].men = nummen; |
@@ -1589,27 +1604,33 @@ static int killmen(int colour) { | |||
1589 | } | 1604 | } |
1590 | 1605 | ||
1591 | /* return -1 if error, 1 if attack is succeeded, 0 otherwise */ | 1606 | /* return -1 if error, 1 if attack is succeeded, 0 otherwise */ |
1592 | static int attack_territory(int colour, int x, int y) { | 1607 | static int attack_territory(int colour, int x, int y) |
1608 | { | ||
1593 | bool human = (colour == COLOUR_LIGHT); | 1609 | bool human = (colour == COLOUR_LIGHT); |
1594 | int str_diff; | 1610 | int str_diff; |
1595 | 1611 | ||
1596 | if(board[x][y].colour == colour) { | 1612 | if(board[x][y].colour == colour) |
1613 | { | ||
1597 | if(human) | 1614 | if(human) |
1598 | rb->splash(HZ, "You can't attack your own territory"); | 1615 | rb->splash(HZ, "You can't attack your own territory"); |
1599 | return -1; | 1616 | return -1; |
1600 | } | 1617 | } |
1601 | str_diff = calc_strength(COLOUR_DARK, x, y) - | 1618 | str_diff = calc_strength(COLOUR_DARK, x, y) - |
1602 | calc_strength(COLOUR_LIGHT, x, y); | 1619 | calc_strength(COLOUR_LIGHT, x, y); |
1603 | if(human) { | 1620 | if(human) |
1621 | { | ||
1604 | str_diff = -str_diff; | 1622 | str_diff = -str_diff; |
1605 | } | 1623 | } |
1606 | rb->srand(*rb->current_tick); | 1624 | if(str_diff > 0 || (str_diff == 0 && rb->rand()%2)) |
1607 | if(str_diff > 0 || (str_diff == 0 && rb->rand()%2)) { | 1625 | { |
1608 | struct resources *offres, *defres; | 1626 | struct resources *offres, *defres; |
1609 | if(human) { | 1627 | if(human) |
1628 | { | ||
1610 | offres = &humanres; | 1629 | offres = &humanres; |
1611 | defres = &compres; | 1630 | defres = &compres; |
1612 | } else { | 1631 | } |
1632 | else | ||
1633 | { | ||
1613 | offres = &compres; | 1634 | offres = &compres; |
1614 | defres = &humanres; | 1635 | defres = &humanres; |
1615 | } | 1636 | } |
@@ -1632,7 +1653,9 @@ static int attack_territory(int colour, int x, int y) { | |||
1632 | else | 1653 | else |
1633 | rb->sleep(HZ); | 1654 | rb->sleep(HZ); |
1634 | return 1; | 1655 | return 1; |
1635 | } else { | 1656 | } |
1657 | else | ||
1658 | { | ||
1636 | if(human) | 1659 | if(human) |
1637 | rb->splash(HZ, "Your troops were unable to overcome" | 1660 | rb->splash(HZ, "Your troops were unable to overcome" |
1638 | " the enemy troops"); | 1661 | " the enemy troops"); |
@@ -1645,20 +1668,23 @@ static int attack_territory(int colour, int x, int y) { | |||
1645 | return 0; | 1668 | return 0; |
1646 | } | 1669 | } |
1647 | 1670 | ||
1648 | static int war_menu(void) { | 1671 | static int war_menu(void) |
1672 | { | ||
1649 | int selection = 0, temp; | 1673 | int selection = 0, temp; |
1650 | 1674 | ||
1651 | MENUITEM_STRINGLIST(menu, "War!", NULL, | 1675 | MENUITEM_STRINGLIST(menu, "War!", NULL, |
1652 | "Select territory to attack", | 1676 | "Select territory to attack", |
1653 | "Finish turn", "Game menu"); | 1677 | "Finish turn", "Game menu"); |
1654 | 1678 | ||
1655 | while(humanres.moves) { | 1679 | while(humanres.moves) |
1656 | switch(rb->do_menu(&menu, &selection, NULL, false)) { | 1680 | { |
1681 | switch(rb->do_menu(&menu, &selection, NULL, false)) | ||
1682 | { | ||
1657 | case 0: | 1683 | case 0: |
1658 | switch(select_square()) { | 1684 | switch(select_square()) |
1685 | { | ||
1659 | case RET_VAL_OK: | 1686 | case RET_VAL_OK: |
1660 | if(attack_territory(COLOUR_LIGHT, cursor.x, cursor.y) | 1687 | if(attack_territory(COLOUR_LIGHT, cursor.x, cursor.y) >= 0) |
1661 | >= 0) | ||
1662 | humanres.moves--; | 1688 | humanres.moves--; |
1663 | break; | 1689 | break; |
1664 | case RET_VAL_USB: | 1690 | case RET_VAL_USB: |
@@ -1684,63 +1710,76 @@ struct threat { | |||
1684 | int str_diff; | 1710 | int str_diff; |
1685 | }; | 1711 | }; |
1686 | 1712 | ||
1687 | static bool place_adjacent(bool tank, int x, int y) { | 1713 | static bool place_adjacent(bool tank, int x, int y) |
1688 | int type = (tank? 1: 2); | 1714 | { |
1689 | if(!buy_resources(COLOUR_DARK, type, x, y, 0)) { | 1715 | int type = (tank ? 1: 2); |
1716 | if(!buy_resources(COLOUR_DARK, type, x, y, 0)) | ||
1717 | { | ||
1690 | return true; | 1718 | return true; |
1691 | } | 1719 | } |
1692 | if(!buy_resources(COLOUR_DARK, type, x-1, y, 0)) { | 1720 | if(!buy_resources(COLOUR_DARK, type, x-1, y, 0)) |
1721 | { | ||
1693 | return true; | 1722 | return true; |
1694 | } | 1723 | } |
1695 | if(!buy_resources(COLOUR_DARK, type, x+1, y, 0)) { | 1724 | if(!buy_resources(COLOUR_DARK, type, x+1, y, 0)) |
1725 | { | ||
1696 | return true; | 1726 | return true; |
1697 | } | 1727 | } |
1698 | if(!buy_resources(COLOUR_DARK, type, x, y-1, 0)) { | 1728 | if(!buy_resources(COLOUR_DARK, type, x, y-1, 0)) |
1729 | { | ||
1699 | return true; | 1730 | return true; |
1700 | } | 1731 | } |
1701 | if(!buy_resources(COLOUR_DARK, type, x, y+1, 0)) { | 1732 | if(!buy_resources(COLOUR_DARK, type, x, y+1, 0)) |
1733 | { | ||
1702 | return true; | 1734 | return true; |
1703 | } | 1735 | } |
1704 | return false; | 1736 | return false; |
1705 | } | 1737 | } |
1706 | 1738 | ||
1707 | static bool has_adjacent(int x, int y) { | 1739 | static bool has_adjacent(int x, int y) |
1708 | if((board[x][y].colour == COLOUR_LIGHT) && | 1740 | { |
1709 | ((board[x-1][y].colour == COLOUR_DARK) || | 1741 | if ((board[x][y].colour == COLOUR_LIGHT) && |
1710 | (board[x+1][y].colour == COLOUR_DARK) || | 1742 | ((board[x-1][y].colour == COLOUR_DARK) || |
1711 | (board[x][y+1].colour == COLOUR_DARK) || | 1743 | (board[x+1][y].colour == COLOUR_DARK) || |
1744 | (board[x][y+1].colour == COLOUR_DARK) || | ||
1712 | (board[x][y-1].colour == COLOUR_DARK))) | 1745 | (board[x][y-1].colour == COLOUR_DARK))) |
1713 | return 1; | 1746 | return 1; |
1714 | else | 1747 | else |
1715 | return 0; | 1748 | return 0; |
1716 | } | 1749 | } |
1717 | 1750 | ||
1718 | static void find_adjacent(int x, int y, int* adj_x, int* adj_y) { | 1751 | static void find_adjacent(int x, int y, int* adj_x, int* adj_y) |
1752 | { | ||
1719 | /* Finds adjacent squares, returning squares without tanks on them | 1753 | /* Finds adjacent squares, returning squares without tanks on them |
1720 | * in preference to those with them */ | 1754 | * in preference to those with them */ |
1721 | if(board[x-1][y].colour == COLOUR_DARK) { | 1755 | if(board[x-1][y].colour == COLOUR_DARK) |
1756 | { | ||
1722 | *adj_x = x-1; | 1757 | *adj_x = x-1; |
1723 | *adj_y = y; | 1758 | *adj_y = y; |
1724 | return; | 1759 | return; |
1725 | } | 1760 | } |
1726 | if(board[x+1][y].colour == COLOUR_DARK) { | 1761 | if(board[x+1][y].colour == COLOUR_DARK) |
1762 | { | ||
1727 | *adj_x = x+1; | 1763 | *adj_x = x+1; |
1728 | *adj_y = y; | 1764 | *adj_y = y; |
1729 | return; | 1765 | return; |
1730 | } | 1766 | } |
1731 | if(board[x][y-1].colour == COLOUR_DARK) { | 1767 | if(board[x][y-1].colour == COLOUR_DARK) |
1768 | { | ||
1732 | *adj_x = x; | 1769 | *adj_x = x; |
1733 | *adj_y = y-1; | 1770 | *adj_y = y-1; |
1734 | return; | 1771 | return; |
1735 | } | 1772 | } |
1736 | if(board[x][y+1].colour == COLOUR_DARK) { | 1773 | if(board[x][y+1].colour == COLOUR_DARK) |
1774 | { | ||
1737 | *adj_x = x; | 1775 | *adj_x = x; |
1738 | *adj_y = y+1; | 1776 | *adj_y = y+1; |
1739 | return; | 1777 | return; |
1740 | } | 1778 | } |
1741 | } | 1779 | } |
1742 | 1780 | ||
1743 | static void computer_allocate(void) { | 1781 | static void computer_allocate(void) |
1782 | { | ||
1744 | /* Firstly, decide whether to go offensive or defensive. | 1783 | /* Firstly, decide whether to go offensive or defensive. |
1745 | * This is primarily decided by the human player posing a threat to either | 1784 | * This is primarily decided by the human player posing a threat to either |
1746 | * the computer's farms or factories */ | 1785 | * the computer's farms or factories */ |
@@ -1758,14 +1797,19 @@ static void computer_allocate(void) { | |||
1758 | 1797 | ||
1759 | compres.cash += compres.bank; | 1798 | compres.cash += compres.bank; |
1760 | compres.bank = 0; | 1799 | compres.bank = 0; |
1761 | for(i=1;i<11;i++) { | 1800 | for(i=1;i<11;i++) |
1762 | for(j=1;j<11;j++) { | 1801 | { |
1763 | if(board[i][j].colour == COLOUR_DARK) { | 1802 | for(j=1;j<11;j++) |
1803 | { | ||
1804 | if(board[i][j].colour == COLOUR_DARK) | ||
1805 | { | ||
1764 | numterritory++; | 1806 | numterritory++; |
1765 | str_diff = calc_strength(COLOUR_LIGHT,i,j) - | 1807 | str_diff = calc_strength(COLOUR_LIGHT,i,j) - |
1766 | calc_strength(COLOUR_DARK,i,j); | 1808 | calc_strength(COLOUR_DARK,i,j); |
1767 | if(str_diff > 0 && (board[i][j].ind || board[i][j].farm)) { | 1809 | if(str_diff > 0 && (board[i][j].ind || board[i][j].farm)) |
1768 | if(numthreats < 3) { | 1810 | { |
1811 | if(numthreats < 3) | ||
1812 | { | ||
1769 | offensive = false; | 1813 | offensive = false; |
1770 | threats[numthreats].x = i; | 1814 | threats[numthreats].x = i; |
1771 | threats[numthreats].y = j; | 1815 | threats[numthreats].y = j; |
@@ -1777,25 +1821,33 @@ static void computer_allocate(void) { | |||
1777 | rb->yield(); | 1821 | rb->yield(); |
1778 | } | 1822 | } |
1779 | } | 1823 | } |
1780 | if(offensive) { | 1824 | if(offensive) |
1825 | { | ||
1781 | /* The AI is going to go straight for the throat here and attack | 1826 | /* The AI is going to go straight for the throat here and attack |
1782 | * the player's farms and factories. The amount of cash | 1827 | * the player's farms and factories. The amount of cash |
1783 | * the AI has to spend will determine how many targets there are */ | 1828 | * the AI has to spend will determine how many targets there are */ |
1784 | if(compres.cash > 1200) { | 1829 | if(compres.cash > 1200) |
1830 | { | ||
1785 | /* 1200 is a figure I pulled out of nowhere. Adjust as needed */ | 1831 | /* 1200 is a figure I pulled out of nowhere. Adjust as needed */ |
1786 | numtargets = 2; | 1832 | numtargets = 2; |
1787 | } else { | 1833 | } |
1834 | else | ||
1835 | { | ||
1788 | numtargets = 1; | 1836 | numtargets = 1; |
1789 | } | 1837 | } |
1790 | /* Work out which target(s) to attack. They must have adjacent squares | 1838 | /* Work out which target(s) to attack. They must have adjacent squares |
1791 | * owned by the computer. If none are found just place troops in | 1839 | * owned by the computer. If none are found just place troops in |
1792 | * random places around the map until we run out of money */ | 1840 | * random places around the map until we run out of money */ |
1793 | k = 0; | 1841 | k = 0; |
1794 | for(i=1;i<11;i++) { | 1842 | for(i=1;i<11;i++) |
1795 | for(j=1;j<11;j++) { | 1843 | { |
1844 | for(j=1;j<11;j++) | ||
1845 | { | ||
1796 | if(has_adjacent(i,j) && | 1846 | if(has_adjacent(i,j) && |
1797 | (board[i][j].ind || board[i][j].farm)) { | 1847 | (board[i][j].ind || board[i][j].farm)) |
1798 | if(k<numtargets) { | 1848 | { |
1849 | if(k<numtargets) | ||
1850 | { | ||
1799 | targets[k].x = i; | 1851 | targets[k].x = i; |
1800 | targets[k].y = j; | 1852 | targets[k].y = j; |
1801 | targets[k].str_diff = | 1853 | targets[k].str_diff = |
@@ -1807,10 +1859,10 @@ static void computer_allocate(void) { | |||
1807 | rb->yield(); | 1859 | rb->yield(); |
1808 | } | 1860 | } |
1809 | } | 1861 | } |
1810 | if(k == 0) { | 1862 | if(k == 0) |
1863 | { | ||
1811 | /* No targets found! Randomly pick squares and if they're owned | 1864 | /* No targets found! Randomly pick squares and if they're owned |
1812 | * by the computer then stick a tank on it. */ | 1865 | * by the computer then stick a tank on it. */ |
1813 | rb->srand(*rb->current_tick); | ||
1814 | while(compres.cash >= 300 && compres.tanks < numterritory) { | 1866 | while(compres.cash >= 300 && compres.tanks < numterritory) { |
1815 | i = rb->rand()%10 + 1; | 1867 | i = rb->rand()%10 + 1; |
1816 | j = rb->rand()%10 + 1; | 1868 | j = rb->rand()%10 + 1; |
@@ -1819,16 +1871,22 @@ static void computer_allocate(void) { | |||
1819 | } | 1871 | } |
1820 | rb->yield(); | 1872 | rb->yield(); |
1821 | } | 1873 | } |
1822 | } else { | 1874 | } |
1823 | for(i=0;i<k;i++) { | 1875 | else |
1876 | { | ||
1877 | for(i=0;i<k;i++) | ||
1878 | { | ||
1824 | str_diff = targets[i].str_diff; | 1879 | str_diff = targets[i].str_diff; |
1825 | while(str_diff + 20 > 0 && compres.cash > 0) { | 1880 | while(str_diff + 20 > 0 && compres.cash > 0) |
1881 | { | ||
1826 | /* While we still need them keep placing men */ | 1882 | /* While we still need them keep placing men */ |
1827 | if(!place_adjacent(true, targets[i].x, targets[i].y)) { | 1883 | if(!place_adjacent(true, targets[i].x, targets[i].y)) |
1884 | { | ||
1828 | find_adjacent(targets[i].x, targets[i].y, | 1885 | find_adjacent(targets[i].x, targets[i].y, |
1829 | &adj.x, &adj.y); | 1886 | &adj.x, &adj.y); |
1830 | men_needed = (str_diff + 20)*1000/133; | 1887 | men_needed = (str_diff + 20)*1000/133; |
1831 | if(compres.cash < men_needed) { | 1888 | if(compres.cash < men_needed) |
1889 | { | ||
1832 | men_needed = compres.cash; | 1890 | men_needed = compres.cash; |
1833 | } | 1891 | } |
1834 | buy_resources(COLOUR_DARK, 0, adj.x, adj.y, | 1892 | buy_resources(COLOUR_DARK, 0, adj.x, adj.y, |
@@ -1842,7 +1900,9 @@ static void computer_allocate(void) { | |||
1842 | } | 1900 | } |
1843 | } | 1901 | } |
1844 | } | 1902 | } |
1845 | } else { | 1903 | } |
1904 | else | ||
1905 | { | ||
1846 | /* Work out what to place on each square to defend it. | 1906 | /* Work out what to place on each square to defend it. |
1847 | * Tanks are preferential because they do not require food, | 1907 | * Tanks are preferential because they do not require food, |
1848 | * but if the budget is tight then we fall back onto troops. | 1908 | * but if the budget is tight then we fall back onto troops. |
@@ -1850,34 +1910,44 @@ static void computer_allocate(void) { | |||
1850 | * place planes will be deployed. We would like a margin of at least | 1910 | * place planes will be deployed. We would like a margin of at least |
1851 | * 20 points to be safe. */ | 1911 | * 20 points to be safe. */ |
1852 | 1912 | ||
1853 | for(i=0;i<numthreats;i++) { | 1913 | for(i=0;i<numthreats;i++) |
1914 | { | ||
1854 | total_str_diff += threats[i].str_diff; | 1915 | total_str_diff += threats[i].str_diff; |
1855 | } | 1916 | } |
1856 | if((total_str_diff+20)*10 > compres.cash) { | 1917 | if((total_str_diff+20)*10 > compres.cash) |
1918 | { | ||
1857 | /* Not enough cash to accomodate all threats using tanks alone - | 1919 | /* Not enough cash to accomodate all threats using tanks alone - |
1858 | * use men as a backup */ | 1920 | * use men as a backup */ |
1859 | for(i=0;i<numthreats;i++) { | 1921 | for(i=0;i<numthreats;i++) |
1922 | { | ||
1860 | men_needed = ((threats[i].str_diff + 20)*1000)/133; | 1923 | men_needed = ((threats[i].str_diff + 20)*1000)/133; |
1861 | if(compres.cash < men_needed) { | 1924 | if(compres.cash < men_needed) |
1925 | { | ||
1862 | men_needed = compres.cash; | 1926 | men_needed = compres.cash; |
1863 | } | 1927 | } |
1864 | buy_resources(COLOUR_DARK, 0, threats[i].x, threats[i].y, | 1928 | buy_resources(COLOUR_DARK, 0, threats[i].x, threats[i].y, |
1865 | men_needed); | 1929 | men_needed); |
1866 | } | 1930 | } |
1867 | } else { | 1931 | } |
1932 | else | ||
1933 | { | ||
1868 | /* Tanks it is */ | 1934 | /* Tanks it is */ |
1869 | /* Enough money to pay their way by planes? */ | 1935 | /* Enough money to pay their way by planes? */ |
1870 | bool tank = ((total_str_diff+20)*15 >= compres.cash); | 1936 | bool tank = ((total_str_diff+20)*15 >= compres.cash); |
1871 | for(i=0;i<numthreats;i++) { | 1937 | for(i=0;i<numthreats;i++) |
1938 | { | ||
1872 | str_diff = threats[i].str_diff; | 1939 | str_diff = threats[i].str_diff; |
1873 | while(str_diff + 20 > 0) { | 1940 | while(str_diff + 20 > 0) |
1874 | if(!place_adjacent(tank, threats[i].x, threats[i].y)) { | 1941 | { |
1942 | if(!place_adjacent(tank, threats[i].x, threats[i].y)) | ||
1943 | { | ||
1875 | /* No room for any more planes or tanks, revert to | 1944 | /* No room for any more planes or tanks, revert to |
1876 | * men */ | 1945 | * men */ |
1877 | find_adjacent(threats[i].x, threats[i].y, | 1946 | find_adjacent(threats[i].x, threats[i].y, |
1878 | &adj.x, &adj.y); | 1947 | &adj.x, &adj.y); |
1879 | men_needed = (str_diff + 20)*1000/133; | 1948 | men_needed = (str_diff + 20)*1000/133; |
1880 | if(compres.cash < men_needed) { | 1949 | if(compres.cash < men_needed) |
1950 | { | ||
1881 | men_needed = compres.cash; | 1951 | men_needed = compres.cash; |
1882 | } | 1952 | } |
1883 | buy_resources(COLOUR_DARK, 0, threats[i].x, | 1953 | buy_resources(COLOUR_DARK, 0, threats[i].x, |
@@ -1896,29 +1966,34 @@ static void computer_allocate(void) { | |||
1896 | compres.cash = 0; | 1966 | compres.cash = 0; |
1897 | } | 1967 | } |
1898 | 1968 | ||
1899 | static int find_adj_target(int x, int y, struct cursor* adj) { | 1969 | static int find_adj_target(int x, int y, struct cursor* adj) |
1970 | { | ||
1900 | /* Find a square next to a computer's farm or factory owned by the player | 1971 | /* Find a square next to a computer's farm or factory owned by the player |
1901 | * that is vulnerable. Return 1 on success, 0 otherwise */ | 1972 | * that is vulnerable. Return 1 on success, 0 otherwise */ |
1902 | if(board[x+1][y].colour == COLOUR_LIGHT && | 1973 | if(board[x+1][y].colour == COLOUR_LIGHT && |
1903 | calc_strength(COLOUR_LIGHT,x+1,y)<=calc_strength(COLOUR_DARK,x+1,y)) { | 1974 | calc_strength(COLOUR_LIGHT,x+1,y)<=calc_strength(COLOUR_DARK,x+1,y)) |
1975 | { | ||
1904 | adj->x = x+1; | 1976 | adj->x = x+1; |
1905 | adj->y = y; | 1977 | adj->y = y; |
1906 | return 1; | 1978 | return 1; |
1907 | } | 1979 | } |
1908 | if(board[x-1][y].colour == COLOUR_LIGHT && | 1980 | if(board[x-1][y].colour == COLOUR_LIGHT && |
1909 | calc_strength(COLOUR_LIGHT,x-1,y)<=calc_strength(COLOUR_DARK,x-1,y)) { | 1981 | calc_strength(COLOUR_LIGHT,x-1,y)<=calc_strength(COLOUR_DARK,x-1,y)) |
1982 | { | ||
1910 | adj->x = x-1; | 1983 | adj->x = x-1; |
1911 | adj->y = y; | 1984 | adj->y = y; |
1912 | return 1; | 1985 | return 1; |
1913 | } | 1986 | } |
1914 | if(board[x][y+1].colour == COLOUR_LIGHT && | 1987 | if(board[x][y+1].colour == COLOUR_LIGHT && |
1915 | calc_strength(COLOUR_LIGHT,x,y+1)<=calc_strength(COLOUR_DARK,x,y+1)) { | 1988 | calc_strength(COLOUR_LIGHT,x,y+1)<=calc_strength(COLOUR_DARK,x,y+1)) |
1989 | { | ||
1916 | adj->x = x; | 1990 | adj->x = x; |
1917 | adj->y = y+1; | 1991 | adj->y = y+1; |
1918 | return 1; | 1992 | return 1; |
1919 | } | 1993 | } |
1920 | if(board[x][y-1].colour == COLOUR_LIGHT && | 1994 | if(board[x][y-1].colour == COLOUR_LIGHT && |
1921 | calc_strength(COLOUR_LIGHT,x,y-1)<=calc_strength(COLOUR_DARK,x,y-1)) { | 1995 | calc_strength(COLOUR_LIGHT,x,y-1)<=calc_strength(COLOUR_DARK,x,y-1)) |
1996 | { | ||
1922 | adj->x = x; | 1997 | adj->x = x; |
1923 | adj->y = y-1; | 1998 | adj->y = y-1; |
1924 | return 1; | 1999 | return 1; |
@@ -1926,21 +2001,27 @@ static int find_adj_target(int x, int y, struct cursor* adj) { | |||
1926 | return 0; | 2001 | return 0; |
1927 | } | 2002 | } |
1928 | 2003 | ||
1929 | static void computer_war(void) { | 2004 | static void computer_war(void) |
2005 | { | ||
1930 | /* Work out where to attack - prioritise the defence of buildings */ | 2006 | /* Work out where to attack - prioritise the defence of buildings */ |
1931 | int i, j; | 2007 | int i, j; |
1932 | bool found_target = true; | 2008 | bool found_target = true; |
1933 | struct cursor adj; | 2009 | struct cursor adj; |
1934 | 2010 | ||
1935 | while(found_target) { | 2011 | while(found_target) |
2012 | { | ||
1936 | found_target = false; | 2013 | found_target = false; |
1937 | for(i=1;i<11;i++) { | 2014 | for(i=1;i<11;i++) |
1938 | for(j=1;j<11;j++) { | 2015 | { |
1939 | if((board[i][j].colour == COLOUR_DARK) && | 2016 | for(j=1;j<11;j++) |
2017 | { | ||
2018 | if((board[i][j].colour == COLOUR_DARK) && | ||
1940 | (board[i][j].farm || board[i][j].ind) && | 2019 | (board[i][j].farm || board[i][j].ind) && |
1941 | find_adj_target(i, j, &adj)) { | 2020 | find_adj_target(i, j, &adj)) |
2021 | { | ||
1942 | found_target = true; | 2022 | found_target = true; |
1943 | if(attack_territory(COLOUR_DARK, adj.x, adj.y) >= 0) { | 2023 | if(attack_territory(COLOUR_DARK, adj.x, adj.y) >= 0) |
2024 | { | ||
1944 | compres.moves--; | 2025 | compres.moves--; |
1945 | if(!compres.moves) | 2026 | if(!compres.moves) |
1946 | return; | 2027 | return; |
@@ -1952,16 +2033,20 @@ static void computer_war(void) { | |||
1952 | } | 2033 | } |
1953 | /* Defence stage done, move on to OFFENCE */ | 2034 | /* Defence stage done, move on to OFFENCE */ |
1954 | found_target = true; | 2035 | found_target = true; |
1955 | while(found_target) { | 2036 | while(found_target) |
2037 | { | ||
1956 | found_target = false; | 2038 | found_target = false; |
1957 | for(i=1;i<11;i++) { | 2039 | for(i=1;i<11;i++) |
1958 | for(j=1;j<11;j++) { | 2040 | { |
1959 | if(board[i][j].colour == COLOUR_LIGHT && | 2041 | for(j=1;j<11;j++) |
2042 | { | ||
2043 | if(board[i][j].colour == COLOUR_LIGHT && | ||
1960 | (board[i][j].ind || board[i][j].farm) && | 2044 | (board[i][j].ind || board[i][j].farm) && |
1961 | (calc_strength(COLOUR_DARK, i, j) >= | 2045 | (calc_strength(COLOUR_DARK, i, j) >= calc_strength(COLOUR_LIGHT, i, j))) |
1962 | calc_strength(COLOUR_LIGHT, i, j))) { | 2046 | { |
1963 | found_target = true; | 2047 | found_target = true; |
1964 | if(attack_territory(COLOUR_DARK, i, j) >= 0) { | 2048 | if(attack_territory(COLOUR_DARK, i, j) >= 0) |
2049 | { | ||
1965 | compres.moves--; | 2050 | compres.moves--; |
1966 | if(!compres.moves) | 2051 | if(!compres.moves) |
1967 | return; | 2052 | return; |
@@ -1973,15 +2058,20 @@ static void computer_war(void) { | |||
1973 | } | 2058 | } |
1974 | /* Spend leftover moves wherever attacking randomly */ | 2059 | /* Spend leftover moves wherever attacking randomly */ |
1975 | found_target = true; | 2060 | found_target = true; |
1976 | while(found_target) { | 2061 | while(found_target) |
2062 | { | ||
1977 | found_target = false; | 2063 | found_target = false; |
1978 | for(i=1;i<11;i++) { | 2064 | for(i=1;i<11;i++) |
1979 | for(j=1;j<11;j++) { | 2065 | { |
2066 | for(j=1;j<11;j++) | ||
2067 | { | ||
1980 | if(board[i][j].colour == COLOUR_LIGHT && | 2068 | if(board[i][j].colour == COLOUR_LIGHT && |
1981 | (calc_strength(COLOUR_DARK, i, j) >= | 2069 | (calc_strength(COLOUR_DARK, i, j) >= |
1982 | calc_strength(COLOUR_LIGHT, i, j))) { | 2070 | calc_strength(COLOUR_LIGHT, i, j))) |
2071 | { | ||
1983 | found_target = true; | 2072 | found_target = true; |
1984 | if(attack_territory(COLOUR_DARK, i, j) >= 0) { | 2073 | if(attack_territory(COLOUR_DARK, i, j) >= 0) |
2074 | { | ||
1985 | compres.moves--; | 2075 | compres.moves--; |
1986 | if(!compres.moves) | 2076 | if(!compres.moves) |
1987 | return; | 2077 | return; |
@@ -1993,16 +2083,19 @@ static void computer_war(void) { | |||
1993 | } | 2083 | } |
1994 | } | 2084 | } |
1995 | 2085 | ||
1996 | static int load_game(const char* file) { | 2086 | static int load_game(const char* file) |
2087 | { | ||
1997 | int fd; | 2088 | int fd; |
1998 | 2089 | ||
1999 | fd = rb->open(file, O_RDONLY); | 2090 | fd = rb->open(file, O_RDONLY); |
2000 | if(fd < 0) { | 2091 | if(fd < 0) |
2092 | { | ||
2001 | DEBUGF("Couldn't open savegame\n"); | 2093 | DEBUGF("Couldn't open savegame\n"); |
2002 | return -1; | 2094 | return -1; |
2003 | } | 2095 | } |
2004 | rb->read(fd, buf, 5); | 2096 | rb->read(fd, buf, 5); |
2005 | if(rb->strcmp(buf, "SSGv3")) { | 2097 | if(rb->strcmp(buf, "SSGv3")) |
2098 | { | ||
2006 | rb->splash(HZ, "Invalid/incompatible savegame"); | 2099 | rb->splash(HZ, "Invalid/incompatible savegame"); |
2007 | return -1; | 2100 | return -1; |
2008 | } | 2101 | } |
@@ -2039,7 +2132,8 @@ static int load_game(const char* file) { | |||
2039 | return 0; | 2132 | return 0; |
2040 | } | 2133 | } |
2041 | 2134 | ||
2042 | static void default_settings(void) { | 2135 | static void default_settings(void) |
2136 | { | ||
2043 | superdom_settings.compstartfarms = 1; | 2137 | superdom_settings.compstartfarms = 1; |
2044 | superdom_settings.compstartinds = 1; | 2138 | superdom_settings.compstartinds = 1; |
2045 | superdom_settings.humanstartfarms = 2; | 2139 | superdom_settings.humanstartfarms = 2; |
@@ -2049,14 +2143,18 @@ static void default_settings(void) { | |||
2049 | superdom_settings.movesperturn = 2; | 2143 | superdom_settings.movesperturn = 2; |
2050 | } | 2144 | } |
2051 | 2145 | ||
2052 | static int average_strength(int colour) { | 2146 | static int average_strength(int colour) |
2147 | { | ||
2053 | /* This function calculates the average strength of the given player, | 2148 | /* This function calculates the average strength of the given player, |
2054 | * used to determine when the computer wins or loses. */ | 2149 | * used to determine when the computer wins or loses. */ |
2055 | int i,j; | 2150 | int i,j; |
2056 | int totalpower = 0; | 2151 | int totalpower = 0; |
2057 | for(i=1;i<11;i++) { | 2152 | for(i=1;i<11;i++) |
2058 | for(j=1;j<11;j++) { | 2153 | { |
2059 | if(board[i][j].colour != -1) { | 2154 | for(j=1;j<11;j++) |
2155 | { | ||
2156 | if(board[i][j].colour != -1) | ||
2157 | { | ||
2060 | totalpower += calc_strength(colour, i, j); | 2158 | totalpower += calc_strength(colour, i, j); |
2061 | } | 2159 | } |
2062 | } | 2160 | } |
@@ -2066,6 +2164,7 @@ static int average_strength(int colour) { | |||
2066 | 2164 | ||
2067 | enum plugin_status plugin_start(const void* parameter) | 2165 | enum plugin_status plugin_start(const void* parameter) |
2068 | { | 2166 | { |
2167 | rb->srand(*rb->current_tick); | ||
2069 | #if LCD_DEPTH > 1 | 2168 | #if LCD_DEPTH > 1 |
2070 | rb->lcd_set_backdrop(NULL); | 2169 | rb->lcd_set_backdrop(NULL); |
2071 | rb->lcd_set_foreground(LCD_BLACK); | 2170 | rb->lcd_set_foreground(LCD_BLACK); |
@@ -2075,11 +2174,16 @@ enum plugin_status plugin_start(const void* parameter) | |||
2075 | cursor.x = 1; | 2174 | cursor.x = 1; |
2076 | cursor.y = 1; | 2175 | cursor.y = 1; |
2077 | default_settings(); | 2176 | default_settings(); |
2078 | if(parameter) { | 2177 | if(parameter) |
2079 | if(load_game(parameter) != 0) { | 2178 | { |
2179 | if(load_game(parameter) != 0) | ||
2180 | { | ||
2080 | DEBUGF("Loading failed, generating new game\n"); | 2181 | DEBUGF("Loading failed, generating new game\n"); |
2081 | } else { | 2182 | } |
2082 | switch(gamestate) { | 2183 | else |
2184 | { | ||
2185 | switch(gamestate) | ||
2186 | { | ||
2083 | case GS_PROD: | 2187 | case GS_PROD: |
2084 | goto startprod; | 2188 | goto startprod; |
2085 | break; | 2189 | break; |
@@ -2096,7 +2200,8 @@ enum plugin_status plugin_start(const void* parameter) | |||
2096 | } | 2200 | } |
2097 | } | 2201 | } |
2098 | 2202 | ||
2099 | switch(start_menu()) { | 2203 | switch(start_menu()) |
2204 | { | ||
2100 | case RET_VAL_OK: /* start playing */ | 2205 | case RET_VAL_OK: /* start playing */ |
2101 | break; | 2206 | break; |
2102 | case RET_VAL_QUIT_ERR: /* quit */ | 2207 | case RET_VAL_QUIT_ERR: /* quit */ |
@@ -2111,14 +2216,17 @@ enum plugin_status plugin_start(const void* parameter) | |||
2111 | init_board(); | 2216 | init_board(); |
2112 | gen_resources(); | 2217 | gen_resources(); |
2113 | startyear: | 2218 | startyear: |
2114 | while(1) { | 2219 | while(1) |
2220 | { | ||
2115 | int avg_str_diff = (average_strength(COLOUR_LIGHT) - | 2221 | int avg_str_diff = (average_strength(COLOUR_LIGHT) - |
2116 | average_strength(COLOUR_DARK)); | 2222 | average_strength(COLOUR_DARK)); |
2117 | if(avg_str_diff > 15) { | 2223 | if(avg_str_diff > 15) |
2224 | { | ||
2118 | rb->splash(HZ*4, "The computer has surrendered. You win."); | 2225 | rb->splash(HZ*4, "The computer has surrendered. You win."); |
2119 | return PLUGIN_OK; | 2226 | return PLUGIN_OK; |
2120 | } | 2227 | } |
2121 | if(-avg_str_diff > 15) { | 2228 | if(-avg_str_diff > 15) |
2229 | { | ||
2122 | rb->splash(HZ*4, "Your army have suffered terrible morale from" | 2230 | rb->splash(HZ*4, "Your army have suffered terrible morale from" |
2123 | " the bleak prospects of winning. You lose."); | 2231 | " the bleak prospects of winning. You lose."); |
2124 | return PLUGIN_OK; | 2232 | return PLUGIN_OK; |
@@ -2127,7 +2235,8 @@ startyear: | |||
2127 | /* production */ | 2235 | /* production */ |
2128 | startprod: | 2236 | startprod: |
2129 | gamestate = GS_PROD; | 2237 | gamestate = GS_PROD; |
2130 | switch(production_menu()) { | 2238 | switch(production_menu()) |
2239 | { | ||
2131 | case RET_VAL_USB: | 2240 | case RET_VAL_USB: |
2132 | return PLUGIN_USB_CONNECTED; | 2241 | return PLUGIN_USB_CONNECTED; |
2133 | break; | 2242 | break; |
@@ -2141,7 +2250,8 @@ startyear: | |||
2141 | humanres.moves = superdom_settings.movesperturn; | 2250 | humanres.moves = superdom_settings.movesperturn; |
2142 | startmove: | 2251 | startmove: |
2143 | gamestate = GS_MOVE; | 2252 | gamestate = GS_MOVE; |
2144 | switch(movement_menu()) { | 2253 | switch(movement_menu()) |
2254 | { | ||
2145 | case RET_VAL_USB: | 2255 | case RET_VAL_USB: |
2146 | return PLUGIN_USB_CONNECTED; | 2256 | return PLUGIN_USB_CONNECTED; |
2147 | break; | 2257 | break; |
@@ -2150,22 +2260,30 @@ startyear: | |||
2150 | break; | 2260 | break; |
2151 | } | 2261 | } |
2152 | /* feed men */ | 2262 | /* feed men */ |
2153 | if(humanres.men) { | 2263 | if(humanres.men) |
2154 | if(humanres.food > humanres.men) { | 2264 | { |
2265 | if(humanres.food > humanres.men) | ||
2266 | { | ||
2155 | rb->snprintf(buf, sizeof(buf), "Your men ate %d units of food", | 2267 | rb->snprintf(buf, sizeof(buf), "Your men ate %d units of food", |
2156 | humanres.men); | 2268 | humanres.men); |
2157 | humanres.food -= humanres.men; | 2269 | humanres.food -= humanres.men; |
2158 | } else { | 2270 | } |
2271 | else | ||
2272 | { | ||
2159 | rb->snprintf(buf, sizeof(buf), "There was not enough food" | 2273 | rb->snprintf(buf, sizeof(buf), "There was not enough food" |
2160 | " to feed all your men, %d men have died of starvation", | 2274 | " to feed all your men, %d men have died of starvation", |
2161 | killmen(COLOUR_LIGHT)); | 2275 | killmen(COLOUR_LIGHT)); |
2162 | } | 2276 | } |
2163 | rb->splash(HZ*2, buf); | 2277 | rb->splash(HZ*2, buf); |
2164 | } | 2278 | } |
2165 | if(compres.men) { | 2279 | if(compres.men) |
2166 | if(compres.food > compres.men) { | 2280 | { |
2281 | if(compres.food > compres.men) | ||
2282 | { | ||
2167 | compres.food -= compres.men; | 2283 | compres.food -= compres.men; |
2168 | } else { | 2284 | } |
2285 | else | ||
2286 | { | ||
2169 | rb->snprintf(buf, sizeof(buf), "The computer does not have" | 2287 | rb->snprintf(buf, sizeof(buf), "The computer does not have" |
2170 | " enough food to feed its men. %d have died of starvation", | 2288 | " enough food to feed its men. %d have died of starvation", |
2171 | killmen(COLOUR_DARK)); | 2289 | killmen(COLOUR_DARK)); |
@@ -2176,7 +2294,8 @@ startyear: | |||
2176 | humanres.moves = superdom_settings.movesperturn; | 2294 | humanres.moves = superdom_settings.movesperturn; |
2177 | startwar: | 2295 | startwar: |
2178 | gamestate = GS_WAR; | 2296 | gamestate = GS_WAR; |
2179 | switch(war_menu()) { | 2297 | switch(war_menu()) |
2298 | { | ||
2180 | case RET_VAL_USB: | 2299 | case RET_VAL_USB: |
2181 | return PLUGIN_USB_CONNECTED; | 2300 | return PLUGIN_USB_CONNECTED; |
2182 | break; | 2301 | break; |