2024-06-16 05:41:47 -04:00
|
|
|
#include <xolatile/xtandard.c>
|
|
|
|
|
2024-06-16 08:13:27 -04:00
|
|
|
enum { wheat, gold, wood, stone, resources };
|
|
|
|
enum { granary, mine, storehouse, quarry, constructions };
|
2024-06-16 13:31:34 -04:00
|
|
|
enum { reply_invalid, reply_build, reply_report, reply_status, replies };
|
2024-06-16 08:13:27 -04:00
|
|
|
|
2024-06-16 12:29:39 -04:00
|
|
|
static int population = 0;
|
|
|
|
static int reputation = 0;
|
|
|
|
static int monthly_immigration = 0;
|
|
|
|
static int monthly_emigration = 0;
|
|
|
|
|
|
|
|
static int resource [resources] = { 0 };
|
|
|
|
static int construction [constructions] = { 0 };
|
2024-06-16 08:13:27 -04:00
|
|
|
|
|
|
|
static char * resource_name [] = { "wheat", "gold", "wood", "stone" };
|
|
|
|
static char * construction_name [] = { "granary", "mine", "storehouse", "quarry" };
|
2024-06-16 13:31:34 -04:00
|
|
|
static char * reply_name [] = { "--", "build", "report", "status" };
|
2024-06-16 08:13:27 -04:00
|
|
|
|
2024-06-16 09:18:51 -04:00
|
|
|
static int construction_price [constructions] [resources] = {
|
2024-06-16 08:13:27 -04:00
|
|
|
{ 0, 10, 60, 30 },
|
|
|
|
{ 0, 120, 60, 10 },
|
|
|
|
{ 0, 30, 10, 60 },
|
|
|
|
{ 0, 60, 30, 10 }
|
|
|
|
};
|
|
|
|
|
2024-06-16 12:29:39 -04:00
|
|
|
static void separate (void) {
|
|
|
|
print ("/0------------------------------------------------------------------------------------------/-\n");
|
|
|
|
}
|
|
|
|
|
2024-06-16 08:13:27 -04:00
|
|
|
static void build_construction (int index) {
|
2024-06-16 09:18:51 -04:00
|
|
|
int price;
|
2024-06-16 08:13:27 -04:00
|
|
|
|
2024-06-16 09:18:51 -04:00
|
|
|
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]);
|
2024-06-16 12:29:39 -04:00
|
|
|
separate ();
|
2024-06-16 08:13:27 -04:00
|
|
|
return;
|
|
|
|
}
|
2024-06-16 05:41:47 -04:00
|
|
|
}
|
|
|
|
|
2024-06-16 09:18:51 -04:00
|
|
|
for (price = 0; price < resources; ++price) {
|
|
|
|
resource [price] -= construction_price [index] [price];
|
2024-06-16 05:41:47 -04:00
|
|
|
}
|
|
|
|
|
2024-06-16 08:13:27 -04:00
|
|
|
construction [index] += 1;
|
2024-06-16 05:41:47 -04:00
|
|
|
|
2024-06-16 09:18:51 -04:00
|
|
|
print ("Construction of /2%s/- was completed successfully.\n", construction_name [index]);
|
2024-06-16 12:29:39 -04:00
|
|
|
|
|
|
|
separate ();
|
2024-06-16 05:41:47 -04:00
|
|
|
}
|
|
|
|
|
2024-06-16 06:02:32 -04:00
|
|
|
static void print_resources (void) {
|
2024-06-16 09:18:51 -04:00
|
|
|
int index;
|
|
|
|
|
|
|
|
for (index = 0; index < resources; ++index) {
|
|
|
|
if (resource [index] == 0) {
|
|
|
|
print ("You don't have any /1%s/-.\n", resource_name [index]);
|
|
|
|
} else if (resource [index] == 1) {
|
|
|
|
print ("You have /31/- unit of /3%s/-.\n", resource_name [index]);
|
|
|
|
} else {
|
|
|
|
print ("You have /3%i/- units of type /3%s/-.\n", resource [index], resource_name [index]);
|
|
|
|
}
|
|
|
|
}
|
2024-06-16 12:29:39 -04:00
|
|
|
|
|
|
|
separate ();
|
2024-06-16 09:18:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_constructions (void) {
|
|
|
|
int index;
|
|
|
|
|
|
|
|
for (index = 0; index < constructions; ++index) {
|
|
|
|
if (construction [index] == 0) {
|
|
|
|
print ("You don't have any construction of type /1%s/-.\n", construction_name [index]);
|
|
|
|
} else if (construction [index] == 1) {
|
|
|
|
print ("You have /31/- construction of type /3%s/-.\n", construction_name [index]);
|
|
|
|
} else {
|
|
|
|
print ("You have /3%i/- constructions of type /3%s/-.\n", construction [index], construction_name [index]);
|
|
|
|
}
|
|
|
|
}
|
2024-06-16 12:29:39 -04:00
|
|
|
|
|
|
|
separate ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_statistics (void) {
|
|
|
|
print ("Reputation = %i\n", reputation);
|
|
|
|
print ("Monthly immigration = %i\n", monthly_immigration);
|
|
|
|
print ("Monthly emigration = %i\n", monthly_emigration);
|
|
|
|
print ("Population = %i\n", population);
|
|
|
|
|
|
|
|
separate ();
|
2024-06-16 06:02:32 -04:00
|
|
|
}
|
|
|
|
|
2024-06-16 13:31:34 -04:00
|
|
|
static int query (void) {
|
|
|
|
char input [1024] = "";
|
|
|
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
for (index = 0; index < 1024; ++index) {
|
|
|
|
in (& input [index], 1);
|
|
|
|
|
|
|
|
if (input [index] == '\n') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
input [index] = '\0';
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
return (reply_invalid);
|
|
|
|
}
|
|
|
|
|
2024-06-16 05:41:47 -04:00
|
|
|
int main (void) {
|
2024-06-16 12:29:39 -04:00
|
|
|
int index;
|
2024-06-16 13:31:34 -04:00
|
|
|
int reply;
|
2024-06-16 12:29:39 -04:00
|
|
|
|
|
|
|
reputation = random (0, 10);
|
|
|
|
monthly_immigration = random (0, 10);
|
|
|
|
monthly_emigration = random (0, 10);
|
|
|
|
population = random (6, 12) * 20 + monthly_immigration - monthly_emigration;
|
|
|
|
|
|
|
|
for (index = 0; index < resources; ++index) {
|
|
|
|
resource [index] = random (6, 12) * 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < constructions; ++index) {
|
|
|
|
construction [index] = random (1, 2);
|
|
|
|
}
|
|
|
|
|
2024-06-16 13:31:34 -04:00
|
|
|
for (reply = replies; reply != reply_invalid; reply = query ()) {
|
|
|
|
separate ();
|
2024-06-16 12:29:39 -04:00
|
|
|
|
2024-06-16 13:31:34 -04:00
|
|
|
print_resources ();
|
|
|
|
print_constructions ();
|
2024-06-16 06:02:32 -04:00
|
|
|
|
2024-06-16 13:31:34 -04:00
|
|
|
build_construction (granary);
|
|
|
|
build_construction (mine);
|
|
|
|
build_construction (storehouse);
|
|
|
|
build_construction (quarry);
|
2024-06-16 06:02:32 -04:00
|
|
|
|
2024-06-16 13:31:34 -04:00
|
|
|
print_statistics ();
|
|
|
|
}
|
2024-06-16 12:29:39 -04:00
|
|
|
|
|
|
|
print ("The end!\n");
|
|
|
|
|
|
|
|
separate ();
|
2024-06-16 05:41:47 -04:00
|
|
|
|
|
|
|
return (log_success);
|
|
|
|
}
|