1
0
forked from 0ad/0ad

Added running support to GENERIC orders through a field that can be sent across the network (previous implementation used to be by setting properties on the entity itself).

This was SVN commit r6223.
This commit is contained in:
Matei 2008-07-13 06:24:50 +00:00
parent 922874e2ef
commit e4966f6f1b
8 changed files with 204 additions and 262 deletions

View File

@ -109,7 +109,10 @@ function worldClickHandler(event)
return;
}
issueCommand (selection, isOrderQueued(), cmd, args[0], args[1]);
if (cmd == NMT_GENERIC) // For NMT_GENERIC, add a third argument - whether to run
issueCommand (selection, isOrderQueued(), cmd, args[0], args[1], event.clicks > 1);
else
issueCommand (selection, isOrderQueued(), cmd, args[0], args[1]);
}
// ====================================================================

View File

@ -259,19 +259,15 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
{
if ( idx + 2 > argc )
{
STMT(
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
);
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;
);
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] );
@ -298,19 +294,15 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
{
if ( idx + 2 > argc )
{
STMT(
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
);
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;
);
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] );
@ -337,19 +329,15 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
{
if ( idx + 2 > argc )
{
STMT(
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
);
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;
);
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] );
@ -376,19 +364,15 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
{
if ( idx + 2 > argc )
{
STMT(
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
);
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;
);
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] );
@ -415,19 +399,15 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
{
if ( idx + 2 > argc )
{
STMT(
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
);
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;
);
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_TargetX = ToPrimitive< int >( argv[ idx++ ] );
@ -450,44 +430,42 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
pMessage->m_IsQueued = isQueued;
pMessage->m_Entities = entities;
STMT(
if ( idx + 2 > argc )
{
STMT(
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
);
}
if ( idx + 3 > argc )
{
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
}
if ( !JSVAL_IS_OBJECT( argv[ idx ] ) )
{
STMT(
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
);
}
if ( !JSVAL_IS_OBJECT( argv[ idx ] ) )
{
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;
);
}
CEntity* pEntity = ToNative< CEntity >( argv[ idx++ ] );
if ( !pEntity )
{
JS_ReportError( pContext, "Invalid entity parameter" );
return NULL;
}
pMessage->m_Target = pEntity->me;
pMessage->m_Target = pEntity->me;
if ( !JSVAL_IS_INT( argv[ idx ] ) )
{
STMT(
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
);
}
pMessage->m_Action = ToPrimitive< int >( argv[ idx++ ] )
);
if ( !JSVAL_IS_INT( argv[ idx ] ) )
{
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_Action = ToPrimitive< int >( argv[ idx++ ] );
if ( !JSVAL_IS_BOOLEAN( argv[ idx ] ) )
{
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_Run = ToPrimitive< bool >( argv[ idx++ ] );
return pMessage;
}
@ -500,34 +478,28 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
pMessage->m_IsQueued = isQueued;
pMessage->m_Entities = entities;
STMT(
if ( idx + 1 > argc )
{
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;
);
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
}
if ( !JSVAL_IS_OBJECT( argv[ idx ] ) )
{
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;
return pMessage;
}
@ -539,34 +511,26 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
pMessage->m_IsQueued = isQueued;
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;
);
if ( idx + 1 > argc )
{
JS_ReportError( pContext, "Too few parameters!" );\
return NULL;
}
if ( !JSVAL_IS_OBJECT( argv[ idx ] ) )
{
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;
return pMessage;
}
@ -579,45 +543,33 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
pMessage->m_IsQueued = isQueued;
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;
);
}
if ( idx + 1 > argc )
{
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
}
if ( !JSVAL_IS_INT( argv[ idx ] ) )
{
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_Type = ToPrimitive< int >( argv[ idx++ ] );
);
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++ ] );
);
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_Name = ToPrimitive< CStrW >( argv[ idx++ ] );
return pMessage;
}
@ -630,104 +582,74 @@ CNetMessage* CNetMessage::CommandFromJSArgs(
pMessage->m_IsQueued = isQueued;
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++ ] );
);
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_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++ ] );
);
if ( idx + 1 > argc )
{
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
}
if ( !JSVAL_IS_INT( argv[ idx ] ) )
{
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;
);
}
if ( idx + 1 > argc )
{
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
}
if ( !JSVAL_IS_INT( argv[ idx ] ) )
{
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_Y = ToPrimitive< int >( argv[ idx++ ] );
);
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;
);
}
if ( idx + 1 > argc )
{
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
}
if ( !JSVAL_IS_INT( argv[ idx ] ) )
{
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_Z = ToPrimitive< int >( argv[ idx++ ] );
);
pMessage->m_Z = ToPrimitive< int >( argv[ idx++ ] );
STMT(
if ( idx + 1 > argc )
{
STMT(
JS_ReportError( pContext, "Too few parameters!" );
return NULL;
);
}
if ( idx + 1 > argc )
{
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++ ] );
);
if ( !JSVAL_IS_INT( argv[ idx ] ) )
{
JS_ReportError( pContext, "Parameter type error!" );
return NULL;
}
pMessage->m_Angle = ToPrimitive< int >( argv[ idx++ ] );
return pMessage;
}

