I have now tested this and whilst it has solved the problem of my Stars/Planets disappearing it is not preventing the unit types from moving outside of the borders. Also there are no error messages generated so there doesn't appear to be any errors in what has been done so far.Loose the self. on this line though:Code:self.deactivated = set()
The movement restriction seems to be working correctly for the UNITCOMBAT_DESTROYER but not for the UNITCOMBAT_FRIGATE. An unfortunate side effect of the movement restriction is that it is also preventing the Alien/Pirates/Barbarians from moving around the map at least with their UNITCOMBAT_DESTROYER.
Any ideas as to what needs to be amended, added or removed?
if eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_FRIGATE"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
if eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_DESTROYER"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
else:
bRestricted = False
if eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_FRIGATE"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
[B][COLOR="DarkRed"]elif [/COLOR][/B]eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_DESTROYER"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
else:
bRestricted = False
lRestrict = [gc.getInfoTypeForString("UNITCOMBAT_FRIGATE"),
gc.getInfoTypeForString("UNITCOMBAT_DESTROYER")]
if eUnitCombat in lRestrict:
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
else:
bRestricted = False
They need to be completely excluded from this code as it should only affect the playable Civ's.For the barbarian issue, what to do to the code depends on the details of what you want to do. Should barbarians be completely excluded from this, or just some ship unitcombat types excluded for them but other types still restricted?
They need to be completely excluded from this code as it should only affect the playable Civ's.
def unitCannotMoveInto(self,argsList):
ePlayer, iUnit, iX, iY = argsList
if ePlayer in self.deactivated:
return False
else:
if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(gc.getInfoTypeForString("TECH_B5_SHIP_CONSTRUCTION")) [B][COLOR="DarkRed"]or gc.getPlayer(ePlayer).isBarbarian()[/COLOR][/B]:
self.deactivated.add(ePlayer)
You should be able to exclude barbarians from the effect by modifying one line near the beginning of the function to add the barbarian player to the "deactivated" set of players.
You could also get the same effect by specifically checking if the player is the barbarian in the first "if" where it checks the deactivated list, instead of adding it to the list.Code:def unitCannotMoveInto(self,argsList): ePlayer, iUnit, iX, iY = argsList if ePlayer in self.deactivated: return False else: if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(gc.getInfoTypeForString("TECH_B5_SHIP_CONSTRUCTION")) [B][COLOR="DarkRed"]or gc.getPlayer(ePlayer).isBarbarian()[/COLOR][/B]: self.deactivated.add(ePlayer)
def unitCannotMoveInto(self,argsList):
ePlayer, iUnit, iX, iY = argsList
if ePlayer in self.deactivated:
return False
else:
if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(gc.getInfoTypeForString("TECH_B5_SHIP_CONSTRUCTION")) or gc.getPlayer(ePlayer).isBarbarian():
self.deactivated.add(ePlayer)
[B][COLOR="DarkRed"]return False[/COLOR][/B]
if eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_FRIGATE"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
elif eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_DESTROYER"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
else:
bRestricted = False
elif eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_DESTROYER"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
if eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_FRIGATE"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
elif eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_DESTROYER"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
elif eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_CARRIER"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
else:
bRestricted = False
Every plot that was restricted is still restricted. It doesn't matter if it is now inside the borders, you still can't move on it if you ever tried to do so before with a ship of the same type.
There is one exception. The data is not saved in the savegame. Therefore if you save the game and then run from the save this starts from scratch each time. This allows all players to recover from any bad restrictions, but this is not exactly a recommended approach.
So it may be better to just remove the caching of that data. It would be a bit slower, but it would solve the problem. Alternatively the data could be stored someplace more easily accessible, allowing the data to be adjusted in the onCityGrowth event handler.
Where/how would I go about doing either of these things?
unitCannotMoveIntoDict = dict()
tKey = ePlayer, eUnitType, iX, iY
bRestricted = self.unitCannotMoveIntoDict.get(tKey, None)
if bRestricted == None:
self.unitCannotMoveIntoDict[tKey] = bRestricted
I did not read the whole 6 pages so I am not sure what it is meant to be like.
However, if it is meant to allow the ships to move only within cultural borders, then whether it is onCultureExpansion or onCityGrowth, neither one will be accurate.
OnCultureExpansion only activates when the city reaches the next culture level, but it does not tell you whether the plots themselves have changed ownership. For border cities near to rivals, the plots will change ownership occasionally due to culture ratio, but it is not updated with onCE and certainly not onCG. Thus, even if the plots flipped to yours, the data will not be updated, and the reverse holds true also
Assuming I have read everything correctly my new code looks like thisQuote:
Originally Posted by PsiCorps
Where/how would I go about doing either of these things?
The easiest method is to simply not store the restriction data, just check it each time. This will increase the amount of time it takes on average for each movement check slightly (but reduce the amount of memory used, although in comparison to the amount the game uses it is trivial). Since the restriction is removed once the tech is researched, which is relatively early in the game, the slower code will only be used early in the game when there are only a small number of units so the net effect should be very small.
To do this, remove references to unitCannotMoveIntoDict.
First, well first keep a copy of what you have now...
Second, remove this line that initially defines the variable:
Code:unitCannotMoveIntoDict = dict()
Then remove the lines referencing it in the function and defining the key used for the dictionary, and unindent one section of code.
Remove:
Code:tKey = ePlayer, eUnitType, iX, iY bRestricted = self.unitCannotMoveIntoDict.get(tKey, None) if bRestricted == None:
and
Code:self.unitCannotMoveIntoDict[tKey] = bRestricted
Then, finally, reduce by one level the indentation of all the code that used to be inside the "if" block for the now removed "if bRestricted == None:" statement .
That ought to do the trick.
The degree to which turn processing is slower will probably be unnoticeably small, and nonexistent once everyone has the tech to remove the restriction.
Edit: By the way, if you were interested in resetting the data on border growth the correct event hander is onCultureExpansion, not the onCityGrowth (which is for population changes) that I mentioned in the earlier post. Population grows, borders expand. Oops.
# start unit movement restriction code
unitCombatDict = dict()
deactivated = set()
def unitCannotMoveInto(self,argsList):
ePlayer, iUnit, iX, iY = argsList
if ePlayer in self.deactivated:
return False
else:
if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(gc.getInfoTypeForString("TECH_B5_SHIP_CONSTRUCTION")) or gc.getPlayer(ePlayer).isBarbarian():
self.deactivated.add(ePlayer)
return False
eUnitType = gc.getPlayer(ePlayer).getUnit(iUnit).getUnitType()
eUnitCombat = self.unitCombatDict.get(eUnitType, None)
if eUnitCombat == None:
eUnitCombat = gc.getUnitInfo(eUnitType).getUnitCombatType()
self.unitCombatDict[eUnitType] = eUnitCombat
if eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_FRIGATE"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
elif eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_DESTROYER"):
bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
else:
bRestricted = False
return bRestricted
# end unit movement restriction code