UnitPromotions.TechPrereq how does it work?

chriscisco

Chieftain
Joined
Oct 2, 2014
Messages
13
Hey,

I was looking for a way to make a technology give a promotion, much like optics gives PROMOTION_EMBARKATION.

This is what I did but when I research the technology my units do not receive the promotion. It also does not show up under the technology in the technology tree.

Any help would be appreciated, Thanks.

Spoiler :

<UnitPromotions>
<!-- Need new icon for trenches promotion-->
<Row>
<Type>PROMOTION_TRENCHES</Type>
<Description>TXT_KEY_PROMOTION_TRENCHES</Description>
<Help>TXT_KEY_PROMOTION_TRENCHES_HELP</Help>
<Sound/>
<DefenseMod>50</DefenseMod>
<TechPrereq>TECH_TRENCH_WARFARE</TechPrereq>
<PortraitIndex>57</PortraitIndex>
<CannotBeChosen>true</CannotBeChosen>
<IconAtlas>ABILITY_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTES</PediaType>
<PediaEntry>TXT_KEY_PEDIA_PROMOTION_TRENCHES</PediaEntry>
</Row>
</UnitPromotions>

<UnitPromotions_UnitCombats>
<Row>
<PromotionType>PROMOTION_TRENCHES</PromotionType>
<UnitCombatType>UNITCOMBAT_ARCHER</UnitCombatType>
</Row>
<Row>
<PromotionType>PROMOTION_TRENCHES</PromotionType>
<UnitCombatType>UNITCOMBAT_GUN</UnitCombatType>
</Row>
</UnitPromotions_UnitCombats>


P.S. The full mod WIP

https://onedrive.live.com/redir?resid=8433BEE2D91A6305!208&authkey=!AM8Eu1KwFn9HvWw&ithint=file,7z
 
The prereq means the player (AI or human) can't pick the promotion for their units until they have the tech, and not that all units get the promotion on researching the tech (or when trained after researching the tech), so combining it with CannotBeChoosen makes no sense
 
The reason that PROMOTION_EMBARKATION works for the units getting the promotion when Optics is discovered, is that PROMOTION_EMBARKATION contains the following boolean column command: <AllowsEmbarkation>true</AllowsEmbarkation> , which is also used with PROMOTION_DEFENSIVE_EMBARKATION and PROMOTION_ALLWATER_EMBARKATION.

TECH_OPTICS has <AllowsEmbarking>true</AllowsEmbarking>, which is what instructs the game to give the appropriate promotion(s).

TECH_ASTRONOMY has <EmbarkedAllWaterPassage>true</EmbarkedAllWaterPassage>, which matches up with PROMOTION_ALLWATER_EMBARKATION and its <EmbarkedAllWater>true</EmbarkedAllWater>

..........................................................................................................................................................

Otherwise, all the <TechPrereq> will do is unlock when a player is able to choose the promotion. See PROMOTION_AMBUSH_1.

In the case of PROMOTION_AMBUSH_1 a player also already has to have chosen one of promotions PROMOTION_SHOCK_2 or PROMOTION_DRILL_2 for an individual unit, in addition to the player must have researched TECH_COMBUSTION.
 
Another possibility through lua is to give a dummy building in the capital when a particular tech is discovered, and where the dummy building has <FreePromotion>PROMOTION_X</FreePromotion> as part of its definition within <Buildings>.
 
Alright,

so with lua this is what I have so far the code, I have a couple of questions however.

http://pastebin.com/h7JMwtjp

How exactly does Unit:Promote() work, and how can I check if a player has a tech already, could I use Player:CanResearch(), if so how do I get the tech id from GameInfo.Technologies,
would GameInfo.Technologies["TECH_TRENCH_WARFARE"] work?

Thanks.

Edit: so I took my assumptions and added them into the code, going to test.
Going to debug the code.

Edit: so I tested it and I get no errors, but the units do not get the promotions.

Edit: I have debugged the code and it works in every case, but the units do not get promoted.

my guess is that this is failing, but outside of lua and not reporting an error. I cannot find any documentation on this so I am guessing at it's usage.

unit:Promote("PROMOTION_TRENCHES", unit.ID);
 
Try this instead:
Code:
unit:SetHasPromotion(GameInfoTypes.PROMOTION_TRENCHES, true);

EDIT: As for technology prereqs, you need to use:
Code:
if (Teams[player:GetTeam()]:IsHasTech(GameInfoTypes.TECH_TRENCH_WARFARE)) then

Note: GameInfoTypes.TECH_TRENCH_WARFARE is the same as GameInfo.Technologies["TECH_TRENCH_WARFARE"].ID
 
Thanks,

for the second part, this code fragment works, would it be faster or slower?

Spoiler :
if not player:CanResearch(GameInfoTypes.TECH_TRENCH_WARFARE) then
 
CanResearch() lets you know whether the technology is one you can immediately begin researching (i.e., without needing to research a prerequisite first). IsHasTech() lets you know whether you've learned the technology already.
 
Yes I figured that, which one would be faster code wise?

Considering both will work.

XML/SQL will not work for this apparently, see early posts.
 
Any difference would be incredibly tiny. You're saying you would want to check CanResearch() of a tech that requires Trench Warfare? That seems silly, but I guess it's the same thing.

Depending on what you're trying to do, you could also just use XML or SQL with the TechPrereq column of the UnitPromotions table.
I guess that's moot. I forgot what the original post was asking.
 
Alright, thanks

actually CanResearch returns false, if the tech is already researched, and since the tech is available at the start of each custom scenario I know it can be researched.

I think I will switch to the other method, just in case I use this code were this would not be true.
 
I am giving units a promotion if the player has a tech, I need to give it to all current units and future units.

which is why I have two events hooked in.

http://pastebin.com/zbDDs7RK

Events.TechAcquired
Events.SerialEventUnitCreated

but I have actually got it working now, I can add a promotion to a unit when a tech is researched and to all future units after the tech is researched.
 
Back
Top Bottom