• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

How to check the Extra Attack Percentage from a Feature

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.
 
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
 
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

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.
 
FeatureAttackModifier Func is used to get the Modifier
it can not set the value

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);
 
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:getExtraFeatureDefensePercent(FeatureTypes eIndex);
int unit:featureAttackModifier(FeatureTypes eFeature);

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.
 
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.

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.
 
Does one of them return the correct value when you change it in the XML? If so, that's the one you need
 
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.
 
Highly doubt it, but you can give the unit a custom promotion you prepared for this.
 
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.
 
Back
Top Bottom