aboutsummaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-02-18 19:51:17 -0500
committerNathan Vance <nathav63@gmail.com>2015-02-18 19:51:17 -0500
commitd43d5b206ae3393a19b21c36d2b8ba443ed0e121 (patch)
treea6607af121caf8a79e528ae20d6786e108136d84 /data.c
parentadded data to keep track of hands and what's been built (diff)
download7w-d43d5b206ae3393a19b21c36d2b8ba443ed0e121.tar.gz
7w-d43d5b206ae3393a19b21c36d2b8ba443ed0e121.tar.bz2
7w-d43d5b206ae3393a19b21c36d2b8ba443ed0e121.zip
Added a view for the hand
Diffstat (limited to 'data.c')
-rw-r--r--data.c60
1 files changed, 51 insertions, 9 deletions
diff --git a/data.c b/data.c
index fcfb5f5..fe81c90 100644
--- a/data.c
+++ b/data.c
@@ -3,6 +3,7 @@
int* getdeck(int era, int numplayers);
int* cards_getproduction(int era, int card);
int* get_intarray(int size);
+void array_cpy(int *a, int *b, int len); //copies b to a
#define MISC 3
#define DATAGOLD 0
@@ -11,6 +12,18 @@ static int decks[3][49];
static int player[7][4][7]; //3 eras and extra stuff (gold, military wins/defeats, etc.)
static int hands[7][7];
static int numplayers;
+static int era;
+
+void data_nextera()
+{
+ if(era == 2) return;
+ era++;
+ int i, j, k;
+ k = 0;
+ for(i = 0; i < numplayers; i++)
+ for(j = 0; j < 7; j++)
+ hands[i][j] = decks[era][k++];
+}
void data_init(int n)
{
@@ -18,24 +31,53 @@ void data_init(int n)
int i, j, *deck;
for(i = 0; i < 3; i++) {
deck = getdeck(i, numplayers);
- for(j = 0; j < numplayers; j++)
+ for(j = 0; j < numplayers*7; j++)
decks[i][j] = deck[j];
}
+ era = -1;
+ data_nextera();
+}
+
+void data_passturn()
+{ //remember, player numbers are arranged clockwise
+ int buffer[7], i;
+ if(era == 0 || era == 2) { //pass to the left
+ array_cpy(buffer, hands[numplayers-1], 7);
+ for(i = numplayers-1; i > 0; i--) {
+ array_cpy(hands[i], hands[i-1], 7);
+ }
+ array_cpy(hands[0], buffer, 7);
+ } else { //pass to the right
+ array_cpy(buffer, hands[0], 7);
+ for(i = 0; i < numplayers-1; i++) {
+ array_cpy(hands[i], hands[i+1], 7);
+ }
+ array_cpy(hands[numplayers-1], buffer, 7);
+ }
}
-void data_startera(int era)
+int* data_gethand(int p)
{
- int i, j, k;
- k = 0;
- for(i = 0; i < numplayers; i++)
- for(j = 0; j < 7; j++)
- hands[i][j] = decks[era][k++];
+ return hands[p];
+}
+
+int data_getera()
+{
+ return era;
+}
+
+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;
}
//0 is non producing, 1 produces one kind of resource, 2 produces multiple resources
-int data_productiontype(int era, int card)
+int data_productiontype(int e, int card)
{
- int *prod = cards_getproduction(era, card);
+ int *prod = cards_getproduction(e, card);
int i;
int type = 0;
for(i = 0; i < GOLD; i++) {
bgstack15