Work in progress update because Lain is crashing...

This commit is contained in:
Ognjen Milan Robovic 2024-06-16 14:17:08 -04:00
parent 254a6c46c9
commit 8ae399eee9

View File

@ -2,7 +2,11 @@
enum { wheat, gold, wood, stone, resources };
enum { granary, mine, storehouse, quarry, constructions };
enum { reply_invalid, reply_build, reply_report, reply_status, replies };
enum {
reply_quit, reply_help, reply_report, reply_status, reply_build, reply_train, reply_trade, reply_plant,
replies
};
static int population = 0;
static int reputation = 0;
@ -14,7 +18,21 @@ static int construction [constructions] = { 0 };
static char * resource_name [] = { "wheat", "gold", "wood", "stone" };
static char * construction_name [] = { "granary", "mine", "storehouse", "quarry" };
static char * reply_name [] = { "--", "build", "report", "status" };
static char * reply_name [] = {
"quit", "help", "report", "status", "build", "train", "trade", "plant"
};
static char * reply_text [] = {
"Quit game.",
"Print reply strings and their explanation, like this one.",
"Request a report from your court advisors about the state of your fortress.",
"Request a meeting with lords and merchants about affairs in your fiefdom.",
"Propose what kind of construction should be built this month to your architect.",
"Spend more time training with your warriors this entire month.",
"Discuss what goods should be sold or bought this month with merchant guild.",
"Order what kind of plants should your peasants harvest this month."
};
static int construction_price [constructions] [resources] = {
{ 0, 10, 60, 30 },
@ -27,26 +45,13 @@ static void separate (void) {
print ("/0------------------------------------------------------------------------------------------/-\n");
}
static void build_construction (int index) {
int price;
static void print_help (void) {
int index;
for (price = 0; price < resources; ++price) {
if (resource [price] < construction_price [index] [price]) {
print ("You don't have enough /1%s/-, need /1%i/- more.\n", resource_name [price], construction_price [index] [price] - resource [price]);
print ("Your architect humbly refused to build /1%s/-.\n", construction_name [index]);
separate ();
return;
}
for (index = 0; index < replies; ++index) {
print ("/3%s/- /0<>/- %s\n", reply_name [index], reply_text [index]);
}
for (price = 0; price < resources; ++price) {
resource [price] -= construction_price [index] [price];
}
construction [index] += 1;
print ("Construction of /2%s/- was completed successfully.\n", construction_name [index]);
separate ();
}
@ -91,11 +96,36 @@ static void print_statistics (void) {
separate ();
}
static void build_construction (int index) {
int price;
for (price = 0; price < resources; ++price) {
if (resource [price] < construction_price [index] [price]) {
print ("You don't have enough /1%s/-, need /1%i/- more.\n", resource_name [price], construction_price [index] [price] - resource [price]);
print ("Your architect humbly refused to build /1%s/-.\n", construction_name [index]);
separate ();
return;
}
}
for (price = 0; price < resources; ++price) {
resource [price] -= construction_price [index] [price];
}
construction [index] += 1;
print ("Construction of /2%s/- was completed successfully.\n", construction_name [index]);
separate ();
}
static int query (void) {
char input [1024] = "";
int index;
requery:
for (index = 0; index < 1024; ++index) {
in (& input [index], 1);
@ -108,14 +138,13 @@ static int query (void) {
for (index = 0; index < replies; ++index) {
if (string_compare (input, reply_name [index]) == true) {
print ("-- /2%s/-\n", reply_name [index]);
return (index);
}
}
print ("/1Unknown kind of reply, type 'help' to see valid replies./-\n");
print_help ();
return (reply_invalid);
goto requery;
}
int main (void) {
@ -135,12 +164,14 @@ int main (void) {
construction [index] = random (1, 2);
}
for (reply = replies; reply != reply_invalid; reply = query ()) {
for (reply = replies; reply != reply_quit; reply = query ()) {
separate ();
print_resources ();
print_constructions ();
print_help ();
build_construction (granary);
build_construction (mine);
build_construction (storehouse);
@ -149,7 +180,9 @@ int main (void) {
print_statistics ();
}
print ("The end!\n");
separate ();
print ("/0The end!/-\n");
separate ();