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

Need to create a new function?

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

  1. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    Hi, I'm new to modding the SDK and C++ so please forgive my ignorance and lack of understanding. (I am working through a C++ beginners book I swear.)

    I successfully copied tags <SpecialistYieldChanges> from buildinginfos to civicinfos so civics can grant a specific specialist extra yield types (like angkor wat does with priests).

    Tried to do the same for commerce types, however the CvPlayer::changeSpecialistExtraCommerce function that already exist cannot take 3 arguments. I *think* I need to write a new function that includes specialisttypes index argument.

    I am wondering if I should model off of:

    CvPlayer::changeSpecialistExtraYield in player.cpp

    Code:
    int CvPlayer::getSpecialistExtraYield(SpecialistTypes eIndex1, YieldTypes eIndex2) const
    {
    	FAssertMsg(eIndex1 >= 0, "eIndex1 expected to be >= 0");
    	FAssertMsg(eIndex1 < GC.getNumSpecialistInfos(), "eIndex1 expected to be < GC.getNumSpecialistInfos()");
    	FAssertMsg(eIndex2 >= 0, "eIndex2 expected to be >= 0");
    	FAssertMsg(eIndex2 < NUM_YIELD_TYPES, "eIndex2 expected to be < NUM_YIELD_TYPES");
    	return m_ppaaiSpecialistExtraYield[eIndex1][eIndex2];
    }
    
    
    void CvPlayer::changeSpecialistExtraYield(SpecialistTypes eIndex1, YieldTypes eIndex2, int iChange)
    {
    	FAssertMsg(eIndex1 >= 0, "eIndex1 expected to be >= 0");
    	FAssertMsg(eIndex1 < GC.getNumSpecialistInfos(), "eIndex1 expected to be < GC.getNumSpecialistInfos()");
    	FAssertMsg(eIndex2 >= 0, "eIndex2 expected to be >= 0");
    	FAssertMsg(eIndex2 < NUM_YIELD_TYPES, "eIndex2 expected to be < NUM_YIELD_TYPES");
    
    	if (iChange != 0)
    	{
    		m_ppaaiSpecialistExtraYield[eIndex1][eIndex2] = (m_ppaaiSpecialistExtraYield[eIndex1][eIndex2] + iChange);
    		FAssert(getSpecialistExtraYield(eIndex1, eIndex2) >= 0);
    
    		updateExtraSpecialistYield();
    
    		AI_makeAssignWorkDirty();
    	}
    }
    or

    Code:
    int CvPlayer::getSpecialistExtraCommerce(CommerceTypes eIndex) const
    {
    	FAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");
    	FAssertMsg(eIndex < NUM_COMMERCE_TYPES, "eIndex is expected to be within maximum bounds (invalid Index)");
    	return m_aiSpecialistExtraCommerce[eIndex];
    }
    
    
    void CvPlayer::changeSpecialistExtraCommerce(CommerceTypes eIndex, int iChange)
    {
    	FAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");
    	FAssertMsg(eIndex < NUM_COMMERCE_TYPES, "eIndex is expected to be within maximum bounds (invalid Index)");
    
    	if (iChange != 0)
    	{
    		m_aiSpecialistExtraCommerce[eIndex] = (m_aiSpecialistExtraCommerce[eIndex] + iChange);
    		FAssert(getSpecialistExtraCommerce(eIndex) >= 0);
    
    		updateCommerce(eIndex);
    
    		AI_makeAssignWorkDirty();
    	}
    }
    Not sure if either makes any difference but I tried it with yields creating a "ppaaiSpecialistCivicExtraYield" but that led to more problems about re-declaring functions that I couldn't solve. I'd be really grateful for someone to point me in the right direction on this!
     
  2. Tholal

    Tholal Emperor

    Joined:
    May 19, 2009
    Messages:
    1,676
    Why not just use the changeSpecialistExtraYield function? Doesnt that do what you want?
     
  3. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    I've already have the Yield array working. I want to have the same functionality but for Commerce ie. culture, gold, beakers, espionage. If I use changeSpecialistExtraYield then the function will change the yield not commerce. I think I need to create a changeSpecialistExtraCommerce function that allows 3 arguments ie. (SpecialistTypes eIndex1, YieldTypes eIndex2, int iChange).
     
  4. LyTning94

    LyTning94 Dragonborn

    Joined:
    Nov 10, 2010
    Messages:
    397
    Location:
    Skyrim
    Do you want it to change the commerce for all specialists, or only a certain type? Civic commerce change for all specialists is already included in changeSpecialistExtraCommerce() (Representation adds +3:science: to all specialists).

    If you only want to add commerce to a certain type of specialist, you can't use changeSpecialistExtraCommerce() because that applies to all specialists. I suggest you edit CvPlayer::specialistCommerce() which applies to each individual type of specialist.
     
  5. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    For certain types rather than all Specialist. For example, Merchants grant +1 culture under free religion for example. Yes, I just looked at
    Code:
    int CvPlayer::specialistYield(SpecialistTypes eSpecialist, YieldTypes eYield) const
    {
    	return (GC.getSpecialistInfo(eSpecialist).getYieldChange(eYield) + getSpecialistExtraYield(eSpecialist, eYield));
    }
    
    
    int CvPlayer::specialistCommerce(SpecialistTypes eSpecialist, CommerceTypes eCommerce) const
    {
    	return (GC.getSpecialistInfo(eSpecialist).getCommerceChange(eCommerce) + getSpecialistExtraCommerce(eCommerce));
    }
    To begin with I think I need to change
    Code:
     getSpecialistExtraCommerce(eCommerce));
    to

    Code:
     getSpecialistExtraCommerce(eSpecialist, eCommerce));
    Will have a play, cheers.
     
  6. LyTning94

    LyTning94 Dragonborn

    Joined:
    Nov 10, 2010
    Messages:
    397
    Location:
    Skyrim
    I would simply edit the specialistCommerce() function itself and add your extra commerce to that. Instead of:

    Code:
    int CvPlayer::specialistCommerce(SpecialistTypes eSpecialist, CommerceTypes eCommerce) const
    {
    	return (GC.getSpecialistInfo(eSpecialist).getCommerceChange(eCommerce) + getSpecialistExtraCommerce(eCommerce));
    }
    
    do something like:

    Code:
    int CvPlayer::specialistCommerce(SpecialistTypes eSpecialist, CommerceTypes eCommerce) const
    {
    	int iCommerce = GC.getSpecialistInfo(eSpecialist).getCommerceChange(eCommerce) + getSpecialistExtraCommerce(eCommerce);
    
            if (eSpecialist == // whatever type of specialist
            {
                    iCommerce += // whatever value loaded from XML
            }
            
            return iCommerce;
    }
    
    This way you don't have to worry about passing another argument to getSpecialistExtraCommerce().
     

Share This Page