aboutsummaryrefslogtreecommitdiff
path: root/war.c
blob: 20e6bcf6ec6683514157032d8eb249641d9c4b02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "7w.h"

int data_getdir(int dir, int p);
void data_adddefeat(int p);
void data_addvictory(int p);
int data_numplayers();
int* data_getbuilt(int p);
int data_haswonderstage(int p, int wonder, int stage);
int* cards_getproduction(int era, int card);

int military_might(int player)
{
 int *built = data_getbuilt(player);
 int i, sum;
 sum = 0;
 for(i = 0; built[i] != -1; i += 2)
  sum += cards_getproduction(built[i], built[i+1])[SHIELD];
 if(data_haswonderstage(player, 3, 2)) sum += 2;
 if(data_haswonderstage(player, 3, 4)) sum += 1;
 if(data_haswonderstage(player, 3, 5)) sum += 1;
 return sum;
}

void war()
{
 int numplayers = data_numplayers();
 int player, j;
 for(player = 0; player < numplayers; player++)
  for(j = 0; j < 2; j++) {
   if(military_might(player) > military_might(data_getdir(j, player)))
    data_addvictory(player);
   else if(military_might(player) != military_might(data_getdir(j, player)))
    data_adddefeat(player);
  }
}
bgstack15