Afforess
The White Wizard
Okay, so EmperorFool, advised me that I wasn't supposed to be editing the CvEventManager in BUG 4.0. So, I'm trying to move the modcomp, War Prizes into my own module and load it from the init.xml file. I've got the War Prizes code pretty well isolated, in a python file named WarPrizes.py. Then, I added WarPrizes to the init.xml. I load the game and start a map. Initially, I got a few errors, but once I fixed those, I tested out War Prizes setting the odds to 100%. Nothing happened. (For those who aren't familiar, War Prizes gives a percent chance, out of 100, that an enemy ship will be captured after successful naval combat.) So, I'm assuming WarPrizes isn't really being loaded, or at least not called when it needs to be, but, because I pretty much have no python abilities, and am very new to BUG 4.0, I haven't the slightest clue as to what I'm doing wrong.
The Init.xml addition is this:
Here's the contents of WarPrizes.py
The Init.xml addition is this:
Code:
<events module="WarPrizes"> </events>
Here's the contents of WarPrizes.py
Code:from CvPythonExtensions import * import CvEventInterface import CvUtil import BugUtil gc = CyGlobalContext() class WarPrizes: def __init__(self, eventManager): eventManager.addEventHandler("Combat Result", self.onCombatResult) def onCombatResult(self, argsList): 'Combat Result' pWinner,pLoser = argsList playerX = PyPlayer(pWinner.getOwner()) unitX = PyInfo.UnitInfo(pWinner.getUnitType()) playerY = PyPlayer(pLoser.getOwner()) unitY = PyInfo.UnitInfo(pLoser.getUnitType()) ## mechaerik War Prize ModComp START## pPlayer = gc.getPlayer(pWinner.getOwner()) pPlayerLoser = gc.getPlayer(pLoser.getOwner()) if not (gc.getPlayer(pWinner.getOwner()).isBarbarian()): if (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_WOODEN_SHIPS")) or (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_STEAM_SHIPS")) or (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_DIESEL_SHIPS")) or (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_NUCLEAR_SHIPS")): if (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_WOODEN_SHIPS")) or (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_STEAM_SHIPS")) or (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_DIESEL_SHIPS")) or (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_NUCLEAR_SHIPS")): if not (unitX.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_PRIVATEER")): if not (unitY.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_PRIVATEER")): if CyGame().getSorenRandNum(100, "Bob") <= 100: iUnit = pLoser.getUnitType() newUnit = pPlayer.initUnit(pLoser.getUnitType(), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION) newUnit.finishMoves() newUnit.setDamage(50, pWinner.getOwner()) CyInterface().addMessage(pWinner.getOwner(),false,20,CyTranslator().getText("We've taken an enemy ship as a prize!",()),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(gc.getInfoTypeForString("COLOR_BLUE")), pWinner.getX(), pWinner.getY(), True,True) CyInterface().addMessage(pLoser.getOwner(),false,20,CyTranslator().getText("One of our ships has been taken as a prize!",()),'',0,'Art/Interface/Buttons/General/warning_popup.dds',ColorTypes(gc.getInfoTypeForString("COLOR_RED")), pLoser.getX(), pLoser.getY(), True,True) ## War Prize Modcomp END##