diff options
-rw-r--r-- | apps/plugins/superdom.c | 310 |
1 files changed, 212 insertions, 98 deletions
diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index 91747edb80..3cbc5f285d 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c | |||
@@ -33,9 +33,55 @@ | |||
33 | 33 | ||
34 | char buf[255]; | 34 | char buf[255]; |
35 | 35 | ||
36 | /* key mappings */ | ||
37 | |||
38 | #define SUPERDOM_OK PLA_SELECT | ||
39 | #define SUPERDOM_CANCEL PLA_CANCEL | ||
40 | #define SUPERDOM_RIGHT PLA_RIGHT | ||
41 | #define SUPERDOM_LEFT PLA_LEFT | ||
42 | #define SUPERDOM_UP PLA_UP | ||
43 | #define SUPERDOM_DOWN PLA_DOWN | ||
44 | |||
45 | #define SUPERDOM_RIGHT_REPEAT PLA_RIGHT_REPEAT | ||
46 | #define SUPERDOM_LEFT_REPEAT PLA_LEFT_REPEAT | ||
47 | #define SUPERDOM_UP_REPEAT PLA_UP_REPEAT | ||
48 | #define SUPERDOM_DOWN_REPEAT PLA_DOWN_REPEAT | ||
49 | |||
50 | /***** game settings *****/ | ||
51 | |||
52 | /* Some defines for the prices */ | ||
53 | #define PRICE_MEN 1 | ||
54 | #define PRICE_MOVE 100 | ||
55 | #define PRICE_TANK 300 | ||
56 | #define PRICE_PLANE 600 | ||
57 | #define PRICE_FARM 1150 | ||
58 | #define PRICE_FACTORY 1300 | ||
59 | #define PRICE_NUKE 2000 | ||
60 | |||
61 | #define STRINGIZE_2(X) #X | ||
62 | #define STRINGIZE(X) STRINGIZE_2(X) | ||
63 | |||
64 | #define PRICE_MEN_STR STRINGIZE(PRICE_MEN) | ||
65 | #define PRICE_MOVE_STR STRINGIZE(PRICE_MOVE) | ||
66 | #define PRICE_TANK_STR STRINGIZE(PRICE_TANK) | ||
67 | #define PRICE_PLANE_STR STRINGIZE(PRICE_PLANE) | ||
68 | #define PRICE_FARM_STR STRINGIZE(PRICE_FARM) | ||
69 | #define PRICE_FACTORY_STR STRINGIZE(PRICE_FACTORY) | ||
70 | #define PRICE_NUKE_STR STRINGIZE(PRICE_NUKE) | ||
71 | |||
72 | /* surrender thresholds */ | ||
73 | #define HUMAN_SURRENDER_THRESHOLD 15 | ||
74 | #define COMPUTER_SURRENDER_THRESHOLD 15 | ||
75 | #define COMPUTER_HARD_SURRENDER_THRESHOLD 25 | ||
76 | |||
77 | /* board size */ | ||
78 | #define BOARD_SIZE 10 | ||
79 | #define NUM_SPACES (BOARD_SIZE*BOARD_SIZE) | ||
36 | #define COLOUR_DARK 0 | 80 | #define COLOUR_DARK 0 |
37 | #define COLOUR_LIGHT 1 | 81 | #define COLOUR_LIGHT 1 |
38 | 82 | ||
83 | /* drawing presets */ | ||
84 | |||
39 | #define MARGIN 5 | 85 | #define MARGIN 5 |
40 | 86 | ||
41 | #if (LCD_DEPTH >= 16) | 87 | #if (LCD_DEPTH >= 16) |
@@ -45,11 +91,11 @@ char buf[255]; | |||
45 | #endif | 91 | #endif |
46 | 92 | ||
47 | #if LCD_WIDTH > LCD_HEIGHT | 93 | #if LCD_WIDTH > LCD_HEIGHT |
48 | #define BOX_WIDTH ((LCD_WIDTH-(MARGIN*2))/10) | 94 | #define BOX_WIDTH ((LCD_WIDTH-(MARGIN*2))/BOARD_SIZE) |
49 | #define BOX_HEIGHT ((BOX_WIDTH*2)/3) | 95 | #define BOX_HEIGHT ((BOX_WIDTH*2)/3) |
50 | 96 | ||
51 | #else | 97 | #else |
52 | #define BOX_HEIGHT ((LCD_HEIGHT-(MARGIN*2)-15)/10) | 98 | #define BOX_HEIGHT ((LCD_HEIGHT-(MARGIN*2)-15)/BOARD_SIZE) |
53 | #define BOX_WIDTH ((BOX_HEIGHT*2)/3) | 99 | #define BOX_WIDTH ((BOX_HEIGHT*2)/3) |
54 | 100 | ||
55 | #endif | 101 | #endif |
@@ -72,38 +118,6 @@ char buf[255]; | |||
72 | #define ICON_HEIGHT (BMPHEIGHT_superdom_boarditems/6) | 118 | #define ICON_HEIGHT (BMPHEIGHT_superdom_boarditems/6) |
73 | #define ICON_WIDTH (BMPWIDTH_superdom_boarditems/2) | 119 | #define ICON_WIDTH (BMPWIDTH_superdom_boarditems/2) |
74 | 120 | ||
75 | #define SUPERDOM_OK PLA_SELECT | ||
76 | #define SUPERDOM_CANCEL PLA_CANCEL | ||
77 | #define SUPERDOM_RIGHT PLA_RIGHT | ||
78 | #define SUPERDOM_LEFT PLA_LEFT | ||
79 | #define SUPERDOM_UP PLA_UP | ||
80 | #define SUPERDOM_DOWN PLA_DOWN | ||
81 | |||
82 | #define SUPERDOM_RIGHT_REPEAT PLA_RIGHT_REPEAT | ||
83 | #define SUPERDOM_LEFT_REPEAT PLA_LEFT_REPEAT | ||
84 | #define SUPERDOM_UP_REPEAT PLA_UP_REPEAT | ||
85 | #define SUPERDOM_DOWN_REPEAT PLA_DOWN_REPEAT | ||
86 | |||
87 | /* Some defines for the prices */ | ||
88 | #define PRICE_MEN 1 | ||
89 | #define PRICE_MOVE 100 | ||
90 | #define PRICE_TANK 300 | ||
91 | #define PRICE_PLANE 600 | ||
92 | #define PRICE_FARM 1150 | ||
93 | #define PRICE_FACTORY 1300 | ||
94 | #define PRICE_NUKE 2000 | ||
95 | |||
96 | #define STRINGIZE_2(X) #X | ||
97 | #define STRINGIZE(X) STRINGIZE_2(X) | ||
98 | |||
99 | #define PRICE_MEN_STR STRINGIZE(PRICE_MEN) | ||
100 | #define PRICE_MOVE_STR STRINGIZE(PRICE_MOVE) | ||
101 | #define PRICE_TANK_STR STRINGIZE(PRICE_TANK) | ||
102 | #define PRICE_PLANE_STR STRINGIZE(PRICE_PLANE) | ||
103 | #define PRICE_FARM_STR STRINGIZE(PRICE_FARM) | ||
104 | #define PRICE_FACTORY_STR STRINGIZE(PRICE_FACTORY) | ||
105 | #define PRICE_NUKE_STR STRINGIZE(PRICE_NUKE) | ||
106 | |||
107 | enum { | 121 | enum { |
108 | RET_VAL_OK, | 122 | RET_VAL_OK, |
109 | RET_VAL_USB, | 123 | RET_VAL_USB, |
@@ -149,6 +163,21 @@ static struct settings { | |||
149 | int startcash; | 163 | int startcash; |
150 | int startfood; | 164 | int startfood; |
151 | int movesperturn; | 165 | int movesperturn; |
166 | /* 1=easy 2=medium 3=hard */ | ||
167 | /* AI difficulty works like this: | ||
168 | easy: | ||
169 | - no movement | ||
170 | - no investing | ||
171 | medium: | ||
172 | - movement | ||
173 | - investing | ||
174 | - can build factories/farms | ||
175 | hard: | ||
176 | - nuclear war | ||
177 | - harder to surrender | ||
178 | */ | ||
179 | int compdiff; | ||
180 | bool spoil_enabled; | ||
152 | } superdom_settings; | 181 | } superdom_settings; |
153 | 182 | ||
154 | static struct resources humanres; | 183 | static struct resources humanres; |
@@ -161,7 +190,7 @@ static struct cursor { | |||
161 | int y; | 190 | int y; |
162 | } cursor; | 191 | } cursor; |
163 | 192 | ||
164 | static struct tile board[12][12]; | 193 | static struct tile board[BOARD_SIZE+2][BOARD_SIZE+2]; |
165 | 194 | ||
166 | static const struct button_mapping *plugin_contexts[] = { pla_main_ctx }; | 195 | static const struct button_mapping *plugin_contexts[] = { pla_main_ctx }; |
167 | 196 | ||
@@ -171,9 +200,9 @@ static void init_board(void) | |||
171 | rb->srand(*rb->current_tick); | 200 | rb->srand(*rb->current_tick); |
172 | for(i=0;i<12;i++) | 201 | for(i=0;i<12;i++) |
173 | { /* Hopefully about 50% each colour */ | 202 | { /* Hopefully about 50% each colour */ |
174 | for(j=0;j<12;j++) | 203 | for(j=0;j<BOARD_SIZE+2;j++) |
175 | { | 204 | { |
176 | if((i<1)||(j<1)||(i>10)||(j>10)) | 205 | if((i<1)||(j<1)||(i>BOARD_SIZE)||(j>BOARD_SIZE)) |
177 | board[i][j].colour = -1; /* Unset */ | 206 | board[i][j].colour = -1; /* Unset */ |
178 | else | 207 | else |
179 | board[i][j].colour = rb->rand()%2; | 208 | board[i][j].colour = rb->rand()%2; |
@@ -188,8 +217,8 @@ static void init_board(void) | |||
188 | 217 | ||
189 | while(compres.farms < superdom_settings.compstartfarms) | 218 | while(compres.farms < superdom_settings.compstartfarms) |
190 | { | 219 | { |
191 | i = rb->rand()%10 + 1; | 220 | i = rb->rand()%BOARD_SIZE + 1; |
192 | j = rb->rand()%10 + 1; | 221 | j = rb->rand()%BOARD_SIZE + 1; |
193 | if((board[i][j].colour == COLOUR_DARK) && (board[i][j].farm == false)) | 222 | if((board[i][j].colour == COLOUR_DARK) && (board[i][j].farm == false)) |
194 | { | 223 | { |
195 | board[i][j].farm = true; | 224 | board[i][j].farm = true; |
@@ -198,8 +227,8 @@ static void init_board(void) | |||
198 | } | 227 | } |
199 | while(compres.inds < superdom_settings.compstartinds) | 228 | while(compres.inds < superdom_settings.compstartinds) |
200 | { | 229 | { |
201 | i = rb->rand()%10 + 1; | 230 | i = rb->rand()%BOARD_SIZE + 1; |
202 | j = rb->rand()%10 + 1; | 231 | j = rb->rand()%BOARD_SIZE + 1; |
203 | if((board[i][j].colour == COLOUR_DARK) && (board[i][j].ind == false)) | 232 | if((board[i][j].colour == COLOUR_DARK) && (board[i][j].ind == false)) |
204 | { | 233 | { |
205 | board[i][j].ind = true; | 234 | board[i][j].ind = true; |
@@ -208,8 +237,8 @@ static void init_board(void) | |||
208 | } | 237 | } |
209 | while(humanres.farms < superdom_settings.humanstartfarms) | 238 | while(humanres.farms < superdom_settings.humanstartfarms) |
210 | { | 239 | { |
211 | i = rb->rand()%10 + 1; | 240 | i = rb->rand()%BOARD_SIZE + 1; |
212 | j = rb->rand()%10 + 1; | 241 | j = rb->rand()%BOARD_SIZE + 1; |
213 | if((board[i][j].colour == COLOUR_LIGHT)&&(board[i][j].farm == false)) | 242 | if((board[i][j].colour == COLOUR_LIGHT)&&(board[i][j].farm == false)) |
214 | { | 243 | { |
215 | board[i][j].farm = true; | 244 | board[i][j].farm = true; |
@@ -218,8 +247,8 @@ static void init_board(void) | |||
218 | } | 247 | } |
219 | while(humanres.inds < superdom_settings.humanstartinds) | 248 | while(humanres.inds < superdom_settings.humanstartinds) |
220 | { | 249 | { |
221 | i = rb->rand()%10 + 1; | 250 | i = rb->rand()%BOARD_SIZE + 1; |
222 | j = rb->rand()%10 + 1; | 251 | j = rb->rand()%BOARD_SIZE + 1; |
223 | if((board[i][j].colour == COLOUR_LIGHT) && (board[i][j].ind == false)) | 252 | if((board[i][j].colour == COLOUR_LIGHT) && (board[i][j].ind == false)) |
224 | { | 253 | { |
225 | board[i][j].ind = true; | 254 | board[i][j].ind = true; |
@@ -232,9 +261,9 @@ void draw_board(void) | |||
232 | { | 261 | { |
233 | int i,j; | 262 | int i,j; |
234 | rb->lcd_clear_display(); | 263 | rb->lcd_clear_display(); |
235 | for(i=1;i<11;i++) | 264 | for(i=1;i<=BOARD_SIZE;i++) |
236 | { | 265 | { |
237 | for(j=1;j<11;j++) | 266 | for(j=1;j<=BOARD_SIZE;j++) |
238 | { | 267 | { |
239 | if(board[i][j].colour == COLOUR_DARK) | 268 | if(board[i][j].colour == COLOUR_DARK) |
240 | { | 269 | { |
@@ -325,14 +354,14 @@ void draw_board(void) | |||
325 | } | 354 | } |
326 | rb->lcd_set_foreground(LCD_BLACK); | 355 | rb->lcd_set_foreground(LCD_BLACK); |
327 | /* Draw Horizontal lines */ | 356 | /* Draw Horizontal lines */ |
328 | for(i=0;i<=10;i++) | 357 | for(i=0;i<=BOARD_SIZE;i++) |
329 | { | 358 | { |
330 | rb->lcd_hline(MARGIN, MARGIN+(BOX_WIDTH*10), MARGIN+(BOX_HEIGHT*i)); | 359 | rb->lcd_hline(MARGIN, MARGIN+(BOX_WIDTH*BOARD_SIZE), MARGIN+(BOX_HEIGHT*i)); |
331 | } | 360 | } |
332 | /* Draw Vertical lines */ | 361 | /* Draw Vertical lines */ |
333 | for(i=0;i<=10;i++) | 362 | for(i=0;i<=BOARD_SIZE;i++) |
334 | { | 363 | { |
335 | rb->lcd_vline(MARGIN+(BOX_WIDTH*i), MARGIN, MARGIN+(BOX_HEIGHT*10)); | 364 | rb->lcd_vline(MARGIN+(BOX_WIDTH*i), MARGIN, MARGIN+(BOX_HEIGHT*BOARD_SIZE)); |
336 | } | 365 | } |
337 | rb->lcd_update(); | 366 | rb->lcd_update(); |
338 | } | 367 | } |
@@ -346,15 +375,30 @@ static int calc_strength(int colour, int x, int y) | |||
346 | { | 375 | { |
347 | if(board[x+a][y+b].colour==colour) | 376 | if(board[x+a][y+b].colour==colour) |
348 | { | 377 | { |
349 | score += 10; | 378 | if(a && b) /* diagonally adjacent, give less influence */ |
350 | if(board[x + a][y + b].tank || board[x + a][y + b].farm) | 379 | { |
351 | score += 30; | 380 | score += 5; |
352 | if(board[x + a][y + b].plane || board[x + a][y + b].ind) | 381 | if(board[x + a][y + b].tank || board[x + a][y + b].farm) |
353 | score += 40; | 382 | score += 15; |
354 | if(board[x + a][y + b].nuke) | 383 | if(board[x + a][y + b].plane || board[x + a][y + b].ind) |
355 | score += 20; | 384 | score += 20; |
356 | if(board[x + a][y + b].men) | 385 | if(board[x + a][y + b].nuke) |
357 | score += (board[x + a][y + b].men*133/1000); | 386 | score += 10; |
387 | if(board[x + a][y + b].men) | ||
388 | score += (board[x + a][y + b].men*133/1000); | ||
389 | } | ||
390 | else | ||
391 | { | ||
392 | score += 10; | ||
393 | if(board[x + a][y + b].tank || board[x + a][y + b].farm) | ||
394 | score += 30; | ||
395 | if(board[x + a][y + b].plane || board[x + a][y + b].ind) | ||
396 | score += 40; | ||
397 | if(board[x + a][y + b].nuke) | ||
398 | score += 20; | ||
399 | if(board[x + a][y + b].men) | ||
400 | score += (board[x + a][y + b].men*133/1000); | ||
401 | } | ||
358 | } | 402 | } |
359 | } | 403 | } |
360 | } | 404 | } |
@@ -468,6 +512,7 @@ void gen_resources(void) | |||
468 | static void update_score(void) | 512 | static void update_score(void) |
469 | { | 513 | { |
470 | int strength; | 514 | int strength; |
515 | |||
471 | rb->lcd_setfont(FONT_SYSFIXED); | 516 | rb->lcd_setfont(FONT_SYSFIXED); |
472 | rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID); | 517 | rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID); |
473 | rb->lcd_fillrect(5,LCD_HEIGHT-20,105,20); | 518 | rb->lcd_fillrect(5,LCD_HEIGHT-20,105,20); |
@@ -486,7 +531,7 @@ static int settings_menu(void) | |||
486 | MENUITEM_STRINGLIST(menu, "Super Domination Settings", NULL, | 531 | MENUITEM_STRINGLIST(menu, "Super Domination Settings", NULL, |
487 | "Computer starting farms", "Computer starting factories", | 532 | "Computer starting farms", "Computer starting factories", |
488 | "Human starting farms", "Human starting factories", | 533 | "Human starting farms", "Human starting factories", |
489 | "Starting cash", "Starting food", "Moves per turn"); | 534 | "Starting cash", "Starting food", "Computer difficulty","Food spoilage", "Moves per turn"); |
490 | 535 | ||
491 | while(1) | 536 | while(1) |
492 | { | 537 | { |
@@ -523,6 +568,22 @@ static int settings_menu(void) | |||
523 | 250, 0, 5000, NULL); | 568 | 250, 0, 5000, NULL); |
524 | break; | 569 | break; |
525 | case 6: | 570 | case 6: |
571 | { | ||
572 | static const struct opt_items difficulty_options[3]={ | ||
573 | {"Easy", 1}, | ||
574 | {"Intermediate", 2}, | ||
575 | {"Hard", 3} | ||
576 | }; | ||
577 | rb->set_option("Computer difficulty", &superdom_settings.compdiff, | ||
578 | INT, difficulty_options, 3, NULL); | ||
579 | superdom_settings.compdiff++; | ||
580 | break; | ||
581 | } | ||
582 | case 7: | ||
583 | rb->set_bool_options("Food spoilage", &superdom_settings.spoil_enabled, "Enabled", | ||
584 | 0, "Disabled", 0, NULL); | ||
585 | break; | ||
586 | case 8: | ||
526 | rb->set_int("Moves per turn", "", UNIT_INT, | 587 | rb->set_int("Moves per turn", "", UNIT_INT, |
527 | &superdom_settings.movesperturn, NULL, | 588 | &superdom_settings.movesperturn, NULL, |
528 | 1, 1, 5, NULL); | 589 | 1, 1, 5, NULL); |
@@ -1499,7 +1560,7 @@ static int select_square(void) | |||
1499 | } | 1560 | } |
1500 | else | 1561 | else |
1501 | { | 1562 | { |
1502 | cursor.x = 10; | 1563 | cursor.x = BOARD_SIZE; |
1503 | } | 1564 | } |
1504 | update_score(); | 1565 | update_score(); |
1505 | draw_cursor(); | 1566 | draw_cursor(); |
@@ -1507,7 +1568,7 @@ static int select_square(void) | |||
1507 | case SUPERDOM_RIGHT: | 1568 | case SUPERDOM_RIGHT: |
1508 | case SUPERDOM_RIGHT_REPEAT: | 1569 | case SUPERDOM_RIGHT_REPEAT: |
1509 | draw_cursor(); /* Deselect the current tile */ | 1570 | draw_cursor(); /* Deselect the current tile */ |
1510 | if(cursor.x<10) | 1571 | if(cursor.x<BOARD_SIZE) |
1511 | { | 1572 | { |
1512 | cursor.x++; | 1573 | cursor.x++; |
1513 | } | 1574 | } |
@@ -1531,9 +1592,9 @@ static int select_square(void) | |||
1531 | if(cursor.x > 1) | 1592 | if(cursor.x > 1) |
1532 | cursor.x--; | 1593 | cursor.x--; |
1533 | else | 1594 | else |
1534 | cursor.x = 10; | 1595 | cursor.x = BOARD_SIZE; |
1535 | #endif | 1596 | #endif |
1536 | cursor.y = 10; | 1597 | cursor.y = BOARD_SIZE; |
1537 | } | 1598 | } |
1538 | update_score(); | 1599 | update_score(); |
1539 | draw_cursor(); | 1600 | draw_cursor(); |
@@ -1541,14 +1602,14 @@ static int select_square(void) | |||
1541 | case SUPERDOM_DOWN: | 1602 | case SUPERDOM_DOWN: |
1542 | case SUPERDOM_DOWN_REPEAT: | 1603 | case SUPERDOM_DOWN_REPEAT: |
1543 | draw_cursor(); /* Deselect the current tile */ | 1604 | draw_cursor(); /* Deselect the current tile */ |
1544 | if(cursor.y<10) | 1605 | if(cursor.y<BOARD_SIZE) |
1545 | { | 1606 | { |
1546 | cursor.y++; | 1607 | cursor.y++; |
1547 | } | 1608 | } |
1548 | else | 1609 | else |
1549 | { | 1610 | { |
1550 | #if CONFIG_KEYPAD == IRIVER_H10_PAD | 1611 | #if CONFIG_KEYPAD == IRIVER_H10_PAD |
1551 | if(cursor.x < 10) | 1612 | if(cursor.x < BOARD_SIZE) |
1552 | cursor.x++; | 1613 | cursor.x++; |
1553 | else | 1614 | else |
1554 | cursor.x = 1; | 1615 | cursor.x = 1; |
@@ -1583,9 +1644,9 @@ static int killmen(int colour) | |||
1583 | compres.food = 0; | 1644 | compres.food = 0; |
1584 | } | 1645 | } |
1585 | menkilled = 0; | 1646 | menkilled = 0; |
1586 | for(i=1;i<11;i++) | 1647 | for(i=1;i<=BOARD_SIZE;i++) |
1587 | { | 1648 | { |
1588 | for(j=1;j<11;j++) | 1649 | for(j=1;j<=BOARD_SIZE;j++) |
1589 | { | 1650 | { |
1590 | if(board[i][j].colour == colour) | 1651 | if(board[i][j].colour == colour) |
1591 | { | 1652 | { |
@@ -1642,11 +1703,11 @@ static int attack_territory(int colour, int x, int y) | |||
1642 | defres->inds -= board[x][y].ind; | 1703 | defres->inds -= board[x][y].ind; |
1643 | offres->farms += board[x][y].farm; | 1704 | offres->farms += board[x][y].farm; |
1644 | offres->inds += board[x][y].ind; | 1705 | offres->inds += board[x][y].ind; |
1706 | offres->nukes += board[x][y].nuke; | ||
1645 | board[x][y].colour = colour; | 1707 | board[x][y].colour = colour; |
1646 | board[x][y].men = 0; | 1708 | board[x][y].men = 0; |
1647 | board[x][y].tank = false; | 1709 | board[x][y].tank = false; |
1648 | board[x][y].plane = false; | 1710 | board[x][y].plane = false; |
1649 | board[x][y].nuke = false; | ||
1650 | draw_board(); | 1711 | draw_board(); |
1651 | if(human) | 1712 | if(human) |
1652 | rb->sleep(HZ*2); | 1713 | rb->sleep(HZ*2); |
@@ -1668,6 +1729,19 @@ static int attack_territory(int colour, int x, int y) | |||
1668 | return 0; | 1729 | return 0; |
1669 | } | 1730 | } |
1670 | 1731 | ||
1732 | static void spoil_food(void) | ||
1733 | { | ||
1734 | /* spoil 0-10% of food, different amounts for computer/player */ | ||
1735 | int spoil_amount=humanres.food*(0.1*rb->rand()/RAND_MAX); | ||
1736 | if(spoil_amount) | ||
1737 | rb->splashf(2*HZ, "Spoilage claims %d units of food", spoil_amount); | ||
1738 | humanres.food-=spoil_amount; | ||
1739 | |||
1740 | /* now for computer */ | ||
1741 | spoil_amount=compres.food*(0.1*rb->rand()/RAND_MAX); | ||
1742 | compres.food-=spoil_amount; | ||
1743 | } | ||
1744 | |||
1671 | static int war_menu(void) | 1745 | static int war_menu(void) |
1672 | { | 1746 | { |
1673 | int selection = 0, temp; | 1747 | int selection = 0, temp; |
@@ -1782,7 +1856,7 @@ static void computer_allocate(void) | |||
1782 | { | 1856 | { |
1783 | /* Firstly, decide whether to go offensive or defensive. | 1857 | /* Firstly, decide whether to go offensive or defensive. |
1784 | * This is primarily decided by the human player posing a threat to either | 1858 | * This is primarily decided by the human player posing a threat to either |
1785 | * the computer's farms or factories */ | 1859 | * the computer's farms, factories or nukes */ |
1786 | int i, j, k; | 1860 | int i, j, k; |
1787 | bool offensive = true; | 1861 | bool offensive = true; |
1788 | struct threat threats[4]; | 1862 | struct threat threats[4]; |
@@ -1797,17 +1871,18 @@ static void computer_allocate(void) | |||
1797 | 1871 | ||
1798 | compres.cash += compres.bank; | 1872 | compres.cash += compres.bank; |
1799 | compres.bank = 0; | 1873 | compres.bank = 0; |
1800 | for(i=1;i<11;i++) | 1874 | for(i=1;i<=BOARD_SIZE;i++) |
1801 | { | 1875 | { |
1802 | for(j=1;j<11;j++) | 1876 | for(j=1;j<=BOARD_SIZE;j++) |
1803 | { | 1877 | { |
1804 | if(board[i][j].colour == COLOUR_DARK) | 1878 | if(board[i][j].colour == COLOUR_DARK) |
1805 | { | 1879 | { |
1806 | numterritory++; | 1880 | numterritory++; |
1807 | str_diff = calc_strength(COLOUR_LIGHT,i,j) - | 1881 | str_diff = calc_strength(COLOUR_LIGHT,i,j) - |
1808 | calc_strength(COLOUR_DARK,i,j); | 1882 | calc_strength(COLOUR_DARK,i,j); |
1809 | if(str_diff > 0 && (board[i][j].ind || board[i][j].farm)) | 1883 | if(str_diff > 0 && (board[i][j].ind || board[i][j].farm || board[i][j].nuke)) |
1810 | { | 1884 | { |
1885 | /* computer's farm/factory/nuke is being threatened */ | ||
1811 | if(numthreats < 3) | 1886 | if(numthreats < 3) |
1812 | { | 1887 | { |
1813 | offensive = false; | 1888 | offensive = false; |
@@ -1821,10 +1896,24 @@ static void computer_allocate(void) | |||
1821 | rb->yield(); | 1896 | rb->yield(); |
1822 | } | 1897 | } |
1823 | } | 1898 | } |
1899 | /* AI player will buy nukes if possible first */ | ||
1900 | if(compres.cash > PRICE_NUKE + PRICE_TANK && superdom_settings.compdiff>=3) | ||
1901 | { | ||
1902 | while(compres.cash >= PRICE_NUKE && compres.nukes < numterritory) | ||
1903 | { | ||
1904 | i = rb->rand()%BOARD_SIZE + 1; | ||
1905 | j = rb->rand()%BOARD_SIZE + 1; | ||
1906 | if(board[i][j].colour == COLOUR_DARK) | ||
1907 | { | ||
1908 | buy_resources(COLOUR_DARK, 5, i, j, 0); | ||
1909 | } | ||
1910 | rb->yield(); | ||
1911 | } | ||
1912 | } | ||
1824 | if(offensive) | 1913 | if(offensive) |
1825 | { | 1914 | { |
1826 | /* The AI is going to go straight for the throat here and attack | 1915 | /* The AI is going to go straight for the throat here and attack |
1827 | * the player's farms and factories. The amount of cash | 1916 | * the player's farms, nukes, and factories. The amount of cash |
1828 | * the AI has to spend will determine how many targets there are */ | 1917 | * the AI has to spend will determine how many targets there are */ |
1829 | if(compres.cash > 1200) | 1918 | if(compres.cash > 1200) |
1830 | { | 1919 | { |
@@ -1839,12 +1928,12 @@ static void computer_allocate(void) | |||
1839 | * owned by the computer. If none are found just place troops in | 1928 | * owned by the computer. If none are found just place troops in |
1840 | * random places around the map until we run out of money */ | 1929 | * random places around the map until we run out of money */ |
1841 | k = 0; | 1930 | k = 0; |
1842 | for(i=1;i<11;i++) | 1931 | for(i=1;i<=BOARD_SIZE;i++) |
1843 | { | 1932 | { |
1844 | for(j=1;j<11;j++) | 1933 | for(j=1;j<=BOARD_SIZE;j++) |
1845 | { | 1934 | { |
1846 | if(has_adjacent(i,j) && | 1935 | if(has_adjacent(i,j) && |
1847 | (board[i][j].ind || board[i][j].farm)) | 1936 | (board[i][j].ind || board[i][j].farm || board[i][j].nuke)) |
1848 | { | 1937 | { |
1849 | if(k<numtargets) | 1938 | if(k<numtargets) |
1850 | { | 1939 | { |
@@ -1863,10 +1952,12 @@ static void computer_allocate(void) | |||
1863 | { | 1952 | { |
1864 | /* No targets found! Randomly pick squares and if they're owned | 1953 | /* No targets found! Randomly pick squares and if they're owned |
1865 | * by the computer then stick a tank on it. */ | 1954 | * by the computer then stick a tank on it. */ |
1866 | while(compres.cash >= 300 && compres.tanks < numterritory) { | 1955 | while(compres.cash >= 300 && compres.tanks < numterritory) |
1867 | i = rb->rand()%10 + 1; | 1956 | { |
1868 | j = rb->rand()%10 + 1; | 1957 | i = rb->rand()%BOARD_SIZE + 1; |
1869 | if(board[i][j].colour == COLOUR_DARK) { | 1958 | j = rb->rand()%BOARD_SIZE + 1; |
1959 | if(board[i][j].colour == COLOUR_DARK) | ||
1960 | { | ||
1870 | buy_resources(COLOUR_DARK, 1, i, j, 0); | 1961 | buy_resources(COLOUR_DARK, 1, i, j, 0); |
1871 | } | 1962 | } |
1872 | rb->yield(); | 1963 | rb->yield(); |
@@ -1962,8 +2053,12 @@ static void computer_allocate(void) | |||
1962 | } | 2053 | } |
1963 | } | 2054 | } |
1964 | } | 2055 | } |
1965 | compres.bank += compres.cash; | 2056 | /* no investing in easy mode */ |
1966 | compres.cash = 0; | 2057 | if(superdom_settings.compdiff>=2) |
2058 | { | ||
2059 | compres.bank += compres.cash; | ||
2060 | compres.cash = 0; | ||
2061 | } | ||
1967 | } | 2062 | } |
1968 | 2063 | ||
1969 | static int find_adj_target(int x, int y, struct cursor* adj) | 2064 | static int find_adj_target(int x, int y, struct cursor* adj) |
@@ -2001,9 +2096,14 @@ static int find_adj_target(int x, int y, struct cursor* adj) | |||
2001 | return 0; | 2096 | return 0; |
2002 | } | 2097 | } |
2003 | 2098 | ||
2099 | static void computer_movement(void) | ||
2100 | { | ||
2101 | |||
2102 | } | ||
2103 | |||
2004 | static void computer_war(void) | 2104 | static void computer_war(void) |
2005 | { | 2105 | { |
2006 | /* Work out where to attack - prioritise the defence of buildings */ | 2106 | /* Work out where to attack - prioritise the defence of buildings and nukes */ |
2007 | int i, j; | 2107 | int i, j; |
2008 | bool found_target = true; | 2108 | bool found_target = true; |
2009 | struct cursor adj; | 2109 | struct cursor adj; |
@@ -2011,12 +2111,12 @@ static void computer_war(void) | |||
2011 | while(found_target) | 2111 | while(found_target) |
2012 | { | 2112 | { |
2013 | found_target = false; | 2113 | found_target = false; |
2014 | for(i=1;i<11;i++) | 2114 | for(i=1;i<=BOARD_SIZE;i++) |
2015 | { | 2115 | { |
2016 | for(j=1;j<11;j++) | 2116 | for(j=1;j<=BOARD_SIZE;j++) |
2017 | { | 2117 | { |
2018 | if((board[i][j].colour == COLOUR_DARK) && | 2118 | if((board[i][j].colour == COLOUR_DARK) && |
2019 | (board[i][j].farm || board[i][j].ind) && | 2119 | (board[i][j].farm || board[i][j].ind || board[i][j].nuke) && |
2020 | find_adj_target(i, j, &adj)) | 2120 | find_adj_target(i, j, &adj)) |
2021 | { | 2121 | { |
2022 | found_target = true; | 2122 | found_target = true; |
@@ -2036,12 +2136,12 @@ static void computer_war(void) | |||
2036 | while(found_target) | 2136 | while(found_target) |
2037 | { | 2137 | { |
2038 | found_target = false; | 2138 | found_target = false; |
2039 | for(i=1;i<11;i++) | 2139 | for(i=1;i<=BOARD_SIZE;i++) |
2040 | { | 2140 | { |
2041 | for(j=1;j<11;j++) | 2141 | for(j=1;j<=BOARD_SIZE;j++) |
2042 | { | 2142 | { |
2043 | if(board[i][j].colour == COLOUR_LIGHT && | 2143 | if(board[i][j].colour == COLOUR_LIGHT && |
2044 | (board[i][j].ind || board[i][j].farm) && | 2144 | (board[i][j].ind || board[i][j].farm || board[i][j].nuke) && |
2045 | (calc_strength(COLOUR_DARK, i, j) >= calc_strength(COLOUR_LIGHT, i, j))) | 2145 | (calc_strength(COLOUR_DARK, i, j) >= calc_strength(COLOUR_LIGHT, i, j))) |
2046 | { | 2146 | { |
2047 | found_target = true; | 2147 | found_target = true; |
@@ -2061,9 +2161,9 @@ static void computer_war(void) | |||
2061 | while(found_target) | 2161 | while(found_target) |
2062 | { | 2162 | { |
2063 | found_target = false; | 2163 | found_target = false; |
2064 | for(i=1;i<11;i++) | 2164 | for(i=1;i<=BOARD_SIZE;i++) |
2065 | { | 2165 | { |
2066 | for(j=1;j<11;j++) | 2166 | for(j=1;j<=BOARD_SIZE;j++) |
2067 | { | 2167 | { |
2068 | if(board[i][j].colour == COLOUR_LIGHT && | 2168 | if(board[i][j].colour == COLOUR_LIGHT && |
2069 | (calc_strength(COLOUR_DARK, i, j) >= | 2169 | (calc_strength(COLOUR_DARK, i, j) >= |
@@ -2141,6 +2241,8 @@ static void default_settings(void) | |||
2141 | superdom_settings.startcash = 0; | 2241 | superdom_settings.startcash = 0; |
2142 | superdom_settings.startfood = 0; | 2242 | superdom_settings.startfood = 0; |
2143 | superdom_settings.movesperturn = 2; | 2243 | superdom_settings.movesperturn = 2; |
2244 | superdom_settings.compdiff=2; | ||
2245 | superdom_settings.spoil_enabled=false; | ||
2144 | } | 2246 | } |
2145 | 2247 | ||
2146 | static int average_strength(int colour) | 2248 | static int average_strength(int colour) |
@@ -2149,9 +2251,9 @@ static int average_strength(int colour) | |||
2149 | * used to determine when the computer wins or loses. */ | 2251 | * used to determine when the computer wins or loses. */ |
2150 | int i,j; | 2252 | int i,j; |
2151 | int totalpower = 0; | 2253 | int totalpower = 0; |
2152 | for(i=1;i<11;i++) | 2254 | for(i=1;i<=BOARD_SIZE;i++) |
2153 | { | 2255 | { |
2154 | for(j=1;j<11;j++) | 2256 | for(j=1;j<=BOARD_SIZE;j++) |
2155 | { | 2257 | { |
2156 | if(board[i][j].colour != -1) | 2258 | if(board[i][j].colour != -1) |
2157 | { | 2259 | { |
@@ -2159,7 +2261,7 @@ static int average_strength(int colour) | |||
2159 | } | 2261 | } |
2160 | } | 2262 | } |
2161 | } | 2263 | } |
2162 | return totalpower/100; | 2264 | return totalpower/NUM_SPACES; |
2163 | } | 2265 | } |
2164 | 2266 | ||
2165 | enum plugin_status plugin_start(const void* parameter) | 2267 | enum plugin_status plugin_start(const void* parameter) |
@@ -2220,12 +2322,15 @@ startyear: | |||
2220 | { | 2322 | { |
2221 | int avg_str_diff = (average_strength(COLOUR_LIGHT) - | 2323 | int avg_str_diff = (average_strength(COLOUR_LIGHT) - |
2222 | average_strength(COLOUR_DARK)); | 2324 | average_strength(COLOUR_DARK)); |
2223 | if(avg_str_diff > 15) | 2325 | /* computer will hold out longer in hard mode */ |
2326 | if(avg_str_diff > (superdom_settings.compdiff>=3 ? | ||
2327 | COMPUTER_HARD_SURRENDER_THRESHOLD : | ||
2328 | COMPUTER_SURRENDER_THRESHOLD)) | ||
2224 | { | 2329 | { |
2225 | rb->splash(HZ*4, "The computer has surrendered. You win."); | 2330 | rb->splash(HZ*4, "The computer has surrendered. You win."); |
2226 | return PLUGIN_OK; | 2331 | return PLUGIN_OK; |
2227 | } | 2332 | } |
2228 | if(-avg_str_diff > 15) | 2333 | if(-avg_str_diff > HUMAN_SURRENDER_THRESHOLD) |
2229 | { | 2334 | { |
2230 | rb->splash(HZ*4, "Your army have suffered terrible morale from" | 2335 | rb->splash(HZ*4, "Your army have suffered terrible morale from" |
2231 | " the bleak prospects of winning. You lose."); | 2336 | " the bleak prospects of winning. You lose."); |
@@ -2259,6 +2364,15 @@ startyear: | |||
2259 | return PLUGIN_OK; | 2364 | return PLUGIN_OK; |
2260 | break; | 2365 | break; |
2261 | } | 2366 | } |
2367 | /* computer movement */ | ||
2368 | computer_movement(); | ||
2369 | |||
2370 | /* spoil food */ | ||
2371 | if(superdom_settings.spoil_enabled) | ||
2372 | { | ||
2373 | spoil_food(); | ||
2374 | } | ||
2375 | |||
2262 | /* feed men */ | 2376 | /* feed men */ |
2263 | if(humanres.men) | 2377 | if(humanres.men) |
2264 | { | 2378 | { |