58 lines
2.0 KiB
C
58 lines
2.0 KiB
C
#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;
|
|
}
|
|
}
|
|
|
|
for (cost = 0; cost < resources; ++cost) {
|
|
resource [cost] -= construction_cost [index] [cost];
|
|
}
|
|
|
|
construction [index] += 1;
|
|
|
|
print ("Construction that you ordered to be built was finished without issues.\n", construction [index]);
|
|
}
|
|
|
|
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]);
|
|
}
|
|
|
|
int main (void) {
|
|
print_resources ();
|
|
|
|
build_construction (granary);
|
|
build_construction (mine);
|
|
build_construction (storehouse);
|
|
build_construction (quarry);
|
|
|
|
print_resources ();
|
|
|
|
return (log_success);
|
|
}
|