#include "pch.h"
#include "SetCommandAction.h"
#include "TypeIDTarget.h"
#include "TrainingMission.h"
namespace Training
{
extern TrainingMission* g_pMission;
SetCommandAction::SetCommandAction (IshipIGC* pShip, Command command, ImodelIGC* pTarget, CommandID commandID) :
m_pShip (new TypeIDTarget (pShip->GetObjectType (), pShip->GetObjectID ())),
m_pTarget (new TypeIDTarget (pTarget ? pTarget->GetObjectType () : NA, pTarget ? pTarget->GetObjectID () : NA)),
m_command (command),
m_commandID (commandID)
{
}
SetCommandAction::SetCommandAction (IshipIGC* pShip, Command command, ObjectType targetType, ObjectID targetID, CommandID commandID) :
m_pShip (new TypeIDTarget (pShip->GetObjectType (), pShip->GetObjectID ())),
m_pTarget (new TypeIDTarget (targetType, targetID)),
m_command (command),
m_commandID (commandID)
{
}
SetCommandAction::SetCommandAction (ShipID shipID, Command command, ObjectType targetType, ObjectID targetID, CommandID commandID) :
m_pShip (new TypeIDTarget (OT_ship, shipID)),
m_pTarget (new TypeIDTarget (targetType, targetID)),
m_command (command),
m_commandID (commandID)
{
}
SetCommandAction::SetCommandAction (ShipID shipID, Command command, ImodelIGC* pTarget, CommandID commandID) :
m_pShip (new TypeIDTarget (OT_ship, shipID)),
m_pTarget (new TypeIDTarget (pTarget ? pTarget->GetObjectType () : NA, pTarget ? pTarget->GetObjectID () : NA)),
m_command (command),
m_commandID (commandID)
{
}
SetCommandAction::~SetCommandAction (void)
{
delete m_pShip;
delete m_pTarget;
}
void SetCommandAction::Execute (void)
{
IshipIGC* pShip = static_cast<IshipIGC*> (static_cast<ImodelIGC*> (*m_pShip));
ImodelIGC* pTarget = static_cast<ImodelIGC*> (*m_pTarget);
if (pShip)
{
if ((pShip == trekClient.GetShip ()) and (m_command == c_cmdQueued))
{
TrekWindow* pWindow = GetWindow ();
IshipIGC* pCommander = g_pMission->GetCommanderShip ();
ZString strOrder = ZString (c_cdAllCommands[m_commandID].szVerb);
if (pTarget)
strOrder = strOrder + " " + GetModelName (pTarget);
pWindow->SetQueuedCommand (pCommander, m_commandID, pTarget);
trekClient.PostText(true, "New orders from %s to %s: %s. Press [insert] to accept.", (const char*)GetModelName (pCommander), GetModelName (pShip), (const char*) strOrder);
}
else
pShip->SetCommand (m_command, pTarget, m_commandID);
}
}
}