Olleus
Deity
Incase anybody here wanted to know the game uses 1.5 as the square root of 2. And when using the getPathDistance function (which finds the passable distance between 2 plots) it does use pythagoras. Just a very inacurate value.
elif(iImprovement==lowerelev):
if(pPlot.getPlotType()==PlotTypes.PLOT_LAND):
numberofunits = pPlot.getNumUnits()
while(numberofunits > 0):
pPlot.getUnit(0).jumpToNearestValidPlot()
numberofunits = pPlot.getNumUnits()
pPlot.setPlotType(PlotTypes.PLOT_OCEAN, true, true)
else:
pPlot.setPlotType(PlotTypes.PLOT_LAND, true, true)
if(pPlot.getTerrainType()==gc.getInfoTypeForString("TERRAIN_DESERT") and pPlot.isRiver()):
pPlot.setFeatureType(gc.getInfoTypeForString("FEATURE_FLOOD_PLAINS"), 0)
pPlot.setImprovementType(-1)
def onCityBuilt(self, argsList):
'For player 1, create a Warrior (index 17) in every city that is built'
city = argsList[0]
if city.getOwner() == 1:
city.getOwner().initUnit(17, city.getX(), city.getY(), UnitAITypes.NO_UNITAI)
The Butler said:Hey I was wondering if anyone can help me...
if pLoser.getUnitType() == gc.getInfoTypeForString('UNIT_PYRE_ZOMBIE'):
pPlot = pWinner.plot()
point = pPlot.getPoint()
for i in range(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(i)
iRnd = CyGame().getSorenRandNum(30, "Bob") - 10
if pUnit.isHasPromotion('PROMOTION_MAGIC_RESISTANCE'):
iRnd = iRnd - 10
if pUnit.isHasPromotion('PROMOTION_FIRE_RESISTANCE'):
iRnd = iRnd - 10
if pUnit.isHasPromotion('PROMOTION_VULNERABLE_TO_FIRE'):
iRnd = iRnd + 10
if iRnd >= 1:
pUnit.setDamage(pUnit.getDamage() + iRnd, True)
CyEngine().triggerEffect(cf.FFHgetEffectInfo('EFFECT_ARTILLERY_SHELL_EXPLODE'),point)
CyAudioGame().Play3DSound("AS3D_UN_GRENADE_EXPLODE",point.x,point.y,point.z)
Lord Olleus said:'bob' is the name of the random number generated and is only used by the debug files. How exactly do you create new missions in python? I've heard of mods where a unit could be used to create another unit but how do you do this *cough* Kael-I-know-you-did-this *cough*
if iPromotion == gc.getInfoTypeForString('PROMOTION_SUMMON_DEMON'):
newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_DEMON'), pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI)
pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUMMON_DEMON'), False)
cf.FFHApplySpellMods(newUnit, pUnit)
## FU edit start -- append Turns to Complete
iCulRate = pHeadSelectedCity.getCommerceRate(CommerceTypes.COMMERCE_CULTURE)
if ( iCulRate > 0 ):
iCulNext = pHeadSelectedCity.getCultureThreshold()
iCulNow = pHeadSelectedCity.getCulture(pHeadSelectedCity.getOwner())
iCulTurns = (iCulNext-iCulNow+iCulRate-1)/iCulRate
szTurnsToComplete = " %d Turns" %(iCulTurns)
szBuffer = szBuffer + szTurnsToComplete
szTurnsToComplete = ""
## FU edit end
screen.setLabel( "CultureText", "Background", szBuffer, CvUtil.FONT_CENTER_JUSTIFY, 125, yResolution - 184, -1.3, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
## FU edit start -- append turns to completion
iGPRate = pHeadSelectedCity.getGreatPeopleRate()
if ( iGPRate > 0 ):
iGPNext = gc.getPlayer( pHeadSelectedCity.getOwner() ).greatPeopleThreshold()
iGPNow = pHeadSelectedCity.getGreatPeopleProgress()
iGPTurns = (iGPNext-iGPNow+iGPRate-1)/iGPRate
szTurnsToComplete = " %d Turns" %(iGPTurns)
szBuffer = szBuffer + szTurnsToComplete
szTurnsToComplete = ""
## FU edit end
screen.setLabel( "GreatPeopleText", "Background", szBuffer, CvUtil.FONT_CENTER_JUSTIFY, xResolution - 146, yResolution - 176, -1.3, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
def startWar(iPlayer,i2Player):
iTeam = gc.getPlayer(iPlayer).getTeam()
i2Team = gc.getPlayer(i2Player).getTeam()
eTeam = gc.getTeam(iTeam)
if (eTeam.isAtWar(i2Team) == False and iTeam != i2Team):
eTeam.declareWar(i2Team, False)
def getPlotHealFactor(pUnit):
# heal rates for certain areas. They are usually stored in the GlobalDefines.XML but can't be read out with a standard API function.
# So I placed them here as constants.
ENEMY_HEAL_RATE = 5
NEUTRAL_HEAL_RATE = 10
FRIENDLY_HEAL_RATE = 15
CITY_HEAL_RATE = 20
# set/reset some variables
pPlot = pUnit.plot()
iSameTileHealFactor = 0
iAdjacentTileHealFactor = 0
iBuildingHealFactor = 0
iSelfHealFactor = 0
iPromotionHealFactor = 0
iTileHealFactor = 0
iActivePlayer = CyGame().getActivePlayer()
pActivePlayer = gc.getPlayer(iActivePlayer)
iActivePlayerTeam = pActivePlayer.getTeam()
eDomain = gc.getUnitInfo(pUnit.getUnitType()).getDomainType()
# a sea or air unit in a city, behaves like a land unit
if pPlot.isCity():
eDomain = DomainTypes.DOMAIN_LAND
# calculate the adjacent-tile heal-factor caused by other units (only the unit with the highest factor counts)
for dx in range(-1, 2):
for dy in range(-1, 2):
# ignore same tile. Adjacent-tile healing does not work on the same tile.
if not (dx == 0 and dy == 0):
pLoopPlot = CyMap().plot(pPlot.getX()+dx, pPlot.getY()+dy)
# loop through all units on the plot
for i in range(pLoopPlot.getNumUnits()):
pLoopUnit = pLoopPlot.getUnit(i)
eLoopUnitDomain = gc.getUnitInfo(pLoopUnit.getUnitType()).getDomainType()
# a sea or air unit in a city, behaves like a land unit
if ((eDomain == DomainTypes.DOMAIN_SEA) or (eDomain == DomainTypes.DOMAIN_AIR)) and pLoopPlot.isCity():
eLoopUnitDomain = DomainTypes.DOMAIN_LAND
# adjacent-tile heal does only work if the units have the same domain type
if (eDomain == eLoopUnitDomain):
if (pLoopUnit.getTeam() == iActivePlayerTeam):
if (pLoopUnit.getAdjacentTileHeal() > iAdjacentTileHealFactor):
iAdjacentTileHealFactor = pLoopUnit.getAdjacentTileHeal()
# calculate the same-tile heal-factor caused by other or same unit (only the unit with the highest factor counts)
# the same-tile healing is also a kind of self-healing. Means : the promotion Medic I has also effect on the owner unit
for i in range(pPlot.getNumUnits()):
pLoopUnit = pPlot.getUnit(i)
eLoopUnitDomain = gc.getUnitInfo(pLoopUnit.getUnitType()).getDomainType()
# a sea or air unit in a city, behaves like a land unit
if pLoopPlot.isCity():
eLoopUnitDomain = DomainTypes.DOMAIN_LAND
# same tile heal does only work if the units are of the same domain type
if (eDomain == eLoopUnitDomain):
if (pLoopUnit.getTeam() == iActivePlayerTeam):
if (pLoopUnit.getSameTileHeal() > iSameTileHealFactor):
iSameTileHealFactor = pLoopUnit.getSameTileHeal()
# only the highest value counts
iTileHealFactor = max(iAdjacentTileHealFactor, iSameTileHealFactor)
# calculate the self heal factor by the location and promotion
iTeam = pPlot.getTeam()
pTeam = gc.getTeam(iTeam)
iSelfHealFactor = NEUTRAL_HEAL_RATE
iPromotionHealFactor = pUnit.getExtraNeutralHeal()
if pPlot.isCity():
iSelfHealFactor = CITY_HEAL_RATE
iPromotionHealFactor = pUnit.getExtraFriendlyHeal()
elif (iTeam == iActivePlayerTeam):
iSelfHealFactor = FRIENDLY_HEAL_RATE
iPromotionHealFactor = pUnit.getExtraFriendlyHeal()
elif (iTeam != TeamTypes.NO_TEAM):
if (pTeam.isAtWar(iActivePlayerTeam)):
iSelfHealFactor = ENEMY_HEAL_RATE
iPromotionHealFactor = pUnit.getExtraEnemyHeal()
# calculate the heal factor by city buildings
if pPlot.isCity():
if (pPlot.getTeam() == iActivePlayerTeam):
pCity = pPlot.getPlotCity()
# loop for all buldings
for iBuilding in range(gc.getNumBuildingClassInfos()):
# check if city has that building
if pCity.hasBuilding(iBuilding):
# sum up all heal rates
iBuildingHealFactor += gc.getBuildingInfo(iBuilding).getHealRateChange()
# return the sum of all heal factors
return iTileHealFactor + iBuildingHealFactor + iSelfHealFactor + iPromotionHealFactor
# heal rates for certain areas. They are usually stored in the GlobalDefines.XML but can't be read out with a standard API function.
# So I placed them here as constants.
ENEMY_HEAL_RATE = 5
NEUTRAL_HEAL_RATE = 10
FRIENDLY_HEAL_RATE = 15
CITY_HEAL_RATE = 20
# set/reset some variables
pPlot = pUnit.plot()
iSameTileHealFactor = 0
iAdjacentTileHealFactor = 0
iBuildingHealFactor = 0
iSelfHealFactor = 0
iPromotionHealFactor = 0
iTileHealFactor = 0
iActivePlayer = CyGame().getActivePlayer()
pActivePlayer = gc.getPlayer(iActivePlayer)
iActivePlayerTeam = pActivePlayer.getTeam()
eDomain = gc.getUnitInfo(pUnit.getUnitType()).getDomainType()
# a sea or air unit in a city, behaves like a land unit
if pPlot.isCity():
eDomain = DomainTypes.DOMAIN_LAND
# calculate the adjacent-tile heal-factor caused by other units (only the unit with the highest factor counts)
for dx in range(-1, 2):
for dy in range(-1, 2):
# ignore same tile. Adjacent-tile healing does not work on the same tile.
if not (dx == 0 and dy == 0):
pLoopPlot = CyMap().plot(pPlot.getX()+dx, pPlot.getY()+dy)
# loop through all units on the plot
for i in range(pLoopPlot.getNumUnits()):
pLoopUnit = pLoopPlot.getUnit(i)
eLoopUnitDomain = gc.getUnitInfo(pLoopUnit.getUnitType()).getDomainType()
# a sea or air unit in a city, behaves like a land unit
if pLoopPlot.isCity():
eLoopUnitDomain = DomainTypes.DOMAIN_LAND
# adjacent-tile heal does only work if the units have the same domain type
if (eDomain == eLoopUnitDomain):
if (pLoopUnit.getTeam() == iActivePlayerTeam):
if (pLoopUnit.getAdjacentTileHeal() > iAdjacentTileHealFactor):
iAdjacentTileHealFactor = pLoopUnit.getAdjacentTileHeal()
# calculate the same-tile heal-factor caused by other or same unit (only the unit with the highest factor counts)
# the same-tile healing is also a kind of self-healing. Means : the promotion Medic I has also effect on the owner unit
for i in range(pPlot.getNumUnits()):
pLoopUnit = pPlot.getUnit(i)
eLoopUnitDomain = gc.getUnitInfo(pLoopUnit.getUnitType()).getDomainType()
# a sea or air unit in a city, behaves like a land unit
if pLoopPlot.isCity():
eLoopUnitDomain = DomainTypes.DOMAIN_LAND
# same tile heal does only work if the units are of the same domain type
if (eDomain == eLoopUnitDomain):
if (pLoopUnit.getTeam() == iActivePlayerTeam):
if (pLoopUnit.getSameTileHeal() > iSameTileHealFactor):
iSameTileHealFactor = pLoopUnit.getSameTileHeal()
# only the highest value counts
iTileHealFactor = max(iAdjacentTileHealFactor, iSameTileHealFactor)
# calculate the self heal factor by the location and promotion
iTeam = pPlot.getTeam()
pTeam = gc.getTeam(iTeam)
iSelfHealFactor = NEUTRAL_HEAL_RATE
iPromotionHealFactor = pUnit.getExtraNeutralHeal()
if pPlot.isCity():
iSelfHealFactor = CITY_HEAL_RATE
iPromotionHealFactor = pUnit.getExtraFriendlyHeal()
elif (iTeam == iActivePlayerTeam):
iSelfHealFactor = FRIENDLY_HEAL_RATE
iPromotionHealFactor = pUnit.getExtraFriendlyHeal()
elif (iTeam != TeamTypes.NO_TEAM):
if (pTeam.isAtWar(iActivePlayerTeam)):
iSelfHealFactor = ENEMY_HEAL_RATE
iPromotionHealFactor = pUnit.getExtraEnemyHeal()
# calculate the heal factor by city buildings
if pPlot.isCity():
if (pPlot.getTeam() == iActivePlayerTeam):
pCity = pPlot.getPlotCity()
# loop for all buldings
for iBuilding in range(gc.getNumBuildingClassInfos()):
# check if city has that building
if pCity.hasBuilding(iBuilding):
# sum up all heal rates
iBuildingHealFactor += gc.getBuildingInfo(iBuilding).getHealRateChange()
# return the sum of all heal factors
return iTileHealFactor + iBuildingHealFactor + iSelfHealFactor + iPromotionHealFactor
if (eUnitDomain == DomainTypes.DOMAIN_AIR):
fCurrStrength = float(pUnit.airCurrCombatStr()*0.01)
fMaxStrength = float(pUnit.airMaxCombatStr()*0.01)
else:
fCurrStrength = float(pUnit.baseCombatStr())*float(1.0-pUnit.getDamage()*0.01)
fMaxStrength = float(pUnit.baseCombatStr())
iTurnsToHeal = int((fMaxStrength-fCurrStrength)/float(fMaxStrength*float(mt.getPlotHealFactor(pUnit))*0.01)+0.999) # force to round up
def onLoadGame(self, argsList):
#Displays the "Welcome Back!" Message when a saved game loads.
CyInterface().addImmediateMessage("Welcome back!","")
#ENDLoadGame
return 0
IVZanIV said:Also, since it is here...
This piece of code is so simple that I'm not sure if it's even worthy of putting here,,,,,
myResult = "whatever the heck your trying to test"
CyInterface().addMessage(CyGame().getActivePlayer(),True,10,"%s" %(myResult),'',
1,'',ColorTypes(8),-1,-1,True,True)
IVZanIV said:12monkeys, if you set the domain of sea and air units to land while in a city, doesn't that mean that air units will not work as they were created ever again? Because air units by default stay in cities and bomb from there, but as land units, they can move, which is against the "city rule"... Sorry if that's wrong...
naf4ever said:I started programming pretty much from scratch a month ago just so i could mod python civ files...
12monkeys said:I don't change the unit itself. I just treat them in the code as land units, to simplify the handling. So there is no problem.
naf4ever said:Trust me this is very useful. I started programming pretty much from scratch a month ago just so i could mod python civ files.. It took me a week just to figure out how to put up a message like yours. So hopefully you'll save someone else a week of time... heh.
Heres another useful message contribution that can be used at any interrupt point. IVe found it invaluable when learning python and trying to figure out if my programs are actually working or not:
Code:myResult = "whatever the heck your trying to test" CyInterface().addMessage(CyGame().getActivePlayer(),True,10,"%s" %(myResult),'', 1,'',ColorTypes(8),-1,-1,True,True)
What it does: Prints a message thats based on a variable, in this case myResult.
Use: If you got some long complex function that gives no python errors yet doesnt seem to be working it can be frustrating debugging it. This allows you to test if the result your trying to achieve is actually happening in the first place and if so what its value is. Especially good if you got some function that involves lots of math or got some loop error you are trying to track down.
# Import statements
# ...
# ...
# Global variables
# ...
# ...
# Change this to enable or disable debug messages
g_bDebug = true
LOG_ONLY = 1
SCREEN_ONLY = 2
LOG_AND_SCREEN = 3
# Change to redirect the debug messages to the logs, screen or both.
g_iDebugMessageTarget = LOG_ONLY
class CvFoo:
def fooBar(self):
# Debug code - Start
if(g_bDebug):
self.printDebugMessage("Hello, World!")
# Debug code - End
return iHangingBodyCount
# Prints the debug message to the logs, screen or both
def printDebugMessage(self, strMessage):
if(g_iDebugMessageTarget == LOG_ONLY):
CvUtil.pyPrint(strMessage)
elif(g_iDebugMessageTarget == SCREEN_ONLY):
CyInterface().addImmediateMessage(strMessage)
else:
CvUtil.pyPrint(strMessage)
CyInterface().addImmediateMessage(strMessage)