From 48b4726624994097174fa820cd9c529177566d07 Mon Sep 17 00:00:00 2001 From: Nathan Vance Date: Wed, 25 Mar 2015 09:07:04 -0400 Subject: Discards are now tracked --- data.c | 34 ++++++++++++++++++-- special_cards.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ specialcards.c | 96 --------------------------------------------------------- view.c | 16 +++++++--- wonder.c | 19 +++++++++--- 5 files changed, 152 insertions(+), 109 deletions(-) create mode 100644 special_cards.c delete mode 100644 specialcards.c diff --git a/data.c b/data.c index 81bfe56..da23108 100644 --- a/data.c +++ b/data.c @@ -25,6 +25,7 @@ int data_haswonderstage(int p, int wonder, int stage); #define DATAGOLD 0 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 hands[7][7]; @@ -87,6 +88,9 @@ void data_init(int n) for(j = 0; j < numplayers*7; j++) decks[i][j] = deck[j]; } + for(i = 0; i < 3; i++) + for(j = 0; j < 49; j++) + discards[i][j] = -1; era = -1; data_nextera(); data_distributewonders(n); @@ -240,7 +244,23 @@ int data_numplayers() return numplayers; } -void data_discard(int p, int card) +int** data_getdiscards() +{ + static int **ret; + int i; + for(i = 0; i < 3; i++) + ret[i] = discards[i]; + return ret; +} + +void data_deletediscard(int era, int card) +{ + int i; + for(i = 0; discards[era][i] != card && i < 48; i++); + discards[era][i] = -1; +} + +void data_remove(int p, int card) //as in, removes it from the hand { int i; int *hand = hands[(p+turn)%numplayers]; @@ -250,6 +270,14 @@ void data_discard(int p, int card) for(i = 0; i < 7; i++) turngoldbuffer[i] = 0; //end of turn } +void data_discard(int p, int card) +{ + data_remove(p, card); + int i; + for(i = 0; discards[era][i] != -1 && i < 49; i++); + discards[era][i] = card; +} + void data_build(int p, int card) { buffer[p][0] = card; //will be added to player array at end of turn @@ -257,7 +285,7 @@ void data_build(int p, int card) 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_discard(p, card); + data_remove(p, card); } void data_buildwonder(int p, int card) @@ -266,7 +294,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_discard(p, card); + data_remove(p, card); } //0 is non producing, 1 produces one kind of resource, 2 produces multiple resources diff --git a/special_cards.c b/special_cards.c new file mode 100644 index 0000000..b49e53c --- /dev/null +++ b/special_cards.c @@ -0,0 +1,96 @@ +#include "7w.h" + +int data_geteast(int p); +int data_getwest(int p); +int* data_getbuilt(int p); +int cards_gettype(int era, int card); +int data_getwonderstages(int p); +int data_getdefeats(int p); + +int cardcounter(int *cards, int type) +{ + int sum = 0; + int i; + for(i = 0; cards[i] != -1; i+=2) { + if(cards_gettype(cards[i], cards[i+1]) == type) sum++; + } + return sum; +} + +int* get_special(int era, int card, int player) +{ + //formatted vp, gold + static int ret[2]; + ret[0] = ret[1] = 0; + switch(era*100+card) { + case 113: //Vineyard: 1 coin for each resource card of adjacent players or your own. + ret[1] += cardcounter(data_getbuilt(data_geteast(player)), RESOURCE); + ret[1] += cardcounter(data_getbuilt(data_getwest(player)), RESOURCE); + ret[1] += cardcounter(data_getbuilt(player), RESOURCE); + break; + case 114: //Bazaar: 2 coins for each industry card of adjacent players or your own. + ret[1] += cardcounter(data_getbuilt(data_geteast(player)), INDUSTRY); + ret[1] += cardcounter(data_getbuilt(data_getwest(player)), INDUSTRY); + ret[1] += cardcounter(data_getbuilt(player), INDUSTRY); + ret[1] *= 2; + break; + case 205: //Haven: 1 coin and 1 vp for each resource card. + ret[0] = ret[1] = cardcounter(data_getbuilt(player), RESOURCE); + break; + case 206: //Lighthouse: 1 coin and 1 vp for each commercial card. + ret[0] = ret[1] = cardcounter(data_getbuilt(player), COMMERCIAL); + break; + case 207: //Chamber Of Commerce: 2 coins and 2 vps for each industrial card. + ret[0] = ret[1] = cardcounter(data_getbuilt(player), INDUSTRY) * 2; + break; + case 208: //Arena: 3 coins and 1 vp for each completed wonder stage. + ret[0] = data_getwonderstages(player); + ret[1] = 3*ret[1]; + break; + case 218: //Workers Guild: 1 vp for each resource card owned by adjacent players. + ret[0] += cardcounter(data_getbuilt(data_geteast(player)), RESOURCE); + ret[0] += cardcounter(data_getbuilt(data_getwest(player)), RESOURCE); + break; + case 219: //Craftmens Guild: 2 vps for each industrial card owned by adjacent players. + ret[0] += cardcounter(data_getbuilt(data_geteast(player)), INDUSTRY); + ret[0] += cardcounter(data_getbuilt(data_getwest(player)), INDUSTRY); + ret[0] *= 2; + break; + case 220: //Traders Guild: 1 vp for each commercial card owned by adjacent players. + ret[0] += cardcounter(data_getbuilt(data_geteast(player)), COMMERCIAL); + ret[0] += cardcounter(data_getbuilt(data_getwest(player)), COMMERCIAL); + break; + case 221: //Philosophers Guild: 1 vp for each scientific card owned by adjacent players. + ret[0] += cardcounter(data_getbuilt(data_geteast(player)), SCIENTIFIC); + ret[0] += cardcounter(data_getbuilt(data_getwest(player)), SCIENTIFIC); + break; + case 222: //Spy Guild: 1 vp for each military card owned by adjacent players. + ret[0] += cardcounter(data_getbuilt(data_geteast(player)), MILITARY); + ret[0] += cardcounter(data_getbuilt(data_getwest(player)), MILITARY); + break; + case 223: //Strategy Guild: 1 vp for each military defeat by adjacent players. + ret[0] += data_getdefeats(data_geteast(player)); + ret[0] += data_getdefeats(data_getwest(player)); + break; + case 224: //Shipowners Guild: 1 vp for each resource, industrial, and guild card. + ret[0] += cardcounter(data_getbuilt(player), RESOURCE); + ret[0] += cardcounter(data_getbuilt(player), INDUSTRY); + ret[0] += cardcounter(data_getbuilt(player), GUILD); + break; + case 225: //Scientists Guild: Counts as either a compass, gear or tablet. + ret[0] = ret[1] = 0; + break; + case 226: //Magistrates Guild: 1 vp for each structure card owned by adjacent players. + ret[0] += cardcounter(data_getbuilt(data_geteast(player)), STRUCTURE); + ret[0] += cardcounter(data_getbuilt(data_getwest(player)), STRUCTURE); + break; + case 227: //Builders Guild: 1 vp for each completed wonder stage by you or adjacent players. + ret[0] += data_getwonderstages(data_geteast(player)); + ret[0] += data_getwonderstages(data_getwest(player)); + ret[0] += data_getwonderstages(player); + break; + default: ret[0] = ret[1] = 0; + break; + } + return ret; +} diff --git a/specialcards.c b/specialcards.c deleted file mode 100644 index b49e53c..0000000 --- a/specialcards.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "7w.h" - -int data_geteast(int p); -int data_getwest(int p); -int* data_getbuilt(int p); -int cards_gettype(int era, int card); -int data_getwonderstages(int p); -int data_getdefeats(int p); - -int cardcounter(int *cards, int type) -{ - int sum = 0; - int i; - for(i = 0; cards[i] != -1; i+=2) { - if(cards_gettype(cards[i], cards[i+1]) == type) sum++; - } - return sum; -} - -int* get_special(int era, int card, int player) -{ - //formatted vp, gold - static int ret[2]; - ret[0] = ret[1] = 0; - switch(era*100+card) { - case 113: //Vineyard: 1 coin for each resource card of adjacent players or your own. - ret[1] += cardcounter(data_getbuilt(data_geteast(player)), RESOURCE); - ret[1] += cardcounter(data_getbuilt(data_getwest(player)), RESOURCE); - ret[1] += cardcounter(data_getbuilt(player), RESOURCE); - break; - case 114: //Bazaar: 2 coins for each industry card of adjacent players or your own. - ret[1] += cardcounter(data_getbuilt(data_geteast(player)), INDUSTRY); - ret[1] += cardcounter(data_getbuilt(data_getwest(player)), INDUSTRY); - ret[1] += cardcounter(data_getbuilt(player), INDUSTRY); - ret[1] *= 2; - break; - case 205: //Haven: 1 coin and 1 vp for each resource card. - ret[0] = ret[1] = cardcounter(data_getbuilt(player), RESOURCE); - break; - case 206: //Lighthouse: 1 coin and 1 vp for each commercial card. - ret[0] = ret[1] = cardcounter(data_getbuilt(player), COMMERCIAL); - break; - case 207: //Chamber Of Commerce: 2 coins and 2 vps for each industrial card. - ret[0] = ret[1] = cardcounter(data_getbuilt(player), INDUSTRY) * 2; - break; - case 208: //Arena: 3 coins and 1 vp for each completed wonder stage. - ret[0] = data_getwonderstages(player); - ret[1] = 3*ret[1]; - break; - case 218: //Workers Guild: 1 vp for each resource card owned by adjacent players. - ret[0] += cardcounter(data_getbuilt(data_geteast(player)), RESOURCE); - ret[0] += cardcounter(data_getbuilt(data_getwest(player)), RESOURCE); - break; - case 219: //Craftmens Guild: 2 vps for each industrial card owned by adjacent players. - ret[0] += cardcounter(data_getbuilt(data_geteast(player)), INDUSTRY); - ret[0] += cardcounter(data_getbuilt(data_getwest(player)), INDUSTRY); - ret[0] *= 2; - break; - case 220: //Traders Guild: 1 vp for each commercial card owned by adjacent players. - ret[0] += cardcounter(data_getbuilt(data_geteast(player)), COMMERCIAL); - ret[0] += cardcounter(data_getbuilt(data_getwest(player)), COMMERCIAL); - break; - case 221: //Philosophers Guild: 1 vp for each scientific card owned by adjacent players. - ret[0] += cardcounter(data_getbuilt(data_geteast(player)), SCIENTIFIC); - ret[0] += cardcounter(data_getbuilt(data_getwest(player)), SCIENTIFIC); - break; - case 222: //Spy Guild: 1 vp for each military card owned by adjacent players. - ret[0] += cardcounter(data_getbuilt(data_geteast(player)), MILITARY); - ret[0] += cardcounter(data_getbuilt(data_getwest(player)), MILITARY); - break; - case 223: //Strategy Guild: 1 vp for each military defeat by adjacent players. - ret[0] += data_getdefeats(data_geteast(player)); - ret[0] += data_getdefeats(data_getwest(player)); - break; - case 224: //Shipowners Guild: 1 vp for each resource, industrial, and guild card. - ret[0] += cardcounter(data_getbuilt(player), RESOURCE); - ret[0] += cardcounter(data_getbuilt(player), INDUSTRY); - ret[0] += cardcounter(data_getbuilt(player), GUILD); - break; - case 225: //Scientists Guild: Counts as either a compass, gear or tablet. - ret[0] = ret[1] = 0; - break; - case 226: //Magistrates Guild: 1 vp for each structure card owned by adjacent players. - ret[0] += cardcounter(data_getbuilt(data_geteast(player)), STRUCTURE); - ret[0] += cardcounter(data_getbuilt(data_getwest(player)), STRUCTURE); - break; - case 227: //Builders Guild: 1 vp for each completed wonder stage by you or adjacent players. - ret[0] += data_getwonderstages(data_geteast(player)); - ret[0] += data_getwonderstages(data_getwest(player)); - ret[0] += data_getwonderstages(player); - break; - default: ret[0] = ret[1] = 0; - break; - } - return ret; -} diff --git a/view.c b/view.c index 54c8ee8..88b8901 100644 --- a/view.c +++ b/view.c @@ -1,16 +1,18 @@ #include "7w.h" -int print_wonder(int x, int y, int player, int cursor); +int* print_wonder(int x, int y, int player, int cursor); int print_wondersmall(int x, int y, int player, int selected, int dir); int io_printhand(int x, int y, int player, int cursor); +int io_printcard(int x, int y, int wonder, int stage, int player); void io_clearscreen(); int data_numplayers(); void printmessage(int x, int y, int width); int data_geteast(int p); int data_getwest(int p); -void view_printwonders(int focus, int cursor, int player) +int* view_printwonders(int focus, int cursor, int player) { + int *ret; int num = data_numplayers(); int x, y, i, dir, p; x = y = 0; @@ -20,22 +22,26 @@ void view_printwonders(int focus, int cursor, int player) if(p == data_geteast(player)) dir = 1; if(p == data_getwest(player)) dir = 2; if(focus == p) - print_wonder(34, 0, p, cursor); + ret = print_wonder(34, 0, p, cursor); y = print_wondersmall(x, y, p, focus == p, dir); } printmessage(0, y+2, 35); + return ret; } int view_refresh(int focus, int cursor, int player) { int ret; + int *card; io_clearscreen(); if(focus == data_numplayers()) { - view_printwonders(player, -1, player); + card = view_printwonders(player, -1, player); ret = io_printhand(61, 0, player, cursor); } else { - view_printwonders((focus+player)%data_numplayers(), cursor, player); + card = view_printwonders((focus+player)%data_numplayers(), cursor, player); ret = io_printhand(61, 0, player, -1); } + if(card[0] != -1) + ret = io_printcard(61, ret-1, card[0], card[1], player); return ret; } diff --git a/wonder.c b/wonder.c index 252472d..dffceb4 100644 --- a/wonder.c +++ b/wonder.c @@ -36,7 +36,7 @@ int wonder_numstages(int player) return 3; } -int print_wonder(int x, int y, int player, int cursor) +int* print_wonder(int x, int y, int player, int cursor) { int i, j; io_printborder(x, y++, 28); @@ -97,10 +97,19 @@ int print_wonder(int x, int y, int player, int cursor) io_printborder(x, y, 28); //Info about component - if(cursor >= 0 && cursor < wonder_numstages(player)) - return io_printcard(x, y, data_getwonder(player), cursor+1+3*data_getwonderside(player), player); - if(cursor >= wonder_numstages(player)) - return io_printcard(x, y, built[print], built[print+1], player); + static int ret[2]; + ret[0] = ret[1] = -1; + if(cursor >= 0 && cursor < wonder_numstages(player)) { + 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; } //dir is 0 for none, 1 for east, 2 for west -- cgit