1
0
forked from 0ad/0ad

Run order, secondary order support --still needs secondary cursor.

This was SVN commit r3363.
This commit is contained in:
pyrolink 2006-01-16 10:56:12 +00:00
parent 01ff2fdf3b
commit a917ffa711
7 changed files with 95 additions and 3 deletions

View File

@ -347,6 +347,8 @@ void Render()
glLoadIdentity();
g_Mouseover.renderHealthBars();
g_Selection.renderHealthBars();
g_Mouseover.renderStaminaBars();
g_Selection.renderStaminaBars();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
@ -496,6 +498,7 @@ static void InitScripting()
g_ScriptingHost.DefineConstant( "ORDER_NONE", -1 );
g_ScriptingHost.DefineConstant( "ORDER_GOTO", CEntityOrder::ORDER_GOTO );
g_ScriptingHost.DefineConstant( "ORDER_RUN", CEntityOrder::ORDER_RUN );
g_ScriptingHost.DefineConstant( "ORDER_PATROL", CEntityOrder::ORDER_PATROL );
g_ScriptingHost.DefineConstant( "ORDER_ATTACK", CEntityOrder::ORDER_ATTACK_MELEE );
g_ScriptingHost.DefineConstant( "ORDER_GATHER", CEntityOrder::ORDER_GATHER );

View File

@ -91,6 +91,24 @@ void CSelectedEntities::renderHealthBars()
glDisable( GL_BLEND );
}
}
void CSelectedEntities::renderStaminaBars()
{
std::vector<HEntity>::iterator it;
for( it = m_selected.begin(); it < m_selected.end(); it++ )
(*it)->renderStaminaBar();
if( m_group_highlight != -1 )
{
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_BLEND );
std::vector<HEntity>::iterator it;
for( it = m_groups[m_group_highlight].begin(); it < m_groups[m_group_highlight].end(); it++ )
(*it)->renderStaminaBar();
glDisable( GL_BLEND );
}
}
void CSelectedEntities::renderOverlays()
{
@ -403,6 +421,7 @@ void CSelectedEntities::update()
if( !g_Game->GetWorld()->GetTerrain()->isOnMap( g_Mouseover.m_worldposition ) )
{
m_defaultCommand = -1;
m_secondaryCommand = -1;
return;
}
@ -413,9 +432,16 @@ void CSelectedEntities::update()
std::map<CStrW, int, CStrW_hash_compare> defaultCursor[numCommands];
std::map<int, int> defaultAction[numCommands];
int t, vote;
int secondaryPoll[numCommands];
std::map<CStrW, int, CStrW_hash_compare> secondaryCursor[numCommands];
std::map<int, int> secondaryAction[numCommands];
int t, vote, secvote;
for( t = 0; t < numCommands; t++ )
{
defaultPoll[t] = 0;
secondaryPoll[t] = 0;
}
std::vector<HEntity>::iterator it;
for( it = m_selected.begin(); it < m_selected.end(); it++ )
@ -423,6 +449,7 @@ void CSelectedEntities::update()
CEventTargetChanged evt( g_Mouseover.m_target );
(*it)->DispatchEvent( &evt );
vote = evt.m_defaultOrder - NMT_COMMAND_FIRST;
secvote = evt.m_secondaryOrder - NMT_COMMAND_FIRST;
if( ( vote >= 0 ) && ( vote < numCommands ) )
{
@ -430,18 +457,28 @@ void CSelectedEntities::update()
defaultCursor[vote][evt.m_defaultCursor]++;
defaultAction[vote][evt.m_defaultAction]++;
}
if( ( secvote >= 0 ) && ( secvote < numCommands ) )
{
secondaryPoll[secvote]++;
secondaryCursor[secvote][evt.m_secondaryCursor]++;
secondaryAction[secvote][evt.m_secondaryAction]++;
}
}
vote = -1;
secvote = -1;
for( t = 0; t < numCommands; t++ )
{
if( ( vote == -1 ) || ( defaultPoll[t] > defaultPoll[vote] ) )
vote = t;
if( ( secvote == -1 ) || ( secondaryPoll[t] > secondaryPoll[secvote] ) )
secvote = t;
}
std::map<CStrW, int, CStrW_hash_compare>::iterator itv;
std::map<int, int>::iterator iti;
m_defaultCommand = vote + NMT_COMMAND_FIRST;
m_secondaryCommand = secvote + NMT_COMMAND_FIRST;
// Now find the most appropriate cursor
t = 0;
@ -453,6 +490,19 @@ void CSelectedEntities::update()
g_CursorName = itv->first;
}
}
/*
TODO: provide secondary cursor name?
t = 0;
for( itv = secondaryCursor[secvote].begin(); itv != secondaryCursor[secvote].end(); itv++ )
{
if( itv->second > t )
{
t = itv->second;
g_CursorName = itv->first;
}
}*/
// Find the most appropriate action parameter too
t = 0;
@ -464,6 +514,16 @@ void CSelectedEntities::update()
m_defaultAction = iti->first;
}
}
t = 0;
for( iti = secondaryAction[secvote].begin(); iti != secondaryAction[secvote].end(); iti++ )
{
if( iti->second > t )
{
t = iti->second;
m_secondaryAction = iti->first;
}
}
m_selectionChanged = false;
g_Mouseover.m_targetChanged = false;
@ -718,6 +778,18 @@ void CMouseoverEntities::renderHealthBars()
glDisable( GL_BLEND );
}
void CMouseoverEntities::renderStaminaBars()
{
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_BLEND );
std::vector<SMouseoverFader>::iterator it;
for( it = m_mouseover.begin(); it < m_mouseover.end(); it++ )
it->entity->renderStaminaBar();
glDisable( GL_BLEND );
}
void CMouseoverEntities::renderOverlays()
{
CCamera *pCamera=g_Game->GetView()->GetCamera();
@ -784,8 +856,8 @@ void FireWorldClickEvent(uint button, int clicks)
clicks,
g_Selection.m_defaultCommand,
g_Selection.m_defaultAction,
-1, // FIXME Secondary order, depends entity scripts etc
-1, // FIXME Secondary action, depends entity scripts etc
g_Selection.m_secondaryCommand, // FIXME Secondary order, depends entity scripts etc
g_Selection.m_secondaryAction, // FIXME Secondary action, depends entity scripts etc
g_Mouseover.m_target,
(uint)g_Mouseover.m_worldposition.x,
(uint)g_Mouseover.m_worldposition.y);

