Skip to content

Commit

Permalink
Update Markets to no longer use AList
Browse files Browse the repository at this point in the history
This has been partially done previously, this was just cleaning up
some leftover turds.  Renamed Market class functions to use new
style of naming.  Make the enum type for the market into a named
enum.
  • Loading branch information
jt-traub committed Sep 28, 2024
1 parent 8a7ecbf commit 1e48676
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 143 deletions.
8 changes: 4 additions & 4 deletions aregion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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->Writeout(f);
for (const auto& market : markets) market->write_out(f);

f << objects.Num() << '\n';
forlist ((&objects)) ((Object *) elem)->Writeout(f);
Expand Down Expand Up @@ -1127,7 +1127,7 @@ void ARegion::Readin(istream &f, AList *facs)
markets.reserve(n);
for (int i = 0; i < n; i++) {
Market *m = new Market();
m->Readin(f);
m->read_in(f);
markets.push_back(m);
}

Expand Down Expand Up @@ -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 == M_SELL) {
if (m->type == Market::M_SELL) {
if (ItemDefs[m->item].type & IT_ADVANCED) {
if (!Globals->MARKETS_SHOW_ADVANCED_ITEMS) {
if (!HasItem(fac, m->item)) continue;
Expand Down Expand Up @@ -3999,7 +3999,7 @@ void ARegionList::ResourcesStatistics() {
}

for (const auto& m : reg->markets) {
if (m->type == M_BUY) {
if (m->type == Market::M_BUY) {
forSale[m->item] += m->amount;
}
else {
Expand Down
10 changes: 5 additions & 5 deletions basic/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2526,31 +2526,31 @@ 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(M_BUY,i,(ItemDefs[i].baseprice*5/2),-1, 5000,5000,-1,-1);
m = new Market(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);
m = new Market(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);
m = new Market(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 );
m = new Market(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 );
m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400);
markets.push_back(m);
}
}
Expand Down
50 changes: 31 additions & 19 deletions economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ 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(M_BUY, race, (int)(Wages()*4*ratio), Population()/25, 0, 10000, 0, 2000);
Market *m = new Market(Market::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(M_BUY, I_LEADERS, (int)(Wages()*4*ratio), Population()/125, 0, 10000, 0, 400);
m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400);
markets.push_back(m);
}
}
Expand Down Expand Up @@ -470,7 +470,7 @@ void ARegion::SetupCityMarket()

cap = (citymax * 3/4) - 5000;
if (cap < 0) cap = citymax/2;
Market * m = new Market (M_SELL, i, price, amt, population, population+cap, amt, amt*2);
Market * m = new Market(Market::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
Expand All @@ -486,7 +486,7 @@ void ARegion::SetupCityMarket()

cap = (citymax * 3/4) - 5000;
if (cap < 0) cap = citymax/2;
Market * m = new Market (M_BUY, i, price, amt, population, population+2*cap, amt, amt*5);
Market * m = new Market(Market::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
Expand Down Expand Up @@ -549,7 +549,9 @@ void ARegion::SetupCityMarket()
if (cap < citymax/2) cap = citymax / 2;
offset = citymax / 8;
if (cap+offset < citymax) {
Market * m = new Market (M_SELL, i, price, amt/6, population+cap+offset, population+citymax, 0, amt);
Market * m = new Market(
Market::M_SELL, i, price, amt / 6, population + cap + offset, population + citymax, 0, amt
);
markets.push_back(m);
}
}
Expand Down Expand Up @@ -580,7 +582,7 @@ void ARegion::SetupCityMarket()
cap = (citymax *3/4) - 5000;
if (cap < citymax/2) cap = citymax / 2;
offset = (citymax/20) + ((citymax/5) * 2);
Market * m = new Market (M_SELL, i, price, amt/6, population+cap, population+citymax, 0, amt);
Market * m = new Market(Market::M_SELL, i, price, amt / 6, population + cap, population + citymax, 0, amt);
markets.push_back(m);
}
}
Expand Down Expand Up @@ -614,7 +616,9 @@ void ARegion::SetupCityMarket()

cap = (citymax/4);
offset = - (citymax/20) + ((5-num) * citymax * 3/40);
Market * m = new Market (M_SELL, i, price, amt/6, population+cap+offset, population+citymax, 0, amt);
Market * m = new Market(
Market::M_SELL, i, price, amt / 6, population + cap + offset, population + citymax, 0, amt
);
markets.push_back(m);
demand[i] = 0;
num--;
Expand Down Expand Up @@ -650,7 +654,7 @@ void ARegion::SetupCityMarket()
cap = (citymax/4);
offset = ((3-num) * citymax * 3 / 40);
if (supply[i] < 4) offset += citymax / 20;
Market * m = new Market (M_BUY, i, price, 0, population+cap+offset, population+citymax, 0, amt);
Market * m = new Market(Market::M_BUY, i, price, 0, population + cap + offset, population + citymax, 0, amt);
markets.push_back(m);
supply[i] = 0;
num--;
Expand Down Expand Up @@ -713,7 +717,9 @@ void ARegion::SetupCityMarket()
tradesell++;
offset = - (citymax/20) + tradesell * (tradesell * tradesell * citymax/40);
if (cap + offset < citymax) {
Market * m = new Market (M_SELL, i, price, amt/5, cap+population+offset, citymax+population, 0, amt);
Market * m = new Market(
Market::M_SELL, i, price, amt / 5, cap + population + offset, citymax + population, 0, amt
);
markets.push_back(m);
}
}
Expand All @@ -736,7 +742,9 @@ void ARegion::SetupCityMarket()
cap = (citymax/2);
offset = tradebuy++ * (citymax/6);
if (cap+offset < citymax) {
Market * m = new Market (M_BUY, i, price, amt/6, cap+population+offset, citymax+population, 0, amt);
Market * m = new Market(
Market::M_BUY, i, price, amt / 6, cap + population + offset, citymax + population, 0, amt
);
markets.push_back(m);
}
}
Expand Down Expand Up @@ -897,7 +905,7 @@ void ARegion::UpdateEditRegion()
{
// redo markets and entertainment/tax income for extra people.
SetIncome();
for (auto& m : markets) m->PostTurn(Population(), Wages());
for (auto& m : markets) m->post_turn(Population(), Wages());

//Replace man selling
markets.erase(
Expand All @@ -907,13 +915,13 @@ 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(M_BUY, race, (int)(Wages()*4*ratio), Population()/25, 0, 10000, 0, 2000);
Market *m = new Market(Market::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(M_BUY, I_LEADERS, (int)(Wages()*4*ratio), Population()/125, 0, 10000, 0, 400);
m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400);
markets.push_back(m);
}
}
Expand Down Expand Up @@ -1025,13 +1033,13 @@ 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(M_BUY, race, (int)(Wages()*4*ratio), Population()/25, 0, 10000, 0, 2000);
Market *m = new Market(Market::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(M_BUY, I_LEADERS, (int)(Wages()*4*ratio), Population()/125, 0, 10000, 0, 400);
m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400);
markets.push_back(m);
}
}
Expand Down Expand Up @@ -1194,7 +1202,7 @@ int ARegion::TownGrowth()
int tot = 0;
for (const auto& m : markets) {
if (Population() > m->minpop) {
if (m->type == M_BUY) {
if (m->type == Market::M_BUY) {
if (ItemDefs[m->item].type & IT_TRADE) {
amt += 5 * m->activity;
tot += 5 * m->maxamt;
Expand Down Expand Up @@ -1574,11 +1582,15 @@ void ARegion::PostTurn(ARegionList *pRegs)
SetupCityMarket();
float ratio = ItemDefs[race].baseprice / (float) (Globals->BASE_MAN_COST * 10);
// Setup Recruiting
Market *m = new Market(M_BUY, race, (int)(Wages()*4*ratio), Population()/25, 0, 10000, 0, 2000);
Market *m = new Market(
Market::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(M_BUY, I_LEADERS, (int)(Wages()*4*ratio), Population()/125, 0, 10000, 0, 400);
m = new Market(
Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 125, 0, 10000, 0, 400
);
markets.push_back(m);
}
}
Expand All @@ -1590,7 +1602,7 @@ void ARegion::PostTurn(ARegionList *pRegs)
}

/* update markets */
for (auto& m : markets) m->PostTurn(Population(), Wages());
for (auto& m : markets) m->post_turn(Population(), Wages());

/* update resources */
UpdateProducts();
Expand Down
16 changes: 8 additions & 8 deletions edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ void Game::EditGameRegionMarkets( ARegion *pReg )

Awrite("Wanted: ");
for (const auto &m : pReg->markets) {
if (m->type == M_SELL) {
if (m->type == Market::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 + ".";
Expand All @@ -756,7 +756,7 @@ void Game::EditGameRegionMarkets( ARegion *pReg )
}
Awrite("For Sale: ");
for (const auto &m : pReg->markets) {
if (m->type == M_BUY) {
if (m->type == Market::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 + ".";
Expand All @@ -770,7 +770,7 @@ void Game::EditGameRegionMarkets( ARegion *pReg )
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 swop an item between wanted and sold" );
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." );

Expand Down Expand Up @@ -851,7 +851,7 @@ void Game::EditGameRegionMarkets( ARegion *pReg )

if (!done) {
int price = (ItemDefs[mitem].baseprice * (100 + getrandom(50))) / 100;
Market *m = new Market(M_SELL, mitem, price, 0, minimum, maximum, 0, 0);
Market *m = new Market(Market::M_SELL, mitem, price, 0, minimum, maximum, 0, 0);
pReg->markets.push_back(m);
}

Expand Down Expand Up @@ -910,8 +910,8 @@ 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(M_SELL, mitem, price, mamount, 0, 5000, minimum, maximum);
int mamount = minimum + (maximum * population / 5000);
Market *m = new Market(Market::M_SELL, mitem, price, mamount, 0, 5000, minimum, maximum);
pReg->markets.push_back(m);
}

Expand Down Expand Up @@ -954,7 +954,7 @@ void Game::EditGameRegionMarkets( ARegion *pReg )
}

if (!done) {
Market *m = new Market(M_SELL, mitem, price, 0, 0, 5000, 0, 0);
Market *m = new Market(Market::M_SELL, mitem, price, 0, 0, 5000, 0, 0);
m->baseprice = baseprice;
pReg->markets.push_back(m);
}
Expand Down Expand Up @@ -990,7 +990,7 @@ void Game::EditGameRegionMarkets( ARegion *pReg )
[mitem](const Market *m) { return m->item == mitem; }
);
if (m != pReg->markets.end()) {
(*m)->type = (*m)->type == M_SELL ? M_BUY : M_SELL;
(*m)->type = (*m)->type == Market::M_SELL ? Market::M_BUY : Market::M_SELL;
} else {
Awrite("No such market");
}
Expand Down
10 changes: 5 additions & 5 deletions fracas/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2529,31 +2529,31 @@ 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(M_BUY,i,(ItemDefs[i].baseprice*5/2),-1, 5000,5000,-1,-1);
m = new Market(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);
m = new Market(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);
m = new Market(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 );
m = new Market(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 );
m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400);
markets.push_back(m);
}
}
Expand Down
10 changes: 5 additions & 5 deletions havilah/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,31 +786,31 @@ 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(M_BUY,i,(ItemDefs[i].baseprice*5/2),-1, 5000,5000,-1,-1);
m = new Market(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);
m = new Market(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);
m = new Market(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 );
m = new Market(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 );
m = new Market(Market::M_BUY, I_LEADERS, (int)(Wages() * 4 * ratio), Population() / 25, 0, 10000, 0, 400);
markets.push_back(m);
}
}
Expand Down
Loading

0 comments on commit 1e48676

Please sign in to comment.