hi, I would like to insert the Hunter promotion in my modmod direalism invictus, I want to ask you if I can insert it in the modified WarPeace file
this is the string:
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())
## Hunter Promotion Start ##
if pLoser.isAnimal():
if pWinner.isHasPromotion(gc.getInfoTypeForString("PROMOTION_HUNTER")):
pPlayer = gc.getPlayer(pWinner.getOwner())
Capital = pPlayer.getCapitalCity()
Capital.changeFood(pLoser.baseCombatStr() * 3)
## Hunter Promotion End ##
if (not self.__LOG_COMBAT):
return
if playerX and playerX and unitX and playerY:
CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s'
%(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(),
playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))
________________________________________________________________
this is WarPeace with the additions and bug fixes done together with you:
##WarNPeace
###MODDER READ THIS:
###You do not have to change anything in this file
###all changes have to be done in the CvEventManager.
###This file just has to be in the same folder like the CvEventManager.py.
from CvPythonExtensions import *
import sys
import Popup as PyPopup
import CvUtil
import BugGameUtils
gc = CyGlobalContext()
bDebug = False
lEvents = []
lApplicableEvents = []
import BugEventManager
def init():
em = BugEventManager.g_eventManager
em.addEventHandler('LoadGame', loadCustomXML)
em.addEventHandler('GameStart', loadCustomXML)
em.addEventHandler('BeginGameTurn', onBeginGameTurn)
BugGameUtils.addHandler(canDeclareWar)
BugGameUtils.addHandler(cannotFoundCity)
BugGameUtils.addHandler(cannotTrain)
def cannotFoundCity(argsList):
iPlayer, iPlotX, iPlotY = argsList
#City Restriction Part 1 Start
FreeCities = 2
pPlayer = gc.getPlayer(iPlayer)
if ((pPlayer.getNumCities() >= FreeCities)and (pPlayer.getNumCities()>0)):
return True
###City Restriction Part 1 End
return False
def cannotTrain(argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
bIgnoreUpgrades = argsList[5]
###City Restriction Part 2 Start
ePlayer = pCity.getOwner()
pPlayer = gc.getPlayer(ePlayer)
FreeCities = 2
if (eUnit == gc.getInfoTypeForString("UNIT_SETTLER")):
if not bTestVisible:
if (pPlayer.getNumCities() >= FreeCities):
return True
###City Restriction Part 2 End
return False
def canDeclareWar(argsList):
iAttackingTeam, iDefendingTeam = argsList
if iDefendingTeam == 4 or iAttackingTeam == 4:
return False
return True
def loadCustomXML(argsList):
loadEvents("Mods/Realism Invictus/Assets/XML/CustomXML/WarNPeace.xml")
def onBeginGameTurn(argsList):
iGameTurn = argsList[0]
triggerEvents(iGameTurn)
def triggerEvents(iTurn):
iTurn = iTurn+1
iYear = gc.getGame().getTurnYear(iTurn)
if bDebug:CyInterface().addMessage(0,False,15,CyTranslator().getText("trying to trigger at turn "+str(iTurn)+" and year: "+str(iYear),()),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), 1, 1, True,True)
for item in lApplicableEvents:
if bDebug:
CyInterface().addMessage(0,False,15,CyTranslator().getText("inside loop",()),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), 1, 1, True,True)
CyInterface().addMessage(0,False,15,str(item.iDate),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), 1, 1, True,True)
CyInterface().addMessage(0,False,15,str(item.iTurn),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), 1, 1, True,True)
if (item.iDate==iYear) or (item.iTurn==iTurn) and not(iTurn==-1) and not(iYear==0):
if bDebug:CyInterface().addMessage(0,False,15,CyTranslator().getText("it matches",()),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), 1, 1, True,True)
if bDebug:CyInterface().addMessage(0,False,15,item.sType,'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), 1, 1, True,True)
iMaxCiv = gc.getMAX_CIV_PLAYERS ()
iAttacker = -1
iDefender = -1
for i in range(iMaxCiv):
curPlayer = gc.getPlayer(i)
iType = curPlayer.getCivilizationType ()
if (gc.getInfoTypeForString(item.sAttacker)==iType):
iAttacker = i
if (gc.getInfoTypeForString(item.sDefender)==iType):
iDefender = i
if (iAttacker!=-1) and (iDefender!=-1):
pAttackerTeam = gc.getTeam(gc.getPlayer(iAttacker).getTeam())
iDefenderTeam = gc.getPlayer(iDefender).getTeam()
pDefenderTeam = gc.getTeam(iDefenderTeam)
bNoPopup = False
if item.sType =="WAR":
if not pAttackerTeam.isAtWar(iDefenderTeam):
pAttackerTeam.declareWar(iDefenderTeam,False,WarPlanTypes.WARPLAN_TOTAL)
bNoPopup = True
pAttackerTeam.setPermanentWarPeace(iDefenderTeam,True)
if item.sType=="PEACE":
if pAttackerTeam.isAtWar(iDefenderTeam):
pAttackerTeam.makePeace(iDefenderTeam)
bNoPopup=True
pAttackerTeam.setPermanentWarPeace(iDefenderTeam,True)
if pAttackerTeam.isHuman() and bNoPopup:
addPopup(item.sMessage,iAttacker)
if pDefenderTeam.isHuman() and bNoPopup:
addPopup(item.sMessage,iDefender)
def addPopup(sText,iPlayer):
if sText!="-1" and iPlayer!=-1:
pPlayer = gc.getPlayer(iPlayer)
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_TEXT)
szText = CyTranslator().getText(sText, ())
popupInfo.setText(szText)
popupInfo.addPopup(iPlayer)
def loadEvents(sFilePath):
del lEvents[:]
MyFile=open(sFilePath)
for CurString in MyFile.readlines():
if "Attacker" in CurString:
CurEvent = Events()
CurEvent.sAttacker = CutString(CurString)
if "Defender" in CurString:
CurEvent.sDefender = CutString(CurString)
if "Type" in CurString:
CurEvent.sType = CutString(CurString)
if "Map" in CurString:
CurEvent.sMap = CutString(CurString)
if "Date" in CurString:
CurEvent.iDate = int(CutString(CurString))
if "Turn" in CurString:
CurEvent.iTurn = int(CutString(CurString))
if "Message" in CurString:
CurEvent.sMessage = CutString(CurString)
lEvents.append(CurEvent)
MyFile.close()
if bDebug: print "all events have been read"
cleanEvents()
def cleanEvents():
del lApplicableEvents[:]
sMapName = getMapname()
iYear = gc.getGame().getGameTurnYear()
iTurn = gc.getGame().getGameTurn ()
lCivs = getCivs()
if bDebug:CyInterface().addMessage(0,False,15,CyTranslator().getText("cleaning",()),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), 1, 1, True,True)
for item in lEvents:
if item.sMap!=sMapName:continue
if (item.iDate<iYear) and (item.iDate!=0):continue
if (item.iTurn<iTurn) and (item.iTurn!=-1):continue
if bDebug:CyInterface().addMessage(0,False,15,CyTranslator().getText("before civ check",()),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), 1, 1, True,True)
if (gc.getInfoTypeForString(item.sAttacker) in lCivs) and (gc.getInfoTypeForString(item.sDefender) in lCivs):
lApplicableEvents.append(item)
if bDebug:CyInterface().addMessage(0,False,15,CyTranslator().getText("event is on list",()),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), 1, 1, True,True)
def getMapname():
MapName = CyMap().getMapScriptName ()
if (".civ" in MapName) or(".Civ" in MapName):
if "civbeyondswordwbsave" in MapName:
MapName = MapName[0:-21]
if "CivBeyondSwordWBSave" in MapName:
MapName = MapName[0:-21]
if "CivWarlordsWBSave" in MapName:
MapName = MapName[0:-18]
if "Civ4WorldBuilderSave" in MapName:
MapName = MapName[0:-21]
if "civ4worldbuildersave" in MapName:
MapName = MapName[0:-21]
return MapName
else:
return "-1"
def getCivs():
iMaxCiv = gc.getMAX_CIV_PLAYERS ()
lCivs = []
del lCivs[:]
for i in range(iMaxCiv):
curPlayer = gc.getPlayer(i)
iType = curPlayer.getCivilizationType ()
lCivs.append(iType)
return lCivs
###generic string cutting function
###first < and > at the end are cut of, then the other
###> and < are searched, and what is between is used as value
def CutString(string):
print "Cutting"
string = str(string)
string = string.strip()
string = string[2:-1]
BeginPos=-1
EndPos = -1
for i in xrange(len(string)):
if string==">":
BeginPos=i
elif string=="<":
EndPos=i
break
else:
return "-1"
NewString = string[BeginPos+1:EndPos]
return str(NewString)
class Events:
def __init__(self):
self.sAttacker = 0
self.sDefender = 0
self.sType = 0
self.sMap = 0
self.iDate = 0
self.iTurn = 0
self.sMessage = ""