diff options
author | Nathan Vance <nathav63@gmail.com> | 2015-02-22 23:04:50 -0500 |
---|---|---|
committer | Nathan Vance <nathav63@gmail.com> | 2015-02-22 23:04:50 -0500 |
commit | c5e6b7b4c1adab9c40ea7c73e828605cbad833f8 (patch) | |
tree | 04251e3529c5481885c7ae0a91107b95f360bd63 | |
parent | Added basic purchasing with definites (diff) | |
download | 7w-c5e6b7b4c1adab9c40ea7c73e828605cbad833f8.tar.gz 7w-c5e6b7b4c1adab9c40ea7c73e828605cbad833f8.tar.bz2 7w-c5e6b7b4c1adab9c40ea7c73e828605cbad833f8.zip |
Added more support for idefinites, but has major bugs!
-rw-r--r-- | 7w.h | 2 | ||||
-rw-r--r-- | data.c | 47 | ||||
-rw-r--r-- | util.c | 2 | ||||
-rw-r--r-- | wonder.c | 32 |
4 files changed, 47 insertions, 36 deletions
@@ -52,3 +52,5 @@ #define COLORMILITARY 31 #define COLORSCIENTIFIC 32 #define COLORGUILD 35 + +#define INDEF 8 @@ -208,19 +208,25 @@ void data_removedefinites(int p, int *cost) } } -#define INDEF 16 - -int* data_getindefinites(int p) +int** data_getindefinites(int p) { - int *ret = get_intarray(INDEF); - int i, j, k; + int i, j, k, l, m, *prod; + static int *ret[INDEF]; + for(i = 0; i < INDEF; i++) { + ret[i] = get_intarray(4); + for(j = 0; j < 4; j++) + ret[i][j] = -1; + } k = 0; - for(i = 0; i < INDEF; i++) ret[i] = 0; for(i = 0; i < 2; i++) { for(j = 0; j < 7; j++) { if(data_productiontype(i, player[p][i][j]) == 2) { - ret[k++] = i; - ret[k++] = player[p][i][j]; + m = 0; + prod = cards_getproduction(i, player[p][i][j]); + for(l = 0; l < GOLD; l++) { + if(prod[l]) ret[k][m++] = l; + } + k++; } } } @@ -236,24 +242,17 @@ int data_iszerocost(int *cost) return free; } -static int recurse(int *cost, int *indef) +static int recurse(int *cost, int **indef, int c) { + if(c == INDEF) return 0; int i; - int ncost[GOLD], nindef[INDEF], *prod; + int ncost[GOLD]; for(i = 0; i < GOLD; i++) ncost[i] = cost[i]; - for(i = 0; i < INDEF; i++) nindef[i] = indef[i]; - for(i = 0; i < INDEF && nindef[i] != 0; i += 2); - if(i < INDEF) { - prod = cards_getproduction(nindef[i-1], nindef[i]); - nindef[i-1] = nindef[i] = 0; - for(i = 0; i < GOLD; i++) { - if(prod[i] && ncost[i]) { - ncost[i] -= prod[i]; - if(data_iszerocost(ncost)) return 1; - if(recurse(ncost, nindef)) return 1; - ncost[i] += prod[i]; - } - } + for(i = 0; i < 4 && indef[c][i] != -1; i++) { + ncost[indef[c][i]]--; + if(data_iszerocost(ncost)) return 1; + if(recurse(ncost, indef, c+1)) return 1; + ncost[indef[c][i]]++; } return 0; } @@ -265,7 +264,7 @@ int data_canafford(int p, int *cost) int i, j, k; data_removedefinites(p, cost); if(data_iszerocost(cost)) return 2; - return recurse(cost, data_getindefinites(p)); + return recurse(cost, data_getindefinites(p), 0); } int* data_getbuilt(int p) @@ -8,6 +8,7 @@ static void replace(char a[], char b[], int x, int y); #define POOLSIZE 10000 static int ipool[POOLSIZE]; static int *ipoolp = ipool; + int* get_intarray(int size) { if(ipoolp + size > ipool + POOLSIZE) ipoolp = ipool; @@ -18,6 +19,7 @@ int* get_intarray(int size) static char cpool[POOLSIZE]; static char *cpoolp = cpool; + char* get_chararray(int size) { if(cpoolp + size > cpool + POOLSIZE) cpoolp = cpool; @@ -21,6 +21,7 @@ void io_clearscreen(); 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 wonder_numstages(int player) { @@ -34,7 +35,7 @@ int wonder_numstages(int player) int print_wonder(int x, int y, int player, int cursor) { - int i; + int i, j; io_printborder(x, y++); y = io_printtext(x, y, 29, cards_getname(data_getwonder(player), 0)); y = io_printtext(x, y, 29, cat("Produces: 1 ", getname(cards_gettype(data_getwonder(player), 0)))); @@ -43,18 +44,26 @@ int print_wonder(int x, int y, int player, int cursor) //Print resource incomes int *def = data_getdefinites(player); - int has = 0; - for(i = 0; i < GOLD; i++) - if(def[i]) has = 1; - if(has) { - y = io_printtext(x, y, 29, "Production:"); - for(i = 0; i < GOLD; i++) { - if(def[i]) { - y = io_printtext(x, y, 29, cat(cat(cat(" ", getname(i)), ": "), itoa(def[i]))); - } + def[cards_gettype(data_getwonder(player), 0)]++; + int **indef = data_getindefinites(player); + y = io_printtext(x, y, 29, "Production:"); + for(i = 0; i < GOLD; i++) { + if(def[i]) { + y = io_printtext(x, y, 29, cat(cat(cat(" ", getname(i)), ": "), itoa(def[i]))); } - io_printborder(x, y++); } + for(i = 0; i < INDEF; i++) { + char *text = ""; + for(j = 0; j < 4; j++) { + if(indef[i][j] != -1) + text = cat(cat(text, "/"), getname(indef[i][j])); + } + if(text[0] != '\0') { + y = io_printtext(x, y, 29, text); + io_printplain(x+2, y-1, " "); + } + } + io_printborder(x, y++); //Print wonder stages for(i = 0; i < wonder_numstages(player); i++) { @@ -73,7 +82,6 @@ int print_wonder(int x, int y, int player, int cursor) //Print what has been built int *built = data_getbuilt(player); - int j; int print = -1; for(j = 0; built[j] != -1; j+=2) { io_printname(x, y++, built[j], built[j+1]); |