GameEvents and the DLL source

PawelS

Ancient Druid
Joined
Dec 11, 2003
Messages
2,811
Location
Poland
In order to understand the Lua GameEvents better, I wanted to search for them in the DLL code. To my surprise, in the entire source code I found only one occurrence of "GameEvents", in a comment. So can someone enlighten me by telling me where the GameEvents are declared? :)

Edit: Also, is there a way to display all GameEvents using FireTuner?
 
There are 3 types: "CallHook", "CallTestAll", and "CallAccumulator".

For convenience here is a list of "GameEvents" (of course the parameters in parentheses are those provided to the hooked function when called, which first needs to be hooked up with GameEvents.xxxx.Add( yourfunction_xxxx ) and until removed by GameEvents.xxxx.Remove( yourfunction_xxxx ) ):

"CallHook":
SetPopulation( x, y, oldPopulation, newPopulation )
GameCoreUpdateBegin()
GameCoreUpdateEnd()
GameCoreTestVictory()
SetAlly( minorPlayerID, oldAllyID, newAllyID )
CityCaptureComplete( oldOwnerID, isCapital, x, y, newOwnerID [BNW:,bConquest, iGreatWorksPresent, iGreatWorksXferred] )
PlayerDoTurn( playerID )
PlayerAdoptPolicy( playerID, policyID )
PlayerAdoptPolicyBranch( playerID, policyBranchID )
UnitKilledInCombat( killerID, ownerID, unitTypeID )
GatherPerTurnReplayStats( playerID )
PlayerPreAIUnitUpdate( playerID )
TeamMeet( teamID1, teamID2 )
TeamTechResearched( teamID, techID, enhancedItemChange )
TeamSetHasTech( teamID, techID, isHasTech )
UnitSetXY( ownerID, unitID, x, y )
G&K BNW:
PlayerCityFounded( playerID, x, y )
CityConvertsReligion( ownerID, religionID, x, y )
BNW:
BuildFinished( playerID, x, y, improvementID )

"CallTestAll":
CanDeclareWar( myTeamID, theirTeamID ) --> true/false
CityCanConstruct( playerID, cityID, buildingTypeID ) --> true/false
CityCanTrain( playerID, cityID, unitTypeID ) --> true/false
CityCanCreate( ownerID, cityID, projectTypeID ) --> true/false
CityCanPrepare( ownerID, cityID, specialistTypeID ) --> true/false
CityCanMaintain( ownerID, cityID, processTypeID ) --> true/false
CityCanBuyPlot( ownerID, cityID, x, y ) --> true/false
CityCanBuyAnyPlot( ownerID, cityID ) --> true/false
PlayerCanTrain( playerID, unitTypeID ) --> true/false
PlayerCanConstruct( playerID, buildingTypeID ) --> true/false
PlayerCanCreate( playerID, projectTypeID ) --> true/false
PlayerCanPrepare( playerID, specialistTypeID ) --> true/false
PlayerCanMaintain( playerID, processTypeID ) --> true/false
PlayerCanAdoptPolicy( playerID, policyID ) --> true/false
PlayerCanAdoptPolicyBranch( playerID, policyBranchID ) --> true/false
PlayerCanEverResearch( playerID, techID ) --> true/false
PlayerCanResearch( playerID, techID ) --> true/false
CanPillage( playerID, unitID, missionID ) --> true/false
UnitGetSpecialExploreTarget( ownerID, unitID ) --> true/false
Except BNW:
DoResolveVictoryVote( isPreliminaryVote ) --> true/false
G&K BNW:
CityBuildingsIsBuildingSellable( ownerID, buildingID ) --> true/false
BNW:
CanStartMission( playerID, unitID, missionID ) --> true/false
CanDisplaceCivilian( playerID, unitID ) --> true(prevents unit from being captured or killed)/false
CanSaveUnit( player, unitID ) --> true(prevents unit from being killed)/false
CityStrategyCanActivate( strategyID, playerID, cityID ) --> true/false
EconomicStrategyCanActivate( strategyID, playerID ) --> true/false
MilitaryStrategyCanActivate( strategyID, playerID ) --> true/false

