[MODCOMP] Unit Statistics

It's done and has been successfully tested with Unit Statistics (some changes to UnitStatisticsUtils.py and CvUnitStatisticsEventManager.py were necessary.

I'll now test whether I can use the modified version of sdToolKit for the player statistics. I'll tell you shortly if it works.



Edit: Works fine :)
 

Attachments

  • SdToolKitAdvanced.zip
    2.5 KB · Views: 425
Teg,

The only issue I see is that you never check if the object passed in has the correct method or not. Then of course you provide which objects have the script data methods in your comment... I guess it's up to you how much checking you want to do. Otherwise it looks good to me.
 
One thing you might want to consider is leaving all of the original method names and changing your sdLoad( object ) to sdObjectLoad( object ). This way if someone wants to use your version but previously used SD's original file it won't break their code.
 
Yep, the original sd toolkit is a bit more error-friendly.

For example, sdObjectGetVal and sdObjectSetVal don't work if you haven't initialized the object first, sdGetVal and sdSetVal (the original ones) do (at least partly).
 
TheLopez said:
One thing you might want to consider is leaving all of the original method names and changing your sdLoad( object ) to sdObjectLoad( object ). This way if someone wants to use your version but previously used SD's original file it won't break their code.

the original method is still intact (sdModLoad(ModID)). I named it sdLoad instead of sdObjectLoad because I had a name conflict with sdObjectInit, which existed twice. But since I removed one of them, I could change the name again. But now I really have to go... :)
 
Teg_Navanis said:
the original method is still intact (sdModLoad(ModID)). I named it sdLoad instead of sdObjectLoad because I had a name conflict with sdObjectInit. But since I removed one of them, I could do this. But now I really have to go... :)
You are correct, it is still intact, my bad, sorry. Anyways, thanks for updating the toolkit and making more work for me :p. Now I have to go and update all my mods...
 
Thanks to the SDK, unique unit names are now no longer necessary... :)

There are several other improvements and bugfixes that found their way into version 1.32, but this is clearly the greatest one, since I never wanted to force unit naming (it can still be switched on of course).
 
How are you getting around unique unit naming?
 
I modified the CvUnit.convert function in CvUnit.cpp.

Code:
	setGameTurnCreated(pUnit->getGameTurnCreated());
	setDamage(pUnit->getDamage());
	setMoves(pUnit->getMoves());
	setExperience(pUnit->getExperience());
	setLevel(pUnit->getLevel());
//unitstats additionstart
	setScriptData(pUnit->getScriptData());
//unitstats additionend
	setName(pUnit->getNameNoDesc());


Edit: Additionally, I created two new python events. onCombatBegin and onCombatHit. They are very similar to onCombatLogCalc and onCombatLogHit, with two slight differences.
1. the events are called in every battle, not just when a human is involved. thus, all units can be tracked.
2. instead of combat detail objects (cdAttacker/cdDefender), the unit objects are provided in the argsList. Hence, the unit's script data can be accessed and modified directly, while I originally needed the unit name to find the unit object that corresponded to the combat detail object.
 
I see that you have created a Python event called 'onCombatBegin'. Exactly when is it called and do how do I implement it in my own mod?
Thanks in advance
 
Is is called shortly before onCombatLogCalc, e.g. after the various checks if there is a valid defender (or only a worker) and before the damage calculation begins.

To implement it, you have to use the mod's CvGameCoreDLL (or create a new file using the CvUnit.cpp in the mod's SDKfiles folder. Then, the event needs to be added either in CvEventManager.py or whatever you use. Just add the line

Code:
'combatBegin' 			: self.nameofthefunctionyouwanttouse,

in the EventHandlerMap (lines 73-130 in the original CvEventManager.py)

I used Gillmer J. Derge's CustomEventManager, which allows me to add an EventHandler without messing with the CvEventManager file. Check CvUnitStatisticsEventManager.py if you're interested in this approach.

Anyway, you also need to know the argsList (which you could check in the mod). It looks like this:

Code:
		genericArgs = argsList[0][0]

		attackerUnit = genericArgs[0]
		defenderUnit = genericArgs[1]
		iDefenderOdds = genericArgs[2]
 
=DOCTOR= said:
Is there any way to combine this mod with 12monkey's Plot List Enhancement Mod?

As far as I can see, the mods don't conflict. The easiest way to run both mods is by installing the Plot List Enhancement Mod into the CustomAssets folder and Unit Statistics into a mod folder and then start the game with Unit Statistics running. Of course, you can also easily merge the mods: Just copy both mods into the same mod directory and rename 'CustomAssets' to 'Assets'.
 
Nice mod, very cool, I always like more info on how my units are doing. :D

I was playing around, trying the different nameing options and I noticed two things.

One, the version of TheLopez's RandomNameUtils lacks the option to use Civilization specific names. I already added the option in for my own play, but if you get the time, might be good to update that. :)

