[Live Tuner] AI info dump

Joined
Jul 31, 2002
Messages
705
Description:
this little script will 1) let you see all sorts of information about the current state of your game in the tuner's console 2) provide a few shortcuts to do stuff to the AI that the tuner only provides for the player and 3) pick up various game events and print out the relevant information to the console as the events occur

extremely useful for testing out immediate and long term changes to your game. all data printing works without having an active human player so you can set up those '1000 turn autoplay return as observer' huge map marathon tests, and come back the next day to see what went wrong with your mod ;)


Installation:
set 'EnableTuner' to 1 in your config.ini
download and extract to your civ5 MODS directory
activate in the civ5 mod menu
once a civ5 game is loaded, select the aiinfodump lua state in the tuner


Usage:
commands you can type in the console

sev()
turn on and off automatic information on game changes. can display diplomacy, policy, war, technology, city captures, combat reports, new cities, population change and new units (all off by default)

turntimer()
turns on a timer that reports how many seconds a turn took to process

dodow()
force a player declare war on another player

giveculture()
culture to a specific player

givegold()
gold to a specific player

givetech()
give a specified tech to a player

listcity
extra information on a city (city type, population, defense, gold, science, production, buildings built)

fast()
a shorter version of info(), this will show shortened information from every major civ

info()
prints out information for the specified major civ, all of them or the minor civs:
research, science, golden age, culture, gold, income, happiness
resource data, usage, export, imports
city list showing the city size, growth, production, science, income
adopted social policies of the player
diplomatic deals


Thanks:
ArgentumStudios and his AgS - Resource Info Panel which is where the civ resource code originates from and for its insight it gave me into the civ5 lua api

robk and his Info Addict mod: since i started this project, i kept on pushing back listing diplo deals and the task of diving into tradelogic, but his mod did an awesome job of clearing it all up for me right away


version history:
Spoiler :

v1.35 (11/26/2010)
fixed tracking so there's no skipping of any players (IsTurnActive() is false in autoplay for the first player after the human)
cleaned up diplomacy tracking and added comments as to what's happening there
turntimerplayer was using turntimer() on the first calc, stupid bug squashed
added more known/unknown events their passed values and triggers


v1.34 (11/23/2010)
turntimerplayer() and whosactive() added to debug game freezes (not crashes). shows how long each player takes, and who's currently active
policytracker shows anarchy, blocked, not blocked policies and updates at every player instead of every turn
cleaned up the diplomacy printouts for better readability
diplomacy table indexing (key=value) changed a bit to help avoid dupes
started to document/comment functions with more clarity, we'll see how long that lasts ;)

v1.33 (11/22/2010)
diplomacy finally added
info now has minor, also a fast info for toppanelish data at a glance
event prints for diplomacy, policy, combat, etc
added giveculture and givegold
turntimer doesnt need an activeplayer anymore
specific city info
streamlined the code a bit

v1.3 (11/08/2010)
cleaned up some messy parts of the script
added listing of techs and civs
added give specific tech to AI
added make AI declare war
added a turn timer

v1.2 (10/29/2010)
policies get displayed
warnings/prints on certain events
basic unit tracking coded in, doesn't do much
lots of other code from playing around left in

v1.1 (10/22/2010)
now prints out city information. base hammer production shown and build progress is rounded down (from citylist.lua and cityview.lua)
cleaned up the script, more condensed now
formatting is a bit more neat.

v1
prints out civ toppanel info (gold, science, happiness, etc), current research, and resource information (bonus resources included)


todo/wishlist:
Spoiler :

building tracking
how to print stuff in color!?!
neater formating
have all the info available in a UI panel in game (pipe dream)
map out more events
more timer functions
 

Attachments

  • ss01aiid.jpg
    ss01aiid.jpg
    34.8 KB · Views: 1,016
  • ss02aiid.jpg
    ss02aiid.jpg
    70.1 KB · Views: 1,142
  • AI info dump (v 1.35).zip
    15.8 KB · Views: 598
