[MODCOMP] Unit Statistics

Yay, I fixed the high scores!

It now runs smoothly in most cases. If you lose a unit that has all (or most) high scores and you have hundreds of units (which is an unlikely combination), it may take a few seconds to calculate the best remaining units. In all other cases, the performance is not slowed down by having many units (well, having more units will of course always be slower, but not because of Unit Statistics ;))

I removed the transport high scores though. they took too much system resources when moving and are not that interesting after all...
 
Great update. I'm loving this mod.

However I found another bug, or 3. But I think I fixed most of them. I will attach the files and post the code.


For the first 5 turns, or so, I get the following error with checkHighScoresAllUnits but then it starts to go away. (Maybe to few units to check?)
Spoiler :
Traceback (most recent call last):

File "CvEventInterface", line 27, in onEvent

File "CvCustomEventManager", line 76, in handleEvent

File "CvCustomEventManager", line 87, in _handleDefaultEvent

File "CvUnitStatisticsEventManager", line 186, in onUnitLost

File "UnitStatisticsUtils", line 296, in onUnitLost

File "UnitStatisticsUtils", line 481, in checkHighScoresAllUnits

File "SdToolKit", line 144, in sdGetVal

KeyError: 16385
ERR: Python function onEvent failed, module CvEventInterface


I was still getting the same error as before when I build my city with the settler. So I fixed that with this code(below) to only name military units. It is added to def logUnitCreation of the UnitStatisticsUtils.py and is denoted by ##########Nexus start######(or similiar)
Spoiler :
NeedName = 0

if (objUnit.getUnitClassType() >= 16 and objUnit.getUnitClassType() <= 43):
NeedName= 1

elif (objUnit.getUnitClassType() >= 45 and objUnit.getUnitClassType() <= 54):
NeedName= 1

elif (objUnit.getUnitClassType() >= 55 and objUnit.getUnitClassType() <= 59):
NeedName= 1


if (NeedName == 1):



In the CvUnitStatisticsEventManager.py under def onUnitLost I add similiar code denoted the same way.
Spoiler :
NeedName = 0

if (objUnit.getUnitClassType() >= 16 and objUnit.getUnitClassType() <= 43):
NeedName= 1

elif (objUnit.getUnitClassType() >= 45 and objUnit.getUnitClassType() <= 54):
NeedName= 1

elif (objUnit.getUnitClassType() >= 55 and objUnit.getUnitClassType() <= 59):
NeedName= 1


if (NeedName == 1):



This way only military units get tracked statwise and build/killed wise. (You may wish to edit the numbers to include scouts, etc, as they are not included in this code. I just did this to see if it would work and yes it fixes the error).


In the ini file I added:
Spoiler :
; This only works if Custom Name = 3
; This determines numbering
; 0 = 1 ,2, 3 ... 7 for numbering IE Tank 1 Army 1 Corp 1 Div
; 1 = 1st, 2nd, 3rd for numbering IE Tank 1st Army 1st Corp 1st Div
; Default is 1
Unit Name Number = 1

; This only works if Custom Name = 3
; This determines Naming
; 0 = A, C, D for naming IE Tank 1st A 1st C 1st D or 1 A 1 C 1 D
; 1 = Army, Corp, Div for naming IE Tank 1st Army 1st Corp 1st Div or 1 Army 1 Corp 1 Div
; Default is 1
Unit Name Abreviation = 0

; This only works if Custom Name = 3
; This determines spacing
; 0 = no space between number and naming IE Tank 1stArmy 1stCorp 1stDiv
; 1 = space between number and name IE Tank 1st Army 1st Corp 1st Div
; Default is 0
Unit Name Spacing = 0


As part of my naming code. Though they seem to not be ready and I can't figure out why not.

I also made an update not NexusNameUtils.py. I now include another option so people can use Unitname + 1stA 1stC 1stD (unitname) or just 1stA 1stC 1stD (unitname) Everything is include in the attached zip.


