Announcement

Collapse
No announcement yet.

Project: Good Value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Project: Good Value

    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
    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
    in Const.txt

    Code:
    MIN_GOOD_VALUE 0.01
    MAX_GOOD_VALUE 0.05
    Last edited by Ekmek; April 20, 2006, 18:04.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

  • #2
    this may also entail changing:

    Code:
    sint32 TradeRouteData::GetValue() const
    {
    	if(m_sourceRouteType != ROUTE_TYPE_RESOURCE)
    		return 0;
    
    	
    	double baseValue = g_theWorld->GetGoodValue(m_sourceResource);
    	double distance = double(m_destinationCity->GetCityData()->GetDistanceToGood(m_sourceResource));
    	return sint32(baseValue * distance);
    }
    and

    Code:
    sint32 tradeutil_GetTradeValue(const sint32 owner, Unit &destination, sint32 resource)
    {
    	Assert(destination.IsValid());
    	if(!destination.IsValid()) return 0;
    
    	Assert(resource >= 0 && resource < g_theResourceDB->NumRecords());
    	if(resource < 0 || resource >= g_theResourceDB->NumRecords())
    		return 0;
    
    
    	double baseValue = g_theWorld->GetGoodValue(resource);
    	double distance = static_cast(destination.CD()->GetDistanceToGood(resource));
    	sint32 totalValue = sint32(baseValue * distance);
    	
    	
    	
    	bool trade_pact = 
    		AgreementMatrix::s_agreements.HasAgreement(owner, destination.GetOwner(), PROPOSAL_TREATY_TRADE_PACT);
    	if (trade_pact) {
    		totalValue = (sint32) (totalValue * 1.05);
    	}
    
    	return totalValue;
    }
    So far it calcluates the distance to the good to the destination city and the value of the good.

    Shouldn't be something like the distance between cities and the population size of the destination city (a bigger market) and then maybe the random demand?
    Last edited by Ekmek; April 21, 2006, 16:36.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #3
      I would be careful with this stuff, I used some of it to allow the loading of games with a different number of goods. You might break it if you modify the value calculation.

      -Martin
      Civ2 military advisor: "No complaints, Sir!"

      Comment

      Working...
      X