aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c30
-rw-r--r--messenger.c12
-rw-r--r--player_turn.c2
-rw-r--r--util.c44
-rw-r--r--war.c32
5 files changed, 68 insertions, 52 deletions
diff --git a/data.c b/data.c
index a9dda93..fbe8dec 100644
--- a/data.c
+++ b/data.c
@@ -10,6 +10,7 @@ int* get_intarray(int size);
void shuffle(int *deck, int n);
int* trade_buffer();
int* get_special(int era, int card, int player);
+void war();
#define MISC 3
#define DATAGOLD 0
@@ -26,20 +27,21 @@ static int turngoldbuffer[7];
void data_sorthands()
{
- int i, j, k, type, buffer[7];
+ int i, j, k, type, buff[7];
for(i = 0; i < numplayers; i++) {
k = 0;
for(type = 0; type <= 7; type++) {
for(j = 0; j < 7; j++) {
- if(cards_gettype(era, hands[i][j]) == type) buffer[k++] = hands[i][j];
+ if(cards_gettype(era, hands[i][j]) == type) buff[k++] = hands[i][j];
}
}
- for(k = 0; k < 7; k++) hands[i][k] = buffer[k];
+ for(k = 0; k < 7; k++) hands[i][k] = buff[k];
}
}
void data_nextera()
{
+ war();
if(era == 2) return;
era++;
turn = 0;
@@ -105,6 +107,7 @@ void data_endturn()
player[i][3][6] += buffer[i][2];
buffer[i][0] = -1;
buffer[i][1] = 0;
+ buffer[i][2] = 0;
}
totturns++;
if(totturns == 6) data_nextera();
@@ -121,6 +124,12 @@ int data_getwest(int p)
return (p+1)%numplayers;
}
+int data_getdir(int dir, int p)
+{
+ if(dir == 0) return data_geteast(p);
+ return data_getwest(p);
+}
+
int* data_gethand(int p)
{
return hands[(p+turn)%numplayers];
@@ -159,6 +168,20 @@ int data_getdefeats(int p)
return player[p][3][5];
}
+void data_adddefeat(int p)
+{
+ player[p][3][5]++;
+}
+
+void data_addvictory(int p)
+{
+ int amnt;
+ if(era == 0) amnt = 1;
+ if(era == 1) amnt = 3;
+ if(era == 2) amnt = 5;
+ player[p][3][4] += amnt;
+}
+
int data_getgold(int p)
{
return player[p][3][3] + turngoldbuffer[p];
@@ -205,6 +228,7 @@ void data_buildwonder(int p, int card)
buffer[p][0] = -2;
data_addgold(cards_getcost(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[GOLD] * -1, p);
data_addgold(cards_getproduction(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[GOLD], p);
+ data_addvps(cards_getproduction(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[VP], p);
data_discard(p, card);
}
diff --git a/messenger.c b/messenger.c
index 45e872e..8881c9b 100644
--- a/messenger.c
+++ b/messenger.c
@@ -28,18 +28,19 @@ void clearmessage()
void posthelp()
{
- postmessage(" 7 Wonders Help:\nKeys:\n Arrow keys move cursor\n Return - buys resource\n h - prints this message");
+ postmessage(" 7 Wonders Help:\nKeys:\n Arrow keys move cursor\n Return - buys card\n h - prints this message");
}
int postoptions(int x, int y)
{
- int width = 19;
+ int width = 26;
int yorig = y;
int cursor = 0;
- char* a = "Buy Sell Wonder";
+ char* a = "Buy Sell Wonder Cancel";
char* b = " *";
char* c = " *";
char* d = " *";
+ char* e = " *";
while(1) {
y = yorig;
io_printborder(x, y++, width);
@@ -47,6 +48,7 @@ int postoptions(int x, int y)
if(cursor == 0) y = io_printtext(x, y, width, b);
if(cursor == 1) y = io_printtext(x, y, width, c);
if(cursor == 2) y = io_printtext(x, y, width, d);
+ if(cursor == 3) y = io_printtext(x, y, width, e);
io_printborder(x, y++, width);
switch(io_getkey()) {
case LEFT: cursor--;
@@ -57,7 +59,7 @@ int postoptions(int x, int y)
break;
default: break;
}
- if(cursor < 0) cursor = 2;
- cursor = cursor%3;
+ if(cursor < 0) cursor = 3;
+ cursor = cursor%4;
}
}
diff --git a/player_turn.c b/player_turn.c
index 3f84465..1759c5f 100644
--- a/player_turn.c
+++ b/player_turn.c
@@ -26,7 +26,7 @@ int player_build(int focus, int cursor, int player)
int *hand = data_gethand(player);
if(focus == data_numplayers()) {
if(hand[cursor] == -1) return 0;
- int choice = postoptions(65, 20);
+ int choice = postoptions(62, 20);
if(choice == 0) {
if(data_canafford(player, cards_getcost(data_getera(), hand[cursor]))) {
data_build(player, hand[cursor]);
diff --git a/util.c b/util.c
index 2935600..20e8290 100644
--- a/util.c
+++ b/util.c
@@ -5,7 +5,7 @@
static void replace(char a[], char b[], int x, int y);
-#define POOLSIZE 10000
+#define POOLSIZE 100000
static int ipool[POOLSIZE];
static int *ipoolp = ipool;
@@ -28,48 +28,6 @@ char* get_chararray(int size)
return ret;
}
-/* In string a[], replace nth occerence of x[] with y[],
- or all occerences if n == 0. Note '.' is wild and
- the last . replaced will be returned. */
-char util_strreplace(char a[], char x[], char y[], int n) {
- int replaceAll = ! n;
- int i, j, lengthY;
- char dot = '\0';
- for(lengthY = 0; y[lengthY] != '\0'; lengthY++);
- for(i = 0; a[i] != '\0'; i++) {
- for(j = 0;; j++) {
- if(a[i+j] != x[j] && x[j] != '\0' && x[j] != '.') // '.' is wild
- break;
- if (x[j] == '.') dot = a[i+j];
- if (x[j] == '\0') { //it's a match
- n--;
- if(replaceAll) { //replace it
- replace(a, y, i, j);
- i += lengthY - 1;
- }
- else if(n == 0) { //replace it
- replace(a, y, i, j);
- return dot;
- }
- break;
- }
- if(a[i+j] == '\0') //end of string
- return dot;
- }
- }
-}
-
-/* In string a[], replace characters x - y with b[] */
-static void replace(char a[], char b[], int x, int y)
-{
- int i, j;
- for(i = 0; a[i] != '\0'; i++);
- char save[i-y+1];
- for(i = x+y, j = 0; (save[j] = a[i]) != '\0'; i++, j++);
- for(i = x, j = 0; (a[i] = b[j]) != '\0'; i++, j++);
- for(i = i, j = 0; (a[i] = save[j]) != '\0'; i++, j++);
-}
-
/* Concatinates a and b and returns a different
string. Only use when returned string can be recycled. */
char* cat(char a[], char b[]) {
diff --git a/war.c b/war.c
new file mode 100644
index 0000000..53a9239
--- /dev/null
+++ b/war.c
@@ -0,0 +1,32 @@
+#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];
+ 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