[MODCOMP] Unit Statistics

Teg_Navanis said:
-----v1.16------

- integrated TheLopez' Random Name Generator as an optional way of naming units

- unit naming is now also compatible with multiplayer

May I ask what was involved with making unit naming multiplayer compatible? I was talking with Gerikes, Caesium, and Jeckel (see thread) and it seems like you are checking against CyGame.getActivePlayer() in your latest version, before calling CyUnit.setName(), which I thought would be a problem. Is your mod still multiplayer compatible? Can different unit names for the same unit cause an out of sync?
 
The line is

Code:
		if (g_bTrackAllPlayers or objUnit.getOwner() == gc.getGame().getActivePlayer()):

If you want to play the mod in mulitplayer, you should set "Track All Players" in the config.ini to true. Then, it won't matter whether you are the active player or not. However, I could not yet test the mod in proper multiplayer games (LAN/internet), only in hotseat ones.
 
I just want to point out the link that Gaurav gave in post #142, ie this link.

Gerikes does very well in explaining the causes of oos errors and the proper use of getActivePlayer. All modders that want their mods to be MP compatiable should read through it. :)
 
Jeckel said:
I just want to point out the link that Gaurav gave in post #142, ie this link.

Gerikes does very well in explaining the causes of oos errors and the proper use of getActivePlayer. All modders that want their mods to be MP compatiable should read through it. :)

Don't worry, I know about the issue with gc.getActivePlayer().

