How to add custom script to mod?

anon176

Chieftain
Joined
Sep 2, 2012
Messages
2
I want to modify the ships in civ4 bts in order to be a little bit more realistic in my point of view... So, for this, I commented out from the .xml:

<!-- <TerrainImpassable>
<TerrainType>TERRAIN_OCEAN</TerrainType>
<bTerrainImpassable>1</bTerrainImpassable>
</TerrainImpassable> -->

for UNITCLASS_WORKBOAT, UNITCLASS_GALLEY and UNITCLASS_TRIREME and now I want to add a 25% chance of it to die in the ocean terrain. The point is to make it possible to do some ocean travels just like it is known to science today that some ancient civilizations did (the vikings for example, came to America around 1000AC).
The XML worked and now the ships can travel abroad, however I couldn't yet add a script to kill the ships (like, in the end of turn event, for example? or in the moveUnit event, etc...). What i've tried so far:

in Mods/MyMod/Assets/Python/CvEventManager.py I copied and pasted the from BTS and overwritten the function in scope:

def onUnitMove(self, argsList):
'unit move'
self.addPopup("Debug", "Init onUnitMove")
pPlot,pUnit,pOldPlot = argsList
player = PyPlayer(pUnit.getOwner())
unitInfo = PyInfo.UnitInfo(pUnit.getUnitType())
if (not self.__LOG_MOVEMENT):
self.addPopup("Debug", "not self.__LOG_MOVEMENT")
return
if player and unitInfo:
CvUtil.pyPrint('Player %d Civilization %s unit %s is moving to %d, %d'
%(player.getID(), player.getCivilizationName(), unitInfo.getDescription(),
pUnit.getX(), pUnit.getY()))

iOceanType = CvUtil.findInfoTypeNum(gc.getTerrainInfo,gc.getNumTerrainInfos(),'TERRAIN_OCEAN')

unitType = pUnit.getUnitType()

self.addPopup("Debug unitType", unitType)

if pPlot.getTerrainType() == iOceanType and ( unitType == gc.getInfoTypeForString("UNIT_GALLEY") or unitType == gc.getInfoTypeForString("UNIT_TRIREME") or unitType == gc.getInfoTypeForString("UNIT_WORKBOAT") ) :
randomNum = random.randint(0,100)

if randomNum > 80:
if(player.isHuman()):
pUnit.centerCamera()
self.addPopup("Sink :(", "The ship couldn't handle the deep ocean and sank")
pUnit.kill(false, -1)
else:
if(player.isHuman()):
pUnit.centerCamera()
self.addPopup("Warning", "The ship is enterning in deep waters and can sink")



However, the code that runs in the mod seems to be the original from BTS​
 
Top Bottom