diff options
| author | Franklin Wei <franklin@fwei.tk> | 2014-06-25 17:17:24 -0400 |
|---|---|---|
| committer | Franklin Wei <franklin@fwei.tk> | 2014-06-25 17:17:24 -0400 |
| commit | ca5288e1dc13f5e765f4f25c5c8082c9511c29c0 (patch) | |
| tree | 7322aa25379b0ea3d83401ca528a88cfb53c5bf6 | |
| parent | 6884a80079292a5475de0abb64652a4c79e886ae (diff) | |
| download | wargames-server-ca5288e1dc13f5e765f4f25c5c8082c9511c29c0.zip wargames-server-ca5288e1dc13f5e765f4f25c5c8082c9511c29c0.tar.gz wargames-server-ca5288e1dc13f5e765f4f25c5c8082c9511c29c0.tar.bz2 wargames-server-ca5288e1dc13f5e765f4f25c5c8082c9511c29c0.tar.xz | |
Added ICBM simulation
| -rw-r--r-- | GAMESPEC | 11 | ||||
| -rw-r--r-- | games.c | 53 | ||||
| -rw-r--r-- | location.h | 2 |
3 files changed, 49 insertions, 17 deletions
@@ -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: @@ -5,12 +5,38 @@ #include <location.h> #include <unistd.h> #include <string.h> -static int max(int a, int b) +static unsigned int min(unsigned int a, unsigned int b) { - if(a>b) - return a; + return a<b?a:b; +} +static void fire_missile(struct location_t* city) +{ + int random=rand()%100; + int x=city->x, 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<max_targets && good;++i) { getnstr(target_names[i], 128); if(strcmp(target_names[i],"")==0) @@ -136,7 +165,7 @@ void global_thermonuclear_war(void) found=true; if(world[j].owner!=side) { - targets[num_targets_found]=world[j]; + targets[num_targets_found]=&world[j]; ++num_targets_found; } else @@ -156,7 +185,7 @@ void global_thermonuclear_war(void) if(strcmp(response, "yes")==0 || strcmp(response, "y")==0) { print_string("\nTARGET CONFIRMED.\n\n"); - targets[num_targets_found]=world[j]; + targets[num_targets_found]=&world[j]; ++num_targets_found; } } @@ -173,7 +202,7 @@ void global_thermonuclear_war(void) } for(int i=0;i<num_targets_found;++i) { - map[targets[i].y][targets[i].x]='X'; + fire_missile(targets[i]); } clear(); print_map_with_pops(); @@ -4,7 +4,7 @@ struct location_t { const char* name; int x; int y; /* x,y-coords on the map */ - int population; /* around 1980 */ + unsigned int population; /* around 1980 */ enum player_t owner; bool print; const char* print_name; |