Let me share a simple solution how to use keyboard to end turn-based turn and combat.
First, let's create (unsafe) scripts on Server side, that will end turn and/or try to end combat. I have chosen
combat.fos for that, but you can add these functions wherever suits you the best.
So this is the function for ending turn:
void unsafe_EndTurnBasedTurn(Critter& player, int, int, int, string@, int[]@)
{
Map@ map = player.GetMap();
if(!valid(map))
return;
if(map.IsTurnBased() && (player.Stat[ST_CURRENT_AP] > 0 || player.Stat[ST_MOVE_AP] > 0))
{
player.StatBase[ST_CURRENT_AP] = 0;
player.StatBase[ST_MOVE_AP] = 0;
}
}
Basically, what is done here (besides some basic checks), is we are setting Action points of player to 0 and also Move AP for Bonus move perk to 0 (thanks b_B), which makes engine to end current turn.
To end combat we have to use MODE_END_COMBAT for that, which says to engine that we would like to end combat. Function looks like this:
void unsafe_EndTurnBasedTurn(Critter& player, int, int, int, string@, int[]@)
{
Map@ map = player.GetMap();
if(!valid(map))
return;
if(map.IsTurnBased() && (player.Stat[ST_CURRENT_AP] > 0 || player.Stat[ST_MOVE_AP] > 0))
{
player.ModeBase[MODE_END_COMBAT] = 1;
player.StatBase[ST_CURRENT_AP] = 0;
player.StatBase[ST_MOVE_AP] = 0;
}
}
That's it for server side.
Next think we need to do is to call these (unsafe) scripts from client side. We decided to use keyboard input for that, more specifically SPACE to end turn and CTRL+SPACE to end combat. Of course, you can use whatever shortkeys that suits you better.
Let's create simple functions that will do some checking before calling our (unsafe) scripts. I will add them to
client_main.fos for simplicity of the example, but again, add them wherever they suit better in your code (to make it cleaner).
bool EndTurnBasedTurn()
{
if(__ConsoleActive)
return false;
CritterCl@ chosen = GetChosen();
if(valid(chosen) && chosen.IsTurnBasedTurn())
{
RunServerScriptUnsafe( "combat@unsafe_EndTurnBasedTurn", 0, 0, 0, null, null );
return true;
}
return false;
}
bool EndTurnBasedCombat()
{
if(__ConsoleActive)
return false;
CritterCl@ chosen = GetChosen();
if(valid(chosen) && chosen.IsTurnBasedTurn())
{
RunServerScriptUnsafe( "combat@unsafe_EndTurnBasedCombat", 0, 0, 0, null, null );
return true;
}
return false;
}
And finally, let's use them in
client_main.fos in function
key_down. So add following lines before return statement:
if(!AltDown && !ShiftDown && !CtrlDown && key == DIK_SPACE)
if(EndTurnBasedTurn())
return true;
if(!AltDown && !ShiftDown && CtrlDown && key == DIK_SPACE)
if(EndTurnBasedCombat())
return true;
And now, let's enjoy turn-based combats even more.
Implemented solution can be also found in FOnline: Vault 112 project.