forked from 0ad/0ad
# Fixed some warnings and potentially misleading code
* Removed ToJSVal<jsval> because it's treated as ToJSVal<long> and causes minor confusion and/or compiler errors. Changed script interface functions to return either C++ types or a jsval_t wrapper. * Replaced some C casts with static_cast to avoid significant confusion and to cause compiler errors instead. * Removed some redundant argument-checking code. Simplified some string-generating code. * Fixed some "dereferencing type-punned pointer will break strict-aliasing rules" warnings (from `g++ -O3`). This was SVN commit r5115.
This commit is contained in:
parent
5919fc7877
commit
fba692c8b5
@ -59,8 +59,8 @@ void CProgressBar::Draw()
|
|||||||
float bz = GetBufferedZ();
|
float bz = GetBufferedZ();
|
||||||
|
|
||||||
CGUISpriteInstance *sprite_background, *sprite_bar;
|
CGUISpriteInstance *sprite_background, *sprite_bar;
|
||||||
int cell_id;
|
int cell_id = 0;
|
||||||
float value;
|
float value = 0;
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background);
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar);
|
||||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
// Hashing functions are currently 32-bit only
|
// Hashing functions are currently 32-bit only
|
||||||
cassert(sizeof(int) == 4);
|
cassert(sizeof(int) == 4);
|
||||||
cassert(sizeof(double) == 8);
|
cassert(sizeof(double) == 8);
|
||||||
|
// (TODO: the hashing here is quite rubbish)
|
||||||
|
|
||||||
using namespace I18n;
|
using namespace I18n;
|
||||||
|
|
||||||
@ -48,7 +49,12 @@ StrImW BufferVariable_double::ToString(CLocale*)
|
|||||||
u32 BufferVariable_double::Hash()
|
u32 BufferVariable_double::Hash()
|
||||||
{
|
{
|
||||||
// Add the two four-bytes of the double
|
// Add the two four-bytes of the double
|
||||||
return *((u32*)&value) + *((u32*)&value + 1);
|
union {
|
||||||
|
u32 i[2];
|
||||||
|
double d;
|
||||||
|
} u;
|
||||||
|
u.d = value;
|
||||||
|
return u.i[0]+u.i[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -584,7 +584,7 @@ LibError tree_lookup_dir(const char* V_path, TDir** ptd, uint flags)
|
|||||||
WARN_RETURN(ERR::TNODE_WRONG_TYPE);
|
WARN_RETURN(ERR::TNODE_WRONG_TYPE);
|
||||||
|
|
||||||
TDir* td = (flags & LF_START_DIR)? *ptd : tree_root;
|
TDir* td = (flags & LF_START_DIR)? *ptd : tree_root;
|
||||||
TNode* node;
|
TNode* node = NULL;
|
||||||
CHECK_ERR(lookup(td, V_path, flags, &node));
|
CHECK_ERR(lookup(td, V_path, flags, &node));
|
||||||
// directories should exist, so warn if this fails
|
// directories should exist, so warn if this fails
|
||||||
*ptd = (TDir*)node;
|
*ptd = (TDir*)node;
|
||||||
@ -598,7 +598,7 @@ LibError tree_lookup(const char* V_path, TFile** pfile, uint flags)
|
|||||||
if(VFS_PATH_IS_DIR(V_path))
|
if(VFS_PATH_IS_DIR(V_path))
|
||||||
WARN_RETURN(ERR::TNODE_WRONG_TYPE);
|
WARN_RETURN(ERR::TNODE_WRONG_TYPE);
|
||||||
|
|
||||||
TNode* node;
|
TNode* node = NULL;
|
||||||
LibError ret = lookup(tree_root, V_path, flags, &node);
|
LibError ret = lookup(tree_root, V_path, flags, &node);
|
||||||
RETURN_ERR(ret);
|
RETURN_ERR(ret);
|
||||||
*pfile = (TFile*)node;
|
*pfile = (TFile*)node;
|
||||||
|
@ -110,12 +110,15 @@ static LibError Ogl_Shader_reload(Ogl_Shader* shdr, const char* filename, Handle
|
|||||||
// bad code.
|
// bad code.
|
||||||
ogl_WarnIfError();
|
ogl_WarnIfError();
|
||||||
|
|
||||||
err = ERR::SHDR_CREATE;
|
err = ERR::SHDR_CREATE;
|
||||||
goto fail_fileloaded;
|
goto fail_fileloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
pglShaderSourceARB(shdr->id, 1, (const char**)&file, (const GLint*)&file_size);
|
{
|
||||||
pglCompileShaderARB(shdr->id);
|
const GLchar* strings[] = { (const GLchar*)file };
|
||||||
|
pglShaderSourceARB(shdr->id, 1, strings, (const GLint*)&file_size);
|
||||||
|
pglCompileShaderARB(shdr->id);
|
||||||
|
}
|
||||||
|
|
||||||
pglGetObjectParameterivARB(shdr->id, GL_OBJECT_COMPILE_STATUS_ARB, &compile_success);
|
pglGetObjectParameterivARB(shdr->id, GL_OBJECT_COMPILE_STATUS_ARB, &compile_success);
|
||||||
pglGetObjectParameterivARB(shdr->id, GL_OBJECT_INFO_LOG_LENGTH_ARB, &log_length);
|
pglGetObjectParameterivARB(shdr->id, GL_OBJECT_INFO_LOG_LENGTH_ARB, &log_length);
|
||||||
|
@ -280,13 +280,13 @@ void CGameAttributes::ScriptingInit()
|
|||||||
g_ScriptingHost.DefineCustomObjectType(&PlayerSlotArray_JS::Class,
|
g_ScriptingHost.DefineCustomObjectType(&PlayerSlotArray_JS::Class,
|
||||||
PlayerSlotArray_JS::Construct, 0, NULL, NULL, NULL, NULL);
|
PlayerSlotArray_JS::Construct, 0, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
AddMethod<jsval, &CGameAttributes::JSI_GetOpenSlot>("getOpenSlot", 0);
|
AddMethod<jsval_t, &CGameAttributes::JSI_GetOpenSlot>("getOpenSlot", 0);
|
||||||
AddProperty(L"slots", &CGameAttributes::JSI_GetPlayerSlots);
|
AddProperty(L"slots", &CGameAttributes::JSI_GetPlayerSlots);
|
||||||
|
|
||||||
CJSObject<CGameAttributes>::ScriptingInit("GameAttributes");
|
CJSObject<CGameAttributes>::ScriptingInit("GameAttributes");
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CGameAttributes::JSI_GetOpenSlot(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
|
jsval_t CGameAttributes::JSI_GetOpenSlot(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
|
||||||
{
|
{
|
||||||
vector <CPlayerSlot *>::iterator it;
|
vector <CPlayerSlot *>::iterator it;
|
||||||
for (it = m_PlayerSlots.begin();it != m_PlayerSlots.end();++it)
|
for (it = m_PlayerSlots.begin();it != m_PlayerSlots.end();++it)
|
||||||
|
@ -150,7 +150,7 @@ private:
|
|||||||
static void OnNumSlotsUpdate(CSynchedJSObjectBase *owner);
|
static void OnNumSlotsUpdate(CSynchedJSObjectBase *owner);
|
||||||
|
|
||||||
jsval JSI_GetPlayerSlots(JSContext* cx);
|
jsval JSI_GetPlayerSlots(JSContext* cx);
|
||||||
jsval JSI_GetOpenSlot(JSContext *cx, uintN argc, jsval *argv);
|
jsval_t JSI_GetOpenSlot(JSContext *cx, uintN argc, jsval *argv);
|
||||||
static void ScriptingInit();
|
static void ScriptingInit();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -25,19 +25,21 @@ struct SHotkeyMapping
|
|||||||
|
|
||||||
typedef std::vector<SHotkeyMapping> KeyMapping;
|
typedef std::vector<SHotkeyMapping> KeyMapping;
|
||||||
|
|
||||||
// 'Keycodes' for the mouse buttons
|
enum {
|
||||||
const int MOUSE_LEFT = SDLK_LAST + SDL_BUTTON_LEFT;
|
// 'Keycodes' for the mouse buttons
|
||||||
const int MOUSE_RIGHT = SDLK_LAST + SDL_BUTTON_RIGHT;
|
MOUSE_LEFT = SDLK_LAST + SDL_BUTTON_LEFT,
|
||||||
const int MOUSE_MIDDLE = SDLK_LAST + SDL_BUTTON_MIDDLE;
|
MOUSE_RIGHT = SDLK_LAST + SDL_BUTTON_RIGHT,
|
||||||
const int MOUSE_WHEELUP = SDLK_LAST + SDL_BUTTON_WHEELUP;
|
MOUSE_MIDDLE = SDLK_LAST + SDL_BUTTON_MIDDLE,
|
||||||
const int MOUSE_WHEELDOWN = SDLK_LAST + SDL_BUTTON_WHEELDOWN;
|
MOUSE_WHEELUP = SDLK_LAST + SDL_BUTTON_WHEELUP,
|
||||||
|
MOUSE_WHEELDOWN = SDLK_LAST + SDL_BUTTON_WHEELDOWN,
|
||||||
|
|
||||||
// 'Keycodes' for the unified modifier keys
|
// 'Keycodes' for the unified modifier keys
|
||||||
const int UNIFIED_SHIFT = MOUSE_WHEELDOWN + 1;
|
UNIFIED_SHIFT,
|
||||||
const int UNIFIED_CTRL = MOUSE_WHEELDOWN + 2;
|
UNIFIED_CTRL,
|
||||||
const int UNIFIED_ALT = MOUSE_WHEELDOWN + 3;
|
UNIFIED_ALT,
|
||||||
const int UNIFIED_META = MOUSE_WHEELDOWN + 4;
|
UNIFIED_META,
|
||||||
const int UNIFIED_SUPER = MOUSE_WHEELDOWN + 5;
|
UNIFIED_SUPER
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HK_MAX_KEYCODES: Global maximum number of keycodes, including our "fake" keycodes for
|
* HK_MAX_KEYCODES: Global maximum number of keycodes, including our "fake" keycodes for
|
||||||
@ -358,31 +360,31 @@ InReaction HotkeyInputHandler( const SDL_Event_* ev )
|
|||||||
phantom.ev.type = ( ( ev->ev.type == SDL_KEYDOWN ) || ( ev->ev.type == SDL_MOUSEBUTTONDOWN ) ) ? SDL_KEYDOWN : SDL_KEYUP;
|
phantom.ev.type = ( ( ev->ev.type == SDL_KEYDOWN ) || ( ev->ev.type == SDL_MOUSEBUTTONDOWN ) ) ? SDL_KEYDOWN : SDL_KEYUP;
|
||||||
if( ( keycode == SDLK_LSHIFT ) || ( keycode == SDLK_RSHIFT ) )
|
if( ( keycode == SDLK_LSHIFT ) || ( keycode == SDLK_RSHIFT ) )
|
||||||
{
|
{
|
||||||
(int&)phantom.ev.key.keysym.sym = UNIFIED_SHIFT;
|
phantom.ev.key.keysym.sym = (SDLKey)UNIFIED_SHIFT;
|
||||||
unified[0] = ( phantom.ev.type == SDL_KEYDOWN );
|
unified[0] = ( phantom.ev.type == SDL_KEYDOWN );
|
||||||
HotkeyInputHandler( &phantom );
|
HotkeyInputHandler( &phantom );
|
||||||
}
|
}
|
||||||
else if( ( keycode == SDLK_LCTRL ) || ( keycode == SDLK_RCTRL ) )
|
else if( ( keycode == SDLK_LCTRL ) || ( keycode == SDLK_RCTRL ) )
|
||||||
{
|
{
|
||||||
(int&)phantom.ev.key.keysym.sym = UNIFIED_CTRL;
|
phantom.ev.key.keysym.sym = (SDLKey)UNIFIED_CTRL;
|
||||||
unified[1] = ( phantom.ev.type == SDL_KEYDOWN );
|
unified[1] = ( phantom.ev.type == SDL_KEYDOWN );
|
||||||
HotkeyInputHandler( &phantom );
|
HotkeyInputHandler( &phantom );
|
||||||
}
|
}
|
||||||
else if( ( keycode == SDLK_LALT ) || ( keycode == SDLK_RALT ) )
|
else if( ( keycode == SDLK_LALT ) || ( keycode == SDLK_RALT ) )
|
||||||
{
|
{
|
||||||
(int&)phantom.ev.key.keysym.sym = UNIFIED_ALT;
|
phantom.ev.key.keysym.sym = (SDLKey)UNIFIED_ALT;
|
||||||
unified[2] = ( phantom.ev.type == SDL_KEYDOWN );
|
unified[2] = ( phantom.ev.type == SDL_KEYDOWN );
|
||||||
HotkeyInputHandler( &phantom );
|
HotkeyInputHandler( &phantom );
|
||||||
}
|
}
|
||||||
else if( ( keycode == SDLK_LMETA ) || ( keycode == SDLK_RMETA ) )
|
else if( ( keycode == SDLK_LMETA ) || ( keycode == SDLK_RMETA ) )
|
||||||
{
|
{
|
||||||
(int&)phantom.ev.key.keysym.sym = UNIFIED_META;
|
phantom.ev.key.keysym.sym = (SDLKey)UNIFIED_META;
|
||||||
unified[3] = ( phantom.ev.type == SDL_KEYDOWN );
|
unified[3] = ( phantom.ev.type == SDL_KEYDOWN );
|
||||||
HotkeyInputHandler( &phantom );
|
HotkeyInputHandler( &phantom );
|
||||||
}
|
}
|
||||||
else if( ( keycode == SDLK_LSUPER ) || ( keycode == SDLK_RSUPER ) )
|
else if( ( keycode == SDLK_LSUPER ) || ( keycode == SDLK_RSUPER ) )
|
||||||
{
|
{
|
||||||
(int&)phantom.ev.key.keysym.sym = UNIFIED_SUPER;
|
phantom.ev.key.keysym.sym = (SDLKey)UNIFIED_SUPER;
|
||||||
unified[4] = ( phantom.ev.type == SDL_KEYDOWN );
|
unified[4] = ( phantom.ev.type == SDL_KEYDOWN );
|
||||||
HotkeyInputHandler( &phantom );
|
HotkeyInputHandler( &phantom );
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ CPlayer::CPlayer(uint playerID):
|
|||||||
for(int i=0; i<=PS_MAX_PLAYERS; i++)
|
for(int i=0; i<=PS_MAX_PLAYERS; i++)
|
||||||
{
|
{
|
||||||
CStrW name = CStrW(L"diplomaticStance_") + CStrW(i);
|
CStrW name = CStrW(L"diplomaticStance_") + CStrW(i);
|
||||||
ISynchedJSProperty *prop=new CSynchedJSProperty<int>(name, (int*)&m_DiplomaticStance[i], this);
|
ISynchedJSProperty *prop=new CSynchedJSProperty<int>(name, &m_DiplomaticStance[i], this);
|
||||||
m_SynchedProperties[name]=prop;
|
m_SynchedProperties[name]=prop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,11 +66,11 @@ void CPlayer::ScriptingInit()
|
|||||||
g_ScriptingHost.DefineConstant("DIPLOMACY_NEUTRAL", DIPLOMACY_NEUTRAL);
|
g_ScriptingHost.DefineConstant("DIPLOMACY_NEUTRAL", DIPLOMACY_NEUTRAL);
|
||||||
g_ScriptingHost.DefineConstant("DIPLOMACY_ALLIED", DIPLOMACY_ALLIED);
|
g_ScriptingHost.DefineConstant("DIPLOMACY_ALLIED", DIPLOMACY_ALLIED);
|
||||||
|
|
||||||
AddMethod<jsval, &CPlayer::JSI_ToString>( "toString", 0 );
|
AddMethod<CStrW, &CPlayer::JSI_ToString>("toString", 0);
|
||||||
AddMethod<jsval, &CPlayer::JSI_SetColour>( "setColour", 1);
|
AddMethod<void, &CPlayer::JSI_SetColour>("setColour", 1);
|
||||||
AddMethod<jsval, &CPlayer::JSI_GetColour>( "getColour", 0);
|
AddMethod<jsval_t, &CPlayer::JSI_GetColour>("getColour", 0);
|
||||||
AddMethod<jsval, &CPlayer::JSI_SetDiplomaticStance>( "setDiplomaticStance", 2);
|
AddMethod<void, &CPlayer::JSI_SetDiplomaticStance>("setDiplomaticStance", 2);
|
||||||
AddMethod<jsval, &CPlayer::JSI_GetDiplomaticStance>( "getDiplomaticStance", 1);
|
AddMethod<jsval_t, &CPlayer::JSI_GetDiplomaticStance>("getDiplomaticStance", 1);
|
||||||
|
|
||||||
AddProperty( L"id", &CPlayer::m_PlayerID, true );
|
AddProperty( L"id", &CPlayer::m_PlayerID, true );
|
||||||
// MT: Work out how this fits with the Synched stuff...
|
// MT: Work out how this fits with the Synched stuff...
|
||||||
@ -112,13 +112,9 @@ void CPlayer::GetControlledEntities(std::vector<HEntity>& controlled_entities)
|
|||||||
g_EntityManager.GetMatchingAsHandles( controlled_entities, ControllerPredicate, this );
|
g_EntityManager.GetMatchingAsHandles( controlled_entities, ControllerPredicate, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CPlayer::JSI_ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) )
|
CStrW CPlayer::JSI_ToString( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
wchar_t buffer[256];
|
return L"[object Player: " + m_Name + L"]";
|
||||||
swprintf( buffer, 256, L"[object Player: %ls]", m_Name.c_str() );
|
|
||||||
buffer[255] = 0;
|
|
||||||
utf16string str16(buffer, buffer+wcslen(buffer));
|
|
||||||
return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CPlayer::JSI_GetControlledEntities(JSContext* UNUSED(cx))
|
jsval CPlayer::JSI_GetControlledEntities(JSContext* UNUSED(cx))
|
||||||
@ -129,20 +125,14 @@ jsval CPlayer::JSI_GetControlledEntities(JSContext* UNUSED(cx))
|
|||||||
return( vp );
|
return( vp );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CPlayer::JSI_SetColour( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
void CPlayer::JSI_SetColour( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* argv )
|
||||||
{
|
{
|
||||||
if (argc != 1)
|
|
||||||
return JSVAL_NULL;
|
|
||||||
|
|
||||||
m_Colour=*( ToNative<SPlayerColour>(argv[0]) );
|
m_Colour=*( ToNative<SPlayerColour>(argv[0]) );
|
||||||
ISynchedJSProperty *prop=GetSynchedProperty(L"colour");
|
ISynchedJSProperty *prop=GetSynchedProperty(L"colour");
|
||||||
Update(L"colour", prop);
|
Update(L"colour", prop);
|
||||||
|
|
||||||
// Return something that isn't null, so users can check whether this function succeeded
|
|
||||||
return argv[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CPlayer::JSI_GetColour( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CPlayer::JSI_GetColour( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
//ISynchedJSProperty *prop=GetSynchedProperty(L"colour");
|
//ISynchedJSProperty *prop=GetSynchedProperty(L"colour");
|
||||||
//return prop->Get(cx, this);
|
//return prop->Get(cx, this);
|
||||||
@ -150,35 +140,32 @@ jsval CPlayer::JSI_GetColour( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval*
|
|||||||
return ToJSVal(col);
|
return ToJSVal(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CPlayer::JSI_SetDiplomaticStance(JSContext *cx, uintN argc, jsval *argv)
|
void CPlayer::JSI_SetDiplomaticStance(JSContext *cx, uintN UNUSED(argc), jsval *argv)
|
||||||
{
|
{
|
||||||
JSU_ASSERT(argc==2, "2 arguments required");
|
|
||||||
JSU_ASSERT( JSVAL_IS_INT(argv[1]), "Argument 2 must be a valid stance ID" );
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CPlayer* player = ToPrimitive<CPlayer*>( argv[0] );
|
CPlayer* player = ToPrimitive<CPlayer*>( argv[0] );
|
||||||
int stance = ToPrimitive<int>( argv[1] );
|
int stance = ToPrimitive<int>( argv[1] );
|
||||||
JSU_ASSERT( stance==DIPLOMACY_ENEMY || stance==DIPLOMACY_NEUTRAL || stance==DIPLOMACY_ALLIED,
|
if (! (stance==DIPLOMACY_ENEMY || stance==DIPLOMACY_NEUTRAL || stance==DIPLOMACY_ALLIED))
|
||||||
"Argument 2 must be a valid stance ID" );
|
{
|
||||||
|
JS_ReportError(cx, "Argument 2 must be a valid stance ID");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_DiplomaticStance[player->m_PlayerID] = (EDiplomaticStance) stance;
|
m_DiplomaticStance[player->m_PlayerID] = (EDiplomaticStance) stance;
|
||||||
|
|
||||||
CStrW name = CStrW(L"diplomaticStance_") + CStrW(player->m_PlayerID);
|
CStrW name = CStrW(L"diplomaticStance_") + CStrW(player->m_PlayerID);
|
||||||
ISynchedJSProperty *prop=GetSynchedProperty(name);
|
ISynchedJSProperty *prop=GetSynchedProperty(name);
|
||||||
Update(name, prop);
|
Update(name, prop);
|
||||||
|
|
||||||
return JSVAL_VOID;
|
|
||||||
}
|
}
|
||||||
catch( PSERROR_Scripting_ConversionFailed )
|
catch( PSERROR_Scripting_ConversionFailed )
|
||||||
{
|
{
|
||||||
JS_ReportError( cx, "Could not convert argument 1 to a Player object" );
|
JS_ReportError( cx, "Could not convert argument 1 to a Player object" );
|
||||||
return JSVAL_VOID;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CPlayer::JSI_GetDiplomaticStance(JSContext *cx, uintN argc, jsval *argv)
|
jsval_t CPlayer::JSI_GetDiplomaticStance(JSContext *cx, uintN UNUSED(argc), jsval *argv)
|
||||||
{
|
{
|
||||||
JSU_ASSERT(argc==1, "1 argument required");
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CPlayer* player = ToPrimitive<CPlayer*>( argv[0] );
|
CPlayer* player = ToPrimitive<CPlayer*>( argv[0] );
|
||||||
|
@ -31,7 +31,7 @@ private:
|
|||||||
PS_uint m_PlayerID;
|
PS_uint m_PlayerID;
|
||||||
PS_uint m_LOSToken;
|
PS_uint m_LOSToken;
|
||||||
SPlayerColour m_Colour;
|
SPlayerColour m_Colour;
|
||||||
EDiplomaticStance m_DiplomaticStance[PS_MAX_PLAYERS+1];
|
int /*EDiplomaticStance*/ m_DiplomaticStance[PS_MAX_PLAYERS+1];
|
||||||
std::vector<CTechnology*> m_ActiveTechs;
|
std::vector<CTechnology*> m_ActiveTechs;
|
||||||
|
|
||||||
UpdateCallback *m_UpdateCB;
|
UpdateCallback *m_UpdateCB;
|
||||||
@ -64,7 +64,7 @@ public:
|
|||||||
{ m_Colour = colour; }
|
{ m_Colour = colour; }
|
||||||
|
|
||||||
inline EDiplomaticStance GetDiplomaticStance(CPlayer* other) const
|
inline EDiplomaticStance GetDiplomaticStance(CPlayer* other) const
|
||||||
{ return m_DiplomaticStance[other->m_PlayerID]; }
|
{ return (EDiplomaticStance)m_DiplomaticStance[other->m_PlayerID]; }
|
||||||
inline void SetDiplomaticStance(CPlayer* other, EDiplomaticStance stance)
|
inline void SetDiplomaticStance(CPlayer* other, EDiplomaticStance stance)
|
||||||
{ m_DiplomaticStance[other->m_PlayerID] = stance; }
|
{ m_DiplomaticStance[other->m_PlayerID] = stance; }
|
||||||
|
|
||||||
@ -88,12 +88,12 @@ public:
|
|||||||
void GetControlledEntities(std::vector<HEntity>& controlled_entities);
|
void GetControlledEntities(std::vector<HEntity>& controlled_entities);
|
||||||
|
|
||||||
// JS Interface Functions
|
// JS Interface Functions
|
||||||
jsval JSI_ToString( JSContext* context, uintN argc, jsval* argv );
|
CStrW JSI_ToString( JSContext* context, uintN argc, jsval* argv );
|
||||||
jsval JSI_GetControlledEntities( JSContext* context );
|
jsval JSI_GetControlledEntities( JSContext* context );
|
||||||
jsval JSI_SetColour(JSContext *context, uintN argc, jsval *argv);
|
void JSI_SetColour(JSContext *context, uintN argc, jsval *argv);
|
||||||
jsval JSI_GetColour(JSContext *context, uintN argc, jsval *argv);
|
jsval_t JSI_GetColour(JSContext *context, uintN argc, jsval *argv);
|
||||||
jsval JSI_SetDiplomaticStance(JSContext *context, uintN argc, jsval *argv);
|
void JSI_SetDiplomaticStance(JSContext *context, uintN argc, jsval *argv);
|
||||||
jsval JSI_GetDiplomaticStance(JSContext *context, uintN argc, jsval *argv);
|
jsval_t JSI_GetDiplomaticStance(JSContext *context, uintN argc, jsval *argv);
|
||||||
|
|
||||||
static void ScriptingInit();
|
static void ScriptingInit();
|
||||||
};
|
};
|
||||||
|
@ -163,10 +163,10 @@ CScriptEvent::CScriptEvent( const CStrW& Type, unsigned int TypeCode, bool Cance
|
|||||||
|
|
||||||
void CScriptEvent::ScriptingInit()
|
void CScriptEvent::ScriptingInit()
|
||||||
{
|
{
|
||||||
AddMethod<jsval, &CScriptEvent::ToString>( "toString", 0 );
|
AddMethod<CStr, &CScriptEvent::ToString>( "toString", 0 );
|
||||||
AddMethod<jsval, &CScriptEvent::PreventDefault>( "preventDefault", 0 );
|
AddMethod<void, &CScriptEvent::PreventDefault>( "preventDefault", 0 );
|
||||||
AddMethod<jsval, &CScriptEvent::PreventDefault>( "cancel", 0 );
|
AddMethod<void, &CScriptEvent::PreventDefault>( "cancel", 0 );
|
||||||
AddMethod<jsval, &CScriptEvent::StopPropagation>( "stopPropagation", 0 );
|
AddMethod<void, &CScriptEvent::StopPropagation>( "stopPropagation", 0 );
|
||||||
|
|
||||||
AddProperty( L"type", &CScriptEvent::m_Type, true );
|
AddProperty( L"type", &CScriptEvent::m_Type, true );
|
||||||
AddProperty( L"cancelable", &CScriptEvent::m_Cancelable, true );
|
AddProperty( L"cancelable", &CScriptEvent::m_Cancelable, true );
|
||||||
@ -176,26 +176,19 @@ void CScriptEvent::ScriptingInit()
|
|||||||
CJSObject<CScriptEvent>::ScriptingInit( "Event" );
|
CJSObject<CScriptEvent>::ScriptingInit( "Event" );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CScriptEvent::PreventDefault( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
void CScriptEvent::PreventDefault( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
if( m_Cancelable )
|
if( m_Cancelable )
|
||||||
m_Cancelled = true;
|
m_Cancelled = true;
|
||||||
return( JSVAL_VOID );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CScriptEvent::StopPropagation( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
void CScriptEvent::StopPropagation( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
if( m_Blockable )
|
if( m_Blockable )
|
||||||
m_Blocked = true;
|
m_Blocked = true;
|
||||||
return( JSVAL_VOID );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CScriptEvent::ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) )
|
CStr CScriptEvent::ToString( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
wchar_t buffer[256];
|
return "[object Event: " + CStr(m_Type) + "]";
|
||||||
swprintf( buffer, 256, L"[object Event: %ls]", m_Type.c_str() );
|
|
||||||
buffer[255] = 0;
|
|
||||||
utf16string str16=utf16string(buffer, buffer+wcslen(buffer));
|
|
||||||
return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,9 +121,9 @@ public:
|
|||||||
|
|
||||||
// --
|
// --
|
||||||
|
|
||||||
jsval ToString( JSContext* cx, uintN argc, jsval* argv );
|
CStr ToString( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval PreventDefault( JSContext* cx, uintN argc, jsval* argv );
|
void PreventDefault( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval StopPropagation( JSContext* cx, uintN argc, jsval* argv );
|
void StopPropagation( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CScriptEvent( const CStrW& Type, unsigned int TypeCode = (unsigned int)-1, bool Cancelable = true, bool Blockable = true );
|
CScriptEvent( const CStrW& Type, unsigned int TypeCode = (unsigned int)-1, bool Cancelable = true, bool Blockable = true );
|
||||||
|
@ -251,9 +251,9 @@ template<> jsval ToJSVal<CStr8>( CStr8& Native )
|
|||||||
|
|
||||||
// jsval
|
// jsval
|
||||||
|
|
||||||
template<> jsval ToJSVal<jsval>( const jsval& Native )
|
template<> jsval ToJSVal<jsval_t>( const jsval_t& Native )
|
||||||
{
|
{
|
||||||
return( Native );
|
return( Native.v );
|
||||||
}
|
}
|
||||||
|
|
||||||
// String->JSVal
|
// String->JSVal
|
||||||
|
@ -158,7 +158,15 @@ template<> jsval ToJSVal<CStr8>( CStr8& Native );
|
|||||||
|
|
||||||
// jsval
|
// jsval
|
||||||
|
|
||||||
template<> jsval ToJSVal<jsval>( const jsval& Native );
|
// Don't want to just use jsval directly, because it's equivalent to long and
|
||||||
|
// can cause conflicts or confusion. So create a simple wrapper class for it,
|
||||||
|
// so it's a real distinguishable type.
|
||||||
|
struct jsval_t
|
||||||
|
{
|
||||||
|
jsval v;
|
||||||
|
jsval_t(jsval v) : v(v) {}
|
||||||
|
};
|
||||||
|
template<> jsval ToJSVal<jsval_t>( const jsval_t& Native );
|
||||||
|
|
||||||
// Intelligent CStrW->JSVal conversion
|
// Intelligent CStrW->JSVal conversion
|
||||||
|
|
||||||
|
@ -111,11 +111,14 @@ public:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TAG_DOUBLE:
|
case TAG_DOUBLE:
|
||||||
// Ehm. I think this works, but I can't say as it's something I've tried before.
|
|
||||||
{
|
{
|
||||||
u64 ival;
|
union {
|
||||||
Deserialize_int_8( buffer, ival );
|
u64 ival;
|
||||||
JS_NewDoubleValue( g_ScriptingHost.GetContext(), *( (double*)(&ival) ), &m_data );
|
double dval;
|
||||||
|
} val;
|
||||||
|
cassert(sizeof(val.ival) == sizeof(val.dval));
|
||||||
|
Deserialize_int_8( buffer, val.ival );
|
||||||
|
JS_NewDoubleValue( g_ScriptingHost.GetContext(), val.dval, &m_data );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TAG_STRING:
|
case TAG_STRING:
|
||||||
|
@ -47,7 +47,7 @@ void SColour::SColourInit( float _r, float _g, float _b, float _a )
|
|||||||
|
|
||||||
void SColour::ScriptingInit()
|
void SColour::ScriptingInit()
|
||||||
{
|
{
|
||||||
AddMethod<jsval, &SColour::ToString>( "toString", 0 );
|
AddMethod<CStr, &SColour::ToString>( "toString", 0 );
|
||||||
AddProperty<float>( L"r", (float IJSObject::*)&SColour::r );
|
AddProperty<float>( L"r", (float IJSObject::*)&SColour::r );
|
||||||
AddProperty<float>( L"g", (float IJSObject::*)&SColour::g );
|
AddProperty<float>( L"g", (float IJSObject::*)&SColour::g );
|
||||||
AddProperty<float>( L"b", (float IJSObject::*)&SColour::b );
|
AddProperty<float>( L"b", (float IJSObject::*)&SColour::b );
|
||||||
@ -56,15 +56,9 @@ void SColour::ScriptingInit()
|
|||||||
CJSObject<SColour>::ScriptingInit( "Colour", SColour::Construct, 3 );
|
CJSObject<SColour>::ScriptingInit( "Colour", SColour::Construct, 3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval SColour::ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) )
|
CStr SColour::ToString( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
wchar_t buffer[256];
|
return "[object Colour: ( " + CStr(r) + ", " + CStr(g) + ", " + CStr(b) + ", " + CStr(a) + " )]";
|
||||||
|
|
||||||
swprintf( buffer, 256, L"[object Colour: ( %f, %f, %f, %f )]", r, g, b, a );
|
|
||||||
buffer[255] = 0;
|
|
||||||
|
|
||||||
utf16string str16(buffer, buffer+wcslen(buffer));
|
|
||||||
return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
|
|
||||||
SColour &operator = (const SColour &o);
|
SColour &operator = (const SColour &o);
|
||||||
|
|
||||||
jsval ToString( JSContext* cx, uintN argc, jsval* argv );
|
CStr ToString( JSContext* cx, uintN argc, jsval* argv );
|
||||||
static void ScriptingInit();
|
static void ScriptingInit();
|
||||||
static JSBool Construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
|
static JSBool Construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
|
||||||
};
|
};
|
||||||
|
@ -171,6 +171,23 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Special case for void functions
|
||||||
|
template<typename T, bool ReadOnly, void (T::*NativeFunction)( JSContext* cx, uintN argc, jsval* argv )>
|
||||||
|
class CNativeFunction<T, ReadOnly, void, NativeFunction>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static JSBool JSFunction( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* UNUSED(rval) )
|
||||||
|
{
|
||||||
|
T* Native = ToNative<T>( cx, obj );
|
||||||
|
if( !Native )
|
||||||
|
return( JS_TRUE );
|
||||||
|
|
||||||
|
(Native->*NativeFunction)( cx, argc, argv );
|
||||||
|
|
||||||
|
return( JS_TRUE );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T, bool ReadOnly> class CJSObject : public IJSObject
|
template<typename T, bool ReadOnly> class CJSObject : public IJSObject
|
||||||
{
|
{
|
||||||
// This object
|
// This object
|
||||||
|
@ -371,53 +371,53 @@ public:
|
|||||||
void DestroyAllNotifiers();
|
void DestroyAllNotifiers();
|
||||||
|
|
||||||
int FindSector( int divs, float angle, float maxAngle, bool negative=true );
|
int FindSector( int divs, float angle, float maxAngle, bool negative=true );
|
||||||
jsval FlattenTerrain( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t FlattenTerrain( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
CEntityFormation* GetFormation();
|
CEntityFormation* GetFormation();
|
||||||
jsval GetFormationPenalty( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetFormationPenalty( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval GetFormationPenaltyBase( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetFormationPenaltyBase( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval GetFormationPenaltyType( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetFormationPenaltyType( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval GetFormationPenaltyVal( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetFormationPenaltyVal( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
jsval GetFormationBonus( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetFormationBonus( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval GetFormationBonusBase( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetFormationBonusBase( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval GetFormationBonusType( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetFormationBonusType( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval GetFormationBonusVal( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetFormationBonusVal( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
void DispatchFormationEvent( int type );
|
void DispatchFormationEvent( int type );
|
||||||
|
|
||||||
jsval RegisterDamage( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t RegisterDamage( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval RegisterOrderChange( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t RegisterOrderChange( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval GetAttackDirections( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetAttackDirections( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
jsval FindSector( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t FindSector( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
// Script constructor
|
// Script constructor
|
||||||
static JSBool Construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
|
static JSBool Construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
|
||||||
|
|
||||||
// Script-bound functions
|
// Script-bound functions
|
||||||
|
|
||||||
jsval ToString( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t ToString( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
bool Kill( JSContext* cx, uintN argc, jsval* argv );
|
bool Kill( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval GetSpawnPoint( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetSpawnPoint( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
inline jsval HasRallyPoint( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t HasRallyPoint( JSContext* cx, uintN argc, jsval* argv );
|
||||||
inline jsval GetRallyPoint( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetRallyPoint( JSContext* cx, uintN argc, jsval* argv );
|
||||||
inline jsval SetRallyPoint( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t SetRallyPoint( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
jsval AddAura( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t AddAura( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval RemoveAura( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t RemoveAura( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
jsval SetActionParams( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t SetActionParams( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval TriggerRun( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t TriggerRun( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval SetRun( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t SetRun( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval IsRunning( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t IsRunning( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval GetRunState( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetRunState( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
jsval OnDamaged( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t OnDamaged( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
jsval GetVisibleEntities( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t GetVisibleEntities( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
float GetDistance( JSContext* cx, uintN argc, jsval* argv );
|
float GetDistance( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
@ -426,8 +426,8 @@ public:
|
|||||||
bool ForceCheckListeners( JSContext* cx, uintN argc, jsval* argv );
|
bool ForceCheckListeners( JSContext* cx, uintN argc, jsval* argv );
|
||||||
int GetCurrentRequest( JSContext* cx, uintN argc, jsval* argv );
|
int GetCurrentRequest( JSContext* cx, uintN argc, jsval* argv );
|
||||||
void CheckListeners( int type, CEntity *target );
|
void CheckListeners( int type, CEntity *target );
|
||||||
jsval DestroyAllNotifiers( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t DestroyAllNotifiers( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval DestroyNotifier( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t DestroyNotifier( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
jsval JSI_GetPlayer();
|
jsval JSI_GetPlayer();
|
||||||
void JSI_SetPlayer(jsval val);
|
void JSI_SetPlayer(jsval val);
|
||||||
@ -464,7 +464,7 @@ public:
|
|||||||
return( m_classes.IsMember( ToPrimitive<CStrW>( cx, argv[0] ) ) );
|
return( m_classes.IsMember( ToPrimitive<CStrW>( cx, argv[0] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval TerminateOrder( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
jsval_t TerminateOrder( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
debug_assert( argc >= 1);
|
debug_assert( argc >= 1);
|
||||||
if ( ToPrimitive<bool>( argv[0] ) )
|
if ( ToPrimitive<bool>( argv[0] ) )
|
||||||
@ -474,7 +474,7 @@ public:
|
|||||||
return JSVAL_VOID;
|
return JSVAL_VOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval GetHeight( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t GetHeight( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal(m_position.Y);
|
return ToJSVal(m_position.Y);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ struct SOrderData
|
|||||||
class CEntityListener
|
class CEntityListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum
|
enum EType
|
||||||
{
|
{
|
||||||
NOTIFY_NONE = 0x00,
|
NOTIFY_NONE = 0x00,
|
||||||
|
|
||||||
|
@ -46,48 +46,50 @@ extern int g_xres, g_yres;
|
|||||||
|
|
||||||
void CEntity::ScriptingInit()
|
void CEntity::ScriptingInit()
|
||||||
{
|
{
|
||||||
AddMethod<jsval, &CEntity::ToString>( "toString", 0 );
|
// TODO: lots of these return jsval when they should return proper types
|
||||||
|
// and make use of automatic type conversion
|
||||||
|
AddMethod<jsval_t, &CEntity::ToString>( "toString", 0 );
|
||||||
AddMethod<bool, &CEntity::OrderSingle>( "order", 1 );
|
AddMethod<bool, &CEntity::OrderSingle>( "order", 1 );
|
||||||
AddMethod<bool, &CEntity::OrderQueued>( "orderQueued", 1 );
|
AddMethod<bool, &CEntity::OrderQueued>( "orderQueued", 1 );
|
||||||
AddMethod<bool, &CEntity::OrderFromTriggers>( "orderFromTriggers", 1 );
|
AddMethod<bool, &CEntity::OrderFromTriggers>( "orderFromTriggers", 1 );
|
||||||
AddMethod<jsval, &CEntity::TerminateOrder>( "terminateOrder", 1 );
|
AddMethod<jsval_t, &CEntity::TerminateOrder>( "terminateOrder", 1 );
|
||||||
AddMethod<bool, &CEntity::Kill>( "kill", 0 );
|
AddMethod<bool, &CEntity::Kill>( "kill", 0 );
|
||||||
AddMethod<bool, &CEntity::IsIdle>( "isIdle", 0 );
|
AddMethod<bool, &CEntity::IsIdle>( "isIdle", 0 );
|
||||||
AddMethod<bool, &CEntity::HasClass>( "hasClass", 1 );
|
AddMethod<bool, &CEntity::HasClass>( "hasClass", 1 );
|
||||||
AddMethod<jsval, &CEntity::GetSpawnPoint>( "getSpawnPoint", 1 );
|
AddMethod<jsval_t, &CEntity::GetSpawnPoint>( "getSpawnPoint", 1 );
|
||||||
AddMethod<jsval, &CEntity::AddAura>( "addAura", 3 );
|
AddMethod<jsval_t, &CEntity::AddAura>( "addAura", 3 );
|
||||||
AddMethod<jsval, &CEntity::RemoveAura>( "removeAura", 1 );
|
AddMethod<jsval_t, &CEntity::RemoveAura>( "removeAura", 1 );
|
||||||
AddMethod<jsval, &CEntity::SetActionParams>( "setActionParams", 5 );
|
AddMethod<jsval_t, &CEntity::SetActionParams>( "setActionParams", 5 );
|
||||||
AddMethod<int, &CEntity::GetCurrentRequest>( "getCurrentRequest", 0 );
|
AddMethod<int, &CEntity::GetCurrentRequest>( "getCurrentRequest", 0 );
|
||||||
AddMethod<bool, &CEntity::ForceCheckListeners>( "forceCheckListeners", 2 );
|
AddMethod<bool, &CEntity::ForceCheckListeners>( "forceCheckListeners", 2 );
|
||||||
AddMethod<bool, &CEntity::RequestNotification>( "requestNotification", 4 );
|
AddMethod<bool, &CEntity::RequestNotification>( "requestNotification", 4 );
|
||||||
AddMethod<jsval, &CEntity::DestroyNotifier>( "destroyNotifier", 1 );
|
AddMethod<jsval_t, &CEntity::DestroyNotifier>( "destroyNotifier", 1 );
|
||||||
AddMethod<jsval, &CEntity::DestroyAllNotifiers>( "destroyAllNotifiers", 0 );
|
AddMethod<jsval_t, &CEntity::DestroyAllNotifiers>( "destroyAllNotifiers", 0 );
|
||||||
AddMethod<jsval, &CEntity::TriggerRun>( "triggerRun", 1 );
|
AddMethod<jsval_t, &CEntity::TriggerRun>( "triggerRun", 1 );
|
||||||
AddMethod<jsval, &CEntity::SetRun>( "setRun", 1 );
|
AddMethod<jsval_t, &CEntity::SetRun>( "setRun", 1 );
|
||||||
AddMethod<jsval, &CEntity::GetRunState>( "getRunState", 0 );
|
AddMethod<jsval_t, &CEntity::GetRunState>( "getRunState", 0 );
|
||||||
AddMethod<bool, &CEntity::IsInFormation>( "isInFormation", 0 );
|
AddMethod<bool, &CEntity::IsInFormation>( "isInFormation", 0 );
|
||||||
AddMethod<jsval, &CEntity::GetFormationBonus>( "getFormationBonus", 0 );
|
AddMethod<jsval_t, &CEntity::GetFormationBonus>( "getFormationBonus", 0 );
|
||||||
AddMethod<jsval, &CEntity::GetFormationBonusType>( "getFormationBonusType", 0 );
|
AddMethod<jsval_t, &CEntity::GetFormationBonusType>( "getFormationBonusType", 0 );
|
||||||
AddMethod<jsval, &CEntity::GetFormationBonusVal>( "getFormationBonusVal", 0 );
|
AddMethod<jsval_t, &CEntity::GetFormationBonusVal>( "getFormationBonusVal", 0 );
|
||||||
AddMethod<jsval, &CEntity::GetFormationPenalty>( "getFormationPenalty", 0 );
|
AddMethod<jsval_t, &CEntity::GetFormationPenalty>( "getFormationPenalty", 0 );
|
||||||
AddMethod<jsval, &CEntity::GetFormationPenaltyType>( "getFormationPenaltyType", 0 );
|
AddMethod<jsval_t, &CEntity::GetFormationPenaltyType>( "getFormationPenaltyType", 0 );
|
||||||
AddMethod<jsval, &CEntity::GetFormationPenaltyVal>( "getFormationPenaltyVal", 0 );
|
AddMethod<jsval_t, &CEntity::GetFormationPenaltyVal>( "getFormationPenaltyVal", 0 );
|
||||||
AddMethod<jsval, &CEntity::RegisterDamage>( "registerDamage", 0 );
|
AddMethod<jsval_t, &CEntity::RegisterDamage>( "registerDamage", 0 );
|
||||||
AddMethod<jsval, &CEntity::RegisterOrderChange>( "registerOrderChange", 0 );
|
AddMethod<jsval_t, &CEntity::RegisterOrderChange>( "registerOrderChange", 0 );
|
||||||
AddMethod<jsval, &CEntity::GetAttackDirections>( "getAttackDirections", 0 );
|
AddMethod<jsval_t, &CEntity::GetAttackDirections>( "getAttackDirections", 0 );
|
||||||
AddMethod<jsval, &CEntity::FindSector>( "findSector", 4);
|
AddMethod<jsval_t, &CEntity::FindSector>( "findSector", 4);
|
||||||
AddMethod<jsval, &CEntity::GetHeight>( "getHeight", 0 );
|
AddMethod<jsval_t, &CEntity::GetHeight>( "getHeight", 0 );
|
||||||
AddMethod<jsval, &CEntity::HasRallyPoint>( "hasRallyPoint", 0 );
|
AddMethod<jsval_t, &CEntity::HasRallyPoint>( "hasRallyPoint", 0 );
|
||||||
AddMethod<jsval, &CEntity::SetRallyPoint>( "setRallyPoint", 0 );
|
AddMethod<jsval_t, &CEntity::SetRallyPoint>( "setRallyPoint", 0 );
|
||||||
AddMethod<jsval, &CEntity::GetRallyPoint>( "getRallyPoint", 0 );
|
AddMethod<jsval_t, &CEntity::GetRallyPoint>( "getRallyPoint", 0 );
|
||||||
AddMethod<jsval, &CEntity::OnDamaged>( "onDamaged", 1 );
|
AddMethod<jsval_t, &CEntity::OnDamaged>( "onDamaged", 1 );
|
||||||
AddMethod<jsval, &CEntity::GetVisibleEntities>( "getVisibleEntities", 0 );
|
AddMethod<jsval_t, &CEntity::GetVisibleEntities>( "getVisibleEntities", 0 );
|
||||||
AddMethod<float, &CEntity::GetDistance>( "getDistance", 1 );
|
AddMethod<float, &CEntity::GetDistance>( "getDistance", 1 );
|
||||||
AddMethod<jsval, &CEntity::FlattenTerrain>( "flattenTerrain", 0 );
|
AddMethod<jsval_t, &CEntity::FlattenTerrain>( "flattenTerrain", 0 );
|
||||||
|
|
||||||
AddClassProperty( L"traits.id.classes", (GetFn)&CEntity::GetClassSet, (SetFn)&CEntity::SetClassSet );
|
AddClassProperty( L"traits.id.classes", static_cast<GetFn>(&CEntity::GetClassSet), static_cast<SetFn>(&CEntity::SetClassSet) );
|
||||||
AddClassProperty( L"template", (CEntityTemplate* CEntity::*)&CEntity::m_base, false, (NotifyFn)&CEntity::LoadBase );
|
AddClassProperty( L"template", static_cast<CEntityTemplate* CEntity::*>(&CEntity::m_base), false, static_cast<NotifyFn>(&CEntity::LoadBase) );
|
||||||
|
|
||||||
/* Any inherited property MUST be added to EntityTemplate.cpp as well */
|
/* Any inherited property MUST be added to EntityTemplate.cpp as well */
|
||||||
|
|
||||||
@ -97,13 +99,13 @@ void CEntity::ScriptingInit()
|
|||||||
AddClassProperty( L"actions.move.run.range", &CEntity::m_runMaxRange );
|
AddClassProperty( L"actions.move.run.range", &CEntity::m_runMaxRange );
|
||||||
AddClassProperty( L"actions.move.run.regenRate", &CEntity::m_runRegenRate );
|
AddClassProperty( L"actions.move.run.regenRate", &CEntity::m_runRegenRate );
|
||||||
AddClassProperty( L"actions.move.run.decayRate", &CEntity::m_runDecayRate );
|
AddClassProperty( L"actions.move.run.decayRate", &CEntity::m_runDecayRate );
|
||||||
AddClassProperty( L"selected", &CEntity::m_selected, false, (NotifyFn)&CEntity::CheckSelection );
|
AddClassProperty( L"selected", &CEntity::m_selected, false, static_cast<NotifyFn>(&CEntity::CheckSelection) );
|
||||||
AddClassProperty( L"group", &CEntity::m_grouped, false, (NotifyFn)&CEntity::CheckGroup );
|
AddClassProperty( L"group", &CEntity::m_grouped, false, static_cast<NotifyFn>(&CEntity::CheckGroup) );
|
||||||
AddClassProperty( L"traits.extant", &CEntity::m_extant );
|
AddClassProperty( L"traits.extant", &CEntity::m_extant );
|
||||||
AddClassProperty( L"actions.move.turningRadius", &CEntity::m_turningRadius );
|
AddClassProperty( L"actions.move.turningRadius", &CEntity::m_turningRadius );
|
||||||
AddClassProperty( L"position", &CEntity::m_position, false, (NotifyFn)&CEntity::Teleport );
|
AddClassProperty( L"position", &CEntity::m_position, false, static_cast<NotifyFn>(&CEntity::Teleport) );
|
||||||
AddClassProperty( L"orientation", &CEntity::m_orientation, false, (NotifyFn)&CEntity::Reorient );
|
AddClassProperty( L"orientation", &CEntity::m_orientation, false, static_cast<NotifyFn>(&CEntity::Reorient) );
|
||||||
AddClassProperty( L"player", (GetFn)&CEntity::JSI_GetPlayer, (SetFn)&CEntity::JSI_SetPlayer );
|
AddClassProperty( L"player", static_cast<GetFn>(&CEntity::JSI_GetPlayer), static_cast<SetFn>(&CEntity::JSI_SetPlayer) );
|
||||||
AddClassProperty( L"traits.health.curr", &CEntity::m_healthCurr );
|
AddClassProperty( L"traits.health.curr", &CEntity::m_healthCurr );
|
||||||
AddClassProperty( L"traits.health.max", &CEntity::m_healthMax );
|
AddClassProperty( L"traits.health.max", &CEntity::m_healthMax );
|
||||||
AddClassProperty( L"traits.health.regenRate", &CEntity::m_healthRegenRate );
|
AddClassProperty( L"traits.health.regenRate", &CEntity::m_healthRegenRate );
|
||||||
@ -113,7 +115,7 @@ void CEntity::ScriptingInit()
|
|||||||
AddClassProperty( L"traits.stamina.max", &CEntity::m_staminaMax );
|
AddClassProperty( L"traits.stamina.max", &CEntity::m_staminaMax );
|
||||||
AddClassProperty( L"traits.rank.name", &CEntity::m_rankName );
|
AddClassProperty( L"traits.rank.name", &CEntity::m_rankName );
|
||||||
AddClassProperty( L"traits.vision.los", &CEntity::m_los );
|
AddClassProperty( L"traits.vision.los", &CEntity::m_los );
|
||||||
AddClassProperty( L"traits.ai.stance.curr", &CEntity::m_stanceName, false, (NotifyFn)&CEntity::StanceChanged );
|
AddClassProperty( L"traits.ai.stance.curr", &CEntity::m_stanceName, false, static_cast<NotifyFn>(&CEntity::StanceChanged) );
|
||||||
AddClassProperty( L"lastCombatTime", &CEntity::m_lastCombatTime );
|
AddClassProperty( L"lastCombatTime", &CEntity::m_lastCombatTime );
|
||||||
AddClassProperty( L"lastRunTime", &CEntity::m_lastRunTime );
|
AddClassProperty( L"lastRunTime", &CEntity::m_lastRunTime );
|
||||||
AddClassProperty( L"building", &CEntity::m_building );
|
AddClassProperty( L"building", &CEntity::m_building );
|
||||||
@ -208,7 +210,7 @@ JSBool CEntity::Construct( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsva
|
|||||||
|
|
||||||
// Script-bound methods
|
// Script-bound methods
|
||||||
|
|
||||||
jsval CEntity::ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
CStrW name( L"[object Entity: " + m_base->m_Tag + L"]" );
|
CStrW name( L"[object Entity: " + m_base->m_Tag + L"]" );
|
||||||
return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, name.utf16().c_str() ) ) );
|
return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, name.utf16().c_str() ) ) );
|
||||||
@ -267,7 +269,7 @@ bool CEntity::Order( JSContext* cx, uintN argc, jsval* argv, CEntityOrder::EOrde
|
|||||||
|
|
||||||
CEntity* target;
|
CEntity* target;
|
||||||
|
|
||||||
(int&)newOrder.m_type = orderCode;
|
newOrder.m_type = (CEntityOrder::EOrderType)orderCode;
|
||||||
|
|
||||||
switch( orderCode )
|
switch( orderCode )
|
||||||
{
|
{
|
||||||
@ -359,7 +361,7 @@ bool CEntity::Kill( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(arg
|
|||||||
return( true );
|
return( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntity::GetSpawnPoint( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
jsval_t CEntity::GetSpawnPoint( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
float spawn_clearance = 2.0f;
|
float spawn_clearance = 2.0f;
|
||||||
if( argc >= 1 )
|
if( argc >= 1 )
|
||||||
@ -501,7 +503,7 @@ jsval CEntity::GetSpawnPoint( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
|||||||
return( JSVAL_NULL );
|
return( JSVAL_NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntity::AddAura( JSContext* cx, uintN argc, jsval* argv )
|
jsval_t CEntity::AddAura( JSContext* cx, uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
debug_assert( argc >= 8 );
|
debug_assert( argc >= 8 );
|
||||||
debug_assert( JSVAL_IS_OBJECT(argv[7]) );
|
debug_assert( JSVAL_IS_OBJECT(argv[7]) );
|
||||||
@ -527,7 +529,7 @@ jsval CEntity::AddAura( JSContext* cx, uintN argc, jsval* argv )
|
|||||||
return JSVAL_VOID;
|
return JSVAL_VOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntity::RemoveAura( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
jsval_t CEntity::RemoveAura( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
debug_assert( argc >= 1 );
|
debug_assert( argc >= 1 );
|
||||||
CStrW name = ToPrimitive<CStrW>( argv[0] );
|
CStrW name = ToPrimitive<CStrW>( argv[0] );
|
||||||
@ -542,7 +544,7 @@ jsval CEntity::RemoveAura( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
|||||||
return JSVAL_VOID;
|
return JSVAL_VOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntity::SetActionParams( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
jsval_t CEntity::SetActionParams( JSContext* UNUSED(cx), uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
debug_assert( argc == 5 );
|
debug_assert( argc == 5 );
|
||||||
|
|
||||||
@ -563,7 +565,7 @@ bool CEntity::RequestNotification( JSContext* cx, uintN argc, jsval* argv )
|
|||||||
|
|
||||||
CEntityListener notify;
|
CEntityListener notify;
|
||||||
CEntity *target = ToNative<CEntity>( argv[0] );
|
CEntity *target = ToNative<CEntity>( argv[0] );
|
||||||
(int&)notify.m_type = ToPrimitive<int>( argv[1] );
|
notify.m_type = (CEntityListener::EType)ToPrimitive<int>( argv[1] );
|
||||||
bool tmpDestroyNotifiers = ToPrimitive<bool>( argv[2] );
|
bool tmpDestroyNotifiers = ToPrimitive<bool>( argv[2] );
|
||||||
entf_set_to(ENTF_DESTROY_NOTIFIERS, !ToPrimitive<bool>( argv[3] ));
|
entf_set_to(ENTF_DESTROY_NOTIFIERS, !ToPrimitive<bool>( argv[3] ));
|
||||||
|
|
||||||
@ -682,25 +684,25 @@ void CEntity::CheckListeners( int type, CEntity *target)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsval CEntity::DestroyAllNotifiers( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::DestroyAllNotifiers( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
DestroyAllNotifiers();
|
DestroyAllNotifiers();
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
jsval CEntity::DestroyNotifier( JSContext* cx, uintN argc, jsval* argv )
|
jsval_t CEntity::DestroyNotifier( JSContext* cx, uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
JSU_REQUIRE_PARAMS_CPP(1);
|
JSU_REQUIRE_PARAMS_CPP(1);
|
||||||
DestroyNotifier( ToNative<CEntity>( argv[0] ) );
|
DestroyNotifier( ToNative<CEntity>( argv[0] ) );
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntity::TriggerRun( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::TriggerRun( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
entf_set(ENTF_TRIGGER_RUN);
|
entf_set(ENTF_TRIGGER_RUN);
|
||||||
return JSVAL_VOID;
|
return JSVAL_VOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntity::SetRun( JSContext* cx, uintN argc, jsval* argv )
|
jsval_t CEntity::SetRun( JSContext* cx, uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
JSU_REQUIRE_PARAMS_CPP(1);
|
JSU_REQUIRE_PARAMS_CPP(1);
|
||||||
bool should_run = ToPrimitive<bool> ( argv[0] );
|
bool should_run = ToPrimitive<bool> ( argv[0] );
|
||||||
@ -708,44 +710,44 @@ jsval CEntity::SetRun( JSContext* cx, uintN argc, jsval* argv )
|
|||||||
entf_set_to(ENTF_IS_RUNNING, should_run);
|
entf_set_to(ENTF_IS_RUNNING, should_run);
|
||||||
return JSVAL_VOID;
|
return JSVAL_VOID;
|
||||||
}
|
}
|
||||||
jsval CEntity::GetRunState( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetRunState( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return BOOLEAN_TO_JSVAL( entf_get(ENTF_SHOULD_RUN) );
|
return BOOLEAN_TO_JSVAL( entf_get(ENTF_SHOULD_RUN) );
|
||||||
}
|
}
|
||||||
jsval CEntity::GetFormationPenalty( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetFormationPenalty( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( GetFormation()->GetBase()->GetPenalty() );
|
return ToJSVal( GetFormation()->GetBase()->GetPenalty() );
|
||||||
}
|
}
|
||||||
jsval CEntity::GetFormationPenaltyBase( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetFormationPenaltyBase( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( GetFormation()->GetBase()->GetPenaltyBase() );
|
return ToJSVal( GetFormation()->GetBase()->GetPenaltyBase() );
|
||||||
}
|
}
|
||||||
jsval CEntity::GetFormationPenaltyType( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetFormationPenaltyType( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( GetFormation()->GetBase()->GetPenaltyType() );
|
return ToJSVal( GetFormation()->GetBase()->GetPenaltyType() );
|
||||||
}
|
}
|
||||||
jsval CEntity::GetFormationPenaltyVal( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetFormationPenaltyVal( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( GetFormation()->GetBase()->GetPenaltyVal() );
|
return ToJSVal( GetFormation()->GetBase()->GetPenaltyVal() );
|
||||||
}
|
}
|
||||||
jsval CEntity::GetFormationBonus( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetFormationBonus( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( GetFormation()->GetBase()->GetBonus() );
|
return ToJSVal( GetFormation()->GetBase()->GetBonus() );
|
||||||
}
|
}
|
||||||
jsval CEntity::GetFormationBonusBase( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetFormationBonusBase( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( GetFormation()->GetBase()->GetBonusBase() );
|
return ToJSVal( GetFormation()->GetBase()->GetBonusBase() );
|
||||||
}
|
}
|
||||||
jsval CEntity::GetFormationBonusType( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetFormationBonusType( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( GetFormation()->GetBase()->GetBonusType() );
|
return ToJSVal( GetFormation()->GetBase()->GetBonusType() );
|
||||||
}
|
}
|
||||||
jsval CEntity::GetFormationBonusVal( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetFormationBonusVal( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( GetFormation()->GetBase()->GetBonusVal() );
|
return ToJSVal( GetFormation()->GetBase()->GetBonusVal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntity::RegisterDamage( JSContext* cx, uintN argc, jsval* argv )
|
jsval_t CEntity::RegisterDamage( JSContext* cx, uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
JSU_REQUIRE_PARAMS_CPP(1);
|
JSU_REQUIRE_PARAMS_CPP(1);
|
||||||
CEntity* inflictor = ToNative<CEntity>( argv[0] );
|
CEntity* inflictor = ToNative<CEntity>( argv[0] );
|
||||||
@ -759,7 +761,7 @@ jsval CEntity::RegisterDamage( JSContext* cx, uintN argc, jsval* argv )
|
|||||||
m_sectorValues[sector]=true;
|
m_sectorValues[sector]=true;
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
jsval CEntity::RegisterOrderChange( JSContext* cx, uintN argc, jsval* argv )
|
jsval_t CEntity::RegisterOrderChange( JSContext* cx, uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
JSU_REQUIRE_PARAMS_CPP(1);
|
JSU_REQUIRE_PARAMS_CPP(1);
|
||||||
CEntity* idleEntity = ToNative<CEntity>( argv[0] );
|
CEntity* idleEntity = ToNative<CEntity>( argv[0] );
|
||||||
@ -774,7 +776,7 @@ jsval CEntity::RegisterOrderChange( JSContext* cx, uintN argc, jsval* argv )
|
|||||||
m_sectorValues[sector]=false;
|
m_sectorValues[sector]=false;
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
jsval CEntity::GetAttackDirections( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetAttackDirections( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
int directions=0;
|
int directions=0;
|
||||||
|
|
||||||
@ -785,7 +787,7 @@ jsval CEntity::GetAttackDirections( JSContext* UNUSED(cx), uintN UNUSED(argc), j
|
|||||||
}
|
}
|
||||||
return ToJSVal( directions );
|
return ToJSVal( directions );
|
||||||
}
|
}
|
||||||
jsval CEntity::FindSector( JSContext* cx, uintN argc, jsval* argv )
|
jsval_t CEntity::FindSector( JSContext* cx, uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
JSU_REQUIRE_PARAMS_CPP(4);
|
JSU_REQUIRE_PARAMS_CPP(4);
|
||||||
|
|
||||||
@ -804,15 +806,15 @@ jsval CEntity::FindSector( JSContext* cx, uintN argc, jsval* argv )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsval CEntity::HasRallyPoint( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::HasRallyPoint( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( entf_get(ENTF_HAS_RALLY_POINT) );
|
return ToJSVal( entf_get(ENTF_HAS_RALLY_POINT) );
|
||||||
}
|
}
|
||||||
jsval CEntity::GetRallyPoint( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetRallyPoint( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( m_rallyPoint );
|
return ToJSVal( m_rallyPoint );
|
||||||
}
|
}
|
||||||
jsval CEntity::SetRallyPoint( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::SetRallyPoint( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
entf_set(ENTF_HAS_RALLY_POINT);
|
entf_set(ENTF_HAS_RALLY_POINT);
|
||||||
m_rallyPoint = g_Game->GetView()->GetCamera()->GetWorldCoordinates(true);
|
m_rallyPoint = g_Game->GetView()->GetCamera()->GetWorldCoordinates(true);
|
||||||
@ -820,7 +822,7 @@ jsval CEntity::SetRallyPoint( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Called by the script when the entity is damaged, to let it retaliate
|
// Called by the script when the entity is damaged, to let it retaliate
|
||||||
jsval CEntity::OnDamaged( JSContext* cx, uintN argc, jsval* argv )
|
jsval_t CEntity::OnDamaged( JSContext* cx, uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
JSU_REQUIRE_PARAMS_CPP(1);
|
JSU_REQUIRE_PARAMS_CPP(1);
|
||||||
CEntity* damageSource = ToNative<CEntity>( argv[0] );
|
CEntity* damageSource = ToNative<CEntity>( argv[0] );
|
||||||
@ -828,7 +830,7 @@ jsval CEntity::OnDamaged( JSContext* cx, uintN argc, jsval* argv )
|
|||||||
return JSVAL_VOID;
|
return JSVAL_VOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntity::GetVisibleEntities( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::GetVisibleEntities( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
std::vector<CEntity*> pointers;
|
std::vector<CEntity*> pointers;
|
||||||
g_EntityManager.GetInLOS( this, pointers );
|
g_EntityManager.GetInLOS( this, pointers );
|
||||||
@ -870,7 +872,7 @@ int CEntity::GetAttackAction( HEntity target )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntity::FlattenTerrain( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
jsval_t CEntity::FlattenTerrain( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
float xDiff, yDiff;
|
float xDiff, yDiff;
|
||||||
CVector3D pos = m_position;
|
CVector3D pos = m_position;
|
||||||
|
@ -407,9 +407,9 @@ void CEntityTemplate::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElem
|
|||||||
|
|
||||||
void CEntityTemplate::ScriptingInit()
|
void CEntityTemplate::ScriptingInit()
|
||||||
{
|
{
|
||||||
AddMethod<jsval, &CEntityTemplate::ToString>( "toString", 0 );
|
AddMethod<CStr, &CEntityTemplate::ToString>( "toString", 0 );
|
||||||
|
|
||||||
AddClassProperty( L"traits.id.classes", (GetFn)&CEntityTemplate::GetClassSet, (SetFn)&CEntityTemplate::SetClassSet );
|
AddClassProperty( L"traits.id.classes", static_cast<GetFn>(&CEntityTemplate::GetClassSet), static_cast<SetFn>(&CEntityTemplate::SetClassSet) );
|
||||||
|
|
||||||
AddClassProperty( L"actions.move.speed", &CEntityTemplate::m_speed );
|
AddClassProperty( L"actions.move.speed", &CEntityTemplate::m_speed );
|
||||||
AddClassProperty( L"actions.move.turningRadius", &CEntityTemplate::m_turningRadius );
|
AddClassProperty( L"actions.move.turningRadius", &CEntityTemplate::m_turningRadius );
|
||||||
@ -420,8 +420,8 @@ void CEntityTemplate::ScriptingInit()
|
|||||||
AddClassProperty( L"actions.move.run.decayRate", &CEntityTemplate::m_runDecayRate );
|
AddClassProperty( L"actions.move.run.decayRate", &CEntityTemplate::m_runDecayRate );
|
||||||
AddClassProperty( L"actions.move.passThroughAllies", &CEntityTemplate::m_passThroughAllies );
|
AddClassProperty( L"actions.move.passThroughAllies", &CEntityTemplate::m_passThroughAllies );
|
||||||
AddClassProperty( L"actor", &CEntityTemplate::m_actorName );
|
AddClassProperty( L"actor", &CEntityTemplate::m_actorName );
|
||||||
AddClassProperty( L"traits.health.max", &CEntityTemplate::m_healthMax );
|
AddClassProperty( L"traits.health.max", &CEntityTemplate::m_healthMax );
|
||||||
AddClassProperty( L"traits.health.barHeight", &CEntityTemplate::m_healthBarHeight );
|
AddClassProperty( L"traits.health.barHeight", &CEntityTemplate::m_healthBarHeight );
|
||||||
AddClassProperty( L"traits.health.barSize", &CEntityTemplate::m_healthBarSize );
|
AddClassProperty( L"traits.health.barSize", &CEntityTemplate::m_healthBarSize );
|
||||||
AddClassProperty( L"traits.health.barWidth", &CEntityTemplate::m_healthBarWidth );
|
AddClassProperty( L"traits.health.barWidth", &CEntityTemplate::m_healthBarWidth );
|
||||||
AddClassProperty( L"traits.health.borderHeight", &CEntityTemplate::m_healthBorderHeight);
|
AddClassProperty( L"traits.health.borderHeight", &CEntityTemplate::m_healthBorderHeight);
|
||||||
@ -430,8 +430,8 @@ void CEntityTemplate::ScriptingInit()
|
|||||||
AddClassProperty( L"traits.health.regenRate", &CEntityTemplate::m_healthRegenRate );
|
AddClassProperty( L"traits.health.regenRate", &CEntityTemplate::m_healthRegenRate );
|
||||||
AddClassProperty( L"traits.health.regenStart", &CEntityTemplate::m_healthRegenStart );
|
AddClassProperty( L"traits.health.regenStart", &CEntityTemplate::m_healthRegenStart );
|
||||||
AddClassProperty( L"traits.health.decayRate", &CEntityTemplate::m_healthDecayRate );
|
AddClassProperty( L"traits.health.decayRate", &CEntityTemplate::m_healthDecayRate );
|
||||||
AddClassProperty( L"traits.stamina.max", &CEntityTemplate::m_staminaMax );
|
AddClassProperty( L"traits.stamina.max", &CEntityTemplate::m_staminaMax );
|
||||||
AddClassProperty( L"traits.stamina.barHeight", &CEntityTemplate::m_staminaBarHeight );
|
AddClassProperty( L"traits.stamina.barHeight", &CEntityTemplate::m_staminaBarHeight );
|
||||||
AddClassProperty( L"traits.stamina.barSize", &CEntityTemplate::m_staminaBarSize );
|
AddClassProperty( L"traits.stamina.barSize", &CEntityTemplate::m_staminaBarSize );
|
||||||
AddClassProperty( L"traits.stamina.barWidth", &CEntityTemplate::m_staminaBarWidth );
|
AddClassProperty( L"traits.stamina.barWidth", &CEntityTemplate::m_staminaBarWidth );
|
||||||
AddClassProperty( L"traits.stamina.borderHeight", &CEntityTemplate::m_staminaBorderHeight);
|
AddClassProperty( L"traits.stamina.borderHeight", &CEntityTemplate::m_staminaBorderHeight);
|
||||||
@ -477,14 +477,10 @@ JSObject* CEntityTemplate::GetScriptExecContext( IEventTarget* target )
|
|||||||
return( target->GetScriptExecContext( target ) );
|
return( target->GetScriptExecContext( target ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CEntityTemplate::ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) )
|
CStr CEntityTemplate::ToString( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
wchar_t buffer[256];
|
|
||||||
if( m_player == 0 )
|
if( m_player == 0 )
|
||||||
swprintf( buffer, 256, L"[object EntityTemplate: %ls base]", m_Tag.c_str() );
|
return "[object EntityTemplate: " + CStr(m_Tag) + " base]";
|
||||||
else
|
else
|
||||||
swprintf( buffer, 256, L"[object EntityTemplate: %ls for player %d]", m_Tag.c_str(), m_player->GetPlayerID() );
|
return "[object EntityTemplate: " + CStr(m_Tag) + " for player " + CStr(m_player->GetPlayerID()) + "]";
|
||||||
buffer[255] = 0;
|
|
||||||
utf16string str16(buffer, buffer+wcslen(buffer));
|
|
||||||
return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) );
|
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ public:
|
|||||||
// Get script execution contexts - always run in the context of the entity that fired it.
|
// Get script execution contexts - always run in the context of the entity that fired it.
|
||||||
JSObject* GetScriptExecContext(IEventTarget* target);
|
JSObject* GetScriptExecContext(IEventTarget* target);
|
||||||
|
|
||||||
jsval ToString(JSContext* cx, uintN argc, jsval* argv);
|
CStr ToString(JSContext* cx, uintN argc, jsval* argv);
|
||||||
|
|
||||||
static void ScriptingInit();
|
static void ScriptingInit();
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ void CProductionItem::ScriptingInit()
|
|||||||
AddProperty(L"name", &CProductionItem::m_name, true);
|
AddProperty(L"name", &CProductionItem::m_name, true);
|
||||||
AddProperty(L"elapsedTime", &CProductionItem::m_elapsedTime, true);
|
AddProperty(L"elapsedTime", &CProductionItem::m_elapsedTime, true);
|
||||||
AddProperty(L"totalTime", &CProductionItem::m_totalTime, true);
|
AddProperty(L"totalTime", &CProductionItem::m_totalTime, true);
|
||||||
AddProperty(L"progress", (GetFn)&CProductionItem::JSI_GetProgress);
|
AddProperty(L"progress", static_cast<GetFn>(&CProductionItem::JSI_GetProgress));
|
||||||
CJSObject<CProductionItem>::ScriptingInit("ProductionItem");
|
CJSObject<CProductionItem>::ScriptingInit("ProductionItem");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,12 +103,12 @@ jsval CProductionQueue::JSI_GetLength( JSContext* UNUSED(cx) )
|
|||||||
return ToJSVal( (int) m_items.size() );
|
return ToJSVal( (int) m_items.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CProductionQueue::JSI_Get( JSContext* cx, uintN argc, jsval* argv )
|
jsval_t CProductionQueue::JSI_Get( JSContext* cx, uintN argc, jsval* argv )
|
||||||
{
|
{
|
||||||
debug_assert( argc == 1 );
|
debug_assert( argc == 1 );
|
||||||
debug_assert( JSVAL_IS_INT(argv[0]) );
|
debug_assert( JSVAL_IS_INT(argv[0]) );
|
||||||
|
|
||||||
int index = ToPrimitive<int>( argv[0] );
|
int index = ToPrimitive<int>( argv[0] );
|
||||||
|
|
||||||
if(index < 0 || index >= (int)m_items.size() )
|
if(index < 0 || index >= (int)m_items.size() )
|
||||||
{
|
{
|
||||||
@ -124,7 +124,7 @@ bool CProductionQueue::JSI_Cancel( JSContext* cx, uintN argc, jsval* argv )
|
|||||||
debug_assert( argc == 1 );
|
debug_assert( argc == 1 );
|
||||||
debug_assert( JSVAL_IS_INT(argv[0]) );
|
debug_assert( JSVAL_IS_INT(argv[0]) );
|
||||||
|
|
||||||
int index = ToPrimitive<int>( argv[0] );
|
int index = ToPrimitive<int>( argv[0] );
|
||||||
|
|
||||||
if(index < 0 || index >= (int)m_items.size() )
|
if(index < 0 || index >= (int)m_items.size() )
|
||||||
{
|
{
|
||||||
@ -141,8 +141,8 @@ bool CProductionQueue::JSI_Cancel( JSContext* cx, uintN argc, jsval* argv )
|
|||||||
|
|
||||||
void CProductionQueue::ScriptingInit()
|
void CProductionQueue::ScriptingInit()
|
||||||
{
|
{
|
||||||
AddProperty(L"length", (GetFn)&CProductionQueue::JSI_GetLength);
|
AddProperty(L"length", static_cast<GetFn>(&CProductionQueue::JSI_GetLength));
|
||||||
AddMethod<jsval, &CProductionQueue::JSI_Get>( "get", 1 );
|
AddMethod<jsval_t, &CProductionQueue::JSI_Get>( "get", 1 );
|
||||||
AddMethod<bool, &CProductionQueue::JSI_Cancel>( "cancel", 1 );
|
AddMethod<bool, &CProductionQueue::JSI_Cancel>( "cancel", 1 );
|
||||||
CJSObject<CProductionQueue>::ScriptingInit("ProductionQueue");
|
CJSObject<CProductionQueue>::ScriptingInit("ProductionQueue");
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
void CancelAll();
|
void CancelAll();
|
||||||
|
|
||||||
jsval JSI_GetLength( JSContext* cx );
|
jsval JSI_GetLength( JSContext* cx );
|
||||||
jsval JSI_Get( JSContext* cx, uintN argc, jsval* argv );
|
jsval_t JSI_Get( JSContext* cx, uintN argc, jsval* argv );
|
||||||
bool JSI_Cancel( JSContext* cx, uintN argc, jsval* argv );
|
bool JSI_Cancel( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
static void ScriptingInit();
|
static void ScriptingInit();
|
||||||
|
@ -419,23 +419,23 @@ void CTechnology::ScriptingInit()
|
|||||||
AddClassProperty(L"time", &CTechnology::m_ReqTime); //Techs may upgrade research time and cost of other techs
|
AddClassProperty(L"time", &CTechnology::m_ReqTime); //Techs may upgrade research time and cost of other techs
|
||||||
AddClassProperty(L"in_progress", &CTechnology::m_inProgress);
|
AddClassProperty(L"in_progress", &CTechnology::m_inProgress);
|
||||||
|
|
||||||
AddMethod<jsval, &CTechnology::ApplyEffects>( "applyEffects", 2 );
|
AddMethod<bool, &CTechnology::ApplyEffects>( "applyEffects", 2 );
|
||||||
AddMethod<jsval, &CTechnology::IsExcluded>( "isExcluded", 0 );
|
AddMethod<bool, &CTechnology::IsExcluded>( "isExcluded", 0 );
|
||||||
AddMethod<jsval, &CTechnology::IsValid>( "isValid", 0 );
|
AddMethod<bool, &CTechnology::IsValid>( "isValid", 0 );
|
||||||
AddMethod<jsval, &CTechnology::IsResearched>( "isResearched", 0 );
|
AddMethod<bool, &CTechnology::IsResearched>( "isResearched", 0 );
|
||||||
AddMethod<jsval, &CTechnology::GetPlayerID>( "getPlayerID", 0 );
|
AddMethod<int, &CTechnology::GetPlayerID>( "getPlayerID", 0 );
|
||||||
|
|
||||||
CJSComplex<CTechnology>::ScriptingInit("Technology");
|
CJSComplex<CTechnology>::ScriptingInit("Technology");
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CTechnology::ApplyEffects( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
bool CTechnology::ApplyEffects( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
// Unmark ourselves as in progress
|
// Unmark ourselves as in progress
|
||||||
m_inProgress = false;
|
m_inProgress = false;
|
||||||
|
|
||||||
if ( !IsTechValid() )
|
if ( !IsTechValid() )
|
||||||
{
|
{
|
||||||
return JSVAL_FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable any paired techs
|
// Disable any paired techs
|
||||||
@ -467,27 +467,27 @@ jsval CTechnology::ApplyEffects( JSContext* UNUSED(cx), uintN UNUSED(argc), jsva
|
|||||||
// Add ourselves to player's researched techs
|
// Add ourselves to player's researched techs
|
||||||
m_player->AddActiveTech( this );
|
m_player->AddActiveTech( this );
|
||||||
|
|
||||||
return JSVAL_TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CTechnology::IsValid( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
bool CTechnology::IsValid( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( IsTechValid() );
|
return IsTechValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CTechnology::IsExcluded( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
bool CTechnology::IsExcluded( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( m_excluded );
|
return m_excluded;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CTechnology::IsResearched( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
bool CTechnology::IsResearched( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( IsResearched() );
|
return IsResearched();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline jsval CTechnology::GetPlayerID( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
int CTechnology::GetPlayerID( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||||
{
|
{
|
||||||
return ToJSVal( m_player->GetPlayerID() );
|
return m_player->GetPlayerID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,11 +42,11 @@ public:
|
|||||||
|
|
||||||
//JS functions
|
//JS functions
|
||||||
static void ScriptingInit();
|
static void ScriptingInit();
|
||||||
jsval ApplyEffects( JSContext* cx, uintN argc, jsval* argv );
|
bool ApplyEffects( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval IsValid( JSContext* cx, uintN argc, jsval* argv );
|
bool IsValid( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval IsResearched( JSContext* cx, uintN argc, jsval* argv );
|
bool IsResearched( JSContext* cx, uintN argc, jsval* argv );
|
||||||
jsval IsExcluded( JSContext* cx, uintN argc, jsval* argv );
|
bool IsExcluded( JSContext* cx, uintN argc, jsval* argv );
|
||||||
inline jsval GetPlayerID( JSContext* cx, uintN argc, jsval* argv );
|
int GetPlayerID( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
void Apply( CEntity* entity );
|
void Apply( CEntity* entity );
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ void CTrigger::ScriptingInit()
|
|||||||
AddProperty<int>(L"maxRunCount", &CTrigger::m_maxRunCount);
|
AddProperty<int>(L"maxRunCount", &CTrigger::m_maxRunCount);
|
||||||
AddProperty<float>(L"timeDelay", &CTrigger::m_timeDelay);
|
AddProperty<float>(L"timeDelay", &CTrigger::m_timeDelay);
|
||||||
|
|
||||||
AddMethod<jsval, &CTrigger::Activate>( "activate", 0 );
|
AddMethod<void, &CTrigger::Activate>( "activate", 0 );
|
||||||
AddMethod<jsval, &CTrigger::Deactivate>( "deactivate", 0 );
|
AddMethod<void, &CTrigger::Deactivate>( "deactivate", 0 );
|
||||||
|
|
||||||
CJSObject<CTrigger>::ScriptingInit("Trigger", CTrigger::Construct, 6);
|
CJSObject<CTrigger>::ScriptingInit("Trigger", CTrigger::Construct, 6);
|
||||||
}
|
}
|
||||||
@ -103,15 +103,13 @@ bool CTrigger::Fire()
|
|||||||
return (m_runCount < m_maxRunCount);
|
return (m_runCount < m_maxRunCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CTrigger::Activate(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* UNUSED(argv))
|
void CTrigger::Activate(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* UNUSED(argv))
|
||||||
{
|
{
|
||||||
m_active = true;
|
m_active = true;
|
||||||
return JS_TRUE;
|
|
||||||
}
|
}
|
||||||
jsval CTrigger::Deactivate(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* UNUSED(argv))
|
void CTrigger::Deactivate(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* UNUSED(argv))
|
||||||
{
|
{
|
||||||
m_active = false;
|
m_active = false;
|
||||||
return JS_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,8 +115,8 @@ public:
|
|||||||
//Returns false if trigger exceeds run count
|
//Returns false if trigger exceeds run count
|
||||||
bool Fire();
|
bool Fire();
|
||||||
|
|
||||||
jsval Activate(JSContext* cx, uint argc, jsval* argv);
|
void Activate(JSContext* cx, uint argc, jsval* argv);
|
||||||
jsval Deactivate(JSContext* cx, uint argc, jsval* argv);
|
void Deactivate(JSContext* cx, uint argc, jsval* argv);
|
||||||
|
|
||||||
static JSBool Construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
|
static JSBool Construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
|
||||||
static void ScriptingInit();
|
static void ScriptingInit();
|
||||||
|
@ -154,7 +154,7 @@ bool JSI_Sound::Free(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(ar
|
|||||||
|
|
||||||
void JSI_Sound::ScriptingInit()
|
void JSI_Sound::ScriptingInit()
|
||||||
{
|
{
|
||||||
AddMethod<jsval, &JSI_Sound::ToString>("toString", 0);
|
AddMethod<CStr, &JSI_Sound::ToString>("toString", 0);
|
||||||
AddMethod<bool, &JSI_Sound::Play>("play", 0);
|
AddMethod<bool, &JSI_Sound::Play>("play", 0);
|
||||||
AddMethod<bool, &JSI_Sound::Loop>("loop", 0);
|
AddMethod<bool, &JSI_Sound::Loop>("loop", 0);
|
||||||
AddMethod<bool, &JSI_Sound::Free>("free", 0);
|
AddMethod<bool, &JSI_Sound::Free>("free", 0);
|
||||||
@ -166,10 +166,9 @@ void JSI_Sound::ScriptingInit()
|
|||||||
CJSObject<JSI_Sound>::ScriptingInit("Sound", &JSI_Sound::Construct, 1);
|
CJSObject<JSI_Sound>::ScriptingInit("Sound", &JSI_Sound::Construct, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval JSI_Sound::ToString(JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv))
|
CStr JSI_Sound::ToString(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
|
||||||
{
|
{
|
||||||
CStr name = "[object Sound: " + CStr(h_filename(m_Handle)) + "]";
|
return "[object Sound: " + CStr(h_filename(m_Handle)) + "]";
|
||||||
return STRING_TO_JSVAL(JS_NewStringCopyZ(cx, name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Sound::Construct(JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval)
|
JSBool JSI_Sound::Construct(JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval)
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
|
|
||||||
// Script-bound functions
|
// Script-bound functions
|
||||||
|
|
||||||
jsval ToString( JSContext* cx, uintN argc, jsval* argv );
|
CStr ToString( JSContext* cx, uintN argc, jsval* argv );
|
||||||
|
|
||||||
// start playing the sound (one-shot).
|
// start playing the sound (one-shot).
|
||||||
// it will automatically be freed when done.
|
// it will automatically be freed when done.
|
||||||
|
Loading…
Reference in New Issue
Block a user