I think I tracked down why cant access some goods not appearing on the map with my enables good. It appears that the distance to goodvalue is set to zero if the goodvalue upon generation is higher than the const.txt MaxGoodValue. the good value at generation is calculated by finding it on the map and then compute values good adds 1+ the max good value to any good not found thereby preventing them from being accessed as a good.
the question is: If I want goods not on the map accesible should I change the code in ComputeGoods or in the Citydata code?
I think I should make it a value that is negated by standard Const.txt but if I adjust it for my mod then I can access it. there by leave it as 1 but remove the max good value.
reference below
citydata.cpp
void World::ComputeGoodsValues()
sample from Ctp_debug generating goods
in Const.txt
the question is: If I want goods not on the map accesible should I change the code in ComputeGoods or in the Citydata code?
I think I should make it a value that is negated by standard Const.txt but if I adjust it for my mod then I can access it. there by leave it as 1 but remove the max good value.
reference below
citydata.cpp
Code:
void CityData::FindGoodDistances() { sint32 i; sint32 goodsToFind = 0; for(i = 0; i < g_theResourceDB->NumRecords(); i++) { if(g_theWorld->GetGoodValue(i) <= g_theConstDB->GetMaxGoodValue()) { goodsToFind++; } m_distanceToGood[i] = 0; } // g_theWorld->FindDistances(m_owner, m_home_city.RetPos(), goodsToFind, // FindGoodDistancesCallback, this); g_theWorld->FindDistances(m_owner, m_pos, goodsToFind, FindGoodDistancesCallback, this); }
void World::ComputeGoodsValues()
Code:
void World::ComputeGoodsValues() { if (g_theResourceDB->NumRecords() <= 0) { delete [] m_goodValue; m_goodValue = NULL; return; } sint32 *goodCounts = new sint32[g_theResourceDB->NumRecords()]; memset(goodCounts, 0, sizeof(sint32) * g_theResourceDB->NumRecords()); MapPoint pos; sint32 good; sint32 totalGoods = 0; for(pos.x = 0; pos.x < m_size.x; pos.x++) { for(pos.y = 0; pos.y < m_size.y; pos.y++) { if(GetGood(pos, good)) { Assert(good >= 0); Assert(good < g_theResourceDB->NumRecords()); totalGoods++; goodCounts[good]++; } } } sint32 maxGood = -1; sint32 maxCount = 0; sint32 minGood = -1; sint32 minCount = 0x7fffffff; sint32 i; for(i = 0; i < g_theResourceDB->NumRecords(); i++) { if(goodCounts[i] > maxCount) { maxCount = goodCounts[i]; maxGood = i; } if((goodCounts[i] > 0) && (goodCounts[i] < minCount)) { minCount = goodCounts[i]; minGood = i; } } double valueDiff = g_theConstDB->GetMaxGoodValue() - g_theConstDB->GetMinGoodValue(); delete [] m_goodValue; m_goodValue = new double[g_theResourceDB->NumRecords()]; for(i = 0; i < g_theResourceDB->NumRecords(); i++) { if(goodCounts[i] <= 0) { m_goodValue[i] = g_theConstDB->GetMaxGoodValue() + 1; } else { // goodCounts[i] > 0 => maxCount > 0, so division by maxCount is OK double percent = double(goodCounts[i]) / double(maxCount); m_goodValue[i] = g_theConstDB->GetMinGoodValue() + ((1.0 - percent) * double(valueDiff)); } DPRINTF(k_DBG_GAMESTATE, ("Good %s has a base value of %lf\n", g_theResourceDB->Get(i)->GetNameText(), m_goodValue[i])); } delete [] goodCounts; }
sample from Ctp_debug generating goods
Code:
wldgen.cpp@991 : Good Coffee has a base value of 0.048333 wldgen.cpp@991 : Good Cotton has a base value of 0.036667 wldgen.cpp@991 : Good Spices has a base value of 0.048333 wldgen.cpp@991 : Good Sugar has a base value of 1.050000
Code:
MIN_GOOD_VALUE 0.01 MAX_GOOD_VALUE 0.05
Comment