forked from 0ad/0ad
Fixes for two pathfinding bugs (neither of which were actually pathfinding bugs), added player objects (details in TM)
This was SVN commit r1733.
This commit is contained in:
parent
4b5aff926d
commit
25fdbfd931
@ -4,6 +4,7 @@
|
||||
#include "MapReader.h"
|
||||
#include "UnitManager.h"
|
||||
#include "Unit.h"
|
||||
#include "Game.h"
|
||||
#include "ObjectManager.h"
|
||||
#include "BaseEntity.h"
|
||||
#include "BaseEntityCollection.h"
|
||||
@ -287,7 +288,7 @@ void CMapReader::ReadXML(const char* filename)
|
||||
}
|
||||
|
||||
HEntity ent = g_EntityManager.create(g_EntityTemplateCollection.getTemplate(TemplateName), Position, Orientation);
|
||||
ent->m_player = PlayerID;
|
||||
ent->m_player = g_Game->GetPlayer( PlayerID );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -718,11 +718,15 @@ TIMER(InitScripting)
|
||||
#endif
|
||||
JSI_Vector3D::init();
|
||||
EntityCollection::Init( "EntityCollection" );
|
||||
// PlayerCollection::Init( "PlayerCollection" );
|
||||
SColour::ScriptingInit();
|
||||
CPlayer::ScriptingInit();
|
||||
|
||||
PlayerCollection::Init( "PlayerCollection" );
|
||||
CDamageType::ScriptingInit();
|
||||
CJSPropertyAccessor<CEntity>::ScriptingInit(); // <-- Doesn't really matter which we use, but we know CJSPropertyAccessor<T> is already being compiled for T = CEntity.
|
||||
CScriptEvent::ScriptingInit();
|
||||
|
||||
|
||||
g_ScriptingHost.DefineConstant( "ORDER_NONE", -1 );
|
||||
g_ScriptingHost.DefineConstant( "ORDER_GOTO", CEntityOrder::ORDER_GOTO );
|
||||
g_ScriptingHost.DefineConstant( "ORDER_PATROL", CEntityOrder::ORDER_PATROL );
|
||||
|
@ -173,8 +173,16 @@ PSRETURN CGame::StartGame(CGameAttributes *pAttribs)
|
||||
delete m_Players[i];
|
||||
|
||||
m_NumPlayers=pAttribs->GetValue("numPlayers").ToUInt();
|
||||
m_Players.resize(m_NumPlayers);
|
||||
for (uint i=0;i<m_NumPlayers;i++)
|
||||
|
||||
// Note: If m_Players is resized after this point (causing a reallocation)
|
||||
// various bits of code will still contain pointers to data at the original
|
||||
// locations. This is seldom a good thing. Make it big enough here.
|
||||
|
||||
// Player 0 = Gaia
|
||||
|
||||
m_Players.resize(m_NumPlayers + 1);
|
||||
|
||||
for (uint i=0;i <= m_NumPlayers;i++)
|
||||
m_Players[i]=new CPlayer(i);
|
||||
|
||||
// FIXME If the GUI hasn't set attributes for all players, the CPlayer
|
||||
@ -186,7 +194,22 @@ PSRETURN CGame::StartGame(CGameAttributes *pAttribs)
|
||||
// TODO Set player attributes in the player object
|
||||
}
|
||||
|
||||
m_pLocalPlayer=m_Players[0];
|
||||
m_Players[0]->m_Name = L"Gaia";
|
||||
m_Players[0]->m_Colour.r = 0.2f;
|
||||
m_Players[0]->m_Colour.g = 0.7f;
|
||||
m_Players[0]->m_Colour.b = 0.2f;
|
||||
|
||||
m_Players[1]->m_Name = L"Acumen";
|
||||
m_Players[1]->m_Colour.r = 1.0f;
|
||||
m_Players[1]->m_Colour.g = 0.0f;
|
||||
m_Players[1]->m_Colour.b = 0.0f;
|
||||
|
||||
m_Players[2]->m_Name = L"Boco the Insignificant";
|
||||
m_Players[2]->m_Colour.r = 0.0f;
|
||||
m_Players[2]->m_Colour.g = 0.0f;
|
||||
m_Players[2]->m_Colour.b = 1.0f;
|
||||
|
||||
m_pLocalPlayer=m_Players[1];
|
||||
|
||||
// RC, 040804 - GameView needs to be initialised before World, otherwise GameView initialisation
|
||||
// overwrites anything stored in the map file that gets loaded by CWorld::Initialize with default
|
||||
|
@ -74,6 +74,10 @@ public:
|
||||
|
||||
inline CPlayer *GetPlayer(uint idx)
|
||||
{ return m_Players[idx]; }
|
||||
|
||||
inline std::vector<CPlayer*>* GetPlayers()
|
||||
{ return( &m_Players ); }
|
||||
|
||||
inline uint GetNumPlayers()
|
||||
{ return m_NumPlayers; }
|
||||
|
||||
|
@ -548,7 +548,8 @@ void CSelectedEntities::contextOrder( bool pushQueue )
|
||||
contextRandomized.m_data[0].location.y += _y * radius;
|
||||
|
||||
// Clamp it to within the map, just in case.
|
||||
float mapsize = (float)g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide();
|
||||
float mapsize = (float)g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide() * CELL_SIZE;
|
||||
|
||||
if( contextRandomized.m_data[0].location.x < 0.0f )
|
||||
contextRandomized.m_data[0].location.x = 0.0f;
|
||||
if( contextRandomized.m_data[0].location.x >= mapsize )
|
||||
|
@ -19,6 +19,21 @@ template<> JSObject* ToScript<HEntity>( HEntity* Native )
|
||||
return( ToScript<CEntity>( &( **Native ) ) );
|
||||
}
|
||||
|
||||
// CPlayer*
|
||||
template<> bool ToPrimitive<CPlayer*>( JSContext* cx, jsval v, CPlayer*& Storage )
|
||||
{
|
||||
if( !JSVAL_IS_OBJECT( v ) ) return( false );
|
||||
CPlayer* Data = (CPlayer*)JS_GetInstancePrivate( cx, JSVAL_TO_OBJECT( v ), &CPlayer::JSI_class, NULL );
|
||||
if( !Data ) return( false );
|
||||
Storage = Data;
|
||||
return( true );
|
||||
}
|
||||
|
||||
template<> JSObject* ToScript<CPlayer*>( CPlayer** Native )
|
||||
{
|
||||
return( ToScript<CPlayer>( *Native ) );
|
||||
}
|
||||
|
||||
// CBaseEntity*
|
||||
|
||||
template<> bool ToPrimitive<CBaseEntity*>( JSContext* cx, jsval v, CBaseEntity*& Storage )
|
||||
|
@ -91,6 +91,7 @@ JSPropertySpec ScriptGlobalTable[] =
|
||||
{ "camera", GLOBAL_CAMERA, JSPROP_PERMANENT, JSI_Camera::getCamera, JSI_Camera::setCamera },
|
||||
{ "console", GLOBAL_CONSOLE, JSPROP_PERMANENT | JSPROP_READONLY, JSI_Console::getConsole, NULL },
|
||||
{ "entities", 0, JSPROP_PERMANENT | JSPROP_READONLY, GetEntitySet, NULL },
|
||||
{ "players", 0, JSPROP_PERMANENT | JSPROP_READONLY, GetPlayerSet, NULL },
|
||||
{ 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
@ -186,6 +187,15 @@ JSBool GetEntitySet( JSContext* context, JSObject* globalObject, jsval argv, jsv
|
||||
return( JS_TRUE );
|
||||
}
|
||||
|
||||
JSBool GetPlayerSet( JSContext* cx, JSObject* globalObject, jsval argv, jsval* vp )
|
||||
{
|
||||
std::vector<CPlayer*>* players = g_Game->GetPlayers();
|
||||
|
||||
*vp = OBJECT_TO_JSVAL( PlayerCollection::Create( *players ) );
|
||||
|
||||
return( JS_TRUE );
|
||||
}
|
||||
|
||||
JSBool setTimeout( JSContext* context, JSObject* UNUSEDPARAM(globalObject), unsigned int argc, jsval* argv, jsval* UNUSEDPARAM(rval) )
|
||||
{
|
||||
assert( argc >= 2 );
|
||||
|
@ -15,6 +15,9 @@ JSFunc getEntityByHandle;
|
||||
JSFunc getEntityTemplate;
|
||||
JSBool GetEntitySet( JSContext* context, JSObject* globalObject, jsval argv, jsval* vp );
|
||||
|
||||
// Player
|
||||
JSBool GetPlayerSet( JSContext* context, JSObject* globalObject, jsval argv, jsval* vp );
|
||||
|
||||
// Timer
|
||||
JSFunc setTimeout;
|
||||
JSFunc setInterval;
|
||||
@ -45,6 +48,7 @@ JSFunc loadLanguage;
|
||||
JSFunc getLanguageID;
|
||||
|
||||
JSFunc getFPS;
|
||||
JSFunc getCursorPosition;
|
||||
JSFunc v3dist;
|
||||
|
||||
// Returns a string that says when ScriptGlue.cpp was last recompiled
|
||||
|
@ -40,6 +40,7 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
|
||||
AddProperty( L"actions.attack.rangemin", &m_meleeRangeMin );
|
||||
AddProperty( L"position", &m_graphics_position, false, (NotifyFn)&CEntity::teleport );
|
||||
AddProperty( L"orientation", &m_graphics_orientation, false, (NotifyFn)&CEntity::reorient );
|
||||
AddProperty( L"player", &m_player );
|
||||
|
||||
for( int t = 0; t < EVENT_LAST; t++ )
|
||||
AddProperty( EventNames[t], &m_EventHandlers[t] );
|
||||
@ -70,7 +71,7 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
|
||||
|
||||
m_grouped = -1;
|
||||
|
||||
m_player = 1;
|
||||
m_player = g_Game->GetPlayer( 0 );
|
||||
}
|
||||
|
||||
CEntity::~CEntity()
|
||||
@ -513,8 +514,8 @@ void CEntity::renderSelectionOutline( float alpha )
|
||||
glColor4f( 1.0f, 0.5f, 0.5f, alpha );
|
||||
else
|
||||
{
|
||||
int player = min(max(1, m_player), 8) - 1;
|
||||
glColor4f( PlayerColours[player][0], PlayerColours[player][1], PlayerColours[player][2], alpha);
|
||||
SColour& col = m_player->m_Colour;
|
||||
glColor3f( col.r, col.g, col.b );
|
||||
}
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include <deque>
|
||||
#include "scripting/ScriptableObject.h"
|
||||
#include "Player.h"
|
||||
|
||||
#include "Vector2D.h"
|
||||
#include "Vector3D.h"
|
||||
@ -68,8 +69,8 @@ public:
|
||||
bool m_selected;
|
||||
i32 m_grouped;
|
||||
|
||||
// The player that owns this entity. TODO: do this properly (if this way is wrong)
|
||||
int m_player;
|
||||
// The player that owns this entity
|
||||
CPlayer* m_player;
|
||||
|
||||
// If this unit has been removed from the gameworld but has still
|
||||
// has references.
|
||||
|
@ -50,6 +50,7 @@ HEntity* CEntityManager::getByHandle( u16 index )
|
||||
if( !m_entities[index].m_refcount ) return( NULL );
|
||||
return( new HEntity( index ) );
|
||||
}
|
||||
|
||||
std::vector<HEntity>* CEntityManager::matches( EntityPredicate predicate )
|
||||
{
|
||||
std::vector<HEntity>* matchlist = new std::vector<HEntity>;
|
||||
@ -60,6 +61,16 @@ std::vector<HEntity>* CEntityManager::matches( EntityPredicate predicate )
|
||||
return( matchlist );
|
||||
}
|
||||
|
||||
std::vector<HEntity>* CEntityManager::matches( EntityPredicateUD predicate, void* userdata )
|
||||
{
|
||||
std::vector<HEntity>* matchlist = new std::vector<HEntity>;
|
||||
for( int i = 0; i < MAX_HANDLES; i++ )
|
||||
if( m_entities[i].m_refcount && !m_entities[i].m_entity->m_destroyed )
|
||||
if( predicate( m_entities[i].m_entity, userdata ) )
|
||||
matchlist->push_back( HEntity( i ) );
|
||||
return( matchlist );
|
||||
}
|
||||
|
||||
std::vector<HEntity>* CEntityManager::matches( EntityPredicate predicate1, EntityPredicate predicate2 )
|
||||
{
|
||||
std::vector<HEntity>* matchlist = new std::vector<HEntity>;
|
||||
@ -70,6 +81,16 @@ std::vector<HEntity>* CEntityManager::matches( EntityPredicate predicate1, Entit
|
||||
return( matchlist );
|
||||
}
|
||||
|
||||
std::vector<HEntity>* CEntityManager::matches( EntityPredicateUD predicate1, EntityPredicateUD predicate2, void* userdata )
|
||||
{
|
||||
std::vector<HEntity>* matchlist = new std::vector<HEntity>;
|
||||
for( int i = 0; i < MAX_HANDLES; i++ )
|
||||
if( m_entities[i].m_refcount && !m_entities[i].m_entity->m_destroyed )
|
||||
if( predicate1( m_entities[i].m_entity, userdata ) && predicate2( m_entities[i].m_entity, userdata ) )
|
||||
matchlist->push_back( HEntity( i ) );
|
||||
return( matchlist );
|
||||
}
|
||||
|
||||
std::vector<HEntity>* CEntityManager::getExtant()
|
||||
{
|
||||
std::vector<HEntity>* activelist = new std::vector<HEntity>;
|
||||
|
@ -8,6 +8,27 @@ CScriptObject::CScriptObject()
|
||||
Function = NULL;
|
||||
}
|
||||
|
||||
CScriptObject::~CScriptObject()
|
||||
{
|
||||
Uproot();
|
||||
}
|
||||
|
||||
void CScriptObject::Root()
|
||||
{
|
||||
if( !Function )
|
||||
return;
|
||||
|
||||
FunctionObject = JS_GetFunctionObject( Function );
|
||||
|
||||
JS_AddRoot( g_ScriptingHost.GetContext(), &FunctionObject );
|
||||
}
|
||||
|
||||
void CScriptObject::Uproot()
|
||||
{
|
||||
if( Function )
|
||||
JS_RemoveRoot( g_ScriptingHost.GetContext(), &FunctionObject );
|
||||
}
|
||||
|
||||
CScriptObject::CScriptObject( JSFunction* _Function )
|
||||
{
|
||||
SetFunction( _Function );
|
||||
@ -20,7 +41,11 @@ CScriptObject::CScriptObject( jsval v )
|
||||
|
||||
void CScriptObject::SetFunction( JSFunction* _Function )
|
||||
{
|
||||
Uproot();
|
||||
|
||||
Function = _Function;
|
||||
|
||||
Root();
|
||||
}
|
||||
|
||||
void CScriptObject::SetJSVal( jsval v )
|
||||
@ -43,7 +68,7 @@ void CScriptObject::SetJSVal( jsval v )
|
||||
JSObject* CScriptObject::GetFunctionObject()
|
||||
{
|
||||
if( Function )
|
||||
return( JS_GetFunctionObject( Function ) );
|
||||
return( FunctionObject );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
@ -78,7 +103,12 @@ bool CScriptObject::DispatchEvent( JSObject* Context, CScriptEvent* evt )
|
||||
|
||||
void CScriptObject::Compile( CStrW FileNameTag, CStrW FunctionBody )
|
||||
{
|
||||
if( Function )
|
||||
JS_RemoveRoot( g_ScriptingHost.GetContext(), &Function );
|
||||
|
||||
const char* argnames[] = { "evt" };
|
||||
utf16string str16=FunctionBody.utf16();
|
||||
Function = JS_CompileUCFunction( g_ScriptingHost.GetContext(), NULL, NULL, 1, argnames, str16.c_str(), str16.size(), (CStr)FileNameTag, 0 );
|
||||
|
||||
Root();
|
||||
}
|
||||
|
@ -15,12 +15,18 @@
|
||||
class CScriptObject
|
||||
{
|
||||
JSFunction* Function;
|
||||
JSObject* FunctionObject;
|
||||
void Root();
|
||||
void Uproot();
|
||||
|
||||
public:
|
||||
|
||||
CScriptObject();
|
||||
CScriptObject( JSFunction* _Function );
|
||||
CScriptObject( jsval v );
|
||||
|
||||
~CScriptObject();
|
||||
|
||||
// Initialize in various ways: from a JS function, a string to be compiled, or a jsval containing either.
|
||||
void SetFunction( JSFunction* _Function );
|
||||
void SetJSVal( jsval v );
|
||||
|
Loading…
Reference in New Issue
Block a user