End of human player turn

Pazyryk

Deity
Joined
Jun 13, 2008
Messages
3,584
As noted by others here, Events.ActivePlayerTurnEnd actually fires after the next player's turn starts. Is there an event that really fires before the player's turn is over, say when the human presses the End Turn button?

One strange thing is that when ActivePlayerTurnEnd fires (which is really the next player's turn), unit:MovesLeft() now returns 120 for units that I know used up all their movement (though if I try to move them, they don't move). It's causing me all sorts of problems and I really just need to catch the human player turn before it is really over.
 
Raised a similar thread a while back and concluded that there was no event of this nature.

Last night I ran a few tests on SerialEventEndTurnDirty which seems to fire 3 times on starting the turn and then around 20 on clicking the end turn button.

I tracked the function down to the ActionInfoPanel (don't have name in front of me) and it seems to check the various states to display for the next turn button. If you can figure this function out then your probably a step closer to something useful.

I wrote some code to store each unit's movement points for refueling, but was forced to attach it to the UnitSetXY function. If I had a preference it would have been at the end of the turn to speed things up.
 
Well, I can do it for the human player by intercepting in ActionInfoPanel.lua right before Game.DoControl(iEndTurnControl). This is a case where I only need it for the human player, so that should work for me.
 
Please post any useful findings or examples as I am sure many here would appreciate the knowledge :)
 
Well, I can do it for the human player by intercepting in ActionInfoPanel.lua right before Game.DoControl(iEndTurnControl). This is a case where I only need it for the human player, so that should work for me.

That's not the end of the player's turn, only the end of their manual moves. Any unit with a mission will move after that.
 
That's not the end of the player's turn, only the end of their manual moves. Any unit with a mission will move after that.

I know, but that works for my purpose. What isn't working for me is ActivePlayerTurnEnd because it doesn't really do what its name implies. It should be renamed ActivePlayerAfterNextPlayerTurnStart.

What I'm not 100% sure about is whether we always get to the Game.DoControl(iEndTurnControl) line in ActionInfoPanel.lua exactly once in a turn. I think so, but I'm not sure.
 
If it's an issue, just store the turn you last ran in a file scope variable and test that you're not executing twice in the same turn (and add a warning if you detect a skipped turn)

Code:
local g_LastExecTurn = 0

function ExecOncePerTurn()
  local iThisTurn = Game.GetGameTurn()

  if (iThisTurn = g_LastExecTurn) then
    -- Don't do stuff twice
  elseif (iThisTurn ~= (g_LastExecTurn+1)) then
    -- Oops, we skipped a turn or more
  else
    g_LastExecTurn = iThisTurn

    -- Do some useful stuff
  end
end

(or something like that)
 
Well, just to follow up, Game.DoControl(iEndTurnControl) line in ActionInfoPanel.lua fires whenever you actually end turn by pressing the "Next Turn" button (or really, as whoward69 said, fires as your units with queued moves are moving). However, it does not fire when you end turn by pressing Enter. There is nowhere else in UI that Game.DoControl() is used to end turn (I don't know where the Enter key gets processed in this situation). So that's a failure.

What I really need is a way to catch the game when the human player's queued missions normally fire (which is before end of turn when the player presses Next Turn or achieves the same effect with Enter). But it has to work even if you don't have any queued missions. Is there an event like this or any way to jury rig one?
 
Back
Top Bottom