v1.2 uploaded, now shows policies and prints out info based on events + a bunch of code being tested left in (optional to run) for other lua interested folks
 
Thanks for this, I am obsessed by the long time waiting for turns, I have tested your timer and it is a start of what I was looking for.

Any chance you can get more info on what is going on during the end turn phase, not just the time but a full trace so we can get to know under which conditions the turn takes longer and where does it get stuck.
 
i think that's what the debug panels are used for. if i make sense of them i'd probably add something like that into the timer function. especially if something is eating up all the time, it would be good to know what it is
 
This utility is a good idea. Just a couple satirical documentation suggestions. :)

--24 hours and still hasn't fired???
Events.SerialEventSunRise.Add( OnSunRise );

--why don't these arguments seem to do anything???
function OnTaxation( iTakeThis, iTakeThat, iTakeOther )

--why does this appear to fire randomly???
Events.SerialEventsDeath.Add( onDeath );
 
I just updated from 1.33 to 1.35 and noticed a bunch of UNITSTATECHANGED lines showing up in the console like this one:
Code:
aiinfodump: 114: UNITSTATECHANGEDETECTED: Iroquois unit: Scout at x,y: 51, 34	c=0
And then looking in the Lua I see the following:
Code:
function unitstatechangedetected ( pnum, unitid, c )
	-- what triggers this ?
	-- what is c?
Intrigued, I poked about in the vanilla files and noticed that UnitMemberOverlay.lua and UnitFlagManager.lua are the only places that monitor this event and both of them use the variable name "fogState" for parameter c. Additionally, the UnitFlagManager identifies the following as the potential fogState values:
Code:
local BlackFog = 0; -- invisible
local GreyFog  = 1; -- once seen
local WhiteFog = 2; -- eyes on
So it looks like this event has something to do with other player's units entering/leaving the active player's field of vision where 0 is probably a unit moving into unrevealed territory, 1 is probably a unit going into revealed territory that's not currently in vision, and 2 is probably a unit moving into a visible tile. I only tested it really briefly though.
 
Also, I rewrote the cityinfo() function on my local copy to provide additional information and use a more rigid format. Changes include city HP if damaged, Governor focus, raze/revolt counter, adjusted production rate, border expansion progress, and estimated turns for border expansion, growth, and production. If you are interested in incorporating any of these changes in the official version, code and sample output are spoilered below.

Spoiler code :
Code:
-- Note also that the print("Cities") line was moved from inside cityinfo() to the process() function so it only prints once

