Prize Ships For Land Units?

CaseyAnthony

Chieftain
Joined
Sep 29, 2019
Messages
3
Howdy, even more new blood on the modding scene here. I'm working on a civ with a UU that essentially has the Ottoman Prize Ships promotion, but on land. The concept is a marine that has a 25% chance to convert defeated melee and gunpowder units while fighting in rough terrain. I've been looking at the code for Prize Ships, but my brain is too smooth to figure out how to convert the ability to work on land. Does anybody know how I can set this up? Pleas note that I am an absolute doofus at anything code-related.
 
Howdy, even more new blood on the modding scene here. I'm working on a civ with a UU that essentially has the Ottoman Prize Ships promotion, but on land. The concept is a marine that has a 25% chance to convert defeated melee and gunpowder units while fighting in rough terrain. I've been looking at the code for Prize Ships, but my brain is too smooth to figure out how to convert the ability to work on land. Does anybody know how I can set this up? Pleas note that I am an absolute doofus at anything code-related.
The Prize Ships promotion seems to handle capture through the <CaptureDefeatedUnits>-column in the <UnitPromotions>-table. By inspecting the DLL source it seems that such capturing is not limited to naval units only. A unit of some type may capture another unit of the same type if the capturerer has such a promotion (it is unclear which units exactly count though, as we do not have access to that part of the DLL). The only way to find out what units are valid is through testing in-game.
The capture chance is hardcoded to be based on the difference between combat strenghts of the units; The higher the difference (in favour of the attacker), the more likely the capture is.

The "while fighting in rough terrain"-part can be done using Lua, by granting or removing a promotion with <CaptureDefeatedUnits> in GameEvents.UnitSetXY(..)
 
The Prize Ships promotion seems to handle capture through the <CaptureDefeatedUnits>-column in the <UnitPromotions>-table. By inspecting the DLL source it seems that such capturing is not limited to naval units only. A unit of some type may capture another unit of the same type if the capturerer has such a promotion (it is unclear which units exactly count though, as we do not have access to that part of the DLL). The only way to find out what units are valid is through testing in-game.
The capture chance is hardcoded to be based on the difference between combat strenghts of the units; The higher the difference (in favour of the attacker), the more likely the capture is.

The "while fighting in rough terrain"-part can be done using Lua, by granting or removing a promotion with <CaptureDefeatedUnits> in GameEvents.UnitSetXY(..)

Forgive my ignorance, but I can't pinpoint what it is you're looking at. I'm looking in CIV5Traits.xml at the Prize Ships promotion, and there is no CaptureDefeatedUnits column. I've dug through the SDK's GameCoreDLL and I can't locate it there, either. I also can't find any dll files related to traits in the Civ 5 folder. Where should I be looking?
 
Forgive my ignorance, but I can't pinpoint what it is you're looking at. I'm looking in CIV5Traits.xml at the Prize Ships promotion, and there is no CaptureDefeatedUnits column. I've dug through the SDK's GameCoreDLL and I can't locate it there, either. I also can't find any dll files related to traits in the Civ 5 folder. Where should I be looking?
Check the <UnitPromotions>-table. Everything regarding unit capturing is through a promotion (The Ottoman trait just happens to give all ships that promotion).

Relevant sections in the game's source code:
Spoiler :

CIV5_UnitPromotions_Expansion.xml
Code:
<Row>
            <Type>PROMOTION_PRIZE_SHIPS</Type>
            <Description>TXT_KEY_PROMOTION_PRIZE_SHIPS</Description>
            <Help>TXT_KEY_PROMOTION_PRIZE_SHIPS_HELP</Help>
            <Sound>AS2D_IF_LEVELUP</Sound>
            <CaptureDefeatedEnemy>true</CaptureDefeatedEnemy>
            <PortraitIndex>59</PortraitIndex>
            <IconAtlas>ABILITY_ATLAS</IconAtlas>
            <PediaType>PEDIA_ATTRIBUTES</PediaType>
            <PediaEntry>TXT_KEY_PROMOTION_PRIZE_SHIPS</PediaEntry>
        </Row>

