Skip to content

Commit

Permalink
Implement the object reports (#154)
Browse files Browse the repository at this point in the history
* Part 3 of json reports.   Next level down from factions to regions to
  objects.  This implements writing out the basic object data, but not
  the data related to units within the object.
* Fix a bug where unit tests were not idempotent due to the fact that
  the RNG was being seeded with the time the test was run.
  * To fix this , added an overriddable function pointer that the unit
    tests can use to ensure the same sequence of random numbers each
    time.
* Got rid of remaining (direct) Alists in faction. (skills and items
  are still using SkillList and ItemList)
* converted markets & products in aregion to std::vector
  • Loading branch information
jt-traub authored Nov 4, 2023
1 parent 1a812a2 commit 0dce186
Show file tree
Hide file tree
Showing 39 changed files with 950 additions and 918 deletions.
333 changes: 174 additions & 159 deletions aregion.cpp

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions aregion.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class ARegion : public AListElem
void WriteEconomy(ostream& f, Faction *, int);
void WriteExits(ostream& f, ARegionList *pRegs, int *exits_seen);
void write_text_report(ostream& f, Faction *fac, int month, ARegionList *pRegions);
json basic_json_data(ARegionList *pRegions);
void write_json_report(json& j, Faction *fac, int month, ARegionList *pRegions);
// DK
void WriteTemplate(ostream& f, Faction *, ARegionList *, int);
Expand Down Expand Up @@ -353,15 +354,17 @@ class ARegion : public AListElem
AList farsees;
// List of units which passed through the region
AList passers;
ProductionList products;
MarketList markets;
std::vector<Production *> products;
std::vector<Market*> markets;
int xloc, yloc, zloc;
int visited;

// Used for calculating distances using an A* search
int distance;
ARegion *next;

// find a production for a certain skill.
Production *get_production_for_skill(int item, int skill);
// Editing functions
void UpdateEditRegion();
void SetupEditRegion();
Expand Down
29 changes: 14 additions & 15 deletions basic/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2515,44 +2515,43 @@ void ARegion::MakeStartingCity()
town->dev = TownDevelopment();

float ratio;

for (auto& m : markets) delete m; // Free the allocated object
markets.clear(); // empty the vector.

Market *m;
markets.DeleteAll();
if (Globals->START_CITIES_START_UNLIMITED) {
for (int i=0; i<NITEMS; i++) {
if ( ItemDefs[i].flags & ItemType::DISABLED ) continue;
if ( ItemDefs[ i ].type & IT_NORMAL ) {
if (i==I_SILVER || i==I_LIVESTOCK || i==I_FISH || i==I_GRAIN)
continue;
m = new Market(M_BUY,i,(ItemDefs[i].baseprice*5/2),-1,
5000,5000,-1,-1);
markets.Add(m);
m = new Market(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(M_BUY,race,(int)(Wages()*4*ratio),-1, 5000,5000,-1,-1);
markets.Add(m);
m = new Market(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(M_BUY,I_LEADERS,(int)(Wages()*4*ratio),
-1,5000,5000,-1,-1);
markets.Add(m);
m = new Market(M_BUY,I_LEADERS,(int)(Wages()*4*ratio), -1,5000,5000,-1,-1);
markets.push_back(m);
}
} else {
SetupCityMarket();
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( M_BUY, race, (int)(Wages()*4*ratio),
Population()/5, 0, 10000, 0, 2000 );
markets.Add(m);
m = new Market( 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( M_BUY, I_LEADERS, (int)(Wages()*4*ratio),
Population()/25, 0, 10000, 0, 400 );
markets.Add(m);
m = new Market( M_BUY, I_LEADERS, (int)(Wages()*4*ratio), Population()/25, 0, 10000, 0, 400 );
markets.push_back(m);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ void Battle::write_text_report(ostream& f,Faction * fac) {
f << asstext << "\n";
return;
}
for(auto line: text) {
for (const auto& line: text) {
f << line << '\n';
}
}
Expand Down
Loading

0 comments on commit 0dce186

Please sign in to comment.