function cityinfo ( pnum, cityid )

	local player = Players[ pnum ]
	local city = player:GetCityByID( cityid )

	local citystatus = "";
	if ( city:IsCapital() ) then
		citystatus = "Capital"
	elseif city:IsRazing() then
		citystatus = string.format("Razing - %d turns", city:GetRazingTurns())
	elseif ( city:IsPuppet() ) then
		citystatus = "Puppet"
	elseif ( city:IsOccupied() and not city:IsNoOccupiedUnhappiness() ) then
		citystatus = "Occupied";
	end

	local cityrevolt = ""
	if city:IsResistance() then
		cityrevolt = string.format("Revolt - %d turns", city:GetResistanceTurns())
	end

	local cityfocus = ""
	local focusType = city:GetFocusType()
	-- There's probably a way to iterate and retreive names from the localized text keys
	-- Note also AI has access to extra focus types not available on CityView screen
	if focusType ~= CityAIFocusTypes.NO_CITY_AI_FOCUS_TYPE then
		if focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FOOD then
			cityfocus = "Food"
		elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_PRODUCTION then
			cityfocus = "Production"
		elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GOLD then
			cityfocus = "Gold"
		elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_SCIENCE then
			cityfocus = "Science"
		elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_CULTURE then
			cityfocus = "Culture"
		elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GREAT_PEOPLE then
			cityfocus = "Great Person"
		elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GOLD_GROWTH then
			cityfocus = "Gold/Growth"
		elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_PROD_GROWTH then
			cityfocus = "Prod/Growth"
		else 
			cityfocus = "Unknown"
		end
		cityfocus = cityfocus .. " Focus"
	end

	-- Using cityextra as a way to keep all the extra info directly under the city name.
	-- Note that values are inserted in reverse order of priority.
	local cityextra = {"", "", ""}
	if cityrevolt ~= "" then table.insert(cityextra, 1, cityrevolt) end
	if citystatus ~= "" then table.insert(cityextra, 1, citystatus) end
	if cityfocus ~= "" then table.insert(cityextra, 1, cityfocus) end

	local cityHP = ""
	if city:GetDamage() > 0 then
		local fullHP = GameDefines.MAX_CITY_HIT_POINTS
		cityHP = string.format( "HP: %2d/%2d", fullHP - city:GetDamage(), fullHP )
	end

	print(string.format("%-20s  Size: %-3d  Strength: %-3d  %s",
						city:GetName(), city:GetPopulation(),
						math.floor( city:GetStrengthValue() / 100 ), cityHP))
	local rate = city:GetJONSCulturePerTurn()
	local stored = city:GetJONSCultureStored()
	local threshold = city:GetJONSCultureThreshold()
	local turns = ""
	if rate ~= 0 then
		turns = string.format("(%d turns)", math.ceil( ( threshold - stored ) / rate ))
	end
	print(string.format("  %-18s  Gold: %-3d  Science: %-3d   Culture: %-3d  Expand: %d/%d %s",
						cityextra[ 1 ], city:GetYieldRateTimes100( YieldTypes.YIELD_GOLD ) / 100 ,
						city:GetYieldRateTimes100( YieldTypes.YIELD_SCIENCE ) / 100,
						rate, stored, threshold, turns ))
	rate = city:FoodDifference()
	stored = city:GetFood()
	threshold = city:GrowthThreshold()
	turns = ""
	if rate ~= 0 then
		turns = string.format("(%d turns)", math.ceil( math.abs( threshold - stored ) / rate ))
	end
	print(string.format("  %-18s  Food: %-3d  (%3d produced - %3d eaten)   Growth: %d/%d %s",
						cityextra[ 2 ], rate, city:GetYieldRateTimes100( YieldTypes.YIELD_FOOD ) / 100,
						city:FoodConsumption(true, 0), stored, threshold, turns ))
	rate = city:GetCurrentProductionDifferenceTimes100( false, false ) / 100
	stored = city:GetProductionTimes100() / 100
	threshold = city:GetProductionNeeded()
	if threshold < 0 or threshold == 2147483647 then threshold = 0 end
	turns = ""
	if rate ~= 0 then
		turns = string.format("(%d turns)", math.ceil( ( threshold - stored ) / rate ))
	end
	print(string.format("  %-18s  Prod: %-3d  (%3d base)     Producing: %s %d/%d %s",
						cityextra[ 3 ], math.floor( rate ), 
						city:GetYieldRateTimes100( YieldTypes.YIELD_PRODUCTION ) / 100,
						Locale.ConvertTextKey( city:GetProductionNameKey() ),
						math.floor( stored ), threshold, turns ))
	print("")
end

