Detecting combat?

Does RunCombatSim not work for Strategic View? It's what I've been using for my own combat-related Lua functions. But I never use strategic view, so I haven't checked it for that.
 
Apparently "combat sim" is "combat animation," not triggered at all in strategic view. Unit flags use the event because they hide during the combat animation.
 
I guess that's not entirely surprising given the UI-centric nature of the other Events class members, but that would mean combat is an even bigger hole in the event system than I previously thought. :(

Events.SerialEventUnitSetDamage seems to be triggered by combat regardless of the view, but it's also triggered by other things (like healing.) If the damage increases I guess you can assume combat was involved (for the vanilla game) but you can't tell why there was damage or what other units/cities were involved. Listener arguments for that appear to be (playerID, unitID, newDamage, oldDamage). There's a similar event for cities but it has 3 more arguments.
 
I guess that's not entirely surprising given the UI-centric nature of the other Events

The strange thing about this? It's not even CONSISTENT on which are UI-related. For instance:

SerialEventImprovementCreated: triggers whenever you first see an improvement, but it actually has the potential to trigger TWICE, once when the improvement is started (status = 2), and one when it's completed (status=4), because it's supposed to be used to determine whether to show the "in progress" version of the improvement in the UI. So this one's clearly UI-linked (although the 2-state triggering makes some logic very difficult to use).

But SerialEventUnitCreated, on the other hand, triggers whenever a unit is created, period. Seriously, create an Event that uses this, and just put a print statement in it to say which civ name and which unit type it is. Then start up a new game. You'll see N settlers and N Warriors for an Ancient start, plus the city-state settlers. So clearly this one doesn't depend on the user seeing the event happen.

EDIT: However, I've just discovered one problem with SerialEventUnitCreated: while it triggers whenever a new unit is added to the game, it ALSO triggers whenever a unit embarks or disembarks, since this would trigger a redraw. So it's not perfect.
 
I was going to post a thread, but I'm thinking that (sadly) this answers my question...

I was hoping that I could hook into the game events system somehow to know when a unit is damaged, for how much, and by what. I needed this event to be triggered for all units in the game regardless of ownership of visibility, challenging when so much of the LUA is UI centric.

I had the idea of putting together a simple Zombie Apocalypse themed mod that replaced Barbarians with Zombies. Unoriginal I know, but I didn't know that until I started digging around for help with it and by then the idea had latched on :P

Original plan was to introduce a new unit promotion for any Zombie unit, which would incorporate all the attributes which can be configured in XML (resistant to range damage etc) but also be checked for in a combat related event handler. Such a handler doesn't seem to exist.

I wanted to have Zombies heal by the amount of damage they did, and create a new Zombie unit if this took them over max health. I may have to settle for the vanilla full heal on killing a unit.
 
I was hoping that I could hook into the game events system somehow to know when a unit is damaged, for how much, and by what. I needed this event to be triggered for all units in the game regardless of ownership of visibility, challenging when so much of the LUA is UI centric.

RunCombatSim and EndCombatSim do this. They're the combat event handlers; RunCombatSim triggers at the start of the combat (and its damage numbers will be the "projected" ones you see when you mouse over an enemy unit), while EndCombatSim triggers at the end of combat. The arguments include unit and player IDs, starting damage, ending damage, and a couple other things. They don't depend on whether a fight is visible to the active player.

For instance, in my Alpha Centauri mod, RunCombatSim applies the effects of three custom promotions (Critical Strike: 10% chance of dealing +5 damage. Spontaneous Healing: 10% chance of healing 5 damage. Synthesis: can steal promotions from your opponent.), and a similar RunCombatSim event causes Psi units' base power to shift to more closely match that of their opponents in every fight.
I also use EndCombatSim; in my mod, every new unit starts with the Rookie promotion (-25% combat but x2 XP gain) until the end of its first fight, where that promotion is removed. This is necessary to fix the UnitCreated degeneracies mentioned earlier in this thread. So yes, I know these events both work just fine.

The only catch on these is that the events apparently only trigger when you're NOT in Strategic View. But as long as you tell your mod's users that it's not compatible with SV (like how most complex mods aren't compatible with multiplayer), then you'll be fine.
 
Thanks for the clarification, sounds like those events are exactly what I need as long as they player isn't in strategic view. Easy solution then would be to try to take the strategic view button out of the UI :p
 
And so also not in multiplayer I guess, not that it is an issue yet with multiplayer mods not being enabled.

Despite all the posturing on Civ 5 "modability", it looks like Firaxis really didn't have a lot of vision around a modders desire to extend the game rules / engine. Even if their core engine uses C++ for all of the game events handling, creating a LUA method stub or event trigger would have made complex changes much less "hacky".
 
Strategic view is still very useful for planning... strategy. :lol: City placement and such.

I haven't ever used it for regular gameplay though, so it's not a big restriction for me.
 
I haven't ever used it for regular gameplay though, so it's not a big restriction for me.

I'm the same way. It's just unfortunate that to use the functions we want, we have to continually add to the list of things that the players can't use. No strategic view, or else you can't use RunCombatSim. No Quick Combat. No multiplayer. Limited use of custom maps. At some point, you reach the threshold where your mods become unplayable in any way other than the way you do it, and that's not good in the long term.

But yes, losing Strategic View isn't generally much of a problem. It's nice as a planning tool, although I never use it any more (on-map grids work just fine for me), but if you're not using the normal map view for general gameplay, then what's the point?
 
Back
Top Bottom