How to check the Extra Attack Percentage from a Feature

Discussion in 'Civ5 - SDK / LUA' started by martijnaikema, Jan 3, 2011.

  1. martijnaikema

    martijnaikema Warlord

    Joined:
    Oct 30, 2010
    Messages:
    111
    Can someone help me on how to adjust the Extra Attack Percentage from a Feature.

    Say I want a unit to get an attack bonus when he is on a Forest-tile with a river.

    I know how to read an Attack Percentage when it is set in the XML-file via <UnitPromotions> - <Attack>

    local pUnit = UI.GetHeadSelectedUnit();
    local pPlot = pUnit:GetPlot();
    local pFeature = pPlot:GetFeatureType();
    local pBonus = pUnit:GetExtraFeatureAttackPercent(pFeature);

    print (pBonus)

    But say I want to adjust this percentage from 25 to 50 when the plot has a river. How would I do that? I guess I would need the FeatureAttackModifier. In the wiki it is defiened as:

    int unit:featureAttackModifier(FeatureTypes eFeature);

    So I guess I should check if there is a river on the plot:
    pPlot:IsRiver

    And then change the bonus with something like:
    pUnit:FeatureAttackModifier(pFeature, 50);

    But when I try this and I read it after updating, it is not changed. I guess I am doing something wrong. Hope someone can help me out.
     
  2. alpaca

    alpaca King of Ungulates

    Joined:
    Aug 3, 2006
    Messages:
    2,322
    Are you sure the game is actually using your percentages? The strength and damage displays should be correct if the logic works. Verify this before making the UI display your stuff
     
  3. Seraphim8400

    Seraphim8400 Warlord

    Joined:
    Nov 7, 2010
    Messages:
    112
    FeatureAttackModifier Func is used to get the Modifier
    it can not set the value
     
  4. martijnaikema

    martijnaikema Warlord

    Joined:
    Oct 30, 2010
    Messages:
    111
    The game is indeed showing the percentages I added in the XML-file. I added:
    Spoiler :

    <UnitPromotions>
    <Row>
    <Type>PROMOTION_WATERGEUS</Type>
    <Description>TXT_KEY_PROMOTION_WATERGEUS</Description>
    <Help>TXT_KEY_PROMOTION_WATERGEUS_HELP</Help>
    <Sound>AS2D_IF_LEVELUP</Sound>
    <PortraitIndex>57</PortraitIndex>
    <IconAtlas>ABILITY_ATLAS</IconAtlas>
    <PediaType>PEDIA_ATTRIBUTES</PediaType>
    <PediaEntry>TXT_KEY_PEDIA_WATERGEUS</PediaEntry>
    </Row>
    </UnitPromotions>
    <UnitPromotions_Features>
    <Row>
    <PromotionType>PROMOTION_WATERGEUS</PromotionType>
    <FeatureType>FEATURE_MARSH</FeatureType>
    <Defense>25</Defense>
    <Attack>25</Attack>
    </Row>
    <Row>
    <PromotionType>PROMOTION_WATERGEUS</PromotionType>
    <FeatureType>FEATURE_OASIS</FeatureType>
    <Defense>25</Defense>
    <Attack>25</Attack>
    </Row>
    </UnitPromotions_Features>


    Both the Oasis and Marsh get their promotion and they show up in the Enemy Unit Panel.
     
  5. martijnaikema

    martijnaikema Warlord

    Joined:
    Oct 30, 2010
    Messages:
    111
    I thought GetExtraFeatureAttackPercent is used to get the modifier. Can you tell me the difference between FeatureAttackModifier and GetExtraFeatureAttackPercent?

    I checked both in the modiki:
    int unit:getExtraFeatureAttackPercent(FeatureTypes eIndex);
    int unit:featureAttackModifier(FeatureTypes eFeature);
     
  6. alpaca

    alpaca King of Ungulates

    Joined:
    Aug 3, 2006
    Messages:
    2,322
    One is attack one is defence, the game uses both. You can set a unit that gets only a defensive bonus in a forest, for example. The question is not if the promotion shows up, however, but if it modifies the strength the game shows. You can write arbitrary stuff to the UI, that doesn't guarantee it does anything under the hood.
     
  7. martijnaikema

    martijnaikema Warlord

    Joined:
    Oct 30, 2010
    Messages:
    111
    Lol I see I posted the wrong LUA object. It should have been:
    int unit:getExtraFeatureAttackPercent(FeatureTypes eIndex);
    int unit:featureAttackModifier(FeatureTypes eFeature);

    I can't change the FeatureAttackPercent through LUA. I thought one of the objects would let me change it, but it seems that it is not possible.
     
  8. alpaca

    alpaca King of Ungulates

    Joined:
    Aug 3, 2006
    Messages:
    2,322
    Does one of them return the correct value when you change it in the XML? If so, that's the one you need
     
  9. martijnaikema

    martijnaikema Warlord

    Joined:
    Oct 30, 2010
    Messages:
    111
    Yes, the correct value is returned with GetExtraFeatureAttackPercent. But I was wondering if it would also be possible to adjust the value (through LUA and not XML). I thought I would use pUnit:FeatureAttackModifier(pFeature, 50), but that does not seem to work.
     
  10. alpaca

    alpaca King of Ungulates

    Joined:
    Aug 3, 2006
    Messages:
    2,322
    Highly doubt it, but you can give the unit a custom promotion you prepared for this.
     
  11. martijnaikema

    martijnaikema Warlord

    Joined:
    Oct 30, 2010
    Messages:
    111
    I know. But it is not possible to give this promotion for fighting in a river tile. I am trying to get a workaround for this and I am almost there. The only thing I don't know yet how to display the bonus ("Attack into Rivertiles" "50") in the EnemyUnitPanel.

    What I want to do is adjust the BaseCombatStrength of a Unit when it is on a river. It is complicated though cause a bonus a unit gets is always calculated from this BaseCombatStrength.
     

Share This Page