Spoiler output :
Code:
 aiinfodump: Cities:
 aiinfodump: Onondaga              Size: 12   Strength: 18   
 aiinfodump:   Capital             Gold: 17   Science: 15    Culture: 1    Expand: 44/60 (16 turns)
 aiinfodump:                       Food: 12   ( 34 produced -  24 eaten)   Growth: 46/155 (10 turns)
 aiinfodump:                       Prod: 18   ( 18 base)     Producing: Archer 60/70 (1 turns)
 aiinfodump: 
 aiinfodump: Osininka              Size: 7    Strength: 12   
 aiinfodump:   Prod/Growth Focus   Gold: 7    Science: 7     Culture: 2    Expand: 5/75 (35 turns)
 aiinfodump:                       Food: 4    ( 18 produced -  14 eaten)   Growth: 50/76 (7 turns)
 aiinfodump:                       Prod: 7    (  7 base)     Producing: Walls 98/100 (1 turns)
 aiinfodump: 
 aiinfodump: Grand River           Size: 5    Strength: 10   
 aiinfodump:                       Gold: 8    Science: 5     Culture: 2    Expand: 6/45 (20 turns)
 aiinfodump:                       Food: 2    ( 12 produced -  10 eaten)   Growth: 1/51 (25 turns)
 aiinfodump:                       Prod: 9    (  9 base)     Producing: Barracks 63/80 (2 turns)
 aiinfodump: 
 aiinfodump: Akwesasme             Size: 6    Strength: 10   
 aiinfodump:   Prod/Growth Focus   Gold: 6    Science: 6     Culture: 2    Expand: 14/45 (16 turns)
 aiinfodump:                       Food: 2    ( 14 produced -  12 eaten)   Growth: 28/63 (18 turns)
 aiinfodump:                       Prod: 13   ( 13 base)     Producing: Forge 110/150 (4 turns)
 aiinfodump: 
 aiinfodump: Buffalo Creek         Size: 4    Strength: 16   
 aiinfodump:                       Gold: 6    Science: 4     Culture: 2    Expand: 18/45 (14 turns)
 aiinfodump:                       Food: 4    ( 12 produced -   8 eaten)   Growth: 32/40 (2 turns)
 aiinfodump:                       Prod: 8    (  8 base)     Producing: Scout 0/25 (4 turns)
 aiinfodump: 
 aiinfodump: Brantford             Size: 5    Strength: 11   
 aiinfodump:   Science Focus       Gold: 4    Science: 5     Culture: 2    Expand: 22/30 (4 turns)
 aiinfodump:                       Food: 3    ( 13 produced -  10 eaten)   Growth: 13/51 (13 turns)
 aiinfodump:                       Prod: 8    (  8 base)     Producing: Granary 99/100 (1 turns)
 aiinfodump: 
 aiinfodump: Montreal              Size: 5    Strength: 10   
 aiinfodump:   Science Focus       Gold: 5    Science: 5     Culture: 2    Expand: 14/30 (8 turns)
 aiinfodump:                       Food: 3    ( 13 produced -  10 eaten)   Growth: 14/51 (13 turns)
 aiinfodump:                       Prod: 5    (  5 base)     Producing: Longhouse 58/80 (5 turns)
 aiinfodump: 
 aiinfodump: Genesse River         Size: 2    Strength: 9    
 aiinfodump:                       Gold: 3    Science: 2     Culture: 0    Expand: 0/20 
 aiinfodump:                       Food: 5    (  9 produced -   4 eaten)   Growth: 18/22 (1 turns)
 aiinfodump:                       Prod: 3    (  3 base)     Producing: Longhouse 22/80 (20 turns)
 aiinfodump: 
 aiinfodump: Sparta                Size: 2    Strength: 9    HP: 13/20
 aiinfodump:   Gold Focus          Gold: 4    Science: 2     Culture: 0    Expand: 0/20 
 aiinfodump:   Puppet              Food: 4    (  8 produced -   4 eaten)   Growth: 12/22 (3 turns)
 aiinfodump:                       Prod: 4    (  4 base)     Producing: Monument 8/60 (13 turns)
 aiinfodump:
 aiinfodump: Persepolis            Size: 4    Strength: 11   HP: 11/20
 aiinfodump:   Gold Focus          Gold: 0    Science: 0     Culture: 0    Expand: 0/20 
 aiinfodump:   Puppet              Food: 0    ( 16 produced -   8 eaten)   Growth: 0/40 
 aiinfodump:   Revolt - 3 turns    Prod: 0    (  4 base)     Producing:  0/0 
 aiinfodump: 
 aiinfodump: Pasargadae            Size: 1    Strength: 10   HP: 11/20
 aiinfodump:   Razing - 1 turns    Gold: 0    Science: 0     Culture: 0    Expand: 0/20 
 aiinfodump:   Revolt - 1 turns    Food: 0    (  8 produced -   2 eaten)   Growth: 0/15 
 aiinfodump:                       Prod: 0    (  2 base)     Producing:  0/0 
 aiinfodump: 
 aiinfodump: Susa                  Size: 3    Strength: 11   HP: 11/20
 aiinfodump:   Occupied            Gold: 0    Science: 0     Culture: 0    Expand: 0/20 
 aiinfodump:   Revolt - 2 turns    Food: 0    ( 15 produced -   6 eaten)   Growth: 0/30 
 aiinfodump:                       Prod: 0    (  2 base)     Producing: Monument 0/60 
 aiinfodump:
 
