aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-02-22 22:06:42 -0500
committerNathan Vance <nathav63@gmail.com>2015-02-22 22:06:42 -0500
commitd1d3262b5727f9ffda33aa7bcd3eaf5bcf2d7d40 (patch)
treeb7b93c7c5ba59afdd0861f54610073326f5594e1
parentMajor view improvements (diff)
download7w-d1d3262b5727f9ffda33aa7bcd3eaf5bcf2d7d40.tar.gz
7w-d1d3262b5727f9ffda33aa7bcd3eaf5bcf2d7d40.tar.bz2
7w-d1d3262b5727f9ffda33aa7bcd3eaf5bcf2d7d40.zip
Added basic purchasing with definites
-rw-r--r--data.c87
-rw-r--r--main.c2
-rw-r--r--player_turn.c48
-rw-r--r--view.c8
-rw-r--r--wonder.c43
5 files changed, 154 insertions, 34 deletions
diff --git a/data.c b/data.c
index e07f7af..a1669f6 100644
--- a/data.c
+++ b/data.c
@@ -4,6 +4,8 @@
int* getdeck(int era, int numplayers);
int* cards_getproduction(int era, int card);
int cards_gettype(int era, int card);
+int* cards_getcost(int era, int card);
+int* cards_getproduction(int era, int card);
int* get_intarray(int size);
void shuffle(int *deck, int n);
@@ -12,10 +14,12 @@ void shuffle(int *deck, int n);
static int decks[3][49];
static int player[7][4][7]; //3 eras and extra stuff (wonder, wonder side, wonder stages completed, gold, military wins, defeats)
+static int buffer[7][2];
static int hands[7][7];
static int numplayers;
static int era;
static int turn;
+static int totturns;
void data_sorthands()
{
@@ -36,6 +40,7 @@ void data_nextera()
if(era == 2) return;
era++;
turn = 0;
+ totturns = 0;
int i, j, k;
k = 0;
for(i = 0; i < numplayers; i++)
@@ -69,19 +74,36 @@ void data_init(int n)
era = -1;
data_nextera();
data_distributewonders(n);
- for(i = 0; i < n; i++)
+ for(i = 0; i < n; i++) {
for(j = 0; j < 3; j++)
for(k = 0; k < 7; k++)
player[i][j][k] = -1;
+ player[i][3][3] = 2; //start with 2 gold
+ buffer[i][0] = -1;
+ }
}
-void data_passturn()
+void data_endturn()
{ //remember, player numbers are arranged clockwise
if(era == 0 || era == 2) //pass to the left
turn++;
else //pass to the right
turn--;
if(turn < 0) turn = numplayers-1;
+ int i, j;
+ for(i = 0; i < numplayers; i++) {
+ if(buffer[i][0] == -2) {
+ player[i][3][2]++;
+ } else {
+ for(j = 0; player[i][era][j] != -1; j++); //get free spot in array
+ player[i][era][j] = buffer[i][0]; //build card
+ }
+ player[i][3][3] += buffer[i][1]; //change in gold
+ buffer[i][0] = -1;
+ buffer[i][1] = 0;
+ }
+ totturns++;
+ if(totturns == 6) data_nextera();
}
int* data_gethand(int p)
@@ -109,6 +131,11 @@ int data_getwonderstages(int p)
return player[p][3][2];
}
+int data_getgold(int p)
+{
+ return player[p][3][3];
+}
+
int data_numplayers()
{
return numplayers;
@@ -117,11 +144,25 @@ int data_numplayers()
void data_build(int p, int card)
{
int i;
- for(i = 0; hands[p][i] != card; i++);
- for(; i < 7; i++) hands[p][i] = hands[p][i+1];
- hands[p][7] = -1;
- for(i = 0; player[p][era][i] != -1; i++);
- player[p][era][i] = card;
+ int *hand = data_gethand(p);
+ for(i = 0; hand[i] != card; i++);
+ for(; i < 6; i++) hand[i] = hand[i+1];
+ hand[6] = -1;
+ buffer[p][0] = card; //will be added to player array at end of turn
+ buffer[p][1] -= cards_getcost(era, card)[GOLD];
+ buffer[p][1] += cards_getproduction(era, card)[GOLD];
+}
+
+void data_buildwonder(int p, int card)
+{
+ int i;
+ int *hand = data_gethand(p);
+ for(i = 0; hand[i] != card; i++);
+ for(; i < 6; i++) hand[i] = hand[i+1];
+ hand[6] = -1;
+ buffer[p][0] = -2;
+ buffer[p][1] -= cards_getcost(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[GOLD];
+ buffer[p][1] += cards_getproduction(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[GOLD];
}
//0 is non producing, 1 produces one kind of resource, 2 produces multiple resources
@@ -139,22 +180,32 @@ int data_productiontype(int e, int card)
return type;
}
-void data_removedefinites(int p, int *cost)
+int* data_getdefinites(int p)
{
+ int *ret = get_intarray(GOLD);
int i, j, k, *prod;
for(i = 0; i < 3; i++) {
for(j = 0; j < 7; j++) {
- if(data_productiontype(i, player[p][p][j]) == 1) {
+ if(data_productiontype(i, player[p][i][j]) == 1) {
prod = cards_getproduction(i, player[p][i][j]);
for(k = 0; k < GOLD; k++) {
- if(prod[k] && cost[k]) {
- cost[k] -= prod[k];
- if(cost[k] < 0) cost[k] = 0;
- }
+ ret[k] += prod[k];
}
}
}
}
+ return ret;
+}
+
+void data_removedefinites(int p, int *cost)
+{
+ cost[cards_gettype(data_getwonder(p), 0)]--;
+ int *prod = data_getdefinites(p);
+ int i;
+ for(i = 0; i < GOLD; i++) {
+ cost[i] -= prod[i];
+ if(cost[i] < 0) cost[i] = 0;
+ }
}
#define INDEF 16
@@ -232,3 +283,13 @@ int* data_getbuilt(int p)
ret[i] = -1; //Cap it here
return ret;
}
+
+int data_numbuilt(int p)
+{
+ int num = 0;
+ int i, j;
+ for(i = 0; i < 3; i++)
+ for(j = 0; j < 7; j++)
+ if(player[p][i][j] != -1) num++;
+ return num;
+}
diff --git a/main.c b/main.c
index 7100656..f59a1cd 100644
--- a/main.c
+++ b/main.c
@@ -23,7 +23,7 @@ main()
{
io_init();
cards_init();
- data_init(7);
+ data_init(3);
// tester();
// wonder_selected(0);
player_turn(0);
diff --git a/player_turn.c b/player_turn.c
index 203f430..cc52825 100644
--- a/player_turn.c
+++ b/player_turn.c
@@ -5,43 +5,73 @@ int data_getera();
void io_printhand(int x, int y, int player, int cursor);
void io_printcard(int x, int y, int era, int card);
int io_getkey();
-void data_passturn();
+void data_endturn();
void data_nextera();
int data_numplayers();
+void data_build(int p, int card);
+void data_buildwonder(int p, int card);
void view_refresh(int focus, int cursor, int player);
int wonder_numstages(int player);
+int* cards_getcost(int era, int card);
+int data_numbuilt(int p);
+
+int player_build(int focus, int cursor, int player)
+{
+ if(focus == data_numplayers()) {
+ int *hand = data_gethand(player);
+ if(data_canafford(player, cards_getcost(data_getera(), hand[cursor])) == 2) {
+ data_build(player, hand[cursor]);
+ return 1;
+ }
+ }
+ if(focus == 0) {
+ if(data_canafford(player, cards_getcost(data_getwonder(player), data_getwonderside(player)*3+1+cursor)) == 2) {
+ data_buildwonder(player, 0); //change to choose card used
+ return 1;
+ }
+ }
+ return 0;
+}
void player_turn(int player)
{
- int *hand = data_gethand(player);
- int numcards;
- for(numcards = 0; numcards < 7 && hand[numcards] > -1; numcards++);
+ int numcards, *hand;
int cursor = 0;
int focus = data_numplayers();
while(1) {
+ hand = data_gethand(player);
+ for(numcards = 0; numcards < 7 && hand[numcards] > -1; numcards++);
view_refresh(focus, cursor, player);
switch(io_getkey()) {
case UP: cursor--;
break;
case DOWN: cursor++;
break;
- case RIGHT: data_passturn();
+ case RIGHT: focus++;
break;
- case LEFT: player = (player+1)%data_numplayers();
+ case LEFT: focus--;
break;
- case ENTER: data_nextera();
+ case ENTER:
+ if(player_build(focus, cursor, player))
+ player++;
break;
case '\t': focus = (focus+1)%(data_numplayers()+1);
break;
default: break;
}
+ if(player >= data_numplayers()) {
+ data_endturn();
+ player = 0;
+ }
+ if(focus < 0) focus = data_numplayers();
+ focus = focus%(data_numplayers()+1);
if(focus == data_numplayers()) {
if(cursor < 0) cursor = numcards-1;
if(cursor >= numcards) cursor = 0;
}
else {
- if(cursor < 0) cursor = wonder_numstages((player+focus)%data_numplayers())-1;
- cursor = cursor % wonder_numstages((player+focus)%data_numplayers());
+ if(cursor < 0) cursor = wonder_numstages((player+focus)%data_numplayers())+data_numbuilt(player+focus%data_numplayers())-1;
+ cursor = cursor % (wonder_numstages((player+focus)%data_numplayers())+data_numbuilt(player+focus%data_numplayers()));
}
}
}
diff --git a/view.c b/view.c
index 874d43f..68337b4 100644
--- a/view.c
+++ b/view.c
@@ -10,11 +10,11 @@ void io_printhand(int x, int y, int player, int cursor);
void view_printwonders(int focus, int cursor, int player)
{
-int num = data_numplayers();
- int x, y, i, dir;
+ int num = data_numplayers();
+ int x, y, i, dir, p;
x = y = 0;
for(i = 0; i < num; i++) {
- int p = (player+i)%num;
+ p = (player+i)%num;
dir = 0;
if(i == 1) dir = 1;
if(i == num-1) dir = 2;
@@ -31,7 +31,7 @@ void view_refresh(int focus, int cursor, int player)
view_printwonders(player, -1, player);
io_printhand(61, 0, player, cursor);
} else {
- view_printwonders(focus, cursor, player);
+ view_printwonders((focus+player)%data_numplayers(), cursor, player);
io_printhand(61, 0, player, -1);
}
}
diff --git a/wonder.c b/wonder.c
index 36923ce..c916e95 100644
--- a/wonder.c
+++ b/wonder.c
@@ -13,12 +13,14 @@ int io_printtext(int xorigin, int y, int width, char* text);
int io_printcard(int x, int y, int wonder, int stage);
void io_printname(int x, int y, int era, int card);
int data_getwonderstages(int p);
+int data_getgold(int p);
char* cat(char a[], char b[]);
char* itoa(int i);
int io_getkey();
void io_clearscreen();
int* data_getbuilt(int p);
void io_printplain(int x, int y, char *s);
+int* data_getdefinites(int p);
int wonder_numstages(int player)
{
@@ -32,11 +34,29 @@ int wonder_numstages(int player)
int print_wonder(int x, int y, int player, int cursor)
{
-// if(cursor != -1) cursor = cursor % wonder_numstages(player);
+ int i;
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))));
- int i;
+ y = io_printtext(x, y, 29, cat("Produces: 1 ", getname(cards_gettype(data_getwonder(player), 0))));
+ y = io_printtext(x, y, 29, cat(cat("Treasury: ", itoa(data_getgold(player))), " gold"));
+ io_printborder(x, y++);
+
+ //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])));
+ }
+ }
+ io_printborder(x, y++);
+ }
+
+ //Print wonder stages
for(i = 0; i < wonder_numstages(player); i++) {
char *text = cat("Stage ", itoa(i+1));
if(data_getwonderstages(player) > i)
@@ -44,7 +64,7 @@ int print_wonder(int x, int y, int player, int cursor)
else
text = cat(text, " ");
if(cursor == i)
- text = cat(text, " *");
+ text = cat(text, " *");
else
text = cat(text, " ");
y = io_printtext(x, y, 29, text);
@@ -53,14 +73,23 @@ int print_wonder(int x, int y, int player, int cursor)
//Print what has been built
int *built = data_getbuilt(player);
- for(i = 0; built[i] != -1; i+=2) {
- io_printname(x, y++, built[i], built[i+1]);
+ int j;
+ int print = -1;
+ for(j = 0; built[j] != -1; j+=2) {
+ io_printname(x, y++, built[j], built[j+1]);
+ if(cursor == i++) {
+ io_printplain(x+25, y-1, "*");
+ print = j;
+ }
}
- if(i == 0) y--;
+ if(j == 0) y--;
+ io_printborder(x, y);
//Info about component
if(cursor >= 0 && cursor < wonder_numstages(player))
return io_printcard(x, y, data_getwonder(player), cursor+1+3*data_getwonderside(player));
+ if(cursor >= wonder_numstages(player))
+ return io_printcard(x, y, built[print], built[print+1]);
}
//dir is 0 for none, 1 for east, 2 for west
bgstack15