help with code, please (promotion for water units)

hrochland

Prince
Joined
Apr 9, 2006
Messages
2,512
Location
Czech Kingdom
Hi all programmers!!
Help Please...
I made building which has add to the water units promotion for multiple attack.
Can someone write in python code for it, please?
Thank you very much

HROCHland
 
Giving promotion only to currently existing units is quite simple:
Ex.:
Spoiler :

player = gc.getPlayer(iPlayer)
promotion = CvUtil.findInfoTypeNum(gc.getPromotionInfo,gc.getNumPromotionInfos(),'PROMOTION_BLITZ')
unitCombatNaval = gc.getInfoTypeForString("UNITCOMBAT_NAVAL")
(unit, iter) = player.firstUnit(false)
while (unit):
if unit.getUnitCombatType() == unitCombatNaval:
unit.setHasPromotion(promotion,true)
(unit, iter) = player.nextUnit(iter, false)


If you want an effect that gives that promotion to both existing and future units of a certain type (like the Axeman Shock event).....
If you want to do it in Python, this is a bit more difficult, and I'm currently in trouble too.



Maybe, the easiest way to have a similar effect is to use an event, which is triggered when you have that building, and has this effect in the Event infos:


Spoiler :

<UnitCombatPromotions>
<UnitCombatPromotion>
<UnitCombat>UNITCOMBAT_NAVAL</UnitCombat>
<UnitPromotion>PROMOTION_BLITZ</UnitPromotion>
</UnitCombatPromotion>
</UnitCombatPromotions>
 
WOW, thanks, ViterboKnight.
Unfortunately I´m not programmer and don´t know where I must paste your code. Can you, please, advice me more? :please:
In BtS is not possibility give to naval unit PROMOTION_BLITZ and I very desire set right this game error by my new national wander.

I tried set it in xml but game give in place of blitz Promotion Medic I :( :( :(
 
Ok, you can do this:
in the Python\EntryPoints folder, you can create your file, copying one of the existing ones and renaming it as you like (eg, MyPythonScripts.py).
Here, you can write the headings

Spoiler :

import CvUtil
from CvPythonExtensions import *

gc = CyGlobalContext()
localText = CyTranslator()


and your functions

Spoiler :

def GivePromotionToNavalUnits(iPlayer):

player = gc.getPlayer(iPlayer)
promotion = CvUtil.findInfoTypeNum(gc.getPromotionInfo,gc.getN umPromotionInfos(),'PROMOTION_BLITZ')
unitCombatNaval = gc.getInfoTypeForString("UNITCOMBAT_NAVAL")
(unit, iter) = player.firstUnit(false)
while (unit):
if unit.getUnitCombatType() == unitCombatNaval:
unit.setHasPromotion(promotion,true)​
(unit, iter) = player.nextUnit(iter, false)​



Now, all you have to do is call this function every time a new turn starts for each player.
In the CvEventManager.py file, you can find these events.
Edit this file, and first add a reference to your new file, adding a new "import" clause.

Spoiler :

import CvWBPopups
import PyHelpers
import Popup as PyPopup
import CvCameraControls
import CvTopCivs
import MyPythonScripts
import sys
import CvWorldBuilderScreen
import CvAdvisorUtils
import CvTechChooser


Then, find the "onBeginPlayerTurn" function, and add a new line after the "iGameTurn, iPlayer = argsList", writing:

MyPythonScripts.GivePromotionToNavalUnits(iPlayer)

That's all!! I hope there are no errors!! :)
 
Awesome, I will try it today evening at home. Thank you very much.
How can the game check out that just in the city with this building is the possibility to give promotion blitz to the water unit? Please?
 
why didn't you just give blitz to water units?

Hi, Ekmek. :) I want not blitz for all water units. I've been thinking that advanced national wander what give blitz to units trained in one city per nation with wander is good solution...
Problem is that I himself can not write it... I´m not programmer :(

Can somebody help me. please????? :please: :please:
 
Back
Top Bottom