mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-10-09 08:21:10 +00:00
# Updates to techs.
- Added name and player JS properties for use in scripts. - Remoed IsJSFirst since it doesn't make much sense for techs that also apply to newly created units. This was SVN commit r4154.
This commit is contained in:
@@ -16,13 +16,12 @@
|
||||
|
||||
STL_HASH_SET<CStr, CStr_hash_compare> CTechnology::m_scriptsLoaded;
|
||||
|
||||
CTechnology::CTechnology( CPlayer* player ) : m_player(player)
|
||||
CTechnology::CTechnology( const CStrW& name, CPlayer* player ) : m_Name(name), m_player(player)
|
||||
{
|
||||
ONCE( ScriptingInit(); );
|
||||
|
||||
m_researched=false;
|
||||
m_excluded = false;
|
||||
m_JSFirst = false;
|
||||
m_inProgress = false;
|
||||
}
|
||||
bool CTechnology::loadXML( const CStr& filename )
|
||||
@@ -89,7 +88,7 @@ bool CTechnology::loadELID( XMBElement ID, CXeromyces& XeroFile )
|
||||
{
|
||||
XMBElement element = children.item(i);
|
||||
int name = element.getNodeName();
|
||||
CStr value = CStr(element.getText());
|
||||
CStrW value = element.getText();
|
||||
|
||||
if ( name == el_generic )
|
||||
m_Generic = value;
|
||||
@@ -134,7 +133,7 @@ bool CTechnology::loadELReq( XMBElement Req, CXeromyces& XeroFile )
|
||||
{
|
||||
XMBElement element = children.item(i);
|
||||
int name = element.getNodeName();
|
||||
CStr value = element.getText();
|
||||
CStrW value = element.getText();
|
||||
|
||||
if ( name == el_time )
|
||||
m_ReqTime = value.ToFloat();
|
||||
@@ -145,7 +144,7 @@ bool CTechnology::loadELReq( XMBElement Req, CXeromyces& XeroFile )
|
||||
{
|
||||
XMBElement resElement = resChildren.item(j);
|
||||
int resName = resElement.getNodeName();
|
||||
CStr resValue = CStr(resElement.getText());
|
||||
CStrW resValue = resElement.getText();
|
||||
|
||||
if ( resName == el_food ) //NOT LOADED-GET CHILD NODES
|
||||
m_ReqFood = resValue.ToFloat();
|
||||
@@ -190,7 +189,6 @@ bool CTechnology::loadELEffect( XMBElement effect, CXeromyces& XeroFile, const C
|
||||
EL(script);
|
||||
EL(function);
|
||||
AT(name);
|
||||
AT(order);
|
||||
AT(file);
|
||||
|
||||
#undef EL
|
||||
@@ -215,7 +213,7 @@ bool CTechnology::loadELEffect( XMBElement effect, CXeromyces& XeroFile, const C
|
||||
for ( int j=0; j<modChildren.Count; ++j )
|
||||
{
|
||||
XMBElement modElement = modChildren.item(j);
|
||||
CStr modValue = CStr(modElement.getText());
|
||||
CStrW modValue = modElement.getText();
|
||||
|
||||
if ( modElement.getNodeName() == el_attribute)
|
||||
m_Modifiers.back().attribute = modValue;
|
||||
@@ -237,7 +235,7 @@ bool CTechnology::loadELEffect( XMBElement effect, CXeromyces& XeroFile, const C
|
||||
for ( int j=0; j<setChildren.Count; ++j )
|
||||
{
|
||||
XMBElement setElement = setChildren.item(j);
|
||||
CStr setValue = CStr(setElement.getText());
|
||||
CStrW setValue = setElement.getText();
|
||||
|
||||
if ( setElement.getNodeName() == el_attribute)
|
||||
m_Sets.back().attribute = setValue;
|
||||
@@ -270,8 +268,6 @@ bool CTechnology::loadELEffect( XMBElement effect, CXeromyces& XeroFile, const C
|
||||
{
|
||||
utf16string funcName = element.getAttributes().getNamedItem( at_name );
|
||||
CStr Inline = element.getText();
|
||||
//default to first
|
||||
m_JSFirst = (utf16string() == element.getAttributes().getNamedItem( at_order ));
|
||||
|
||||
if ( funcName != utf16string() )
|
||||
{
|
||||
@@ -385,6 +381,8 @@ void CTechnology::apply( CEntity* entity )
|
||||
|
||||
void CTechnology::ScriptingInit()
|
||||
{
|
||||
AddProperty(L"name", &CTechnology::m_Name, true);
|
||||
AddProperty(L"player", &CTechnology::m_player, true);
|
||||
AddProperty(L"generic", &CTechnology::m_Generic, true);
|
||||
AddProperty(L"specific", &CTechnology::m_Specific, true);
|
||||
AddProperty(L"icon", &CTechnology::m_Icon); //GUI might want to change this...?
|
||||
@@ -404,7 +402,6 @@ void CTechnology::ScriptingInit()
|
||||
AddMethod<jsval, &CTechnology::IsValid>( "isValid", 0 );
|
||||
AddMethod<jsval, &CTechnology::IsResearched>( "isResearched", 0 );
|
||||
AddMethod<jsval, &CTechnology::GetPlayerID>( "getPlayerID", 0 );
|
||||
AddMethod<jsval, &CTechnology::IsJSFirst>( "isJSFirst", 0 );
|
||||
|
||||
CJSObject<CTechnology>::ScriptingInit("Technology");
|
||||
|
||||
@@ -468,11 +465,6 @@ inline jsval CTechnology::GetPlayerID( JSContext* UNUSED(cx), uintN UNUSED(argc)
|
||||
return ToJSVal( m_player->GetPlayerID() );
|
||||
}
|
||||
|
||||
jsval CTechnology::IsJSFirst( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
|
||||
{
|
||||
return ToJSVal( m_JSFirst );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class CTechnology : public CJSObject<CTechnology>
|
||||
static STL_HASH_SET<CStr, CStr_hash_compare> m_scriptsLoaded;
|
||||
|
||||
public:
|
||||
CTechnology(CPlayer* player);
|
||||
CTechnology(const CStrW& name, CPlayer* player);
|
||||
~CTechnology() {}
|
||||
|
||||
//JS functions
|
||||
@@ -35,7 +35,6 @@ public:
|
||||
jsval ApplyEffects( JSContext* cx, uintN argc, jsval* argv );
|
||||
jsval IsValid( JSContext* cx, uintN argc, jsval* argv );
|
||||
jsval IsResearched( JSContext* cx, uintN argc, jsval* argv );
|
||||
jsval IsJSFirst( JSContext* cx, uintN argc, jsval* argv );
|
||||
jsval IsExcluded( JSContext* cx, uintN argc, jsval* argv );
|
||||
inline jsval GetPlayerID( JSContext* cx, uintN argc, jsval* argv );
|
||||
|
||||
@@ -52,13 +51,15 @@ public:
|
||||
bool loadELEffect( XMBElement Effect, CXeromyces& XeroFile, const CStr& filename );
|
||||
|
||||
private:
|
||||
CStr m_Generic;
|
||||
CStr m_Specific;
|
||||
CStrW m_Name; // name of the tech file
|
||||
|
||||
CStr m_Icon;
|
||||
CStrW m_Generic;
|
||||
CStrW m_Specific;
|
||||
|
||||
CStrW m_Icon;
|
||||
int m_IconCell;
|
||||
CStr m_Classes;
|
||||
CStr m_History;
|
||||
CStrW m_Classes;
|
||||
CStrW m_History;
|
||||
|
||||
float m_ReqTime;
|
||||
float m_ReqWood;
|
||||
@@ -74,9 +75,8 @@ private:
|
||||
std::vector<Modifier> m_Sets;
|
||||
|
||||
CPlayer* m_player; //Which player this tech belongs to
|
||||
|
||||
CScriptObject m_effectFunction;
|
||||
|
||||
bool m_JSFirst; //Should JS effect function run before C++
|
||||
|
||||
bool m_excluded;
|
||||
bool m_researched;
|
||||
|
||||
@@ -48,7 +48,7 @@ CTechnology* CTechnologyCollection::getTechnology( const CStrW& name, CPlayer* p
|
||||
CStr path( filename_it->second );
|
||||
|
||||
//Try to load to the tech
|
||||
CTechnology* newTemplate = new CTechnology( player );
|
||||
CTechnology* newTemplate = new CTechnology( name, player );
|
||||
if( !newTemplate->loadXML( path ) )
|
||||
{
|
||||
LOG(ERROR, LOG_CATEGORY, "CTechnologyCollection::getTechnology(): Couldn't load tech \"%s\"", path.c_str());
|
||||
|
||||
Reference in New Issue
Block a user