From 5db01145c5ae2b6358b486c87826991fa7155808 Mon Sep 17 00:00:00 2001 From: JT Traub Date: Sat, 28 Sep 2024 18:02:24 -0700 Subject: [PATCH] Another rename on MarketType Actually do a named enum correctly in order to enforce typechecking. Also, modified editor settings to get rid of dumb extra spaces, and wrap things better, so these will occur over time as I edit files. --- aregion.cpp | 68 ++-- basic/world.cpp | 18 +- economy.cpp | 209 ++++++----- edit.cpp | 860 ++++++++++++++++++++++--------------------- fracas/world.cpp | 18 +- havilah/world.cpp | 18 +- kingdoms/world.cpp | 18 +- market.cpp | 5 +- market.h | 2 +- neworigins/world.cpp | 21 +- runorders.cpp | 15 +- standard/world.cpp | 20 +- unittest/world.cpp | 20 +- 13 files changed, 685 insertions(+), 607 deletions(-) diff --git a/aregion.cpp b/aregion.cpp index bc73e479..74e94113 100644 --- a/aregion.cpp +++ b/aregion.cpp @@ -387,7 +387,7 @@ int ARegion::RoadDevelopmentBonus(int range, int dev) if (!r) continue; if (HasConnectingRoad(d)) bonus = r->TraceConnectedRoad(d, bonus, con, range-1, dev); } - return bonus; + return bonus; } // AS @@ -1052,7 +1052,7 @@ void ARegion::Writeout(ostream& f) f << products.size() << '\n'; for (const auto& product : products) product->write_out(f); f << markets.size() << '\n'; - for (const auto& market : markets) market->write_out(f); + for (const auto& market : markets) market->write_out(f); f << objects.Num() << '\n'; forlist ((&objects)) ((Object *) elem)->Writeout(f); @@ -1291,7 +1291,7 @@ void ARegion::build_json_report(json& j, Faction *fac, int month, ARegionList *r if (m->amount != -1) item["amount"] = m->amount; else item["unlimited"] = true; - if (m->type == Market::M_SELL) { + if (m->type == Market::MarketType::M_SELL) { if (ItemDefs[m->item].type & IT_ADVANCED) { if (!Globals->MARKETS_SHOW_ADVANCED_ITEMS) { if (!HasItem(fac, m->item)) continue; @@ -1345,7 +1345,7 @@ void ARegion::build_json_report(json& j, Faction *fac, int month, ARegionList *r j["exits"] = json::array(); for (int i=0; ibasic_region_data() } } ); @@ -1783,7 +1783,6 @@ void ARegion::AddFleet(Object * fleet) objects.Add(fleet); //Awrite(AString("Setting up fleet alias #") + fleetalias + ": " + fleet->num); newfleets.insert(make_pair(fleetalias++, fleet->num)); - } int ARegion::ResolveFleetAlias(int alias) @@ -2188,7 +2187,7 @@ void ARegionList::TownStatistics() break; case TOWN_CITY: cities++; - } + } } } int tot = villages + towns + cities; @@ -2455,7 +2454,7 @@ int ARegionList::GetPlanarDistance(ARegion *one, ARegion *two, int penalty, int r->distance = -1; r->next = 0; } - + zdist = (one->zloc - two->zloc); if (zdist < 0) zdist = -zdist; start->distance = zdist * penalty; @@ -2635,11 +2634,11 @@ int ParseTerrain(AString *token) for (int i = 0; i < R_NUM; i++) { if (*token == TerrainDefs[i].type) return i; } - + for (int i = 0; i < R_NUM; i++) { if (*token == TerrainDefs[i].name) return i; } - + return (-1); } @@ -2741,8 +2740,11 @@ bool isNearWaterBody(ARegion* reg, std::vector& list) { return false; } -void makeRivers(Map* map, ARegionArray* arr, std::vector& waterBodies, std::unordered_map& rivers, - const int w, const int h, const int maxRiverReach) { +void makeRivers( + Map* map, ARegionArray* arr, std::vector& waterBodies, + std::unordered_map& rivers, + const int w, const int h, const int maxRiverReach +) { std::cout << "Let's have RIVERS!" << std::endl; // all non-coast water regions @@ -2822,7 +2824,7 @@ void makeRivers(Map* map, ARegionArray* arr, std::vector& waterBodie if (otherWater < 0) { continue; } - + int currentDist = distances[water->name][otherWater]; if (newDist < currentDist ) { distances[water->name][otherWater] = newDist; @@ -3014,7 +3016,10 @@ void makeRivers(Map* map, ARegionArray* arr, std::vector& waterBodie } } -void cleanupIsolatedPlaces(ARegionArray* arr, std::vector& waterBodies, std::unordered_map& rivers, int w, int h) { +void cleanupIsolatedPlaces( + ARegionArray* arr, std::vector& waterBodies, + std::unordered_map& rivers, int w, int h +) { for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { if ((x + y) % 2) { @@ -3067,7 +3072,7 @@ void cleanupIsolatedPlaces(ARegionArray* arr, std::vector& waterBodi int countNeighbors(ARegionGraph& graph, ARegion* reg, int ofType, int distance) { graphs::Location2D loc = { reg->xloc, reg->yloc }; - + int count = 0; auto result = graphs::breadthFirstSearch(graph, loc); @@ -3139,7 +3144,7 @@ std::vector getPoints(const int w, const int h, int minDist = initialMinDist; int cellSize = ceil(minDist / sqrt(2)); - + graphs::Location2D loc; do { loc = { .x = getrandom(w), .y = getrandom(h) }; @@ -3313,7 +3318,10 @@ Ethnicity getRegionEtnos(ARegion* reg) { return etnos; } -void subdivideArea(const int width, const int height, const int distance, const std::vector ®ions, std::vector> &subgraphs) { +void subdivideArea( + const int width, const int height, const int distance, + const std::vector ®ions, std::vector> &subgraphs +) { auto points = getPointsFromList(width, distance, 8, regions); std::unordered_map> centers; @@ -3343,7 +3351,10 @@ void subdivideArea(const int width, const int height, const int distance, const } } -void nameArea(int width, int height, ARegionGraph &graph, std::unordered_set &usedNames, std::vector& nameAnchors, std::vector ®ions, std::unordered_set &named) { +void nameArea( + int width, int height, ARegionGraph &graph, std::unordered_set &usedNames, + std::vector& nameAnchors, std::vector ®ions, std::unordered_set &named +) { std::string name; Ethnicity etnos = Ethnicity::NONE; @@ -3389,7 +3400,7 @@ void nameArea(int width, int height, ARegionGraph &graph, std::unordered_settype, 1, false); } usedNames.emplace(volcanoName); - + std::cout << volcanoName << std::endl; r->SetName(volcanoName.c_str()); } @@ -3401,14 +3412,19 @@ void nameArea(int width, int height, ARegionGraph &graph, std::unordered_set& waterBodies, std::unordered_map& rivers, const int w, const int h) { +void giveNames( + ARegionArray* arr, std::vector& waterBodies, std::unordered_map& rivers, + const int w, const int h +) { std::unordered_set named; std::unordered_set usedNames; // generate name areas std::vector nameAnchors; std::unordered_set usedNameSeeds; - for (auto p : getPoints(w, h, 8, 16, [](graphs::Location2D p) { return 8; }, [](graphs::Location2D p) { return true; })) { + auto onPoint = [](graphs::Location2D p) { return 8; }; + auto onIsIncluded = [](graphs::Location2D p) { return true; }; + for (auto p : getPoints(w, h, 8, 16, onPoint, onIsIncluded)) { int seed; do { seed = getrandom(w * h) + 1; @@ -3727,7 +3743,7 @@ void ARegionList::AddHistoricalBuildings(ARegionArray* arr, const int w, const i } ARegionGraph graph = ARegionGraph(arr); - + graph.setInclusion([](ARegion* current, ARegion* next) { return next->type != R_OCEAN && next->type != R_VOLCANO; }); @@ -3898,7 +3914,7 @@ void ARegionList::CreateNaturalSurfaceLevel(Map* map) { const int h = map->map.height / 2; MakeRegions(level, w, h); - + pRegionArrays[level]->SetName(0); pRegionArrays[level]->levelType = ARegionArray::LEVEL_SURFACE; @@ -3925,13 +3941,13 @@ void ARegionList::CreateNaturalSurfaceLevel(Map* map) { const int maxRiverReach = std::min(w, h) / 4; makeRivers(map, arr, waterBodies, rivers, w, h, maxRiverReach); - + cleanupIsolatedPlaces(arr, waterBodies, rivers, w, h); placeVolcanoes(arr, w, h); GrowRaces(arr); - + giveNames(arr, waterBodies, rivers, w, h); assertAllRegionsHaveName(w, h, arr); @@ -3993,13 +4009,13 @@ void ARegionList::ResourcesStatistics() { forlist(this) { ARegion* reg = (ARegion*) elem; - + for (const auto& p : reg->products) { resources[p->itemtype] += p->amount; } for (const auto& m : reg->markets) { - if (m->type == Market::M_BUY) { + if (m->type == Market::MarketType::M_BUY) { forSale[m->item] += m->amount; } else { diff --git a/basic/world.cpp b/basic/world.cpp index 15c1e852..6aba17c1 100644 --- a/basic/world.cpp +++ b/basic/world.cpp @@ -2503,9 +2503,9 @@ void ARegion::MakeStartingCity() if (!Globals->TOWNS_EXIST) return; if (Globals->GATES_EXIST) gate = -1; - + if (town) delete town; - + AddTown(TOWN_CITY); if (!Globals->START_CITIES_EXIST) return; @@ -2526,18 +2526,18 @@ void ARegion::MakeStartingCity() if ( ItemDefs[ i ].type & IT_NORMAL ) { if (i==I_SILVER || i==I_LIVESTOCK || i==I_FISH || i==I_GRAIN) continue; - m = new Market(Market::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); markets.push_back(m); } } ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); } } else { @@ -2545,12 +2545,16 @@ void ARegion::MakeStartingCity() ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above /* Setup Recruiting */ - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000); + m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000) + ; markets.push_back(m); if ( Globals->LEADERS_EXIST ) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400 + ); markets.push_back(m); } } diff --git a/economy.cpp b/economy.cpp index 271a8940..badb72ce 100644 --- a/economy.cpp +++ b/economy.cpp @@ -72,7 +72,7 @@ int ARegion::Wages() } wages *= 10; if (dv > last) - wages += 10 * (dv - last) / (level - last); + wages += 10 * (dv - last) / (level - last); return wages; } @@ -94,7 +94,7 @@ void ARegion::SetupHabitat(TerrainType* terrain) { int pop = terrain->pop; int mw = terrain->wages; - + // fix economy when MAINTENANCE_COST has been adjusted mw += Globals->MAINTENANCE_COST - 10; if (mw < 0) mw = 0; @@ -136,7 +136,7 @@ void ARegion::SetupHabitat(TerrainType* terrain) { basepopulation = habitat / 3; // hmm... somewhere not too far off equilibrium pop population = habitat * (60 + getrandom(6) + getrandom(6)) / 100; - + // Setup development int level = 1; development = 1; @@ -196,7 +196,7 @@ void ARegion::SetupEconomy() { e->baseamount = maxent / Globals->ENTERTAIN_FRACTION; // raise entertainment income by productivity factor 10 e->productivity = Globals->ENTERTAIN_INCOME * 10; - + // note: wage factor 10, population factor 5 - included as "/ 50" /* More wealth in safe Starting Cities */ if ((Globals->SAFE_START_CITIES) && (IsStartingCity())) { @@ -213,13 +213,17 @@ void ARegion::SetupEconomy() { float ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float assignment above // Setup Recruiting - Market *m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 2000); + Market *m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 2000 + ); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio = ItemDefs[I_LEADERS].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float assignment above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400 + ); markets.push_back(m); } } @@ -276,12 +280,12 @@ void ARegion::SetIncome() if (basepopulation == 0) return; maxwages = Wages(); - + /* taxable region wealth */ wealth = (int) ((float) (Population() * (Wages() - 10 * Globals->MAINTENANCE_COST) / 50)); if (wealth < 0) wealth = 0; - + /* Wages */ // wage-relevant population (/10 wages /5 popfactor) int pp = Population(); @@ -327,7 +331,7 @@ void ARegion::SetIncome() e->skill = S_ENTERTAINMENT; // raise entertainment income by productivity factor 10 e->productivity = Globals->ENTERTAIN_INCOME * 10; - + // note: wage factor 10, population factor 5 - included as "/ 50" /* More wealth in safe Starting Cities */ if ((Globals->SAFE_START_CITIES) && (IsStartingCity())) { @@ -337,7 +341,7 @@ void ARegion::SetIncome() w->baseamount += wbonus / Globals->WORK_FRACTION; e->amount += wbonus / Globals->ENTERTAIN_FRACTION; e->baseamount += wbonus / Globals->ENTERTAIN_FRACTION; - } + } } void ARegion::DisbandInRegion(int item, int amt) @@ -393,7 +397,7 @@ void ARegion::SetupCityMarket() ManType *locals = FindRace(ItemDefs[race].abr); if (!locals) locals = FindRace("SELF"); /* compose array of possible supply & demand items */ - int supply[NITEMS]; + int supply[NITEMS]; int demand[NITEMS]; /* possible advanced and magic items */ int rare[NITEMS]; @@ -425,7 +429,7 @@ void ARegion::SetupCityMarket() break; } } - } + } // Non-raw goods else { canProduceHere = 1; @@ -454,9 +458,9 @@ void ARegion::SetupCityMarket() isUseful = locals->CanUse(i); //Normal Items if (ItemDefs[ i ].type & IT_NORMAL) { - + if (i==I_GRAIN || i==I_LIVESTOCK || i==I_FISH) { - // Add foodstuffs directly to market + // Add foodstuffs directly to market int amt = Globals->CITY_MARKET_NORMAL_AMT; int price; @@ -470,7 +474,9 @@ void ARegion::SetupCityMarket() cap = (citymax * 3/4) - 5000; if (cap < 0) cap = citymax/2; - Market * m = new Market(Market::M_SELL, i, price, amt, population, population + cap, amt, amt * 2); + Market * m = new Market( + Market::MarketType::M_SELL, i, price, amt, population, population + cap, amt, amt * 2 + ); markets.push_back(m); } else if (i == I_FOOD) { // Add foodstuffs directly to market @@ -486,7 +492,9 @@ void ARegion::SetupCityMarket() cap = (citymax * 3/4) - 5000; if (cap < 0) cap = citymax/2; - Market * m = new Market(Market::M_BUY, i, price, amt, population, population + 2 * cap, amt, amt * 5); + Market * m = new Market( + Market::MarketType::M_BUY, i, price, amt, population, population + 2 * cap, amt, amt * 5 + ); markets.push_back(m); } else if (ItemDefs[i].pInput[0].item == -1) { // Basic resource @@ -500,7 +508,7 @@ void ARegion::SetupCityMarket() } else if (isUseful) demand[i] = 4; } } else { - + // Tool, weapon or armor if (isUseful) { // Add to supply? @@ -550,7 +558,8 @@ void ARegion::SetupCityMarket() offset = citymax / 8; if (cap+offset < citymax) { Market * m = new Market( - Market::M_SELL, i, price, amt / 6, population + cap + offset, population + citymax, 0, amt + Market::MarketType::M_SELL, i, price, amt / 6, population + cap + offset, + population + citymax, 0, amt ); markets.push_back(m); } @@ -573,20 +582,21 @@ void ARegion::SetupCityMarket() if (Globals->RANDOM_ECONOMY) { amt += getrandom(amt); - price = (ItemDefs[i].baseprice * (100 + getrandom(50))) / - 100; + price = (ItemDefs[i].baseprice * (100 + getrandom(50))) / 100; } else { price = ItemDefs[ i ].baseprice; } - + cap = (citymax *3/4) - 5000; if (cap < citymax/2) cap = citymax / 2; offset = (citymax/20) + ((citymax/5) * 2); - Market * m = new Market(Market::M_SELL, i, price, amt / 6, population + cap, population + citymax, 0, amt); + Market * m = new Market( + Market::MarketType::M_SELL, i, price, amt / 6, population + cap, population + citymax, 0, amt + ); markets.push_back(m); } } - + /* Add demand (normal) items */ int num = 4; int sum = 1; @@ -601,11 +611,11 @@ void ARegion::SetupCityMarket() if (dm < sum) break; } if (dm >= sum) continue; - + int amt = Globals->CITY_MARKET_NORMAL_AMT; amt = demand[i] * amt / 4; int price; - + if (Globals->RANDOM_ECONOMY) { amt += getrandom(amt); price = (ItemDefs[i].baseprice * @@ -613,17 +623,17 @@ void ARegion::SetupCityMarket() } else { price = ItemDefs[i].baseprice; } - + cap = (citymax/4); offset = - (citymax/20) + ((5-num) * citymax * 3/40); Market * m = new Market( - Market::M_SELL, i, price, amt / 6, population + cap + offset, population + citymax, 0, amt + Market::MarketType::M_SELL, i, price, amt / 6, population + cap + offset, population + citymax, 0, amt ); markets.push_back(m); demand[i] = 0; - num--; + num--; } - + /* Add supply (normal) items */ num = 2; sum = 1; @@ -650,11 +660,13 @@ void ARegion::SetupCityMarket() } else { price = ItemDefs[ i ].baseprice; } - + cap = (citymax/4); offset = ((3-num) * citymax * 3 / 40); if (supply[i] < 4) offset += citymax / 20; - Market * m = new Market(Market::M_BUY, i, price, 0, population + cap + offset, population + citymax, 0, amt); + Market * m = new Market( + Market::MarketType::M_BUY, i, price, 0, population + cap + offset, population + citymax, 0, amt + ); markets.push_back(m); supply[i] = 0; num--; @@ -712,13 +724,14 @@ void ARegion::SetupCityMarket() } else { price = ItemDefs[ i ].baseprice; } - + cap = (citymax/2); tradesell++; offset = - (citymax/20) + tradesell * (tradesell * tradesell * citymax/40); if (cap + offset < citymax) { Market * m = new Market( - Market::M_SELL, i, price, amt / 5, cap + population + offset, citymax + population, 0, amt + Market::MarketType::M_SELL, i, price, amt / 5, cap + population + offset, + citymax + population, 0, amt ); markets.push_back(m); } @@ -743,7 +756,8 @@ void ARegion::SetupCityMarket() offset = tradebuy++ * (citymax/6); if (cap+offset < citymax) { Market * m = new Market( - Market::M_BUY, i, price, amt / 6, cap + population + offset, citymax + population, 0, amt + Market::MarketType::M_BUY, i, price, amt / 6, cap + population + offset, + citymax + population, 0, amt ); markets.push_back(m); } @@ -806,14 +820,14 @@ void ARegion::AddTown() void ARegion::AddTown(AString * tname) { int size = DetermineTownSize(); - AddTown(size, tname); + AddTown(size, tname); } /* Create a town of given Town Type */ void ARegion::AddTown(int size) { AString *tname = new AString(AGetNameString(AGetName(1, this))); - AddTown(size, tname); + AddTown(size, tname); } /* Create a town of specific type with name @@ -859,10 +873,10 @@ void ARegion::SetTownType(int level) town->hab = TownHabitat(); town->pop = town->hab * 2 / 3; town->dev = TownDevelopment(); - + // Sanity check if ((level < TOWN_VILLAGE) || (level > TOWN_CITY)) return; - + // increment values int poptown = getrandom((level -1) * (level -1) * Globals->CITY_POP/12) + level * level * Globals->CITY_POP/12; town->hab += poptown; @@ -890,7 +904,7 @@ void ARegion::SetTownType(int level) int popdecr = getrandom(Globals->CITY_POP/3) + getrandom(Globals->CITY_POP/3); // don't depopulate while ((town->pop < popdecr) || (town->hab < popdecr)) { - popdecr = popdecr / 2; + popdecr = popdecr / 2; } town->hab -= popdecr; town->pop = town->hab * 2 / 3; @@ -906,7 +920,7 @@ void ARegion::UpdateEditRegion() // redo markets and entertainment/tax income for extra people. SetIncome(); for (auto& m : markets) m->post_turn(Population(), Wages()); - + //Replace man selling markets.erase( remove_if(markets.begin(), markets.end(), [](const Market * m) { return ItemDefs[m->item].type & IT_MAN; }), @@ -915,15 +929,19 @@ void ARegion::UpdateEditRegion() float ratio = ItemDefs[race].baseprice / (float) (Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - Market *m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population()/ 25, 0, 10000, 0, 2000); + Market *m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population()/ 25, 0, 10000, 0, 2000 + ); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio = ItemDefs[I_LEADERS].baseprice / (float) (Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400 + ); markets.push_back(m); - } + } } void ARegion::SetupEditRegion() @@ -937,7 +955,7 @@ void ARegion::SetupEditRegion() int pop = typer->pop; int mw = typer->wages; - + // fix economy when MAINTENANCE_COST has been adjusted mw += Globals->MAINTENANCE_COST - 10; if (mw < 0) mw = 0; @@ -979,7 +997,7 @@ void ARegion::SetupEditRegion() basepopulation = habitat / 3; // hmm... somewhere not too far off equilibrium pop population = habitat * (60 + getrandom(6) + getrandom(6)) / 100; - + // Setup development int level = 1; development = 1; @@ -1033,13 +1051,17 @@ void ARegion::SetupEditRegion() float ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float assignment above // Setup Recruiting - Market *m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 2000); + Market *m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 2000 + ); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio = ItemDefs[I_LEADERS].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float assignment above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400 + ); markets.push_back(m); } } @@ -1083,7 +1105,7 @@ int ARegion::BaseDev() prev = 0; } } - + basedev = (Globals->MAINTENANCE_COST + basedev) / 2; return basedev; } @@ -1131,14 +1153,14 @@ int ARegion::TownHabitat() if (temple) build++; if (caravan) build++; if (build > 2) build = 2; - + build++; hab = (build * build + 1) * hab * hab + habitat / 4 + 50; - + // Effect of town development on habitat: int totalhab = hab + (TownDevelopment() * (habitat + 800 + hab + Globals->CITY_POP / 2)) / 100; - + return totalhab; } @@ -1184,9 +1206,9 @@ int ARegion::TownDevelopment() int df = development - basedev; if (df < 0) df = 0; if (df > 100) df = 100; - + return df; -} +} // Checks the growth potential of towns // and cancels unlimited markets for Starting Cities @@ -1202,7 +1224,7 @@ int ARegion::TownGrowth() int tot = 0; for (const auto& m : markets) { if (Population() > m->minpop) { - if (m->type == Market::M_BUY) { + if (m->type == Market::MarketType::M_BUY) { if (ItemDefs[m->item].type & IT_TRADE) { amt += 5 * m->activity; tot += 5 * m->maxamt; @@ -1225,12 +1247,12 @@ int ARegion::TownGrowth() } } } - + if (amt > tot) amt = tot; if (tot) { tarpop += (Globals->CITY_POP * amt) / tot; - } + } // Let's bump tarpop up // tarpop = (tarpop * 5) / 4; if (tarpop > Globals->CITY_POP) tarpop = Globals->CITY_POP; @@ -1261,15 +1283,15 @@ void ARegion::Grow() // We don't need to grow 0 pop regions if (basepopulation == 0) return; - // growpop is the overall population growth + // growpop is the overall population growth int growpop = 0; - + // Init migration parameters - // immigrants = entering this region, + // immigrants = entering this region, // emigrants = leaving immigrants = habitat - basepopulation; emigrants = population - basepopulation; - + // First, check regional population growth // Check resource production activity int activity = 0; @@ -1280,29 +1302,29 @@ void ARegion::Grow() // bonuses for productivity are calculated from // the _baseamount_ of all resources. // because trade structures increase the produceable - // amount and not the baseamount this creates an + // amount and not the baseamount this creates an // effective advantage for trade structures amount += p->baseamount; } } - + // Now set the target population for the hex // Ant: I'm not sure why population's being subtracted here.. // Shouldn't it be something like : // tarpop = habitat + basepopulation? int tarpop = habitat - population + basepopulation; - + // Ant: Increase tarpop for any trading that's going on? // Not sure why (habitat - basepopulation) is included if (amount) tarpop += ((habitat - basepopulation) * 2 * activity) / (3 * amount); - + // diff is the amount we can grow? int diff = tarpop - population; int adiff = abs(diff); //if (adiff < 0) adiff = adiff * (- 1); - - // Adjust basepop? + + // Adjust basepop? // raise basepop depending on production // absolute basepop increase if (diff > (basepopulation / 20)) { @@ -1315,28 +1337,28 @@ void ARegion::Grow() // lower basepop for extremely low levels of population if (population < basepopulation) { int depop = (basepopulation - population) / 4; - basepopulation -= depop + getrandom(depop); + basepopulation -= depop + getrandom(depop); } - + // debug strings //Awrite(AString("immigrants = ") + immigrants); //Awrite(AString("emigrants = ") + emigrants); //Awrite(AString("adiff = ") + adiff); //Awrite(AString("diff = ") + diff); //Awrite(AString("habitat = ") + habitat); - + // Limit excessive growth at low pop / hab ratios // and avoid overflowing // What are grow2 and grow representing? Maybe these formulae // could be broken up a bit more and commented? long int grow2 = 5 * ((long int) habitat + (3 * (long int) adiff)); //Awrite(AString("grow2 = ") + (unsigned int) grow2); // debug string - + // Ant: In the following formula, dgrow is almost always 0! long int dgrow = ((long int) adiff * (long int) habitat ) / grow2; //if (diff < 0) dgrow = dgrow * (- 1); //Awrite(AString("dgrow = ") + (unsigned int) dgrow); // debug string - + // long int dgrow = ((long int) diff) * ((long int) habitat) // / (5 * (long int) ((long int) habitat + 3 * (long int) abs(diff))); if (diff < 0) growpop -= (int) dgrow; @@ -1351,7 +1373,7 @@ void ARegion::Grow() // update emigrants - only if region has a decent population level if (emigrants > 0) emigrants += diff; - + // Now check town population growth if (town) { int maxpop = TownGrowth(); @@ -1374,14 +1396,14 @@ void ARegion::Grow() // ((2 * town->hab) - town->pop) seems clearer float increase = tgrowth * (2 * town->hab - town->pop); float limitingfactor = (10 * town->hab); - + // Ant: Not sure whether we still need the typecasts here growpop += (int) (increase / limitingfactor); } // Update population AdjustPop(growpop); - + /* Initialise the migration variables */ migdev = 0; migfrom.DeleteAll(); @@ -1395,7 +1417,7 @@ void ARegion::FindMigrationDestination(int round) { // is emigration possible? if (emigrants < 0) return; - + int maxattract = 0; ARegion *target = this; // Check all hexes within 2 hexes @@ -1425,11 +1447,11 @@ void ARegion::FindMigrationDestination(int round) target = nb2; maxattract = ma; } - } + } } // do we have a target? if (target == this) return; - + // then add this region to the target's migfrom list ARegion *self = this; target->migfrom.Add(self); @@ -1441,7 +1463,7 @@ int ARegion::MigrationAttractiveness(int homedev, int range, int round) int attractiveness = 0; int mdev = development; /* Is there enough immigration capacity? */ - if (immigrants < 100) return 0; + if (immigrants < 100) return 0; /* on the second round, consider as a mid-way target */ if (round > 1) mdev = migdev; /* minimum development difference 8 x range */ @@ -1461,8 +1483,8 @@ int ARegion::MigrationAttractiveness(int homedev, int range, int round) } /* attractiveness due to development */ attractiveness += (int) (space * ((float) 100 * (mdev - homedev) / homedev + entertain)); - - return attractiveness; + + return attractiveness; } /* Performs migration for each region with a migration @@ -1479,16 +1501,16 @@ void ARegion::Migrate() totalmig += r->emigrants; } } - + // is there any migration to perform? if (totalmig == 0) return; - + // do each migration int totalimm = 0; forlist(&migfrom) { ARegion *r = (ARegion *) elem; if (!r) continue; - + // figure range int xdist = r->xloc - xloc; if (xdist < 0) xdist = - xdist; @@ -1496,7 +1518,7 @@ void ARegion::Migrate() if (ydist < 0) ydist = - ydist; ydist = (ydist - xdist) / 2; int range = xdist + ydist; - + // sanity check - huh? if (range < 1) continue; int migrants = (int) (immigrants * ((float) (r->emigrants / totalmig))); @@ -1512,7 +1534,7 @@ void ARegion::Migrate() r->emigrants -= migrants; totalimm += migrants; AString wout = AString("Migrating from ") /* + (r->name) + " in " */ + r->xloc - + "," + (r->yloc) + " to " /* + name + " in " */ + (xloc) + "," + yloc + + "," + (r->yloc) + " to " /* + name + " in " */ + (xloc) + "," + yloc + ": " + migrants + " migrants."; Awrite(wout); // set the region's mid-way migration development @@ -1532,7 +1554,7 @@ void ARegion::PostTurn(ARegionList *pRegs) if (Globals->DECAY) { DoDecayCheck(pRegs); } - + /* Development increase due to player activity */ // scale improvement float imp1 = improvement / 25; @@ -1547,7 +1569,7 @@ void ARegion::PostTurn(ARegionList *pRegs) for (int a=0; a<3; a++) if (getrandom(progress) < diff) development++; if (development > maxdevelopment) maxdevelopment = development; } - + /* Development increase for very poor regions */ int recoveryRounds = 1 + earthlore + clearskies; @@ -1555,13 +1577,13 @@ void ARegion::PostTurn(ARegionList *pRegs) while (recoveryRounds-- > 0) { if (maxdevelopment > development) { - if (getrandom(maxdevelopment) > development) development++; + if (getrandom(maxdevelopment) > development) development++; } if (maxdevelopment > development) { - if (getrandom(maxdevelopment) > development) development++; + if (getrandom(maxdevelopment) > development) development++; } if (maxdevelopment > development) { - if (getrandom(3) == 1) development++; + if (getrandom(3) == 1) development++; } } @@ -1583,13 +1605,14 @@ void ARegion::PostTurn(ARegionList *pRegs) float ratio = ItemDefs[race].baseprice / (float) (Globals->BASE_MAN_COST * 10); // Setup Recruiting Market *m = new Market( - Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 2000 + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 2000 ); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio = ItemDefs[I_LEADERS].baseprice / (float)Globals->BASE_MAN_COST; m = new Market( - Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400 + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, + 0, 10000, 0, 400 ); markets.push_back(m); } @@ -1600,7 +1623,7 @@ void ARegion::PostTurn(ARegionList *pRegs) if (type != R_NEXUS) { SetIncome(); } - + /* update markets */ for (auto& m : markets) m->post_turn(Population(), Wages()); diff --git a/edit.cpp b/edit.cpp index e6bd1934..11b0f636 100644 --- a/edit.cpp +++ b/edit.cpp @@ -41,7 +41,7 @@ int Game::EditGame(int *pSaveGame) } else if (*pStr == "2") { EditGameFindUnit(); } else if (*pStr == "3") { - EditGameCreateUnit(); + EditGameCreateUnit(); } else { Awrite("Select from the menu."); } @@ -120,97 +120,97 @@ void Game::EditGameFindUnit() void Game::EditGameRegion(ARegion *pReg) //copied direct from AtlantisDev 030730 post -{ +{ do { Awrite( AString("Region ") + pReg->num + ": " + - pReg->Print() ); - Awrite( " 1) Edit objects..." ); + pReg->Print() ); + Awrite( " 1) Edit objects..." ); Awrite( " 2) Edit terrain..." ); - Awrite( " q) Return to previous menu." ); + Awrite( " q) Return to previous menu." ); - int exit = 0; - AString *pStr = AGetString(); + int exit = 0; + AString *pStr = AGetString(); if ( *pStr == "1" ) { - EditGameRegionObjects( pReg ); - } + EditGameRegionObjects( pReg ); + } else if ( *pStr == "2" ) { - EditGameRegionTerrain( pReg ); - } + EditGameRegionTerrain( pReg ); + } else if ( *pStr == "q" ) { - exit = 1; - } + exit = 1; + } else { - Awrite( "Select from the menu." ); - } - if (pStr) delete pStr; + Awrite( "Select from the menu." ); + } + if (pStr) delete pStr; if ( exit ) { - break; - } - } - while( 1 ); -} + break; + } + } + while( 1 ); +} /* RegionEdit Patch 030829 BS */ -void Game::EditGameRegionObjects( ARegion *pReg ) +void Game::EditGameRegionObjects( ARegion *pReg ) //template copied from AtlantisDev 030730 post. Modified option a, added option h, m. -{ +{ do { - Awrite( AString( "Region: " ) + pReg->ShortPrint() ); - Awrite( "" ); - int i = 0; + Awrite( AString( "Region: " ) + pReg->ShortPrint() ); + Awrite( "" ); + int i = 0; AString temp = AString(""); - forlist (&(pReg->objects)) { - Object * obj = (Object *)elem; + forlist (&(pReg->objects)) { + Object * obj = (Object *)elem; temp = AString ((AString(i) + ". " + *obj->name + " : " + ObjectDefs[obj->type].name)); -// if (Globals->HEXSIDE_TERRAIN && obj->hexside>-1) temp += AString( AString(" (side:") + DirectionAbrs[obj->hexside] + ")."); +// if (Globals->HEXSIDE_TERRAIN && obj->hexside>-1) temp += AString( AString(" (side:") + DirectionAbrs[obj->hexside] + ")."); Awrite(temp); - i++; - } - Awrite( "" ); - - Awrite( " [a] [object type] [dir] to add object" ); - Awrite( " [d] [index] to delete object" ); -// if (Globals->HEXSIDE_TERRAIN) Awrite( " [h] [index] [dir] to change the hexside of an object" ); - Awrite( " [n] [index] [name] to rename object" ); + i++; + } + Awrite( "" ); + + Awrite( " [a] [object type] [dir] to add object" ); + Awrite( " [d] [index] to delete object" ); +// if (Globals->HEXSIDE_TERRAIN) Awrite( " [h] [index] [dir] to change the hexside of an object" ); + Awrite( " [n] [index] [name] to rename object" ); // if (Globals->HEXSIDE_TERRAIN) Awrite( " [m] [index] to add/delete a mirrored object" ); - Awrite( " q) Return to previous menu." ); - - int exit = 0; - AString *pStr = AGetString(); - if ( *pStr == "q" ) { - exit = 1; - } else { - AString *pToken = 0; - do { - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } - - // add object - if (*pToken == "a") { - SAFE_DELETE( pToken ); - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } - - int objType = ParseObject(pToken, 0); - if ( (objType == -1) || (ObjectDefs[objType].flags & ObjectType::DISABLED) ) { - Awrite( "No such object." ); - break; - } - SAFE_DELETE( pToken ); - + Awrite( " q) Return to previous menu." ); + + int exit = 0; + AString *pStr = AGetString(); + if ( *pStr == "q" ) { + exit = 1; + } else { + AString *pToken = 0; + do { + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } + + // add object + if (*pToken == "a") { + SAFE_DELETE( pToken ); + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } + + int objType = ParseObject(pToken, 0); + if ( (objType == -1) || (ObjectDefs[objType].flags & ObjectType::DISABLED) ) { + Awrite( "No such object." ); + break; + } + SAFE_DELETE( pToken ); + /* int dir=-1; if (ObjectDefs[objType].hexside && Globals->HEXSIDE_TERRAIN ) { if (!ObjectIsShip(objType) || !(TerrainDefs[pReg->type].similar_type == R_OCEAN) ) { - pToken = pStr->gettoken(); + pToken = pStr->gettoken(); if (!pToken) { Awrite( "Specify direction" ); break; @@ -223,91 +223,91 @@ void Game::EditGameRegionObjects( ARegion *pReg ) } } */ - - Object *o = new Object(pReg); - o->type = objType; - o->incomplete = 0; - o->inner = -1; + + Object *o = new Object(pReg); + o->type = objType; + o->incomplete = 0; + o->inner = -1; // o->hexside = dir; - if (o->IsFleet()) { - o->num = shipseq++; - o->name = new AString(AString("Fleet") + " [" + o->num + "]"); - } - else { - o->num = pReg->buildingseq++; - o->name = new AString(AString("Building") + " [" + o->num + "]"); - } - pReg->objects.Add(o); - } - // delete object - else if (*pToken == "d") { - SAFE_DELETE( pToken ); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } - - int index = pToken->value(); + if (o->IsFleet()) { + o->num = shipseq++; + o->name = new AString(AString("Fleet") + " [" + o->num + "]"); + } + else { + o->num = pReg->buildingseq++; + o->name = new AString(AString("Building") + " [" + o->num + "]"); + } + pReg->objects.Add(o); + } + // delete object + else if (*pToken == "d") { + SAFE_DELETE( pToken ); + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } + + int index = pToken->value(); if ( (index < 0) || (index >= pReg->objects.Num()) ) { //modified minimum to <0 to allow deleting object 0. 030824 BS - Awrite( "Incorrect index." ); - break; - } - SAFE_DELETE( pToken ); - - int i = 0; - AListElem *tmp = pReg->objects.First(); - for (i = 0; i < index; i++) tmp = pReg->objects.Next(tmp); - pReg->objects.Remove(tmp); - } + Awrite( "Incorrect index." ); + break; + } + SAFE_DELETE( pToken ); + + int i = 0; + AListElem *tmp = pReg->objects.First(); + for (i = 0; i < index; i++) tmp = pReg->objects.Next(tmp); + pReg->objects.Remove(tmp); + } //hexside change - /* else if (*pToken == "h") { - SAFE_DELETE( pToken ); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } - - int index = pToken->value(); - if ( (index < 1) || (index >= pReg->objects.Num()) ) { - Awrite( "Incorrect index." ); - break; - } - SAFE_DELETE( pToken ); - - int i = 0; - Object *tmp = (Object *)pReg->objects.First(); - for (i = 0; i < index; i++) tmp = (Object *)pReg->objects.Next(tmp); - + /* else if (*pToken == "h") { + SAFE_DELETE( pToken ); + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } + + int index = pToken->value(); + if ( (index < 1) || (index >= pReg->objects.Num()) ) { + Awrite( "Incorrect index." ); + break; + } + SAFE_DELETE( pToken ); + + int i = 0; + Object *tmp = (Object *)pReg->objects.First(); + for (i = 0; i < index; i++) tmp = (Object *)pReg->objects.Next(tmp); + if (!(ObjectDefs[tmp->type].hexside)) { Awrite("Not a hexside object."); break; } - + if (!Globals->HEXSIDE_TERRAIN) { Awrite("Hexside terrain disabled under game rules."); break; } - + pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Specify Direction." ); - break; - } - + if ( !pToken ) { + Awrite( "Specify Direction." ); + break; + } + int dir=-1; dir = ParseHexside(pToken); if (dir==-1) { Awrite("Incorrect direction. Use N,NE,SE,S,SW,NW"); break; } - - SAFE_DELETE(pToken); - if (dir) { - tmp->hexside = dir; + + SAFE_DELETE(pToken); + if (dir) { + tmp->hexside = dir; if (tmp->mirror) { // reset mirrors, else problems later tmp->mirror->mirror = NULL; tmp->mirror->mirrornum = -1; @@ -318,35 +318,35 @@ void Game::EditGameRegionObjects( ARegion *pReg ) } } //mirror change - else if (*pToken == "m") { - SAFE_DELETE( pToken ); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } - - int index = pToken->value(); - if ( (index < 1) || (index >= pReg->objects.Num()) ) { - Awrite( "Incorrect index." ); - break; - } - SAFE_DELETE( pToken ); - - int i = 0; - Object *tmp = (Object *)pReg->objects.First(); - for (i = 0; i < index; i++) tmp = (Object *)pReg->objects.Next(tmp); - + else if (*pToken == "m") { + SAFE_DELETE( pToken ); + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } + + int index = pToken->value(); + if ( (index < 1) || (index >= pReg->objects.Num()) ) { + Awrite( "Incorrect index." ); + break; + } + SAFE_DELETE( pToken ); + + int i = 0; + Object *tmp = (Object *)pReg->objects.First(); + for (i = 0; i < index; i++) tmp = (Object *)pReg->objects.Next(tmp); + // if has a mirror, delete the mirror if (tmp->mirror) { // Awrite(AString(AString("Mirror ") + tmp->mirror->name + " deleted.")); Awrite("Mirror deleted"); - tmp->mirror->region->objects.Remove(tmp->mirror); + tmp->mirror->region->objects.Remove(tmp->mirror); tmp->mirror == NULL; tmp->mirrornum == -1; } - + else { if (!(ObjectDefs[tmp->type].hexside)) { Awrite("Not a hexside object."); @@ -355,21 +355,21 @@ void Game::EditGameRegionObjects( ARegion *pReg ) if (tmp->hexside < 0) { Awrite("Object not on a hexside."); break; - } + } if (tmp->IsFleet()) { Awrite("Fleets cannot be mirrored."); break; - } + } if (!Globals->HEXSIDE_TERRAIN) { Awrite("Hexside terrain disabled under game rules."); break; } - + if (!pReg->neighbors[tmp->hexside]) { Awrite("No neighbouring region."); break; } - + Object *o = new Object(pReg->neighbors[tmp->hexside]); o->num = pReg->neighbors[tmp->hexside]->buildingseq++; o->type = ObjectDefs[tmp->type].mirror; @@ -380,72 +380,72 @@ void Game::EditGameRegionObjects( ARegion *pReg ) o->mirrornum = tmp->num; o->mirror = tmp; pReg->neighbors[tmp->hexside]->objects.Add(o); - + tmp->mirrornum = o->num; - tmp->mirror = o; - Awrite("Mirror added"); + tmp->mirror = o; + Awrite("Mirror added"); } } */ - // rename object - else if (*pToken == "n") { - SAFE_DELETE( pToken ); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } - - int index = pToken->value(); - if ( (index < 1) || (index >= pReg->objects.Num()) ) { - Awrite( "Incorrect index." ); - break; - } - SAFE_DELETE( pToken ); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "No name given." ); - break; - } - - int i = 0; - Object *tmp = (Object *)pReg->objects.First(); - for (i = 0; i < index; i++) tmp = (Object *)pReg->objects.Next(tmp); - - AString * newname = pToken->getlegal(); - SAFE_DELETE(pToken); - if (newname) { - delete tmp->name; - *newname += AString(" [") + tmp->num + "]"; - tmp->name = newname; - } - } - - } while( 0 ); - if (pToken) delete pToken; - } - if (pStr) delete pStr; - - if (exit) { - break; - } - } - while( 1 ); -} - -void Game::EditGameRegionTerrain( ARegion *pReg ) -{ + // rename object + else if (*pToken == "n") { + SAFE_DELETE( pToken ); + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } + + int index = pToken->value(); + if ( (index < 1) || (index >= pReg->objects.Num()) ) { + Awrite( "Incorrect index." ); + break; + } + SAFE_DELETE( pToken ); + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "No name given." ); + break; + } + + int i = 0; + Object *tmp = (Object *)pReg->objects.First(); + for (i = 0; i < index; i++) tmp = (Object *)pReg->objects.Next(tmp); + + AString * newname = pToken->getlegal(); + SAFE_DELETE(pToken); + if (newname) { + delete tmp->name; + *newname += AString(" [") + tmp->num + "]"; + tmp->name = newname; + } + } + + } while( 0 ); + if (pToken) delete pToken; + } + if (pStr) delete pStr; + + if (exit) { + break; + } + } + while( 1 ); +} + +void Game::EditGameRegionTerrain( ARegion *pReg ) +{ do { - Awrite(""); - Awrite( AString( "Region: " ) + pReg->Print() ); - Awrite( "" ); + Awrite(""); + Awrite( AString( "Region: " ) + pReg->Print() ); + Awrite( "" ); // write pop stuff Awrite( AString("") + pReg->population + " " + ItemDefs[pReg->race].names + " basepop"); if (pReg->town) Awrite( AString("") + pReg->town->pop + " " + ItemDefs[pReg->race].names + " townpop"); Awrite( AString("") + pReg->Population() + " " + ItemDefs[pReg->race].names + " totalpop"); - + // write wages Awrite(AString("Wages: ") + pReg->WagesForReport() + "."); Awrite(AString("Maxwages: ") + pReg->maxwages + "."); @@ -480,7 +480,7 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) if (has==0) temp += "none"; temp += "."; Awrite(temp); - Awrite( "" ); + Awrite( "" ); if (Globals->GATES_EXIST && pReg->gate && pReg->gate != -1) { Awrite(AString("There is a Gate here (Gate ") + pReg->gate + @@ -491,67 +491,67 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) } - Awrite( " [t] [terrain type] to modify terrain type" ); + Awrite( " [t] [terrain type] to modify terrain type" ); Awrite( " [r] [race] to modify local race" ); Awrite( " (use none, None or 0 to unset)" ); Awrite( " [w] [maxwages] to modify local wages" ); - Awrite( " [p] to regenerate products according to terrain type" ); + Awrite( " [p] to regenerate products according to terrain type" ); Awrite( " [g] to regenerate all according to terrain type" ); if (pReg->gate > 0) Awrite( " [dg] to delete the gate in this region" ); else Awrite( " [ag] to add a gate to this region" ); Awrite( " [n] [name] to modify region name" ); if (pReg->town) { - Awrite( " [town] to regenerate a town" ); + Awrite( " [town] to regenerate a town" ); Awrite( " [deltown] to remove a town" ); Awrite( " [tn] [name] to rename a town" ); Awrite( " [v] to view/modify town markets" ); - } else Awrite( " [town] to add a town" ); - Awrite( " q) Return to previous menu." ); - - int exit = 0; - AString *pStr = AGetString(); - if ( *pStr == "q" ) { - exit = 1; - } else { - AString *pToken = 0; - do { - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + } else Awrite( " [town] to add a town" ); + Awrite( " q) Return to previous menu." ); + + int exit = 0; + AString *pStr = AGetString(); + if ( *pStr == "q" ) { + exit = 1; + } else { + AString *pToken = 0; + do { + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } // modify terrain - if (*pToken == "t") { - SAFE_DELETE( pToken ); - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + if (*pToken == "t") { + SAFE_DELETE( pToken ); + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int terType = ParseTerrain(pToken); - if (terType == -1) { - Awrite( "No such terrain." ); - break; - } - SAFE_DELETE( pToken ); - + if (terType == -1) { + Awrite( "No such terrain." ); + break; + } + SAFE_DELETE( pToken ); + pReg->type = terType; - } - else if (*pToken == "r") { - SAFE_DELETE( pToken ); - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + } + else if (*pToken == "r") { + SAFE_DELETE( pToken ); + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int prace = 0; prace = ParseAllItems(pToken); if (!(ItemDefs[prace].type & IT_MAN) || (ItemDefs[prace].flags & ItemType::DISABLED) ) { if (!(*pToken == "none" || *pToken == "None" || *pToken == "0")) { - Awrite( "No such race." ); + Awrite( "No such race." ); break; } else { prace = -1; @@ -561,8 +561,8 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) pReg->UpdateEditRegion(); SAFE_DELETE( pToken ); } - else if (*pToken == "dg") { - SAFE_DELETE( pToken ); + else if (*pToken == "dg") { + SAFE_DELETE( pToken ); if (Globals->DISPERSE_GATE_NUMBERS) { pReg->gate = 0; regions.numberofgates--; @@ -582,7 +582,7 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) } } } - else if (*pToken == "ag") { + else if (*pToken == "ag") { SAFE_DELETE( pToken ); if (pReg->gate > 0) break; regions.numberofgates++; @@ -622,15 +622,15 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) } pReg->gate = gatenum; } - pReg->gatemonth = getrandom(12); + pReg->gatemonth = getrandom(12); } else if (*pToken == "w") { SAFE_DELETE( pToken ); - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int val = pToken->value(); SAFE_DELETE( pToken ); if (val) { @@ -639,8 +639,8 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) pReg->wages += change; } pReg->UpdateEditRegion(); - } - else if (*pToken == "p") { + } + else if (*pToken == "p") { SAFE_DELETE(pToken); auto removes = remove_if( pReg->products.begin(), @@ -650,8 +650,8 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) for_each (removes, pReg->products.end(), [](Production *p) mutable { delete p; }); pReg->products.erase(removes, pReg->products.end()); pReg->SetupProds(1); - } - else if (*pToken == "g") { + } + else if (*pToken == "g") { SAFE_DELETE(pToken); if (pReg->town) delete pReg->town; @@ -665,35 +665,35 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) pReg->markets.clear(); // empty the vector. pReg->SetupEditRegion(); - pReg->UpdateEditRegion(); + pReg->UpdateEditRegion(); } - else if (*pToken == "n") { + else if (*pToken == "n") { SAFE_DELETE(pToken); - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } - + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } + *pReg->name = *pToken; - SAFE_DELETE(pToken); - } - else if (*pToken == "tn") { SAFE_DELETE(pToken); - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } - + } + else if (*pToken == "tn") { + SAFE_DELETE(pToken); + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } + if (pReg->town) *pReg->town->name = *pToken; - SAFE_DELETE(pToken); - } - else if (*pToken == "town") { SAFE_DELETE(pToken); - + } + else if (*pToken == "town") { + SAFE_DELETE(pToken); + if (pReg->race<0) pReg->race = 9; - + AString *townname = new AString("name"); if (pReg->town) { *townname = *pReg->town->name; @@ -702,10 +702,10 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) pReg->markets.clear(); // empty the vector. } pReg->AddTown(townname); - + pReg->UpdateEditRegion(); // financial stuff! Does markets } - else if (*pToken == "deltown") { + else if (*pToken == "deltown") { SAFE_DELETE(pToken); if (pReg->town) { delete pReg->town; @@ -720,34 +720,34 @@ void Game::EditGameRegionTerrain( ARegion *pReg ) if (pReg->town) EditGameRegionMarkets(pReg); } } - while( 0 ); - if (pToken) delete pToken; - } - if (pStr) delete pStr; - - if ( exit ) { - break; - } - } - while( 1 ); -} + while( 0 ); + if (pToken) delete pToken; + } + if (pStr) delete pStr; + + if ( exit ) { + break; + } + } + while( 1 ); +} void Game::EditGameRegionMarkets( ARegion *pReg ) { /* This only gets called if pReg->town exists! */ do { - Awrite(""); + Awrite(""); Awrite( AString( "Region: " ) + pReg->Print() ); - Awrite( "" ); + Awrite( "" ); // write pop stuff Awrite( AString("") + pReg->town->pop + " " + ItemDefs[pReg->race].names + " townpop"); - + //write markets Awrite(AString("Market Format: ... price(base). minpop/maxpop. minamt/maxamt.")); Awrite("Wanted: "); for (const auto &m : pReg->markets) { - if (m->type == Market::M_SELL) { + if (m->type == Market::MarketType::M_SELL) { AString temp = AString(ItemString(m->item, m->amount)) + " at $" + m->price + "(" + m->baseprice + ")."; temp += AString(" Pop: ") + m->minpop + "/" + m->maxpop + "."; temp += AString(" Amount: ") + m->minamt + "/" + m->maxamt + "."; @@ -756,7 +756,7 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) } Awrite("For Sale: "); for (const auto &m : pReg->markets) { - if (m->type == Market::M_BUY) { + if (m->type == Market::MarketType::M_BUY) { AString temp = AString(ItemString(m->item, m->amount)) + " at $" + m->price + "(" + m->baseprice + ")."; temp += AString(" Pop: ") + m->minpop + "/" + m->maxpop + "."; temp += AString(" Amount: ") + m->minamt + "/" + m->maxamt + "."; @@ -764,31 +764,31 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) } } - Awrite( "" ); + Awrite( "" ); - Awrite( " [g] to regenerate all markets" ); - Awrite( " [p] [item] [minpop] [maxpop] to add/modify market population" ); + Awrite( " [g] to regenerate all markets" ); + Awrite( " [p] [item] [minpop] [maxpop] to add/modify market population" ); Awrite( " [a] [item] [minamt] [maxamt] to add/modify market amounts" ); Awrite( " [c] [item] [price] [baseprice] to add/modify item prices" ); Awrite( " [s] [item] to swap an item between wanted and sold" ); Awrite( " [d] [item] to delete an item from the market" ); - Awrite( " q) Return to previous menu." ); - - int exit = 0; - AString *pStr = AGetString(); - if ( *pStr == "q" ) { - exit = 1; - } else { - AString *pToken = 0; + Awrite( " q) Return to previous menu." ); + + int exit = 0; + AString *pStr = AGetString(); + if ( *pStr == "q" ) { + exit = 1; + } else { + AString *pToken = 0; do { - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } // regenerate markets - if (*pToken == "g") { + if (*pToken == "g") { SAFE_DELETE(pToken); for (auto& m : pReg->markets) delete m; // Free the allocated object @@ -797,14 +797,14 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) pReg->SetupCityMarket(); pReg->UpdateEditRegion(); } - else if (*pToken == "p") { + else if (*pToken == "p") { SAFE_DELETE(pToken); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int mitem = ParseEnabledItem(pToken); if (mitem<0) { Awrite("No such item"); @@ -812,23 +812,23 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) } SAFE_DELETE( pToken ); - pToken = pStr->gettoken(); + pToken = pStr->gettoken(); int minimum = pToken->value(); SAFE_DELETE( pToken ); - - pToken = pStr->gettoken(); + + pToken = pStr->gettoken(); int maximum = pToken->value(); SAFE_DELETE( pToken ); int done = 0; - + if (minimum + 1 > maximum) { Awrite("Maximum must be more than minimum"); break; } int population = pReg->Population(); - + for (auto& m : pReg->markets) { if (m->item == mitem) { m->minpop = minimum; @@ -851,19 +851,19 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) if (!done) { int price = (ItemDefs[mitem].baseprice * (100 + getrandom(50))) / 100; - Market *m = new Market(Market::M_SELL, mitem, price, 0, minimum, maximum, 0, 0); + Market *m = new Market(Market::MarketType::M_SELL, mitem, price, 0, minimum, maximum, 0, 0); pReg->markets.push_back(m); } } - else if (*pToken == "a") { + else if (*pToken == "a") { SAFE_DELETE(pToken); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int mitem = ParseEnabledItem(pToken); if (mitem<0) { Awrite("No such item"); @@ -871,28 +871,28 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) } SAFE_DELETE( pToken ); - pToken = pStr->gettoken(); + pToken = pStr->gettoken(); int minimum = pToken->value(); SAFE_DELETE( pToken ); - - pToken = pStr->gettoken(); + + pToken = pStr->gettoken(); int maximum = pToken->value(); SAFE_DELETE( pToken ); int done = 0; - + if (minimum + 1 > maximum) { Awrite("Maximum must be more than minimum"); break; } - + int population = pReg->Population(); - + for (auto& m: pReg->markets) { if (m->item == mitem) { m->minamt = minimum; m->maxamt = maximum; - + if (population <= m->minpop) m->amount = m->minamt; else { @@ -911,19 +911,21 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) if (!done) { int price = (ItemDefs[mitem].baseprice * (100 + getrandom(50))) / 100; int mamount = minimum + (maximum * population / 5000); - Market *m = new Market(Market::M_SELL, mitem, price, mamount, 0, 5000, minimum, maximum); + Market *m = new Market( + Market::MarketType::M_SELL, mitem, price, mamount, 0, 5000, minimum, maximum + ); pReg->markets.push_back(m); } } - else if (*pToken == "c") { + else if (*pToken == "c") { SAFE_DELETE(pToken); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int mitem = ParseEnabledItem(pToken); if (mitem<0) { Awrite("No such item"); @@ -931,11 +933,11 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) } SAFE_DELETE( pToken ); - pToken = pStr->gettoken(); + pToken = pStr->gettoken(); int price = pToken->value(); SAFE_DELETE( pToken ); - - pToken = pStr->gettoken(); + + pToken = pStr->gettoken(); int baseprice = pToken->value(); SAFE_DELETE( pToken ); @@ -954,27 +956,27 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) } if (!done) { - Market *m = new Market(Market::M_SELL, mitem, price, 0, 0, 5000, 0, 0); + Market *m = new Market(Market::MarketType::M_SELL, mitem, price, 0, 0, 5000, 0, 0); m->baseprice = baseprice; pReg->markets.push_back(m); } - } - else if (*pToken == "s") { + } + else if (*pToken == "s") { SAFE_DELETE(pToken); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int mitem = ParseEnabledItem(pToken); if (mitem<0) { Awrite("No such item"); break; } SAFE_DELETE( pToken ); - + // remove all duplicate market items of the same type. std::unordered_set s; auto dupes = remove_if( @@ -990,26 +992,30 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) [mitem](const Market *m) { return m->item == mitem; } ); if (m != pReg->markets.end()) { - (*m)->type = (*m)->type == Market::M_SELL ? Market::M_BUY : Market::M_SELL; + (*m)->type = ( + (*m)->type == Market::MarketType::M_SELL + ? Market::MarketType::M_BUY + : Market::MarketType::M_SELL + ); } else { - Awrite("No such market"); + Awrite("No such market"); } } - else if (*pToken == "d") { + else if (*pToken == "d") { SAFE_DELETE(pToken); - - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int mitem = ParseEnabledItem(pToken); if (mitem<0) { Awrite("No such item"); break; } SAFE_DELETE( pToken ); - + auto m = find_if( pReg->markets.begin(), pReg->markets.end(), @@ -1024,20 +1030,20 @@ void Game::EditGameRegionMarkets( ARegion *pReg ) for_each (dupes, pReg->markets.end(), [](Market *m) mutable { delete m; }); pReg->markets.erase(dupes, pReg->markets.end()); } else { - Awrite("No such market"); + Awrite("No such market"); } - } + } } - while( 0 ); - if (pToken) delete pToken; - } - if (pStr) delete pStr; - - if ( exit ) { - break; - } - } - while( 1 ); + while( 0 ); + if (pToken) delete pToken; + } + if (pStr) delete pStr; + + if ( exit ) { + break; + } + } + while( 1 ); } @@ -1051,8 +1057,8 @@ void Game::EditGameUnit(Unit *pUnit) Awrite(" 1) Edit items..."); Awrite(" 2) Edit skills..."); Awrite(" 3) Move unit..."); - Awrite(" 4) Edit details..."); - + Awrite(" 4) Edit details..."); + Awrite(" q) Stop editing this unit."); int exit = 0; @@ -1064,7 +1070,7 @@ void Game::EditGameUnit(Unit *pUnit) } else if (*pStr == "3") { EditGameUnitMove(pUnit); } else if (*pStr == "4") { - EditGameUnitDetails(pUnit); + EditGameUnitDetails(pUnit); } else if (*pStr == "q") { exit = 1; } else { @@ -1205,7 +1211,7 @@ void Game::EditGameUnitDetails(Unit *pUnit) { do { int exit = 0; - Awrite(AString("Unit: ") + *(pUnit->name)); + Awrite(AString("Unit: ") + *(pUnit->name)); Awrite(AString("Unit faction: ") + *(pUnit->faction->name)); AString temp = " ("; @@ -1221,26 +1227,26 @@ void Game::EditGameUnitDetails(Unit *pUnit) break; case U_WMON: temp += "monster"; - break; + break; case U_GUARDMAGE: temp += "guardmage"; break; case U_APPRENTICE: temp += Globals->APPRENTICE_NAME; - break; + break; } temp += ")"; Awrite(AString("Unit type: ") + pUnit->type + temp); - + Awrite(""); Awrite(" [f] [num] to change the unit's faction."); - Awrite(" [t] [num] to change the unit's type."); + Awrite(" [t] [num] to change the unit's type."); Awrite(" [q] Go back one screen."); - + AString *pStr = AGetString(); if (*pStr == "q") { exit = 1; - } + } else { AString *pToken = 0; do { @@ -1250,33 +1256,33 @@ void Game::EditGameUnitDetails(Unit *pUnit) break; } // change faction - if (*pToken == "f") { - SAFE_DELETE( pToken ); - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + if (*pToken == "f") { + SAFE_DELETE( pToken ); + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int fnum = pToken->value(); - SAFE_DELETE( pToken ); + SAFE_DELETE( pToken ); if (fnum<1) { Awrite("Invalid Faction Number"); break; } - + Faction *fac = GetFaction(&factions, fnum); if (fac) pUnit->faction = fac; else Awrite("Cannot Find Faction"); } - else if (*pToken == "t") { - SAFE_DELETE( pToken ); - pToken = pStr->gettoken(); - if ( !pToken ) { - Awrite( "Try again." ); - break; - } + else if (*pToken == "t") { + SAFE_DELETE( pToken ); + pToken = pStr->gettoken(); + if ( !pToken ) { + Awrite( "Try again." ); + break; + } int newtype = pToken->value(); - SAFE_DELETE( pToken ); + SAFE_DELETE( pToken ); if (newtype<0 || newtype>NUNITTYPES-1) { Awrite("Invalid Type"); break; diff --git a/fracas/world.cpp b/fracas/world.cpp index 34cf47fc..42483843 100644 --- a/fracas/world.cpp +++ b/fracas/world.cpp @@ -2506,9 +2506,9 @@ void ARegion::MakeStartingCity() if (!Globals->TOWNS_EXIST) return; if (Globals->GATES_EXIST) gate = -1; - + if (town) delete town; - + AddTown(TOWN_CITY); if (!Globals->START_CITIES_EXIST) return; @@ -2529,18 +2529,18 @@ void ARegion::MakeStartingCity() if ( ItemDefs[ i ].type & IT_NORMAL ) { if (i==I_SILVER || i==I_LIVESTOCK || i==I_FISH || i==I_GRAIN) continue; - m = new Market(Market::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); markets.push_back(m); } } ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); } } else { @@ -2548,12 +2548,16 @@ void ARegion::MakeStartingCity() ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above /* Setup Recruiting */ - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000); + m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000 + ); markets.push_back(m); if ( Globals->LEADERS_EXIST ) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400 + ); markets.push_back(m); } } diff --git a/havilah/world.cpp b/havilah/world.cpp index 0301ad81..c588de83 100644 --- a/havilah/world.cpp +++ b/havilah/world.cpp @@ -764,9 +764,9 @@ void ARegion::MakeStartingCity() if (!Globals->TOWNS_EXIST) return; if (Globals->GATES_EXIST) gate = -1; - + if (town) delete town; - + AddTown(TOWN_CITY); if (!Globals->START_CITIES_EXIST) return; @@ -786,18 +786,18 @@ void ARegion::MakeStartingCity() if ( ItemDefs[ i ].type & IT_NORMAL ) { if (i==I_SILVER || i==I_LIVESTOCK || i==I_FISH || i==I_GRAIN) continue; - m = new Market(Market::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); markets.push_back(m); } } ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); } } else { @@ -805,12 +805,16 @@ void ARegion::MakeStartingCity() ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above /* Setup Recruiting */ - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000); + m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000 + ); markets.push_back(m); if ( Globals->LEADERS_EXIST ) { ratio = ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400 + ); markets.push_back(m); } } diff --git a/kingdoms/world.cpp b/kingdoms/world.cpp index 2d4dada5..cbe524c0 100644 --- a/kingdoms/world.cpp +++ b/kingdoms/world.cpp @@ -2503,9 +2503,9 @@ void ARegion::MakeStartingCity() if (!Globals->TOWNS_EXIST) return; if (Globals->GATES_EXIST) gate = -1; - + if (town) delete town; - + AddTown(TOWN_CITY); if (!Globals->START_CITIES_EXIST) return; @@ -2526,18 +2526,18 @@ void ARegion::MakeStartingCity() if ( ItemDefs[ i ].type & IT_NORMAL ) { if (i==I_SILVER || i==I_LIVESTOCK || i==I_FISH || i==I_GRAIN) continue; - m = new Market(Market::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); markets.push_back(m); } } ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); } } else { @@ -2545,12 +2545,16 @@ void ARegion::MakeStartingCity() ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above /* Setup Recruiting */ - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000); + m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000 + ); markets.push_back(m); if ( Globals->LEADERS_EXIST ) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400 + ); markets.push_back(m); } } diff --git a/market.cpp b/market.cpp index 5d2ccb42..4a11f4a9 100644 --- a/market.cpp +++ b/market.cpp @@ -27,6 +27,7 @@ #include "items.h" #include "gameio.h" #include "gamedata.h" +#include void Market::post_turn(int population, int wages) { @@ -52,7 +53,7 @@ void Market::post_turn(int population, int wages) int tarprice = price; if (amount) { int fluctuation = (baseprice * activity)/amount; - if (type == M_BUY) + if (type == MarketType::M_BUY) tarprice = (2 * baseprice + fluctuation) / 2; else tarprice = (3 * baseprice - fluctuation) / 2; @@ -70,7 +71,7 @@ void Market::post_turn(int population, int wages) void Market::write_out(std::ostream& f) { - f << type << '\n'; + f << static_cast>(type) << '\n'; f << (item == -1 ? "NO_ITEM" : ItemDefs[item].abr) << '\n'; f << price << '\n'; f << amount << '\n'; diff --git a/market.h b/market.h index 045e2431..7a6496e0 100644 --- a/market.h +++ b/market.h @@ -29,7 +29,7 @@ class Market { public: - enum MarketType : int { + enum struct MarketType : int { M_BUY, M_SELL }; diff --git a/neworigins/world.cpp b/neworigins/world.cpp index 11feef96..dd8d828b 100644 --- a/neworigins/world.cpp +++ b/neworigins/world.cpp @@ -510,10 +510,9 @@ void Game::CreateWorld() regions.FinalSetupGates(); // do final modifications to add in the victory objects (the ritual altars and the deactivated monolith) - regions.CalcDensities(); - + regions.TownStatistics(); regions.ResourcesStatistics(); @@ -801,9 +800,9 @@ void ARegion::MakeStartingCity() if (!Globals->TOWNS_EXIST) return; if (Globals->GATES_EXIST) gate = -1; - + if (town) delete town; - + AddTown(TOWN_CITY); if (!Globals->START_CITIES_EXIST) return; @@ -824,18 +823,18 @@ void ARegion::MakeStartingCity() if ( ItemDefs[ i ].type & IT_NORMAL ) { if (i==I_SILVER || i==I_LIVESTOCK || i==I_FISH || i==I_GRAIN) continue; - m = new Market(Market::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); markets.push_back(m); } } ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio = ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); } } else { @@ -843,12 +842,16 @@ void ARegion::MakeStartingCity() ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above /* Setup Recruiting */ - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000); + m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000 + ); markets.push_back(m); if ( Globals->LEADERS_EXIST ) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400 + ); markets.push_back(m); } } diff --git a/runorders.cpp b/runorders.cpp index c75349a6..c0ca0c9c 100644 --- a/runorders.cpp +++ b/runorders.cpp @@ -544,7 +544,9 @@ void Game::Do1Destroy(ARegion *r, Object *o, Unit *u) { destroyPower = structurePoints; } else { - destroyablePoints = std::max(Globals->MIN_DESTROY_POINTS, maxStructurePoints * Globals->MAX_DESTROY_PERCENT / 100); + destroyablePoints = std::max( + Globals->MIN_DESTROY_POINTS, maxStructurePoints * Globals->MAX_DESTROY_PERCENT / 100 + ); destroyablePoints = std::max(0, std::min(structurePoints, destroyablePoints) - o->destroyed); if (Globals->DESTROY_BEHAVIOR == DestroyBehavior::PER_SKILL) { @@ -1451,7 +1453,7 @@ void Game::RunSellOrders() forlist((®ions)) { ARegion *r = (ARegion *) elem; for (const auto& m : r->markets) { - if (m->type == Market::M_SELL) DoSell(r, m); + if (m->type == Market::MarketType::M_SELL) DoSell(r, m); } forlist((&r->objects)) { Object *obj = (Object *) elem; @@ -1534,7 +1536,7 @@ void Game::RunBuyOrders() forlist((®ions)) { ARegion *r = (ARegion *) elem; for (const auto& m : r->markets) { - if (m->type == Market::M_BUY) DoBuy(r, m); + if (m->type == Market::MarketType::M_BUY) DoBuy(r, m); } forlist((&r->objects)) { Object *obj = (Object *) elem; @@ -3062,7 +3064,9 @@ void Game::CheckTransportOrders() dist = regions.GetPlanarDistance(r, tar->region, penalty, maxdist); } if (dist > maxdist) { - u->error("TRANSPORT: Recipient " + string(tar->unit->name->const_str()) + " is too far away."); + u->error( + "TRANSPORT: Recipient " + string(tar->unit->name->const_str()) + " is too far away." + ); o->type = NORDERS; continue; } @@ -3307,7 +3311,8 @@ void Game::RunSacrificeOrders() { if (reward_obj != -1 ) { sacrifice_object->type = reward_obj; - string name = string(ObjectDefs[reward_obj].name) + " [" + to_string(sacrifice_object->num) + "]"; + string name = string(ObjectDefs[reward_obj].name) + " [" + + to_string(sacrifice_object->num) + "]"; sacrifice_object->name = new AString(name); u->faction->objectshows.push_back({.obj = reward_obj}); } diff --git a/standard/world.cpp b/standard/world.cpp index 52219f92..c7f7e59d 100644 --- a/standard/world.cpp +++ b/standard/world.cpp @@ -2142,7 +2142,7 @@ void Game::CreateWorld() SetupNames(); regions.CreateNexusLevel( 0, nx, ny, "nexus" ); - + regions.CreateSurfaceLevel(1, xx, yy, 0); // Create underworld levels @@ -2497,9 +2497,9 @@ void ARegion::MakeStartingCity() if (!Globals->TOWNS_EXIST) return; if (Globals->GATES_EXIST) gate = -1; - + if (town) delete town; - + AddTown(TOWN_CITY); if (!Globals->START_CITIES_EXIST) return; @@ -2519,18 +2519,18 @@ void ARegion::MakeStartingCity() if ( ItemDefs[ i ].type & IT_NORMAL ) { if (i==I_SILVER || i==I_LIVESTOCK || i==I_FISH || i==I_GRAIN) continue; - m = new Market(Market::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); markets.push_back(m); } } ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); } } else { @@ -2538,12 +2538,16 @@ void ARegion::MakeStartingCity() ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above /* Setup Recruiting */ - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000); + m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000 + ); markets.push_back(m); if ( Globals->LEADERS_EXIST ) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400 + ); markets.push_back(m); } } diff --git a/unittest/world.cpp b/unittest/world.cpp index 3d9338d2..0d8a846f 100644 --- a/unittest/world.cpp +++ b/unittest/world.cpp @@ -35,14 +35,14 @@ char const *AGetNameString( int name ) { return (name == 0) ? "Testing Wilds" : void Game::CreateWorld() { Awrite("Creating world"); - regions.CreateLevels(1); + regions.CreateLevels(1); // because of the way regions are numbered, if you want 4 hexes you need a height of 4 and a width of 2. regions.CreateSurfaceLevel(0, 2, 4, nullptr); // Make an underworld level regions.CreateUnderworldLevel(1, 1, 2, "underworld"); // Make a shaft regions.MakeShaftLinks(0, 1, 100); - + ARegion *reg = regions.GetRegion(0,0,0); reg->MakeStartingCity(); } @@ -65,7 +65,7 @@ int ARegion::CanBeStartingCity( ARegionArray *pRA ) { return 1; } void ARegion::MakeStartingCity() { if (!Globals->TOWNS_EXIST) return; if (town) delete town; - + AddTown(TOWN_CITY); if (!Globals->START_CITIES_EXIST) return; @@ -85,18 +85,18 @@ void ARegion::MakeStartingCity() { if ( ItemDefs[ i ].type & IT_NORMAL ) { if (i==I_SILVER || i==I_LIVESTOCK || i==I_FISH || i==I_GRAIN) continue; - m = new Market(Market::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, i, (ItemDefs[i].baseprice * 5 / 2), -1, 5000, 5000, -1, -1); markets.push_back(m); } } ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); if (Globals->LEADERS_EXIST) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); + m = new Market(Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), -1, 5000, 5000, -1, -1); markets.push_back(m); } } else { @@ -104,12 +104,16 @@ void ARegion::MakeStartingCity() { ratio = ItemDefs[race].baseprice / ((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above /* Setup Recruiting */ - m = new Market(Market::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000); + m = new Market( + Market::MarketType::M_BUY, race, (int)(Wages() * 4 * ratio), Population() / 5, 0, 10000, 0, 2000 + ); markets.push_back(m); if ( Globals->LEADERS_EXIST ) { ratio=ItemDefs[I_LEADERS].baseprice/((float)Globals->BASE_MAN_COST * 10); // hack: include wage factor of 10 in float calculation above - m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400); + m = new Market( + Market::MarketType::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400 + ); markets.push_back(m); } }