diff options
author | Nathan Vance <nathav63@gmail.com> | 2015-02-28 00:18:29 -0500 |
---|---|---|
committer | Nathan Vance <nathav63@gmail.com> | 2015-02-28 00:18:29 -0500 |
commit | 68d09777d9f188b2ac69c98ccfdcc315037224fd (patch) | |
tree | 76d41617e8ec05be2afe50a8f1b3dd6660f32332 | |
parent | Added battles (diff) | |
download | 7w-68d09777d9f188b2ac69c98ccfdcc315037224fd.tar.gz 7w-68d09777d9f188b2ac69c98ccfdcc315037224fd.tar.bz2 7w-68d09777d9f188b2ac69c98ccfdcc315037224fd.zip |
added science to vp count; color to trades
-rw-r--r-- | 7w.h | 3 | ||||
-rw-r--r-- | data.c | 19 | ||||
-rw-r--r-- | io.c | 10 | ||||
-rw-r--r-- | science.c | 42 | ||||
-rw-r--r-- | trade.c | 6 | ||||
-rw-r--r-- | wonder.c | 6 |
6 files changed, 84 insertions, 2 deletions
@@ -54,3 +54,6 @@ #define COLORGUILD 35 #define INDEF 8 + +#define RED 31 +#define ESC '\1' @@ -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; +} @@ -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; +} @@ -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); @@ -1,4 +1,5 @@ #include "7w.h" +#include <stdio.h> 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; } |