diff --git a/binaries/data/mods/official/gui/test/functions_page_session_status_commands.js b/binaries/data/mods/official/gui/test/functions_page_session_status_commands.js index aa72a1b3ab..b921bb761f 100644 --- a/binaries/data/mods/official/gui/test/functions_page_session_status_commands.js +++ b/binaries/data/mods/official/gui/test/functions_page_session_status_commands.js @@ -379,22 +379,17 @@ function updateTab (tab, type, cellSheet, attribute, attribute2, arrayCells) { // Extract the properties from the comma-delimited string. var tempArray = parseDelimiterString (this.hotkey, ","); - // Set .curr property to refer to this item. -// console.write (tempArray[0]); -// console.write (tempArray[1]); - tempStr = tempArray[0] + " = '" + tempArray[1] + "'"; - eval(tempStr); -// console.write (tempArray[0]); -// console.write (tempArray[1]); -// console.write (selection[0].traits.ai.stance.curr); // Refresh tab so it displays the new .curr sprite. tabCounter = tempArray[4]; - updateTab (tempArray[3], "pick", "", tempArray[2], tempArray[0]); + updateTab (tempArray[3], "pick", "", tempArray[2], '"' + tempArray[1] + '"'); // Do case-specific stuff depending on name of tab. switch (tempArray[3]) { + case "stance": + issueCommand(selection, true, NMT_SET_STANCE, tempArray[1]); + break; case "formation": // Remove the selected units from any existing formation. removeFromFormation (selection); @@ -661,11 +656,11 @@ function refreshCommandButtons() updateTab ("barter", "production", "Tab", "selection[0].actions.barter.list"); // Update pick lists (formation, stance, trade). (Tab button holds current selection, click a button to select a new option and close the tab.) - updateTab ("formation", "pick", "", "selection[0].traits.formation.list", "selection[0].traits.formation.curr"); + //updateTab ("formation", "pick", "", "selection[0].traits.formation.list", "selection[0].traits.formation.curr"); updateTab ("stance", "pick", "", "selection[0].traits.ai.stance.list", "selection[0].traits.ai.stance.curr"); - updateTab ("trade", "pick", "", "selection[0].actions.trade.list", "selection[0].actions.trade.curr"); - updateTab ("gate", "pick", "", "selection[0].actions.gate.list", "selection[0].actions.gate.curr"); - updateTab ("weapon", "pick", "", "selection[0].actions.attack", "selection[0].actions.attack.curr"); + //updateTab ("trade", "pick", "", "selection[0].actions.trade.list", "selection[0].actions.trade.curr"); + //updateTab ("gate", "pick", "", "selection[0].actions.gate.list", "selection[0].actions.gate.curr"); + //updateTab ("weapon", "pick", "", "selection[0].actions.attack", "selection[0].actions.attack.curr"); /* // Update Allegiance. (Tab button, persistent buttons (though unit will be lost as soon as option selected), click them to do things.) tempArray = new Array ("kill", "food"); diff --git a/binaries/data/mods/official/scripts/entity_functions.js b/binaries/data/mods/official/scripts/entity_functions.js index 44d50cadee..2b0d943cec 100644 --- a/binaries/data/mods/official/scripts/entity_functions.js +++ b/binaries/data/mods/official/scripts/entity_functions.js @@ -1391,6 +1391,7 @@ function entityEventPrepareOrder( evt ) break; case ORDER_SET_RALLY_POINT: + case ORDER_SET_STANCE: break; default: diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index aaa9686b1f..2f89ea1af0 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -187,6 +187,7 @@ bool CNetClient::SetupSession( CNetSession* pSession ) pSession->AddTransition( NCS_INGAME, ( uint )NMT_PLACE_OBJECT, NCS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NCS_INGAME, ( uint )NMT_RUN, NCS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NCS_INGAME, ( uint )NMT_SET_RALLY_POINT, NCS_INGAME, (void*)&OnInGame, pContext ); + pSession->AddTransition( NCS_INGAME, ( uint )NMT_SET_STANCE, NCS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NCS_INGAME, ( uint )NMT_NOTIFY_REQUEST, NCS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NCS_INGAME, ( uint )NMT_FORMATION_GOTO, NCS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NCS_INGAME, ( uint )NMT_FORMATION_GENERIC, NCS_INGAME, (void*)&OnInGame, pContext ); diff --git a/source/network/NetMessage.cpp b/source/network/NetMessage.cpp index 96f7e53802..2b513dadfe 100644 --- a/source/network/NetMessage.cpp +++ b/source/network/NetMessage.cpp @@ -214,6 +214,7 @@ void CNetMessage::ScriptingInit() g_ScriptingHost.DefineConstant( "NMT_PRODUCE", NMT_PRODUCE ); g_ScriptingHost.DefineConstant( "NMT_PLACE_OBJECT", NMT_PLACE_OBJECT ); g_ScriptingHost.DefineConstant( "NMT_SET_RALLY_POINT", NMT_SET_RALLY_POINT ); + g_ScriptingHost.DefineConstant( "NMT_SET_STANCE", NMT_SET_STANCE ); g_ScriptingHost.DefineConstant( "NMT_NOTIFY_REQUEST", NMT_NOTIFY_REQUEST ); g_ScriptingHost.DefineConstant( "NMT_FORMATION_GOTO", NMT_FORMATION_GOTO ); g_ScriptingHost.DefineConstant( "NMT_FORMATION_GENERIC", NMT_FORMATION_GENERIC ); @@ -423,6 +424,39 @@ CNetMessage* CNetMessage::CommandFromJSArgs( return pMessage; } + case NMT_SET_STANCE: + { + CSetStanceMessage* pMessage = new CSetStanceMessage; + if ( !pMessage ) return NULL; + + pMessage->m_IsQueued = isQueued; + pMessage->m_Entities = entities; + + try + { + if ( idx + 1 > argc ) + { + JS_ReportError( pContext, "Too few parameters!" ); + return NULL; + } + + if ( !JSVAL_IS_STRING( argv[ idx ] ) ) + { + JS_ReportError( pContext, "Parameter type error!" ); + return NULL; + } + + pMessage->m_Stance = ToPrimitive< CStrW >( argv[ idx++ ] ); + } + catch ( PSERROR_Scripting_ConversionFailed ) + { + JS_ReportError( pContext, "Invalid location" ); + return NULL; + } + + return pMessage; + } + case NMT_FORMATION_GOTO: { CFormationGotoMessage* pMessage = new CFormationGotoMessage; @@ -964,6 +998,10 @@ CNetMessage* CNetMessageFactory::CreateMessage(const void* pData, pNewMessage = new CSetRallyPointMessage; break; + case NMT_SET_STANCE: + pNewMessage = new CSetStanceMessage; + break; + case NMT_NOTIFY_REQUEST: pNewMessage = new CNotifyRequestMessage; break; @@ -986,576 +1024,3 @@ CNetMessage* CNetMessageFactory::CreateMessage(const void* pData, return pNewMessage; } - -//----------------------------------------------------------------------------- -// Name: CreateMessage() -// Desc: Creates a message from the specified JavaScript arguments -//----------------------------------------------------------------------------- -CNetMessage* CNetMessageFactory::CreateMessage( - const CEntityList &entities, - JSContext *pContext, - uintN argc, - jsval *argv, - bool queued ) -{ - CNetMessage* pNewMessage = NULL; - uint idx = 0; - uint msgType; - - // Validate parameters - if ( argv == 0 ) return NULL; - - try - { - msgType = ToPrimitive< uint >( argv[ idx++ ] ); - } - catch ( PSERROR_Scripting_ConversionFailed ) - { - JS_ReportError( pContext, "Invalid order type" ); - return NULL; - } - - switch ( msgType ) - { - case NMT_GOTO: - { - CGotoMessage *pMessage = new CGotoMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - try - { - if ( idx + 2 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) || - !JSVAL_IS_INT( argv[ idx + 1 ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] ); - pMessage->m_TargetY = ToPrimitive< int >( argv[ idx++ ] ); - } - catch ( PSERROR_Scripting_ConversionFailed ) - { - JS_ReportError( pContext, "Invalid location" ); - return NULL; - } - - pNewMessage = pMessage; - } - break; - - case NMT_RUN: - { - CRunMessage *pMessage = new CRunMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - try - { - if ( idx + 2 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) || - !JSVAL_IS_INT( argv[ idx + 1 ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] ); - pMessage->m_TargetY = ToPrimitive< int >( argv[ idx++ ] ); - } - catch ( PSERROR_Scripting_ConversionFailed ) - { - JS_ReportError( pContext, "Invalid location" ); - return NULL; - } - - pNewMessage = pMessage; - } - break; - - case NMT_PATROL: - { - CPatrolMessage *pMessage = new CPatrolMessage; - if ( pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - try - { - if ( idx + 2 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) || - !JSVAL_IS_INT( argv[ idx + 1 ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] ); - pMessage->m_TargetY = ToPrimitive< int >( argv[ idx++ ] ); - } - catch ( PSERROR_Scripting_ConversionFailed ) - { - JS_ReportError( pContext, "Invalid location" ); - return NULL; - } - - pNewMessage = pMessage; - } - break; - - case NMT_ADD_WAYPOINT: - { - CAddWaypointMessage *pMessage = new CAddWaypointMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - try - { - if ( idx + 2 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) || - !JSVAL_IS_INT( argv[ idx + 1 ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] ); - pMessage->m_TargetY = ToPrimitive< int >( argv[ idx++ ] ); - } - catch ( PSERROR_Scripting_ConversionFailed ) - { - JS_ReportError( pContext, "Invalid location" ); - return NULL; - } - - pNewMessage = pMessage; - } - break; - - case NMT_SET_RALLY_POINT: - { - CSetRallyPointMessage *pMessage = new CSetRallyPointMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - try - { - if ( idx + 2 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) || - !JSVAL_IS_INT( argv[ idx + 1 ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] ); - pMessage->m_TargetY = ToPrimitive< int >( argv[ idx++ ] ); - } - catch ( PSERROR_Scripting_ConversionFailed ) - { - JS_ReportError( pContext, "Invalid location" ); - return NULL; - } - - pNewMessage = pMessage; - } - break; - - case NMT_FORMATION_GOTO: - { - CFormationGotoMessage *pMessage = new CFormationGotoMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - try - { - if ( idx + 2 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) || - !JSVAL_IS_INT( argv[ idx + 1 ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] ); - pMessage->m_TargetY = ToPrimitive< int >( argv[ idx++ ] ); - } - catch ( PSERROR_Scripting_ConversionFailed ) - { - JS_ReportError( pContext, "Invalid location" ); - return NULL; - } - - pNewMessage = pMessage; - } - break; - - case NMT_GENERIC: - { - CGenericMessage* pMessage = new CGenericMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - if ( idx + 1 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_OBJECT( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - CEntity* pEntity = ToNative< CEntity >( argv[ idx++ ] ); - if ( !pEntity ) - { - STMT( - JS_ReportError( pContext, "Invalid entity parameter" ); - return NULL; - ); - } - - pMessage->m_Target = pEntity->me; - - pNewMessage = pMessage; - - if ( !JSVAL_IS_INT( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_Action = ToPrimitive< int >( argv[ idx++ ] ); - break; - } - - case NMT_NOTIFY_REQUEST: - { - CNotifyRequestMessage* pMessage = new CNotifyRequestMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - STMT( - if ( idx + 1 > argc ) - { - - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_OBJECT( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - CEntity* pEntity = ToNative< CEntity >( argv[ idx++ ] ); - if ( !pEntity ) - { - JS_ReportError( pContext, "Invalid entity parameter" ); - return NULL; - } - - pMessage->m_Target = pEntity->me; - ); - - pNewMessage = pMessage; - } - break; - - case NMT_FORMATION_GENERIC: - { - CFormationGenericMessage* pMessage = new CFormationGenericMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - STMT( - if ( idx + 1 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" );\ - return NULL; - ); - } - - if ( !JSVAL_IS_OBJECT( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - CEntity* pEntity = ToNative< CEntity >( argv[ idx++ ] ); - if ( !pEntity ) - { - STMT( - JS_ReportError( pContext, "Invalid entity parameter" ); - return NULL; - ); - } - - pMessage->m_Target = pEntity->me; - ); - - pNewMessage = pMessage; - } - break; - - case NMT_PRODUCE: - { - CProduceMessage* pMessage = new CProduceMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - STMT( - if ( idx + 1 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_Type = ToPrimitive< int >( argv[ idx++ ] ); - ); - - STMT( - if ( idx + 1 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_STRING( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_Name = ToPrimitive< CStrW >( argv[ idx++ ] ); - ); - - pNewMessage = pMessage; - } - break; - - case NMT_PLACE_OBJECT: - { - CPlaceObjectMessage* pMessage = new CPlaceObjectMessage; - if ( !pMessage ) return NULL; - - pMessage->m_IsQueued = queued; - pMessage->m_Entities = entities; - - STMT( - if ( idx + 1 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_STRING( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_Template = ToPrimitive< CStrW >( argv[ idx++ ] ); - ); - - STMT( - if ( idx + 1 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_X = ToPrimitive< int >( argv[ idx++ ] ); - ); - - STMT( - if ( idx + 1 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_Y = ToPrimitive< int >( argv[ idx++ ] ); - ); - - STMT( - if ( idx + 1 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - if ( !JSVAL_IS_INT( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_Z = ToPrimitive< int >( argv[ idx++ ] ); - ); - - STMT( - if ( idx + 1 > argc ) - { - STMT( - JS_ReportError( pContext, "Too few parameters!" ); - return NULL; - ); - } - - if ( !JSVAL_IS_INT( argv[ idx ] ) ) - { - STMT( - JS_ReportError( pContext, "Parameter type error!" ); - return NULL; - ); - } - - pMessage->m_Angle = ToPrimitive< int >( argv[ idx++ ] ); - ); - - pNewMessage = pMessage; - } - break; - - default: - - JS_ReportError( pContext, "Invalid order type" ); - break; - } - - return pNewMessage; -} - diff --git a/source/network/NetMessage.h b/source/network/NetMessage.h index 360348cfe3..2584db7f55 100644 --- a/source/network/NetMessage.h +++ b/source/network/NetMessage.h @@ -186,23 +186,6 @@ public: */ static CNetMessage* CreateMessage( const void* pData, size_t dataSize ); - /** - * Factory methods which creates a message object from JavaScript arguments - * - * @param entities - * @param pContext - * @param argc - * @param argv - * @param isQueued - * @return The new message created - */ - static CNetMessage* CreateMessage( - const CEntityList &entities, - JSContext *pContext, - uintN argc, - jsval *argv, - bool queued ); - protected: private: diff --git a/source/network/NetMessages.h b/source/network/NetMessages.h index 4f7d58d457..8a175b0c34 100644 --- a/source/network/NetMessages.h +++ b/source/network/NetMessages.h @@ -57,6 +57,7 @@ enum NetMessageType NMT_PLACE_OBJECT, NMT_RUN, NMT_SET_RALLY_POINT, + NMT_SET_STANCE, NMT_NOTIFY_REQUEST, NMT_FORMATION_GOTO, NMT_FORMATION_GENERIC, @@ -204,6 +205,10 @@ DERIVE_NMT_CLASS_(Command, SetRallyPoint, NMT_SET_RALLY_POINT) NMT_FIELD_INT(m_TargetY, u32, 2) END_NMT_CLASS() +DERIVE_NMT_CLASS_(Command, SetStance, NMT_SET_STANCE) + NMT_FIELD(CStrW, m_Stance) +END_NMT_CLASS() + DERIVE_NMT_CLASS_(Command, Generic, NMT_GENERIC) NMT_FIELD(HEntity, m_Target) NMT_FIELD_INT(m_Action, u32, 4) diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index d23bdae291..3b79b95367 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -50,7 +50,7 @@ CNetServer::CNetServer( CGame *pGame, CGameAttributes *pGameAttributes ) // (e.g. less command batch spam that way) for ( uint i = 0; i < 3; i++ ) { - CTurnManager::SetTurnLength( i, 150 ); + CTurnManager::SetTurnLength( i, DEFAULT_TURN_LENGTH ); } g_ScriptingHost.SetGlobal( "g_NetServer", OBJECT_TO_JSVAL( GetScript() ) ); @@ -145,6 +145,7 @@ bool CNetServer::SetupSession( CNetSession* pSession ) pSession->AddTransition( NSS_INGAME, ( uint )NMT_PLACE_OBJECT, NSS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NSS_INGAME, ( uint )NMT_RUN, NSS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NSS_INGAME, ( uint )NMT_SET_RALLY_POINT, NSS_INGAME, (void*)&OnInGame, pContext ); + pSession->AddTransition( NSS_INGAME, ( uint )NMT_SET_STANCE, NSS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NSS_INGAME, ( uint )NMT_NOTIFY_REQUEST, NSS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NSS_INGAME, ( uint )NMT_FORMATION_GOTO, NSS_INGAME, (void*)&OnInGame, pContext ); pSession->AddTransition( NSS_INGAME, ( uint )NMT_FORMATION_GENERIC, NSS_INGAME, (void*)&OnInGame, pContext ); diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 2942c18431..92a2573b30 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -824,7 +824,7 @@ void CEntity::PopOrder() } void CEntity::PushOrder( const CEntityOrder& order ) { - CEventPrepareOrder evt( order.m_target_entity, order.m_type, order.m_action, order.m_produce_name ); + CEventPrepareOrder evt( order.m_target_entity, order.m_type, order.m_action, order.m_name ); if( DispatchEvent(&evt) ) { if (order.m_type == CEntityOrder::ORDER_SET_RALLY_POINT) @@ -833,6 +833,12 @@ void CEntity::PushOrder( const CEntityOrder& order ) entf_set(ENTF_HAS_RALLY_POINT); m_rallyPoint = order.m_target_location; } + else if (order.m_type == CEntityOrder::ORDER_SET_STANCE) + { + // It doesn't make sense to queue this type of order; just set the stance + m_stanceName = order.m_name; + StanceChanged(); + } else { m_orderQueue.push_back( order ); diff --git a/source/simulation/EntityOrders.h b/source/simulation/EntityOrders.h index efbd8c2a40..9b18d06811 100644 --- a/source/simulation/EntityOrders.h +++ b/source/simulation/EntityOrders.h @@ -40,15 +40,6 @@ #include -// An order data field, which could represent different things depending on the type of order. -struct SOrderData -{ - CVector2D location; - HEntity entity; - CStrW string; - u64 data; // could be recast as a double or int -}; - class CEntityListener { public: @@ -97,8 +88,9 @@ public: ORDER_PRODUCE, // 12 ORDER_START_CONSTRUCTION, // 13 ORDER_SET_RALLY_POINT, // 14 - ORDER_NOTIFY_REQUEST, // 15 - ORDER_LAST // 16 + ORDER_SET_STANCE, // 15 + ORDER_NOTIFY_REQUEST, // 16 + ORDER_LAST // 17 }; EOrderType m_type; @@ -113,27 +105,29 @@ public: // all commands involving pathfinder (i.e. all :P) float m_pathfinder_radius; - // NMT_PlaceObject + // NMT_PLACE_OBJECT HEntity m_new_obj; - // NMT_Goto - // NMT_FormationGoto - // NMT_Run - // NMT_Patrol - // NMT_AddWaypoint + // NMT_GOTO + // NMT_FORMATION_GOTO + // NMT_RUN + // NMT_PATROL + // NMT_ADD_WAYPOINT CVector2D m_target_location; - // NMT_Generic - // NMT_FormationGeneric - // NMT_NotifyRequest + // NMT_GENERIC + // NMT_FORMATION_GENERIC + // NMT_NOTIFY_REQUEST HEntity m_target_entity; int m_action; - // NMT_Produce - CStrW m_produce_name; + // NMT_PRODUCE, NMT_SET_STANCE + CStrW m_name; + + // NMT_PRODUCE int m_produce_type; - // NMT_Generic + // NMT_GENERIC bool m_run; CEntityOrder(): m_type(ORDER_INVALID), m_source(SOURCE_PLAYER) {} diff --git a/source/simulation/EntityScriptInterface.cpp b/source/simulation/EntityScriptInterface.cpp index dcbcd88f84..4bdb6ead7c 100644 --- a/source/simulation/EntityScriptInterface.cpp +++ b/source/simulation/EntityScriptInterface.cpp @@ -341,7 +341,7 @@ bool CEntity::Order( JSContext* cx, uintN argc, jsval* argv, CEntityOrder::EOrde case CEntityOrder::ORDER_PRODUCE: JSU_REQUIRE_PARAMS_CPP(3); try { - newOrder.m_produce_name = ToPrimitive(argv[2]); + newOrder.m_name = ToPrimitive(argv[2]); newOrder.m_produce_type = ToPrimitive(argv[1]); } catch( PSERROR_Scripting_ConversionFailed ) diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 8056dc8631..9c7036498e 100644 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -707,10 +707,10 @@ bool CEntity::ProcessPatrol( CEntityOrder* current, int UNUSED(timestep_millis) bool CEntity::ProcessProduce( CEntityOrder* order ) { - CEventStartProduction evt( order->m_produce_type, order->m_produce_name ); + CEventStartProduction evt( order->m_produce_type, order->m_name ); if( DispatchEvent( &evt ) && evt.GetTime() >= 0 ) { - m_productionQueue->AddItem( order->m_produce_type, order->m_produce_name, evt.GetTime() ); + m_productionQueue->AddItem( order->m_produce_type, order->m_name, evt.GetTime() ); } return( false ); } diff --git a/source/simulation/Simulation.cpp b/source/simulation/Simulation.cpp index e5aa8aadf5..0e2ad40740 100644 --- a/source/simulation/Simulation.cpp +++ b/source/simulation/Simulation.cpp @@ -321,10 +321,18 @@ size_t CSimulation::TranslateMessage(CNetMessage* pMsg, size_t clientMask, void* _msg *msg=(_msg *)pMsg; \ isQueued = msg->m_IsQueued != 0; \ order.m_type=CEntityOrder::_order; \ - order.m_produce_name=msg->m_Name; \ + order.m_name=msg->m_Name; \ order.m_produce_type=msg->m_Type; \ QueueOrder(order, msg->m_Entities, isQueued); \ } while(0) +#define ENTITY_STRING(_msg, _order) \ + do { \ + _msg *msg=(_msg *)pMsg; \ + isQueued = msg->m_IsQueued != 0; \ + order.m_type=CEntityOrder::_order; \ + order.m_name=msg->m_Stance; \ + QueueOrder(order, msg->m_Entities, isQueued); \ + } while(0) switch (pMsg->GetType()) { @@ -374,6 +382,9 @@ size_t CSimulation::TranslateMessage(CNetMessage* pMsg, size_t clientMask, void* case NMT_SET_RALLY_POINT: ENTITY_POSITION(CSetRallyPointMessage, ORDER_SET_RALLY_POINT); break; + case NMT_SET_STANCE: + ENTITY_STRING(CSetStanceMessage, ORDER_SET_STANCE); + break; case NMT_FORMATION_GOTO: ENTITY_POSITION_FORM(CFormationGotoMessage, ORDER_GOTO); break; diff --git a/source/simulation/scripting/SimulationScriptInit.cpp b/source/simulation/scripting/SimulationScriptInit.cpp index 945c5a3ccd..769eec6a20 100644 --- a/source/simulation/scripting/SimulationScriptInit.cpp +++ b/source/simulation/scripting/SimulationScriptInit.cpp @@ -54,6 +54,7 @@ void SimulationScriptInit() g_ScriptingHost.DefineConstant( "ORDER_GENERIC", CEntityOrder::ORDER_GENERIC ); g_ScriptingHost.DefineConstant( "ORDER_PRODUCE", CEntityOrder::ORDER_PRODUCE ); g_ScriptingHost.DefineConstant( "ORDER_SET_RALLY_POINT", CEntityOrder::ORDER_SET_RALLY_POINT ); + g_ScriptingHost.DefineConstant( "ORDER_SET_STANCE", CEntityOrder::ORDER_SET_STANCE ); g_ScriptingHost.DefineConstant( "ORDER_START_CONSTRUCTION", CEntityOrder::ORDER_START_CONSTRUCTION ); }