diff options
-rw-r--r-- | 7w.h | 2 | ||||
-rw-r--r-- | cards.c | 45 | ||||
-rw-r--r-- | io.c | 81 | ||||
-rw-r--r-- | main.c | 28 |
4 files changed, 133 insertions, 23 deletions
@@ -1,3 +1,5 @@ +#define CARDSPERERA 30 + #define NUMRESOURCES 8 #define WOOD 0 #define STONE 1 @@ -4,14 +4,14 @@ #define STARTPRODUCTION 1+NUMRESOURCES #define STARTCOUPONS 1+NUMRESOURCES+NUMPRODUCTS #define STARTCOUPONED 1+NUMRESOURCES+NUMPRODUCTS+4 - +#define STARTNAME 1+NUMRESOURCES+NUMPRODUCTS+8 +#define STARTDESCRIPTION STARTNAME+25 char* get_chararray(int size); int* get_intarray(int size); //era, card#, resource cost / resource production / coupons / couponed by / card name -#define CARDSPERERA 30 -static int cards[3][CARDSPERERA][60]; +static int cards[3][CARDSPERERA][200]; void cards_setcost(int era, int card, int res, int num) { @@ -86,7 +86,7 @@ void cards_updatecoupons() for(i = 0; i <= 1; i++) { for(j = 0; j < CARDSPERERA; j++) { for(k = STARTCOUPONS; k <= STARTCOUPONS+2; k += 2) { - if(cards[i][j][k] != 0) { + if(cards[i][j][k]) { card = cards[cards[i][j][k]][cards[i][j][k+1]]; if(card[STARTCOUPONED+1]) { card[STARTCOUPONED+2] = i; @@ -104,7 +104,7 @@ void cards_updatecoupons() void cards_setname(int era, int card, char *name, int type) { int i; - for(i = 0; (cards[era][card][i+1+NUMRESOURCES+NUMPRODUCTS+8] = name[i]) != '\0'; i++); + for(i = 0; (cards[era][card][STARTNAME+i] = name[i]) != '\0'; i++); cards_settype(era, card, type); } @@ -112,7 +112,21 @@ char* cards_getname(int era, int card) { char *ret = get_chararray(26); int i; - for(i = 0; (ret[i] = cards[era][card][i+1+NUMRESOURCES+NUMPRODUCTS+8]) != '\0'; i++); + for(i = 0; (ret[i] = cards[era][card][STARTNAME+i]) != '\0'; i++); + return ret; +} + +void cards_setmessage(int era, int card, char *message) +{ + int i; + for(i = 0; (cards[era][card][STARTDESCRIPTION+i] = message[i]) != '\0'; i++); +} + +char* cards_specialmessage(int era, int card) +{ + char *ret = get_chararray(100); + int i; + for(i = 0; (ret[i] = cards[era][card][STARTDESCRIPTION+i]) != '\0'; i++); return ret; } @@ -210,12 +224,15 @@ void cards_init() cards_setname(0, 17, "Tavern", COMMERCIAL); cards_setcoupons(0, 18, 1, 11, 0, 0); + cards_setmessage(0, 18, "Can trade 1 coin for resources with player to the LEFT."); cards_setname(0, 18, "East Trading Post", COMMERCIAL); cards_setcoupons(0, 19, 1, 11, 0, 0); + cards_setmessage(0, 19, "Can trade 1 coin for resources with player to the RIGHT."); cards_setname(0, 19, "West Trading Post", COMMERCIAL); cards_setcoupons(0, 20, 1, 12, 0, 0); + cards_setmessage(0, 20, "Can trade 1 coin for industry products with adjacent players."); cards_setname(0, 20, "Marketplace", COMMERCIAL); cards_setcost(0, 21, WOOD, 1); @@ -308,8 +325,10 @@ void cards_init() cards_setcoupons(1, 12, 2, 6, 0, 0); cards_setname(1, 12, "Caravansery", COMMERCIAL); + cards_setmessage(1, 13, "1 coin for each resource card of adjacent players or your own."); cards_setname(1, 13, "Vineyard", COMMERCIAL); + cards_setmessage(1, 14, "2 coins for each industry card of adjacent players or your own."); cards_setname(1, 14, "Bazar", COMMERCIAL); cards_setcost(1, 15, STONE, 3); @@ -397,18 +416,22 @@ void cards_init() cards_setcost(2, 5, ORE, 1); cards_setcost(2, 5, WOOD, 1); cards_setcost(2, 5, CLOTH, 1); + cards_setmessage(2, 7, "1 coin and 1 vp for each resource card."); cards_setname(2, 5, "Haven", COMMERCIAL); cards_setcost(2, 6, STONE, 1); cards_setcost(2, 6, GLASS, 1); + cards_setmessage(2, 7, "1 coin and 1 vp for each commercial card."); cards_setname(2, 6, "Lighthouse", COMMERCIAL); cards_setcost(2, 7, CLAY, 2); cards_setcost(2, 7, PAPER, 1); + cards_setmessage(2, 7, "2 coins and 2 vps for each industrial card."); cards_setname(2, 7, "Chamber Of Commerce", COMMERCIAL); cards_setcost(2, 8, STONE, 2); cards_setcost(2, 8, ORE, 1); + cards_setmessage(2, 8, "3 coins and 1 vp for each completed wonder stage."); cards_setname(2, 8, "Arena", COMMERCIAL); cards_setcost(2, 9, ORE, 3); @@ -465,49 +488,59 @@ void cards_init() cards_setcost(2, 18, CLAY, 1); cards_setcost(2, 18, STONE, 1); cards_setcost(2, 18, WOOD, 1); + cards_setmessage(2, 18, "1 vp for each resource card owned by adjacent players."); cards_setname(2, 18, "Workers Guild", GUILD); cards_setcost(2, 19, ORE, 2); cards_setcost(2, 19, STONE, 2); + cards_setmessage(2, 19, "2 vps for each industrial card owned by adjacent players."); cards_setname(2, 19, "Craftmens Guild", GUILD); cards_setcost(2, 20, CLOTH, 1); cards_setcost(2, 20, PAPER, 1); cards_setcost(2, 20, GLASS, 1); + cards_setmessage(2, 20, "1 vp for each commercial card owned by adjacent players."); cards_setname(2, 20, "Traders Guild", GUILD); cards_setcost(2, 21, CLAY, 3); cards_setcost(2, 21, CLOTH, 1); cards_setcost(2, 21, PAPER, 1); + cards_setmessage(2, 21, "1 vp for each scientific card owned by adjacent players."); cards_setname(2, 21, "Philosophers Guild", GUILD); cards_setcost(2, 22, CLAY, 3); cards_setcost(2, 22, GLASS, 1); + cards_setmessage(2, 22, "1 vp for each military card owned by adjacent players."); cards_setname(2, 22, "Spy Guild", GUILD); cards_setcost(2, 23, ORE, 2); cards_setcost(2, 23, STONE, 1); cards_setcost(2, 23, CLOTH, 1); + cards_setmessage(2, 23, "1 vp for each military defeat by adjacent players."); cards_setname(2, 23, "Strategy Guild", GUILD); cards_setcost(2, 24, WOOD, 3); cards_setcost(2, 24, PAPER, 1); cards_setcost(2, 24, GLASS, 1); + cards_setmessage(2, 24, "1 vp for each resource, industrial, and guild card."); cards_setname(2, 24, "Shipowners Guild", GUILD); cards_setcost(2, 25, WOOD, 2); cards_setcost(2, 25, ORE, 2); cards_setcost(2, 25, CLOTH, 1); + cards_setmessage(2, 25, "Counts as either a compass, gear or tablet."); cards_setname(2, 25, "Scientists Guild", GUILD); cards_setcost(2, 26, WOOD, 3); cards_setcost(2, 26, STONE, 1); cards_setcost(2, 26, CLOTH, 1); + cards_setmessage(2, 26, "1 vp for each structure card."); cards_setname(2, 26, "Magistrates Guild", GUILD); cards_setcost(2, 27, STONE, 2); cards_setcost(2, 27, CLAY, 2); cards_setcost(2, 27, GLASS, 1); + cards_setmessage(2, 27, "1 vp for each completed wonder stage by you or adjacent players."); cards_setname(2, 27, "Builders Guild", GUILD); cards_updatecoupons(); @@ -10,6 +10,7 @@ char* getname(int res); int gettypecolor(int type); int* cards_getcoupons(int era, int card); int* cards_getcouponed(int era, int card); +char* cards_specialmessage(int era, int card); void io_init() { @@ -61,6 +62,11 @@ int c; } } +void io_clearscreen() +{ + clear(); +} + void io_printname(int x, int y, int era, int card) { mvprintw(y, x, "# "); @@ -70,30 +76,73 @@ void io_printname(int x, int y, int era, int card) printw(" #"); } +io_printblankline(int x, int y, int width) +{ + int i; + mvprintw(y, x, "#"); + for(i = 0; i < width-1; i++) printw(" "); + printw("#"); +} + +io_printtext(int xorigin, int y, int width, char* text) +{ + width -= 2; //padding + int x = xorigin+2; + int wordlength; + int wordstart = 0; + int i; + //start with a cleared line + io_printblankline(xorigin, y, width); + while(text[wordstart] != '\0') { + wordlength = 0; + while(text[wordstart+(wordlength++)] != ' ' && text[wordstart+wordlength] != '\0'); + if(x-xorigin+wordlength > width) { + io_printblankline(xorigin, ++y, width); + x = xorigin+2; + } + mvprintw(y, x, ""); + for(i = wordstart; i < wordstart+wordlength; i++) addch(text[i]); + x += wordlength; + wordstart += wordlength; + } + return y+1; +} + void io_printcard(int x, int y, int era, int card) { mvprintw(y++, x, "############################"); io_printname(x, y++, era, card); - mvprintw(y++, x, "# Costs: | Produces: #"); int *costs = cards_getcost(era, card); int *products = cards_getproduction(era, card); + int hasCP = 0; int i, j, k; - i = j = -1; - while(i < NUMRESOURCES || j < NUMPRODUCTS) { - while(i < NUMRESOURCES && costs[++i] == 0); - while(j < NUMPRODUCTS && products[++j] == 0); - if(i == NUMRESOURCES && j == NUMPRODUCTS) break; - mvprintw(y++, x, "# "); - if(i < NUMRESOURCES) printw(" %d %-6s| ", costs[i], getname(i)); - else printw(" | "); - int isFinal = 1; - for(k = j+1; k < NUMPRODUCTS; k++) - if(products[k]) isFinal = 0; - if(j < NUMPRODUCTS) - if(isFinal) printw(" %d %-10s #", products[j], getname(j)); - else printw(" %d %-7s or #", products[j], getname(j)); - else printw(" #"); + for(i = 0; i < NUMRESOURCES; i++) + if(costs[i] > 0) hasCP = 1; + for(i = 0; i < NUMPRODUCTS; i++) + if(products[i] > 0) hasCP = 1; + if(hasCP) { + mvprintw(y++, x, "# Costs: | Produces: #"); + i = j = -1; + while(i < NUMRESOURCES || j < NUMPRODUCTS) { + while(i < NUMRESOURCES && costs[++i] == 0); + while(j < NUMPRODUCTS && products[++j] == 0); + if(i == NUMRESOURCES && j == NUMPRODUCTS) break; + mvprintw(y++, x, "# "); + if(i < NUMRESOURCES) printw(" %d %-6s| ", costs[i], getname(i)); + else printw(" | "); + int isFinal = 1; + for(k = j+1; k < NUMPRODUCTS; k++) + if(products[k]) isFinal = 0; + if(j < NUMPRODUCTS) + if(isFinal) printw(" %d %-10s #", products[j], getname(j)); + else printw(" %d %-7s or #", products[j], getname(j)); + else printw(" #"); + } } + + char* message = cards_specialmessage(era, card); + if(message[0] != '\0') + y = io_printtext(x, y, 29, message); int* coupons = cards_getcoupons(era, card); if(coupons[1] || coupons[3]) @@ -4,6 +4,8 @@ void io_init(); void cards_init(); void io_printcard(int x, int y, int era, int card); +void cardtour(); +void io_clearscreen(); void halt() { @@ -15,11 +17,35 @@ main() { io_init(); cards_init(); + cardtour(); io_printcard(0, 0, 0, 0); io_printcard(0, 6, 2, 14); io_printcard(0, 20, 2, 3); io_printcard(31, 0, 1, 12); - io_printcard(31, 20, 1, 20); + io_printcard(31, 20, 2, 25); io_getkey(); halt(); } + +void cardtour() +{ + int era, card; + era = card = 0; + while(1) { + io_clearscreen(); + io_printcard(0, 0, era, card); + switch(io_getkey()) { + case DOWN: if(card < CARDSPERERA-1) card++; + break; + case UP: if(card > 0) card--; + break; + case LEFT: if(era > 0) era--; + break; + case RIGHT: if(era < 2) era++; + break; + case 'q': halt(); + break; + default: break; + } + } +} |