"CallAccumulator"
GK & BNW:
GetScenarioDiploModifier1( playerID1, playerID2 ) --> integer modifier
GetScenarioDiploModifier2( playerID1, playerID2 ) --> integer modifier
GetScenarioDiploModifier3( playerID1, playerID2 ) --> integer modifier
-- What religion should this AI civ be spreading?
GetReligionToSpread( playerID ) --> religionID
-- Get the religion for which this player is eligible for founder benefits
GetFounderBenefitsReligion( playerID ) --> religionID

correction
 
Thanks for the information :)

@bc1: Your list doesn't seem to be complete, as it doesn't contain PlayerCanConstruct, which I'm using successfully in my mod...
 
There are 3 types: "CallHook", "CallTestAll", and "CallAccumulator".

A fourth is available to DLL modders (but unused by the standard game core) "CallTestAny"
 
If I understand it correctly, CallTestAll will check multiple conditions (defined as functions) using AND, and CallTestAny using OR, right?

CallHook just triggers an event when something happens, but what does "CallAccumulator" mean?
 
If I understand it correctly, CallTestAll will check multiple conditions (defined as functions) using AND, and CallTestAny using OR, right?

CallHook just triggers an event when something happens, but what does "CallAccumulator" mean?

CallTestAll - every connected Lua function has to return true for the composite event to return true (ie it's an AND)

CallTestAny - any connected Lua function has to return true for the composite event to return true (ie it's an OR)

CallHook - just a notification of something happening

CallAccumulator - same as CallHook, but the Lua function can return a value back to the game core. If more than one Lua function is connected the value passed back to the game core will be the sum of all individual values (ie the values are accumulated) - used in my own DLL mod to get a variable range for city bombard radius, to pre-select a religion for a player, to over-ride the AI's choice of next tech, etc
 
"CallTestAll" should "and" the values returned by hooked function calls
"CallAccumulator" should sum the values returned by hooked function calls
but I am not sure they actually work with more than one listener :lol:
Edit: whoward69 has tested they do, but that would give funny results with "GetReligionToSpread" and "GetFounderBenefitsReligion" ...
"CallHook" will just call the hooked function (i.e. treated as a method)
 
I wasn't aware of the new BNW GameEvents. Some of these look very useful, if I'm interpreting/guessing their function correctly:

  • BuildFinished( playerID, x, y, improvementID ) We can hook Lua logic onto the completion of any improvement. No longer need to scan whole map to find them as we did before.

  • CanStartMission( playerID, unitID, missionID ) --> true/false This seems pretty versatile. We can control whether a unit can do a particular mission. For example, prevent some unit from doing a ranged attack under some condition. (But overhead may be high.)

  • CanDisplaceCivilian( playerID, unitID ) --> true(prevents unit from being captured or killed)/false; CanSaveUnit( player, unitID ) --> true(prevents unit from being killed)/false These two interest me very much. Question for DLL modders: Can one or both of these save the unit object from being deleted in all cases? (Even obcsure ones like being cargo on a ship that sinks?)

  • CityStrategyCanActivate( strategyID, playerID, cityID ) --> true/false; EconomicStrategyCanActivate( strategyID, playerID ) --> true/false; MilitaryStrategyCanActivate( strategyID, playerID ) --> true/false More Lua control of AI is always welcome.

Another question. Is there any way to scan the DLL for Events (as opposed to GameEvents). I realize that these are in the graphics engine that we don't have access to. But I have to assume that our DLL calls these from time to time. Is there some searchable signature when this happens?
 
Another question. Is there any way to scan the DLL for Events (as opposed to GameEvents). I realize that these are in the graphics engine that we don't have access to. But I have to assume that our DLL calls these from time to time. Is there some searchable signature when this happens?

Don't know of anyway to find the Events that the dll calls, but you can find all "cross-dll" calls from the game core to the UI with ...

As a regexp
Code:
(GC\.GetEngineUserInterface|DLLUI)

Edit: Note that there are weird sequencing issues calling multiple UI methods in series, from my own comments in the code for "UI - City Expansion"

Code:
// We want the C++ equivalent of UI.SetInterfaceMode(INTERFACEMODE_PURCHASE_PLOT) followed by
// UI.DoSelectCityAtPlot(pPlot) (which itself happens to be bugged!)
// The following is identical to the "Select Next City" then "Open City View" keyboard short-cuts code,
// but it always opens the capital's city view screen!
// DLLUI->selectCity(GC.WrapCityPointer(pCity).get());
// DLLUI->setInterfaceMode(INTERFACEMODE_PURCHASE_PLOT);
// DLLUI->selectLookAtCity();
// DLLUI->lookAtSelectionPlot();
 
BuildFinished( playerID, x, y, improvementID ) We can hook Lua logic onto the completion of any improvement. No longer need to scan whole map to find them as we did before.
Used in the Scramble Africa scenario to detect completion of archelogical digs, should work for any type.
CanStartMission( playerID, unitID, missionID ) --> true/false[/B] This seems pretty versatile. We can control whether a unit can do a particular mission. For example, prevent some unit from doing a ranged attack under some condition. (But overhead may be high.)
Not used by Firaxis...
CanDisplaceCivilian( playerID, unitID ) --> true(prevents unit from being captured or killed)/false[/B]; CanSaveUnit( player, unitID ) --> true(prevents unit from being killed)/false These two interest me very much. Question for DLL modders: Can one or both of these save the unit object from being deleted in all cases? (Even obcsure ones like being cargo on a ship that sinks?)
The DLL seems to pre-empt destruction of units whenever an event listener exits and returns "true", in two possible cases. Now it's used in Civil War scenario to avoid GG's from getting killed or captured, so you can easily test whether it works for embarked...
CityStrategyCanActivate( strategyID, playerID, cityID ) --> true/false[/B]; EconomicStrategyCanActivate( strategyID, playerID ) --> true/false; MilitaryStrategyCanActivate( strategyID, playerID ) --> true/false More Lua control of AI is always welcome.
Used in the Civil War and Scramble Africa scenarii to force AI behavior
Another question. Is there any way to scan the DLL for Events (as opposed to GameEvents). I realize that these are in the graphics engine that we don't have access to. But I have to assume that our DLL calls these from time to time. Is there some searchable signature when this happens?
AFAIK "Events" are not part of the DLL, they are in the executable. The list is the following:
Spoiler :
AbortCombatSim, ActivePlayerTurnEnd, ActivePlayerTurnStart, AddPopupTextEvent, AddUnitMoveHexRangeHex, AdvisorDisplayHide, AdvisorDisplayShow, AfterModsActivate, AfterModsDeactivate, AILeaderMessage, AIProcessingEndedForPlayer, AIProcessingStartedForPlayer, AIProcessingStepChanged, AnimationSamplingChanged, AppInitComplete, AudioAdvanceCurrentPlaylistTrack, AudioDebugChangeMusic, AudioPlay2DSound, AudioRewindCurrentPlaylistTrack, AudioVolumeChanged, BeforeModsActivate, BeforeModsDeactivate, BuildingLibrarySwap, CameraProjectionChanged, CameraStartPitchingDown, CameraStartPitchingUp, CameraStartRotatingCCW, CameraStartRotatingCW, CameraStopPitchingDown, CameraStopPitchingUp, CameraStopRotatingCCW, CameraStopRotatingCW, CameraViewChanged, ChangeGameState, CityDestroyedRazedClearedAndSalted, CityHandleCreated, CityRuinsCreated, ClearDiplomacyTradeTable, ClearHexHighlights, ClearHexHighlightStyle, ClearUnitMoveHexRange, ConnectedToNetworkHost, DisplayMovementIndicator, DontRecordCommandStreams, DragCamera, EndCombatSim, EndGameShow, EndTurnBlockingChanged, EndTurnTimerUpdate, EndUnitMoveHexRange, Event_ToggleTradeRouteDisplay, EventOpenOptionsScreen, EventPoliciesDirty, ExitToMainMenu, FloodplainCreated, FrontEndPopup, GameMessageChat, GameOptionsChanged, GameplayAlertMessage, GameplayFX, GameplaySetActivePlayer, GameViewTypeChanged, GenericWorldAnchor, GlobalUnitScale, GoldenAgeEnded, GoldenAgeStarted, GoToPediaHomePage, GraphicsOptionsChanged, GreatWallCreated, HexFOWStateChanged, HexYieldMightHaveChanged, InitCityRangeStrike, InterfaceModeChanged, KeyUpEvent, LandmarkLibrarySwap, LanguageChanging, Leaderboard_ScoresDownloaded, LeavingLeaderViewMode, LoadScreenClose, LocalMachineAppUpdate, LocalMachineUnitPositionChanged, MarshCreated, MarshRemoved, MinimapClickedEvent, MinimapTextureBroadcastEvent, MultiplayerConnectionComplete, MultiplayerConnectionFailed, MultiplayerGameAbandoned, MultiplayerGameHostMigration, MultiplayerGameInvite, MultiplayerGameLastPlayer, MultiplayerGameLaunched, MultiplayerGameListClear, MultiplayerGameListComplete, MultiplayerGameListUpdated, MultiplayerGamePlayerDisconnected, MultiplayerGamePlayerUpdated, MultiplayerHotJoinCompleted, MultiplayerHotJoinStarted, MultiplayerJoinRoomAttempt, MultiplayerJoinRoomComplete, MultiplayerJoinRoomFailed, MultiplayerPingTimesChanged, MultiplayerProfileDisconnected, MultiplayerProfileFailed, NaturalWonderRevealed, NewGameTurn, NotificationActivated, NotificationAdded, NotificationRemoved, NotifyAILeaderInGame, OpenInfoCorner, OpenPlayerDealScreenEvent, ParticleEffectReloadRequested, ParticleEffectStatsRequested, ParticleEffectStatsResponse, PlayerChoseToLoadGame, PlayerChoseToLoadMap, PlayerVersionMismatchEvent, PreGameDirty, RandomSeedSet, RecordCommandStreams, RemotePlayerTurnEnd, RemotePlayerTurnStart, RemoveAllArrowsEvent, RequestYieldDisplay, RestartGame, RiverTileAdded, RunCombatSim, SearchForPediaEntry, SequenceGameInitComplete, SerialEventBuildingSizeChanged, SerialEventCameraBack, SerialEventCameraCenter, SerialEventCameraForward, SerialEventCameraIn, SerialEventCameraLeft, SerialEventCameraOut, SerialEventCameraRight, SerialEventCameraSetCenterAndZoom, SerialEventCameraStartMovingBack, SerialEventCameraStartMovingForward, SerialEventCameraStartMovingLeft, SerialEventCameraStartMovingRight, SerialEventCameraStopMovingBack, SerialEventCameraStopMovingForward, SerialEventCameraStopMovingLeft, SerialEventCameraStopMovingRight, SerialEventCityCaptured, SerialEventCityContinentChanged, SerialEventCityCreated, SerialEventCityCultureChanged, SerialEventCityDestroyed, SerialEventCityHexHighlightDirty, SerialEventCityInfoDirty, SerialEventCityPopulationChanged, SerialEventCityScreenDirty, SerialEventCitySetDamage, SerialEventDawnOfManHide, SerialEventDawnOfManShow, SerialEventEndTurnDirty, SerialEventEnterCityScreen, SerialEventEraChanged, SerialEventEspionageScreenDirty, SerialEventExitCityScreen, SerialEventFeatureCreated, SerialEventFeatureDestroyed, SerialEventForestCreated, SerialEventForestRemoved, SerialEventGameDataDirty, SerialEventGameInitFinished, SerialEventGameMessagePopup, SerialEventGameMessagePopupProcessed, SerialEventGameMessagePopupShown, SerialEventGreatWorksScreenDirty, SerialEventHexCultureChanged, SerialEventHexDeSelected, SerialEventHexGridOff, SerialEventHexGridOn, SerialEventHexHighlight, SerialEventHexSelected, SerialEventImprovementCreated, SerialEventImprovementDestroyed, SerialEventImprovementIconCreated, SerialEventImprovementIconDestroyed, SerialEventInfoPaneDirty, SerialEventJungleCreated, SerialEventJungleRemoved, SerialEventLeaderToggleDebugCam, SerialEventLeagueScreenDirty, SerialEventMouseOverHex, SerialEventQueueFlushed, SerialEventRawResourceCreated, SerialEventRawResourceDestroyed, SerialEventRawResourceIconCreated, SerialEventRawResourceIconDestroyed, SerialEventResearchDirty, SerialEventRoadCreated, SerialEventRoadDestroyed, SerialEventScoreDirty, SerialEventScreenShot, SerialEventScreenShotTaken, SerialEventStartGame, SerialEventTerrainDecalCreated, SerialEventTerrainOverlayMod, SerialEventTest, SerialEventTestAnimations, SerialEventToggleBridgeState, SerialEventTurnTimerDirty, SerialEventUnitCreated, SerialEventUnitDestroyed, SerialEventUnitDestroyedInCombat, SerialEventUnitFacingChanged, SerialEventUnitFlagSelected, SerialEventUnitInfoDirty, SerialEventUnitMove, SerialEventUnitMoveToHexes, SerialEventUnitSetDamage, SerialEventUnitTeleportedToHex, SerialEventUpdateAllHexCulture, ShowAttackTargets, ShowHexYield, ShowMovementRange, ShowPlayerChangeUI, SpawnArrowEvent, SpecialTileAdded, SpecificCityInfoDirty, StartUnitMoveHexRange, StateMachineDumpStates, StateMachineRequestStates, StrategicViewStateChanged, SystemUpdateUI, TaskListUpdate, TeamMet, TechAcquired, ToggleDisplayUnits, ToolTipEvent, UIPathFinderUpdate, UnitActionChanged, UnitDataEdited, UnitDataRequested, UnitDebugFSM, UnitEmbark, UnitFlagUpdated, UnitGarrison, UnitHandleCreated, UnitHexHighlight, UnitLibrarySwap, UnitMarkThreatening, UnitMemberCombatStateChanged, UnitMemberCombatTargetChanged, UnitMemberOverlayAdd, UnitMemberOverlayMessage, UnitMemberOverlayRemove, UnitMemberOverlayShowHide, UnitMemberOverlayTargetColor, UnitMemberPositionChanged, UnitMoveQueueChanged, UnitNameChanged, UnitResetAnimationState, UnitSelectionChanged, UnitSelectionCleared, UnitShouldDimFlag, UnitStateChangeDetected, UnitTypeChanged, UnitVisibilityChanged, UserRequestClose, VisibilityUpdated, WallCreated, WarStateChanged, WonderCreated, WonderEdited, WonderRemoved, WonderStateChanged, WonderTogglePlacement, WonderTypeChanged, WorldMouseOver

Now you just have to figure out what each one does :lol:
 
I haven't noticed earlier that there is a BuildFinished event. It will be very useful for me, as I'm going to make some types of Great People able to create new resources, which can be done by building a temporary improvement. This way I don't have to use any special methods of enticing the AI to do it - I just need to create an improvement with good yields, so the AI will build it, and then my Lua code will remove it and create a resource on the tile.

There will be a problem with situations where there is already an undiscovered resource on that tile, preferably I'd like to reveal it instead of creating a new one, but I don't know how to do it...
 
Top Bottom