2007-08-02 12:55:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Will Robertson
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-08-02 12:55:14 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2014-08-27 00:11:53 +00:00
|
|
|
/* TODO list:
|
2014-08-31 00:59:20 +00:00
|
|
|
- improve AI
|
|
|
|
- buy/use nukes - DONE
|
|
|
|
- build farms/factories
|
2014-08-27 00:11:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2007-08-02 12:55:14 +00:00
|
|
|
#include "plugin.h"
|
2009-07-14 13:03:17 +00:00
|
|
|
#include "lib/display_text.h"
|
2014-08-27 00:11:53 +00:00
|
|
|
#include "lib/playback_control.h"
|
|
|
|
#include "lib/pluginlib_actions.h"
|
2009-07-23 04:33:10 +00:00
|
|
|
#include "pluginbitmaps/superdom_boarditems.h"
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2007-08-02 12:55:14 +00:00
|
|
|
char buf[255];
|
|
|
|
|
2014-08-28 23:19:08 +00:00
|
|
|
/* key mappings */
|
|
|
|
|
|
|
|
#define SUPERDOM_OK PLA_SELECT
|
|
|
|
#define SUPERDOM_CANCEL PLA_CANCEL
|
|
|
|
#define SUPERDOM_RIGHT PLA_RIGHT
|
|
|
|
#define SUPERDOM_LEFT PLA_LEFT
|
|
|
|
#define SUPERDOM_UP PLA_UP
|
|
|
|
#define SUPERDOM_DOWN PLA_DOWN
|
|
|
|
|
|
|
|
#define SUPERDOM_RIGHT_REPEAT PLA_RIGHT_REPEAT
|
|
|
|
#define SUPERDOM_LEFT_REPEAT PLA_LEFT_REPEAT
|
|
|
|
#define SUPERDOM_UP_REPEAT PLA_UP_REPEAT
|
|
|
|
#define SUPERDOM_DOWN_REPEAT PLA_DOWN_REPEAT
|
|
|
|
|
|
|
|
/***** game settings *****/
|
|
|
|
|
|
|
|
/* Some defines for the prices */
|
|
|
|
#define PRICE_MEN 1
|
|
|
|
#define PRICE_MOVE 100
|
|
|
|
#define PRICE_TANK 300
|
|
|
|
#define PRICE_PLANE 600
|
|
|
|
#define PRICE_FARM 1150
|
|
|
|
#define PRICE_FACTORY 1300
|
|
|
|
#define PRICE_NUKE 2000
|
|
|
|
|
|
|
|
#define STRINGIZE_2(X) #X
|
|
|
|
#define STRINGIZE(X) STRINGIZE_2(X)
|
|
|
|
|
|
|
|
#define PRICE_MEN_STR STRINGIZE(PRICE_MEN)
|
|
|
|
#define PRICE_MOVE_STR STRINGIZE(PRICE_MOVE)
|
|
|
|
#define PRICE_TANK_STR STRINGIZE(PRICE_TANK)
|
|
|
|
#define PRICE_PLANE_STR STRINGIZE(PRICE_PLANE)
|
|
|
|
#define PRICE_FARM_STR STRINGIZE(PRICE_FARM)
|
|
|
|
#define PRICE_FACTORY_STR STRINGIZE(PRICE_FACTORY)
|
|
|
|
#define PRICE_NUKE_STR STRINGIZE(PRICE_NUKE)
|
|
|
|
|
|
|
|
/* surrender thresholds */
|
|
|
|
#define HUMAN_SURRENDER_THRESHOLD 15
|
|
|
|
#define COMPUTER_SURRENDER_THRESHOLD 15
|
|
|
|
#define COMPUTER_HARD_SURRENDER_THRESHOLD 25
|
|
|
|
|
2014-08-31 00:59:20 +00:00
|
|
|
/* AI settings */
|
|
|
|
#define AI_INVESTING_LEVEL 2
|
|
|
|
#define AI_BUILD_NUKES_LEVEL 3
|
|
|
|
#define AI_BUILD_INDS_FARMS_LEVEL 2
|
|
|
|
|
2014-08-28 23:19:08 +00:00
|
|
|
/* board size */
|
|
|
|
#define BOARD_SIZE 10
|
|
|
|
#define NUM_SPACES (BOARD_SIZE*BOARD_SIZE)
|
2007-08-02 12:55:14 +00:00
|
|
|
#define COLOUR_DARK 0
|
|
|
|
#define COLOUR_LIGHT 1
|
|
|
|
|
2014-08-28 23:19:08 +00:00
|
|
|
/* drawing presets */
|
|
|
|
|
2007-08-02 12:55:14 +00:00
|
|
|
#define MARGIN 5
|
|
|
|
|
2014-06-18 05:15:00 +00:00
|
|
|
#if (LCD_DEPTH >= 16)
|
2009-05-16 08:20:54 +00:00
|
|
|
#define MY_BITMAP_PART rb->lcd_bitmap_transparent_part
|
|
|
|
#else
|
|
|
|
#define MY_BITMAP_PART rb->lcd_mono_bitmap_part
|
|
|
|
#endif
|
|
|
|
|
2007-08-02 12:55:14 +00:00
|
|
|
#if LCD_WIDTH > LCD_HEIGHT
|
2014-08-28 23:19:08 +00:00
|
|
|
#define BOX_WIDTH ((LCD_WIDTH-(MARGIN*2))/BOARD_SIZE)
|
2007-08-02 12:55:14 +00:00
|
|
|
#define BOX_HEIGHT ((BOX_WIDTH*2)/3)
|
|
|
|
|
|
|
|
#else
|
2014-08-28 23:19:08 +00:00
|
|
|
#define BOX_HEIGHT ((LCD_HEIGHT-(MARGIN*2)-15)/BOARD_SIZE)
|
2007-08-02 12:55:14 +00:00
|
|
|
#define BOX_WIDTH ((BOX_HEIGHT*2)/3)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-07-23 04:33:10 +00:00
|
|
|
/* NUM_BOX HEIGHT and WIDTH are used for the number pad in the game. The height
|
|
|
|
* calculation includes spacing for the text placed above and below the number
|
|
|
|
* pad (it divides by 6 instead of just 4). The width calculation gives extra
|
|
|
|
* spacing on the sides of the pad too (divides by 5 instead of 3).
|
|
|
|
*/
|
|
|
|
#define NUM_BOX_HEIGHT (LCD_HEIGHT/6)
|
|
|
|
#define NUM_BOX_WIDTH (LCD_WIDTH/5)
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2009-07-23 04:33:10 +00:00
|
|
|
#define NUM_MARGIN_X (LCD_WIDTH-3*NUM_BOX_WIDTH)/2
|
|
|
|
#define NUM_MARGIN_Y (LCD_HEIGHT-4*NUM_BOX_HEIGHT)/2
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2009-07-23 04:33:10 +00:00
|
|
|
/* These parameters define the piece image dimensions, Stride is the total width
|
|
|
|
* of the bitmap.
|
|
|
|
*/
|
2009-09-04 00:46:24 +00:00
|
|
|
#define ICON_STRIDE STRIDE(SCREEN_MAIN, BMPWIDTH_superdom_boarditems, BMPHEIGHT_superdom_boarditems)
|
2009-07-23 04:33:10 +00:00
|
|
|
#define ICON_HEIGHT (BMPHEIGHT_superdom_boarditems/6)
|
|
|
|
#define ICON_WIDTH (BMPWIDTH_superdom_boarditems/2)
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2009-08-02 14:30:09 +00:00
|
|
|
enum {
|
|
|
|
RET_VAL_OK,
|
|
|
|
RET_VAL_USB,
|
|
|
|
RET_VAL_QUIT_ERR, /* quit or error */
|
|
|
|
};
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2012-04-14 15:19:02 +00:00
|
|
|
static void gen_interest(void);
|
|
|
|
static void init_resources(void);
|
|
|
|
static int select_square(void);
|
|
|
|
static void update_score(void);
|
|
|
|
static void gen_resources(void);
|
|
|
|
static void draw_cursor(void);
|
|
|
|
static void draw_board(void);
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
struct tile {
|
2007-08-02 12:55:14 +00:00
|
|
|
signed int colour; /* -1 = Unset */
|
|
|
|
bool tank;
|
|
|
|
bool plane;
|
|
|
|
bool nuke;
|
|
|
|
bool ind;
|
|
|
|
bool farm;
|
|
|
|
int men;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct resources {
|
|
|
|
int cash;
|
|
|
|
int food;
|
|
|
|
int farms;
|
|
|
|
int inds;
|
|
|
|
int men;
|
|
|
|
int tanks;
|
|
|
|
int planes;
|
|
|
|
int nukes;
|
|
|
|
int bank;
|
|
|
|
int moves;
|
|
|
|
};
|
|
|
|
|
2012-04-14 15:19:02 +00:00
|
|
|
static struct settings {
|
2007-08-02 12:55:14 +00:00
|
|
|
int compstartfarms;
|
|
|
|
int compstartinds;
|
|
|
|
int humanstartfarms;
|
|
|
|
int humanstartinds;
|
|
|
|
int startcash;
|
|
|
|
int startfood;
|
|
|
|
int movesperturn;
|
2014-08-28 23:19:08 +00:00
|
|
|
/* 1=easy 2=medium 3=hard */
|
|
|
|
/* AI difficulty works like this:
|
|
|
|
easy:
|
|
|
|
- no movement
|
|
|
|
- no investing
|
2014-08-31 00:59:20 +00:00
|
|
|
- will build factories if it has none
|
2014-08-28 23:19:08 +00:00
|
|
|
medium:
|
|
|
|
- movement
|
|
|
|
- investing
|
2014-08-31 00:59:20 +00:00
|
|
|
- can build factories/farms if it has money
|
2014-08-28 23:19:08 +00:00
|
|
|
hard:
|
2014-08-31 00:59:20 +00:00
|
|
|
- can buy/use nukes
|
|
|
|
- will hold out longer (surrender threshold 25)
|
2014-08-28 23:19:08 +00:00
|
|
|
*/
|
|
|
|
int compdiff;
|
|
|
|
bool spoil_enabled;
|
2014-08-31 01:02:56 +00:00
|
|
|
bool persistent_units;
|
2007-08-02 12:55:14 +00:00
|
|
|
} superdom_settings;
|
|
|
|
|
2012-04-14 15:19:02 +00:00
|
|
|
static struct resources humanres;
|
|
|
|
static struct resources compres;
|
2010-06-18 13:33:22 +00:00
|
|
|
enum { GS_PROD, GS_MOVE, GS_WAR };
|
2012-04-14 15:19:02 +00:00
|
|
|
static int gamestate;
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static struct cursor {
|
2007-08-02 12:55:14 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
} cursor;
|
|
|
|
|
2014-08-28 23:19:08 +00:00
|
|
|
static struct tile board[BOARD_SIZE+2][BOARD_SIZE+2];
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
|
|
|
|
|
|
|
|
static void init_board(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
int i,j;
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->srand(*rb->current_tick);
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<12;i++)
|
|
|
|
{ /* Hopefully about 50% each colour */
|
2014-08-28 23:19:08 +00:00
|
|
|
for(j=0;j<BOARD_SIZE+2;j++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
if((i<1)||(j<1)||(i>BOARD_SIZE)||(j>BOARD_SIZE))
|
2007-08-02 12:55:14 +00:00
|
|
|
board[i][j].colour = -1; /* Unset */
|
|
|
|
else
|
|
|
|
board[i][j].colour = rb->rand()%2;
|
|
|
|
board[i][j].tank = false;
|
|
|
|
board[i][j].plane = false;
|
|
|
|
board[i][j].nuke = false;
|
|
|
|
board[i][j].ind = false;
|
|
|
|
board[i][j].farm = false;
|
|
|
|
board[i][j].men = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
while(compres.farms < superdom_settings.compstartfarms)
|
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
i = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
j = rb->rand()%BOARD_SIZE + 1;
|
2014-08-27 00:11:53 +00:00
|
|
|
if((board[i][j].colour == COLOUR_DARK) && (board[i][j].farm == false))
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
board[i][j].farm = true;
|
|
|
|
compres.farms++;
|
|
|
|
}
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
while(compres.inds < superdom_settings.compstartinds)
|
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
i = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
j = rb->rand()%BOARD_SIZE + 1;
|
2014-08-27 00:11:53 +00:00
|
|
|
if((board[i][j].colour == COLOUR_DARK) && (board[i][j].ind == false))
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
board[i][j].ind = true;
|
|
|
|
compres.inds++;
|
|
|
|
}
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
while(humanres.farms < superdom_settings.humanstartfarms)
|
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
i = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
j = rb->rand()%BOARD_SIZE + 1;
|
2014-08-27 00:11:53 +00:00
|
|
|
if((board[i][j].colour == COLOUR_LIGHT)&&(board[i][j].farm == false))
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
board[i][j].farm = true;
|
|
|
|
humanres.farms++;
|
|
|
|
}
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
while(humanres.inds < superdom_settings.humanstartinds)
|
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
i = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
j = rb->rand()%BOARD_SIZE + 1;
|
2014-08-27 00:11:53 +00:00
|
|
|
if((board[i][j].colour == COLOUR_LIGHT) && (board[i][j].ind == false))
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
board[i][j].ind = true;
|
|
|
|
humanres.inds++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
void draw_board(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
int i,j;
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->lcd_clear_display();
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=1;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
for(j=1;j<=BOARD_SIZE;j++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
|
|
|
if(board[i][j].colour == COLOUR_DARK)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_set_foreground(LCD_DARKGRAY);
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_set_foreground(LCD_LIGHTGRAY);
|
|
|
|
}
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->lcd_fillrect(MARGIN+(BOX_WIDTH*(i-1)),
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1)), BOX_WIDTH,
|
|
|
|
BOX_HEIGHT);
|
2007-08-02 12:55:14 +00:00
|
|
|
#if LCD_DEPTH != 16
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_BG | DRMODE_INVERSEVID);
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[i][j].ind)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
MY_BITMAP_PART(superdom_boarditems,
|
2014-08-27 00:08:17 +00:00
|
|
|
board[i][j].colour?ICON_WIDTH:0, 0, ICON_STRIDE,
|
2007-08-02 12:55:14 +00:00
|
|
|
#if LCD_WIDTH > LCD_HEIGHT
|
2014-08-27 00:08:17 +00:00
|
|
|
MARGIN+(BOX_WIDTH*(i-1))+1,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+ICON_HEIGHT+1,
|
2007-08-02 12:55:14 +00:00
|
|
|
#else
|
2014-08-27 00:08:17 +00:00
|
|
|
MARGIN+(BOX_WIDTH*(i-1))+1+ICON_WIDTH,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+1,
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_WIDTH, ICON_HEIGHT);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[i][j].farm)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
MY_BITMAP_PART(superdom_boarditems,
|
2014-08-27 00:08:17 +00:00
|
|
|
board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT,
|
|
|
|
ICON_STRIDE, MARGIN+(BOX_WIDTH*(i-1))+1,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+1,
|
|
|
|
ICON_WIDTH, ICON_HEIGHT);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[i][j].tank)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
MY_BITMAP_PART(superdom_boarditems,
|
2014-08-27 00:08:17 +00:00
|
|
|
board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*2,
|
|
|
|
ICON_STRIDE, MARGIN+(BOX_WIDTH*(i-1))+ICON_WIDTH+1,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+ICON_HEIGHT+1,
|
|
|
|
ICON_WIDTH, ICON_HEIGHT);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[i][j].men)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
MY_BITMAP_PART(superdom_boarditems,
|
2014-08-27 00:08:17 +00:00
|
|
|
board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*3,
|
2007-08-02 12:55:14 +00:00
|
|
|
#if LCD_WIDTH > LCD_HEIGHT
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_STRIDE, MARGIN+(BOX_WIDTH*(i-1))+ICON_WIDTH+1,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+1,
|
2007-08-02 12:55:14 +00:00
|
|
|
#else
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_STRIDE, MARGIN+(BOX_WIDTH*(i-1))+1,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+1+ICON_HEIGHT,
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_WIDTH, ICON_HEIGHT);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[i][j].plane)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
MY_BITMAP_PART(superdom_boarditems,
|
2014-08-27 00:08:17 +00:00
|
|
|
board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*4,
|
2007-08-02 12:55:14 +00:00
|
|
|
#if LCD_WIDTH > LCD_HEIGHT
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_STRIDE,MARGIN+(BOX_WIDTH*(i-1))+ICON_WIDTH*2+1,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+ICON_HEIGHT+1,
|
2007-08-02 12:55:14 +00:00
|
|
|
#else
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_STRIDE,MARGIN+(BOX_WIDTH*(i-1))+ICON_WIDTH+1,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+ICON_HEIGHT*2+1,
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_WIDTH, ICON_HEIGHT);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[i][j].nuke)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
MY_BITMAP_PART(superdom_boarditems,
|
2014-08-27 00:08:17 +00:00
|
|
|
board[i][j].colour?ICON_WIDTH:0, ICON_HEIGHT*5,
|
2007-08-02 12:55:14 +00:00
|
|
|
#if LCD_WIDTH > LCD_HEIGHT
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_STRIDE,MARGIN+(BOX_WIDTH*(i-1))+ICON_WIDTH*2+1,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+1,
|
2007-08-02 12:55:14 +00:00
|
|
|
#else
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_STRIDE,MARGIN+(BOX_WIDTH*(i-1))+1,
|
|
|
|
MARGIN+(BOX_HEIGHT*(j-1))+ICON_HEIGHT*2+1,
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
2014-08-27 00:08:17 +00:00
|
|
|
ICON_WIDTH, ICON_HEIGHT);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
#if LCD_DEPTH != 16
|
2009-08-02 14:30:09 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
2014-08-27 00:11:53 +00:00
|
|
|
/* Draw Horizontal lines */
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=0;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
rb->lcd_hline(MARGIN, MARGIN+(BOX_WIDTH*BOARD_SIZE), MARGIN+(BOX_HEIGHT*i));
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
/* Draw Vertical lines */
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=0;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
rb->lcd_vline(MARGIN+(BOX_WIDTH*i), MARGIN, MARGIN+(BOX_HEIGHT*BOARD_SIZE));
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
rb->lcd_update();
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int calc_strength(int colour, int x, int y)
|
|
|
|
{
|
2007-08-05 09:20:20 +00:00
|
|
|
int a, b, score=0;
|
2014-08-27 00:11:53 +00:00
|
|
|
for (a = -1; a < 2; a++)
|
|
|
|
{
|
|
|
|
for (b = -1; b < 2; b++)
|
|
|
|
{
|
|
|
|
if(board[x+a][y+b].colour==colour)
|
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
if(a && b) /* diagonally adjacent, give less influence */
|
|
|
|
{
|
|
|
|
score += 5;
|
|
|
|
if(board[x + a][y + b].tank || board[x + a][y + b].farm)
|
|
|
|
score += 15;
|
|
|
|
if(board[x + a][y + b].plane || board[x + a][y + b].ind)
|
|
|
|
score += 20;
|
|
|
|
if(board[x + a][y + b].nuke)
|
|
|
|
score += 10;
|
|
|
|
if(board[x + a][y + b].men)
|
|
|
|
score += (board[x + a][y + b].men*133/1000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
score += 10;
|
|
|
|
if(board[x + a][y + b].tank || board[x + a][y + b].farm)
|
|
|
|
score += 30;
|
|
|
|
if(board[x + a][y + b].plane || board[x + a][y + b].ind)
|
|
|
|
score += 40;
|
|
|
|
if(board[x + a][y + b].nuke)
|
|
|
|
score += 20;
|
|
|
|
if(board[x + a][y + b].men)
|
|
|
|
score += (board[x + a][y + b].men*133/1000);
|
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
void gen_interest(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* Interest should be around 10% */
|
|
|
|
int interest = 7+rb->rand()%6;
|
|
|
|
humanres.bank = humanres.bank+(interest*humanres.bank/100);
|
2014-08-27 00:11:53 +00:00
|
|
|
/* Different interest for AI player */
|
|
|
|
interest = 7+rb->rand()%6;
|
2009-05-16 08:20:54 +00:00
|
|
|
compres.bank = compres.bank+(interest*compres.bank/100);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
void draw_cursor(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->lcd_fillrect(MARGIN+((cursor.x-1)*BOX_WIDTH),
|
|
|
|
MARGIN+((cursor.y-1)*BOX_HEIGHT), BOX_WIDTH+1, BOX_HEIGHT+1);
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
|
|
|
rb->lcd_update();
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
void gen_resources(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
int inccash = 0;
|
|
|
|
int incfood = 0;
|
2009-05-16 08:20:54 +00:00
|
|
|
int ratecash = 0;
|
|
|
|
int ratefood = 0;
|
2007-08-02 12:55:14 +00:00
|
|
|
int i;
|
2009-05-16 08:20:54 +00:00
|
|
|
gen_interest();
|
2007-08-02 12:55:14 +00:00
|
|
|
/* Generate Human's resources */
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<humanres.inds;i++)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
inccash += (300+rb->rand()%200);
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<humanres.farms;i++)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
incfood += (200+rb->rand()%200);
|
|
|
|
}
|
|
|
|
if(humanres.inds)
|
|
|
|
ratecash = inccash/humanres.inds;
|
|
|
|
if(humanres.farms)
|
|
|
|
ratefood = incfood/humanres.farms;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(ratecash > 450)
|
|
|
|
{
|
|
|
|
if(ratefood > 350)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ*2, "Patriotism sweeps the land, all production"
|
|
|
|
" is up this year!");
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ*2, "Factories working at maximum efficiency,"
|
|
|
|
" cash production up this year!");
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else if(ratecash > 350)
|
|
|
|
{
|
|
|
|
if(ratefood > 350)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ*2, "Record crop harvest this year!");
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else if(ratefood > 250)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ*2, "Production continues as normal");
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ*2, "Spoilage of crops leads to reduced farm"
|
|
|
|
" output this year");
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(ratefood > 350)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ*2, "Record crop harvest this year!");
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else if(ratefood > 250)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ*2, "Factory unions introduced. Industrial"
|
|
|
|
" production is down this year.");
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ*2, "Internet created. All production is down"
|
|
|
|
" due to time wasted.");
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:08:17 +00:00
|
|
|
}
|
|
|
|
humanres.cash += inccash;
|
|
|
|
humanres.food += incfood;
|
2007-08-02 12:55:14 +00:00
|
|
|
|
|
|
|
/* Generate Computer's resources */
|
2014-08-27 00:08:17 +00:00
|
|
|
inccash = 0;
|
|
|
|
incfood = 0;
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<compres.inds;i++)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
inccash += (300+rb->rand()%200);
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<compres.farms;i++)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
incfood += (200+rb->rand()%200);
|
|
|
|
}
|
|
|
|
compres.cash += inccash;
|
|
|
|
compres.food += incfood;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static void update_score(void)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
int strength;
|
2014-08-28 23:19:08 +00:00
|
|
|
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID);
|
|
|
|
rb->lcd_fillrect(5,LCD_HEIGHT-20,105,20);
|
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2009-05-16 08:20:54 +00:00
|
|
|
strength = calc_strength(COLOUR_LIGHT, cursor.x, cursor.y);
|
2010-08-28 21:46:45 +00:00
|
|
|
rb->lcd_putsxyf(5,LCD_HEIGHT-20,"Your power: %d.%d",strength/10,strength%10);
|
2009-05-16 08:20:54 +00:00
|
|
|
strength = calc_strength(COLOUR_DARK, cursor.x, cursor.y);
|
2010-08-28 21:46:45 +00:00
|
|
|
rb->lcd_putsxyf(5,LCD_HEIGHT-10,"Comp power: %d.%d",strength/10,strength%10);
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->lcd_setfont(FONT_UI);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int settings_menu(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
int selection = 0;
|
|
|
|
|
2009-08-02 14:30:09 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Super Domination Settings", NULL,
|
2014-08-27 00:08:17 +00:00
|
|
|
"Computer starting farms", "Computer starting factories",
|
|
|
|
"Human starting farms", "Human starting factories",
|
2014-08-31 01:02:56 +00:00
|
|
|
"Starting cash", "Starting food", "Computer difficulty","Food spoilage", "Persistent units", "Moves per turn");
|
2009-05-16 08:20:54 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
case 0:
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->set_int("Computer starting farms", "", UNIT_INT,
|
|
|
|
&superdom_settings.compstartfarms, NULL,
|
|
|
|
1, 0, 5, NULL);
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->set_int("Computer starting factories", "", UNIT_INT,
|
|
|
|
&superdom_settings.compstartinds, NULL,
|
|
|
|
1, 0, 5, NULL);
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->set_int("Human starting farms", "", UNIT_INT,
|
|
|
|
&superdom_settings.humanstartfarms, NULL,
|
|
|
|
1, 0, 5, NULL);
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->set_int("Human starting factories", "", UNIT_INT,
|
2014-08-27 00:08:17 +00:00
|
|
|
&superdom_settings.humanstartinds, NULL,
|
|
|
|
1, 0, 5, NULL);
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->set_int("Starting cash", "", UNIT_INT,
|
|
|
|
&superdom_settings.startcash, NULL,
|
|
|
|
250, 0, 5000, NULL);
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->set_int("Starting food", "", UNIT_INT,
|
|
|
|
&superdom_settings.startfood, NULL,
|
|
|
|
250, 0, 5000, NULL);
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2014-08-28 23:19:08 +00:00
|
|
|
{
|
|
|
|
static const struct opt_items difficulty_options[3]={
|
2014-08-31 00:59:20 +00:00
|
|
|
{"Easy", -1},
|
|
|
|
{"Intermediate", -1},
|
|
|
|
{"Hard", -1}
|
2014-08-28 23:19:08 +00:00
|
|
|
};
|
2014-08-31 00:59:20 +00:00
|
|
|
static int sel=1;
|
|
|
|
rb->set_option("Computer difficulty", &sel,
|
2014-08-28 23:19:08 +00:00
|
|
|
INT, difficulty_options, 3, NULL);
|
2014-08-31 00:59:20 +00:00
|
|
|
superdom_settings.compdiff=sel+1;
|
2014-08-28 23:19:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
rb->set_bool_options("Food spoilage", &superdom_settings.spoil_enabled, "Enabled",
|
|
|
|
0, "Disabled", 0, NULL);
|
|
|
|
break;
|
|
|
|
case 8:
|
2014-08-31 01:02:56 +00:00
|
|
|
rb->set_bool_options("Persistent units", &superdom_settings.persistent_units, "Enabled", 0,
|
|
|
|
"Disabled", 0, NULL);
|
|
|
|
break;
|
|
|
|
case 9:
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->set_int("Moves per turn", "", UNIT_INT,
|
|
|
|
&superdom_settings.movesperturn, NULL,
|
|
|
|
1, 1, 5, NULL);
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
|
|
|
case MENU_ATTACHED_USB:
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_USB;
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
2009-05-16 08:20:54 +00:00
|
|
|
case GO_TO_PREVIOUS:
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2009-05-16 08:20:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int superdom_help(void)
|
|
|
|
{
|
2014-08-31 16:52:16 +00:00
|
|
|
static char* help_text[] = {"Super Domination","",
|
|
|
|
"Aim", "",
|
|
|
|
"Super", "Domination", "is", "a", "turn-based",
|
|
|
|
"strategy", "game", "where", "the", "aim", "is",
|
|
|
|
"to", "overpower", "the", "computer.", "", "",
|
|
|
|
"How", "to", "Play", "",
|
|
|
|
"Each", "year", "you", "are", "allocated", "an", "amount", "of", "cash",
|
|
|
|
"and", "food,", "depending", "on", "how", "many", "farms", "and",
|
|
|
|
"factories", "you", "control.", "",
|
|
|
|
"Use", "this", "cash", "and", "food", "to", "build", "and", "feed", "your",
|
|
|
|
"army.", "Each", "tile", "has", "a", "strength,", "calculated", "by",
|
|
|
|
"the", "ownership", "of", "surrounding", "tiles,", "and", "the", "type",
|
|
|
|
"and", "number", "of", "troops", "on", "them."};
|
2014-09-14 03:16:10 +00:00
|
|
|
static struct style_text style[]={
|
2014-08-31 16:52:16 +00:00
|
|
|
{0, TEXT_CENTER|TEXT_UNDERLINE},
|
|
|
|
{2, C_RED},
|
|
|
|
{21, C_RED},
|
|
|
|
{22, C_RED},
|
|
|
|
{23, C_RED},
|
|
|
|
LAST_STYLE_ITEM
|
2008-04-20 19:33:31 +00:00
|
|
|
};
|
2014-08-27 00:11:53 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
rb->lcd_set_foreground(LCD_WHITE);
|
|
|
|
rb->lcd_set_background(LCD_BLACK);
|
|
|
|
#endif
|
2014-08-31 16:52:16 +00:00
|
|
|
int ret=display_text(ARRAYLEN(help_text), help_text, style, NULL, true);
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
rb->lcd_set_background(LCD_WHITE);
|
|
|
|
#endif
|
|
|
|
if(ret)
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_USB;
|
|
|
|
return RET_VAL_OK;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int start_menu(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
int selection = 0;
|
2009-08-02 14:30:09 +00:00
|
|
|
|
|
|
|
MENUITEM_STRINGLIST(menu, "Super Domination Menu", NULL,
|
2014-08-27 00:08:17 +00:00
|
|
|
"Play Super Domination", "Settings",
|
|
|
|
"Help", "Playback Control", "Quit");
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
|
|
|
return RET_VAL_OK; /* start playing */
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if(settings_menu()==RET_VAL_USB)
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if(superdom_help()==RET_VAL_USB)
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if(playback_control(NULL))
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
return RET_VAL_QUIT_ERR;
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int save_game(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
int fd;
|
|
|
|
char savepath[MAX_PATH];
|
|
|
|
|
|
|
|
rb->snprintf(savepath, sizeof(savepath), "/Savegame.ssg");
|
2020-07-21 06:33:53 +00:00
|
|
|
if(rb->kbd_input(savepath, MAX_PATH, NULL))
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
DEBUGF("Keyboard input failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-05-06 17:35:13 +00:00
|
|
|
fd = rb->open(savepath, O_WRONLY|O_CREAT, 0666);
|
2007-08-02 12:55:14 +00:00
|
|
|
DEBUGF("savepath: %s\n", savepath);
|
2014-08-27 00:11:53 +00:00
|
|
|
if(fd < 0)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
DEBUGF("Couldn't create/open file\n");
|
|
|
|
return -1;
|
2009-07-14 13:03:17 +00:00
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->write(fd, "SSGv3", 5);
|
|
|
|
rb->write(fd, &gamestate, sizeof(gamestate));
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->write(fd, &humanres.cash, sizeof(humanres.cash));
|
|
|
|
rb->write(fd, &humanres.food, sizeof(humanres.food));
|
|
|
|
rb->write(fd, &humanres.bank, sizeof(humanres.bank));
|
|
|
|
rb->write(fd, &humanres.planes, sizeof(humanres.planes));
|
|
|
|
rb->write(fd, &humanres.tanks, sizeof(humanres.tanks));
|
|
|
|
rb->write(fd, &humanres.men, sizeof(humanres.men));
|
|
|
|
rb->write(fd, &humanres.nukes, sizeof(humanres.nukes));
|
|
|
|
rb->write(fd, &humanres.inds, sizeof(humanres.inds));
|
|
|
|
rb->write(fd, &humanres.farms, sizeof(humanres.farms));
|
|
|
|
rb->write(fd, &humanres.moves, sizeof(humanres.moves));
|
|
|
|
rb->write(fd, &compres.cash, sizeof(compres.cash));
|
|
|
|
rb->write(fd, &compres.food, sizeof(compres.food));
|
|
|
|
rb->write(fd, &compres.bank, sizeof(compres.bank));
|
|
|
|
rb->write(fd, &compres.planes, sizeof(compres.planes));
|
|
|
|
rb->write(fd, &compres.tanks, sizeof(compres.tanks));
|
|
|
|
rb->write(fd, &compres.men, sizeof(compres.men));
|
|
|
|
rb->write(fd, &compres.nukes, sizeof(compres.nukes));
|
|
|
|
rb->write(fd, &compres.inds, sizeof(compres.inds));
|
|
|
|
rb->write(fd, &compres.farms, sizeof(compres.farms));
|
|
|
|
rb->write(fd, &compres.moves, sizeof(compres.moves));
|
|
|
|
rb->write(fd, board, sizeof(board));
|
|
|
|
rb->write(fd, &superdom_settings.compstartfarms, sizeof(int));
|
|
|
|
rb->write(fd, &superdom_settings.compstartinds, sizeof(int));
|
|
|
|
rb->write(fd, &superdom_settings.humanstartfarms, sizeof(int));
|
2010-02-04 12:50:13 +00:00
|
|
|
rb->write(fd, &superdom_settings.humanstartinds, sizeof(int));
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->write(fd, &superdom_settings.startcash, sizeof(int));
|
|
|
|
rb->write(fd, &superdom_settings.startfood, sizeof(int));
|
|
|
|
rb->write(fd, &superdom_settings.movesperturn, sizeof(int));
|
|
|
|
rb->close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int ingame_menu(void)
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Super Domination Menu", NULL,
|
2014-08-27 00:08:17 +00:00
|
|
|
"Return to game", "Save Game",
|
|
|
|
"Playback Control", "Quit");
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(rb->do_menu(&menu, NULL, NULL, false))
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
|
|
|
return RET_VAL_OK;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if(!save_game())
|
|
|
|
rb->splash(HZ, "Game saved");
|
|
|
|
else
|
|
|
|
rb->splash(HZ, "Error in save");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if(playback_control(NULL))
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_USB;
|
2014-08-27 00:08:17 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
return RET_VAL_QUIT_ERR;
|
|
|
|
break;
|
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
case GO_TO_PREVIOUS:
|
|
|
|
return RET_VAL_OK;
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int get_number(char* param, int* value, int max)
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
static const char *button_labels[4][3] = {
|
|
|
|
{ "1", "2", "3" },
|
|
|
|
{ "4", "5", "6" },
|
|
|
|
{ "7", "8", "9" },
|
2014-08-27 00:11:53 +00:00
|
|
|
{ "DEL", "0", "OK" }
|
2009-08-02 14:30:09 +00:00
|
|
|
};
|
2009-05-16 08:20:54 +00:00
|
|
|
int i,j,x=0,y=0;
|
|
|
|
int height, width;
|
2010-02-05 15:02:22 +00:00
|
|
|
int button = 0, ret = RET_VAL_OK;
|
|
|
|
bool done = false;
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_clear_display();
|
2014-08-27 00:11:53 +00:00
|
|
|
rb->lcd_getstringsize("DEL", &width, &height);
|
2009-08-02 14:30:09 +00:00
|
|
|
if(width > NUM_BOX_WIDTH || height > NUM_BOX_HEIGHT)
|
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
2007-08-02 12:55:14 +00:00
|
|
|
/* Draw a 3x4 grid */
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<=3;i++)
|
|
|
|
{ /* Vertical lines */
|
2008-04-12 09:51:16 +00:00
|
|
|
rb->lcd_vline(NUM_MARGIN_X+(NUM_BOX_WIDTH*i), NUM_MARGIN_Y,
|
|
|
|
NUM_MARGIN_Y+(4*NUM_BOX_HEIGHT));
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
/* Horizontal lines */
|
|
|
|
for(i=0;i<=4;i++)
|
|
|
|
{
|
2008-04-12 09:51:16 +00:00
|
|
|
rb->lcd_hline(NUM_MARGIN_X, NUM_MARGIN_X+(3*NUM_BOX_WIDTH),
|
|
|
|
NUM_MARGIN_Y+(NUM_BOX_HEIGHT*i));
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<4;i++)
|
|
|
|
{
|
|
|
|
for(j=0;j<3;j++)
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
rb->lcd_getstringsize(button_labels[i][j], &width, &height);
|
2014-08-27 00:11:53 +00:00
|
|
|
rb->lcd_putsxy(NUM_MARGIN_X+(j*NUM_BOX_WIDTH)+NUM_BOX_WIDTH/2-width/2,
|
|
|
|
NUM_MARGIN_Y+(i*NUM_BOX_HEIGHT)+NUM_BOX_HEIGHT/2-height/2,
|
|
|
|
button_labels[i][j]);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-28 21:46:45 +00:00
|
|
|
rb->lcd_putsxyf(NUM_MARGIN_X+10, NUM_MARGIN_Y+4*NUM_BOX_HEIGHT+10,"%d",*value);
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_getstringsize(param, &width, &height);
|
2009-08-02 14:30:09 +00:00
|
|
|
if(width < LCD_WIDTH)
|
|
|
|
rb->lcd_putsxy((LCD_WIDTH-width)/2, (NUM_MARGIN_Y-height)/2, param);
|
|
|
|
else
|
|
|
|
rb->lcd_puts_scroll(0, (NUM_MARGIN_Y/height-1)/2, param);
|
2014-08-27 00:11:53 +00:00
|
|
|
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x),
|
|
|
|
NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y),
|
|
|
|
NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1);
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
|
|
|
rb->lcd_update();
|
2014-08-27 00:11:53 +00:00
|
|
|
|
|
|
|
while(!done)
|
|
|
|
{
|
|
|
|
button=pluginlib_getaction(-1, plugin_contexts, ARRAYLEN(plugin_contexts));
|
2009-08-02 14:30:09 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
|
|
|
rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x),
|
2014-08-27 00:08:17 +00:00
|
|
|
NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y),
|
|
|
|
NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1);
|
2009-08-02 14:30:09 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(button)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case SUPERDOM_OK:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(y!=3)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
*value *= 10;
|
|
|
|
*value += button_labels[y][x][0] - '0';
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else if(x==0)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
*value /= 10;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else if(x==1)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
*value *= 10;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else if(x==2)
|
|
|
|
{
|
2010-02-05 15:02:22 +00:00
|
|
|
done = true;
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
2014-08-27 00:08:17 +00:00
|
|
|
}
|
|
|
|
if ((unsigned) *value > (unsigned) max)
|
|
|
|
*value = max;
|
|
|
|
rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID);
|
|
|
|
rb->lcd_fillrect(0, NUM_MARGIN_Y+4*NUM_BOX_HEIGHT+10,
|
|
|
|
LCD_WIDTH, 30);
|
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
|
|
|
rb->lcd_putsxyf(NUM_MARGIN_X+10,NUM_MARGIN_Y+4*NUM_BOX_HEIGHT+10,
|
|
|
|
"%d", *value);
|
|
|
|
break;
|
|
|
|
case SUPERDOM_CANCEL:
|
|
|
|
*value = 0;
|
|
|
|
done = true;
|
|
|
|
ret = RET_VAL_QUIT_ERR;
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
#if CONFIG_KEYPAD != IRIVER_H10_PAD
|
2014-08-27 00:08:17 +00:00
|
|
|
case SUPERDOM_LEFT:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(x==0)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
x=2;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
x--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SUPERDOM_RIGHT:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(x==2)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
x=0;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
x++;
|
|
|
|
}
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
2014-08-27 00:08:17 +00:00
|
|
|
case SUPERDOM_UP:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(y==0)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
#if CONFIG_KEYPAD == IRIVER_H10_PAD
|
2014-08-27 00:08:17 +00:00
|
|
|
if(x > 0)
|
|
|
|
x--;
|
|
|
|
else
|
|
|
|
x=2;
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
2014-08-27 00:08:17 +00:00
|
|
|
y=3;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
y--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SUPERDOM_DOWN:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(y==3)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
#if CONFIG_KEYPAD == IRIVER_H10_PAD
|
2014-08-27 00:08:17 +00:00
|
|
|
if(x < 2)
|
|
|
|
x++;
|
|
|
|
else
|
|
|
|
x=0;
|
2014-08-27 00:11:53 +00:00
|
|
|
#endif /* CONFIG_KEYPAD == IRIVER_H10_PAD */
|
2014-08-27 00:08:17 +00:00
|
|
|
y=0;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
y++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
2014-08-27 00:08:17 +00:00
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
ret = RET_VAL_USB;
|
|
|
|
}
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x),
|
|
|
|
NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y),
|
|
|
|
NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1);
|
2009-08-02 14:30:09 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
rb->lcd_setfont(FONT_UI);
|
2013-04-03 14:33:23 +00:00
|
|
|
rb->lcd_scroll_stop();
|
2010-02-05 15:02:22 +00:00
|
|
|
if (ret == RET_VAL_QUIT_ERR)
|
|
|
|
rb->splash(HZ, "Cancelled");
|
|
|
|
return ret;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static bool tile_has_item(int type, int x, int y)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
|
|
|
return (board[x][y].men > 0);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return board[x][y].tank;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return board[x][y].plane;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
return board[x][y].farm;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
return board[x][y].ind;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
return board[x][y].nuke;
|
|
|
|
break;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int buy_resources(int colour, int type, int x, int y, int nummen)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
const char *itemnames[][6] = {
|
|
|
|
{
|
|
|
|
"them",
|
|
|
|
"the tank",
|
|
|
|
"the plane",
|
|
|
|
"the farm",
|
|
|
|
"the industrial plant",
|
|
|
|
"the nuke",
|
2014-08-27 00:11:53 +00:00
|
|
|
},
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
"place men",
|
|
|
|
"place a tank",
|
|
|
|
"place a plane",
|
|
|
|
"build a farm",
|
|
|
|
"build an industrial plant",
|
|
|
|
"place a nuke",
|
2014-08-27 00:11:53 +00:00
|
|
|
},
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
NULL,
|
|
|
|
"a tank",
|
|
|
|
"a plane",
|
|
|
|
"a farm",
|
|
|
|
"an industrial plant",
|
|
|
|
"a nuke",
|
|
|
|
},
|
|
|
|
};
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2009-05-16 08:20:54 +00:00
|
|
|
bool human = (colour == COLOUR_LIGHT);
|
|
|
|
int price = 0;
|
2009-08-02 14:30:09 +00:00
|
|
|
int temp;
|
2009-05-16 08:20:54 +00:00
|
|
|
struct resources *res;
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
if(human)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
res = &humanres;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
res = &compres;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0: /* men */
|
2014-08-27 00:11:53 +00:00
|
|
|
price = PRICE_MEN*nummen;
|
2014-08-27 00:08:17 +00:00
|
|
|
break;
|
|
|
|
case 1: /* tank */
|
2014-08-27 00:11:53 +00:00
|
|
|
price = PRICE_TANK;
|
2014-08-27 00:08:17 +00:00
|
|
|
break;
|
|
|
|
case 2: /* plane */
|
2014-08-27 00:11:53 +00:00
|
|
|
price = PRICE_PLANE;
|
2014-08-27 00:08:17 +00:00
|
|
|
break;
|
|
|
|
case 3: /* Farm */
|
2014-08-27 00:11:53 +00:00
|
|
|
price = PRICE_FARM;
|
2014-08-27 00:08:17 +00:00
|
|
|
break;
|
|
|
|
case 4: /* Factory */
|
2014-08-27 00:11:53 +00:00
|
|
|
price = PRICE_FACTORY;
|
2014-08-27 00:08:17 +00:00
|
|
|
break;
|
|
|
|
case 5: /* nuke */
|
2014-08-27 00:11:53 +00:00
|
|
|
price = PRICE_NUKE;
|
2014-08-27 00:08:17 +00:00
|
|
|
break;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(res->cash < price)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splash(HZ, "Not enough money!");
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(human)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->splashf(HZ, "Where do you want to place %s?", itemnames[0][type]);
|
2009-08-02 14:30:09 +00:00
|
|
|
if((temp = select_square()) != RET_VAL_OK)
|
|
|
|
return temp;
|
2009-05-16 08:20:54 +00:00
|
|
|
x = cursor.x;
|
|
|
|
y = cursor.y;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[x][y].colour != colour)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splashf(HZ, "Can't %s on enemy territory", itemnames[1][type]);
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(type != 0 && tile_has_item(type, x, y))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splashf(HZ, "There is already %s there", itemnames[2][type]);
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
|
|
|
board[x][y].men += nummen;
|
|
|
|
res->men += nummen;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
board[x][y].tank = true;
|
|
|
|
res->tanks++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
board[x][y].plane = true;
|
|
|
|
res->planes++;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
board[x][y].farm = true;
|
|
|
|
res->farms++;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
board[x][y].ind = true;
|
|
|
|
res->inds++;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
board[x][y].nuke = true;
|
|
|
|
res->nukes++;
|
|
|
|
break;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
res->cash -= price;
|
|
|
|
|
|
|
|
draw_board();
|
|
|
|
rb->sleep(HZ);
|
|
|
|
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int buy_resources_menu(void)
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
int selection = 0,nummen;
|
2009-05-16 08:20:54 +00:00
|
|
|
|
2009-08-02 14:30:09 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Buy Resources", NULL,
|
2014-08-27 00:11:53 +00:00
|
|
|
"Buy men ($" PRICE_MEN_STR ")", "Buy tank ($" PRICE_TANK_STR ")", "Buy plane ($" PRICE_PLANE_STR ")",
|
|
|
|
"Buy Farm ($" PRICE_FARM_STR ")", "Buy Factory ($" PRICE_FACTORY_STR ")",
|
|
|
|
"Buy Nuke ($" PRICE_NUKE_STR ")",
|
2014-08-27 00:08:17 +00:00
|
|
|
"Finish buying");
|
2009-05-16 08:20:54 +00:00
|
|
|
|
|
|
|
while(1) {
|
2009-08-02 14:30:09 +00:00
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false)) {
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
|
|
|
nummen = 0;
|
|
|
|
if(get_number("How many men would you like?", &nummen,
|
|
|
|
humanres.cash) == RET_VAL_USB)
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_USB;
|
2014-08-27 00:08:17 +00:00
|
|
|
if(!nummen)
|
2009-05-16 08:20:54 +00:00
|
|
|
break;
|
2014-08-27 00:08:17 +00:00
|
|
|
/* fall through */
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(buy_resources(COLOUR_LIGHT, selection, 0, 0, nummen)== RET_VAL_USB)
|
2014-08-27 00:08:17 +00:00
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
return RET_VAL_OK;
|
|
|
|
break;
|
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
case GO_TO_PREVIOUS:
|
|
|
|
return RET_VAL_OK;
|
|
|
|
break;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
|
2012-04-14 15:19:02 +00:00
|
|
|
static int move_unit(int colour, int type, int fromx, int fromy,
|
2014-08-27 00:11:53 +00:00
|
|
|
int tox, int toy, int nummen)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
const char *itemnames[][3] = {
|
|
|
|
{
|
|
|
|
"troops",
|
|
|
|
"the tank",
|
|
|
|
"the plane",
|
2014-08-27 00:11:53 +00:00
|
|
|
},
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
"any troops",
|
|
|
|
"a tank",
|
|
|
|
"a plane",
|
2014-08-27 00:11:53 +00:00
|
|
|
},
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
"the troops",
|
|
|
|
"the tank",
|
|
|
|
"the plane",
|
|
|
|
}
|
|
|
|
};
|
|
|
|
bool human = (colour == COLOUR_LIGHT);
|
2009-08-02 14:30:09 +00:00
|
|
|
int temp;
|
2009-05-16 08:20:54 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
if(human)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->splashf(HZ, "Select where you want to move %s from",
|
2014-08-27 00:08:17 +00:00
|
|
|
itemnames[0][type]);
|
2009-08-02 14:30:09 +00:00
|
|
|
if((temp = select_square()) != RET_VAL_OK)
|
|
|
|
return temp;
|
2009-05-16 08:20:54 +00:00
|
|
|
fromx = cursor.x;
|
|
|
|
fromy = cursor.y;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[fromx][fromy].colour != colour)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splash(HZ, "That isn't your territory");
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(!tile_has_item(type, fromx, fromy))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splashf(HZ, "You don't have %s there", itemnames[1][type]);
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(type == 0)
|
|
|
|
{
|
|
|
|
if(human)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
nummen = board[fromx][fromy].men;
|
2010-02-05 15:02:22 +00:00
|
|
|
if((temp = get_number("How many men do you want to move?", &nummen,
|
2014-08-27 00:08:17 +00:00
|
|
|
nummen)) != RET_VAL_OK)
|
2009-08-02 14:30:09 +00:00
|
|
|
return temp;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(nummen > board[fromx][fromy].men)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splash(HZ, "You don't have that many troops.");
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(human)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->splashf(HZ, "Select where you want to move %s to",
|
2014-08-27 00:08:17 +00:00
|
|
|
itemnames[2][type]);
|
2009-08-02 14:30:09 +00:00
|
|
|
if((temp = select_square()) != RET_VAL_OK)
|
|
|
|
return temp;
|
2009-05-16 08:20:54 +00:00
|
|
|
tox = cursor.x;
|
|
|
|
toy = cursor.y;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if((tox == fromx && toy == fromy) ||
|
|
|
|
board[tox][toy].colour != colour ||
|
|
|
|
(type != 2 && (abs(tox - fromx) > 1 ||
|
|
|
|
abs(toy - fromy) > 1)))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splash(HZ, "Invalid move");
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(type != 0 && tile_has_item(type, tox, toy))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splashf(HZ, "There is already %s there", itemnames[1][type]);
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
|
|
|
board[fromx][fromy].men -= nummen;
|
|
|
|
board[tox][toy].men += nummen;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
board[fromx][fromy].tank = false;
|
|
|
|
board[tox][toy].tank = true;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
board[fromx][fromy].plane = false;
|
|
|
|
board[tox][toy].plane = true;
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int move_unit_menu(void)
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
int selection = 0;
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2009-08-02 14:30:09 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Move unit", NULL,
|
2014-08-27 00:08:17 +00:00
|
|
|
"Move men", "Move tank", "Move plane");
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(move_unit(COLOUR_LIGHT, selection, 0, 0, 0, 0, 0))
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case RET_VAL_OK:
|
|
|
|
humanres.moves--;
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
2014-08-27 00:08:17 +00:00
|
|
|
case RET_VAL_USB:
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_USB;
|
2014-08-27 00:08:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
return RET_VAL_USB;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int launch_nuke(int colour, int nukex, int nukey, int targetx, int targety)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
bool human = (colour == COLOUR_LIGHT);
|
2009-08-02 14:30:09 +00:00
|
|
|
int temp;
|
2009-05-16 08:20:54 +00:00
|
|
|
struct resources *res;
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[nukex][nukey].colour != colour)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splash(HZ, "That isn't your territory");
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(! board[nukex][nukey].nuke)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
2014-08-27 00:11:53 +00:00
|
|
|
rb->splashf(HZ, "You don't have a nuke there");
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_QUIT_ERR;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(human)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->splash(HZ, "Select place to target with nuke");
|
2009-08-02 14:30:09 +00:00
|
|
|
if((temp = select_square()) != RET_VAL_OK)
|
|
|
|
return temp;
|
2009-05-16 08:20:54 +00:00
|
|
|
targetx = cursor.x;
|
|
|
|
targety = cursor.y;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(human)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
humanres.nukes--;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
compres.nukes--;
|
|
|
|
}
|
|
|
|
board[nukex][nukey].nuke = false;
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[targetx][targety].colour == COLOUR_LIGHT)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
res = &humanres;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
res = &compres;
|
|
|
|
}
|
|
|
|
res->men -= board[targetx][targety].men;
|
|
|
|
res->tanks -= board[targetx][targety].tank;
|
|
|
|
res->planes -= board[targetx][targety].plane;
|
|
|
|
res->nukes -= board[targetx][targety].nuke;
|
|
|
|
res->farms -= board[targetx][targety].farm;
|
|
|
|
res->inds -= board[targetx][targety].ind;
|
|
|
|
board[targetx][targety].men = 0;
|
|
|
|
board[targetx][targety].tank = false;
|
|
|
|
board[targetx][targety].plane = false;
|
|
|
|
board[targetx][targety].ind = false;
|
|
|
|
board[targetx][targety].nuke = false;
|
|
|
|
board[targetx][targety].farm = false;
|
|
|
|
/* TODO: Fallout carried by wind */
|
2014-08-30 14:21:25 +00:00
|
|
|
draw_board();
|
|
|
|
if(human)
|
|
|
|
rb->sleep(HZ*2);
|
|
|
|
else
|
|
|
|
rb->sleep(HZ);
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int movement_menu(void)
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
int selection = 0, temp;
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2009-08-02 14:30:09 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Movement", NULL,
|
2014-08-27 00:11:53 +00:00
|
|
|
"Move unit", "Buy additional moves ($" PRICE_MOVE_STR ")",
|
2014-08-27 00:08:17 +00:00
|
|
|
"Launch nuclear missile", "Check map",
|
|
|
|
"Finish moving", "Game menu");
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
case 0:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(humanres.moves)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
if(move_unit_menu()==RET_VAL_USB)
|
|
|
|
return RET_VAL_USB;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ, "You have no more moves left."
|
2014-08-27 00:11:53 +00:00
|
|
|
" You can buy more for $" PRICE_MOVE_STR " each.");
|
2014-08-27 00:08:17 +00:00
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(humanres.cash > PRICE_MOVE)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
humanres.moves++;
|
2014-08-27 00:11:53 +00:00
|
|
|
humanres.cash -= PRICE_MOVE;
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "You now have %d moves",
|
|
|
|
humanres.moves);
|
|
|
|
rb->splash(HZ, buf);
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->splash(HZ, "Not enough money!");
|
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(humanres.nukes==0)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ, "You do not have any nukes to launch");
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ, "Select place to launch nuke from");
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(select_square())
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case RET_VAL_OK:
|
|
|
|
if(launch_nuke(COLOUR_LIGHT, cursor.x, cursor.y,
|
|
|
|
0, 0) == RET_VAL_USB)
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
case RET_VAL_USB:
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-08-27 00:08:17 +00:00
|
|
|
if(select_square() == RET_VAL_USB)
|
|
|
|
return RET_VAL_USB;
|
2009-08-02 14:30:09 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2014-08-27 00:08:17 +00:00
|
|
|
return RET_VAL_OK;
|
2009-08-02 14:30:09 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2014-08-27 00:08:17 +00:00
|
|
|
if((temp = ingame_menu()) != RET_VAL_OK)
|
|
|
|
return temp;
|
2009-08-02 14:30:09 +00:00
|
|
|
break;
|
2014-08-27 00:08:17 +00:00
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
return RET_VAL_USB;
|
2009-08-02 14:30:09 +00:00
|
|
|
break;
|
2014-08-27 00:08:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return RET_VAL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* inventory_data(int selected_item, void * data,
|
2014-08-27 00:11:53 +00:00
|
|
|
char * buffer, size_t buffer_len)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
(void)data;
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(selected_item)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
|
|
|
rb->snprintf(buffer,buffer_len,"Men: %d", humanres.men);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rb->snprintf(buffer,buffer_len,"Tanks: %d", humanres.tanks);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rb->snprintf(buffer,buffer_len,"Planes: %d", humanres.planes);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
rb->snprintf(buffer,buffer_len,"Factories: %d", humanres.inds);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
rb->snprintf(buffer,buffer_len,"Farms: %d", humanres.farms);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
rb->snprintf(buffer,buffer_len,"Nukes: %d", humanres.nukes);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
rb->snprintf(buffer,buffer_len,"Cash: %d", humanres.cash);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
rb->snprintf(buffer,buffer_len,"Food: %d", humanres.food);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
rb->snprintf(buffer,buffer_len,"Bank: %d", humanres.bank);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
2009-08-02 14:30:09 +00:00
|
|
|
}
|
|
|
|
return buffer;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int show_inventory(void)
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
struct simplelist_info info;
|
|
|
|
rb->simplelist_info_init(&info, "Inventory", 9, NULL);
|
|
|
|
info.hide_selection = true;
|
|
|
|
info.get_name = inventory_data;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(rb->simplelist_show_list(&info))
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_USB;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int production_menu(void)
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
int selection = 0, temp;
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2009-08-02 14:30:09 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Production", NULL,
|
2014-08-27 00:08:17 +00:00
|
|
|
"Buy resources", "Show inventory", "Check map",
|
|
|
|
"Invest money", "Withdraw money",
|
|
|
|
"Finish turn", "Game menu");
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
|
|
|
if(buy_resources_menu() == RET_VAL_USB)
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_USB;
|
2014-08-27 00:08:17 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if(show_inventory() == RET_VAL_USB)
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if(select_square() == RET_VAL_USB)
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
temp = humanres.cash;
|
|
|
|
if(get_number("How much do you want to invest?", &temp,
|
|
|
|
humanres.cash) == RET_VAL_USB)
|
|
|
|
return RET_VAL_USB;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(temp > humanres.cash)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ, "You don't have that much cash to invest");
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
humanres.cash -= temp;
|
|
|
|
humanres.bank += temp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
temp = humanres.bank;
|
|
|
|
if(get_number("How much do you want to withdraw?", &temp,
|
|
|
|
humanres.bank) == RET_VAL_USB)
|
|
|
|
return RET_VAL_USB;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(temp > humanres.bank)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->splash(HZ, "You don't have that much cash to withdraw");
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
humanres.cash += temp;
|
|
|
|
humanres.bank -= temp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
return RET_VAL_OK;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if((temp = ingame_menu()) != RET_VAL_OK)
|
|
|
|
return temp;
|
|
|
|
break;
|
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
return RET_VAL_USB;
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static void init_resources(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
humanres.cash = superdom_settings.startcash;
|
|
|
|
humanres.food = superdom_settings.startfood;
|
|
|
|
humanres.tanks = 0;
|
|
|
|
humanres.planes = 0;
|
|
|
|
humanres.nukes = 0;
|
|
|
|
humanres.inds = 0;
|
|
|
|
humanres.farms = 0;
|
|
|
|
humanres.men = 0;
|
|
|
|
humanres.bank = 0;
|
|
|
|
humanres.moves = 0;
|
|
|
|
compres.cash = superdom_settings.startcash;
|
|
|
|
compres.food = superdom_settings.startfood;
|
|
|
|
compres.tanks = 0;
|
|
|
|
compres.planes = 0;
|
|
|
|
compres.nukes = 0;
|
|
|
|
compres.inds = 0;
|
|
|
|
compres.farms = 0;
|
|
|
|
compres.men = 0;
|
|
|
|
compres.bank = 0;
|
|
|
|
compres.moves = 0;
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int select_square(void)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
int button = 0;
|
2007-08-02 12:55:14 +00:00
|
|
|
draw_board();
|
|
|
|
draw_cursor();
|
|
|
|
update_score();
|
|
|
|
#if LCD_WIDTH >= 220
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
2010-08-28 21:46:45 +00:00
|
|
|
rb->lcd_putsxyf(125, LCD_HEIGHT-20,"Cash: %d", humanres.cash);
|
|
|
|
rb->lcd_putsxyf(125, LCD_HEIGHT-10,"Food: %d", humanres.food);
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->lcd_setfont(FONT_UI);
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
|
|
|
rb->lcd_update();
|
2014-08-27 00:11:53 +00:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
button=pluginlib_getaction(-1, plugin_contexts, ARRAYLEN(plugin_contexts));
|
|
|
|
switch(button)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case SUPERDOM_CANCEL:
|
|
|
|
rb->splash(HZ, "Cancelled");
|
|
|
|
return RET_VAL_QUIT_ERR;
|
|
|
|
break;
|
|
|
|
case SUPERDOM_OK:
|
|
|
|
return RET_VAL_OK;
|
|
|
|
break;
|
|
|
|
case SUPERDOM_LEFT:
|
2014-08-27 00:11:53 +00:00
|
|
|
case SUPERDOM_LEFT_REPEAT:
|
2014-08-27 00:08:17 +00:00
|
|
|
draw_cursor(); /* Deselect the current tile */
|
2014-08-27 00:11:53 +00:00
|
|
|
if(cursor.x>1)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
cursor.x--;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
cursor.x = BOARD_SIZE;
|
2014-08-27 00:08:17 +00:00
|
|
|
}
|
|
|
|
update_score();
|
|
|
|
draw_cursor();
|
|
|
|
break;
|
|
|
|
case SUPERDOM_RIGHT:
|
2014-08-27 00:11:53 +00:00
|
|
|
case SUPERDOM_RIGHT_REPEAT:
|
2014-08-27 00:08:17 +00:00
|
|
|
draw_cursor(); /* Deselect the current tile */
|
2014-08-28 23:19:08 +00:00
|
|
|
if(cursor.x<BOARD_SIZE)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
cursor.x++;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
cursor.x = 1;
|
|
|
|
}
|
|
|
|
update_score();
|
|
|
|
draw_cursor();
|
|
|
|
break;
|
|
|
|
case SUPERDOM_UP:
|
2014-08-27 00:11:53 +00:00
|
|
|
case SUPERDOM_UP_REPEAT:
|
2014-08-27 00:08:17 +00:00
|
|
|
draw_cursor(); /* Deselect the current tile */
|
2014-08-27 00:11:53 +00:00
|
|
|
if(cursor.y>1)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
cursor.y--;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
#if CONFIG_KEYPAD == IRIVER_H10_PAD
|
2014-08-27 00:08:17 +00:00
|
|
|
if(cursor.x > 1)
|
|
|
|
cursor.x--;
|
|
|
|
else
|
2014-08-28 23:19:08 +00:00
|
|
|
cursor.x = BOARD_SIZE;
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
2014-08-28 23:19:08 +00:00
|
|
|
cursor.y = BOARD_SIZE;
|
2014-08-27 00:08:17 +00:00
|
|
|
}
|
|
|
|
update_score();
|
|
|
|
draw_cursor();
|
|
|
|
break;
|
|
|
|
case SUPERDOM_DOWN:
|
2014-08-27 00:11:53 +00:00
|
|
|
case SUPERDOM_DOWN_REPEAT:
|
2014-08-27 00:08:17 +00:00
|
|
|
draw_cursor(); /* Deselect the current tile */
|
2014-08-28 23:19:08 +00:00
|
|
|
if(cursor.y<BOARD_SIZE)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
cursor.y++;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
#if CONFIG_KEYPAD == IRIVER_H10_PAD
|
2014-08-28 23:19:08 +00:00
|
|
|
if(cursor.x < BOARD_SIZE)
|
2014-08-27 00:08:17 +00:00
|
|
|
cursor.x++;
|
|
|
|
else
|
|
|
|
cursor.x = 1;
|
2007-08-02 12:55:14 +00:00
|
|
|
#endif
|
2014-08-27 00:08:17 +00:00
|
|
|
cursor.y = 1;
|
|
|
|
}
|
|
|
|
update_score();
|
|
|
|
draw_cursor();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
{
|
|
|
|
return RET_VAL_USB;
|
|
|
|
}
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int killmen(int colour)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
bool human = (colour == COLOUR_LIGHT);
|
2007-08-02 12:55:14 +00:00
|
|
|
int menkilled,i,j;
|
|
|
|
int percent;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(human)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
percent = (humanres.food*1000)/humanres.men;
|
|
|
|
humanres.food = 0;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
percent = (compres.food*1000)/compres.men;
|
|
|
|
compres.food = 0;
|
|
|
|
}
|
|
|
|
menkilled = 0;
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=1;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
for(j=1;j<=BOARD_SIZE;j++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
|
|
|
if(board[i][j].colour == colour)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
int nummen = ((board[i][j].men * percent)/1000);
|
|
|
|
menkilled += board[i][j].men - nummen;
|
|
|
|
board[i][j].men = nummen;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-14 13:03:17 +00:00
|
|
|
|
2007-08-02 12:55:14 +00:00
|
|
|
if(human)
|
|
|
|
humanres.men -= menkilled;
|
|
|
|
else
|
|
|
|
compres.men -= menkilled;
|
|
|
|
return menkilled;
|
|
|
|
}
|
|
|
|
|
2009-05-16 08:20:54 +00:00
|
|
|
/* return -1 if error, 1 if attack is succeeded, 0 otherwise */
|
2014-08-27 00:11:53 +00:00
|
|
|
static int attack_territory(int colour, int x, int y)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
bool human = (colour == COLOUR_LIGHT);
|
|
|
|
int str_diff;
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[x][y].colour == colour)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splash(HZ, "You can't attack your own territory");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
str_diff = calc_strength(COLOUR_DARK, x, y) -
|
2014-08-27 00:08:17 +00:00
|
|
|
calc_strength(COLOUR_LIGHT, x, y);
|
2014-08-27 00:11:53 +00:00
|
|
|
if(human)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
str_diff = -str_diff;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(str_diff > 0 || (str_diff == 0 && rb->rand()%2))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
struct resources *offres, *defres;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(human)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
offres = &humanres;
|
|
|
|
defres = &compres;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
offres = &compres;
|
|
|
|
defres = &humanres;
|
|
|
|
}
|
|
|
|
defres->men -= board[x][y].men;
|
|
|
|
defres->tanks -= board[x][y].tank;
|
|
|
|
defres->planes -= board[x][y].plane;
|
|
|
|
defres->nukes -= board[x][y].nuke;
|
|
|
|
defres->farms -= board[x][y].farm;
|
|
|
|
defres->inds -= board[x][y].ind;
|
|
|
|
offres->farms += board[x][y].farm;
|
|
|
|
offres->inds += board[x][y].ind;
|
2014-08-28 23:19:08 +00:00
|
|
|
offres->nukes += board[x][y].nuke;
|
2009-05-16 08:20:54 +00:00
|
|
|
board[x][y].colour = colour;
|
2014-08-31 01:02:56 +00:00
|
|
|
if(!superdom_settings.persistent_units)
|
|
|
|
{
|
|
|
|
board[x][y].men = 0;
|
|
|
|
board[x][y].tank = false;
|
|
|
|
board[x][y].plane = false;
|
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
draw_board();
|
|
|
|
if(human)
|
|
|
|
rb->sleep(HZ*2);
|
|
|
|
else
|
|
|
|
rb->sleep(HZ);
|
|
|
|
return 1;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(human)
|
|
|
|
rb->splash(HZ, "Your troops were unable to overcome"
|
2014-08-27 00:08:17 +00:00
|
|
|
" the enemy troops");
|
2009-05-16 08:20:54 +00:00
|
|
|
else
|
|
|
|
rb->splash(HZ*2, "The computer attempted to "
|
2014-08-27 00:08:17 +00:00
|
|
|
"attack, but the invasion was"
|
|
|
|
" pushed back");
|
2009-05-16 08:20:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-28 23:19:08 +00:00
|
|
|
static void spoil_food(void)
|
|
|
|
{
|
|
|
|
/* spoil 0-10% of food, different amounts for computer/player */
|
|
|
|
int spoil_amount=humanres.food*(0.1*rb->rand()/RAND_MAX);
|
|
|
|
if(spoil_amount)
|
|
|
|
rb->splashf(2*HZ, "Spoilage claims %d units of food", spoil_amount);
|
|
|
|
humanres.food-=spoil_amount;
|
|
|
|
|
|
|
|
/* now for computer */
|
|
|
|
spoil_amount=compres.food*(0.1*rb->rand()/RAND_MAX);
|
|
|
|
compres.food-=spoil_amount;
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int war_menu(void)
|
|
|
|
{
|
2009-08-02 14:30:09 +00:00
|
|
|
int selection = 0, temp;
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2009-08-02 14:30:09 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "War!", NULL,
|
2014-08-27 00:08:17 +00:00
|
|
|
"Select territory to attack",
|
|
|
|
"Finish turn", "Game menu");
|
2007-08-02 12:55:14 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
while(humanres.moves)
|
|
|
|
{
|
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case 0:
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(select_square())
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case RET_VAL_OK:
|
2014-08-27 00:11:53 +00:00
|
|
|
if(attack_territory(COLOUR_LIGHT, cursor.x, cursor.y) >= 0)
|
2014-08-27 00:08:17 +00:00
|
|
|
humanres.moves--;
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
2014-08-27 00:08:17 +00:00
|
|
|
case RET_VAL_USB:
|
|
|
|
return RET_VAL_USB;
|
2007-08-02 12:55:14 +00:00
|
|
|
break;
|
2014-08-27 00:08:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return RET_VAL_OK;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if((temp = ingame_menu()) != RET_VAL_OK)
|
|
|
|
return temp;
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
return RET_VAL_OK;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct threat {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int str_diff;
|
|
|
|
};
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static bool place_adjacent(bool tank, int x, int y)
|
|
|
|
{
|
|
|
|
int type = (tank ? 1: 2);
|
|
|
|
if(!buy_resources(COLOUR_DARK, type, x, y, 0))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(!buy_resources(COLOUR_DARK, type, x-1, y, 0))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(!buy_resources(COLOUR_DARK, type, x+1, y, 0))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
return true;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(!buy_resources(COLOUR_DARK, type, x, y-1, 0))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(!buy_resources(COLOUR_DARK, type, x, y+1, 0))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static bool has_adjacent(int x, int y)
|
|
|
|
{
|
|
|
|
if ((board[x][y].colour == COLOUR_LIGHT) &&
|
|
|
|
((board[x-1][y].colour == COLOUR_DARK) ||
|
|
|
|
(board[x+1][y].colour == COLOUR_DARK) ||
|
|
|
|
(board[x][y+1].colour == COLOUR_DARK) ||
|
2014-08-27 00:08:17 +00:00
|
|
|
(board[x][y-1].colour == COLOUR_DARK)))
|
2007-08-02 12:55:14 +00:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static void find_adjacent(int x, int y, int* adj_x, int* adj_y)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* Finds adjacent squares, returning squares without tanks on them
|
|
|
|
* in preference to those with them */
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[x-1][y].colour == COLOUR_DARK)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
*adj_x = x-1;
|
|
|
|
*adj_y = y;
|
2009-05-16 08:20:54 +00:00
|
|
|
return;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[x+1][y].colour == COLOUR_DARK)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
*adj_x = x+1;
|
|
|
|
*adj_y = y;
|
2009-05-16 08:20:54 +00:00
|
|
|
return;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[x][y-1].colour == COLOUR_DARK)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
*adj_x = x;
|
|
|
|
*adj_y = y-1;
|
2009-05-16 08:20:54 +00:00
|
|
|
return;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(board[x][y+1].colour == COLOUR_DARK)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
*adj_x = x;
|
|
|
|
*adj_y = y+1;
|
2009-05-16 08:20:54 +00:00
|
|
|
return;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static void computer_allocate(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* Firstly, decide whether to go offensive or defensive.
|
|
|
|
* This is primarily decided by the human player posing a threat to either
|
2014-08-28 23:19:08 +00:00
|
|
|
* the computer's farms, factories or nukes */
|
2007-08-02 12:55:14 +00:00
|
|
|
int i, j, k;
|
|
|
|
bool offensive = true;
|
|
|
|
struct threat threats[4];
|
|
|
|
int numthreats = 0;
|
|
|
|
int total_str_diff = 0;
|
2009-05-16 08:20:54 +00:00
|
|
|
int numterritory = 0;
|
|
|
|
int str_diff;
|
2007-08-02 12:55:14 +00:00
|
|
|
int men_needed;
|
|
|
|
struct threat targets[2];
|
|
|
|
int numtargets;
|
2020-04-13 21:24:07 +00:00
|
|
|
struct cursor adj = { 0, 0 };
|
2009-05-16 08:20:54 +00:00
|
|
|
|
|
|
|
compres.cash += compres.bank;
|
|
|
|
compres.bank = 0;
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=1;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
for(j=1;j<=BOARD_SIZE;j++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
|
|
|
if(board[i][j].colour == COLOUR_DARK)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
numterritory++;
|
|
|
|
str_diff = calc_strength(COLOUR_LIGHT,i,j) -
|
2014-08-27 00:08:17 +00:00
|
|
|
calc_strength(COLOUR_DARK,i,j);
|
2014-08-28 23:19:08 +00:00
|
|
|
if(str_diff > 0 && (board[i][j].ind || board[i][j].farm || board[i][j].nuke))
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
/* computer's farm/factory/nuke is being threatened */
|
2014-08-27 00:11:53 +00:00
|
|
|
if(numthreats < 3)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
offensive = false;
|
|
|
|
threats[numthreats].x = i;
|
|
|
|
threats[numthreats].y = j;
|
2009-05-16 08:20:54 +00:00
|
|
|
threats[numthreats].str_diff = str_diff;
|
2007-08-02 12:55:14 +00:00
|
|
|
numthreats++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-11 01:53:48 +00:00
|
|
|
rb->yield();
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-31 00:59:20 +00:00
|
|
|
/* if the computer has no factories, build some ASAP */
|
|
|
|
if(!compres.inds)
|
|
|
|
{
|
|
|
|
while(compres.cash >= PRICE_FACTORY && compres.inds < numterritory)
|
|
|
|
{
|
|
|
|
i = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
j = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
if(board[i][j].colour == COLOUR_DARK)
|
|
|
|
{
|
|
|
|
buy_resources(COLOUR_DARK, 4, i, j, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(superdom_settings.compdiff>=AI_BUILD_INDS_FARMS_LEVEL && compres.cash>=PRICE_FACTORY)
|
|
|
|
{
|
|
|
|
while(compres.cash>=PRICE_FACTORY)
|
|
|
|
{
|
|
|
|
if(compres.farms<compres.inds)
|
|
|
|
{
|
|
|
|
while(compres.farms<compres.inds && compres.cash>=PRICE_FARM)
|
|
|
|
{
|
|
|
|
i = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
j = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
if(board[i][j].colour == COLOUR_DARK && !board[i][j].farm)
|
|
|
|
{
|
|
|
|
buy_resources(COLOUR_DARK, 3, i, j, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(compres.inds<compres.farms && compres.cash>=PRICE_FACTORY)
|
|
|
|
{
|
|
|
|
i = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
j = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
if(board[i][j].colour == COLOUR_DARK && !board[i][j].ind)
|
|
|
|
{
|
|
|
|
buy_resources(COLOUR_DARK, 4, i, j, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* AI will buy nukes first if possible */
|
|
|
|
if(compres.cash > PRICE_NUKE + PRICE_TANK && superdom_settings.compdiff>=AI_BUILD_NUKES_LEVEL)
|
2014-08-28 23:19:08 +00:00
|
|
|
{
|
|
|
|
while(compres.cash >= PRICE_NUKE && compres.nukes < numterritory)
|
|
|
|
{
|
|
|
|
i = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
j = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
if(board[i][j].colour == COLOUR_DARK)
|
|
|
|
{
|
|
|
|
buy_resources(COLOUR_DARK, 5, i, j, 0);
|
|
|
|
}
|
|
|
|
rb->yield();
|
|
|
|
}
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(offensive)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* The AI is going to go straight for the throat here and attack
|
2014-08-28 23:19:08 +00:00
|
|
|
* the player's farms, nukes, and factories. The amount of cash
|
2007-08-02 12:55:14 +00:00
|
|
|
* the AI has to spend will determine how many targets there are */
|
2014-08-27 00:11:53 +00:00
|
|
|
if(compres.cash > 1200)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* 1200 is a figure I pulled out of nowhere. Adjust as needed */
|
|
|
|
numtargets = 2;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
numtargets = 1;
|
|
|
|
}
|
|
|
|
/* Work out which target(s) to attack. They must have adjacent squares
|
|
|
|
* owned by the computer. If none are found just place troops in
|
|
|
|
* random places around the map until we run out of money */
|
|
|
|
k = 0;
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=1;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
for(j=1;j<=BOARD_SIZE;j++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
if(has_adjacent(i,j) &&
|
2014-08-28 23:19:08 +00:00
|
|
|
(board[i][j].ind || board[i][j].farm || board[i][j].nuke))
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
|
|
|
if(k<numtargets)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
targets[k].x = i;
|
|
|
|
targets[k].y = j;
|
2009-05-16 08:20:54 +00:00
|
|
|
targets[k].str_diff =
|
2014-08-27 00:08:17 +00:00
|
|
|
calc_strength(COLOUR_LIGHT, i, j) -
|
|
|
|
calc_strength(COLOUR_DARK, i, j);
|
2007-08-02 12:55:14 +00:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->yield();
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(k == 0)
|
|
|
|
{
|
2014-08-31 00:59:20 +00:00
|
|
|
/* randomly place tanks */
|
|
|
|
while(compres.cash >= PRICE_TANK && compres.tanks < numterritory)
|
2014-08-28 23:19:08 +00:00
|
|
|
{
|
|
|
|
i = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
j = rb->rand()%BOARD_SIZE + 1;
|
|
|
|
if(board[i][j].colour == COLOUR_DARK)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
buy_resources(COLOUR_DARK, 1, i, j, 0);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:08:17 +00:00
|
|
|
rb->yield();
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(i=0;i<k;i++)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
str_diff = targets[i].str_diff;
|
2014-08-27 00:11:53 +00:00
|
|
|
while(str_diff + 20 > 0 && compres.cash > 0)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* While we still need them keep placing men */
|
2014-08-27 00:11:53 +00:00
|
|
|
if(!place_adjacent(true, targets[i].x, targets[i].y))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
find_adjacent(targets[i].x, targets[i].y,
|
2014-08-27 00:08:17 +00:00
|
|
|
&adj.x, &adj.y);
|
2009-05-16 08:20:54 +00:00
|
|
|
men_needed = (str_diff + 20)*1000/133;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(compres.cash < men_needed)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
men_needed = compres.cash;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
buy_resources(COLOUR_DARK, 0, adj.x, adj.y,
|
2014-08-27 00:08:17 +00:00
|
|
|
men_needed);
|
2009-05-16 08:20:54 +00:00
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
str_diff = calc_strength(COLOUR_LIGHT,
|
2014-08-27 00:08:17 +00:00
|
|
|
targets[i].x, targets[i].y) -
|
|
|
|
calc_strength(COLOUR_DARK,
|
2009-05-16 08:20:54 +00:00
|
|
|
targets[i].x, targets[i].y);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* Work out what to place on each square to defend it.
|
|
|
|
* Tanks are preferential because they do not require food,
|
|
|
|
* but if the budget is tight then we fall back onto troops.
|
|
|
|
* Conversely if cash is not an issue and there are already tanks in
|
|
|
|
* place planes will be deployed. We would like a margin of at least
|
|
|
|
* 20 points to be safe. */
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<numthreats;i++)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
total_str_diff += threats[i].str_diff;
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if((total_str_diff+20)*10 > compres.cash)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* Not enough cash to accomodate all threats using tanks alone -
|
|
|
|
* use men as a backup */
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<numthreats;i++)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
men_needed = ((threats[i].str_diff + 20)*1000)/133;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(compres.cash < men_needed)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
men_needed = compres.cash;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
buy_resources(COLOUR_DARK, 0, threats[i].x, threats[i].y,
|
2014-08-27 00:08:17 +00:00
|
|
|
men_needed);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* Tanks it is */
|
2009-05-16 08:20:54 +00:00
|
|
|
/* Enough money to pay their way by planes? */
|
|
|
|
bool tank = ((total_str_diff+20)*15 >= compres.cash);
|
2014-08-27 00:11:53 +00:00
|
|
|
for(i=0;i<numthreats;i++)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
str_diff = threats[i].str_diff;
|
2014-08-27 00:11:53 +00:00
|
|
|
while(str_diff + 20 > 0)
|
|
|
|
{
|
|
|
|
if(!place_adjacent(tank, threats[i].x, threats[i].y))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
/* No room for any more planes or tanks, revert to
|
|
|
|
* men */
|
|
|
|
find_adjacent(threats[i].x, threats[i].y,
|
2014-08-27 00:08:17 +00:00
|
|
|
&adj.x, &adj.y);
|
2009-05-16 08:20:54 +00:00
|
|
|
men_needed = (str_diff + 20)*1000/133;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(compres.cash < men_needed)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
men_needed = compres.cash;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
buy_resources(COLOUR_DARK, 0, threats[i].x,
|
2014-08-27 00:08:17 +00:00
|
|
|
threats[i].y, men_needed);
|
2009-05-16 08:20:54 +00:00
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
str_diff = calc_strength(COLOUR_LIGHT,
|
2014-08-27 00:08:17 +00:00
|
|
|
threats[i].x, threats[i].y) -
|
|
|
|
calc_strength(COLOUR_DARK,
|
2009-05-16 08:20:54 +00:00
|
|
|
threats[i].x, threats[i].y);
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-28 23:19:08 +00:00
|
|
|
/* no investing in easy mode */
|
2014-08-31 00:59:20 +00:00
|
|
|
if(superdom_settings.compdiff>=AI_INVESTING_LEVEL)
|
2014-08-28 23:19:08 +00:00
|
|
|
{
|
|
|
|
compres.bank += compres.cash;
|
|
|
|
compres.cash = 0;
|
|
|
|
}
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int find_adj_target(int x, int y, struct cursor* adj)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* Find a square next to a computer's farm or factory owned by the player
|
|
|
|
* that is vulnerable. Return 1 on success, 0 otherwise */
|
2014-08-27 00:08:17 +00:00
|
|
|
if(board[x+1][y].colour == COLOUR_LIGHT &&
|
2014-08-27 00:11:53 +00:00
|
|
|
calc_strength(COLOUR_LIGHT,x+1,y)<=calc_strength(COLOUR_DARK,x+1,y))
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
adj->x = x+1;
|
|
|
|
adj->y = y;
|
|
|
|
return 1;
|
|
|
|
}
|
2014-08-27 00:08:17 +00:00
|
|
|
if(board[x-1][y].colour == COLOUR_LIGHT &&
|
2014-08-27 00:11:53 +00:00
|
|
|
calc_strength(COLOUR_LIGHT,x-1,y)<=calc_strength(COLOUR_DARK,x-1,y))
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
adj->x = x-1;
|
|
|
|
adj->y = y;
|
|
|
|
return 1;
|
|
|
|
}
|
2014-08-27 00:08:17 +00:00
|
|
|
if(board[x][y+1].colour == COLOUR_LIGHT &&
|
2014-08-27 00:11:53 +00:00
|
|
|
calc_strength(COLOUR_LIGHT,x,y+1)<=calc_strength(COLOUR_DARK,x,y+1))
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
adj->x = x;
|
|
|
|
adj->y = y+1;
|
|
|
|
return 1;
|
|
|
|
}
|
2014-08-27 00:08:17 +00:00
|
|
|
if(board[x][y-1].colour == COLOUR_LIGHT &&
|
2014-08-27 00:11:53 +00:00
|
|
|
calc_strength(COLOUR_LIGHT,x,y-1)<=calc_strength(COLOUR_DARK,x,y-1))
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
adj->x = x;
|
|
|
|
adj->y = y-1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-28 23:19:08 +00:00
|
|
|
static void computer_movement(void)
|
|
|
|
{
|
2014-08-30 14:21:25 +00:00
|
|
|
/* use nukes */
|
|
|
|
if(superdom_settings.compdiff>=3)
|
|
|
|
{
|
|
|
|
struct cursor nukes[10]; /* 10 for now, change as needed */
|
|
|
|
int nukes_back=0;
|
|
|
|
if(compres.nukes>0)
|
|
|
|
{
|
|
|
|
for(int i=1;i<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;i++)
|
|
|
|
{
|
|
|
|
for(int j=1;j<BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10 ;j++)
|
|
|
|
{
|
|
|
|
if(board[i][j].nuke)
|
|
|
|
{
|
|
|
|
nukes[nukes_back].x=i;
|
|
|
|
nukes[nukes_back].y=j;
|
|
|
|
nukes_back++;
|
|
|
|
}
|
|
|
|
rb->yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool found_target=true;
|
|
|
|
struct cursor adj;
|
|
|
|
int next_nuke=0;
|
|
|
|
/* first, use nukes for defence */
|
|
|
|
while(found_target && next_nuke<nukes_back)
|
|
|
|
{
|
|
|
|
found_target = false;
|
|
|
|
for(int i=1;i<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;i++)
|
|
|
|
{
|
|
|
|
for(int j=1;j<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;j++)
|
|
|
|
{
|
|
|
|
if((board[i][j].colour == COLOUR_DARK) &&
|
|
|
|
(board[i][j].farm || board[i][j].ind || board[i][j].nuke) &&
|
|
|
|
find_adj_target(i, j, &adj))
|
|
|
|
{
|
|
|
|
found_target = true;
|
|
|
|
rb->splashf(2*HZ, "Launching nuke for defence, from (%d, %d) to (%d, %d)", nukes[next_nuke].x, nukes[next_nuke].y, adj.x, adj.y);
|
|
|
|
launch_nuke(COLOUR_DARK, nukes[next_nuke].x, nukes[next_nuke].y, adj.x, adj.y);
|
|
|
|
next_nuke++;
|
|
|
|
}
|
|
|
|
rb->yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-28 23:19:08 +00:00
|
|
|
|
2014-08-30 14:21:25 +00:00
|
|
|
/* if we still have any left over, use those for offence */
|
|
|
|
found_target = true;
|
|
|
|
while(found_target && next_nuke<nukes_back)
|
|
|
|
{
|
|
|
|
found_target = false;
|
|
|
|
for(int i=1;i<=BOARD_SIZE;i++)
|
|
|
|
{
|
|
|
|
for(int j=1;j<=BOARD_SIZE;j++)
|
|
|
|
{
|
|
|
|
if(board[i][j].colour == COLOUR_LIGHT &&
|
|
|
|
(board[i][j].ind || board[i][j].farm || board[i][j].nuke) &&
|
|
|
|
(calc_strength(COLOUR_DARK, i, j) >= calc_strength(COLOUR_LIGHT, i, j)))
|
|
|
|
{
|
|
|
|
found_target = true;
|
|
|
|
rb->splashf(2*HZ, "Launching nuke for offence, nuke index %d", next_nuke);
|
|
|
|
launch_nuke(COLOUR_DARK, nukes[next_nuke].x, nukes[next_nuke].y, i, j);
|
|
|
|
next_nuke++;
|
|
|
|
}
|
|
|
|
rb->yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* TODO: move other units */
|
2014-08-28 23:19:08 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static void computer_war(void)
|
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
/* Work out where to attack - prioritise the defence of buildings and nukes */
|
2007-08-02 12:55:14 +00:00
|
|
|
int i, j;
|
2009-05-16 08:20:54 +00:00
|
|
|
bool found_target = true;
|
2007-08-02 12:55:14 +00:00
|
|
|
struct cursor adj;
|
2009-08-02 14:30:09 +00:00
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
while(found_target)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
found_target = false;
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=1;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
for(j=1;j<=BOARD_SIZE;j++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
|
|
|
if((board[i][j].colour == COLOUR_DARK) &&
|
2014-08-28 23:19:08 +00:00
|
|
|
(board[i][j].farm || board[i][j].ind || board[i][j].nuke) &&
|
2014-08-27 00:11:53 +00:00
|
|
|
find_adj_target(i, j, &adj))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
found_target = true;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(attack_territory(COLOUR_DARK, adj.x, adj.y) >= 0)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
compres.moves--;
|
|
|
|
if(!compres.moves)
|
|
|
|
return;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-11 01:53:48 +00:00
|
|
|
rb->yield();
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
/* Defence stage done, move on to OFFENCE */
|
|
|
|
found_target = true;
|
2014-08-27 00:11:53 +00:00
|
|
|
while(found_target)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
found_target = false;
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=1;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
for(j=1;j<=BOARD_SIZE;j++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
|
|
|
if(board[i][j].colour == COLOUR_LIGHT &&
|
2014-08-28 23:19:08 +00:00
|
|
|
(board[i][j].ind || board[i][j].farm || board[i][j].nuke) &&
|
2014-08-27 00:11:53 +00:00
|
|
|
(calc_strength(COLOUR_DARK, i, j) >= calc_strength(COLOUR_LIGHT, i, j)))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
found_target = true;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(attack_territory(COLOUR_DARK, i, j) >= 0)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
compres.moves--;
|
|
|
|
if(!compres.moves)
|
|
|
|
return;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->yield();
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Spend leftover moves wherever attacking randomly */
|
|
|
|
found_target = true;
|
2014-08-27 00:11:53 +00:00
|
|
|
while(found_target)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
found_target = false;
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=1;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
for(j=1;j<=BOARD_SIZE;j++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
if(board[i][j].colour == COLOUR_LIGHT &&
|
|
|
|
(calc_strength(COLOUR_DARK, i, j) >=
|
2014-08-27 00:11:53 +00:00
|
|
|
calc_strength(COLOUR_LIGHT, i, j)))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
found_target = true;
|
2014-08-27 00:11:53 +00:00
|
|
|
if(attack_territory(COLOUR_DARK, i, j) >= 0)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
compres.moves--;
|
2009-05-16 08:20:54 +00:00
|
|
|
if(!compres.moves)
|
|
|
|
return;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->yield();
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int load_game(const char* file)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = rb->open(file, O_RDONLY);
|
2014-08-27 00:11:53 +00:00
|
|
|
if(fd < 0)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
DEBUGF("Couldn't open savegame\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
rb->read(fd, buf, 5);
|
2014-08-27 00:11:53 +00:00
|
|
|
if(rb->strcmp(buf, "SSGv3"))
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->splash(HZ, "Invalid/incompatible savegame");
|
2007-08-02 12:55:14 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->read(fd, &gamestate, sizeof(gamestate));
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->read(fd, &humanres.cash, sizeof(humanres.cash));
|
|
|
|
rb->read(fd, &humanres.food, sizeof(humanres.food));
|
|
|
|
rb->read(fd, &humanres.bank, sizeof(humanres.bank));
|
|
|
|
rb->read(fd, &humanres.planes, sizeof(humanres.planes));
|
|
|
|
rb->read(fd, &humanres.tanks, sizeof(humanres.tanks));
|
|
|
|
rb->read(fd, &humanres.men, sizeof(humanres.men));
|
|
|
|
rb->read(fd, &humanres.nukes, sizeof(humanres.nukes));
|
|
|
|
rb->read(fd, &humanres.inds, sizeof(humanres.inds));
|
|
|
|
rb->read(fd, &humanres.farms, sizeof(humanres.farms));
|
|
|
|
rb->read(fd, &humanres.moves, sizeof(humanres.moves));
|
|
|
|
rb->read(fd, &compres.cash, sizeof(humanres.cash));
|
|
|
|
rb->read(fd, &compres.food, sizeof(humanres.food));
|
|
|
|
rb->read(fd, &compres.bank, sizeof(humanres.bank));
|
|
|
|
rb->read(fd, &compres.planes, sizeof(humanres.planes));
|
|
|
|
rb->read(fd, &compres.tanks, sizeof(humanres.tanks));
|
|
|
|
rb->read(fd, &compres.men, sizeof(humanres.men));
|
|
|
|
rb->read(fd, &compres.nukes, sizeof(humanres.nukes));
|
|
|
|
rb->read(fd, &compres.inds, sizeof(humanres.inds));
|
|
|
|
rb->read(fd, &compres.farms, sizeof(humanres.farms));
|
|
|
|
rb->read(fd, &compres.moves, sizeof(humanres.moves));
|
|
|
|
rb->read(fd, board, sizeof(board));
|
|
|
|
rb->read(fd, &superdom_settings.compstartfarms, sizeof(int));
|
|
|
|
rb->read(fd, &superdom_settings.compstartinds, sizeof(int));
|
|
|
|
rb->read(fd, &superdom_settings.humanstartfarms, sizeof(int));
|
2010-02-04 12:50:13 +00:00
|
|
|
rb->read(fd, &superdom_settings.humanstartinds, sizeof(int));
|
2007-08-02 12:55:14 +00:00
|
|
|
rb->read(fd, &superdom_settings.startcash, sizeof(int));
|
|
|
|
rb->read(fd, &superdom_settings.startfood, sizeof(int));
|
|
|
|
rb->read(fd, &superdom_settings.movesperturn, sizeof(int));
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->close(fd);
|
2007-08-02 12:55:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static void default_settings(void)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
superdom_settings.compstartfarms = 1;
|
|
|
|
superdom_settings.compstartinds = 1;
|
|
|
|
superdom_settings.humanstartfarms = 2;
|
|
|
|
superdom_settings.humanstartinds = 2;
|
|
|
|
superdom_settings.startcash = 0;
|
|
|
|
superdom_settings.startfood = 0;
|
|
|
|
superdom_settings.movesperturn = 2;
|
2014-08-28 23:19:08 +00:00
|
|
|
superdom_settings.compdiff=2;
|
|
|
|
superdom_settings.spoil_enabled=false;
|
2014-08-31 01:02:56 +00:00
|
|
|
superdom_settings.persistent_units=false;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
static int average_strength(int colour)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
/* This function calculates the average strength of the given player,
|
|
|
|
* used to determine when the computer wins or loses. */
|
|
|
|
int i,j;
|
|
|
|
int totalpower = 0;
|
2014-08-28 23:19:08 +00:00
|
|
|
for(i=1;i<=BOARD_SIZE;i++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-28 23:19:08 +00:00
|
|
|
for(j=1;j<=BOARD_SIZE;j++)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
|
|
|
if(board[i][j].colour != -1)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
totalpower += calc_strength(colour, i, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-28 23:19:08 +00:00
|
|
|
return totalpower/NUM_SPACES;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2007-08-02 12:55:14 +00:00
|
|
|
{
|
2014-08-27 00:11:53 +00:00
|
|
|
rb->srand(*rb->current_tick);
|
2007-08-03 10:44:25 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
rb->lcd_set_background(LCD_WHITE);
|
|
|
|
#endif
|
|
|
|
|
2007-08-02 12:55:14 +00:00
|
|
|
cursor.x = 1;
|
|
|
|
cursor.y = 1;
|
|
|
|
default_settings();
|
2014-08-27 00:11:53 +00:00
|
|
|
if(parameter)
|
|
|
|
{
|
|
|
|
if(load_game(parameter) != 0)
|
|
|
|
{
|
2007-08-02 12:55:14 +00:00
|
|
|
DEBUGF("Loading failed, generating new game\n");
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(gamestate)
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case GS_PROD:
|
|
|
|
goto startprod;
|
|
|
|
break;
|
|
|
|
case GS_MOVE:
|
|
|
|
goto startmove;
|
|
|
|
break;
|
|
|
|
case GS_WAR:
|
|
|
|
goto startwar;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto startyear;
|
|
|
|
break;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(start_menu())
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case RET_VAL_OK: /* start playing */
|
|
|
|
break;
|
|
|
|
case RET_VAL_QUIT_ERR: /* quit */
|
|
|
|
return PLUGIN_OK;
|
|
|
|
break;
|
|
|
|
case RET_VAL_USB:
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-08-02 14:30:09 +00:00
|
|
|
|
2009-05-16 08:20:54 +00:00
|
|
|
init_resources();
|
|
|
|
init_board();
|
2007-08-02 12:55:14 +00:00
|
|
|
gen_resources();
|
|
|
|
startyear:
|
2014-08-27 00:11:53 +00:00
|
|
|
while(1)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
int avg_str_diff = (average_strength(COLOUR_LIGHT) -
|
|
|
|
average_strength(COLOUR_DARK));
|
2014-08-28 23:19:08 +00:00
|
|
|
/* computer will hold out longer in hard mode */
|
|
|
|
if(avg_str_diff > (superdom_settings.compdiff>=3 ?
|
|
|
|
COMPUTER_HARD_SURRENDER_THRESHOLD :
|
|
|
|
COMPUTER_SURRENDER_THRESHOLD))
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->splash(HZ*4, "The computer has surrendered. You win.");
|
2007-08-02 12:55:14 +00:00
|
|
|
return PLUGIN_OK;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-28 23:19:08 +00:00
|
|
|
if(-avg_str_diff > HUMAN_SURRENDER_THRESHOLD)
|
2014-08-27 00:11:53 +00:00
|
|
|
{
|
2014-08-31 00:59:20 +00:00
|
|
|
rb->splash(HZ*4, "Your army has suffered terrible morale from"
|
2014-08-27 00:08:17 +00:00
|
|
|
" the bleak prospects of winning. You lose.");
|
2007-08-02 12:55:14 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
|
|
|
|
/* production */
|
2014-08-27 00:08:17 +00:00
|
|
|
startprod:
|
2009-05-16 08:20:54 +00:00
|
|
|
gamestate = GS_PROD;
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(production_menu())
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case RET_VAL_USB:
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
|
|
|
case RET_VAL_QUIT_ERR:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
break;
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
2009-05-16 08:20:54 +00:00
|
|
|
computer_allocate();
|
|
|
|
|
|
|
|
/* movement */
|
|
|
|
humanres.moves = superdom_settings.movesperturn;
|
2014-08-27 00:08:17 +00:00
|
|
|
startmove:
|
2009-05-16 08:20:54 +00:00
|
|
|
gamestate = GS_MOVE;
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(movement_menu())
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case RET_VAL_USB:
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
|
|
|
case RET_VAL_QUIT_ERR:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
break;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
2014-08-28 23:19:08 +00:00
|
|
|
/* computer movement */
|
|
|
|
computer_movement();
|
|
|
|
|
|
|
|
/* spoil food */
|
|
|
|
if(superdom_settings.spoil_enabled)
|
|
|
|
{
|
|
|
|
spoil_food();
|
|
|
|
}
|
|
|
|
|
2009-05-16 08:20:54 +00:00
|
|
|
/* feed men */
|
2014-08-27 00:11:53 +00:00
|
|
|
if(humanres.men)
|
|
|
|
{
|
|
|
|
if(humanres.food > humanres.men)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Your men ate %d units of food",
|
2014-08-27 00:08:17 +00:00
|
|
|
humanres.men);
|
2009-05-16 08:20:54 +00:00
|
|
|
humanres.food -= humanres.men;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "There was not enough food"
|
2014-08-27 00:08:17 +00:00
|
|
|
" to feed all your men, %d men have died of starvation",
|
|
|
|
killmen(COLOUR_LIGHT));
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
rb->splash(HZ*2, buf);
|
|
|
|
}
|
2014-08-27 00:11:53 +00:00
|
|
|
if(compres.men)
|
|
|
|
{
|
|
|
|
if(compres.food > compres.men)
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
compres.food -= compres.men;
|
2014-08-27 00:11:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "The computer does not have"
|
2014-08-27 00:08:17 +00:00
|
|
|
" enough food to feed its men. %d have died of starvation",
|
|
|
|
killmen(COLOUR_DARK));
|
2009-05-16 08:20:54 +00:00
|
|
|
rb->splash(HZ, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* war */
|
|
|
|
humanres.moves = superdom_settings.movesperturn;
|
2014-08-27 00:08:17 +00:00
|
|
|
startwar:
|
2009-05-16 08:20:54 +00:00
|
|
|
gamestate = GS_WAR;
|
2014-08-27 00:11:53 +00:00
|
|
|
switch(war_menu())
|
|
|
|
{
|
2014-08-27 00:08:17 +00:00
|
|
|
case RET_VAL_USB:
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
|
|
|
case RET_VAL_QUIT_ERR:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
break;
|
2009-05-16 08:20:54 +00:00
|
|
|
}
|
|
|
|
compres.moves = superdom_settings.movesperturn;
|
|
|
|
computer_war();
|
|
|
|
gen_resources();
|
2007-08-02 12:55:14 +00:00
|
|
|
}
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|