aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-03-30 15:35:36 -0400
committerNathan Vance <nathav63@gmail.com>2015-03-30 15:35:36 -0400
commitac78ebaf7f7e9d96cb022ad8a14fc013a58ba262 (patch)
treefe3042b52fc061c88a9b9dc0b51883f7fa0781cb
parentDiscards are now tracked (diff)
download7w-ac78ebaf7f7e9d96cb022ad8a14fc013a58ba262.tar.gz
7w-ac78ebaf7f7e9d96cb022ad8a14fc013a58ba262.tar.bz2
7w-ac78ebaf7f7e9d96cb022ad8a14fc013a58ba262.zip
Started work on special wonder actions
-rw-r--r--data.c64
-rw-r--r--main.c8
-rw-r--r--special_actions.c88
-rw-r--r--wonder.c31
4 files changed, 168 insertions, 23 deletions
diff --git a/data.c b/data.c
index da23108..7488fa4 100644
--- a/data.c
+++ b/data.c
@@ -20,6 +20,7 @@ void io_printborder(int x, int y, int width);
int io_printtext(int xorigin, int y, int width, char* text);
int io_getkey();
int data_haswonderstage(int p, int wonder, int stage);
+void special_action(int player, int wonder, int stage);
#define MISC 3
#define DATAGOLD 0
@@ -27,8 +28,9 @@ int data_haswonderstage(int p, int wonder, int stage);
static int decks[3][49];
static int discards[3][49];
static int player[7][4][7]; //3 eras and extra stuff (wonder, wonder side, wonder stages completed, gold, military wins, defeats, vps(partial))
-static int buffer[7][3];
+static int buffer[7][4];
static int hands[7][7];
+static int ais[7];
static int numplayers;
static int era;
static int turn;
@@ -50,15 +52,19 @@ void data_sorthands()
}
void data_endgame();
+void data_discard(int p, int card);
void data_nextera()
{
+ int i, j, k;
+ for(i = 0; i < numplayers; i++) {
+ data_discard((i+numplayers-turn)%numplayers, hands[i][0]);
+ }
war();
if(era == 2) data_endgame();
era++;
turn = 0;
totturns = 0;
- int i, j, k;
k = 0;
for(i = 0; i < numplayers; i++)
for(j = 0; j < 7; j++)
@@ -76,6 +82,8 @@ void data_distributewonders()
for(i = 0; i < numplayers; i++) {
player[i][3][0] = wonders[i];
player[i][3][1] = rand()%2;
+ player[0][3][0] = 8; //delete these lines later
+ player[0][3][1] = 1; //this one too!
}
}
@@ -120,6 +128,10 @@ void data_endturn()
}
player[i][3][3] += buffer[i][1]; //change in gold
player[i][3][6] += buffer[i][2];
+ if(buffer[i][3]) {
+ buffer[i][3] = 0; //do this early to allow setting of flag as special action
+ special_action(i, data_getwonder(i), data_getwonderside(i)*3+1+data_getwonderstages(i));
+ }
buffer[i][0] = -1;
buffer[i][1] = 0;
buffer[i][2] = 0;
@@ -128,6 +140,21 @@ void data_endturn()
if(totturns == 6) data_nextera();
}
+int data_turnnum()
+{
+ return totturns;
+}
+
+void data_setai(int p)
+{
+ ais[p] = 1;
+}
+
+int data_isai(int p)
+{
+ return ais[p];
+}
+
int data_geteast(int p)
{
int ret = p-1;
@@ -239,17 +266,28 @@ void data_addvps(int amnt, int p)
buffer[p][2] += amnt;
}
+void data_setspecialflag(int p)
+{
+ buffer[p][3] = 1;
+}
+
int data_numplayers()
{
return numplayers;
}
-int** data_getdiscards()
+int* data_getdiscards()
{
- static int **ret;
- int i;
- for(i = 0; i < 3; i++)
- ret[i] = discards[i];
+ static int ret[150];
+ int i, j, k;
+ for(i = 0; i < 150; i++) ret[i] = -1;
+ k = 0;
+ for(i = 0; i < 3; i++) {
+ for(j = 0; discards[i][j] != -1 && j < 49; j++) {
+ ret[k++] = i;
+ ret[k++] = discards[i][j];
+ }
+ }
return ret;
}
@@ -278,13 +316,18 @@ void data_discard(int p, int card)
discards[era][i] = card;
}
+void data_freebuild(int p, int e, int card)
+{
+ data_addgold(cards_getproduction(e, card)[GOLD], p);
+ data_addvps(cards_getproduction(e, card)[VP], p);
+ data_addgold(get_special(e, card, p)[1], p);
+}
+
void data_build(int p, int card)
{
buffer[p][0] = card; //will be added to player array at end of turn
data_addgold(cards_getcost(era, card)[GOLD] * -1, p);
- data_addgold(cards_getproduction(era, card)[GOLD], p);
- data_addvps(cards_getproduction(era, card)[VP], p);
- data_addgold(get_special(era, card, p)[1], p);
+ data_freebuild(p, era, card);
data_remove(p, card);
}
@@ -294,6 +337,7 @@ void data_buildwonder(int p, int card)
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_setspecialflag(p);
data_remove(p, card);
}
diff --git a/main.c b/main.c
index f743298..f37bba3 100644
--- a/main.c
+++ b/main.c
@@ -14,6 +14,8 @@ void view_refresh(int focus, int cursor, int player);
int data_numplayers();
void data_endturn();
int data_getera();
+void data_setai(int p);
+int data_isai(int p);
void halt()
{
@@ -27,7 +29,7 @@ main_routine()
{
int player = 0;
while(1) {
- if(ais[player]) ai_turn(player);
+ if(data_isai(player)) ai_turn(player);
else player_turn(player);
if(++player == data_numplayers()) {
data_endturn();
@@ -41,6 +43,10 @@ main()
io_init();
cards_init();
data_init(4);
+ int i;
+ for(i = 0; i < 7; i++) {
+ if(ais[i]) data_setai(i);
+ }
main_routine();
halt();
}
diff --git a/special_actions.c b/special_actions.c
new file mode 100644
index 0000000..5b6e0ed
--- /dev/null
+++ b/special_actions.c
@@ -0,0 +1,88 @@
+#include "7w.h"
+
+int* data_getdiscards();
+void data_deletediscard(int era, int card);
+void data_build(int p, int card);
+void data_setspecialflag(int p);
+int data_numplayers();
+int data_turnnum();
+int print_cards(int x, int y, int *cards, int cursor);
+int io_printtext(int xorigin, int y, int width, char* text);
+void io_printborder(int x, int y, int width);
+int io_getkey();
+void posthelp();
+int data_isai(int p);
+
+void Halicarnassus(int player)
+{
+ int x = 61;
+ int y = 0;
+ int focus = data_numplayers();
+ int i;
+ int cursor = 0;
+ int *discards = data_getdiscards();
+ int numcards = 0;
+ int bottom = 0;
+ while(discards[numcards++] != -1 && numcards < 50);
+ numcards /= 2;
+ io_printborder(x, y++, 28);
+ y = io_printtext(x, y, 28, " Discards");
+ while(1) {
+ bottom = print_cards(x, y, discards, cursor);
+ switch(io_getkey()) {
+ case UP: cursor--;
+ break;
+ case DOWN: cursor++;
+ break;
+ case RIGHT: focus++;
+ cursor = 0;
+ break;
+ case LEFT: focus--;
+ cursor = 0;
+ break;
+ case '\t': focus = (focus+1)%(data_numplayers()+1);
+ cursor = 0;
+ break;
+ case 'h': posthelp();
+ break;
+ case ENTER:
+ if(data_hasbuiltname(player, discards[cursor*2], discards[cursor*2+1])) {
+ postmessage("Cannot have two of the same card!");
+ }
+ else {
+ data_freebuild(player, discards[cursor*2], discards[cursor*2+1]);
+ data_deletediscard(discards[cursor*2], discards[cursor*2+1]);
+ return;
+ }
+ default: break;
+ }
+ if(focus < 0) focus = data_numplayers();
+ focus = focus%(data_numplayers()+1);
+ if(focus == data_numplayers()) {
+ if(cursor < 0) cursor = numcards-1;
+ if(cursor >= numcards) cursor = 0;
+ }
+ else {
+ if(cursor < 0) cursor = wonder_numstages((player+focus)%data_numplayers())+data_numbuilt(player+focus%data_numplayers())-1;
+ cursor = cursor % (wonder_numstages((player+focus)%data_numplayers())+data_numbuilt(player+focus%data_numplayers()));
+ }
+ }
+}
+
+void special_action(int player, int wonder, int stage)
+{
+ if(wonder == 8) { //Halicarnassus
+ if(stage == 2 || stage == 4 || stage == 5 || stage == 6)
+ if(data_isai(player));
+ else Halicarnassus(player);
+ }
+ if(wonder == 6) { //Babylon
+ if(stage >= 5) {
+ if(data_turnnum() < 6) data_setspecialflag(player);
+ else {
+ if(data_isai(player));
+ else;
+ }
+ }
+ }
+}
diff --git a/wonder.c b/wonder.c
index dffceb4..dc1ba83 100644
--- a/wonder.c
+++ b/wonder.c
@@ -36,6 +36,23 @@ int wonder_numstages(int player)
return 3;
}
+int print_cards(int x, int y, int *cards, int cursor)
+{
+ int i = 0;
+ int j;
+ int print = -1;
+ for(j = 0; cards[j] != -1; j+=2) {
+ io_printname(x, y++, cards[j], cards[j+1]);
+ if(cursor == i++) {
+ io_printplain(x+25, y-1, "*");
+ print = j;
+ }
+ }
+ if(j == 0) y--;
+ io_printborder(x, y, 28);
+ return y;
+}
+
int* print_wonder(int x, int y, int player, int cursor)
{
int i, j;
@@ -85,16 +102,8 @@ int* print_wonder(int x, int y, int player, int cursor)
//Print what has been built
int *built = data_getbuilt(player);
- int print = -1;
- for(j = 0; built[j] != -1; j+=2) {
- io_printname(x, y++, built[j], built[j+1]);
- if(cursor == i++) {
- io_printplain(x+25, y-1, "*");
- print = j;
- }
- }
- if(j == 0) y--;
- io_printborder(x, y, 28);
+ y = print_cards(x, y, built, cursor - i);
+ int print = 2*(cursor - i);
//Info about component
static int ret[2];
@@ -103,12 +112,10 @@ int* print_wonder(int x, int y, int player, int cursor)
ret[0] = data_getwonder(player);
ret[1] = cursor+1+3*data_getwonderside(player), player;
}
- //return io_printcard(x, y, data_getwonder(player), cursor+1+3*data_getwonderside(player), player);
if(cursor >= wonder_numstages(player)) {
ret[0] = built[print];
ret[1] = built[print+1];
}
- //return io_printcard(x, y, built[print], built[print+1], player);
return ret;
}
bgstack15