deanej
Deity
I'm trying to make it so that a specific unit can "repair" its systems for a scenario. I'm using the improvement system for this, basing it off of the Final Frontier starbase code. However, it doesn't work at all. When I try the repair engines build, nothing happens. When I try the repair defensive systems build, I get the following error a couple of turns later:
Here's the code:
I have no idea why this doesn't work. It seems to not like the script data, but then why does the starbase script data work? And if I can't use script data, how do I track the unit/do the required stuff?
Code:
Traceback (most recent call last):
File "CvEventInterface", line 19, in onEvent
File "CvEventManager", line 187, in handleEvent
File "CvFinalFrontierEvents", line 899, in onImprovementBuilt
ArgumentError: Python argument types in
CyUnit.setScriptData(CyUnit)
did not match C++ signature:
setScriptData(class CyUnit {lvalue}, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)
ERR: Python function onEvent failed, module CvEventInterface
Here's the code:
Code:
def onUnitBuildImprovement(self, argsList):
'Unit begins enacting a Build (building an Improvement or Route)'
pUnit, iBuild, bFinished = argsList
iBuildStarbaseID = CvUtil.findInfoTypeNum(gc.getBuildInfo,gc.getNumBuildInfos(),'BUILD_STARBASE')
iBuildEntEngID = CvUtil.findInfoTypeNum(gc.getBuildInfo,gc.getNumBuildInfos(),'BUILD_ENGINE')
iBuildEntDefID = CvUtil.findInfoTypeNum(gc.getBuildInfo,gc.getNumBuildInfos(),'BUILD_WEAPON')
# Starbase WAS built
if (iBuild == iBuildStarbaseID):
pUnit.setScriptData("BuildingStarbase")
elif (iBuild == iBuildEntEngID):
pUnit.setScriptData("RepairEngines")
elif (iBuild == iBuildEntDefID):
pUnit.setScriptData("RepairWeapons")
def onImprovementBuilt(self, argsList):
'Improvement Built'
iImprovement, iX, iY = argsList
iImprovementStarbaseID = CvUtil.findInfoTypeNum(gc.getImprovementInfo,gc.getNumImprovementInfos(),'IMPROVEMENT_STARBASE')
iImprovementEntEngID = CvUtil.findInfoTypeNum(gc.getImprovementInfo,gc.getNumImprovementInfos(),'IMPROVEMENT_ENGINE')
iImprovementEntDefID = CvUtil.findInfoTypeNum(gc.getImprovementInfo,gc.getNumImprovementInfos(),'IMPROVEMENT_WEAPON')
iEntEng = gc.getInfoTypeForString("PROMOTION_ENTENG")
iEntDef = gc.getInfoTypeForString("PROMOTION_ENTDEF")
iUnitConstructShipID = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_CONSTRUCT_SHIP')
# Starbase finished
if (iImprovement == iImprovementStarbaseID):
pPlot = CyMap().plot(iX, iY)
pPlot.setImprovementType(-1)
# Look for Construction Ship on this plot
for iUnitLoop in range(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(iUnitLoop)
if (pUnit.getScriptData() == "BuildingStarbase"):
self.doMakeStarbase(pUnit.getOwner(), iX, iY)
self.aiKillTimerData = [3, pUnit.getOwner(), pUnit.getID()]
elif (iImprovement == iImprovementEntEngID):
pPlot = CyMap().plot(iX, iY)
pPlot.setImprovementType(-1)
for iUnitLoop in range(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(iUnitLoop)
if (pUnit.getScriptData() == "RepairEngines"):
pUnit.setHasPromotion(iEntEng, 1)
elif (iImprovement == iImprovementEntDefID):
pPlot = CyMap().plot(iX, iY)
pPlot.setImprovementType(-1)
for iUnitLoop in range(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(iUnitLoop)
if (pUnit.setScriptData() == "RepairWeapons"):
pUnit.setHasPromotion(iEntDef, 1)
pUnit.setBaseCombatStr(15)
I have no idea why this doesn't work. It seems to not like the script data, but then why does the starbase script data work? And if I can't use script data, how do I track the unit/do the required stuff?