View File

@ -32,6 +32,8 @@ struct CSelectedEntities : public Singleton<CSelectedEntities>
m_group_highlight = -1;
m_defaultCommand = -1;
m_defaultAction = -1;
m_secondaryCommand = -1;
m_secondaryAction = -1;
m_selectionChanged = true;
}
std::vector<HEntity> m_selected;
@ -40,6 +42,8 @@ struct CSelectedEntities : public Singleton<CSelectedEntities>
bool m_selectionChanged;
int m_defaultCommand;
int m_defaultAction;
int m_secondaryCommand;
int m_secondaryAction;
void addSelection( HEntity entity );
void removeSelection( HEntity entity );
@ -64,6 +68,7 @@ struct CSelectedEntities : public Singleton<CSelectedEntities>
void renderSelectionOutlines();
void renderOverlays();
void renderHealthBars();
void renderStaminaBars();
};
// CMouseoverEntities: the singleton containing entities the mouse is currently hovering over or bandboxing
@ -113,6 +118,7 @@ struct CMouseoverEntities : public Singleton<CMouseoverEntities>
void renderSelectionOutlines();
void renderOverlays();
void renderHealthBars();
void renderStaminaBars();
bool isBandbox() { return( m_bandbox ); }
void startBandbox( u16 x, u16 y );

View File

@ -63,6 +63,7 @@ enum ENetMessageType
NMT_Gather,
NMT_Heal,
NMT_Generic,
NMT_Run,
NMT_COMMAND_LAST,
/* Post-Game Stage */
@ -213,6 +214,11 @@ DERIVE_NMT_CLASS_(NetCommand, Goto)
NMT_FIELD_INT(m_TargetY, u32, 2)
END_NMT_CLASS()
DERIVE_NMT_CLASS_(NetCommand, Run)
NMT_FIELD_INT(m_TargetX, u32, 2)
NMT_FIELD_INT(m_TargetY, u32, 2)
END_NMT_CLASS()
DERIVE_NMT_CLASS_(NetCommand, Patrol)
NMT_FIELD_INT(m_TargetX, u32, 2)
NMT_FIELD_INT(m_TargetY, u32, 2)

View File

@ -78,6 +78,7 @@ void CNetMessage::ScriptingInit()
#define def(_msg) g_ScriptingHost.DefineConstant(#_msg, _msg)
def(NMT_Goto);
def(NMT_Run);
def(NMT_Patrol);
def(NMT_AddWaypoint);
def(NMT_AttackMelee);
@ -179,6 +180,8 @@ CNetCommand *CNetMessage::CommandFromJSArgs(const CEntityList &entities, JSConte
{
// NMT_Goto, targetX, targetY
PositionMessage(Goto)
PositionMessage(Run)
PositionMessage(Patrol)
PositionMessage(AddWaypoint)

View File

@ -96,3 +96,4 @@ JSBool JSI_Selection::setGroups( JSContext* cx, JSObject* UNUSED(obj),
return( JS_TRUE );
}

View File

@ -21,6 +21,7 @@ namespace JSI_Selection
JSBool isValidContextOrder( JSContext* context, JSObject* obj, uint argc, jsval* argv, jsval* rval );
JSBool getContextOrder( JSContext* context, JSObject* obj, jsval id, jsval* vp );
JSBool setContextOrder( JSContext* context, JSObject* obj, jsval id, jsval* vp );
};
#endif