xerbia/xerbia.c

58 lines
2.0 KiB
C
Raw Normal View History

2024-06-16 05:41:47 -04:00
#include <xolatile/xtandard.c>
enum { wheat, gold, wood, stone, resources };
enum { granary, mine, storehouse, quarry, constructions };
static int resource [resources] = { 600, 300, 300, 300 };
static int construction [constructions] = { 1, 1, 1, 1 };
static char * resource_name [] = { "wheat", "gold", "wood", "stone" };
static char * construction_name [] = { "granary", "mine", "storehouse", "quarry" };
static int construction_cost [constructions] [resources] = {
{ 0, 10, 60, 30 },
{ 0, 120, 60, 10 },
{ 0, 30, 10, 60 },
{ 0, 60, 30, 10 }
};
static void build_construction (int index) {
int cost;
for (cost = 0; cost < resources; ++cost) {
if (resource [cost] < construction_cost [index] [cost]) {
print ("You have only /3%i %s/- and you need /3%i/-, meaning that you miss /1%i/- more.\n", resource [cost], resource_name [cost], construction_cost [index] [cost], construction_cost [index] [cost] - resource [cost]);
print ("Your architects humbly refused to build %s, while complaining about lacking the resources for that.\n", construction_name [index]);
return;
}
2024-06-16 05:41:47 -04:00
}
for (cost = 0; cost < resources; ++cost) {
resource [cost] -= construction_cost [index] [cost];
2024-06-16 05:41:47 -04:00
}
construction [index] += 1;
2024-06-16 05:41:47 -04:00
print ("Construction that you ordered to be built was finished without issues.\n", construction [index]);
2024-06-16 05:41:47 -04:00
}
2024-06-16 06:02:32 -04:00
static void print_resources (void) {
print ("Wheat = %i\n", resource [wheat]);
print ("Gold = %i\n", resource [gold]);
print ("Wood = %i\n", resource [wood]);
print ("Stone = %i\n", resource [stone]);
2024-06-16 06:02:32 -04:00
}
2024-06-16 05:41:47 -04:00
int main (void) {
2024-06-16 06:02:32 -04:00
print_resources ();
build_construction (granary);
build_construction (mine);
build_construction (storehouse);
build_construction (quarry);
2024-06-16 06:02:32 -04:00
print_resources ();
2024-06-16 05:41:47 -04:00
return (log_success);
}