From aedf71494b2011ceeb06b96e63da1c7a79a32e0e Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Fri, 27 Jun 2014 18:11:06 -0400 Subject: Restructure --- gtnw.c | 382 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 gtnw.c (limited to 'gtnw.c') diff --git a/gtnw.c b/gtnw.c new file mode 100644 index 0000000..22b8e23 --- /dev/null +++ b/gtnw.c @@ -0,0 +1,382 @@ +#include "gtnw.h" +#include "location.h" +#include "map.h" +#include "util.h" +#include +#include +#include +#include +static bool surrender=false; +static int winner=0; /* on surrender */ +static unsigned int max(long long a, long long b) +{ + 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=max((double)city->population*(double).4-400, 0); + } + else if(random>=30) /* minor */ + { + map[y][x]='*'; + city->population=max((double)city->population*(double).6-200, 0); + } + else if(random>=10) /* marginal */ + { + map[y][x]='x'; + city->population=max((double)city->population*(double).8-100, 0); + } + else + { + map[y][x]='O'; + } +} +static void calc_pops(long long* us_pop, long long* ussr_pop) +{ + *us_pop=0; + *ussr_pop=0; + /* calculate populations */ + for(int i=0;iussr_back) + { + while(us_back!=ussr_back) + { + ussr_cities[ussr_back].print=false; + ++ussr_back; + } + } + us_cities[us_back].print=true; + us_cities[us_back].print_name="Total"; + us_cities[us_back].population=us_pop; + ussr_cities[ussr_back].print=true; + ussr_cities[ussr_back].print_name="Total"; + ussr_cities[ussr_back].population=ussr_pop; + ++us_back; + ++ussr_back; + print_string("\n\n"); + char buf[512]; + for(int i=0;i0 && move<5) + good=true; + } + switch(move) + { + case 1: + do_missile_launch(side); + break; + case 2: + do_peace_talks(side); + break; + case 3: + surrender=true; + winner=side==1?2:1; + break; + case 4: + break; + } +} + +void global_thermonuclear_war(void) +{ + srand(time(0)); + surrender=false; + clear(); + for(int i=0;i