diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index d2dab80a68..3964e95c9d 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -49,6 +49,7 @@ #include "simulation/BaseEntityCollection.h" #include "simulation/BaseFormationCollection.h" +#include "simulation/BaseTechCollection.h" #include "simulation/Entity.h" #include "simulation/EntityHandles.h" #include "simulation/EntityManager.h" @@ -1017,7 +1018,9 @@ void Init(int argc, char* argv[], uint flags) // This needs to be done after the renderer has loaded all its actors... new CBaseEntityCollection; new CBaseFormationCollection; + new CBaseTechCollection; g_EntityFormationCollection.loadTemplates(); + g_BaseTechCollection.loadTemplates(); new CFormationManager; // CEntityManager is managed by CWorld diff --git a/source/scripting/ScriptGlue.cpp b/source/scripting/ScriptGlue.cpp index a7336196c4..5382b2f163 100644 --- a/source/scripting/ScriptGlue.cpp +++ b/source/scripting/ScriptGlue.cpp @@ -338,7 +338,7 @@ JSBool getTechTemplate( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* CStrW name = ToPrimitive( argv[0] ); PS_uint playerID = (PS_uint)ToPrimitive( argv[1] ); - rval = JSVAL_NULL; + *rval = JSVAL_NULL; if ( g_Game->GetPlayer(playerID) ) { @@ -347,10 +347,12 @@ JSBool getTechTemplate( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* if ( tech ) { tech->setPlayer( g_Game->GetPlayer(playerID) ); - *rval = OBJECT_TO_JSVAL(tech->GetScript()); + //*rval = OBJECT_TO_JSVAL(tech->GetScript()); + *rval = ToJSVal( tech ); + //*rval = ToJSVal( 42 ); } else - JS_ReportError(cx, "Invalid tech template name \"%s\" passed for getTechTemplate()", name.c_str() ); + JS_ReportError(cx, "Invalid tech template name \"%ls\" passed for getTechTemplate()", name.c_str() ); } else JS_ReportError(cx, "Invalid playerID \"%d\"passed for getTechTemplate()", playerID); diff --git a/source/simulation/BaseTech.cpp b/source/simulation/BaseTech.cpp index 3ed71ed215..99c8892573 100644 --- a/source/simulation/BaseTech.cpp +++ b/source/simulation/BaseTech.cpp @@ -14,24 +14,11 @@ STL_HASH_SET CBaseTech::m_scriptsLoaded; CBaseTech::CBaseTech() { + ONCE( ScriptingInit(); ); + m_researched = m_excluded=false; - AddProperty(L"generic", &CBaseTech::m_Generic, true); - AddProperty(L"specific", &CBaseTech::m_Specific, true); - AddProperty(L"icon", &CBaseTech::m_Icon); //GUI might want to change this...? - AddProperty(L"icon_cell", &CBaseTech::m_IconCell); - AddProperty(L"classes", &CBaseTech::m_Classes, true); - AddProperty(L"history", &CBaseTech::m_History, true); - - AddProperty(L"time", &CBaseTech::m_ReqTime); //Techs may upgrade research time and cost of other techs - AddProperty(L"food", &CBaseTech::m_ReqFood); - AddProperty(L"wood", &CBaseTech::m_ReqWood); - AddProperty(L"stone", &CBaseTech::m_ReqStone); - AddProperty(L"ore", &CBaseTech::m_ReqOre); - m_effectFunction = NULL; m_JSFirst = false; - - ONCE( ScriptingInit() ); } bool CBaseTech::loadXML( CStr filename ) { @@ -368,6 +355,19 @@ bool CBaseTech::hasReqTechs() void CBaseTech::ScriptingInit() { + AddProperty(L"generic", &CBaseTech::m_Generic, true); + AddProperty(L"specific", &CBaseTech::m_Specific, true); + AddProperty(L"icon", &CBaseTech::m_Icon); //GUI might want to change this...? + AddProperty(L"icon_cell", &CBaseTech::m_IconCell); + AddProperty(L"classes", &CBaseTech::m_Classes, true); + AddProperty(L"history", &CBaseTech::m_History, true); + + AddProperty(L"time", &CBaseTech::m_ReqTime); //Techs may upgrade research time and cost of other techs + AddProperty(L"food", &CBaseTech::m_ReqFood); + AddProperty(L"wood", &CBaseTech::m_ReqWood); + AddProperty(L"stone", &CBaseTech::m_ReqStone); + AddProperty(L"ore", &CBaseTech::m_ReqOre); + AddMethod( "applyEffects", 1 ); AddMethod( "isExcluded", 0 ); AddMethod( "isValid", 0 ); @@ -376,6 +376,8 @@ void CBaseTech::ScriptingInit() AddMethod( "isJSFirst", 0 ); CJSObject::ScriptingInit("TechTemplate"); + + debug_printf("CBaseTech::ScriptingInit complete"); } jsval CBaseTech::ApplyEffects( JSContext* cx, uintN argc, jsval* argv ) diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 6be5401697..e4d8a82bca 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -36,6 +36,11 @@ std::map CEntity::m_AttributeTable; CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation, const std::set& actorSelections, CStrW building ) { + if(m_AttributeTable.size() == 0) // not nice + { + initAttributes(this); + } + m_position = position; m_orientation.Y = orientation; m_ahead.x = sin( m_orientation.Y );