cvUnit.cpp
Code:
int CvUnit::GetCaptureChance(CvUnit *pEnemy)
{
    int iRtnValue = 0;

    if (m_iCaptureDefeatedEnemyCount > 0 && AreUnitsOfSameType(*pEnemy))
    {
        // Look at ratio of intrinsic combat strengths
        CvUnitEntry *pkEnemyInfo = GC.getUnitInfo(pEnemy->getUnitType());
        if (pkEnemyInfo)
        {
            int iTheirCombat = pkEnemyInfo->GetCombat();

            if (iTheirCombat > 0)
            {
                int iMyCombat = m_pUnitInfo->GetCombat();
                int iComputedChance = GC.getCOMBAT_CAPTURE_MIN_CHANCE() + (int)(((float)iMyCombat / (float)iTheirCombat) * GC.getCOMBAT_CAPTURE_RATIO_MULTIPLIER());
                iRtnValue = min(GC.getCOMBAT_CAPTURE_MAX_CHANCE(), iComputedChance);
            }
        }
    }

    return iRtnValue;
}

cvUnitCombat.cpp
Code:
else if (iAttackerTotalDamageInflicted >= iMaxHP && kAttacker.IsCaptureDefeatedEnemy() && kAttacker.AreUnitsOfSameType(*pkDefender))
        {
            int iCaptureRoll = GC.getGame().getJonRandNum(100, "Capture Enemy Roll");

            if (iCaptureRoll < kAttacker.GetCaptureChance(pkDefender))
            {
                bAdvance = false;
                pkCombatInfo->setDefenderCaptured(true);
            }
        }


EDIT: I realised I got the tag wrong. It's actually <CaptureDefeatedEnemy> :eek2:
 
Check the <UnitPromotions>-table. Everything regarding unit capturing is through a promotion (The Ottoman trait just happens to give all ships that promotion).

Relevant sections in the game's source code:
Spoiler :

CIV5_UnitPromotions_Expansion.xml
Code:
<Row>
            <Type>PROMOTION_PRIZE_SHIPS</Type>
            <Description>TXT_KEY_PROMOTION_PRIZE_SHIPS</Description>
            <Help>TXT_KEY_PROMOTION_PRIZE_SHIPS_HELP</Help>
            <Sound>AS2D_IF_LEVELUP</Sound>
            <CaptureDefeatedEnemy>true</CaptureDefeatedEnemy>
            <PortraitIndex>59</PortraitIndex>
            <IconAtlas>ABILITY_ATLAS</IconAtlas>
            <PediaType>PEDIA_ATTRIBUTES</PediaType>
            <PediaEntry>TXT_KEY_PROMOTION_PRIZE_SHIPS</PediaEntry>
        </Row>

cvUnit.cpp
Code:
int CvUnit::GetCaptureChance(CvUnit *pEnemy)
{
    int iRtnValue = 0;

    if (m_iCaptureDefeatedEnemyCount > 0 && AreUnitsOfSameType(*pEnemy))
    {
        // Look at ratio of intrinsic combat strengths
        CvUnitEntry *pkEnemyInfo = GC.getUnitInfo(pEnemy->getUnitType());
        if (pkEnemyInfo)
        {
            int iTheirCombat = pkEnemyInfo->GetCombat();

            if (iTheirCombat > 0)
            {
                int iMyCombat = m_pUnitInfo->GetCombat();
                int iComputedChance = GC.getCOMBAT_CAPTURE_MIN_CHANCE() + (int)(((float)iMyCombat / (float)iTheirCombat) * GC.getCOMBAT_CAPTURE_RATIO_MULTIPLIER());
                iRtnValue = min(GC.getCOMBAT_CAPTURE_MAX_CHANCE(), iComputedChance);
            }
        }
    }

    return iRtnValue;
}

cvUnitCombat.cpp
Code:
else if (iAttackerTotalDamageInflicted >= iMaxHP && kAttacker.IsCaptureDefeatedEnemy() && kAttacker.AreUnitsOfSameType(*pkDefender))
        {
            int iCaptureRoll = GC.getGame().getJonRandNum(100, "Capture Enemy Roll");

            if (iCaptureRoll < kAttacker.GetCaptureChance(pkDefender))
            {
                bAdvance = false;
                pkCombatInfo->setDefenderCaptured(true);
            }
        }


EDIT: I realised I got the tag wrong. It's actually <CaptureDefeatedEnemy> :eek2:

Apologies for the late reply. I'm going to look into how LUA works more in-depth before I continue development. Thanks for your help.
 
Back
Top Bottom