smeagolheart
Monarch
Hey I'm a python pre-noob. I came across the Urban Planner unit from Genetic Era for Warlords (and ViSa Modpack). Urban planner being a Call to Power unit that is like an upgraded settler that spawns a couple buildings and a slightly increased city size. Neat deal, so I've been trying to get it to work in my mod.
I added the unit xml fine, unit shows up in game. XML looks like this:
So it seems that the unit also requires python to do it's thing. Here's the code from the warlords version (I think this is all, let me know if I'm missing something).
UrbanPlanner.py
CvCustomEventManager.py
So I've attempted to work this into my mod's CvEventManager.py but it's not working, probably because I'm a noob pythoner...
EDIT: This part is just a snippet of course corresponding to the onUnitLost area..
Advices?
I added the unit xml fine, unit shows up in game. XML looks like this:
Spoiler :
Code:
<UnitInfo>
<Class>UNITCLASS_URBAN_PLANNER</Class>
<Type>UNIT_URBAN_PLANNER</Type>
<UniqueNames/>
<Special>NONE</Special>
<Capture>UNITCLASS_WORKER</Capture>
<Combat>NONE</Combat>
<Domain>DOMAIN_LAND</Domain>
<DefaultUnitAI>UNITAI_SETTLE</DefaultUnitAI>
<Invisible>NONE</Invisible>
<SeeInvisible>NONE</SeeInvisible>
<Description>TXT_KEY_UNIT_URBAN_PLANNER</Description>
<Civilopedia>TXT_KEY_UNIT_URBAN_PLANNER_PEDIA</Civilopedia>
<Strategy>TXT_KEY_UNIT_URBAN_PLANNER_STRATEGY</Strategy>
<Advisor>ADVISOR_GROWTH</Advisor>
<bAnimal>0</bAnimal>
<bFood>1</bFood>
<bNoBadGoodies>0</bNoBadGoodies>
<bOnlyDefensive>0</bOnlyDefensive>
<bNoCapture>0</bNoCapture>
<bQuickCombat>0</bQuickCombat>
<bRivalTerritory>0</bRivalTerritory>
<bMilitaryHappiness>0</bMilitaryHappiness>
<bMilitarySupport>0</bMilitarySupport>
<bMilitaryProduction>0</bMilitaryProduction>
<bPillage>0</bPillage>
<bSpy>0</bSpy>
<bSabotage>0</bSabotage>
<bDestroy>0</bDestroy>
<bStealPlans>0</bStealPlans>
<bInvestigate>0</bInvestigate>
<bCounterSpy>0</bCounterSpy>
<bFound>1</bFound>
<bGoldenAge>0</bGoldenAge>
<bInvisible>0</bInvisible>
<bFirstStrikeImmune>0</bFirstStrikeImmune>
<bNoDefensiveBonus>0</bNoDefensiveBonus>
<bIgnoreBuildingDefense>0</bIgnoreBuildingDefense>
<bCanMoveImpassable>0</bCanMoveImpassable>
<bCanMoveAllTerrain>0</bCanMoveAllTerrain>
<bFlatMovementCost>0</bFlatMovementCost>
<bIgnoreTerrainCost>0</bIgnoreTerrainCost>
<bNukeImmune>0</bNukeImmune>
<bPrereqBonuses>0</bPrereqBonuses>
<bPrereqReligion>0</bPrereqReligion>
<bMechanized>0</bMechanized>
<bSuicide>0</bSuicide>
<bHiddenNationality>0</bHiddenNationality>
<bAlwaysHostile>0</bAlwaysHostile>
<UnitClassUpgrades/>
<UnitClassTargets/>
<UnitCombatTargets/>
<UnitClassDefenders/>
<UnitCombatDefenders/>
<FlankingStrikes/>
<UnitAIs>
<UnitAI>
<UnitAIType>UNITAI_SETTLE</UnitAIType>
<bUnitAI>1</bUnitAI>
</UnitAI>
</UnitAIs>
<NotUnitAIs/>
<Builds/>
<ReligionSpreads/>
<CorporationSpreads/>
<GreatPeoples/>
<Buildings>
<Building>
<BuildingType>BUILDING_GRANARY</BuildingType>
<bBuilding>1</bBuilding>
</Building>
<Building>
<BuildingType>BUILDING_FORGE</BuildingType>
<bBuilding>1</bBuilding>
</Building>
<Building>
<BuildingType>BUILDING_BARRACKS</BuildingType>
<bBuilding>1</bBuilding>
</Building>
<Building>
<BuildingType>BUILDING_STABLE</BuildingType>
<bBuilding>1</bBuilding>
</Building>
<Building>
<BuildingType>BUILDING_COURTHOUSE</BuildingType>
<bBuilding>1</bBuilding>
</Building>
<Building>
<BuildingType>BUILDING_MARKET</BuildingType>
<bBuilding>1</bBuilding>
</Building>
</Buildings>
<ForceBuildings/>
<HolyCity>NONE</HolyCity>
<ReligionType>NONE</ReligionType>
<StateReligion>NONE</StateReligion>
<PrereqReligion>NONE</PrereqReligion>
<PrereqCorporation>NONE</PrereqCorporation>
<PrereqBuilding>NONE</PrereqBuilding>
<PrereqTech>NONE</PrereqTech>
<TechTypes/>
<BonusType>NONE</BonusType>
<PrereqBonuses/>
<ProductionTraits>
<ProductionTrait>
<ProductionTraitType>TRAIT_IMPERIALIST</ProductionTraitType>
<iProductionTrait>50</iProductionTrait>
</ProductionTrait>
</ProductionTraits>
<Flavors/>
<iAIWeight>0</iAIWeight>
<iCost>100</iCost>
<iHurryCostModifier>0</iHurryCostModifier>
<iAdvancedStartCost>100</iAdvancedStartCost>
<iAdvancedStartCostIncrease>0</iAdvancedStartCostIncrease>
<iMinAreaSize>-1</iMinAreaSize>
<iMoves>2</iMoves>
<bNoRevealMap>0</bNoRevealMap>
<iAirRange>0</iAirRange>
<iAirUnitCap>0</iAirUnitCap>
<iDropRange>0</iDropRange>
<iNukeRange>-1</iNukeRange>
<iWorkRate>0</iWorkRate>
<iBaseDiscover>0</iBaseDiscover>
<iDiscoverMultiplier>0</iDiscoverMultiplier>
<iBaseHurry>0</iBaseHurry>
<iHurryMultiplier>0</iHurryMultiplier>
<iBaseTrade>0</iBaseTrade>
<iTradeMultiplier>0</iTradeMultiplier>
<iGreatWorkCulture>0</iGreatWorkCulture>
<iEspionagePoints>0</iEspionagePoints>
<TerrainImpassables/>
<FeatureImpassables/>
<TerrainPassableTechs/>
<FeaturePassableTechs/>
<iCombat>0</iCombat>
<iCombatLimit>0</iCombatLimit>
<iAirCombat>0</iAirCombat>
<iAirCombatLimit>0</iAirCombatLimit>
<iXPValueAttack>0</iXPValueAttack>
<iXPValueDefense>0</iXPValueDefense>
<iFirstStrikes>0</iFirstStrikes>
<iChanceFirstStrikes>0</iChanceFirstStrikes>
<iInterceptionProbability>0</iInterceptionProbability>
<iEvasionProbability>0</iEvasionProbability>
<iWithdrawalProb>0</iWithdrawalProb>
<iCollateralDamage>0</iCollateralDamage>
<iCollateralDamageLimit>0</iCollateralDamageLimit>
<iCollateralDamageMaxUnits>0</iCollateralDamageMaxUnits>
<iCityAttack>0</iCityAttack>
<iCityDefense>0</iCityDefense>
<iAnimalCombat>0</iAnimalCombat>
<iHillsAttack>0</iHillsAttack>
<iHillsDefense>0</iHillsDefense>
<TerrainNatives/>
<FeatureNatives/>
<TerrainAttacks/>
<TerrainDefenses/>
<FeatureAttacks/>
<FeatureDefenses/>
<UnitClassAttackMods/>
<UnitClassDefenseMods/>
<UnitCombatMods/>
<UnitCombatCollateralImmunes/>
<DomainMods/>
<BonusProductionModifiers/>
<iBombRate>0</iBombRate>
<iBombardRate>0</iBombardRate>
<SpecialCargo>NONE</SpecialCargo>
<DomainCargo>NONE</DomainCargo>
<iCargo>0</iCargo>
<iConscription>0</iConscription>
<iCultureGarrison>0</iCultureGarrison>
<iExtraCost>0</iExtraCost>
<iAsset>1</iAsset>
<iPower>0</iPower>
<UnitMeshGroups>
<iGroupSize>2</iGroupSize>
<fMaxSpeed>1.75</fMaxSpeed>
<fPadTime>1</fPadTime>
<iMeleeWaveSize>2</iMeleeWaveSize>
<iRangedWaveSize>0</iRangedWaveSize>
<UnitMeshGroup>
<iRequired>1</iRequired>
<EarlyArtDefineTag>ART_DEF_UNIT_URBAN_PLANNER</EarlyArtDefineTag>
</UnitMeshGroup>
</UnitMeshGroups>
<FormationType>FORMATION_TYPE_DEFAULT</FormationType>
<HotKey/>
<bAltDown>0</bAltDown>
<bShiftDown>0</bShiftDown>
<bCtrlDown>0</bCtrlDown>
<iHotKeyPriority>0</iHotKeyPriority>
<FreePromotions/>
<LeaderPromotion>NONE</LeaderPromotion>
<iLeaderExperience>0</iLeaderExperience>
</UnitInfo>
So it seems that the unit also requires python to do it's thing. Here's the code from the warlords version (I think this is all, let me know if I'm missing something).
UrbanPlanner.py
Spoiler :
Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
##
## Extra EventHandlers by primem0ver
##
from CvPythonExtensions import *
import CvUtil
import PyHelpers
import Popup as PyPopup
# globals
gc = CyGlobalContext()
unitCity = None
class UrbanPlannerHandler:
def __init__(self):
self.city = None
def onUnitLost(self, argsList):
#print "Running Custom Script"
unit = argsList[0]
handleEvent = 0
if (unit.getUnitType() != gc.getInfoTypeForString("UNIT_URBAN_PLANNER")):
return
else:
#print "Handling urban settler"
#print self.city
if (self.city):
#print "Adding Buildings"
self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_GRANARY"), true)
self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_COURTHOUSE"), true)
self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_MARKET"), true)
self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_AQUEDUCT"), true)
self.city.setPopulation(3)
if (self.city.isCoastal(1)):
self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_HARBOR"), true)
self.city.setHasRealBuilding(gc.getInfoTypeForString("BUILDING_LIGHTHOUSE"), true)
return
def setCity(self, argsList):
city = argsList[0]
self.city = city
#print "City founded: " + city.getName()
CvCustomEventManager.py
Spoiler :
Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
##
## This class is passed an argsList from CvAppInterface.onEvent
## The argsList can contain anything from mouse location to key info
## The EVENTLIST that are being notified can be found
from CvPythonExtensions import *
import CvUtil
import CvScreensInterface
import CvDebugTools
import CvWBPopups
import PyHelpers
import Popup as PyPopup
import CvCameraControls
import CvTopCivs
import CvEventManager
import sys
import Terraform
import TechConquest
import SettlerReligion
import Dome
import UrbanPlanner
import MigrantDestination
gc = CyGlobalContext()
localText = CyTranslator()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo
tf = Terraform.Terraform()
dm = Dome.Dome()
techConquest = TechConquest.TechConquest()
sr = SettlerReligion.SettlerReligion()
#added by primem0ver
up = UrbanPlanner.UrbanPlannerHandler()
md = MigrantDestination.MigrantDestination()
# globals
###################################################
class CvCustomEventManager(CvEventManager.CvEventManager):
def __init__(self):
# initialize base class
self.parent = CvEventManager.CvEventManager
self.parent.__init__(self)
self.Events[7502] = ('RemoveWaterPopup', self.__eventRemoveWaterApply , self.__eventRemoveWaterBegin)
def onImprovementBuilt(self, argsList):
self.parent.onImprovementBuilt(self, argsList);
tf.onImprovementBuilt(argsList)
def onRouteBuilt(self, argsList):
self.parent.onRouteBuilt(self, argsList);
tf.onRouteBuilt(argsList)
def __eventRemoveWaterApply(self, playerID, userData, popupReturn):
tf.eventRemoveWaterApply(playerID, userData, popupReturn)
def __eventRemoveWaterBegin(self, argsList):
tf.eventRemoveWaterBegin(argsList)
def onCityAcquired(self, argsList):
self.parent.onCityAcquired(self, argsList)
techConquest.onCityAcquired(argsList)
def onUnitBuilt(self, argsList):
self.parent.onUnitBuilt(self, argsList)
sr.onUnitBuilt(argsList)
md.onUnitBuilt(argsList)
def onUnitLost(self, argsList):
self.parent.onUnitLost(self, argsList)
#added by primem0ver:
md.onUnitLost(argsList)
up.onUnitLost(argsList)
#original line:
sr.onUnitLost(argsList)
def onCityBuilt(self, argsList):
self.parent.onCityBuilt(self, argsList)
sr.onCityBuilt(argsList)
dm.onCityBuilt(argsList)
#added by primem0ver
up.setCity(argsList)
def onUnitMove(self, argsList):
self.parent.onUnitMove(self, argsList)
md.onUnitMove(argsList)
So I've attempted to work this into my mod's CvEventManager.py but it's not working, probably because I'm a noob pythoner...
EDIT: This part is just a snippet of course corresponding to the onUnitLost area..
Spoiler :
Code:
def onUnitLost(self, argsList):
'Unit Lost'
unit = argsList[0]
player = PyPlayer(unit.getOwner())
## Urban Planner Start ##
if (unit.getUnitType() != CyGlobalContext().getInfoTypeForString("UNIT_URBAN_PLANNER")):
return
else:
if (self.city):
self.city.setHasRealBuilding(CyGlobalContext().getInfoTypeForString("BUILDING_GRANARY"), true)
self.city.setHasRealBuilding(CyGlobalContext().getInfoTypeForString("BUILDING_COURTHOUSE"), true)
self.city.setHasRealBuilding(CyGlobalContext().getInfoTypeForString("BUILDING_MARKET"), true)
self.city.setHasRealBuilding(CyGlobalContext().getInfoTypeForString("BUILDING_AQUEDUCT"), true)
self.city.setPopulation(3)
if (self.city.isCoastal(1)):
self.city.setHasRealBuilding(CyGlobalContext().getInfoTypeForString("BUILDING_HARBOR"), true)
self.city.setHasRealBuilding(CyGlobalContext().getInfoTypeForString("BUILDING_LIGHTHOUSE"), true)
return
## Urban Planner End ##
if (not self.__LOG_UNITLOST):
return
CvUtil.pyPrint('%s was lost by Player %d Civilization %s'
%(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))
Advices?