Unit Statistics Mod v1.41
By: Teg_Navanis

Patch Compatibility: v1.61
MP Compatibility: yes

Check http://forums.civfanatics.com/showthread.php?t=162977 for the newest version. please also report bugs there.


-----Description-----

This mod adds some unit and player statistics such as number of battles, number of kills, damage done etc.
To see them, simply select a unit and press U. If no unit is selected, the player statistics will load instead.

There is also a button on the upper right side of the main interface that starts the unit statistics screen. If you don't want the button, simply remove CvMainInterface.py from the mod.

Most components can be turned on and off in the Unit Statistics Config.ini.


-----Installation Instructions-----

Unzip this into the "civ4_install_folder\Mods\" folder.

-----Combining this mod with other mods

To incorporate this mod into another one, copy all files into the other mod's corresponding folders.
If there a several files with the same name, check if there are differences between the files. If there aren't, just use one.
If there are, you have to merge them manually by copying the additions of one file to the right place in the other one.
If there is already a CvCustomEventManager.py in the other mod, check the example-file CvXXXEventManager 
to see how you can modify the CvCustomEventManager file of the other mod to create a file parallel to CvUnitStatisticsEventManager. 
You can load this newly created/modified file by adding a single line in this mod's CvCustomEventManager (appr. line 34).

I won't explain how you can merge several CvGameCoreDLL.dll files. It is explained in the CivFanatics Forum, but rather complicated (in terms of programs needed to compile the DLL).
For those who know how to do it: The required files are in the SDKfiles folder, all changes have been commented. 
search for "unit statistics addition start" and "unit statistics addition end".

if you want to play the mod without the CvGameCoreDLL.dll, download version 1.33, which allows you to disable it.


-----Version Information-----

----v1.41------

- Multiplayer mode now successfully playtested! Yay!

- fixed wrong output in high score screen with "Track All Players" enabled (or multiplayer).

- fixed python error when a unit died with "Track All Players" enabled (or in multiplayer).

- fixed bug with highscore not being resetted when only living unit dies.

- fixed bug with highscore not being resetted when only unit with a value > 0 dies.

- (possibly) fixed bug with goodie huts.

- the position of a unit now also flashes on the minimap when you hover your mouse over its corresponding high score button.

- (Internal change: All global variables and multiple definitions have been moved to UnitStatisticsDefines)

----v1.40b------

- the mod recognizes multiplayer matches and changes its settings accordingly.

- fixed a bug with air interceptions.

----v1.40------

- new feature: view other players' player statistics when both "Track All Players" 
  and "Show All Players" is enabled.
  
- fixed some bugs occuring with "Global High Score" disabled and "Track All Players" enabled

- the 'oldest unit' high score doesn't increase for dead units.

- new high score screens: hall of fame and top 10. 
  hall of fame also includes dead units 
  top 10 searches for the ten best units in any given high score
  
- new feature: track turns in enemy territory (+ high score)

----v1.39b-----

- fixed bug when retreating

----v1.39-----

- fixed bug with minimap

- new config option: Show All Players. If you want to play a hotseat game, 
  I recommend having "Track All Players" on (allowing your units' fights to be stored
  even if it's another's player's turn) and "Show All Players" off (making sure that
  you don't see the location of other players' units and vice versa)
  
- new config option: Global High Score. Enabling this together with "Track All Players"
  makes the Mod take all units into account when creating a high score list. If you want
  to know the world's best units, set this to true

----v1.38------

- fixed bug (new with 1.37): the luckiest fight high score was not correctly calculated

- fixed bug: when all units that had once won a fight died, you could still 
  select the combat odds high score button, but received an error.
  
- added minimap to high scores page (beta)

----v1.37------

- Multi language support

- German Translation