I use it regularly for the output, but since the screen should only appear for the player who opened unit statistics (I just hope I don't have the same issue as FfH, where the spell target screen opened for all units), this is no problem in multiplayer. All other instances of gc.getActivePlayer() can be circumvented by enabling "Track All Players". It might even work with the standard settings - I don't know whether the scriptdata must be the same for every player.
 
I found a new bug:
Traceback (most recent call last):

File "CvEventInterface", line 23, in onEvent

File "CvCustomEventManager", line 187, in handleEvent

File "CvCustomEventManager", line 198, in _handleDefaultEvent

File "CvUnitStatisticsEventManager", line 259, in onAirIntercept

File "UnitStatisticsUtils", line 938, in onAirIntercept

UnboundLocalError: local variable 'iWinnerHealth' referenced before assignment
ERR: Python function onEvent failed, module CvEventInterface
In my opinion it must be strWinnerHealth referenced to line 931.
 
Thanks, fixed. I uploaded a new file with this small bugfix and a better multiplayer compatibility. Specifically, you don't have to adjust the config for multiplayer games anymore. The mod will treat any multiplayer games as if they were played with the 'right' settings.

@Caesium: I also had a look at your modpack and made some changes for easier mergeability: comment lines 21/22 and uncomment lines 23/24 in CvUnitStatisticsEventManager and adjust line 27 in UnitStatisticsDefines and it should work with your mod.
 
A new version is up, for both Civ 4 and Warlords. It includes several bugfixes for multiplayer games.
 
I don't think this version of the mod is compatibility-breaking. It usually is when I change something in the way the data is stored, for example adding a new category or changing a variable name.

Whoops, I forgot: If you want to continue current games, you have to change the name of the Mod to the old one ("Unit Statistics Mod" instead of "Unit Statistics Mod for Civ4" or "Unit Statistics Mod for Warlords").
 
Teg_Navanis said:
I don't think this version of the mod is compatibility-breaking. It usually is when I change something in the way the data is stored, for example adding a new category or changing a variable name.

Whoops, I forgot: If you want to continue current games, you have to change the name of the Mod to the old one ("Unit Statistics Mod" instead of "Unit Statistics Mod for Civ4" or "Unit Statistics Mod for Warlords").

I meant savegame compatibility with vanilla 1.61 games.
 
Try using the file in the attachment instead (you have to change it from .txt to .py and replace the original CvUnitStatisticsEventManager.

Basically, I added this code:

Code:
	def onLoadGame(self):
		
		unitList = []
		
		if (g_bGlobalHighScore and (g_bTrackAllPlayers or gc.getGame().isGameMultiPlayer())):
			for iPlayer in range(gc.getMAX_PLAYERS()):
				if (gc.getPlayer(iPlayer).isEverAlive):
					pyPlayer = PyPlayer(iPlayer)
					unitList = unitList + pyPlayer.getUnitList()	
		else:
			unitList = PyPlayer(iPlayer).getUnitList()
			
		for objUnit in unitList:
			objUnitStatisticsUtils.setupUnitStats()

It will initialize all your units that have no valid unitstats value when you load a game. It may slow you down when you often reload, so I don't yet know whether I'll add this to the core mod. Oh, and it hasn't been tested ;)
 

Attachments

Teg_Navanis said:
Try using the file in the attachment instead (you have to change it from .txt to .py and replace the original CvUnitStatisticsEventManager.

Basically, I added this code:

<snipped>

It will initialize all your units that have no valid unitstats value when you load a game. It may slow you down when you often reload, so I don't yet know whether I'll add this to the core mod. Oh, and it hasn't been tested ;)

Wow, that answer was almost too fast for something I was thinking would be hard. :) I'll see if I can test it out.
 
I still haven't tested it, but I just noticed a bug. The last two lines should be

Code:
		for objUnit in unitList:
			objUnitStatisticsUtils.setupUnitStats([B]objUnit[/B])
 
I have some bad and some good news for you:

Bad news: The file I sent you still doesn't work.

Good news: I now have a working version on my PC which will be included in the next release of the mod. I also made sure that it was way faster if you load a game that is already compatible.

If you can't wait that long, try this:

Code:
	def onLoadGame(self, argsList):
		if(sdObjectExists("UnitStats", gc.getActivePlayer())):
			return
		unitList = []
		
		if (g_bTrackAllPlayers or gc.getGame().isGameMultiPlayer()):
			for iPlayer in range(gc.getMAX_PLAYERS()):
				if (gc.getPlayer(iPlayer).isEverAlive):
					pyPlayer = PyPlayer(iPlayer)
					unitList = unitList + pyPlayer.getUnitList()	
		else:
			unitList = PyPlayer(gc.getGame().getActivePlayer()).getUnitList()
			
		for objUnit in unitList:
			objUnitStatisticsUtils.setupUnitStats(objUnit)
 
As far as I understand your conversation, this new code isn't needed if you play your mod as a modcomp in another mod, let's say like mine, right?

Btw, your mailboxlimit has exceeded...
 
Caesium said:
As far as I understand your conversation, this new code isn't needed if you play your mod as a modcomp in another mod, let's say like mine, right?

Nope, you'll only need it if you want to load a non-UnitStats savegame with UnitStats.

Btw, your mailboxlimit has exceeded...

Thx
 
There seems to be some differences between your CvScreensInterface.py and the one from Warlords. Maybe u forgot "< Unit Statistics Mod Start > tags" but i doubt it. I think u merged it with a non-warlord version.
No idea if it cause problems since i merged mine manually.
Of course i'm talking about the warlords version of your mod.
 
A few more stats you could add:

Cities visited/pillaged/taken, turns in city/friendly/neutral/enemy/road/forrest/hill/grass/plain..., bombard turns
 
turlute said:
There seems to be some differences between your CvScreensInterface.py and the one from Warlords. Maybe u forgot "< Unit Statistics Mod Start > tags" but i doubt it. I think u merged it with a non-warlord version.
No idea if it cause problems since i merged mine manually.
Of course i'm talking about the warlords version of your mod.

Yep, the 'date modified' can't be right. Apparently, I accidentally deleted the Warlords file after merging them. The only problems I could see were that you don't see the XP count for great generals and that something is wrong with the Vassal states. Seems like I'll have to upload a new version soon.

Zuul said:
A few more stats you could add:

Cities visited/pillaged/taken, turns in city/friendly/neutral/enemy/road/forrest/hill/grass/plain..., bombard turns

I tried the first one, but it's not (yet) possible to determine the unit that razed/captured a city. Maybe I'll code something in the SDK that does the trick. Turns in enemy territory are in, I honestly don't care about the rest. Bombard turns are an option, but also not possible in python. I'm a bit more hesitant about SDK changes since some modpacks have incorporated Unit Statistics and while it is easy for them to update the python files, it takes way more effort to update SDK changes.
 
Back
Top Bottom