aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-02-24 15:24:39 -0500
committerNathan Vance <nathav63@gmail.com>2015-02-24 15:24:39 -0500
commit952244e7b184bf88122742ad75b884d1eb97eae5 (patch)
tree0ada6a0b2b200b9e4af7f0c745e25c9fd42b3f3c
parentAdded more support for idefinites, but has major bugs! (diff)
download7w-952244e7b184bf88122742ad75b884d1eb97eae5.tar.gz
7w-952244e7b184bf88122742ad75b884d1eb97eae5.tar.bz2
7w-952244e7b184bf88122742ad75b884d1eb97eae5.zip
Added messages, fixed indefinites
-rw-r--r--data.c4
-rw-r--r--io.c27
-rw-r--r--messenger.c31
-rw-r--r--player_turn.c18
-rw-r--r--view.c2
-rw-r--r--wonder.c32
6 files changed, 80 insertions, 34 deletions
diff --git a/data.c b/data.c
index 656c80a..f164b74 100644
--- a/data.c
+++ b/data.c
@@ -184,6 +184,7 @@ int* data_getdefinites(int p)
{
int *ret = get_intarray(GOLD);
int i, j, k, *prod;
+ for(i = 0; i < GOLD; i++) ret[i] = 0;
for(i = 0; i < 3; i++) {
for(j = 0; j < 7; j++) {
if(data_productiontype(i, player[p][i][j]) == 1) {
@@ -257,13 +258,12 @@ static int recurse(int *cost, int **indef, int c)
return 0;
}
-//return 0 if can't afford, 1 if must buy stuff from neighbors, 2 if have all resources.
int data_canafford(int p, int *cost)
{
if(cost[GOLD] > player[p][MISC][DATAGOLD]) return 0;
int i, j, k;
data_removedefinites(p, cost);
- if(data_iszerocost(cost)) return 2;
+ if(data_iszerocost(cost)) return 1;
return recurse(cost, data_getindefinites(p), 0);
}
diff --git a/io.c b/io.c
index 705007d..2658203 100644
--- a/io.c
+++ b/io.c
@@ -88,7 +88,7 @@ void io_printblankline(int x, int y, int width)
int io_printtext(int xorigin, int y, int width, char* text)
{
- width -= 2; //padding
+ width -= 1; //padding
int x = xorigin+2;
int wordlength;
int wordstart = 0;
@@ -97,27 +97,30 @@ int io_printtext(int xorigin, int y, int width, char* text)
io_printblankline(xorigin, y, width);
while(text[wordstart] != '\0') {
wordlength = 0;
- while(text[wordstart+(wordlength++)] != ' ' && text[wordstart+wordlength] != '\0');
- if(x-xorigin+wordlength > width) {
+ while(text[wordstart+(wordlength++)] != ' ' && text[wordstart+wordlength] != '\0' && text[wordstart+wordlength] != '\n');
+ if(x-xorigin+wordlength > width || text[wordstart] == '\n') {
io_printblankline(xorigin, ++y, width);
x = xorigin+2;
}
mvprintw(y, x, "");
- for(i = wordstart; i < wordstart+wordlength; i++) addch(text[i]);
+ for(i = wordstart; i < wordstart+wordlength; i++)
+ if(text[i] != '\n') addch(text[i]);
x += wordlength;
wordstart += wordlength;
}
return y+1;
}
-void io_printborder(int x, int y)
+void io_printborder(int x, int y, int width)
{
- mvprintw(y, x, "############################");
+ int i;
+ for(i = 0; i < width; i++)
+ mvprintw(y, x+i, "#");
}
int io_printcard(int x, int y, int era, int card)
{
- io_printborder(x, y++);
+ io_printborder(x, y++, 28);
if(cards_getname(era, card)[0] != '\0')
io_printname(x, y++, era, card);
int *costs = cards_getcost(era, card);
@@ -150,7 +153,7 @@ int io_printcard(int x, int y, int era, int card)
char* message = cards_specialmessage(era, card);
if(message[0] != '\0')
- y = io_printtext(x, y, 29, message);
+ y = io_printtext(x, y, 28, message);
int* coupons = cards_getcoupons(era, card);
if(coupons[1] || coupons[3])
@@ -172,7 +175,7 @@ int io_printcard(int x, int y, int era, int card)
io_printname(x, y++, coupons[2], coupons[3]);
}
- io_printborder(x, y);
+ io_printborder(x, y, 28);
return y;
}
@@ -181,8 +184,8 @@ void io_printhand(int x, int y, int player, int cursor)
int *hand = data_gethand(player);
int i;
int cursed = 0;
- io_printborder(x, y++);
- y = io_printtext(x, y, 29, " Hand");
+ io_printborder(x, y++, 28);
+ y = io_printtext(x, y, 28, " Hand");
for(i = 0; hand[i] != -1 && i < 7; i++) {
io_printname(x, y++, data_getera(), hand[i]);
if(i == cursor) {
@@ -191,7 +194,7 @@ void io_printhand(int x, int y, int player, int cursor)
}
}
if(cursed) io_printcard(x, y, data_getera(), hand[cursor]);
- else io_printborder(x, y);
+ else io_printborder(x, y, 28);
}
void io_printplain(int x, int y, char *s)
diff --git a/messenger.c b/messenger.c
new file mode 100644
index 0000000..5c3c947
--- /dev/null
+++ b/messenger.c
@@ -0,0 +1,31 @@
+#include "7w.h"
+
+int io_printtext(int xorigin, int y, int width, char* text);
+void io_printborder(int x, int y, int width);
+
+#define MAXMESSAGE 100
+static char message[MAXMESSAGE];
+
+void printmessage(int x, int y, int width)
+{
+ if(message[0] == '\0') return;
+ io_printborder(x, y++, width);
+ y = io_printtext(x, y, width, message);
+ io_printborder(x, y, width);
+}
+
+void postmessage(char* m)
+{
+ int i;
+ for(i = 0; i < MAXMESSAGE && (message[i] = m[i]) != '\0'; i++);
+}
+
+void clearmessage()
+{
+ message[0] = '\0';
+}
+
+void posthelp()
+{
+ postmessage(" 7 Wonders Help:\nKeys:\n Arrow keys move cursor\n Return - buys resource\n h - prints this message");
+}
diff --git a/player_turn.c b/player_turn.c
index cc52825..5d1b122 100644
--- a/player_turn.c
+++ b/player_turn.c
@@ -14,18 +14,22 @@ 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);
+void postmessage(char* message);
+void posthelp();
+void clearmessage();
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) {
+ if(data_canafford(player, cards_getcost(data_getera(), hand[cursor]))) {
data_build(player, hand[cursor]);
return 1;
}
+ else postmessage("Can't afford this!");
}
if(focus == 0) {
- if(data_canafford(player, cards_getcost(data_getwonder(player), data_getwonderside(player)*3+1+cursor)) == 2) {
+ if(data_canafford(player, cards_getcost(data_getwonder(player), data_getwonderside(player)*3+1+cursor))) {
data_buildwonder(player, 0); //change to choose card used
return 1;
}
@@ -52,11 +56,17 @@ void player_turn(int player)
case LEFT: focus--;
break;
case ENTER:
- if(player_build(focus, cursor, player))
- player++;
+ if(player_build(focus, cursor, player)) {
+ player++;
+ cursor = 0;
+ focus = data_numplayers();
+ clearmessage();
+ }
break;
case '\t': focus = (focus+1)%(data_numplayers()+1);
break;
+ case 'h': posthelp();
+ break;
default: break;
}
if(player >= data_numplayers()) {
diff --git a/view.c b/view.c
index 68337b4..3061435 100644
--- a/view.c
+++ b/view.c
@@ -7,6 +7,7 @@ void io_printhand(int x, int y, int player, int cursor);
void io_clearscreen();
int data_numplayers();
void io_printhand(int x, int y, int player, int cursor);
+void printmessage(int x, int y, int width);
void view_printwonders(int focus, int cursor, int player)
{
@@ -22,6 +23,7 @@ void view_printwonders(int focus, int cursor, int player)
print_wonder(34, 0, p, cursor);
y = print_wondersmall(x, y, p, focus == p, dir);
}
+ printmessage(0, y+2, 35);
}
void view_refresh(int focus, int cursor, int player)
diff --git a/wonder.c b/wonder.c
index 51c032e..5c5169e 100644
--- a/wonder.c
+++ b/wonder.c
@@ -8,7 +8,7 @@ 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);
+void io_printborder(int x, int y, int width);
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);
@@ -36,20 +36,20 @@ int wonder_numstages(int player)
int print_wonder(int x, int y, int player, int cursor)
{
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))));
- y = io_printtext(x, y, 29, cat(cat("Treasury: ", itoa(data_getgold(player))), " gold"));
- io_printborder(x, y++);
+ io_printborder(x, y++, 28);
+ y = io_printtext(x, y, 28, cards_getname(data_getwonder(player), 0));
+ y = io_printtext(x, y, 28, cat("Produces: 1 ", getname(cards_gettype(data_getwonder(player), 0))));
+ y = io_printtext(x, y, 28, cat(cat("Treasury: ", itoa(data_getgold(player))), " gold"));
+ io_printborder(x, y++, 28);
//Print resource incomes
int *def = data_getdefinites(player);
def[cards_gettype(data_getwonder(player), 0)]++;
int **indef = data_getindefinites(player);
- y = io_printtext(x, y, 29, "Production:");
+ y = io_printtext(x, y, 28, "Production:");
for(i = 0; i < GOLD; i++) {
if(def[i]) {
- y = io_printtext(x, y, 29, cat(cat(cat(" ", getname(i)), ": "), itoa(def[i])));
+ y = io_printtext(x, y, 28, cat(cat(cat(" ", getname(i)), ": "), itoa(def[i])));
}
}
for(i = 0; i < INDEF; i++) {
@@ -59,11 +59,11 @@ int print_wonder(int x, int y, int player, int cursor)
text = cat(cat(text, "/"), getname(indef[i][j]));
}
if(text[0] != '\0') {
- y = io_printtext(x, y, 29, text);
+ y = io_printtext(x, y, 28, text);
io_printplain(x+2, y-1, " ");
}
}
- io_printborder(x, y++);
+ io_printborder(x, y++, 28);
//Print wonder stages
for(i = 0; i < wonder_numstages(player); i++) {
@@ -76,9 +76,9 @@ int print_wonder(int x, int y, int player, int cursor)
text = cat(text, " *");
else
text = cat(text, " ");
- y = io_printtext(x, y, 29, text);
+ y = io_printtext(x, y, 28, text);
}
- io_printborder(x, y++);
+ io_printborder(x, y++, 28);
//Print what has been built
int *built = data_getbuilt(player);
@@ -91,7 +91,7 @@ int print_wonder(int x, int y, int player, int cursor)
}
}
if(j == 0) y--;
- io_printborder(x, y);
+ io_printborder(x, y, 28);
//Info about component
if(cursor >= 0 && cursor < wonder_numstages(player))
@@ -103,12 +103,12 @@ int print_wonder(int x, int y, int player, int cursor)
//dir is 0 for none, 1 for east, 2 for west
int print_wondersmall(int x, int y, int player, int selected, int dir)
{
- io_printborder(x, y++);
+ io_printborder(x, y++, 28);
if(selected) io_printplain(28, y, "*");
if(dir == 1) io_printplain(29, y, "East");
if(dir == 2) io_printplain(29, y, "West");
- y = io_printtext(x, y, 29, cards_getname(data_getwonder(player), 0));
- io_printborder(x, y);
+ y = io_printtext(x, y, 28, cards_getname(data_getwonder(player), 0));
+ io_printborder(x, y, 28);
return y;
}
bgstack15