I'm just trying to help out. Not trying to thread hijack! :)
 

Attachments

  • UnitStatsandNaming.zip
    28.6 KB · Views: 212
@Nexushyper: You described three bugs I fixed with 1.18. are you sure you installed the newest version correctly?

EDIT: Just checked your file and compared it to mine. actually, the bugs are caused by changes you made. ;) (namely, I removed your trashbin because it wasn't implemented correctly) I don't like your workaround since it affects all Name Generators, even those that work fine ;) I gotta go now and will come back later and tell you how the trashbin should look like for your Name Generator.
 
@Teg_Navanis: Odd. When I first downloaded 1.18 I was getting those errors before I added any code. So not sure why I get them and you don't. I always test a mod before merging it with my mod. Maybe I have something fishing on my PC. I will look into it. :(
 
Well, 1.19 includes a nice name-trashbin for your name generator. you shouldn't get any more error messages with this one.
 
What's the purpose of line 588 in UnitStatisticsUtils.py ?
Code:
		message1 = str(message0)
		if (message1 == "-1"):
			message1 = ""
str(message0) fails when the message contain unicode characters like éâ...

So far i havent seen a problem without it.
 
@turlute: Phew, that's a relic from the original kill list by RogerBacon. You're right in saying that this bit isn't necessary anymore in unit statistics.
 
I released a new version today (1.19 --> 1.22). Apart from some bugfixes I included a new feature - combat odds tracking! Check the new screenshots for more info.

I think I now included most of the statistics that can be done without the SDK and without wasting resources on unimportant stuff. Instead of new features, the next versions will most likely bring optical improvements and code optimization.
 
I have a current saved game that I would love to incorporate this mod into. Is there any way I can copy this into the standard "Custom Assets" folder rather than the Mod folder and use it with my saved game?
 
Sorry, it won't work retroactively. The mod needs to be running from the beginning, otherwise, it has no data about any past events.
 
Ok, I've got it working. This mod's great!

However, one thing I'd seriously consider is removing some of the extra and probably unnecessary stuff like distance moved and time in service for the units. The reason for this is I've since entered into the late period of the game and all the calculations the mod is doing each time I move any units is causing the game to lag to such extent that it will take 5-10s to move a stack of units anywhere

I'm not sure which parts of the mod are causing the lag, but all you really need is number of units killed, the "this is you best unit" statements, etc, and maybe some of the battle history...what do you think?

In fact along those lines, can you advise on how to remove components from this mod? I'd prefer a rather stripped-down version.
 
Check Unit Statistics Mod Config.ini - most of the stats can be switched on/off there.

Admittedly, the logging of unit movement can't easily be switched off yet, I'll implement it in the next version.



Edit: In 1.24, movement tracking can be disabled.
 
Many thanks. I'll experiment with that file. :)

Edit: When I replaced 1.23 with 1.24 I got a failed to load CvEventInterface.py. Putting the 1.23 Unit Statistics Mod Config back in makes the game load and play ok again, but then changing anything in the 1.23 ini file doesn't seem to change anything in-game. I.e. changing some of the values to false has no apparent effect...??

Any help?
 
yep, just noticed it myself. I uploaded a new file (same version number) that works.
 
whoops, dunno why it wasn't uploaded correctly. Now it's there...
 
Ok, got it loads now.

Checking the values to false in the ini file doesn't seem to remove them from the unit's pop-up description (pressing "u"). Do you have to do something else to remove them, say, modify one of the other files?
 
hum, apparently, CvPath.py and CvConfigParser.py, two files not made by me that are used to load the config, only work in the mods-folder. I don't yet know if this can be changed, but for now, you can change the values at the top of CvUnitStatisticsEventManager.py and UnitStatisticsUtils.py.

Look for "# Change this to either enable or disable" and you will find the entries.
 
Teg, which config values aren't being loaded correctly? Also why do you need to worry about reading the config file outside of your mod directory?
 
Top Bottom