Second, there is a bug with naming air units in the NexusNaming option. I looked into the code and found it. In NexusNameUtils.py, In the part where you init your sd entities
Code:
agroup2 = 5
		nameAGroup2 = {
							AGROUP2 : agroup2 }		
		sdEntityInit("UnitNaming", "AGROUP2", nameAGroup2)
						
		agroup3 = 1
		nameAGroup3 = {
							AGROUP3 : agroup3 }		
		sdEntityInit("UnitNaming", "AGROUP3", nameAGroup3)
						
		agroup4 = 25
		nameAGroup4 = {
							AGROUP4 : agroup4 }		
		sdEntityInit("UnitNaming", "AGROUP4", nameAGroup4)

		asquad1 = 1
		nameASquad1 = {
							[B]NSQUAD1[/B] : asquad1 }		
		sdEntityInit("UnitNaming", "ASQUAD1", nameASquad1)
						
		asquad2 = 5
		nameASquad2 = {
							[B]NSQUAD2[/B] : asquad2 }		
		sdEntityInit("UnitNaming", "ASQUAD2", nameASquad2)
						
		asquad3 = 1
		nameASquad3 = {
							ASQUAD3 : asquad3 }		
		sdEntityInit("UnitNaming", "ASQUAD3", nameASquad3)
 
		asquad4 = 25
		nameASquad4 = {
							ASQUAD4 : asquad4 }		
		sdEntityInit("UnitNaming", "ASQUAD4", nameASquad4)

I bolded the two typos, just 'NSQUAD's that need to be 'ASQUAD's.

Again, very cool mod, I really like the Nexus nameing.
 
So if I take out the new dll, will every thing not related to the two new combat events work? As in, will all the statistics tracked in the vanilla events be tracked?
 
Thanks for your bug reports, I'll add them to my list and fix them in the next release.

V1.33 works without the DLL - you will have to adjust some ini settings though (as explained in the readme file). Since all changes in v1.34 require the DLL, I have decided not to make this version run without the DLL.
This decision is primarily for my convenience, since I can keep the code cleaner and don't have to worry about compatibility. As long as most changes require the SDK, you won't see any difference between the current version and v1.33 anyway.
If the mod gets improved for both the SDK and the python only mode (graphically for example ;)), I may rethink this step.
 
Ahh, thanx for the answer. :)

And I found some more bugs to report.

In the NexusNameUtils.py, under the nameing of air units:
Code:
num[B]w[/B]ing2 = sdGetVal("UnitNaming", "WING2", WING2)
    	num[B]w[/B]ing3 = sdGetVal("UnitNaming", "WING3", WING3)

The bolded two 'w' need to be capitalized.

and a little father down where you acual compile the names together:
Code:
#name unit
    	if (g_CNspacing == 0 and g_CNNameDesc == 1):
    		unitName = unitI.getDescription() + " " + str(NumW) + str(AbrW) + " " + str(NumG) + str(AbrG) + " " + str(NumS) + str(AbrS)
    	elif (g_CNspacing == 1 and g_CNNameDesc == 1):
    		unitName = unitI.getDescription() + " " + str(NumW) + " " + str(AbrW) + " " + str(NumG) + " " + str(AbrG) + " " + str(NumS) + " " + str(AbrS)
    	elif (g_CNspacing == 0 and g_CNNameDesc == 0):			
    		unitName = str(NumW) + str(AbrW) + " " + str(NumG) + str(AbrG) + " " + str(NumS) + str(AbrS)
    	elif (g_CNspacing == 1 and g_CNNameDesc == 0):
    		unitName = str(NumW) + " " + str(AbrW) + " " + str(NumG) + " " + str(AbrG) + " " + str(NumS) + " " + str(AbrS)

The above code is after I fixed it, but some of 'str(AbrS)' were 'str(AbrG)' so the planes would get named '1stWing 1stGroup 1stGroup'.

Hope this helps. :)
 
While I'm glad that you like the Nexus Naming, I can't take credit for it - Nexushyper made it. But since he seems not to be active anymore, I'll make the fixes myself. Actually, I just finished, but I guess I should first test it for more bugs - I haven't done so yet.
 
The latest upgrade of the mod has a new look!

Instead of popups, a new screen opens that has buttons and allows cross-referencing. Now you no longer have to actively search for your best units, since all the units are listed in a panel and can be accessed by a single click.

You will notice that all high score buttons look the same and don't have any functionality or tooltips. I might have to use talchas' Action Buttons 2.0 for the tooltips, but is anyone able to create new buttons or scavenge them from other threads? My first attempt at modifying the promotion buttons didn't end that well - I didn't manage to make the borders transparent... :(
 
To have buttons with transparent borders I suggest you convert any button to .png format, trim out the insides, and save it as a template. For each new button fill the insides of the template, save as a .png, and then convert to .dds. This should mean the button saves it's alpha channel.

I would post my template up, but I don't have it with me.

As for the new version - I like it. The screen could maybe be better - I'd suggest putting aborder around the unit picture, and a panel for the stats text. I'm not sure the title needs to be so long either - surely "Unit Statistics" would do fine.

Do you mind if I see about including this as an option in the CEP? It seems fairly unobtrusive, and quite cool!
 
Top Bottom