diff options
author | Nathan Vance <nathav63@gmail.com> | 2015-03-30 21:16:17 -0400 |
---|---|---|
committer | Nathan Vance <nathav63@gmail.com> | 2015-03-30 21:16:17 -0400 |
commit | 84a9208b7f7713d9c94b23d60757051ffde586a4 (patch) | |
tree | c66d37b8519d8d11029da6e1b10112ae62bdd5e8 | |
parent | Started work on special wonder actions (diff) | |
download | 7w-84a9208b7f7713d9c94b23d60757051ffde586a4.tar.gz 7w-84a9208b7f7713d9c94b23d60757051ffde586a4.tar.bz2 7w-84a9208b7f7713d9c94b23d60757051ffde586a4.zip |
Added more special actions
-rw-r--r-- | ai.c | 2 | ||||
-rw-r--r-- | data.c | 25 | ||||
-rw-r--r-- | messenger.c | 29 | ||||
-rw-r--r-- | player_turn.c | 6 | ||||
-rw-r--r-- | special_actions.c | 6 |
5 files changed, 62 insertions, 6 deletions
@@ -32,7 +32,7 @@ int* ai_bestcard(int *hand, int player) //return card temp = weight_buildcard(data_getera(), hand[i], player); if(data_hasbuiltname(player, data_getera(), hand[i])) temp = 0; - else if(! data_canafford(player, data_getera(), hand[i])) { + else if(data_canafford(player, data_getera(), hand[i]) != 1) { trade = ai_trade(player, data_getera(), hand[i]); if(trade[2]) temp -= trade[2] / 3; else temp = 0; @@ -36,6 +36,7 @@ static int era; static int turn; static int totturns; static int turngoldbuffer[7]; +static int hasfreebuild; //holds player that has a free build. Once set, will be that player, or (player+1)*-1 if already used. void data_sorthands() { @@ -70,6 +71,8 @@ void data_nextera() for(j = 0; j < 7; j++) hands[i][j] = decks[era][k++]; data_sorthands(); + if(hasfreebuild < 0 && hasfreebuild != -10) + hasfreebuild = hasfreebuild * -1 - 1; } void data_distributewonders() @@ -82,13 +85,14 @@ 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! + player[0][3][0] = 7; //delete these lines later + player[0][3][1] = 0; //this one too! } } void data_init(int n) { + hasfreebuild = -10; numplayers = n; int i, j, k, *deck; for(i = 0; i < 3; i++) { @@ -140,6 +144,16 @@ void data_endturn() if(totturns == 6) data_nextera(); } +int data_setfreebuild(int p) +{ + hasfreebuild = p; +} + +int data_spendfreebuild() +{ + hasfreebuild = (hasfreebuild+1)*-1; +} + int data_turnnum() { return totturns; @@ -530,14 +544,17 @@ int data_iscouponed(int p, int era, int card) int data_canafford(int p, int era, int card) { + int ret; if(data_iscouponed(p, era, card)) return 1; int *cost = cards_getcost(era, card); - if(cost[GOLD] > data_getgold(p)) return 0; int i, j, k; data_removedefinites(p, cost); data_removetraded(p, cost); if(data_iszerocost(cost)) return 1; - return recurse(cost, data_getindefinites(p), 0); + ret = recurse(cost, data_getindefinites(p), 0) && (cost[GOLD] <= data_getgold(p)); + if(ret) return 1; + if(p == hasfreebuild) return 2; + return 0; } int data_haswonderstage(int p, int wonder, int stage) diff --git a/messenger.c b/messenger.c index ba49785..bea67df 100644 --- a/messenger.c +++ b/messenger.c @@ -63,3 +63,32 @@ int postoptions(int x, int y) cursor = cursor%4; } } + +int postyn(int x, int y, char *message) +{ + int yorig = y; + int width = 28; + int cursor = 0; + char* a = " * No Yes "; + char* b = " No * Yes "; + while(1) { + y = yorig; + io_printborder(x, y++, width); + y = io_printtext(x, y++, width, message); + if(cursor == 0) y = io_printtext(x, y, width, a); + if(cursor == 1) y = io_printtext(x, y, width, b); + io_printborder(x, y++, width); + switch(io_getkey()) { + case LEFT: cursor--; + break; + case RIGHT: cursor++; + break; + case ENTER: return cursor; + break; + default: break; + } + if(cursor < 0) cursor = 1; + cursor = cursor%2; + } + return cursor; +} diff --git a/player_turn.c b/player_turn.c index f4bf19e..84a02e3 100644 --- a/player_turn.c +++ b/player_turn.c @@ -24,10 +24,13 @@ void clearmessage(); int postoptions(int x, int y); int trade_routine(int x, int y, int player); void trade_commit(int player); +int data_spendfreebuild(); +int postyn(int x, int y, char *message); int player_build(int focus, int cursor, int player, int y) { int *hand = data_gethand(player); + int afford = data_canafford(player, data_getera(), hand[cursor]); if(focus == data_numplayers()) { if(hand[cursor] == -1) return 0; int choice = postoptions(61, y); @@ -36,8 +39,9 @@ int player_build(int focus, int cursor, int player, int y) postmessage("Cannot have two of the same card!"); return 0; } - if(data_canafford(player, data_getera(), hand[cursor])) { + if(afford == 1 || (afford == 2 && postyn(61, y, "Spend free build?"))) { data_build(player, hand[cursor]); + if(afford == 2) data_spendfreebuild(); return 1; } else postmessage("Can't afford this!"); diff --git a/special_actions.c b/special_actions.c index 5b6e0ed..fa8d013 100644 --- a/special_actions.c +++ b/special_actions.c @@ -12,6 +12,7 @@ void io_printborder(int x, int y, int width); int io_getkey(); void posthelp(); int data_isai(int p); +void data_setfreebuild(int p); void Halicarnassus(int player) { @@ -85,4 +86,9 @@ void special_action(int player, int wonder, int stage) } } } + if(wonder == 7) { //Olympia + if(stage == 2) { + data_setfreebuild(player); + } + } } |