1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Help needed with Specialist Commerce CvCity.cpp

Discussion in 'Civ4 - SDK/Python' started by CaptainMidnight, Aug 22, 2011.

  1. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    I've been trying to get some new tags to work. The tags enable civics to grant specific specialist types commerce bonuses. For example, under Free Market Merchant specialist are granted +1 :gold: and :espionage:
    The XML looks like this in CivicInfos.xml:
    Code:
    <SpecialistCommerceChanges>
    		<SpecialistCommerceChange>
    			<SpecialistType>SPECIALIST_MERCHANT</SpecialistType>
    			<CommerceChanges>
    			     <iCommerce>1</iCommerce>
    			     <iCommerce>1</iCommerce>
    			     <iCommerce>1</iCommerce>
    			     <iCommerce>1</iCommerce>
    			</CommerceChanges>
    		</SpecialistCommerceChange>
    	</SpecialistCommerceChanges>

    I have done all the work for infos.cpp and player.cpp. The affected specialist display the change correctly when in the civic. I haven't made any changes to cvcity.cpp yet so the extra commerce is not used by the city and am unsure how to proceed. Any help would be marvelous!

    This is the main things i did in the (excluding the ppaaiSpecialistCivicExtraCommerce stuff) cvplayer.cpp :

    Code:
    [B]// CMEDIT Civic Specialist Commerce Changes 19/08/2011[/B]
    int CvPlayer::getSpecialistCivicExtraCommerce(SpecialistTypes eIndex1, CommerceTypes eIndex) const
    {
    	FAssertMsg(eIndex1 >= 0, "eIndex1 expected to be >= 0");
    	FAssertMsg(eIndex1 < GC.getNumSpecialistInfos(), "eIndex1 expected to be < GC.getNumSpecialistInfos()");
    	FAssertMsg(eIndex >= 0, "eIndex expected to be >= 0");
    	FAssertMsg(eIndex < NUM_COMMERCE_TYPES, "eIndex expected to be < NUM_COMMERCE__TYPES");
    	return m_ppaaiSpecialistCivicExtraCommerce [eIndex1][eIndex];
    }
    
    
    void CvPlayer::changeSpecialistCivicExtraCommerce(SpecialistTypes eIndex1, CommerceTypes eIndex, int iChange)
    {
    	FAssertMsg(eIndex1 >= 0, "eIndex1 expected to be >= 0");
    	FAssertMsg(eIndex1 < GC.getNumSpecialistInfos(), "eIndex1 expected to be < GC.getNumSpecialistInfos()");
    	FAssertMsg(eIndex >= 0, "eIndex expected to be >= 0");
    	FAssertMsg(eIndex < NUM_COMMERCE_TYPES, "eIndex expected to be < NUM_COMMERCE_TYPES");
    
    	if (iChange != 0)
    	{
    		m_ppaaiSpecialistCivicExtraCommerce[eIndex1][eIndex] = (m_ppaaiSpecialistCivicExtraCommerce[eIndex1][eIndex] + iChange);
    		FAssert(m_ppaaiSpecialistCivicExtraCommerce(eIndex1, eIndex) >= 0);
    
    		updateCommerce(eIndex);
    
    		AI_makeAssignWorkDirty();
    	}
    }
    
    [B]//CMEdit End[/B]
    and also here:
    Code:
    changeSpecialistExtraCommerce(((CommerceTypes)iI), (GC.getCivicInfo(eCivic).getSpecialistExtraCommerce(iI) * iChange));
    	}
    	
    	[B]// CMEDIT Civic Specialist Commerce Changes 17/08/2011[/B]
    	for (iI = 0; iI < GC.getNumSpecialistInfos(); iI++)
    	{
    		for (iJ = 0; iJ < NUM_COMMERCE_TYPES; iJ++)
    		{
    			changeSpecialistCivicExtraCommerce(((SpecialistTypes)iI), ((CommerceTypes)iJ), (GC.getCivicInfo(eCivic).getSpecialistCommerceChange(iI, iJ) * iChange));
    		}
    	}
    [B]	// CMEDIT end[/B]
    
    	for (iI = 0; iI < GC.getNumBuildingClassInfos(); iI++)
    and finally this piece
    Code:
    int CvPlayer::specialistCommerce(SpecialistTypes eSpecialist, CommerceTypes eCommerce) const
    {
    [B]// CMEDIT Civic Specialist Commerce Changes 19/08/2011[/B]
    //	return (GC.getSpecialistInfo(eSpecialist).getCommerceChange(eCommerce) + getSpecialistExtraCommerce(eCommerce));
    	return (GC.getSpecialistInfo(eSpecialist).getCommerceChange(eCommerce) + getSpecialistExtraCommerce(eCommerce) + getSpecialistCivicExtraCommerce (eSpecialist, eCommerce));
    [B]// CMEDIT End[/B]
    }
    My question is how do I get this information in player.cpp to be read and used by the city. I figured this piece of code in cvcity.cpp might be significant:
    Code:
    int CvCity::getBaseCommerceRateTimes100(CommerceTypes eIndex) const
    {
    	int iBaseCommerceRate;
    
    	iBaseCommerceRate = getCommerceFromPercent(eIndex, getYieldRate(YIELD_COMMERCE) * 100);
    
    	iBaseCommerceRate += 100 * ((getSpecialistPopulation() + getNumGreatPeople()) * GET_PLAYER(getOwnerINLINE()).getSpecialistExtraCommerce(eIndex));
    	
    	iBaseCommerceRate += 100 * (getBuildingCommerce(eIndex) + getSpecialistCommerce(eIndex) + getReligionCommerce(eIndex) + getCorporationCommerce(eIndex) + GET_PLAYER(getOwnerINLINE()).getFreeCityCommerce(eIndex));
    But everything I've tried hasn't worked. Any suggestions?
     
  2. LyTning94

    LyTning94 Dragonborn

    Joined:
    Nov 10, 2010
    Messages:
    397
    Location:
    Skyrim
    I would look at CvCity::getSpecialistCommerce(eIndex).
     
  3. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    Cheers LyTing94, I've got the tags working fine and the AI working too. getSpecialistCommerce was certainly part to refer to. Now I've just got to sort out the Gametextmgr which I have no idea how to do yet.
     
  4. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    And the gametext is done now
     
  5. LyTning94

    LyTning94 Dragonborn

    Joined:
    Nov 10, 2010
    Messages:
    397
    Location:
    Skyrim
    Good to hear! :goodjob:
     
  6. SaibotLieh

    SaibotLieh Emperor

    Joined:
    Sep 25, 2009
    Messages:
    1,511
  7. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    Yes, I'll release as a modcomp soon, including sources of course. At the moment its tangled up in my modpack. Probably best I merge it with the original unedited core files. I am also looking at a tag which changes XP for particular specialist under civics. Also gonna copy these tags to Traits and buildings.
     
  8. SaibotLieh

    SaibotLieh Emperor

    Joined:
    Sep 25, 2009
    Messages:
    1,511
  9. Cybah

    Cybah Emperor

    Joined:
    Jun 22, 2007
    Messages:
    1,480
    Oh yes I really need this. :)

    Edit: Make sure the AI will understand it. ;)
     
  10. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    The AI uses it appropriately from the few test I've done so far. I've used AI code thats pretty close to the vanilla ExtraSpecialistCommerce functionality
     

Share This Page