summaryrefslogtreecommitdiffstats
path: root/src/script/script.cpp
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2013-05-18 16:44:22 +0200
committerkrzys-h <krzys_h@interia.pl>2013-05-18 18:04:48 +0200
commit47d7b805070e317894efbed653b1d44cd789f2fa (patch)
treefeb09d4dd408f53371b2fbd6fd2f8d37a70554a3 /src/script/script.cpp
parent07839a561fa876539484fdc44e68d3f17e20a89b (diff)
downloadcolobot-47d7b805070e317894efbed653b1d44cd789f2fa.tar.gz
colobot-47d7b805070e317894efbed653b1d44cd789f2fa.tar.bz2
colobot-47d7b805070e317894efbed653b1d44cd789f2fa.zip
Added object.factory(cat)
Diffstat (limited to 'src/script/script.cpp')
-rw-r--r--src/script/script.cpp165
1 files changed, 165 insertions, 0 deletions
diff --git a/src/script/script.cpp b/src/script/script.cpp
index 0d2238d..25a7e73 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -35,6 +35,9 @@
#include "object/task/taskmanager.h"
#include "object/objman.h"
+#include "object/auto/auto.h"
+#include "object/auto/autofactory.h"
+
#include "physics/physics.h"
#include "script/cbottoken.h"
@@ -78,6 +81,11 @@ CBotTypResult CScript::cOneFloat(CBotVar* &var, void* user)
return CBotTypResult(CBotTypFloat);
}
+CBotTypResult CScript::cClassOneFloat(CBotVar* thisclass, CBotVar* &var)
+{
+ return CScript::cOneFloat(var, nullptr);
+}
+
// Compiling a procedure with two real numbers.
CBotTypResult CScript::cTwoFloat(CBotVar* &var, void* user)
@@ -491,6 +499,163 @@ bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* us
return true;
}
+// Instruction "object.factory(cat)"
+
+bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception)
+{
+ Error err;
+
+ exception = 0;
+
+ CBotVar* classVars = thisclass->GetItemList(); // "category"
+ ObjectType thisType = static_cast<ObjectType>(classVars->GetValInt());
+ classVars = classVars->GetNext(); // "position"
+ classVars = classVars->GetNext(); // "orientation"
+ classVars = classVars->GetNext(); // "pitch"
+ classVars = classVars->GetNext(); // "roll"
+ classVars = classVars->GetNext(); // "energyLevel"
+ classVars = classVars->GetNext(); // "shieldLevel"
+ classVars = classVars->GetNext(); // "temperature"
+ classVars = classVars->GetNext(); // "altitude"
+ classVars = classVars->GetNext(); // "lifeTime"
+ classVars = classVars->GetNext(); // "material"
+ classVars = classVars->GetNext(); // "energyCell"
+ classVars = classVars->GetNext(); // "load"
+ classVars = classVars->GetNext(); // "id"
+ int rank = classVars->GetValInt();
+ CObject* factory = CObjectManager::GetInstancePointer()->SearchInstance(rank);
+ CAuto* automat = factory->GetAuto();
+
+ if ( thisType == OBJECT_FACTORY )
+ {
+ ObjectType type = static_cast<ObjectType>(var->GetValInt());
+ bool bEnable = false;
+
+ if ( type == OBJECT_MOBILEwa )
+ {
+ bEnable = true;
+ }
+ if ( type == OBJECT_MOBILEta )
+ {
+ bEnable = g_researchDone&RESEARCH_TANK;
+ }
+ if ( type == OBJECT_MOBILEfa )
+ {
+ bEnable = g_researchDone&RESEARCH_FLY;
+ }
+ if ( type == OBJECT_MOBILEia )
+ {
+ bEnable = g_researchDone&RESEARCH_iPAW;
+ }
+
+ if ( type == OBJECT_MOBILEws )
+ {
+ bEnable = g_researchDone&RESEARCH_SNIFFER;
+ }
+ if ( type == OBJECT_MOBILEts )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
+ (g_researchDone&RESEARCH_TANK) );
+ }
+ if ( type == OBJECT_MOBILEfs )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
+ (g_researchDone&RESEARCH_FLY) );
+ }
+ if ( type == OBJECT_MOBILEis )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
+ (g_researchDone&RESEARCH_iPAW) );
+ }
+
+ if ( type == OBJECT_MOBILEwc )
+ {
+ bEnable = g_researchDone&RESEARCH_CANON;
+ }
+ if ( type == OBJECT_MOBILEtc )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_CANON) &&
+ (g_researchDone&RESEARCH_TANK) );
+ }
+ if ( type == OBJECT_MOBILEfc )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_CANON) &&
+ (g_researchDone&RESEARCH_FLY) );
+ }
+ if ( type == OBJECT_MOBILEic )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_CANON) &&
+ (g_researchDone&RESEARCH_iPAW) );
+ }
+
+ if ( type == OBJECT_MOBILEwi )
+ {
+ bEnable = g_researchDone&RESEARCH_iGUN;
+ }
+ if ( type == OBJECT_MOBILEti )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
+ (g_researchDone&RESEARCH_TANK) );
+ }
+ if ( type == OBJECT_MOBILEfi )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
+ (g_researchDone&RESEARCH_FLY) );
+ }
+ if ( type == OBJECT_MOBILEii )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
+ (g_researchDone&RESEARCH_iPAW) );
+ }
+
+ if ( type == OBJECT_MOBILErt )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_THUMP) &&
+ (g_researchDone&RESEARCH_TANK) );
+ }
+ if ( type == OBJECT_MOBILErc )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_PHAZER) &&
+ (g_researchDone&RESEARCH_TANK) );
+ }
+ if ( type == OBJECT_MOBILErr )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_RECYCLER) &&
+ (g_researchDone&RESEARCH_TANK) );
+ }
+ if ( type == OBJECT_MOBILErs )
+ {
+ bEnable = ( (g_researchDone&RESEARCH_SHIELD) &&
+ (g_researchDone&RESEARCH_TANK) );
+ }
+
+ if ( type == OBJECT_MOBILEsa )
+ {
+ bEnable = g_researchDone&RESEARCH_SUBM;
+ }
+
+ if ( bEnable )
+ err = automat->StartAction(type);
+ else
+ err = ERR_BUILD_DISABLED;
+ } else
+ err = ERR_MANIP_VEH;
+
+ if ( err != ERR_OK )
+ {
+ result->SetValInt(err); // return error
+//TODO: if ( script->m_errMode == ERM_STOP )
+ if( true )
+ {
+ exception = err;
+ return false;
+ }
+ return true;
+ }
+
+ return true;
+}
+
// Compilation of the instruction "destroy(rank[, exploType[, force]])".
CBotTypResult CScript::cDestroy(CBotVar* &var, void* user)