Quick question

I've had to put a hold on any testing developement work as i am once again unemployed and searching for work is a higher priority.
Yeah, it would probably be possible to make the code more efficient. You just need to figure out what approach is working better first - then we can optimize that one.
As soon as i can find some time to check this out i will do so and get back to you.
 
Finally managed to do some testing. I've changed the unit combat from defence to Frigate but when i tested i got the following error message. It can be removed after many clicks but after I removed it I went into WB and checked to see which Civ had built a Frigate. Much to my surprise the only unit moving around was a construction unit, so I've no idea what caused the error message.
 
Looking back through this topic, it looks like you removed the definition of bDebug, where it is set to either true or false, but did not remove all of the "if bDebug then print this debugging stuff to the log" type things from the code.
 
This is the code I am currently using.
Code:
# start unit movement restriction code

	unitCannotMoveIntoDict = dict()
	unitCombatDict = dict()
	bDebug = True # change to False once done debugging

	def unitCannotMoveInto(self,argsList):
		ePlayer, iUnit, iX, iY = argsList
		eUnitType = gc.getPlayer(ePlayer).getUnit(iUnit).getUnitType()
		tKey = ePlayer, eUnitType, iX, iY
		bRestricted = self.unitCannotMoveIntoDict.get(tKey, None)
		if bDebug:
			print ("debug: unitCannotMoveInto()", tKey)
			print "bRestricted = " + str(bRestricted)
			print unitCannotMoveIntoDict
		if bRestricted == None:
			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
			else:
				bRestricted = False
			self.unitCannotMoveIntoDict[tKey] = bRestricted
		if bDebug:
			print "return " + str(bRestricted)
		return bRestricted

# end unit movement restriction code
I've been looking at so many different things today I can't tell if there is anything missing from what I have. If there is something missing or incorrect, please let me know.
 
The key is probably this question: where in the code is this line
Code:
	bDebug = True # change to False once done debugging
i.e. is it actually at the indicated indentation level and inside the class that holds the unitCannotMoveInto function?
If so (and it probably is, given that the unitCombatDict varibale defined on the immediately preceding line is accessed via self.unitCombatDict) then it is not a global variable, it is a class variable. You could change the places it is used in the function into "self.bDebug" to access it, or you could move it up near the top of the file before the start of the class declaration with no indentation to make it accessible as just "bDebug".
 
The key is probably this question: where in the code is this line
Code:
	bDebug = True # change to False once done debugging
i.e. is it actually at the indicated indentation level and inside the class that holds the unitCannotMoveInto function?
If so (and it probably is, given that the unitCombatDict varibale defined on the immediately preceding line is accessed via self.unitCombatDict) then it is not a global variable, it is a class variable. You could change the places it is used in the function into "self.bDebug" to access it, or you could move it up near the top of the file before the start of the class declaration with no indentation to make it accessible as just "bDebug".

C'mon God-Emperor, you should know by now I need my hand held with things like this! :lol:
 
God-Emperor figured it out, listen to him. My stupid mistake, sorry. :blush:
 
Hi Baldyr
As I couldn't get this working quite the way I wanted last year I am now in a position to revisit the idea and see if we can't get it to work again. The attached file has both the old python files and the new python files I think are the ones you require.

Hoping we can get this to work this time.
 
I gave it a shot - file attached. If you change "TECH_OBSOLETE" to something that makes sense, it should work. This is a rather sluggish solution to the problem, however. Because it will continiously keep looking for whether or not the units owner has the tech - causing some considerable lag.

Someone else would have to provide you with a more sophisticated way of keeping track of when players acquire the tech. I sadly don't have access to my own computer for some weeks, nor do I have the time to delve deeper into your mod to set things up properly.

But you could at least test if the current code works, and take things further from there.
 

Attachments

  • CvGameUtils.zip
    6.7 KB · Views: 39
Hi Baldyr
I've got the Python added to the mod but it is stopping the unit from moving and throwing up a lot of error messages as well.

