Some fixes for techs.

This was SVN commit r3954.
This commit is contained in:
Matei 2006-06-07 01:04:41 +00:00
parent b631ac6007
commit 40f29a8345
4 changed files with 30 additions and 18 deletions

View File

@ -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

View File

@ -338,7 +338,7 @@ JSBool getTechTemplate( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval*
CStrW name = ToPrimitive<CStrW>( argv[0] );
PS_uint playerID = (PS_uint)ToPrimitive<int>( 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);

View File

@ -14,24 +14,11 @@ STL_HASH_SET<CStr, CStr_hash_compare> 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<int>(L"icon_cell", &CBaseTech::m_IconCell);
AddProperty(L"classes", &CBaseTech::m_Classes, true);
AddProperty(L"history", &CBaseTech::m_History, true);
AddProperty<float>(L"time", &CBaseTech::m_ReqTime); //Techs may upgrade research time and cost of other techs
AddProperty<float>(L"food", &CBaseTech::m_ReqFood);
AddProperty<float>(L"wood", &CBaseTech::m_ReqWood);
AddProperty<float>(L"stone", &CBaseTech::m_ReqStone);
AddProperty<float>(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<int>(L"icon_cell", &CBaseTech::m_IconCell);
AddProperty(L"classes", &CBaseTech::m_Classes, true);
AddProperty(L"history", &CBaseTech::m_History, true);
AddProperty<float>(L"time", &CBaseTech::m_ReqTime); //Techs may upgrade research time and cost of other techs
AddProperty<float>(L"food", &CBaseTech::m_ReqFood);
AddProperty<float>(L"wood", &CBaseTech::m_ReqWood);
AddProperty<float>(L"stone", &CBaseTech::m_ReqStone);
AddProperty<float>(L"ore", &CBaseTech::m_ReqOre);
AddMethod<jsval, &CBaseTech::ApplyEffects>( "applyEffects", 1 );
AddMethod<jsval, &CBaseTech::IsExcluded>( "isExcluded", 0 );
AddMethod<jsval, &CBaseTech::IsValid>( "isValid", 0 );
@ -376,6 +376,8 @@ void CBaseTech::ScriptingInit()
AddMethod<jsval, &CBaseTech::IsJSFirst>( "isJSFirst", 0 );
CJSObject<CBaseTech>::ScriptingInit("TechTemplate");
debug_printf("CBaseTech::ScriptingInit complete");
}
jsval CBaseTech::ApplyEffects( JSContext* cx, uintN argc, jsval* argv )

View File

@ -36,6 +36,11 @@ std::map<CStr, size_t> CEntity::m_AttributeTable;
CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation, const std::set<CStrW>& 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 );