From 68d09777d9f188b2ac69c98ccfdcc315037224fd Mon Sep 17 00:00:00 2001 From: Nathan Vance Date: Sat, 28 Feb 2015 00:18:29 -0500 Subject: added science to vp count; color to trades --- 7w.h | 3 +++ data.c | 19 ++++++++++++++++++- io.c | 10 +++++++++- science.c | 42 ++++++++++++++++++++++++++++++++++++++++++ trade.c | 6 ++++++ wonder.c | 6 ++++++ 6 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 science.c diff --git a/7w.h b/7w.h index b6ad441..b7be4dd 100644 --- a/7w.h +++ b/7w.h @@ -54,3 +54,6 @@ #define COLORGUILD 35 #define INDEF 8 + +#define RED 31 +#define ESC '\1' diff --git a/data.c b/data.c index fbe8dec..75df70b 100644 --- a/data.c +++ b/data.c @@ -11,6 +11,7 @@ void shuffle(int *deck, int n); int* trade_buffer(); int* get_special(int era, int card, int player); void war(); +int science(int player); #define MISC 3 #define DATAGOLD 0 @@ -218,7 +219,7 @@ 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(get_special(era, card, p)[0], p); + data_addvps(cards_getproduction(era, card)[VP], p); data_addgold(get_special(era, card, p)[1], p); data_discard(p, card); } @@ -394,3 +395,19 @@ int data_numbuilt(int p) if(player[p][i][j] != -1) num++; return num; } + +int data_gettotvps(int p) +{ + int tot = 0; + tot += player[p][3][3] / 3; //gold + tot += player[p][3][4]; //military wins + tot -= player[p][3][5]; //military defeats + tot += player[p][3][6]; //vps + int *built = data_getbuilt(p); + int i; + for(i = 0; built[i] != -1; i += 2) { + tot += get_special(built[i], built[i+1], p)[0]; + } + tot += science(p); + return tot; +} diff --git a/io.c b/io.c index 68c9010..bec7045 100644 --- a/io.c +++ b/io.c @@ -104,8 +104,9 @@ int io_printtext(int xorigin, int y, int width, char* text) x = xorigin+2; } mvprintw(y, x, ""); - for(i = wordstart; i < wordstart+wordlength; i++) + for(i = wordstart; i < wordstart+wordlength; i++) { if(text[i] != '\n') addch(text[i]); + } x += wordlength; wordstart += wordlength; } @@ -216,3 +217,10 @@ void io_printplain(int x, int y, char *s) { mvprintw(y, x, "%s", s); } + +void io_printcolor(int x, int y, int color, char *s) +{ + attron(COLOR_PAIR(color)); + io_printplain(x, y, s); + attrset(A_NORMAL); +} diff --git a/science.c b/science.c new file mode 100644 index 0000000..89af807 --- /dev/null +++ b/science.c @@ -0,0 +1,42 @@ +#include "7w.h" + +int* data_getbuilt(int p); +int* cards_getproduction(int era, int card); +int cards_gettype(int era, int card); +int data_hasbuilt(int p, int era, int card); + +int calc_science(int player, int guildval) +{ + int science[3]; + int i, j; + for(i = 0; i < 3; i++) science[i] = 0; + if(guildval != -1) science[guildval]++; + int *built = data_getbuilt(player); + int *prod; + for(i = 0; built[i] != -1; i += 2) { + if(cards_gettype(built[i], built[i+1]) == SCIENTIFIC) { + prod = cards_getproduction(built[i], built[i+1]); + for(j = COMPASS; j <= TABLET; j++) { + science[j-COMPASS] += prod[j]; + } + } + } + int min = science[0]; + for(i = 0; i < 3; i++) + if(science[i] < min) min = science[i]; + int ret = 7*min; + for(i = 0; i < 3; i++) ret += science[i] * science[i]; + return ret; +} + +int science(int player) +{ + if(! data_hasbuilt(player, 2, 25)) return calc_science(player, -1); + int max = 0; + int i, m; + for(i = 0; i < 3; i++) { + m = calc_science(player, i); + if(m > max) max = m; + } + return max; +} diff --git a/trade.c b/trade.c index be3d339..8e474bd 100644 --- a/trade.c +++ b/trade.c @@ -14,8 +14,10 @@ int io_getkey(); void io_printborder(int x, int y, int width); int io_printtext(int xorigin, int y, int width, char* text); void io_printplain(int x, int y, char *s); +void io_printcolor(int x, int y, int color, char *s); char* getname(int res); int view_refresh(int focus, int cursor, int player); +char* itoa(int i); static int tradebuffer[3][GOLD+1]; @@ -96,6 +98,10 @@ void trade_print(int x, int y, int player, int cursorx, int cursory) for(i = 0; i < GOLD+1; i++) { sprintf(s, "%-7s %d %c| %-7s %d %c", getname(i), west[i], (cursorx == 1 && cursory == i)? '*' : ' ', getname(i), east[i], (cursorx == 0 && cursory == i)? '*' : ' '); y = io_printtext(x, y, width, s); + if(tradebuffer[1][i]) + io_printcolor(x+10, y-1, 31, itoa(west[i])); + if(tradebuffer[0][i]) + io_printcolor(x+23, y-1, 31, itoa(east[i])); } sprintf(s, "Your gold: %d", data_getgold(player)); y = io_printtext(x, y, width, s); diff --git a/wonder.c b/wonder.c index de5a986..e945ea9 100644 --- a/wonder.c +++ b/wonder.c @@ -1,4 +1,5 @@ #include "7w.h" +#include int* cards_getcost(int wonder, int stage); //remember the stage offset! int* cards_getproduction(int wonder, int stage); @@ -22,6 +23,8 @@ int* data_getbuilt(int p); void io_printplain(int x, int y, char *s); int* data_getdefinites(int p); int** data_getindefinites(int p); +int data_gettotvps(int p); +int military_might(int player); int wonder_numstages(int player) { @@ -103,11 +106,14 @@ int print_wonder(int x, int y, int player, int cursor) //dir is 0 for none, 1 for east, 2 for west int print_wondersmall(int x, int y, int player, int selected, int dir) { + char s[28]; io_printborder(x, y++, 28); if(selected) io_printplain(28, y, "*"); if(dir == 1) io_printplain(29, y, "East"); if(dir == 2) io_printplain(29, y, "West"); y = io_printtext(x, y, 28, cards_getname(data_getwonder(player), 0)); + sprintf(s, "army: %-2d vp's: %-2d", military_might(player), data_gettotvps(player)); + y = io_printtext(x, y, 28, s); io_printborder(x, y, 28); return y; } -- cgit