From ca5288e1dc13f5e765f4f25c5c8082c9511c29c0 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Wed, 25 Jun 2014 17:17:24 -0400 Subject: Added ICBM simulation --- GAMESPEC | 11 +++++++---- games.c | 53 +++++++++++++++++++++++++++++++++++++++++------------ location.h | 2 +- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/GAMESPEC b/GAMESPEC index c403a93..85aa7fb 100644 --- a/GAMESPEC +++ b/GAMESPEC @@ -13,21 +13,24 @@ The behavior of each of these options is described below. ICBM launch: - The USA can launch ICBMs at a maximum of 4 cities at a time. - The USSR can launch 6 at a time. - - When an ICBM is launched, there are 4 possible results: + - When an ICBM is launched, there are 5 possible results: - Miss: 0 casualties - Marginal: 10000 casualties + - Minor: 100000 casualties - Major: 500000 casualties - Critical: All inhabitants of the target city are killed - The probabilities of each of these options is outlined below: - Miss - 10% - - Marginal - 50% + - Marginal - 20% + - Minor - 30% - Major - 30% - Critical - 10% - After the turn, the cities targeted will have one of these symbols in it: - Miss - O - Marginal - x - - Major - * - - Critical - X + - Minor - * + - Major - X + - Critical - ! Negociation: - There are three possible outcomes: diff --git a/games.c b/games.c index cca5cce..aa7686a 100644 --- a/games.c +++ b/games.c @@ -5,12 +5,38 @@ #include #include #include -static int max(int a, int b) +static unsigned int min(unsigned int a, unsigned int b) { - if(a>b) - return a; + return ax, y=city->y; + if(random>=90) /* crit */ + { + map[y][x]='!'; + city->population=0; + } + else if(random>=60) /* major */ + { + map[y][x]='X'; + city->population=min(city->population-500000, 0); + } + else if(random>=30) /* minor */ + { + map[y][x]='*'; + city->population=min(city->population-100000, 0); + } + else if(random>=10) /* marginal */ + { + map[y][x]='x'; + city->population=min(city->population-10000, 0); + } else - return b; + { + map[y][x]='O'; + } } static void print_map_with_pops(void) { @@ -74,15 +100,17 @@ static void print_map_with_pops(void) { if(us_cities[i].print && ussr_cities[i].print) { - snprintf(buf, 512, "%s: %d %*s: %d", us_cities[i].print_name, us_cities[i].population, 64-strlen(us_cities[i].print_name), ussr_cities[i].print_name, ussr_cities[i].population); + char buf_2[32]; + snprintf(buf_2, 31, "%u", us_cities[i].population); + snprintf(buf, 512, "%s: %u %*s: %u", us_cities[i].print_name, us_cities[i].population, 64-strlen(us_cities[i].print_name)-strlen(buf_2), ussr_cities[i].print_name, ussr_cities[i].population); } else if(us_cities[i].print && !ussr_cities[i].print) - snprintf(buf, 512, "%s: %d", us_cities[i].print_name, us_cities[i].population); + snprintf(buf, 512, "%s: %u", us_cities[i].print_name, us_cities[i].population); else { memset(buf, ' ', 255); buf[255]=0; - snprintf(buf+64, 512-64, "%s: %d", ussr_cities[i].print_name, ussr_cities[i].population); + snprintf(buf+64, 512-64, "%s: %u", ussr_cities[i].print_name, ussr_cities[i].population); } print_string(buf); print_string("\n"); @@ -114,9 +142,10 @@ void global_thermonuclear_war(void) char target_names[32][129]; good=true; int num_targets=0; - struct location_t targets[32]; + struct location_t *targets[32]; int num_targets_found=0; - for(int i=0;i<32 && good;++i) + int max_targets=side==USA?4:5; + for(int i=0;i