very nice find for the unitstatechange event :)

that thing has been bugging me for a while, always triggering for nearby AI units. it's more than likely just like you said a visibility thing
 
I'm going to give this a try right now. I need to try to figure out why the AI is not researching the new tech tree I made.

i hope it helps you and that relevant information is still being shown. haven't tested this or most of the lua api with the latest patches in a while now. really should go over all the changes and so forth, its on a todo list :)
 
Can't find "aiinfodump" in my state drop-down - any idea what causes this?

Here is my LUA message when game is loaded:


[ Lua State = Main State ]
InstalledPanel: Refreshing Mods
InstalledPanel: ModID IN ('f5028cac-d749-4b76-a05e-83331b857ca1', 'd565342c-f7b5-495e-9c1d-c05c2d55c8a3')
InstalledPanel: Refreshing Mods
InstalledPanel: Refreshing Mods
InstalledPanel: Refreshing Mods
InstalledPanel: Refreshing Mods
CivilopediaScreen: SetSelectedCategory(12)
CivilopediaScreen: CivilopediaCategory[CategoryTerrain].DisplayList
CivilopediaScreen: SetSelectedCategory(1)
CivilopediaScreen: CivilopediaCategory[CategoryHomePage].DisplayList
Tutorial: Enabling Tutorial
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmImprovementRebuildPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\CityPlotManagementPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCommandPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivEnterTerritoryPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\LiberateMinorPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ReturnCivilianPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\AnnexCityPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarMovePopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\BarbarianRansomPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmGiftPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmCityTaskPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\PuppetCityPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\DeclareWarRangeStrikePopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\ConfirmPolicyBranchPopup.lua
GenericPopup: Loaded Popup - Assets\UI\InGame\PopupsGeneric\MinorCivGoldPopup.lua
Runtime Error: [string "Assets/UI/InGame/InGame.lua"]:1076: attempt to index local 'addinFile' (a nil value)
Runtime Error: Error loading Assets/UI/InGame/InGame.lua.
TechTree: AdvisorControl could not be found
 
Yeah this doesn't show up on my livetuner list either, and it looks like exactly what I've been looking for in regards to data mining.

Anyone think they'd be able to fix this mod? It probably is just out of date.
 
ive been able to found the problem on latest civ version . apparently with gods and kings, isWorkingWithPlayer() was removed (forums.civfanatics.com/showthread.php?p=11588466), it was a function that was used to check if a player was in pact of cooperation something that has been replaced with declarations of friendship. so to make it work replace isWorkingWithPlayer() by isFriends(). That's in AI "info dump (v 1.35)/lua/aiinfodump.lua" line 925

edit: you also need to get ride of the pact of secrecy code or replace it with Player.IsDenouncingPlayer(not sure)
 
Last edited:
Top Bottom