#include #include "SectorT.h" #include "WarehouseT.h" #include "LandT.h" #include using namespace std; SectorT::SectorT(char c){ hidden = true; type = SymbolToLandT(c); population = 0; buildings = 0; } LandT SectorT::Type(void) const{ return type; } char SectorT::Symbol(void) const{ return LandTToSymbol(type); } bool SectorT::IsHidden(void) const{ return hidden; } void SectorT::Discover(void){ hidden = false; } void SectorT::Population(int i) { if (i + population < 0) { throw out_of_range("Population can not be negative"); } population += i; } int SectorT::Population(void) const { return population; } void SectorT::PopulationPhase( WarehouseT & warehouse) { int foodNeeded; float foodPct; int dpop; foodNeeded = static_cast(ceil(population * 0.5)); cout << "The sector consumes " << foodNeeded << " food"; if (warehouse.Food() >= foodNeeded) { cout << " out of " << warehouse.Food(); warehouse.Food(-foodNeeded); cout << ", so food is now at " << warehouse.Food() << "." << endl; } else { cout << " but the warehouse only has " << warehouse.Food(); foodPct = static_cast(warehouse.Food()) /static_cast(foodNeeded); warehouse.Food(-warehouse.Food()); dpop = static_cast(static_cast(population)*foodPct); population += dpop; cout << ", so " << dpop << " people die from starvation."; } dpop = static_cast(static_cast(population) * 0.1); population += dpop; cout << "The sector produces " << dpop << " new population,"; cout << " so the sector has a population of " << population << "." << endl; if (population > 1000) { cout << "But there is a max of 1000 population."; population = 1000; } } void SectorT::GoodsPhase( WarehouseT & warehouse) { if (buildings > 0 and warehouse.Wood() >= 10) { warehouse.Wood(-10); warehouse.Construction(1); cout << "The sector produces 1 construction." << endl; } if (buildings > 1 and warehouse.Gold() >= 7) { warehouse.Gold(-7); warehouse.Coins(1); cout << "The sector produces 1 coin." << endl; } if (buildings > 2 and warehouse.Coins() >= 50 and warehouse.Construction() >= 50) { warehouse.Coins(-50); warehouse.Construction(-50); warehouse.Victory(1); cout << "The sector produces 1 victory." << endl; } } void SectorT::ResourcesPhase( WarehouseT & warehouse) { int dfood, dgold, dwood; dgold = static_cast(static_cast(population) * 0.1); dfood = static_cast(static_cast(population) * 0.75); dwood = static_cast(static_cast(population) * 0.5); warehouse.Gold(dgold); warehouse.Food(dfood); warehouse.Wood(dwood); cout << "The sector produces " << dfood << " food, so food is now at " << warehouse.Food() << "." << endl; cout << "The sector produces " << dwood << " wood, so wood is now at " << warehouse.Wood() << "." << endl; cout << "The sector produces " << dgold << " gold, so gold is now at " << warehouse.Gold() << "." << endl; } void SectorT::Build(WarehouseT & warehouse) { switch (buildings) { case 0: if (warehouse.Gold() >= 30 and warehouse.Wood() >= 30) { warehouse.Gold(-30); warehouse.Wood(-30); buildings ++; cout << "Building the first building." << endl; } break; case 1: if (warehouse.Gold() >= 20 and warehouse.Construction() >= 50) { warehouse.Gold(-20); warehouse.Construction(-50); buildings ++; cout << "Building the second building." << endl; } break; case 2: if (warehouse.Gold() >= 100 and warehouse.Construction() >= 100) { warehouse.Gold(-100); warehouse.Construction(-100); buildings ++; cout << "Building the third building." << endl; } break; } } int SectorT::Buildings(void) const { return buildings; }