Skip to content
Merged
55 changes: 14 additions & 41 deletions aregion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ Location *GetUnit(std::list<Location *>& 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<Farsight *>& farsees, Faction *fac)
Expand All @@ -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;
Expand All @@ -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; i<NDIRS; i++)
neighbors[i] = 0;
visited = 0;
neighbors[i] = nullptr;
}

ARegion::~ARegion()
Expand All @@ -114,7 +86,7 @@ ARegion::~ARegion()
void ARegion::ZeroNeighbors()
{
for (int i=0; i<NDIRS; i++) {
neighbors[i] = 0;
neighbors[i] = nullptr;
}
}

Expand Down Expand Up @@ -802,7 +774,7 @@ Location *ARegion::GetLocation(UnitId *id, int faction)
for(const auto o : objects) {
Unit *unit = o->GetUnitId(id, faction);
if (unit) {
Location *l = new Location;
Location *l = new Location();
l->region = this;
l->obj = o;
l->unit = unit;
Expand Down Expand Up @@ -972,7 +944,7 @@ void ARegion::Readin(std::istream &f, std::list<Faction *>& facs)
int n;
f >> n;
if (n) {
town = new TownInfo;
town = new TownInfo();
town->Readin(f);
town->dev = TownDevelopment();
} else {
Expand Down Expand Up @@ -1662,7 +1634,7 @@ int ARegionList::ReadRegions(std::istream &f, std::list<Faction *>& 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);

Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}

51 changes: 24 additions & 27 deletions aregion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Location *>& locs, int unitid);
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -297,15 +294,15 @@ class ARegion
std::list<ARegion *> 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<Object *> objects;
Expand All @@ -317,8 +314,8 @@ class ARegion
std::list<Farsight *>passers;
std::vector<Production *> products;
std::vector<Market*> 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;
Expand Down
17 changes: 7 additions & 10 deletions battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -377,7 +374,7 @@ void AddBattleFact(
) {
if (!Globals->WORLD_EVENTS) return;

auto fact = new BattleFact();
BattleFact * fact = new BattleFact();

fact->location = EventLocation::Create(region);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ enum {
class Battle
{
public:
Battle();
~Battle();

void build_json_report(json &j, Faction *fac);
void AddLine(const std::string& line);

Expand Down
10 changes: 5 additions & 5 deletions economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions events.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,15 @@ struct EventLocation {
int settlementType;
std::vector<Landmark> landmarks;

events::LandmarkType GetLandmarkType();
const std::string GetTerrainName(const bool plural = false);
static EventLocation Create(ARegion* region);
const Landmark *GetSignificantLandmark();
};

class BattleFact : public FactBase {
public:
~BattleFact() = default;

void GetEvents(std::list<Event> &events);
virtual ~BattleFact() = default;
virtual void GetEvents(std::list<Event> &events);

EventLocation location;
BattleSide attacker;
Expand Down
Loading
Loading