aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <franklin@fwei.tk>2014-06-26 14:47:18 -0400
committerFranklin Wei <franklin@fwei.tk>2014-06-26 14:47:18 -0400
commita921d4b4e410b37c1dd7e385303f423106e58b68 (patch)
tree4ac4568135b8137922850057db65926f6da38abd
parentad3259df663a3e0504b26a97d8c00a9454948850 (diff)
downloadwargames-server-a921d4b4e410b37c1dd7e385303f423106e58b68.zip
wargames-server-a921d4b4e410b37c1dd7e385303f423106e58b68.tar.gz
wargames-server-a921d4b4e410b37c1dd7e385303f423106e58b68.tar.bz2
wargames-server-a921d4b4e410b37c1dd7e385303f423106e58b68.tar.xz
Features, bugfixes :)
-rw-r--r--GAMESPEC8
-rw-r--r--games.c31
-rw-r--r--location.h28
3 files changed, 36 insertions, 31 deletions
diff --git a/GAMESPEC b/GAMESPEC
index 85aa7fb..13200a0 100644
--- a/GAMESPEC
+++ b/GAMESPEC
@@ -15,10 +15,10 @@ ICBM launch:
- The USSR can launch 6 at a time.
- 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
+ - Marginal: 20%+100 casualties
+ - Minor: 40%+200 casualties
+ - Major: 60%+400 casualties
+ - Critical: 100% casualties
- The probabilities of each of these options is outlined below:
- Miss - 10%
- Marginal - 20%
diff --git a/games.c b/games.c
index 18df2c9..26ab23f 100644
--- a/games.c
+++ b/games.c
@@ -5,11 +5,12 @@
#include <location.h>
#include <unistd.h>
#include <string.h>
+#include <stdlib.h>
static bool surrender=false;
static int winner=0; /* on surrender */
-static unsigned int min(unsigned int a, unsigned int b)
+static unsigned int max(long long a, long long b)
{
- return a<b?a:b;
+ return a>b?a:b;
}
static void fire_missile(struct location_t* city)
{
@@ -23,24 +24,24 @@ static void fire_missile(struct location_t* city)
else if(random>=60) /* major */
{
map[y][x]='X';
- city->population=min(city->population-500000, 0);
+ city->population=max((double)city->population*(double).4-400, 0);
}
else if(random>=30) /* minor */
{
map[y][x]='*';
- city->population=min(city->population-100000, 0);
+ city->population=max((double)city->population*(double).6-200, 0);
}
else if(random>=10) /* marginal */
{
map[y][x]='x';
- city->population=min(city->population-10000, 0);
+ city->population=max((double)city->population*(double).8-100, 0);
}
else
{
map[y][x]='O';
}
}
-static void calc_pops(unsigned int* us_pop, unsigned int* ussr_pop)
+static void calc_pops(long long* us_pop, long long* ussr_pop)
{
*us_pop=0;
*ussr_pop=0;
@@ -60,7 +61,7 @@ static void print_map_with_pops(void)
print_string(map[i]);
print_string("\n");
}
- unsigned int us_pop=0, ussr_pop=0;
+ long long us_pop=0, ussr_pop=0;
calc_pops(&us_pop, &ussr_pop);
/* now sort into US and USSR cities */
struct location_t us_cities[sizeof(world)/sizeof(struct location_t)+1], ussr_cities[sizeof(world)/sizeof(struct location_t)+1];
@@ -136,7 +137,7 @@ static void do_first_strike(int side)
struct location_t *targets[32];
int num_targets_found=0;
int max_targets=side==USA?4:6;
- for(int i=0;i<max_targets && good;++i)
+ for(int i=0;num_targets_found<max_targets && good;++i)
{
getnstr(target_names[i], 128);
if(strcmp(target_names[i],"")==0)
@@ -200,6 +201,7 @@ static void do_first_strike(int side)
}
static void do_missile_launch(int side)
{
+ clear();
attr_on(WA_UNDERLINE, 0);
print_string("AWAITING STRIKE COMMAND");
attr_off(WA_UNDERLINE, 0);
@@ -210,7 +212,7 @@ static void do_missile_launch(int side)
struct location_t *targets[32];
int num_targets_found=0;
int max_targets=side==USA?4:6;
- for(int i=0;i<max_targets && good;++i)
+ for(int i=0;num_targets_found<max_targets && good;++i)
{
getnstr(target_names[i], 128);
if(strcmp(target_names[i],"")==0)
@@ -281,13 +283,13 @@ static void do_peace_talks(int side)
static void do_human_move(int side)
{
bool good=false;
- print_string("WHAT ACTION DO YOU WISH TO TAKE?\n\n 1. MISSILE LAUNCH\n 2. PEACE TALKS\n 3. SURRENDER\n\n");
+ print_string("\nWHAT ACTION DO YOU WISH TO TAKE?\n\n 1. MISSILE LAUNCH\n 2. PEACE TALKS\n 3. SURRENDER\n 4. NOTHING\n\n");
int move=0;
while(!good)
{
print_string("PLEASE CHOOSE ONE: ");
scanw("%u", &move);
- if(move==1 || move==2 || move==3)
+ if(move>0 && move<5)
good=true;
}
switch(move)
@@ -302,11 +304,14 @@ static void do_human_move(int side)
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<sizeof(map)/sizeof(const char*);++i)
@@ -326,7 +331,7 @@ void global_thermonuclear_war(void)
}
clear();
do_first_strike(side);
- unsigned int us_pop=0, ussr_pop;
+ long long us_pop=0, ussr_pop;
calc_pops(&us_pop, &ussr_pop);
while(us_pop!=0 && ussr_pop!=0 && !surrender)
{
@@ -335,7 +340,7 @@ void global_thermonuclear_war(void)
do_ai_move(side);
calc_pops(&us_pop, &ussr_pop);
}
- clear();
+ print_string("\n\n");
if(!surrender)
{
if(us_pop==0 && ussr_pop==0)
diff --git a/location.h b/location.h
index b26c66c..ed9e4ff 100644
--- a/location.h
+++ b/location.h
@@ -4,27 +4,27 @@ struct location_t {
const char* name;
int x;
int y; /* x,y-coords on the map */
- unsigned int population; /* around 1980 */
+ long long population; /* around 1980 */
enum player_t owner;
bool print;
const char* print_name;
};
struct location_t world[]={
/* US cities */
- {"las vegas", 5, 7, 150000, USA, true, "Las Vegas"},
- {"seattle", 3, 2, 500000, USA, true, "Seattle"},
- {"new york", 34, 5, 7000000, USA, true, "New York City"},
- {"new orleans", 25, 10, 500000, USA, true, "New Orleans"},
- {"washington dc", 33, 6, 650000, USA, true, "Washington, DC"},
- {"winston-salem", 30, 7, 150000, USA, true, "Winston-Salem"},
- {"san francisco", 1, 6, 700000, USA, true, "San Francisco"},
- {"chicago", 24, 4, 3000000, USA, true, "Chicago"},
- {"miami", 33, 11, 1000000, USA, true, "Miami"},
+ {"las vegas", 5, 7, 150000, USA, true, "LAS VEGAS"},
+ {"seattle", 3, 2, 500000, USA, true, "SEATTLE"},
+ {"new york", 34, 5, 7000000, USA, true, "NEW YORK CITY"},
+ {"new orleans", 25, 10, 500000, USA, true, "NEW ORLEANS"},
+ {"washington dc", 33, 6, 650000, USA, true, "WASHINGTON, DC"},
+ {"winston-salem", 30, 7, 150000, USA, true, "WINSTON-SALEM"},
+ {"san francisco", 1, 6, 700000, USA, true, "SAN FRANCISCO"},
+ {"chicago", 24, 4, 3000000, USA, true, "CHICAGO"},
+ {"miami", 33, 11, 1000000, USA, true, "MIAMI"},
/* Soviet cities */
/* NOTE: These cities are not accurate! */
- {"murmansk", 74, 1, 500000, USSR, true,"Murmansk"},
- {"moscow", 70, 5, 8000000, USSR, true, "Moscow"},
- {"minsk", 66, 4, 1500000, USSR, true, "Minsk"},
- {"chelyabinsk", 64, 8, 1250000, USSR, true, "Chelyabinsk"}
+ {"murmansk", 74, 1, 500000, USSR, true,"MURMANSK"},
+ {"moscow", 70, 5, 8000000, USSR, true, "MOSCOW"},
+ {"minsk", 66, 4, 1500000, USSR, true, "MINSK"},
+ {"chelyabinsk", 64, 8, 1250000, USSR, true, "CHELYABINSK"}
};