View File

@ -201,6 +201,7 @@ END_NMT_CLASS()
DERIVE_NMT_CLASS_(Command, Generic, NMT_GENERIC)
NMT_FIELD(HEntity, m_Target)
NMT_FIELD_INT(m_Action, u32, 4)
NMT_FIELD_INT(m_Run, u32, 1)
END_NMT_CLASS()
DERIVE_NMT_CLASS_(Command, Produce, NMT_PRODUCE)

View File

@ -522,6 +522,10 @@ void CEntity::UpdateOrders( int timestep )
UpdateCollisionPatch();
return;
case CEntityOrder::ORDER_GENERIC:
// Choose to run if and only if order.m_run is set
entf_set_to(ENTF_TRIGGER_RUN, current->m_run);
if( !entf_get(ENTF_TRIGGER_RUN) )
entf_set_to(ENTF_SHOULD_RUN, false);
if( ProcessGeneric( current, timestep ) )
break;
UpdateCollisionPatch();
@ -554,7 +558,7 @@ void CEntity::UpdateOrders( int timestep )
return;
case CEntityOrder::ORDER_GOTO:
case CEntityOrder::ORDER_RUN:
// Choose to run only if type == ORDER_RUN
// Choose to run if and only if type == ORDER_RUN
entf_set_to(ENTF_TRIGGER_RUN, current->m_type == CEntityOrder::ORDER_RUN);
if( !entf_get(ENTF_TRIGGER_RUN) )
entf_set_to(ENTF_SHOULD_RUN, false);

View File

@ -132,8 +132,8 @@ public:
CStrW m_produce_name;
int m_produce_type;
//SOrderData m_data[ORDER_MAX_DATA];
// NMT_Generic
bool m_run;
CEntityOrder(): m_type(ORDER_INVALID), m_source(SOURCE_PLAYER) {}

View File

@ -306,6 +306,16 @@ size_t CSimulation::TranslateMessage(CNetMessage* pMsg, size_t clientMask, void*
order.m_action=msg->m_Action; \
QueueOrder(order, msg->m_Entities, isQueued); \
} while(0)
#define ENTITY_ENTITY_INT_BOOL(_msg, _order) \
do { \
_msg *msg=(_msg *)pMsg; \
isQueued = msg->m_IsQueued != 0; \
order.m_type=CEntityOrder::_order; \
order.m_target_entity=msg->m_Target; \
order.m_action=msg->m_Action; \
order.m_run=msg->m_Run != 0; \
QueueOrder(order, msg->m_Entities, isQueued); \
} while(0)
#define ENTITY_INT_STRING(_msg, _order) \
do { \
_msg *msg=(_msg *)pMsg; \
@ -367,7 +377,7 @@ size_t CSimulation::TranslateMessage(CNetMessage* pMsg, size_t clientMask, void*
//TODO: make formation move to within range of target and then attack normally
case NMT_GENERIC:
ENTITY_ENTITY_INT(CGenericMessage, ORDER_GENERIC);
ENTITY_ENTITY_INT_BOOL(CGenericMessage, ORDER_GENERIC);
break;
case NMT_FORMATION_GENERIC:
ENTITY_ENTITY_INT(CFormationGenericMessage, ORDER_GENERIC);

View File

@ -68,6 +68,7 @@ void CDefendStance::OnDamaged(CEntity *source)
CEntityOrder order( CEntityOrder::ORDER_GENERIC, CEntityOrder::SOURCE_UNIT_AI );
order.m_target_entity = source->me;
order.m_action = action;
order.m_run = false;
m_Entity->PushOrder( order );
}
}
@ -141,6 +142,7 @@ void CStanceUtils::Attack(CEntity* entity, CEntity* target)
CEntityOrder order( CEntityOrder::ORDER_GENERIC, CEntityOrder::SOURCE_UNIT_AI );
order.m_target_entity = target->me;
order.m_action = action;
order.m_run = false;
entity->PushOrder( order );
}
}

View File

@ -79,7 +79,7 @@ void CTurnManager::SendMessage(CNetMessage *pMsg, size_t clientMask)
{
for (size_t i=0;i<m_Clients.size();i++)
{
if (true || (clientMask & (1<<i)))
if (clientMask & (1<<i))
{
if (m_Clients[i].m_Pipe)
m_Clients[i].m_Pipe->Push(pMsg);