aboutsummaryrefslogtreecommitdiff
path: root/wonder.c
blob: 5fa2cc2ce48c6caa2b8eb78dee84f56865841cce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "7w.h"

int* cards_getcost(int wonder, int stage); //remember the stage offset!
int* cards_getproduction(int wonder, int stage);
char* cards_getname(int wonder, int stage); //stage should always be 0
char* cards_specialmessage(int wonder, int stage);
char* getname(int res);
int cards_gettype(int wonder, int stage); //stage is 0
int data_getwonder(int p);
int data_getwonderside(int p);
void io_printborder(int x, int y);
int io_printtext(int xorigin, int y, int width, char* text);
void io_printcard(int x, int y, int wonder, int stage);
int data_getwonderstages(int p);
char* cat(char a[], char b[]);
char* itoa(int i);
int io_getkey();
void io_clearscreen();

int wonder_hasstage(int wonder, int side, int stage)
{
 if(side == 0 && stage > 2 || stage > 3) return 0;
 int *cost = cards_getcost(wonder, stage+1+side*3);
 int i;
 int has = 0;
 for(i = 0; i < NUMPRODUCTS; i++)
  if(cost[i]) has = 1;
 return has;
}

void print_wonder(int x, int y, int player, int cursor)
{
 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;
 for(i = 0; wonder_hasstage(data_getwonder(player), data_getwonderside(player), i); i++) {
  char *text = cat("Stage ", itoa(i+1));
  if(data_getwonderstages(player) > i)
   text = cat(text, " (complete)");
  else
   text = cat(text, "           ");
  if(cursor == i)
   text = cat(text, " *");
  else
   text = cat(text, "  ");
  y = io_printtext(x, y, 29, text);
 }
 if(wonder_hasstage(data_getwonder(player), data_getwonderside(player), cursor))
  io_printcard(x, y, data_getwonder(player), cursor+1+3*data_getwonderside(player));
}

void wonder_selected(int player)
{
 int cursor = 0;
 while(1) {
  io_clearscreen();
  print_wonder(0, 0, player, cursor);
  switch(io_getkey()) {
   case UP: cursor--;
    break;
   case DOWN: cursor++;
    break;
   case ENTER: data_distributewonders(4);
   default: break;
  }
  if(cursor < 0) cursor = 0;
  if(! wonder_hasstage(data_getwonder(player), data_getwonderside(player), cursor))
   cursor--;
 }
}
bgstack15