- some optical changes (better look with resolutions I didn't test before / compatibility issues with other languages)

- Some new high score buttons

- Added button to main interface that starts the unit statistics screen. If you don't want the button, simply remove CvMainInterface.py from the mod.

- Commented the new code

----v1.36------

- New high score buttons.

- Some changes to the screen interface.

- PopUps disabled. From now on, pressing "U" opens the screen.

----v1.35------

- New Screen Interface. Press Alt + Y to open it. (Beta)

- updated TheLopez' Random Name Generator to v0.5.1

- several bug fixes for Nexus Naming

----v1.34------

- SDKchange: the damage done can now be no higher than the health of the killed unit.

- new feature: the number of air fights/losses/kills is now logged too.

- SDKchange: air strikes and intercept missions get their own event in case someone wants to modify/remove one of them.

- removed possibility to run the mod without the CvGameCoreDLL.dll. Since most changes in this and future 
  versions are SDK changes, version 1.33 provides the same functionality for anyone playing without the GameCoreDLL.
  
- SDKchange: new event: unitUpgraded

- SDKchange: new event: combatWithdrawal

- new feature: unit log message when a unit withdraws from combat and when it is upgraded.
  
----v1.33------

- fixed bug: the two fortify high scores were intermixed.

- added some options to the ini file and removed others. The ini file is now easier to understand
and you can mostly change a value without having to change others too.

- SDKchange: new feature: collateral damage tracking (also works with air strikes)

- SDKchange: new feature: if an air unit is intercepted, the damage is also logged.

----v1.32------

- SDKchange: also battles between AI-players are tracked when 'Track All Players' is enabled.

- SDKchange: unique naming is no longer necessary for the mod. However, the mod's own CvGameCoreDLL.dll is required.

- Tested with Civ4 1.61

- fixed some bugs that were introduced in 1.31 (damage inflicted/received while defending, luckiest fight)

- Uses generic version of SdToolKitAdvanced (compatible with other mods using this file)

- New feature: turns fortified (can be turned off in the config (Log Turn Information))

- New feature: distance moved with cargo on board (learn which transport unit is your most valuable)

----v1.31------

- rewrote some of the code for better performance (up to 5000% performance boost!!!!)

- enabled movement logging by default (now running smoothly)

- new features: unit statistics now list total kills, kills while attacking and kills while defending (same with number of battles and retreats)

- rewrote some of the code so that theoretically, several players could be tracked at once. (successfully tested with hotseat, but AI-fights aren't tracked) track all units is disabled by default for the time being.

- recycled names are now correctly sorted

- recycling of names can be disabled in the config

- removed some unnecessary configuration options (the six options for damage stats have been merged)

- combat odds can now be turned off

- when a unit is killed in battle, the damage high scores updated so that the unit can enter the hall of fame.

- fixed bug with Hall of Fame value getting overwritten by lower value

----v1.3-------

- disabled movement logging by default for performance reasons.

- average odds and survival odds now calculated for every battle, not just for battles won

- survival odds now take into account withdrawal probability

- new feature: player statistics
	- total amount of units killed, damage inflicted etc.
	- hall of fame: shows the high scores for each category (both including and excluding dead units)

- new feature: battle counter: number of battles fought (including retreats)

- new feature: loss counter: number of battles lost (only in player statistics)

----v1.24-------

- fixed bug when in golden age

- added possibility to disable unit movement logging in the config.ini

----v1.23-------

- new feature: total survival odds. How lucky is your unit still to be alive?

----v1.22-------

- new features: average combat odds, average combat odds high scores (most cautious unit / most reckless unit)

----v1.21-------

- new features: combat odds log for every fight, luckiest combat stat, luckiest unit high score

----v1.20-------

- fixed a bug (errormsg) when losing a Great Person (gameplay not affected)
 
- by default, only combat units are tracked. this saves some performance if you have lots of automated workers.

- commented and optimized some of the code

----v1.19-------

- fixed a bug when upgrading a unit (concerning experience)

- implemented trashbin for Nexushyper's Name Generator (if a unit is lost, its name is reused by the next unit created)

----v1.18-------

- fixed errormsg when not using default name generator (gameplay not affected)

- fixed errormsg when your unit dies in combat (gameplay not affected)

- optimized high score calculation and turned it on by default.

- removed transport high score. it took more resources than it is worth

- integrated Nexushyper's Name Generator

-----v1.17------

- added new statistics
   damage inflicted while attacking
   damage inflicted while defending
   damage suffered while attacking
   damage suffered while defending

- turned off high scores by default because the popup takes too long to load with 100+ units

-----v1.16------

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

- unit naming is now also compatible with multiplayer

- data of lost units is removed (after the information has been copied to the new unit in case of an upgrade).

- names of lost units are stored for re-use.

-----v1.15------

- added new statistics:
	damage inflicted
	damage suffered

- implemented a high score function. the best unit in every highscore category 
  will get a little text at the bottom of its unit statistics. this text is planned to be replaced by a button.
	high scores so far:
		most kills
		most damage inflicted
		most damage suffered
		furthest distance moved
		furthest distance transported
		furthest distance travelled
		oldest unit
		most experience 

-----v1.1 By TheLopez ------

- Renamed the mod unitstats to Unit Statistics Mod, short names are ugly :).

- Updated the mods directory structure to make it easier to identify the unique 
  files for the mod. Renamed CvCustomUnitStatsEventManager.py to 
  CvUnitStatisticsEventManager.py, unitstats.py to UnitStatisticsUtils.py.
  
- Restored the GNU statement in the CvCustomUnitStatsEventManager.py file

- Added a copy of the COPY.TXT file containing the GPL to conform to Dr. Elmer
  Jiggles wishes in regards to the usage of his INI parsing and custom event
  manager code.
  
- Generalized the unit action logging code

- Added INI file configuration support using Dr. Elmer Jiggles code

- Added an option allowing players to turn unit combat logging off and on 
  through the "Unit Statistics Mod Config.ini" file.
  
- Added an option allowing players to turn unit promotion logging off and on 
  through the "Unit Statistics Mod Config.ini" file.
  
- Added an option allowing players to show or hide the units body count through
  the "Unit Statistics Mod Config.ini" file.
  
- Added an option allowing players to show or hide the units service 
  information through the "Unit Statistics Mod Config.ini" file.

- Added an option allowing players to show or hide the number of years a unit
  has been in service through the "Unit Statistics Mod Config.ini" file.
  
- Added an option allowing players to show or hide the number of turns a unit
  has been in service through the "Unit Statistics Mod Config.ini" file.
  
- Added an option allowing players to switch the order that the turns and years
  a unit has been in service are displayed through the "Unit Statistics Mod 
  Config.ini" file.

- Added an option allowing players to show or hide the distance the unit has
  moved through the "Unit Statistics Mod Config.ini" file.

- Added an option allowing players to show or hide the distance the unit has
  been transported through the "Unit Statistics Mod Config.ini" file.

- Added an option allowing players to show or hide the total distance a unit
  has travelled through the "Unit Statistics Mod Config.ini" file.

- Added an option allowing players to turn unit event log off and on through 
  the "Unit Statistics Mod Config.ini" file.

- Added an option allowing players to turn on and off the turn information
  in the units event log through the "Unit Statistics Mod Config.ini" file.
  
- Added an option allowing players to turn on and off the year information
  in the units event log through the "Unit Statistics Mod Config.ini" file.

- Added an option allowing players to switch the order that the turns and years
  information are logged in the units event log through the "Unit Statistics 
  Mod Config.ini" file.
  
- Generalized the code to display the game turn/year information in the units
  event log.  

- Added goody logging (when units go into a village)


-----v1.05------

- (hopefully) fixed bug with statistics being overwritten by AI-units

-----v1.04------

- fixed bug with unit promotion that slipped in in v1.02

-----v1.03------

- changed CvCustomEventManager for easier mod-merging

-----v1.02------

- fixed a bug when upgrading unit (the statistics added a movement from the corner of the map)


-----v1.01------

- Removed redundancy in PopUp Header


-----v1.0------

- Initial release



-----===Credits & Thanks===-----

Special thanks to:

- Roger Bacon
	Kill List Mod - this Mod is the core of the Unit Statistics Mod

- TheLopez 
	version 1.1 of Unit Statistics
	Mercenary Mod - workaround for unit upgrade bug; copied some of his SD-Toolkit-code

thanks to

- Stone-D
	SD-Toolkit

- Impaler
	Fully Extended CvCustomEventManager v1

- Gillmer J. Derge
	CustomEventManager
	INI-Parser

- Nexushyper
	Random Name Generator
	
- Chui Tey
	Numsort.py
	
- Zuul, White Rabbit
	Buttons
	
- Kael
	FfH Editor

Further mods I checked to learn how to code some bits of the Unit Statistics Mod:

autolog by eotinb
Random Unit Names by TheLopez
CulturalDecay by Bhruic