The PythonDbg log has this entry at the end of it.
Code:
19:51:50 TRACE: Error in FinalFrontierGameUtils callback handler unitCannotMoveInto
19:51:50 TRACE: global name 'deactivated' is not defined
19:51:50 DEBUG: BugEventManager - event gotoPlotSet: (<CvPythonExtensions.CyPlot object at 0x1927D3E8>, 0)
19:51:51 DEBUG: BugEventManager - event endTurnReady: (126,)
19:52:08 DEBUG: BugEventManager - event windowActivation: (0,)

I've also attached a copy of the PythonErr logwhich shows the error messages I was getting in game.
 
Did you try the file I posted or did you just copypaste the new lines of code?
 
I had to copy and paste the new lines of code as the Python File you modified no longer exists in either of the FFP & Babylon 5 mods. I had assumed that there was only one section in the file that had the movement restriction in it.
 
You probably missed a line then.
 
This line:
Code:
	unitCannotMoveIntoDict = dict()
	unitCombatDict = dict()
	[COLOR="Red"]deactivated = set()[/COLOR]

	def unitCannotMoveInto(self,argsList):
 
Code:
# start unit movement restriction code

	unitCannotMoveIntoDict = dict()
	unitCombatDict = dict()
	deactivated = set()

	def unitCannotMoveInto(self,argsList):
		ePlayer, iUnit, iX, iY = argsList
		if ePlayer in deactivated:
			return False
		else:
			if gc.getTeam(gc.getPlayer(ePlayer).getTeam()).isHasTech(gc.getInfoTypeForString("TECH_OBSOLETE")):
				deactivated.add(ePlayer)
		eUnitType = gc.getPlayer(ePlayer).getUnit(iUnit).getUnitType()
		tKey = ePlayer, eUnitType, iX, iY
		bRestricted = self.unitCannotMoveIntoDict.get(tKey, None)
		if bRestricted == None:
			eUnitCombat = self.unitCombatDict.get(eUnitType, None)
			if eUnitCombat == None:
				eUnitCombat = gc.getUnitInfo(eUnitType).getUnitCombatType()
				self.unitCombatDict[eUnitType] = eUnitCombat
			if eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_DEFENCE"):
				bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
			else:
				bRestricted = False
			self.unitCannotMoveIntoDict[tKey] = bRestricted
		return bRestricted

# end unit movement restriction code
This is the code I inserted into the CvGameUtils.py file of the mod.
 
I refer you to my last message in this thread...

That is, you should use "self.deactivated" everywhere it currently says "deactivated".

This is because "deactivated" is not a local variable (defined inside the function), it is defined as part of the class (which is one way of allowing the variable and associated data to be kept after the function ends - local variables go away after the function ends and the memory is recycled).
 
I refer you to my last message in this thread...

That is, you should use "self.deactivated" everywhere it currently says "deactivated".

This is because "deactivated" is not a local variable (defined inside the function), it is defined as part of the class (which is one way of allowing the variable and associated data to be kept after the function ends - local variables go away after the function ends and the memory is recycled).
:blush: Shoulda checked that shouldn't I?!
 
@God-Emperor

There were three instances of deactivated which I have prefixed as you suggested (see below)

Code:
# start unit movement restriction code

	unitCannotMoveIntoDict = dict()
	unitCombatDict = dict()
	self.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")):
				self.deactivated.add(ePlayer)
		eUnitType = gc.getPlayer(ePlayer).getUnit(iUnit).getUnitType()
		tKey = ePlayer, eUnitType, iX, iY
		bRestricted = self.unitCannotMoveIntoDict.get(tKey, None)
		if bRestricted == None:
			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
			if eUnitCombat == gc.getInfoTypeForString("UNITCOMBAT_DESTROYER"):
				bRestricted = gc.getMap().plot(iX, iY).getOwner() != ePlayer
			else:
				bRestricted = False
			self.unitCannotMoveIntoDict[tKey] = bRestricted
		return bRestricted

# end unit movement restriction code

Unfortunately this is now causing the Systems Star and planets to disappear from the map. Any suggestions or do you need to see the error logs?
 
Top Bottom