diff --git a/aregion.cpp b/aregion.cpp index a645663a..1ec88078 100644 --- a/aregion.cpp +++ b/aregion.cpp @@ -29,14 +29,12 @@ Location *GetUnit(std::list& locs, int unitid) return nullptr; } -Farsight::Farsight() +Farsight::Farsight(Faction *faction, Unit *unit, int level, int observation) + : faction(faction), unit(unit), level(level), observation(observation) { - faction = 0; - unit = 0; - level = 0; - observation = 0; - for (int i = 0; i < NDIRS; i++) + for (int i = 0; i < NDIRS; i++) { exits_used[i] = 0; + } } Farsight *GetFarsight(std::list& farsees, Faction *fac) @@ -57,15 +55,6 @@ std::string TownString(int i) return "huh?"; } -TownInfo::TownInfo() -{ - pop = 0; - activity = 0; - hab = 0; -} - -TownInfo::~TownInfo() { } - void TownInfo::Readin(std::istream &f) { std::string temp; @@ -81,27 +70,10 @@ void TownInfo::Writeout(std::ostream& f) } ARegion::ARegion() + : name("Region") { - name = "Region"; - xloc = 0; - yloc = 0; - buildingseq = 1; - gate = 0; - gatemonth = 0; - gateopen = 1; - town = 0; - development = 0; - maxdevelopment = 0; - habitat = 0; - immigrants = 0; - emigrants = 0; - improvement = 0; - clearskies = 0; - earthlore = 0; - phantasmal_entertainment = 0; for (int i=0; iGetUnitId(id, faction); if (unit) { - Location *l = new Location; + Location *l = new Location(); l->region = this; l->obj = o; l->unit = unit; @@ -972,7 +944,7 @@ void ARegion::Readin(std::istream &f, std::list& facs) int n; f >> n; if (n) { - town = new TownInfo; + town = new TownInfo(); town->Readin(f); town->dev = TownDevelopment(); } else { @@ -1662,7 +1634,7 @@ int ARegionList::ReadRegions(std::istream &f, std::list& factions) logger::write("Reading the regions..."); for (i = 0; i < num; i++) { - ARegion *temp = new ARegion; + ARegion *temp = new ARegion(); temp->Readin(f, factions); regions.push_back(temp); @@ -1711,7 +1683,7 @@ Location *ARegionList::FindUnit(int i) for(const auto obj : reg->objects) { for(const auto u : obj->units) { if (u->num == i) { - Location *retval = new Location; + Location *retval = new Location(); retval->unit = u; retval->region = reg; retval->obj = obj; @@ -1736,7 +1708,7 @@ void ARegionList::MakeRegions(int level, int xSize, int ySize) for (int y = 0; y < ySize; y++) { for (int x = 0; x < xSize; x++) { if (!((x + y) % 2)) { - ARegion *reg = new ARegion; + ARegion *reg = new ARegion(); reg->SetLoc(x, y, level); reg->num = regions.size(); @@ -1843,7 +1815,7 @@ void ARegionList::MakeIcosahedralRegions(int level, int xSize, int ySize) continue; } - ARegion *reg = new ARegion; + ARegion *reg = new ARegion(); reg->SetLoc(x, y, level); reg->num = regions.size(); @@ -4001,3 +3973,4 @@ int ARegionList::find_distance_between_regions(ARegion *start, ARegion *end) graphs::Location2D b = { end->xloc, end->yloc }; return cylDistance(a, b, w); } + diff --git a/aregion.h b/aregion.h index e6198bf9..a35c5339 100644 --- a/aregion.h +++ b/aregion.h @@ -83,9 +83,9 @@ class TerrainType class Location { public: - Unit *unit; - Object *obj; - ARegion *region; + Unit *unit = nullptr; + Object *obj = nullptr; + ARegion *region = nullptr; }; Location *GetUnit(std::list& locs, int unitid); @@ -96,7 +96,7 @@ const std::string& AGetNameString(int name); class Farsight { public: - Farsight(); + Farsight(Faction *faction, Unit *unit, int level, int observation = 0); Faction *faction; Unit *unit; @@ -117,20 +117,17 @@ enum { class TownInfo { public: - TownInfo(); - ~TownInfo(); - void Readin(std::istream& f); void Writeout(std::ostream& f); int TownType(); std::string name; - int pop; - int activity; + int pop = 0; + int activity = 0; // achieved settled habitat - int hab; + int hab = 0; // town's development - int dev; + int dev = 0; }; struct RegionSetup { @@ -270,13 +267,13 @@ class ARegion std::string name; int num; int type = -1; - int buildingseq; + int buildingseq = 1; int weather = W_NORMAL; - int gate; - int gatemonth; - int gateopen; + int gate = 0; + int gatemonth = 0; + int gateopen = 1; - TownInfo *town; + TownInfo *town = nullptr; int race = -1; int population = -1; int basepopulation; @@ -285,9 +282,9 @@ class ARegion int wealth; /* Economy */ - int habitat; - int development; - int maxdevelopment; + int habitat = 0; + int development = 0; + int maxdevelopment = 0; int elevation = -1; int humidity = -1; int temperature = -1; @@ -297,15 +294,15 @@ class ARegion std::list migfrom; // mid-way migration development int migdev; - int immigrants; - int emigrants; + int immigrants= 0; + int emigrants = 0; // economic improvement - int improvement; + int improvement = 0; /* Potential bonuses to economy */ - int clearskies; - int earthlore; - int phantasmal_entertainment; + int clearskies = 0; + int earthlore = 0; + int phantasmal_entertainment = 0; ARegion *neighbors[NDIRS]; safe::list objects; @@ -317,8 +314,8 @@ class ARegion std::listpassers; std::vector products; std::vector markets; - int xloc, yloc, zloc; - int visited; + int xloc = 0, yloc = 0, zloc = 0; + int visited = 0; // Used for calculating distances using an A* search int distance; diff --git a/battle.cpp b/battle.cpp index 2232c6e9..d60250b6 100644 --- a/battle.cpp +++ b/battle.cpp @@ -95,9 +95,6 @@ void WriteStats(Battle &battle, Army &army, StatsCategory category) { if (statLines == 0) battle.AddLine("Army made no attacks."); } -Battle::Battle() { } -Battle::~Battle() { } - // Checks if army A is overwhelmed by army B bool IsArmyOverwhelmedBy(Army * a, Army * b) { if (!Globals->OVERWHELMING) return false; @@ -377,7 +374,7 @@ void AddBattleFact( ) { if (!Globals->WORLD_EVENTS) return; - auto fact = new BattleFact(); + BattleFact * fact = new BattleFact(); fact->location = EventLocation::Create(region); @@ -737,7 +734,7 @@ void Game::GetAFacs( } if (add && dfacs.find(u->faction) == dfacs.end()) { - Location * l = new Location; + Location * l = new Location(); l->unit = u; l->obj = obj; l->region = r; @@ -773,13 +770,13 @@ void Game::GetSides( { if (ass) { /* Assassination attempt */ - Location * l = new Location; + Location * l = new Location(); l->unit = att; l->obj = r->GetDummy(); l->region = r; atts.push_back(l); - l = new Location; + l = new Location(); l->unit = tar; l->obj = r->GetDummy(); l->region = r; @@ -888,13 +885,13 @@ void Game::GetSides( } if (add == ADD_ATTACK) { - Location * l = new Location; + Location * l = new Location(); l->unit = u; l->obj = o; l->region = r2; atts.push_back(l); } else if (add == ADD_DEFENSE) { - Location * l = new Location; + Location * l = new Location(); l->unit = u; l->obj = o; l->region = r2; @@ -1028,7 +1025,7 @@ int Game::RunBattle(ARegion * r,Unit * attacker,Unit * target,int ass, return BATTLE_IMPOSSIBLE; } - Battle *b = new Battle; + Battle *b = new Battle(); b->WriteSides(r, attacker, target, atts, defs, ass); battles.push_back(b); diff --git a/battle.h b/battle.h index 4e9c144e..81b35df4 100644 --- a/battle.h +++ b/battle.h @@ -31,9 +31,6 @@ enum { class Battle { public: - Battle(); - ~Battle(); - void build_json_report(json &j, Faction *fac); void AddLine(const std::string& line); diff --git a/economy.cpp b/economy.cpp index 7d844eeb..fb1cbd26 100644 --- a/economy.cpp +++ b/economy.cpp @@ -144,7 +144,7 @@ void ARegion::SetupEconomy() { } int wagelimit = (int) ((float) (pp * (Wages() - 10 * Globals->MAINTENANCE_COST) /50)); if (wagelimit < 0) wagelimit = 0; - Production * w = new Production; + Production * w = new Production(); w->itemtype = I_SILVER; w->amount = wagelimit / Globals->WORK_FRACTION; w->baseamount = wagelimit / Globals->WORK_FRACTION; @@ -161,7 +161,7 @@ void ARegion::SetupEconomy() { int maxent = (int) ((float) (ep * ((Wages() - 10 * Globals->MAINTENANCE_COST) + 1) /50)); if (maxent < 0) maxent = 0; - Production * e = new Production; + Production * e = new Production(); e->itemtype = I_SILVER; e->skill = S_ENTERTAINMENT; e->amount = maxent / Globals->ENTERTAIN_FRACTION; @@ -271,7 +271,7 @@ void ARegion::SetIncome() // In some cases (ie. after products.DeleteAll() in EditGameRegionTerrain) // I_SILVER is not in ProductionList if( !w ) { - w = new Production; + w = new Production(); products.push_back(w); } w->itemtype = I_SILVER; @@ -293,7 +293,7 @@ void ARegion::SetIncome() // In some cases (ie. after products.DeleteAll() in EditGameRegionTerrain) // I_SILVER is not in ProductionList if( !e ) { - e = new Production; + e = new Production(); products.push_back(e); } e->itemtype = I_SILVER; @@ -804,7 +804,7 @@ void ARegion::add_town(int size) * in the last instance. */ void ARegion::add_town(int size, const std::string& name) { - town = new TownInfo; + town = new TownInfo(); town->name = name; SetTownType(size); SetupCityMarket(); diff --git a/events.h b/events.h index b395cd70..7c17fc62 100644 --- a/events.h +++ b/events.h @@ -112,7 +112,6 @@ struct EventLocation { int settlementType; std::vector landmarks; - events::LandmarkType GetLandmarkType(); const std::string GetTerrainName(const bool plural = false); static EventLocation Create(ARegion* region); const Landmark *GetSignificantLandmark(); @@ -120,9 +119,8 @@ struct EventLocation { class BattleFact : public FactBase { public: - ~BattleFact() = default; - - void GetEvents(std::list &events); + virtual ~BattleFact() = default; + virtual void GetEvents(std::list &events); EventLocation location; BattleSide attacker; diff --git a/faction.cpp b/faction.cpp index 225317fc..b5a522f5 100644 --- a/faction.cpp +++ b/faction.cpp @@ -72,25 +72,11 @@ std::optional parse_attitude(const parser::token& str) } Faction::Faction() + : password("none") { - exists = true; for (auto &ft : *FactionTypes) { type[ft] = 1; } - - lastchange = -6; - password = "none"; - times = 0; - showunitattitudes = 0; - temformat = TEMPLATE_OFF; - quit = 0; - defaultattitude = AttitudeType::NEUTRAL; - unclaimed = 0; - pReg = NULL; - pStartLoc = NULL; - noStartLeader = 0; - startturn = 0; - battleLogFormat = 0; } Faction::Faction(int n) diff --git a/faction.h b/faction.h index 8095d4f1..7eb9e493 100644 --- a/faction.h +++ b/faction.h @@ -169,18 +169,18 @@ class Faction // std::unordered_map type; - int lastchange; + int lastchange = -6; int lastorders; - int unclaimed; + int unclaimed = 0; std::string name; std::string address; std::string password; - int times; - int showunitattitudes; - int temformat; - int battleLogFormat; - bool exists; - int quit; + int times = 0; + int showunitattitudes = 0; + int temformat = TEMPLATE_OFF; + int battleLogFormat = 0; + bool exists = true; + int quit = 0; int numshows; int nummages; @@ -198,7 +198,7 @@ class Faction /* Used when writing reports */ std::vector present_regions; - AttitudeType defaultattitude; + AttitudeType defaultattitude = AttitudeType::NEUTRAL; // TODO: Convert this to a hashmap of > // For now, just making it a vector of attitudes. More will come later. std::vector attitudes; @@ -220,10 +220,10 @@ class Faction // These are used for 'granting' units to a faction via the players.in // file - ARegion *pReg; - ARegion *pStartLoc; - int noStartLeader; - int startturn; + ARegion *pReg = nullptr; + ARegion *pStartLoc = nullptr; + int noStartLeader = 0; + int startturn = 0; private: std::vector compute_faction_statistics(Game *game, size_t **citems); diff --git a/game.cpp b/game.cpp index 65c3a3fe..32e59e0a 100644 --- a/game.cpp +++ b/game.cpp @@ -450,7 +450,7 @@ int Game::OpenGame() f >> i; for (int j = 0; j < i; j++) { - Faction *temp = new Faction; + Faction *temp = new Faction(); temp->Readin(f); factions.push_back(temp); } diff --git a/havilah/map.cpp b/havilah/map.cpp index bdddfa99..3b625d9f 100644 --- a/havilah/map.cpp +++ b/havilah/map.cpp @@ -225,7 +225,6 @@ void ARegionList::create_underdeep_level(int level, int xSize, int ySize, const FinalSetup(pRegionArrays[level]); } - void ARegionList::MakeLand(ARegionArray *pRegs, int percentOcean, int continentSize) { diff --git a/items.cpp b/items.cpp index e1e3a49a..c70f5e42 100644 --- a/items.cpp +++ b/items.cpp @@ -1325,17 +1325,6 @@ int IsSoldier(int item) return 0; } - -Item::Item() -{ - selling = 0; - checked = 0; -} - -Item::~Item() -{ -} - std::string Item::report(bool see_illusions) { std::string ret = ""; @@ -1377,7 +1366,7 @@ void ItemList::Readin(std::istream &f) int i; f >> i; for (int j = 0; j < i; j++) { - Item *temp = new Item; + Item *temp = new Item(); temp->Readin(f); if (temp->type < 0 || temp->num < 1 || ItemDefs[temp->type].flags & ItemType::DISABLED) { delete temp; @@ -1527,7 +1516,7 @@ void ItemList::SetNum(int t,int n) return; } } - Item *i = new Item; + Item *i = new Item(); i->type = t; i->num = n; items.push_back(i); diff --git a/items.h b/items.h index 2d3806d1..4b1b0083 100644 --- a/items.h +++ b/items.h @@ -432,18 +432,15 @@ extern int IsSoldier(int); class Item { public: - Item(); - ~Item(); - void Readin(std::istream& f); void Writeout(std::ostream& f); std::string report(bool see_illusions); - int type; - int num; - int selling; - int checked; // flag whether item has been reported, counted etc. + int type = 0; + int num = 0; + int selling = 0; + int checked = 0; // flag whether item has been reported, counted etc. }; class ItemList diff --git a/monthorders.cpp b/monthorders.cpp index e7ec2e4a..df73a3f8 100644 --- a/monthorders.cpp +++ b/monthorders.cpp @@ -288,10 +288,7 @@ Location *Game::Do1SailOrder(ARegion *reg, Object *fleet, Unit *cap) } } // And mark the hex being entered - Farsight *f = new Farsight; - f->faction = unit->faction; - f->level = 0; - f->unit = unit; + Farsight *f = new Farsight(unit->faction, unit, 0); f->exits_used[reg->GetRealDirComp(x->dir)] = 1; newreg->passers.push_back(f); } @@ -317,7 +314,7 @@ Location *Game::Do1SailOrder(ARegion *reg, Object *fleet, Unit *cap) } } - loc = new Location; + loc = new Location(); loc->unit = cap; loc->region = reg; loc->obj = fleet; @@ -1037,7 +1034,7 @@ void Game::RunUnitProduce(ARegion *r, Unit *u) u->Practice(o->skill); o->target -= output; if (o->target > 0) { - TurnOrder *tOrder = new TurnOrder; + TurnOrder *tOrder = new TurnOrder(); tOrder->repeating = 0; std::string order = "PRODUCE " + std::to_string(o->target) + " " + ItemDefs[o->item].abr; tOrder->turnOrders.push_back(order); @@ -1208,8 +1205,7 @@ void Game::RunAProduction(ARegion *r, Production *p) p->activity += ubucks; po->target -= ubucks; if (po->target > 0) { - TurnOrder *tOrder = new TurnOrder; - tOrder->repeating = 0; + TurnOrder *tOrder = new TurnOrder(); std::string order = "PRODUCE " + std::to_string(po->target) + " " + ItemDefs[po->item].abr; tOrder->turnOrders.push_back(order); u->turnorders.push_front(tOrder); @@ -1442,8 +1438,7 @@ void Game::Do1StudyOrder(Unit *u, Object *obj) // study to level order if (o->level != -1) { if (u->GetRealSkill(sk) < o->level) { - TurnOrder *tOrder = new TurnOrder; - tOrder->repeating = 0; + TurnOrder *tOrder = new TurnOrder(); std::string order = "STUDY " + std::string(SkillDefs[sk].abbr) + " " + std::to_string(o->level); tOrder->turnOrders.push_back(order); u->turnorders.push_front(tOrder); @@ -1763,10 +1758,7 @@ Location *Game::DoAMoveOrder(Unit *unit, ARegion *region, Object *obj) } } // And mark the hex being entered - Farsight *f = new Farsight; - f->faction = unit->faction; - f->level = 0; - f->unit = unit; + Farsight *f = new Farsight(unit->faction, unit, 0); if (x->dir < MOVE_IN) { f->exits_used[region->GetRealDirComp(x->dir)] = 1; } newreg->passers.push_back(f); } @@ -1776,7 +1768,7 @@ Location *Game::DoAMoveOrder(Unit *unit, ARegion *region, Object *obj) std::erase(o->dirs, x); delete x; - loc = new Location; + loc = new Location(); loc->unit = unit; loc->region = region; loc->obj = nullptr; diff --git a/neworigins/map.cpp b/neworigins/map.cpp index 411eae84..72eb8a59 100644 --- a/neworigins/map.cpp +++ b/neworigins/map.cpp @@ -52,11 +52,11 @@ struct Province; struct ZoneRegion { int id; Coords location; - bool exclude; - int biome; - Zone *zone; - Province *province; - ARegion* region; + bool exclude = false; + int biome = -1; + Zone *zone = nullptr; + Province *province = nullptr; + ARegion* region = nullptr; ZoneRegion *neighbors[NDIRS]; bool HaveBorderWith(Zone* zone); @@ -167,8 +167,8 @@ bool ZoneRegion::IsOuter() { struct Province { int id; int h; - int biome; - Zone* zone; + int biome = -1; + Zone* zone = nullptr; std::map regions; Coords GetLocation(); @@ -336,15 +336,13 @@ Zone::~Zone() { for (auto &kv : provinces) { delete kv.second; } - provinces.clear(); } Province* Zone::CreateProvince(ZoneRegion* region, int h) { - Province* province = new Province; + Province* province = new Province(); province->id = this->provinces.size(); province->zone = this; province->h = h; - province->biome = -1; province->AddRegion(region); this->provinces.insert(std::make_pair(province->id, province)); @@ -577,15 +575,11 @@ MapBuilder::MapBuilder(ARegionArray* aregs) { for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (!((x + y) % 2)) { - ZoneRegion *reg = new ZoneRegion; + ZoneRegion *reg = new ZoneRegion(); reg->id = GetRegionIndex(x, y, this->w, this->h); reg->location.x = x; reg->location.y = y; - reg->zone = NULL; - reg->exclude = false; - reg->province = NULL; reg->region = aregs->GetRegion(x, y); - reg->biome = -1; if (reg->location.x != reg->region->xloc || reg->location.y != reg->region->yloc) { logger::write("Region location do not match"); @@ -610,7 +604,7 @@ MapBuilder::MapBuilder(ARegionArray* aregs) { } Zone* MapBuilder::CreateZone(ZoneType type) { - Zone* zone = new Zone; + Zone* zone = new Zone(); zone->id = this->lastZoneId++; zone->type = type; diff --git a/object.cpp b/object.cpp index a498b2e9..fec1453c 100644 --- a/object.cpp +++ b/object.cpp @@ -117,7 +117,7 @@ void Object::Readin(std::istream& f, std::list& facs) int i; f >> i; for (int j = 0; j < i; j++) { - Unit *temp = new Unit; + Unit *temp = new Unit(); temp->Readin(f, facs); if (!temp->faction) continue; temp->MoveUnit(this); diff --git a/orders.cpp b/orders.cpp index 208ba316..6f60710a 100644 --- a/orders.cpp +++ b/orders.cpp @@ -1,5 +1,6 @@ #include "orders.h" #include "unit.h" +#include "gamedata.h" const std::vector OrderStrs = { "#atlantis", @@ -80,18 +81,9 @@ int Parse1Order(const parser::token& token) return -1; } -Order::Order() +Order::Order(int type, int quiet) + : type(type), quiet(quiet) { - type = NORDERS; - quiet = 0; -} - -Order::~Order() {} - -ExchangeOrder::ExchangeOrder() -{ - type = O_EXCHANGE; - exchangeStatus = -1; } ExchangeOrder::~ExchangeOrder() @@ -99,183 +91,87 @@ ExchangeOrder::~ExchangeOrder() if (target) delete target; } -TurnOrder::TurnOrder() -{ - type = O_TURN; - repeating = 0; -} - -TurnOrder::~TurnOrder() {} - -MoveOrder::MoveOrder() { type = O_MOVE; } - MoveOrder::~MoveOrder() { std::for_each(dirs.begin(), dirs.end(), [](MoveDir *dir) { delete dir; }); } -ForgetOrder::ForgetOrder() { type = O_FORGET; } - -ForgetOrder::~ForgetOrder() {} - -WithdrawOrder::WithdrawOrder() { type = O_WITHDRAW; } - -WithdrawOrder::~WithdrawOrder() {} - -GiveOrder::GiveOrder() -{ - type = O_GIVE; - unfinished = 0; - merge = 0; -} - GiveOrder::~GiveOrder() { if (target) delete target; } -StudyOrder::StudyOrder() { type = O_STUDY; } - -StudyOrder::~StudyOrder() {} - -TeachOrder::TeachOrder() { type = O_TEACH; } - TeachOrder::~TeachOrder() { std::for_each(targets.begin(), targets.end(), [](UnitId *id) { delete id; }); } -ProduceOrder::ProduceOrder() { type = O_PRODUCE; } - -ProduceOrder::~ProduceOrder() {} - -BuyOrder::BuyOrder() { type = O_BUY; } - -BuyOrder::~BuyOrder() {} - -SellOrder::SellOrder() { type = O_SELL; } - -SellOrder::~SellOrder() {} - -AttackOrder::AttackOrder() { type = O_ATTACK; } - AttackOrder::~AttackOrder() { std::for_each(targets.begin(), targets.end(), [](UnitId *id) { delete id; }); } -BuildOrder::BuildOrder() -{ - type = O_BUILD; - new_building = -1; - until_complete = false; - target = nullptr; - needtocomplete = 0; -} - BuildOrder::~BuildOrder() { if (target) delete target; } -SailOrder::SailOrder() { type = O_SAIL; } - SailOrder::~SailOrder() { std::for_each(dirs.begin(), dirs.end(), [](MoveDir *dir) { delete dir; }); } -FindOrder::FindOrder() { type = O_FIND; } - -FindOrder::~FindOrder() {} - -StealthOrder::StealthOrder() {} - -StealthOrder::~StealthOrder() {} - -StealOrder::StealOrder() +StealthOrder::StealthOrder(int type, UnitId *target) + : Order(type), target(target) { - type = O_STEAL; - target = nullptr; } -StealOrder::~StealOrder() -{ +StealthOrder::~StealthOrder() { if (target) delete target; } -AssassinateOrder::AssassinateOrder() { type = O_ASSASSINATE; } - -AssassinateOrder::~AssassinateOrder() -{ - if (target) delete target; +CastMindOrder::CastMindOrder(int level, UnitId *id) + : CastOrder(S_MIND_READING, level), id(id) { } -CastOrder::CastOrder() { type = O_CAST; } - -CastOrder::~CastOrder() {} - -CastMindOrder::CastMindOrder() { id = nullptr; } - CastMindOrder::~CastMindOrder() { if (id) delete id; } -TeleportOrder::TeleportOrder() {} +TeleportOrder::TeleportOrder(int spell, int level, int x, int y, int z) + : CastRegionOrder(spell, level, x, y, z), gate(0) { +} TeleportOrder::~TeleportOrder() { std::for_each(units.begin(), units.end(), [](UnitId *id) { delete id; }); } -CastRegionOrder::CastRegionOrder() {} - -CastRegionOrder::~CastRegionOrder() {} - -CastIntOrder::CastIntOrder() {} - -CastIntOrder::~CastIntOrder() {} - -CastUnitsOrder::CastUnitsOrder() {} +CastUnitsOrder::CastUnitsOrder(int level) + : CastOrder(S_INVISIBILITY, level) { +} CastUnitsOrder::~CastUnitsOrder() { std::for_each(units.begin(), units.end(), [](UnitId *id) { delete id; }); } -EvictOrder::EvictOrder() { type = O_EVICT; } - EvictOrder::~EvictOrder() { std::for_each(targets.begin(), targets.end(), [](UnitId *id) { delete id; }); } -IdleOrder::IdleOrder() { type = O_IDLE; } - -IdleOrder::~IdleOrder() {} - -TransportOrder::TransportOrder() -{ - type = O_TRANSPORT; - item = -1; - amount = 0; - except = 0; - target = NULL; -} - TransportOrder::~TransportOrder() { if (target) delete target; } -CastTransmuteOrder::CastTransmuteOrder() {} - -CastTransmuteOrder::~CastTransmuteOrder() {} - -JoinOrder::JoinOrder() { type = O_JOIN; } - JoinOrder::~JoinOrder() { if (target) delete target; } -AnnihilateOrder::AnnihilateOrder() { type = O_ANNIHILATE; } - -AnnihilateOrder::~AnnihilateOrder() {} +CastTransmuteOrder::CastTransmuteOrder(int level, int item, int number) + : CastOrder(S_TRANSMUTATION, level), item(item), number(number) { +} -SacrificeOrder::SacrificeOrder() { type = O_SACRIFICE; } +CastRegionOrder::CastRegionOrder(int spell, int level, int x, int y, int z) + : CastOrder(spell, level), xloc(x), yloc(y), zloc(z) { +} -SacrificeOrder::~SacrificeOrder() {} +CastIntOrder::CastIntOrder(int spell, int level, int target) + : CastOrder(spell, level), target(target) { +} diff --git a/orders.h b/orders.h index 7f52a09a..43be0c69 100644 --- a/orders.h +++ b/orders.h @@ -101,84 +101,88 @@ int Parse1Order(const parser::token& token); class Order { public: - Order(); - virtual ~Order(); + Order(int type = 0, int quiet = 0); + virtual ~Order() = default; int type; int quiet; }; -class MoveDir { - public: - int dir; +struct MoveDir { + int dir = 0; }; class MoveOrder : public Order { public: - MoveOrder(); - ~MoveOrder(); + MoveOrder(bool advance = false) : Order(O_MOVE), advancing(advance) {} + virtual ~MoveOrder(); - int advancing; + bool advancing; std::list dirs; }; class WithdrawOrder : public Order { public: - WithdrawOrder(); - ~WithdrawOrder(); + WithdrawOrder(int item, int amount) + : Order(O_WITHDRAW), item(item), amount(amount) {}; + virtual ~WithdrawOrder() = default; - int item; - int amount; + int item = 0; + int amount = 0; }; class GiveOrder : public Order { public: - GiveOrder(); - ~GiveOrder(); + GiveOrder(int type = O_GIVE) : Order(type) {} + virtual ~GiveOrder(); - int item; + int item = 0; /* if amount == -1, transfer whole unit, -2 means all of item */ - int amount; - int except; - int unfinished; - int merge; + int amount = 0; + int except = 0; + int unfinished = 0; + int merge = 0; - UnitId *target; + UnitId *target = nullptr; }; class StudyOrder : public Order { public: - StudyOrder(); - ~StudyOrder(); + StudyOrder(int skill) + : Order(O_STUDY), skill(skill) {} + virtual ~StudyOrder() = default; int skill; - int days; - int level; + int days = 0; + int level = -1; }; class TeachOrder : public Order { public: - TeachOrder(); - ~TeachOrder(); + TeachOrder() : Order(O_TEACH) {} + virtual ~TeachOrder(); std::list targets; }; class ProduceOrder : public Order { public: - ProduceOrder(); - ~ProduceOrder(); + ProduceOrder(int item, int skill, int target, int quiet = 0) + : Order(O_PRODUCE, quiet), item(item), skill(skill), target(target) { + } + virtual ~ProduceOrder() = default; int item; int skill; /* -1 for none */ - int productivity; int target; + int productivity = 0; }; class BuyOrder : public Order { public: - BuyOrder(); - ~BuyOrder(); + BuyOrder(int item, int num = 0, bool repeating = false) + : Order(O_BUY), item(item), num(num), repeating(repeating) { + } int item; int num; @@ -187,8 +191,9 @@ class BuyOrder : public Order { class SellOrder : public Order { public: - SellOrder(); - ~SellOrder(); + SellOrder(int item, int num = 0, bool repeating = false) + : Order(O_SELL), item(item), num(num), repeating(repeating) { + } int item; int num; @@ -197,65 +202,67 @@ class SellOrder : public Order { class AttackOrder : public Order { public: - AttackOrder(); - ~AttackOrder(); + AttackOrder() : Order(O_ATTACK) {} + virtual ~AttackOrder(); std::list targets; }; class BuildOrder : public Order { public: - BuildOrder(); - ~BuildOrder(); + BuildOrder(UnitId *target = nullptr) : Order(O_BUILD), target(target), needtocomplete(0) {} + BuildOrder(int needtocomplete) : Order(O_BUILD), target(nullptr), needtocomplete(needtocomplete) {} + virtual ~BuildOrder(); UnitId *target; - int new_building; + int new_building = -1; int needtocomplete; - bool until_complete; + bool until_complete = false; }; class SailOrder : public Order { public: - SailOrder(); - ~SailOrder(); + SailOrder() : Order(O_SAIL) {} + virtual ~SailOrder(); std::list dirs; }; class FindOrder : public Order { public: - FindOrder(); - ~FindOrder(); + FindOrder(int find) : Order(O_FIND), find(find) {} + virtual ~FindOrder() = default; int find; }; class StealthOrder : public Order { public: - StealthOrder(); - ~StealthOrder(); + StealthOrder(int type = 0, UnitId *target = nullptr); + virtual ~StealthOrder(); UnitId *target; }; class StealOrder : public StealthOrder { public: - StealOrder(); - ~StealOrder(); + StealOrder(UnitId *target, int item) + : StealthOrder(O_STEAL, target), item(item) {} + virtual ~StealOrder() = default; int item; }; class AssassinateOrder : public StealthOrder { public: - AssassinateOrder(); - ~AssassinateOrder(); + AssassinateOrder(UnitId * target = nullptr) : StealthOrder(O_ASSASSINATE, target) {} + virtual ~AssassinateOrder() = default; }; class ForgetOrder : public Order { public: - ForgetOrder(); - ~ForgetOrder(); + ForgetOrder(int skill) : Order(O_FORGET), skill(skill) {} + virtual ~ForgetOrder() = default; int skill; }; @@ -263,31 +270,32 @@ class ForgetOrder : public Order { // Add class for exchange class ExchangeOrder : public Order { public: - ExchangeOrder(); - ~ExchangeOrder(); + ExchangeOrder(UnitId *target = nullptr) : Order(O_EXCHANGE), target(target) {}; + virtual ~ExchangeOrder(); - int giveItem; - int giveAmount; - int expectItem; - int expectAmount; + int giveItem = 0; + int giveAmount = 0; + int expectItem = 0; + int expectAmount = 0; - int exchangeStatus; + int exchangeStatus = -1; UnitId *target; }; class TurnOrder : public Order { public: - TurnOrder(); - ~TurnOrder(); + TurnOrder(bool repeating = false) : Order(O_TURN), repeating(repeating) {}; + virtual ~TurnOrder() = default; + bool repeating; std::vector turnOrders; }; class CastOrder : public Order { public: - CastOrder(); - ~CastOrder(); + CastOrder(int spell, int level) : Order(O_CAST), spell(spell), level(level) {}; + virtual ~CastOrder() = default; int spell; int level; @@ -295,24 +303,24 @@ class CastOrder : public Order { class CastMindOrder : public CastOrder { public: - CastMindOrder(); - ~CastMindOrder(); + CastMindOrder(int level, UnitId *id = nullptr); + virtual ~CastMindOrder(); UnitId *id; }; class CastRegionOrder : public CastOrder { public: - CastRegionOrder(); - ~CastRegionOrder(); + CastRegionOrder(int spell, int level, int x = 0, int y = 0, int z = 0); + virtual ~CastRegionOrder() = default; int xloc, yloc, zloc; }; class TeleportOrder : public CastRegionOrder { public: - TeleportOrder(); - ~TeleportOrder(); + TeleportOrder(int spell, int level, int x = 0, int y = 0, int z = 0); + virtual ~TeleportOrder(); int gate; std::list units; @@ -320,24 +328,24 @@ class TeleportOrder : public CastRegionOrder { class CastIntOrder : public CastOrder { public: - CastIntOrder(); - ~CastIntOrder(); + CastIntOrder(int spell, int level, int target); + virtual ~CastIntOrder() = default; int target; }; class CastUnitsOrder : public CastOrder { public: - CastUnitsOrder(); - ~CastUnitsOrder(); + CastUnitsOrder(int level); + virtual ~CastUnitsOrder(); std::list units; }; class CastTransmuteOrder : public CastOrder { public: - CastTransmuteOrder(); - ~CastTransmuteOrder(); + CastTransmuteOrder(int level, int item, int number); + virtual ~CastTransmuteOrder() = default; int item; int number; @@ -345,62 +353,69 @@ class CastTransmuteOrder : public CastOrder { class EvictOrder : public Order { public: - EvictOrder(); - ~EvictOrder(); + EvictOrder() : Order(O_EVICT) {}; + virtual ~EvictOrder(); std::list targets; }; class IdleOrder : public Order { public: - IdleOrder(); - ~IdleOrder(); + IdleOrder() : Order(O_IDLE) {}; + virtual ~IdleOrder() = default; }; class TransportOrder : public Order { public: - TransportOrder(); - ~TransportOrder(); + TransportOrder(int item, int amount, int except, UnitId *target = nullptr) + : Order(O_TRANSPORT), item(item), amount(amount), except(except), target(target) + { + }; + virtual ~TransportOrder(); int item; // amount == -1 means all available at transport time // any other amount is also checked at transport time int amount; int except; - int distance; + int distance = 0; enum class TransportPhase { + UNDEFINED, SHIP_TO_QM, INTER_QM_TRANSPORT, DISTRIBUTE_FROM_QM }; - TransportPhase phase; + TransportPhase phase = TransportPhase::UNDEFINED; UnitId *target; }; class JoinOrder : public Order { public: - JoinOrder(); - ~JoinOrder(); + JoinOrder(int overload, int merge, UnitId *target = nullptr) + : Order(O_JOIN), overload(overload), merge(merge), target(target) {}; + virtual ~JoinOrder(); - UnitId *target; int overload; int merge; + UnitId *target; }; class AnnihilateOrder : public Order { public: - AnnihilateOrder(); - ~AnnihilateOrder(); + AnnihilateOrder(int x, int y, int z) + : Order(O_ANNIHILATE), xloc(x), yloc(y), zloc(z) {}; + virtual ~AnnihilateOrder() = default; int xloc, yloc, zloc; }; class SacrificeOrder : public Order { public: - SacrificeOrder(); - ~SacrificeOrder(); + SacrificeOrder(int item = 0, int amount = 0) + : Order(O_SACRIFICE), item(item), amount(amount) {}; + virtual ~SacrificeOrder() = default; int item; int amount; diff --git a/parseorders.cpp b/parseorders.cpp index ead34245..1472dc1c 100644 --- a/parseorders.cpp +++ b/parseorders.cpp @@ -39,11 +39,7 @@ UnitId *Game::parse_unit(parser::string_parser& parser) if (!token) return nullptr; if (token == "0") { - UnitId *id = new UnitId; - id->unitnum = -1; - id->alias = 0; - id->faction = 0; - return id; + return new UnitId(-1, 0, 0); } if (token == "faction") { @@ -56,32 +52,20 @@ UnitId *Game::parse_unit(parser::string_parser& parser) if (!unit_alias) return nullptr; /* Return UnitId */ - UnitId *id = new UnitId; - id->unitnum = 0; - id->alias = unit_alias; - id->faction = faction_id; - return id; + return new UnitId(0, unit_alias, faction_id); } if (token == "new") { int unit_alias = parser.get_token().get_number().value_or(0); if (!unit_alias) return nullptr; - UnitId *id = new UnitId; - id->unitnum = 0; - id->alias = unit_alias; - id->faction = 0; - return id; + return new UnitId(0, unit_alias, 0); } int unit_id = token.get_number().value_or(0); if (!unit_id) return nullptr; - UnitId *id = new UnitId; - id->unitnum = unit_id; - id->alias = 0; - id->faction = 0; - return id; + return new UnitId(unit_id, 0, 0); } int parse_faction_type(parser::string_parser& parser, std::unordered_map &type) @@ -805,8 +789,7 @@ void Game::ProcessForgetOrder(Unit *u, parser::string_parser& parser, orders_che if (checker) return; - ForgetOrder *ord = new ForgetOrder; - ord->skill = sk; + ForgetOrder *ord = new ForgetOrder(sk); u->forgetorders.push_back(ord); } @@ -822,10 +805,7 @@ void Game::ProcessEntertainOrder(Unit *unit, orders_check *checker) if (Globals->TAX_PILLAGE_MONTH_LONG) unit->taxing = TAX_NONE; - ProduceOrder *order = new ProduceOrder; - order->item = I_SILVER; - order->skill = S_ENTERTAINMENT; - order->target = 0; + ProduceOrder *order = new ProduceOrder(I_SILVER, S_ENTERTAINMENT, 0); unit->monthorders = order; } @@ -1132,9 +1112,7 @@ void Game::ProcessAssassinateOrder(Unit *u, parser::string_parser& parser, order } if (u->stealthorders) delete u->stealthorders; - AssassinateOrder *ord = new AssassinateOrder; - ord->target = id; - u->stealthorders = ord; + u->stealthorders = new AssassinateOrder(id); } void Game::ProcessStealOrder(Unit *u, parser::string_parser& parser, orders_check *checker) @@ -1172,11 +1150,8 @@ void Game::ProcessStealOrder(Unit *u, parser::string_parser& parser, orders_chec return; } - StealOrder *ord = new StealOrder; - ord->target = id; - ord->item = i; if (u->stealthorders) delete u->stealthorders; - u->stealthorders = ord; + u->stealthorders = new StealOrder(id, i); } void Game::ProcessQuitOrder(Unit *u, parser::string_parser& parser, orders_check *checker) @@ -1238,8 +1213,7 @@ void Game::ProcessFindOrder(Unit *u, parser::string_parser& parser, orders_check } if (!checker) { - FindOrder *f = new FindOrder; - f->find = n; + FindOrder *f = new FindOrder(n); u->findorders.push_back(f); } } @@ -1382,7 +1356,7 @@ void Game::ProcessEnterOrder(Unit *u, parser::string_parser& parser, orders_chec BuildOrder* Game::ProcessBuildHelp(Unit *unit, parser::string_parser& parser, orders_check *checker) { - if (checker) return new BuildOrder; + if (checker) return new BuildOrder(); UnitId *target = parse_unit(parser); if (!target || target->unitnum == -1) { @@ -1391,9 +1365,7 @@ BuildOrder* Game::ProcessBuildHelp(Unit *unit, parser::string_parser& parser, or return nullptr; } - BuildOrder *order = new BuildOrder; - order->target = target; - return order; + return new BuildOrder(target); } BuildOrder* Game::ProcessBuildShip(Unit *unit, int object_type) @@ -1414,9 +1386,8 @@ BuildOrder* Game::ProcessBuildShip(Unit *unit, int object_type) // If we already have an unfinished ship, see how much work is left if (unit->items.GetNum(shipType) > 0) maxbuild = unit->items.GetNum(shipType); - BuildOrder* order = new BuildOrder; // Set needtocomplete if we have a maxbuild value - if (maxbuild != 0) order->needtocomplete = maxbuild; + BuildOrder* order = new BuildOrder(maxbuild); return order; } @@ -1434,7 +1405,7 @@ BuildOrder* Game::ProcessBuildStructure(Unit *unit, int object_type) return nullptr; } - BuildOrder* order = new BuildOrder; + BuildOrder* order = new BuildOrder(); order->new_building = object_type; return order; } @@ -1447,7 +1418,7 @@ BuildOrder *Game::ProcessBuildObject(Unit *unit, int object_type, orders_check * } // If we get here, we can just treat it as a valid order and bail early. - if (checker) return new BuildOrder; + if (checker) return new BuildOrder(); ARegion *region = unit->object->region; if (TerrainDefs[region->type].similar_type == R_OCEAN) { @@ -1465,7 +1436,7 @@ BuildOrder *Game::ProcessBuildObject(Unit *unit, int object_type, orders_check * BuildOrder *Game::ProcessContinuedBuild(Unit *unit, orders_check *checker) { - if(checker) return new BuildOrder; + if (checker) return new BuildOrder(); int maxbuild = 0; // Look for an incomplete ship in inventory @@ -1485,9 +1456,8 @@ BuildOrder *Game::ProcessContinuedBuild(Unit *unit, orders_check *checker) maxbuild = unit->items.GetNum(-ship_type); } - BuildOrder *order = new BuildOrder; // Set needtocomplete if we have a maxbuild value - if (maxbuild != 0) order->needtocomplete = maxbuild; + BuildOrder *order = new BuildOrder(maxbuild); return order; } @@ -1546,7 +1516,7 @@ void Game::ProcessAttackOrder(Unit *u, parser::string_parser& parser, orders_che // Process all target units listed in the order while (target && target->unitnum != -1) { // Create attack orders structure if this is the first target - if (!u->attackorders) u->attackorders = new AttackOrder; + if (!u->attackorders) u->attackorders = new AttackOrder(); u->attackorders->targets.push_back(target); target = parse_unit(parser); } @@ -1591,10 +1561,7 @@ void Game::ProcessSellOrder(Unit *u, parser::string_parser& parser, orders_check } // we didn't find one above, so make a new one. - SellOrder *s = new SellOrder; - s->item = it; - s->num = num; - s->repeating = repeating; + SellOrder *s = new SellOrder(it, num, repeating); u->sellorders.push_back(s); } @@ -1636,10 +1603,7 @@ void Game::ProcessBuyOrder(Unit *u, parser::string_parser& parser, orders_check } // we didn't find one above, so make a new one. - BuyOrder *b = new BuyOrder; - b->item = it; - b->num = num; - b->repeating = repeating; + BuyOrder *b = new BuyOrder(it, num, repeating); u->buyorders.push_back(b); } @@ -1668,10 +1632,7 @@ void Game::ProcessProduceOrder(Unit *u, parser::string_parser& parser, orders_ch return; } - ProduceOrder *p = new ProduceOrder; - p->item = it; - p->skill = lookup_skill(item_def.pSkill); - p->target = target; + ProduceOrder *p = new ProduceOrder(it, lookup_skill(item_def.pSkill), target); bool monthtaxing = (Globals->TAX_PILLAGE_MONTH_LONG && (u->taxing == TAX_TAX || u->taxing == TAX_PILLAGE)); if (u->monthorders || monthtaxing) { @@ -1685,11 +1646,7 @@ void Game::ProcessProduceOrder(Unit *u, parser::string_parser& parser, orders_ch void Game::ProcessWorkOrder(Unit *u, int quiet, orders_check *checker) { - ProduceOrder *order = new ProduceOrder; - order->skill = -1; - order->item = I_SILVER; - order->target = 0; - if (quiet) order->quiet = 1; + ProduceOrder *order = new ProduceOrder(I_SILVER, -1, 0, quiet); bool monthtaxing = (Globals->TAX_PILLAGE_MONTH_LONG && (u->taxing == TAX_TAX || u->taxing == TAX_PILLAGE)); if (u->monthorders || monthtaxing) { @@ -1707,7 +1664,7 @@ void Game::ProcessTeachOrder(Unit *u, parser::string_parser& parser, orders_chec // Reuse existing teach order if one exists if (u->monthorders && u->monthorders->type == O_TEACH) order = dynamic_cast(u->monthorders); - else order = new TeachOrder; + else order = new TeachOrder(); // Parse all student units int students = 0; @@ -1752,9 +1709,7 @@ void Game::ProcessStudyOrder(Unit *u, parser::string_parser& parser, orders_chec return; } - StudyOrder *order = new StudyOrder; - order->skill = sk; - order->days = 0; + StudyOrder *order = new StudyOrder(sk); // Parse study level if provided order->level = parser.get_token().get_number().value_or(-1); @@ -1859,9 +1814,7 @@ void Game::ProcessWithdrawOrder(Unit *unit, parser::string_parser& parser, order if (checker) return; - WithdrawOrder *order = new WithdrawOrder; - order->item = item; - order->amount = amt; + WithdrawOrder *order = new WithdrawOrder(item, amt); unit->withdraworders.push_back(order); } @@ -1870,8 +1823,7 @@ std::string Game::ProcessTurnOrder(Unit *unit, std::istream& f, orders_check *ch int turnDepth = 1; int turnLast = 1; int formDepth = 0; - TurnOrder *tOrder = new TurnOrder; - tOrder->repeating = repeat; + TurnOrder *tOrder = new TurnOrder(repeat); parser::string_parser order; @@ -2026,12 +1978,11 @@ void Game::ProcessExchangeOrder(Unit *unit, parser::string_parser& parser, order if (checker) return; - ExchangeOrder *order = new ExchangeOrder; + ExchangeOrder *order = new ExchangeOrder(t); order->giveItem = itemGive; order->giveAmount = amtGive; order->expectAmount = amtExpected; order->expectItem = itemExpected; - order->target = t; unit->exchangeorders.push_back(order); } @@ -2161,8 +2112,7 @@ void Game::ProcessGiveOrder(int order, Unit *unit, parser::string_parser& parser } // Create the order - GiveOrder *go = new GiveOrder; - go->type = order; + GiveOrder *go = new GiveOrder(order); go->item = item; go->target = t; go->amount = amt; @@ -2500,7 +2450,7 @@ Unit *Game::ProcessFormOrder(Unit *former, parser::string_parser& parser, orders } if (checker) { - Unit *unit = new Unit; + Unit *unit = new Unit(); unit->former = former; former->form_repeated = repeating; return unit; @@ -2543,11 +2493,11 @@ void Game::ProcessAdvanceOrder(Unit *u, parser::string_parser& parser, orders_ch if (Globals->TAX_PILLAGE_MONTH_LONG) u->taxing = TAX_NONE; - if (!u->monthorders) u->monthorders = new MoveOrder; + if (!u->monthorders) u->monthorders = new MoveOrder(); u->monthorders->type = O_ADVANCE; MoveOrder *m = dynamic_cast(u->monthorders); - m->advancing = 1; + m->advancing = true; while(parser::token token = parser.get_token()) { int d = parse_dir(token); @@ -2556,8 +2506,7 @@ void Game::ProcessAdvanceOrder(Unit *u, parser::string_parser& parser, orders_ch return; } if (checker) continue; - MoveDir *x = new MoveDir; - x->dir = d; + MoveDir *x = new MoveDir{ d }; m->dirs.push_back(x); } } @@ -2573,10 +2522,10 @@ void Game::ProcessMoveOrder(Unit *u, parser::string_parser& parser, orders_check if (Globals->TAX_PILLAGE_MONTH_LONG) u->taxing = TAX_NONE; - if (!u->monthorders) u->monthorders = new MoveOrder; + if (!u->monthorders) u->monthorders = new MoveOrder(); MoveOrder *m = dynamic_cast(u->monthorders); - m->advancing = 0; + m->advancing = false; while (parser::token token = parser.get_token()) { int d = parse_dir(token); @@ -2585,8 +2534,7 @@ void Game::ProcessMoveOrder(Unit *u, parser::string_parser& parser, orders_check return; } if (checker) continue; - MoveDir *x = new MoveDir; - x->dir = d; + MoveDir *x = new MoveDir{ d }; m->dirs.push_back(x); } } @@ -2601,7 +2549,7 @@ void Game::ProcessSailOrder(Unit *u, parser::string_parser& parser, orders_check } if (Globals->TAX_PILLAGE_MONTH_LONG) u->taxing = TAX_NONE; - if (!u->monthorders) u->monthorders = new SailOrder; + if (!u->monthorders) u->monthorders = new SailOrder(); SailOrder* m = dynamic_cast(u->monthorders); @@ -2612,8 +2560,7 @@ void Game::ProcessSailOrder(Unit *u, parser::string_parser& parser, orders_check return; } if (checker) continue; - MoveDir *x = new MoveDir; - x->dir = d; + MoveDir *x = new MoveDir{ d }; m->dirs.push_back(x); } } @@ -2624,7 +2571,7 @@ void Game::ProcessEvictOrder(Unit *u, parser::string_parser& parser, orders_chec UnitId *id = parse_unit(parser); while (id && id->unitnum != -1) { - if (!u->evictorders) u->evictorders = new EvictOrder; + if (!u->evictorders) u->evictorders = new EvictOrder(); u->evictorders->targets.push_back(id); id = parse_unit(parser); } @@ -2640,7 +2587,7 @@ void Game::ProcessIdleOrder(Unit *u, orders_check *checker) overwrite_month_warning("IDLE", u, checker); } if (Globals->TAX_PILLAGE_MONTH_LONG) u->taxing = TAX_NONE; - IdleOrder *i = new IdleOrder; + IdleOrder *i = new IdleOrder(); u->monthorders = i; } @@ -2707,13 +2654,9 @@ void Game::ProcessTransportOrder(Unit *u, parser::string_parser& parser, orders_ return; } - TransportOrder *order = new TransportOrder; - // At this point we don't know that transport phase for the order but + TransportOrder *order = new TransportOrder(item, amt, except, tar); + // At this point we don't know the transport phase for the order but // we will set that later. - order->item = item; - order->target = tar; - order->amount = amt; - order->except = except; u->transportorders.push_back(order); } @@ -2752,10 +2695,7 @@ void Game::ProcessJoinOrder(Unit *u, parser::string_parser& parser, orders_check if (token == "nooverload") overload = 0; if (token == "merge") merge = 1; - JoinOrder *ord = new JoinOrder; - ord->target = id; - ord->overload = overload; - ord->merge = merge; + JoinOrder *ord = new JoinOrder(overload, merge, id); if (u->joinorders) delete u->joinorders; u->joinorders = ord; } @@ -2796,9 +2736,7 @@ void Game::ProcessSacrificeOrder(Unit *unit, parser::string_parser& parser, orde if (checker) return; - SacrificeOrder *order = new SacrificeOrder; - order->item = item; - order->amount = amt; + SacrificeOrder *order = new SacrificeOrder(item, amt); if (unit->sacrificeorders) delete unit->sacrificeorders; unit->sacrificeorders = order; } @@ -2865,9 +2803,6 @@ void Game::ProcessAnnihilateOrder(Unit *unit, parser::string_parser& parser, ord if (checker) return; - AnnihilateOrder *order = new AnnihilateOrder; - order->xloc = x; - order->yloc = y; - order->zloc = z; + AnnihilateOrder *order = new AnnihilateOrder(x, y, z); unit->annihilateorders.push_back(order); } diff --git a/production.cpp b/production.cpp index 9a156584..291a3809 100644 --- a/production.cpp +++ b/production.cpp @@ -5,23 +5,11 @@ #include "gamedata.h" #include "rng.hpp" -Production::Production() +Production::Production(int it, int amt) + : itemtype(it), baseamount(amt), amount(amt), productivity(10) { - itemtype = -1; - amount = 0; - baseamount = 0; - productivity = 0; - skill = -1; -} - -Production::Production(int it, int maxamt) -{ - itemtype = it; - amount = maxamt; if (Globals->RANDOM_ECONOMY) - amount += rng::get_random(maxamt); - baseamount = amount; - productivity = 10; + amount += rng::get_random(amt); skill = lookup_skill(ItemDefs[it].pSkill); } diff --git a/production.h b/production.h index bf839d20..7f2b42f4 100644 --- a/production.h +++ b/production.h @@ -29,19 +29,19 @@ class Production { public: - Production(int type, int max); - Production(); + Production(int type, int amount); + Production() {}; void write_out(std::ostream& f); void read_in(std::istream& f); std::string write_report(); - int itemtype; - int baseamount; - int amount; - int skill; - int productivity; - int activity; + int itemtype = -1; + int baseamount = 0; + int amount = 0; + int skill = -1; + int productivity = 0; + int activity = 0; }; #endif diff --git a/runorders.cpp b/runorders.cpp index 0b76b9fe..66a8f547 100644 --- a/runorders.cpp +++ b/runorders.cpp @@ -942,18 +942,15 @@ void Game::Do1JoinOrder(ARegion *r, Unit *u) // DoGiveOrder can modify the item list if the last of an item is given, so increment here. it++; GiveOrder go; - UnitId id; go.amount = item->num; go.except = 0; go.item = item->type; - id.unitnum = to->GetOwner()->num; - id.alias = 0; - id.faction = 0; + UnitId id(to->GetOwner()->num, 0, 0); go.target = &id; go.type = O_GIVE; go.merge = 1; DoGiveOrder(r, u, &go); - go.target = NULL; + go.target = nullptr; } for(const auto pass : u->object->units) { pass->MoveUnit(to); @@ -1496,9 +1493,7 @@ void Game::DoBuy(ARegion *r, Market *m) } if (ItemDefs[o->item].type & IT_MAN) { /* recruiting; must dilute skills */ - SkillList *sl = new SkillList; u->AdjustSkills(); - delete sl; /* Setup specialized skill experience */ if (Globals->REQUIRED_EXPERIENCE) { auto mt = find_race(ItemDefs[o->item].abr)->get(); @@ -3265,10 +3260,9 @@ void Game::RunAnnihilateOrders() { AnnihilateOrder *o = u->annihilateorders.front(); u->annihilateorders.pop_front(); - TurnOrder *tOrder = new TurnOrder; + TurnOrder *tOrder = new TurnOrder(); std::string order = "ANNIHILATE " + std::to_string(o->xloc) + " " + std::to_string(o->yloc) + " " + std::to_string(o->zloc); - tOrder->repeating = 0; tOrder->turnOrders.push_back(order); u->turnorders.push_front(tOrder); } diff --git a/skills.cpp b/skills.cpp index 25f1fdf7..4dd9b7a4 100644 --- a/skills.cpp +++ b/skills.cpp @@ -225,12 +225,9 @@ void Skill::Writeout(std::ostream& f) const Skill *Skill::Split(int total, int leave) { - Skill *temp = new Skill; - temp->type = type; - temp->days = (days * leave) / total; - days = days - temp->days; - temp->exp = (exp * leave) / total; - exp = exp - temp->exp; + Skill *temp = new Skill{ type, (days * leave) / total, (exp * leave) / total }; + days -= temp->days; + exp -= temp->exp; return temp; } @@ -244,7 +241,7 @@ int SkillList::GetDays(int skill) return 0; } -void SkillList::SetDays(int skill, int days) +void SkillList::SetDays(int skill, unsigned int days) { for(const auto s: skills) { if (s->type == skill) { @@ -259,10 +256,7 @@ void SkillList::SetDays(int skill, int days) } } if (days == 0) return; - Skill *s = new Skill; - s->type = skill; - s->days = days; - s->exp = 0; + Skill *s = new Skill{ skill, days, 0 }; skills.push_back(s); } @@ -276,7 +270,7 @@ int SkillList::GetExp(int skill) return 0; } -void SkillList::SetExp(int skill, int exp) +void SkillList::SetExp(int skill, unsigned int exp) { for(const auto s: skills) { if (s->type == skill) { @@ -285,16 +279,13 @@ void SkillList::SetExp(int skill, int exp) } } if (exp == 0) return; - Skill *s = new Skill; - s->type = skill; - s->days = 0; - s->exp = exp; + Skill *s = new Skill{ skill, 0, exp }; skills.push_back(s); } SkillList *SkillList::Split(int total, int leave) { - SkillList *ret = new SkillList; + SkillList *ret = new SkillList(); for(auto siter = skills.begin(); siter != skills.end();) { Skill *s = *siter; Skill *n = s->Split(total, leave); @@ -367,7 +358,7 @@ void SkillList::Readin(std::istream& f) int n; f >> n; for (int i = 0; i < n; i++) { - Skill *s = new Skill; + Skill *s = new Skill(); s->Readin(f); if ((s->days == 0) && (s->exp==0)) delete s; else skills.push_back(s); diff --git a/skills.h b/skills.h index 995bf7c4..8c3f8100 100644 --- a/skills.h +++ b/skills.h @@ -101,9 +101,9 @@ class Skill { void Writeout(std::ostream &f) const; Skill *Split(int total, int split); - int type; - unsigned int days; - unsigned int exp; + int type = -1; + unsigned int days = 0; + unsigned int exp = 0; }; class SkillList { @@ -114,8 +114,8 @@ class SkillList { int GetDays(int sk); int GetExp(int sk); - void SetDays(int sk, int days); - void SetExp(int sk,int exp); + void SetDays(int sk, unsigned int days); + void SetExp(int sk, unsigned int exp); void Combine(SkillList *skl); int GetStudyRate(int sk, int men); SkillList *Split(int total, int split); diff --git a/snapshot-tests/run-game-snapshots.sh b/snapshot-tests/run-game-snapshots.sh index deb22458..17190ff1 100755 --- a/snapshot-tests/run-game-snapshots.sh +++ b/snapshot-tests/run-game-snapshots.sh @@ -1,45 +1,46 @@ #!/bin/bash -game=$1 -if [[ $game = "" || $game = "standard" ]]; then +game="$1" +if [[ "$game" = "" || "$game" = "standard" ]]; then game=standard executable=../standard/standard turndir=turns else - executable=../$game/$game - turndir=${game}_turns + executable="../$game/$game" + turndir="${game}_turns" fi -if [[ ! -f $executable ]]; then +[ -f "${executable}" ] || executable="../build/$game" + +if [[ ! -e "${executable}" ]]; then echo "Please build the $game executable before running the snapshot tests. Test failed." exit 1 fi -cp $executable ./$game -chmod +x ./$game +cp "${executable}" "./${game}" +chmod +x "./$game" -if [[ ! -f $turndir/turn ]]; then +if [[ ! -f "$turndir/turn" ]]; then echo "No turns defined for $game. Test failed." exit 1 fi lastTurn=$(<"$turndir/turn") -for turn in $(seq 0 $lastTurn) +for turn in $(seq 0 "$lastTurn") do echo -n "Replaying $game turn $turn..." - if [[ ! -d $turndir/turn_$turn ]]; then + if [[ ! -d "$turndir/turn_$turn" ]]; then echo "turn $turn missing. -- Test failed." exit 1 fi - cp -f $turndir/turn_$turn/game.in game.in - cp -f $turndir/turn_$turn/players.in players.in - cp -f $turndir/turn_$turn/orders.3 orders.3 + cp -f "$turndir/turn_$turn/game.in" game.in + cp -f "$turndir/turn_$turn/players.in" players.in + cp -f "$turndir/turn_$turn/orders.3" orders.3 - ./$game run &> engine-output.txt - if [[ $? != 0 ]]; then + if ! "./$game" run &> engine-output.txt ; then echo "executable crashed. -- Test failed." cat engine-output.txt rm -f game.* @@ -49,28 +50,27 @@ do rm -f template.* rm -f report.* rm -f engine-output.txt - rm -r ./$game + rm -r "./$game" exit 1 fi - mkdir -p output/turn_$turn - mv game.* output/turn_$turn - mv players.* output/turn_$turn + mkdir -p "output/turn_$turn" + mv game.* "output/turn_$turn" + mv players.* "output/turn_$turn" if [[ $(shopt -s nullglob; set -- times.*; echo $#) -ge 1 ]]; then - mv times.* output/turn_$turn + mv times.* "output/turn_$turn" fi - mv orders.* output/turn_$turn - mv template.* output/turn_$turn - mv report.* output/turn_$turn - mv engine-output.txt output/turn_$turn + mv orders.* "output/turn_$turn" + mv template.* "output/turn_$turn" + mv report.* "output/turn_$turn" + mv engine-output.txt "output/turn_$turn" - diff -ur $turndir/turn_$turn output/turn_$turn &> turn-difference.txt - if [[ $? != 0 ]]; then + if ! diff -ur "$turndir/turn_$turn" "output/turn_$turn" &> turn-difference.txt ; then echo "output differed. -- Test failed." cat turn-difference.txt rm -f turn-difference.txt rm -rf ./output - rm -r ./$game + rm -r "./$game" exit 1 fi @@ -79,5 +79,5 @@ do done rm -rf ./output -rm -r ./$game +rm -r "./$game" exit 0 diff --git a/snapshot-tests/run-rules-snapshot.sh b/snapshot-tests/run-rules-snapshot.sh index aaa6a2c5..e28eee18 100755 --- a/snapshot-tests/run-rules-snapshot.sh +++ b/snapshot-tests/run-rules-snapshot.sh @@ -1,57 +1,56 @@ #!/bin/bash -game=$1 -if [[ $game = "" || $game = "standard" ]]; then +cleanup() +{ + game="$1" + rm -f "${game}" + rm -f "${game}.html" + rm -f "${game}_intro.html" + rm -f "${game}.html.strip" + rm -f rules-difference.txt + rm -f engine-output.txt +} + +game="$1" +if [[ "$game" = "" || "$game" = "standard" ]]; then game=standard executable=../standard/standard else - executable=../$game/$game + executable="../$game/$game" fi -if [[ ! -f $executable ]]; then +[ -f "${executable}" ] || executable="../build/$game" + +if [[ ! -f "${executable}" ]]; then echo "Please build the $game executable before running the rules snapshot tests. Test failed." exit 1 fi -cp $executable ./$game -chmod +x ./$game +cp "$executable" "./$game" +chmod +x "./$game" echo -n "Regenerating $game rules..." -cp ../$game/${game}_intro.html . -./$game genrules ${game}_intro.html ${game}.css ${game}.html &> engine-output.txt -if [[ $? != 0 ]]; then +cp "../$game/${game}_intro.html" . +if ! "./$game" genrules "${game}_intro.html" "${game}.css" "${game}.html" &> engine-output.txt ; then echo "executable crashed. -- Test failed." cat engine-output.txt - rm -f ./engine-output.txt - rm -f ${game}_intro.html - rm -f ${game}.html - rm -f ./${game} + cleanup "${game}" exit 1 fi rm -f ./engine-output.txt # Clean up the Last Change: timestamp line so that comparisons can work -sed -e 's/Last Change:.*$/Last Change: __STRIPPED_FOR_COMPARISON__/' ${game}.html > ${game}.html.strip +sed -e 's/Last Change:.*$/Last Change: __STRIPPED_FOR_COMPARISON__/' "${game}.html" > "${game}.html.strip" -diff -ur rules/${game}.html ${game}.html.strip &> rules-difference.txt -if [[ $? != 0 ]]; then +if ! diff -ur "rules/${game}.html" "${game}.html.strip" &> rules-difference.txt ; then echo "output differed. -- Test failed." cat rules-difference.txt - rm -f rules-difference.txt - rm -f ${game}_intro.html - rm -f ${game}.html - rm -f ${game}.html.strip - rm -f ./${game} + cleanup "${game}" exit 1 fi echo "identical. -- Test succeeded." -rm -f rules-difference.txt -rm -f engine-output.txt -rm -f ${game}.html -rm -f ${game}_intro.html -rm -f ${game}.html.strip -rm -f ./$game +cleanup "${game}" exit 0 diff --git a/spells.cpp b/spells.cpp index 8596fdd0..147927ea 100644 --- a/spells.cpp +++ b/spells.cpp @@ -133,13 +133,8 @@ void Game::ProcessMindReading(Unit *u, parser::string_parser& parser, orders_che return; } - CastMindOrder *order = new CastMindOrder; - order->id = id; - order->spell = S_MIND_READING; - order->level = 1; - u->ClearCastOrders(); - u->castorders = order; + u->castorders = new CastMindOrder(1, id); } void Game::ProcessBirdLore(Unit *u, parser::string_parser& parser, orders_check *checker) @@ -151,39 +146,32 @@ void Game::ProcessBirdLore(Unit *u, parser::string_parser& parser, orders_check return; } - if (token != "eagle" && token != "direction") { - parse_error(checker, u, 0, "CAST '" + skdef.name + "': Invalid argument '" + token.get_string() + "'."); - return; + int level = 0, target = -1; + if (token == "eagle") { + level = 3; } - - int dir = -1; - if (token == "direction") { + else if (token == "direction") { + level = 1; parser::token dir_tkn = parser.get_token(); if (!dir_tkn) { parse_error(checker, u, 0, "CAST '" + skdef.name + "': Missing direction."); return; } - dir = parse_dir(dir_tkn); - if (dir == -1 || dir > NDIRS) { + target = parse_dir(dir_tkn); + if (target == -1 || target > NDIRS) { parse_error(checker, u, 0, "CAST '" + skdef.name + "': Invalid direction '" + dir_tkn.get_string() + "'."); return; } } + else { + parse_error(checker, u, 0, "CAST '" + skdef.name + "': Invalid argument '" + token.get_string() + "'."); + return; + } if (checker) return; - CastIntOrder *order = new CastIntOrder; - order->spell = S_BIRD_LORE; - if (token == "eagle") { - order->level = 3; - } - - if (token == "direction") { - order->level = 1; - order->target = dir; - } u->ClearCastOrders(); - u->castorders = order; + u->castorders = new CastIntOrder(S_BIRD_LORE, level, target); } void Game::ProcessInvisibility(Unit *u, parser::string_parser& parser, orders_check *checker) @@ -199,11 +187,9 @@ void Game::ProcessInvisibility(Unit *u, parser::string_parser& parser, orders_ch if (u->castorders && u->castorders->spell == S_INVISIBILITY) { order = dynamic_cast(u->castorders); } else { - order = new CastUnitsOrder; - order->spell = S_INVISIBILITY; - order->level = 1; u->ClearCastOrders(); - u->castorders = order; + order = new CastUnitsOrder(1); + u->castorders = order; } if (checker) return; @@ -240,12 +226,8 @@ void Game::ProcessPhanDemons(Unit *u, parser::string_parser& parser, orders_chec int amt = parser.get_token().get_number().value_or(1); if (amt < 1) amt = 1; - CastIntOrder *order = new CastIntOrder; - order->spell = S_CREATE_PHANTASMAL_DEMONS; - order->level = level; - order->target = amt; u->ClearCastOrders(); - u->castorders = order; + u->castorders = new CastIntOrder(S_CREATE_PHANTASMAL_DEMONS, level, amt); } void Game::ProcessPhanUndead(Unit *u, parser::string_parser& parser, orders_check *checker) @@ -273,12 +255,8 @@ void Game::ProcessPhanUndead(Unit *u, parser::string_parser& parser, orders_chec int amt = parser.get_token().get_number().value_or(1); if (amt < 1) amt = 1; - CastIntOrder *order = new CastIntOrder; - order->spell = S_CREATE_PHANTASMAL_UNDEAD; - order->level = level; - order->target = amt; u->ClearCastOrders(); - u->castorders = order; + u->castorders = new CastIntOrder(S_CREATE_PHANTASMAL_UNDEAD, level, amt); } void Game::ProcessPhanBeasts(Unit *u, parser::string_parser& parser, orders_check *checker) @@ -306,23 +284,16 @@ void Game::ProcessPhanBeasts(Unit *u, parser::string_parser& parser, orders_chec int amt = parser.get_token().get_number().value_or(1); if (amt < 1) amt = 1; - CastIntOrder *order = new CastIntOrder; - order->spell = S_CREATE_PHANTASMAL_BEASTS; - order->level = level; - order->target = amt; u->ClearCastOrders(); - u->castorders = order; + u->castorders = new CastIntOrder(S_CREATE_PHANTASMAL_BEASTS, level, amt); } void Game::ProcessGenericSpell(Unit *u, int spell, orders_check *checker) { if (checker) return; - CastOrder *orders = new CastOrder; - orders->spell = spell; - orders->level = 1; u->ClearCastOrders(); - u->castorders = orders; + u->castorders = new CastOrder(spell, 1); } void Game::ProcessRegionSpell(Unit *u, int spell, parser::string_parser& parser, orders_check *checker) @@ -375,19 +346,14 @@ void Game::ProcessRegionSpell(Unit *u, int spell, parser::string_parser& parser, if (y == -1) y = u->object->region->yloc; if (z == -1) z = u->object->region->zloc; - CastRegionOrder *order; - if (spell == S_TELEPORTATION) order = new TeleportOrder; - else order = new CastRegionOrder; - - order->spell = spell; - order->level = 1; - order->xloc = x; - order->yloc = y; - order->zloc = z; - u->ClearCastOrders(); - if (spell == S_TELEPORTATION) u->teleportorders = dynamic_cast(order); - else u->castorders = order; + + if (spell == S_TELEPORTATION) { + u->teleportorders = new TeleportOrder(spell, 1, x, y, z); + } + else { + u->castorders = new CastRegionOrder(spell, 1, x, y, z); + } } void Game::ProcessCastPortalLore(Unit *u, parser::string_parser& parser, orders_check *checker) @@ -410,15 +376,14 @@ void Game::ProcessCastPortalLore(Unit *u, parser::string_parser& parser, orders_ TeleportOrder *order; if (u->teleportorders && u->teleportorders->spell == S_PORTAL_LORE) { order = u->teleportorders; + order->level = 1; } else { - order = new TeleportOrder; + order = new TeleportOrder(S_PORTAL_LORE, 1); u->ClearCastOrders(); u->teleportorders = order; } order->gate = target; - order->spell = S_PORTAL_LORE; - order->level = 1; UnitId *id = parse_unit(parser); while(id) { @@ -442,11 +407,8 @@ void Game::ProcessCastGateLore(Unit *u, parser::string_parser& parser, orders_ch if (token == "detect") { if (checker) return; - CastOrder *to = new CastOrder; - to->spell = S_GATE_LORE; - to->level = 2; u->ClearCastOrders(); - u->castorders = to; + u->castorders = new CastOrder(S_GATE_LORE, 2); return; } @@ -467,10 +429,8 @@ void Game::ProcessCastGateLore(Unit *u, parser::string_parser& parser, orders_ch if (u->teleportorders && u->teleportorders->spell == S_GATE_LORE && u->teleportorders->gate == gate) { order = u->teleportorders; } else { - order = new TeleportOrder; + order = new TeleportOrder(S_GATE_LORE, 3); order->gate = gate; - order->spell = S_GATE_LORE; - order->level = 3; u->ClearCastOrders(); u->teleportorders = order; } @@ -489,23 +449,27 @@ void Game::ProcessCastGateLore(Unit *u, parser::string_parser& parser, orders_ch if (checker) return; TeleportOrder *order; + int level = 1; + int gate = -1; + + token = parser.get_token(); + if (token == "level") { + gate = -2; + level = 2; + token = parser.get_token(); + } + if (u->teleportorders && u->teleportorders->spell == S_GATE_LORE && u->teleportorders->gate == -1 ) { order = u->teleportorders; + order->gate = gate; + order->level = level; } else { - order = new TeleportOrder; - order->gate = -1; - order->spell = S_GATE_LORE; - order->level = 1; + order = new TeleportOrder(S_GATE_LORE, level); + order->gate = gate; u->ClearCastOrders(); u->teleportorders = order; } - token = parser.get_token(); - if (token == "level") { - order->gate = -2; - order->level = 2; - token = parser.get_token(); - } if (token != "units") return; UnitId *id = parse_unit(parser); @@ -513,7 +477,6 @@ void Game::ProcessCastGateLore(Unit *u, parser::string_parser& parser, orders_ch order->units.push_back(id); id = parse_unit(parser); } - return; } } @@ -555,14 +518,8 @@ void Game::ProcessTransmutation(Unit *u, parser::string_parser& parser, orders_c if (checker) return; - CastTransmuteOrder *order; - order = new CastTransmuteOrder; - order->spell = S_TRANSMUTATION; - order->level = level; - order->item = item; - order->number = amt; u->ClearCastOrders(); - u->castorders = order; + u->castorders = new CastTransmuteOrder(level, item, amt); } void Game::RunACastOrder(ARegion * r,Object *o,Unit * u) @@ -1191,9 +1148,7 @@ int Game::RunBirdLore(ARegion *r,Unit *u) return 0; } - Farsight *f = new Farsight; - f->faction = u->faction; - f->level = u->GetSkill(S_BIRD_LORE); + Farsight *f = new Farsight(u->faction, u, u->GetSkill(S_BIRD_LORE)); tar->farsees.push_back(f); u->event("Sends birds to spy on " + tar->print() + ".", "spell"); return 1; @@ -1484,11 +1439,7 @@ int Game::RunFarsight(ARegion *r,Unit *u) val = GetRegionInRange(r, tar, u, S_FARSIGHT); if (!val) return 0; - Farsight *f = new Farsight; - f->faction = u->faction; - f->level = u->GetSkill(S_FARSIGHT); - f->unit = u; - f->observation = u->GetAttribute("observation"); + Farsight *f = new Farsight(u->faction, u, u->GetSkill(S_FARSIGHT), u->GetAttribute("observation")); tar->farsees.push_back(f); u->event("Casts Farsight on " + tar->short_print() + ".", "spell"); return 1; diff --git a/unit.cpp b/unit.cpp index 6aa47fe5..c0d0f308 100644 --- a/unit.cpp +++ b/unit.cpp @@ -864,15 +864,10 @@ void Unit::DefaultOrders(Object *obj) int dir = directions[dirIndex]; if (dir >= 0) { - MoveOrder *o = new MoveOrder; - o->advancing = 0; + bool advance = (rng::get_random(100) < aggression); - if (rng::get_random(100) < aggression) { - o->advancing = 1; - } - - MoveDir *d = new MoveDir; - d->dir = dir; + MoveOrder *o = new MoveOrder(advance); + MoveDir *d = new MoveDir{ dir }; o->dirs.push_back(d); monthorders = o; } @@ -894,12 +889,7 @@ void Unit::DefaultOrders(Object *obj) if (GetFlag(FLAG_AUTOTAX) && Globals->TAX_PILLAGE_MONTH_LONG && Taxers(1)) { taxing = TAX_AUTO; } else { - ProduceOrder *order = new ProduceOrder; - order->skill = -1; - order->item = I_SILVER; - order->target = 0; - order->quiet = 1; - monthorders = order; + monthorders = new ProduceOrder(I_SILVER, -1, 0, 1); } } } diff --git a/unit.h b/unit.h index b71b9249..2e824c3c 100644 --- a/unit.h +++ b/unit.h @@ -70,7 +70,8 @@ enum { class UnitId { public: - UnitId() {}; + UnitId(int num, int alias = 0, int faction = 0) + : unitnum(num), alias(alias), faction(faction) {}; std::string Print(); int unitnum; /* if 0, it is a new unit */