2012-06-26 20:23:05 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
// *
|
|
|
|
// * This program is free software: you can redistribute it and/or modify
|
|
|
|
// * it under the terms of the GNU General Public License as published by
|
|
|
|
// * the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// * (at your option) any later version.
|
|
|
|
// *
|
|
|
|
// * This program is distributed in the hope that it will be useful,
|
|
|
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// * GNU General Public License for more details.
|
|
|
|
// *
|
|
|
|
// * You should have received a copy of the GNU General Public License
|
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
#include "script/script.h"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-10-06 22:46:46 +00:00
|
|
|
#include "app/app.h"
|
2012-10-17 19:55:45 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
#include "common/global.h"
|
|
|
|
#include "common/iman.h"
|
|
|
|
#include "common/restext.h"
|
2012-10-17 19:55:45 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
#include "graphics/engine/terrain.h"
|
|
|
|
#include "graphics/engine/water.h"
|
|
|
|
#include "graphics/engine/text.h"
|
2012-10-17 19:55:45 +00:00
|
|
|
|
2012-09-15 16:50:51 +00:00
|
|
|
#include "math/geometry.h"
|
|
|
|
#include "math/vector.h"
|
2012-10-17 19:55:45 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
#include "object/object.h"
|
2012-09-15 16:50:51 +00:00
|
|
|
#include "object/robotmain.h"
|
|
|
|
#include "object/task/taskmanager.h"
|
2012-10-17 19:55:45 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
#include "physics/physics.h"
|
2012-10-17 19:55:45 +00:00
|
|
|
|
2012-09-15 16:50:51 +00:00
|
|
|
#include "script/cbottoken.h"
|
2012-10-17 19:55:45 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
#include "ui/interface.h"
|
|
|
|
#include "ui/edit.h"
|
|
|
|
#include "ui/list.h"
|
|
|
|
#include "ui/displaytext.h"
|
2012-09-15 16:50:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int CBOT_IPF = 100; // CBOT: number of instructions / frame
|
|
|
|
|
|
|
|
const int ERM_CONT = 0; // if error -> continue
|
|
|
|
const int ERM_STOP = 1; // if error -> stop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compiling a procedure without any parameters.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cNull(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var != 0 ) return CBotErrOverParam;
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compiling a procedure with a single real number.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cOneFloat(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compiling a procedure with two real numbers.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cTwoFloat(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compiling a procedure with a "dot".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cPoint(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() <= CBotTypDouble )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
//? if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
//? if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
//? var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
return CBotTypResult(0);
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() == CBotTypClass )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( !var->IsElemOfClass("point") ) return CBotTypResult(CBotErrBadParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
return CBotTypResult(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CBotTypResult(CBotErrBadParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compiling a procedure with a single "point".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cOnePoint(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
|
|
|
ret = cPoint(var, user);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compiling a procedure with a single string.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cString(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() != CBotTypString &&
|
|
|
|
var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Seeking value in an array of integers.
|
|
|
|
|
|
|
|
bool FindList(CBotVar* array, int type)
|
|
|
|
{
|
|
|
|
while ( array != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( type == array->GetValInt() ) return true;
|
|
|
|
array = array->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gives a parameter of type "point".
|
|
|
|
|
|
|
|
bool GetPoint(CBotVar* &var, int& exception, Math::Vector& pos)
|
|
|
|
{
|
|
|
|
CBotVar *pX, *pY, *pZ;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() <= CBotTypDouble )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
pos.x = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
pos.z = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
pos.y = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
pX = var->GetItem("x");
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pX == NULL )
|
|
|
|
{
|
|
|
|
exception = CBotErrUndefItem; return true;
|
|
|
|
}
|
2012-09-10 21:29:38 +00:00
|
|
|
pos.x = pX->GetValFloat()*g_unit;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
pY = var->GetItem("y");
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pY == NULL )
|
|
|
|
{
|
|
|
|
exception = CBotErrUndefItem; return true;
|
|
|
|
}
|
2012-09-10 21:29:38 +00:00
|
|
|
pos.z = pY->GetValFloat()*g_unit; // attention y -> z !
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
pZ = var->GetItem("z");
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pZ == NULL )
|
|
|
|
{
|
|
|
|
exception = CBotErrUndefItem; return true;
|
|
|
|
}
|
2012-09-10 21:29:38 +00:00
|
|
|
pos.y = pZ->GetValFloat()*g_unit; // attention z -> y !
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Instruction "sin(degrees)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rSin(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(sinf(value*Math::PI/180.0f));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "cos(degrees)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rCos(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(cosf(value*Math::PI/180.0f));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "tan(degrees)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rTan(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(tanf(value*Math::PI/180.0f));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "asin(degrees)".
|
|
|
|
|
|
|
|
bool raSin(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(asinf(value)*180.0f/Math::PI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "acos(degrees)".
|
|
|
|
|
|
|
|
bool raCos(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(acosf(value)*180.0f/Math::PI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "atan(degrees)".
|
|
|
|
|
|
|
|
bool raTan(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(atanf(value)*180.0f/Math::PI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "sqrt(value)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rSqrt(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(sqrtf(value));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "pow(x, y)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rPow(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
x = var->GetValFloat();
|
|
|
|
var = var->GetNext();
|
|
|
|
y = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(powf(x, y));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "rand()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rRand(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
result->SetValFloat(Math::Rand());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "abs()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rAbs(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(fabs(value));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "retobject(rank)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cGetObject(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
|
|
|
|
return CBotTypResult(CBotTypPointer, "object");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "retobject(rank)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject*>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
CObject* pObj;
|
|
|
|
int rank;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
rank = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
|
|
|
|
|
|
|
|
pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, rank));
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pObj == 0 )
|
|
|
|
{
|
|
|
|
result->SetPointer(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
result->SetPointer(pObj->GetBotVar());
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "search(type, pos)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cSearch(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotVar* array;
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
array = var->GetItemList();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( array == 0 ) return CBotTypResult(CBotTypPointer);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( array->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2012-09-10 21:29:38 +00:00
|
|
|
else if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
|
|
|
ret = cPoint(var, user);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CBotTypResult(CBotTypPointer, "object");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "search(type, pos)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rSearch(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
CObject *pObj, *pBest;
|
|
|
|
CBotVar* array;
|
|
|
|
Math::Vector pos, oPos;
|
|
|
|
bool bNearest = false;
|
|
|
|
bool bArray;
|
|
|
|
float min, dist;
|
|
|
|
int type, oType, i;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
array = var->GetItemList();
|
2012-06-26 20:23:05 +00:00
|
|
|
bArray = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
type = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
bArray = false;
|
|
|
|
}
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
|
|
|
if ( !GetPoint(var, exception, pos) ) return true;
|
|
|
|
bNearest = true;
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
min = 100000.0f;
|
|
|
|
pBest = 0;
|
|
|
|
for ( i=0 ; i<1000000 ; i++ )
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pObj == 0 ) break;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
|
|
|
if ( !pObj->GetActif() ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oType = pObj->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( oType == OBJECT_TOTO ) continue;
|
|
|
|
|
|
|
|
if ( oType == OBJECT_RUINmobilew2 ||
|
|
|
|
oType == OBJECT_RUINmobilet1 ||
|
|
|
|
oType == OBJECT_RUINmobilet2 ||
|
|
|
|
oType == OBJECT_RUINmobiler1 ||
|
|
|
|
oType == OBJECT_RUINmobiler2 )
|
|
|
|
{
|
|
|
|
oType = OBJECT_RUINmobilew1; // any ruin
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oType == OBJECT_SCRAP2 ||
|
|
|
|
oType == OBJECT_SCRAP3 ||
|
|
|
|
oType == OBJECT_SCRAP4 ||
|
|
|
|
oType == OBJECT_SCRAP5 ) // wastes?
|
|
|
|
{
|
|
|
|
oType = OBJECT_SCRAP1; // any waste
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oType == OBJECT_BARRIER2 ||
|
|
|
|
oType == OBJECT_BARRIER3 ) // barriers?
|
|
|
|
{
|
|
|
|
oType = OBJECT_BARRIER1; // any barrier
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bArray )
|
|
|
|
{
|
|
|
|
if ( !FindList(array, oType) ) continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( type != oType && type != OBJECT_NULL ) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bNearest )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
oPos = pObj->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
dist = Math::DistanceProjected(pos, oPos);
|
|
|
|
if ( dist < min )
|
|
|
|
{
|
|
|
|
min = dist;
|
|
|
|
pBest = pObj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pBest = pObj;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pBest == 0 )
|
|
|
|
{
|
|
|
|
result->SetPointer(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
result->SetPointer(pBest->GetBotVar());
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of instruction "radar(type, angle, focus, min, max, sens)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cRadar(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotVar* array;
|
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypPointer, "object");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
array = var->GetItemList();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( array == 0 ) return CBotTypResult(CBotTypPointer, "object");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( array->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // type
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2012-09-10 21:29:38 +00:00
|
|
|
else if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // type
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypPointer, "object");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // angle
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypPointer, "object");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // focus
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypPointer, "object");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // min
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypPointer, "object");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // max
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypPointer, "object");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // sense
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypPointer, "object");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // filter
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypPointer, "object");
|
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "radar(type, angle, focus, min, max, sens, filter)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rRadar(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
CObject *pObj, *pBest;
|
|
|
|
CPhysics* physics;
|
|
|
|
CBotVar* array;
|
|
|
|
Math::Vector iPos, oPos;
|
|
|
|
RadarFilter filter;
|
|
|
|
float best, minDist, maxDist, sens, iAngle, angle, focus, d, a;
|
|
|
|
int type, oType, i;
|
|
|
|
bool bArray;
|
|
|
|
|
|
|
|
type = OBJECT_NULL;
|
|
|
|
angle = 0.0f;
|
|
|
|
focus = Math::PI*2.0f;
|
|
|
|
minDist = 0.0f*g_unit;
|
|
|
|
maxDist = 1000.0f*g_unit;
|
|
|
|
sens = 1.0f;
|
|
|
|
filter = FILTER_NONE;
|
|
|
|
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
array = var->GetItemList();
|
2012-06-26 20:23:05 +00:00
|
|
|
bArray = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
type = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
bArray = false;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
angle = -var->GetValFloat()*Math::PI/180.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
focus = var->GetValFloat()*Math::PI/180.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
minDist = var->GetValFloat()*g_unit;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
maxDist = var->GetValFloat()*g_unit;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
sens = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
filter = static_cast<RadarFilter>(var->GetValInt());
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
iPos = pThis->GetPosition(0);
|
|
|
|
iAngle = pThis->GetAngleY(0)+angle;
|
2012-06-26 20:23:05 +00:00
|
|
|
iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( sens >= 0.0f ) best = 100000.0f;
|
|
|
|
else best = 0.0f;
|
|
|
|
pBest = 0;
|
|
|
|
for ( i=0 ; i<1000000 ; i++ )
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pObj == 0 ) break;
|
|
|
|
if ( pObj == pThis ) continue;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
|
|
|
if ( !pObj->GetActif() ) continue;
|
|
|
|
if ( pObj->GetProxyActivate() ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oType = pObj->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( oType == OBJECT_TOTO ) continue;
|
|
|
|
|
|
|
|
if ( oType == OBJECT_RUINmobilew2 ||
|
|
|
|
oType == OBJECT_RUINmobilet1 ||
|
|
|
|
oType == OBJECT_RUINmobilet2 ||
|
|
|
|
oType == OBJECT_RUINmobiler1 ||
|
|
|
|
oType == OBJECT_RUINmobiler2 )
|
|
|
|
{
|
|
|
|
oType = OBJECT_RUINmobilew1; // any ruin
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oType == OBJECT_SCRAP2 ||
|
|
|
|
oType == OBJECT_SCRAP3 ||
|
|
|
|
oType == OBJECT_SCRAP4 ||
|
|
|
|
oType == OBJECT_SCRAP5 ) // wastes?
|
|
|
|
{
|
|
|
|
oType = OBJECT_SCRAP1; // any waste
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oType == OBJECT_BARRIER2 ||
|
|
|
|
oType == OBJECT_BARRIER3 ) // barriers?
|
|
|
|
{
|
|
|
|
oType = OBJECT_BARRIER1; // any barrier
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( filter == FILTER_ONLYLANDING )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
physics = pObj->GetPhysics();
|
|
|
|
if ( physics != 0 && !physics->GetLand() ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
if ( filter == FILTER_ONLYFLYING )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
physics = pObj->GetPhysics();
|
|
|
|
if ( physics != 0 && physics->GetLand() ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( bArray )
|
|
|
|
{
|
|
|
|
if ( !FindList(array, oType) ) continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( type != oType && type != OBJECT_NULL ) continue;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oPos = pObj->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
d = Math::DistanceProjected(iPos, oPos);
|
|
|
|
if ( d < minDist || d > maxDist ) continue; // too close or too far?
|
|
|
|
|
|
|
|
if ( focus >= Math::PI*2.0f )
|
|
|
|
{
|
|
|
|
if ( (sens >= 0.0f && d < best) ||
|
|
|
|
(sens < 0.0f && d > best) )
|
|
|
|
{
|
|
|
|
best = d;
|
|
|
|
pBest = pObj;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW !
|
2012-09-17 22:01:00 +00:00
|
|
|
//TODO uninitialized variable
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( Math::TestAngle(a, iAngle-focus/2.0f, iAngle+focus/2.0f) )
|
|
|
|
{
|
|
|
|
if ( (sens >= 0.0f && d < best) ||
|
|
|
|
(sens < 0.0f && d > best) )
|
|
|
|
{
|
|
|
|
best = d;
|
|
|
|
pBest = pObj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pBest == 0 )
|
|
|
|
{
|
|
|
|
result->SetPointer(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
result->SetPointer(pBest->GetBotVar());
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Monitoring a task.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::Process(CScript* script, CBotVar* result, int &exception)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
err = script->m_primaryTask->IsEnded();
|
|
|
|
if ( err != ERR_CONTINUE ) // task terminated?
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
|
|
|
|
script->m_bContinue = false;
|
|
|
|
|
|
|
|
if ( err == ERR_STOP ) err = ERR_OK;
|
|
|
|
result->SetValInt(err); // indicates the error or ok
|
|
|
|
if ( err != ERR_OK && script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true; // it's all over
|
|
|
|
}
|
|
|
|
|
|
|
|
script->m_primaryTask->EventProcess(script->m_event);
|
|
|
|
script->m_bContinue = true;
|
|
|
|
return false; // not done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "detect(type)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cDetect(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypBoolean);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "detect(type)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rDetect(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
CObject *pObj, *pGoal, *pBest;
|
|
|
|
CPhysics* physics;
|
|
|
|
CBotVar* array;
|
|
|
|
Math::Vector iPos, oPos;
|
|
|
|
RadarFilter filter;
|
|
|
|
float bGoal, best, minDist, maxDist, sens, iAngle, angle, focus, d, a;
|
|
|
|
int type, oType, i;
|
|
|
|
bool bArray;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
|
|
|
type = OBJECT_NULL;
|
|
|
|
angle = 0.0f;
|
|
|
|
focus = 45.0f*Math::PI/180.0f;
|
|
|
|
minDist = 0.0f*g_unit;
|
|
|
|
maxDist = 20.0f*g_unit;
|
|
|
|
sens = 1.0f;
|
|
|
|
filter = FILTER_NONE;
|
|
|
|
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
array = var->GetItemList();
|
2012-06-26 20:23:05 +00:00
|
|
|
bArray = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
type = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
bArray = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
iPos = pThis->GetPosition(0);
|
|
|
|
iAngle = pThis->GetAngleY(0)+angle;
|
2012-06-26 20:23:05 +00:00
|
|
|
iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
bGoal = 100000.0f;
|
|
|
|
pGoal = 0;
|
|
|
|
if ( sens >= 0.0f ) best = 100000.0f;
|
|
|
|
else best = 0.0f;
|
|
|
|
pBest = 0;
|
|
|
|
for ( i=0 ; i<1000000 ; i++ )
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pObj == 0 ) break;
|
|
|
|
if ( pObj == pThis ) continue;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
|
|
|
if ( !pObj->GetActif() ) continue;
|
|
|
|
if ( pObj->GetProxyActivate() ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oType = pObj->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( oType == OBJECT_TOTO ) continue;
|
|
|
|
|
|
|
|
if ( oType == OBJECT_RUINmobilew2 ||
|
|
|
|
oType == OBJECT_RUINmobilet1 ||
|
|
|
|
oType == OBJECT_RUINmobilet2 ||
|
|
|
|
oType == OBJECT_RUINmobiler1 ||
|
|
|
|
oType == OBJECT_RUINmobiler2 )
|
|
|
|
{
|
|
|
|
oType = OBJECT_RUINmobilew1; // any ruin
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oType == OBJECT_SCRAP2 ||
|
|
|
|
oType == OBJECT_SCRAP3 ||
|
|
|
|
oType == OBJECT_SCRAP4 ||
|
|
|
|
oType == OBJECT_SCRAP5 ) // wastes?
|
|
|
|
{
|
|
|
|
oType = OBJECT_SCRAP1; // any waste
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oType == OBJECT_BARRIER2 ||
|
|
|
|
oType == OBJECT_BARRIER3 ) // barriers?
|
|
|
|
{
|
|
|
|
oType = OBJECT_BARRIER1; // any barrier
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( filter == FILTER_ONLYLANDING )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
physics = pObj->GetPhysics();
|
|
|
|
if ( physics != 0 && !physics->GetLand() ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
if ( filter == FILTER_ONLYFLYING )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
physics = pObj->GetPhysics();
|
|
|
|
if ( physics != 0 && physics->GetLand() ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( bArray )
|
|
|
|
{
|
|
|
|
if ( !FindList(array, oType) ) continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( type != oType && type != OBJECT_NULL ) continue;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oPos = pObj->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
d = Math::DistanceProjected(iPos, oPos);
|
|
|
|
a = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW !
|
|
|
|
|
|
|
|
if ( d < bGoal &&
|
|
|
|
Math::TestAngle(a, iAngle-(5.0f*Math::PI/180.0f)/2.0f, iAngle+(5.0f*Math::PI/180.0f)/2.0f) )
|
|
|
|
{
|
|
|
|
bGoal = d;
|
|
|
|
pGoal = pObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( d < minDist || d > maxDist ) continue; // too close or too far?
|
|
|
|
|
|
|
|
if ( focus >= Math::PI*2.0f )
|
|
|
|
{
|
|
|
|
if ( (sens >= 0.0f && d < best) ||
|
|
|
|
(sens < 0.0f && d > best) )
|
|
|
|
{
|
|
|
|
best = d;
|
|
|
|
pBest = pObj;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Math::TestAngle(a, iAngle-focus/2.0f, iAngle+focus/2.0f) )
|
|
|
|
{
|
|
|
|
if ( (sens >= 0.0f && d < best) ||
|
|
|
|
(sens < 0.0f && d > best) )
|
|
|
|
{
|
|
|
|
best = d;
|
|
|
|
pBest = pObj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pThis->StartDetectEffect(pGoal, pBest!=0);
|
|
|
|
|
|
|
|
if ( pBest == 0 )
|
|
|
|
{
|
|
|
|
script->m_returnValue = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
script->m_returnValue = 1.0f;
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskWait(0.3f);
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !Process(script, result, exception) ) return false; // not finished
|
|
|
|
result->SetValFloat(script->m_returnValue);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "direction(pos)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cDirection(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
ret = cPoint(var, user);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "direction(pos)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rDirection(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
Math::Vector iPos, oPos;
|
2012-09-10 21:29:38 +00:00
|
|
|
float a, g;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( !GetPoint(var, exception, oPos) ) return true;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
iPos = pThis->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
a = pThis->GetAngleY(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
g = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW !
|
|
|
|
|
|
|
|
result->SetValFloat(-Math::Direction(a, g)*180.0f/Math::PI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-14 14:48:02 +00:00
|
|
|
// Compilation of the instruction "produce(pos, angle, type, scriptName, power)".
|
|
|
|
// or "produce(pos, angle, type, scriptName)"
|
|
|
|
// or "produce(pos, angle, type)"
|
|
|
|
// or "produce(type)"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cProduce(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
|
2013-02-14 14:48:02 +00:00
|
|
|
if ( var->GetType() <= CBotTypDouble ) {
|
|
|
|
var = var->GetNext();
|
|
|
|
} else {
|
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-14 14:48:02 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-14 14:48:02 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
|
|
|
|
if ( var != 0 ) {
|
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
|
|
|
|
|
|
|
if ( var != 0 ) {
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
2013-02-14 14:48:02 +00:00
|
|
|
// Instruction "produce(pos, angle, type, scriptName, power)".
|
|
|
|
// or "produce(pos, angle, type, scriptName)"
|
|
|
|
// or "produce(pos, angle, type)"
|
|
|
|
// or "produce(type)"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
CObject* object;
|
2013-02-14 14:48:02 +00:00
|
|
|
CObject* me = (static_cast<CObject *>(user));
|
2012-06-26 20:23:05 +00:00
|
|
|
CBotString cbs;
|
|
|
|
const char* name;
|
|
|
|
Math::Vector pos;
|
|
|
|
float angle;
|
|
|
|
ObjectType type;
|
2013-02-14 14:48:02 +00:00
|
|
|
float power;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-14 14:48:02 +00:00
|
|
|
if ( var->GetType() <= CBotTypDouble ) {
|
|
|
|
type = static_cast<ObjectType>(var->GetValInt());
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-14 14:48:02 +00:00
|
|
|
pos = me->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-14 14:48:02 +00:00
|
|
|
Math::Vector rotation = me->GetAngle(0) + me->GetInclinaison();
|
|
|
|
angle = rotation.y;
|
|
|
|
|
|
|
|
power = -1.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-14 14:48:02 +00:00
|
|
|
name = "";
|
|
|
|
} else {
|
|
|
|
if ( !GetPoint(var, exception, pos) ) return true;
|
|
|
|
|
|
|
|
angle = var->GetValFloat()*Math::PI/180.0f;
|
|
|
|
var = var->GetNext();
|
|
|
|
|
|
|
|
type = static_cast<ObjectType>(var->GetValInt());
|
|
|
|
var = var->GetNext();
|
|
|
|
|
|
|
|
if ( var != 0 ) {
|
|
|
|
cbs = var->GetValString();
|
|
|
|
name = cbs;
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var != 0 ) {
|
|
|
|
power = var->GetValFloat();
|
|
|
|
} else {
|
|
|
|
power = -1.0f;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
name = "";
|
|
|
|
power = -1.0f;
|
|
|
|
}
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-14 16:18:04 +00:00
|
|
|
if ( type == OBJECT_FRET ||
|
|
|
|
type == OBJECT_STONE ||
|
|
|
|
type == OBJECT_URANIUM ||
|
|
|
|
type == OBJECT_METAL ||
|
|
|
|
type == OBJECT_POWER ||
|
|
|
|
type == OBJECT_ATOMIC ||
|
|
|
|
type == OBJECT_BULLET ||
|
|
|
|
type == OBJECT_BBOX ||
|
|
|
|
type == OBJECT_KEYa ||
|
|
|
|
type == OBJECT_KEYb ||
|
|
|
|
type == OBJECT_KEYc ||
|
|
|
|
type == OBJECT_KEYd ||
|
|
|
|
type == OBJECT_TNT ||
|
|
|
|
type == OBJECT_SCRAP1 ||
|
|
|
|
type == OBJECT_SCRAP2 ||
|
|
|
|
type == OBJECT_SCRAP3 ||
|
|
|
|
type == OBJECT_SCRAP4 ||
|
|
|
|
type == OBJECT_SCRAP5 ||
|
|
|
|
type == OBJECT_BOMB ||
|
|
|
|
type == OBJECT_WAYPOINT ||
|
|
|
|
type == OBJECT_SHOW ||
|
|
|
|
type == OBJECT_WINFIRE ||
|
|
|
|
type == OBJECT_BAG ||
|
|
|
|
type == OBJECT_MARKPOWER ||
|
|
|
|
type == OBJECT_MARKSTONE ||
|
|
|
|
type == OBJECT_MARKURANIUM ||
|
|
|
|
type == OBJECT_MARKKEYa ||
|
|
|
|
type == OBJECT_MARKKEYb ||
|
|
|
|
type == OBJECT_MARKKEYc ||
|
|
|
|
type == OBJECT_MARKKEYd ||
|
|
|
|
type == OBJECT_EGG )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
object = new CObject();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( !object->CreateResource(pos, angle, type) )
|
|
|
|
{
|
|
|
|
delete object;
|
|
|
|
result->SetValInt(1); // error
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-14 14:48:02 +00:00
|
|
|
object->SetActivity(false);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( type == OBJECT_MOTHER ||
|
|
|
|
type == OBJECT_ANT ||
|
|
|
|
type == OBJECT_SPIDER ||
|
|
|
|
type == OBJECT_BEE ||
|
|
|
|
type == OBJECT_WORM )
|
|
|
|
{
|
|
|
|
CObject* egg;
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
object = new CObject();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( !object->CreateInsect(pos, angle, type) )
|
|
|
|
{
|
|
|
|
delete object;
|
|
|
|
result->SetValInt(1); // error
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
egg = new CObject();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( !egg->CreateResource(pos, angle, OBJECT_EGG, 0.0f) )
|
|
|
|
{
|
|
|
|
delete egg;
|
|
|
|
}
|
2013-02-14 14:48:02 +00:00
|
|
|
object->SetActivity(false);
|
|
|
|
}
|
|
|
|
else
|
2013-02-14 16:18:04 +00:00
|
|
|
if ( type == OBJECT_PORTICO ||
|
|
|
|
type == OBJECT_BASE ||
|
|
|
|
type == OBJECT_DERRICK ||
|
|
|
|
type == OBJECT_FACTORY ||
|
|
|
|
type == OBJECT_STATION ||
|
|
|
|
type == OBJECT_CONVERT ||
|
|
|
|
type == OBJECT_REPAIR ||
|
|
|
|
type == OBJECT_DESTROYER||
|
|
|
|
type == OBJECT_TOWER ||
|
|
|
|
type == OBJECT_NEST ||
|
|
|
|
type == OBJECT_RESEARCH ||
|
|
|
|
type == OBJECT_RADAR ||
|
|
|
|
type == OBJECT_INFO ||
|
|
|
|
type == OBJECT_ENERGY ||
|
|
|
|
type == OBJECT_LABO ||
|
|
|
|
type == OBJECT_NUCLEAR ||
|
|
|
|
type == OBJECT_PARA ||
|
|
|
|
type == OBJECT_SAFE ||
|
|
|
|
type == OBJECT_HUSTON ||
|
|
|
|
type == OBJECT_TARGET1 ||
|
|
|
|
type == OBJECT_TARGET2 ||
|
|
|
|
type == OBJECT_START ||
|
|
|
|
type == OBJECT_END )
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
object = new CObject();
|
2013-02-14 14:48:02 +00:00
|
|
|
if ( !object->CreateBuilding(pos, angle, 0, type) )
|
|
|
|
{
|
|
|
|
delete object;
|
|
|
|
result->SetValInt(1); // error
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
object->SetActivity(false);
|
2013-02-14 15:04:52 +00:00
|
|
|
script->m_main->CreateShortcuts();
|
2013-02-14 14:48:02 +00:00
|
|
|
}
|
|
|
|
else
|
2013-02-14 16:18:04 +00:00
|
|
|
if ( type == OBJECT_FLAGb ||
|
|
|
|
type == OBJECT_FLAGr ||
|
|
|
|
type == OBJECT_FLAGg ||
|
|
|
|
type == OBJECT_FLAGy ||
|
|
|
|
type == OBJECT_FLAGv )
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
object = new CObject();
|
2013-02-14 16:26:01 +00:00
|
|
|
if ( !object->CreateFlag(pos, angle, type) )
|
2013-02-14 16:18:04 +00:00
|
|
|
{
|
|
|
|
delete object;
|
|
|
|
result->SetValInt(1); // error
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
object->SetActivity(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if ( type == OBJECT_HUMAN ||
|
|
|
|
type == OBJECT_TECH ||
|
|
|
|
type == OBJECT_TOTO ||
|
2013-02-14 14:48:02 +00:00
|
|
|
type == OBJECT_MOBILEfa ||
|
2013-02-14 16:18:04 +00:00
|
|
|
type == OBJECT_MOBILEta ||
|
|
|
|
type == OBJECT_MOBILEwa ||
|
2013-02-14 14:48:02 +00:00
|
|
|
type == OBJECT_MOBILEia ||
|
|
|
|
type == OBJECT_MOBILEfc ||
|
2013-02-14 16:18:04 +00:00
|
|
|
type == OBJECT_MOBILEtc ||
|
|
|
|
type == OBJECT_MOBILEwc ||
|
2013-02-14 14:48:02 +00:00
|
|
|
type == OBJECT_MOBILEic ||
|
|
|
|
type == OBJECT_MOBILEfi ||
|
2013-02-14 16:18:04 +00:00
|
|
|
type == OBJECT_MOBILEti ||
|
|
|
|
type == OBJECT_MOBILEwi ||
|
2013-02-14 14:48:02 +00:00
|
|
|
type == OBJECT_MOBILEii ||
|
|
|
|
type == OBJECT_MOBILEfs ||
|
2013-02-14 16:18:04 +00:00
|
|
|
type == OBJECT_MOBILEts ||
|
|
|
|
type == OBJECT_MOBILEws ||
|
2013-02-14 14:48:02 +00:00
|
|
|
type == OBJECT_MOBILEis ||
|
|
|
|
type == OBJECT_MOBILErt ||
|
|
|
|
type == OBJECT_MOBILErc ||
|
|
|
|
type == OBJECT_MOBILErr ||
|
|
|
|
type == OBJECT_MOBILErs ||
|
|
|
|
type == OBJECT_MOBILEsa ||
|
|
|
|
type == OBJECT_MOBILEtg ||
|
2013-02-14 16:18:04 +00:00
|
|
|
type == OBJECT_MOBILEft ||
|
|
|
|
type == OBJECT_MOBILEtt ||
|
|
|
|
type == OBJECT_MOBILEwt ||
|
|
|
|
type == OBJECT_MOBILEit ||
|
|
|
|
type == OBJECT_MOBILEdr ||
|
|
|
|
type == OBJECT_APOLLO2 )
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
object = new CObject();
|
2013-02-14 14:48:02 +00:00
|
|
|
if ( !object->CreateVehicle(pos, angle, type, power, false, false) )
|
|
|
|
{
|
|
|
|
delete object;
|
|
|
|
result->SetValInt(1); // error
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
object->UpdateMapping();
|
|
|
|
object->SetRange(30.0f);
|
|
|
|
object->SetZoom(0, 1.0f);
|
|
|
|
CPhysics* physics = object->GetPhysics();
|
|
|
|
if ( physics != 0 )
|
|
|
|
{
|
|
|
|
physics->SetFreeze(false); // can move
|
|
|
|
}
|
|
|
|
object->SetLock(false); // vehicle useable
|
|
|
|
object->SetActivity(true);
|
|
|
|
script->m_main->CreateShortcuts();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->SetValInt(1); // impossible
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-14 14:48:02 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
object->ReadProgram(0, static_cast<const char*>(name));
|
2012-06-26 20:23:05 +00:00
|
|
|
object->RunProgram(0);
|
2012-06-26 21:01:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValInt(0); // no error
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "distance(p1, p2)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cDistance(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
ret = cPoint(var, user);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
ret = cPoint(var, user);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "distance(p1, p2)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rDistance(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
Math::Vector p1, p2;
|
|
|
|
float value;
|
|
|
|
|
|
|
|
if ( !GetPoint(var, exception, p1) ) return true;
|
|
|
|
if ( !GetPoint(var, exception, p2) ) return true;
|
|
|
|
|
|
|
|
value = Math::Distance(p1, p2);
|
|
|
|
result->SetValFloat(value/g_unit);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "distance2d(p1, p2)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rDistance2d(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
Math::Vector p1, p2;
|
|
|
|
float value;
|
|
|
|
|
|
|
|
if ( !GetPoint(var, exception, p1) ) return true;
|
|
|
|
if ( !GetPoint(var, exception, p2) ) return true;
|
|
|
|
|
|
|
|
value = Math::DistanceProjected(p1, p2);
|
|
|
|
result->SetValFloat(value/g_unit);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "space(center, rMin, rMax, dist)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cSpace(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypIntrinsic, "point");
|
|
|
|
ret = cPoint(var, user);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypIntrinsic, "point");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "space(center, rMin, rMax, dist)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rSpace(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
CBotVar* pSub;
|
|
|
|
Math::Vector center;
|
|
|
|
float rMin, rMax, dist;
|
|
|
|
|
|
|
|
rMin = 10.0f*g_unit;
|
|
|
|
rMax = 50.0f*g_unit;
|
|
|
|
dist = 4.0f*g_unit;
|
|
|
|
|
|
|
|
if ( var == 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
center = pThis->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !GetPoint(var, exception, center) ) return true;
|
|
|
|
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
rMin = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
rMax = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
dist = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
script->m_main->FreeSpace(center, rMin, rMax, dist, pThis);
|
|
|
|
|
|
|
|
if ( result != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
pSub = result->GetItemList();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pSub != 0 )
|
|
|
|
{
|
|
|
|
pSub->SetValFloat(center.x/g_unit);
|
2012-09-10 21:29:38 +00:00
|
|
|
pSub = pSub->GetNext(); // "y"
|
2012-06-26 20:23:05 +00:00
|
|
|
pSub->SetValFloat(center.z/g_unit);
|
2012-09-10 21:29:38 +00:00
|
|
|
pSub = pSub->GetNext(); // "z"
|
2012-06-26 20:23:05 +00:00
|
|
|
pSub->SetValFloat(center.y/g_unit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "flatground(center, rMax)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cFlatGround(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
ret = cPoint(var, user);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "flatground(center, rMax)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rFlatGround(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
Math::Vector center;
|
|
|
|
float rMax, dist;
|
|
|
|
|
|
|
|
if ( !GetPoint(var, exception, center) ) return true;
|
2012-09-10 21:29:38 +00:00
|
|
|
rMax = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
dist = script->m_main->GetFlatZoneRadius(center, rMax, pThis);
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(dist/g_unit);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Instruction "wait(t)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rWait(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
float value;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskWait(value);
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "move(dist)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rMove(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
float value;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskAdvance(value*g_unit);
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "turn(angle)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rTurn(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
float value;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskTurn(-value*Math::PI/180.0f);
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "goto(pos, altitude, crash, goal)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cGoto(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
ret = cPoint(var, user);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "goto(pos, altitude, mode)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rGoto(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
Math::Vector pos;
|
|
|
|
TaskGotoGoal goal;
|
|
|
|
TaskGotoCrash crash;
|
|
|
|
float altitude;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( !GetPoint(var, exception, pos) ) return true;
|
|
|
|
|
|
|
|
goal = TGG_DEFAULT;
|
|
|
|
crash = TGC_DEFAULT;
|
|
|
|
altitude = 0.0f*g_unit;
|
|
|
|
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
altitude = var->GetValFloat()*g_unit;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
goal = static_cast<TaskGotoGoal>(var->GetValInt());
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
crash = static_cast<TaskGotoCrash>(var->GetValInt());
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = script->m_primaryTask->StartTaskGoto(pos, altitude, goal, crash);
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "find(type)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rFind(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
Math::Vector pos;
|
|
|
|
TaskGotoGoal goal;
|
|
|
|
TaskGotoCrash crash;
|
|
|
|
float altitude;
|
|
|
|
Error err;
|
2012-09-10 21:29:38 +00:00
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
CObject *pObj, *pBest;
|
|
|
|
CBotVar* array;
|
|
|
|
Math::Vector iPos, oPos;
|
2012-09-10 21:29:38 +00:00
|
|
|
float best, minDist, maxDist, iAngle, focus, d, a;
|
2012-06-26 20:23:05 +00:00
|
|
|
int type, oType, i;
|
|
|
|
bool bArray;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
|
|
|
type = OBJECT_NULL;
|
|
|
|
focus = Math::PI*2.0f;
|
|
|
|
minDist = 0.0f*g_unit;
|
|
|
|
maxDist = 1000.0f*g_unit;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
array = var->GetItemList();
|
2012-06-26 20:23:05 +00:00
|
|
|
bArray = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
type = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
bArray = false;
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
best = 100000.0f;
|
|
|
|
pBest = 0;
|
|
|
|
for ( i=0 ; i<1000000 ; i++ )
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pObj == 0 ) break;
|
|
|
|
if ( pObj == pThis ) continue;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
|
|
|
if ( !pObj->GetActif() ) continue;
|
|
|
|
if ( pObj->GetProxyActivate() ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oType = pObj->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( oType == OBJECT_TOTO ) continue;
|
|
|
|
|
|
|
|
if ( oType == OBJECT_RUINmobilew2 ||
|
|
|
|
oType == OBJECT_RUINmobilet1 ||
|
|
|
|
oType == OBJECT_RUINmobilet2 ||
|
|
|
|
oType == OBJECT_RUINmobiler1 ||
|
|
|
|
oType == OBJECT_RUINmobiler2 )
|
|
|
|
{
|
|
|
|
oType = OBJECT_RUINmobilew1; // any ruin
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oType == OBJECT_SCRAP2 ||
|
|
|
|
oType == OBJECT_SCRAP3 ||
|
|
|
|
oType == OBJECT_SCRAP4 ||
|
|
|
|
oType == OBJECT_SCRAP5 ) // wastes?
|
|
|
|
{
|
|
|
|
oType = OBJECT_SCRAP1; // any waste
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oType == OBJECT_BARRIER2 ||
|
|
|
|
oType == OBJECT_BARRIER3 ) // barriers?
|
|
|
|
{
|
|
|
|
oType = OBJECT_BARRIER1; // any barrier
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bArray )
|
|
|
|
{
|
|
|
|
if ( !FindList(array, oType) ) continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( type != oType && type != OBJECT_NULL ) continue;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oPos = pObj->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
d = Math::DistanceProjected(iPos, oPos);
|
|
|
|
if ( d < minDist || d > maxDist ) continue; // too close or too far?
|
|
|
|
|
|
|
|
if ( focus >= Math::PI*2.0f )
|
|
|
|
{
|
|
|
|
if ( d < best )
|
|
|
|
{
|
|
|
|
best = d;
|
|
|
|
pBest = pObj;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW !
|
|
|
|
if ( Math::TestAngle(a, iAngle-focus/2.0f, iAngle+focus/2.0f) )
|
|
|
|
{
|
|
|
|
if ( d < best )
|
|
|
|
{
|
|
|
|
best = d;
|
|
|
|
pBest = pObj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pBest == 0 )
|
|
|
|
{
|
|
|
|
exception = ERR_FIND_IMPOSSIBLE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
pos = pBest->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
goal = TGG_DEFAULT;
|
|
|
|
crash = TGC_DEFAULT;
|
|
|
|
altitude = 0.0f*g_unit;
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskGoto(pos, altitude, goal, crash);
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation "grab/drop(oper)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cGrabDrop(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "grab(oper)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rGrab(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
ObjectType oType;
|
|
|
|
TaskManipArm type;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-12-28 12:37:08 +00:00
|
|
|
if ( var == 0 )
|
2012-09-10 21:29:38 +00:00
|
|
|
{
|
|
|
|
type = TMA_FFRONT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = static_cast<TaskManipArm>(var->GetValInt());
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oType = pThis->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( oType == OBJECT_HUMAN ||
|
|
|
|
oType == OBJECT_TECH )
|
|
|
|
{
|
|
|
|
err = script->m_primaryTask->StartTaskTake();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err = script->m_primaryTask->StartTaskManip(TMO_GRAB, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "drop(oper)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rDrop(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
ObjectType oType;
|
|
|
|
TaskManipArm type;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) type = TMA_FFRONT;
|
2012-09-10 21:29:38 +00:00
|
|
|
else type = static_cast<TaskManipArm>(var->GetValInt());
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oType = pThis->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( oType == OBJECT_HUMAN ||
|
|
|
|
oType == OBJECT_TECH )
|
|
|
|
{
|
|
|
|
err = script->m_primaryTask->StartTaskTake();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err = script->m_primaryTask->StartTaskManip(TMO_DROP, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "sniff()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rSniff(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskSearch();
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "receive(nom, power)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cReceive(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "receive(nom, power)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rReceive(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
CBotString cbs;
|
|
|
|
Error err;
|
|
|
|
const char* p;
|
|
|
|
float value, power;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
cbs = var->GetValString();
|
2012-06-26 20:23:05 +00:00
|
|
|
p = cbs;
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
power = 10.0f*g_unit;
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
power = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
err = script->m_primaryTask->StartTaskInfo(static_cast<const char*>(p), 0.0f, power, false);
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetInit(IS_NAN);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !Process(script, result, exception) ) return false; // not finished
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = pThis->GetInfoReturn();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( value == NAN )
|
|
|
|
{
|
|
|
|
result->SetInit(IS_NAN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->SetValFloat(value);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "send(nom, value, power)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cSend(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 21:01:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "send(nom, value, power)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rSend(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
CBotString cbs;
|
|
|
|
Error err;
|
|
|
|
const char* p;
|
|
|
|
float value, power;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
cbs = var->GetValString();
|
2012-06-26 20:23:05 +00:00
|
|
|
p = cbs;
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
power = 10.0f*g_unit;
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
power = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
err = script->m_primaryTask->StartTaskInfo(static_cast<const char*>(p), value, power, true);
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Seeks the nearest information terminal.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CObject* CScript::SearchInfo(CScript* script, CObject* object, float power)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CObject *pObj, *pBest;
|
|
|
|
Math::Vector iPos, oPos;
|
|
|
|
ObjectType type;
|
|
|
|
float dist, min;
|
|
|
|
int i;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
iPos = object->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
min = 100000.0f;
|
|
|
|
pBest = 0;
|
|
|
|
for ( i=0 ; i<1000000 ; i++ )
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( pObj == 0 ) break;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
type = pObj->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( type != OBJECT_INFO ) continue;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( !pObj->GetActif() ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oPos = pObj->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
dist = Math::Distance(oPos, iPos);
|
|
|
|
if ( dist > power ) continue; // too far?
|
|
|
|
if ( dist < min )
|
|
|
|
{
|
|
|
|
min = dist;
|
|
|
|
pBest = pObj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pBest;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "deleteinfo(nom, power)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cDeleteInfo(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "deleteinfo(nom, power)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rDeleteInfo(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
CObject* pInfo;
|
|
|
|
CBotString cbs;
|
|
|
|
Info info;
|
|
|
|
const char* p;
|
|
|
|
float power;
|
|
|
|
int i, total;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
cbs = var->GetValString();
|
2012-06-26 20:23:05 +00:00
|
|
|
p = cbs;
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
power = 10.0f*g_unit;
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
power = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pInfo = SearchInfo(script, pThis, power);
|
|
|
|
if ( pInfo == 0 )
|
|
|
|
{
|
|
|
|
result->SetValFloat(0.0f); // false
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
total = pInfo->GetInfoTotal();
|
2012-06-26 20:23:05 +00:00
|
|
|
for ( i=0 ; i<total ; i++ )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
info = pInfo->GetInfo(i);
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( strcmp(info.name, p) == 0 )
|
|
|
|
{
|
|
|
|
pInfo->DeleteInfo(i);
|
|
|
|
result->SetValFloat(1.0f); // true
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result->SetValFloat(0.0f); // false
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "testinfo(nom, power)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cTestInfo(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypBoolean);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypBoolean);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "testinfo(nom, power)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rTestInfo(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
CObject* pInfo;
|
|
|
|
CBotString cbs;
|
|
|
|
Info info;
|
|
|
|
const char* p;
|
|
|
|
float power;
|
|
|
|
int i, total;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
cbs = var->GetValString();
|
2012-06-26 20:23:05 +00:00
|
|
|
p = cbs;
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
power = 10.0f*g_unit;
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
power = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pInfo = SearchInfo(script, pThis, power);
|
|
|
|
if ( pInfo == 0 )
|
|
|
|
{
|
|
|
|
result->SetValInt(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
total = pInfo->GetInfoTotal();
|
2012-06-26 20:23:05 +00:00
|
|
|
for ( i=0 ; i<total ; i++ )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
info = pInfo->GetInfo(i);
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( strcmp(info.name, p) == 0 )
|
|
|
|
{
|
|
|
|
result->SetValInt(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result->SetValInt(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "thump()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rThump(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskTerraform();
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "recycle()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rRecycle(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskRecover();
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation "shield(oper, radius)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cShield(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "shield(oper, radius)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rShield(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
float oper, radius;
|
|
|
|
Error err;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
oper = var->GetValFloat(); // 0=down, 1=up
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
radius = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( radius < 10.0f ) radius = 10.0f;
|
|
|
|
if ( radius > 25.0f ) radius = 25.0f;
|
|
|
|
radius = (radius-10.0f)/15.0f;
|
|
|
|
|
|
|
|
if ( *script->m_secondaryTask == 0 ) // shield folds?
|
|
|
|
{
|
|
|
|
if ( oper == 0.0f ) // down?
|
|
|
|
{
|
|
|
|
result->SetValInt(1); // shows the error
|
|
|
|
}
|
|
|
|
else // up ?
|
|
|
|
{
|
|
|
|
pThis->SetParam(radius);
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
*script->m_secondaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
err = (*script->m_secondaryTask)->StartTaskShield(TSM_UP, 1000.0f);
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete *script->m_secondaryTask;
|
|
|
|
*script->m_secondaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // shield deployed?
|
|
|
|
{
|
|
|
|
if ( oper == 0.0f ) // down?
|
|
|
|
{
|
|
|
|
(*script->m_secondaryTask)->StartTaskShield(TSM_DOWN, 0.0f);
|
|
|
|
}
|
|
|
|
else // up?
|
|
|
|
{
|
|
|
|
//? result->SetValInt(1); // shows the error
|
|
|
|
pThis->SetParam(radius);
|
|
|
|
(*script->m_secondaryTask)->StartTaskShield(TSM_UPDATE, 0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation "fire(delay)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cFire(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
#if 0
|
2012-09-10 21:29:38 +00:00
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
ObjectType type;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
type = pThis->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( type == OBJECT_ANT )
|
|
|
|
{
|
|
|
|
return cOnePoint(var, user);
|
|
|
|
}
|
|
|
|
else if ( type == OBJECT_SPIDER )
|
|
|
|
{
|
|
|
|
return cNull(var, user);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "fire(delay)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rFire(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
float delay;
|
|
|
|
Math::Vector impact;
|
|
|
|
Error err;
|
|
|
|
ObjectType type;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
type = pThis->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( type == OBJECT_ANT )
|
|
|
|
{
|
|
|
|
if ( !GetPoint(var, exception, impact) ) return true;
|
2012-09-10 21:29:38 +00:00
|
|
|
impact.y += pThis->GetWaterLevel();
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskFireAnt(impact);
|
|
|
|
}
|
|
|
|
else if ( type == OBJECT_SPIDER )
|
|
|
|
{
|
|
|
|
err = script->m_primaryTask->StartTaskSpiderExplo();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( var == 0 ) delay = 0.0f;
|
2012-09-10 21:29:38 +00:00
|
|
|
else delay = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
err = script->m_primaryTask->StartTaskFire(delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
2013-02-13 01:32:41 +00:00
|
|
|
// Compilation of the instruction "aim(x, y)".
|
|
|
|
|
2013-02-13 13:04:24 +00:00
|
|
|
CBotTypResult CScript::cAim(CBotVar* &var, void* user)
|
2013-02-13 01:32:41 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2013-02-13 12:56:50 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2013-02-13 01:32:41 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2013-02-13 12:56:50 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2013-02-13 01:32:41 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
// Instruction "aim(dir)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rAim(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2013-02-13 01:32:41 +00:00
|
|
|
float x, y;
|
2012-06-26 20:23:05 +00:00
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2013-02-13 12:48:56 +00:00
|
|
|
x = var->GetValFloat();
|
|
|
|
var = var->GetNext();
|
|
|
|
var == 0 ? y=0.0f : y=var->GetValFloat();
|
2013-02-13 01:32:41 +00:00
|
|
|
err = script->m_primaryTask->StartTaskGunGoal(x*Math::PI/180.0f, y*Math::PI/180.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "motor(left, right)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cMotor(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "motor(left, right)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rMotor(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
|
|
|
CPhysics* physics = (static_cast<CObject *>(user))->GetPhysics();
|
2012-06-26 20:23:05 +00:00
|
|
|
float left, right, speed, turn;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
left = var->GetValFloat();
|
|
|
|
var = var->GetNext();
|
|
|
|
right = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
speed = (left+right)/2.0f;
|
|
|
|
if ( speed < -1.0f ) speed = -1.0f;
|
|
|
|
if ( speed > 1.0f ) speed = 1.0f;
|
|
|
|
|
|
|
|
turn = left-right;
|
|
|
|
if ( turn < -1.0f ) turn = -1.0f;
|
|
|
|
if ( turn > 1.0f ) turn = 1.0f;
|
2012-06-26 21:01:17 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( pThis->GetFixed() ) // ant on the back?
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
speed = 0.0f;
|
|
|
|
turn = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
physics->SetMotorSpeedX(speed); // forward/backward
|
|
|
|
physics->SetMotorSpeedZ(turn); // turns
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "jet(power)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rJet(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CPhysics* physics = (static_cast<CObject *>(user))->GetPhysics();
|
2012-06-26 20:23:05 +00:00
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValFloat();
|
2013-03-01 20:35:58 +00:00
|
|
|
if( value > 1.0f ) value = 1.0f;
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
physics->SetMotorSpeedY(value);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "topo(pos)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cTopo(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
ret = CScript::cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "topo(pos)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rTopo(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
Math::Vector pos;
|
|
|
|
float level;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( !GetPoint(var, exception, pos) ) return true;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
level = script->m_terrain->GetFloorLevel(pos);
|
|
|
|
level -= script->m_water->GetLevel();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(level/g_unit);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "message(string, type)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cMessage(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() != CBotTypString &&
|
|
|
|
var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "message(string, type)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rMessage(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
CBotString cbs;
|
|
|
|
const char* p;
|
2012-09-10 21:29:38 +00:00
|
|
|
Ui::TextType type;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
cbs = var->GetValString();
|
2012-06-26 20:23:05 +00:00
|
|
|
p = cbs;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
type = Ui::TT_MESSAGE;
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
type = static_cast<Ui::TextType>(var->GetValInt());
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
script->m_displayText->DisplayText(p, script->m_object, 10.0f, type);
|
|
|
|
script->m_main->CheckEndMessage(p);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "cmdline(rank)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rCmdline(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
float value;
|
|
|
|
int rank;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
rank = var->GetValInt();
|
|
|
|
value = pThis->GetCmdLine(rank);
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(value);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "ismovie()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rIsMovie(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = script->m_main->GetMovieLock()?1.0f:0.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(value);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "errmode(mode)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rErrMode(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
int value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( value < 0 ) value = 0;
|
|
|
|
if ( value > 1 ) value = 1;
|
|
|
|
script->m_errMode = value;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "ipf(num)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rIPF(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
int value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( value < 1 ) value = 1;
|
|
|
|
if ( value > 10000 ) value = 10000;
|
|
|
|
script->m_ipf = value;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "abstime()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rAbsTime(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
float value;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
value = script->m_main->GetGameTime();
|
2012-06-26 20:23:05 +00:00
|
|
|
result->SetValFloat(value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Prepares a file name.
|
|
|
|
|
2012-09-26 20:57:43 +00:00
|
|
|
void PrepareFilename(CBotString &filename, const char *dir)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
pos = filename.ReverseFind('\\');
|
|
|
|
if ( pos > 0 )
|
|
|
|
{
|
|
|
|
filename = filename.Mid(pos+1); // removes folders
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = filename.ReverseFind('/');
|
|
|
|
if ( pos > 0 )
|
|
|
|
{
|
|
|
|
filename = filename.Mid(pos+1); // also those with /
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = filename.ReverseFind(':');
|
|
|
|
if ( pos > 0 )
|
|
|
|
{
|
|
|
|
filename = filename.Mid(pos+1); // also removes the drive letter C:
|
|
|
|
}
|
|
|
|
|
|
|
|
filename = CBotString(dir) + CBotString("\\") + filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "deletefile(filename)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rDeleteFile(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
CBotString cbs;
|
2012-09-10 21:29:38 +00:00
|
|
|
const char* filename;
|
2012-09-26 20:57:43 +00:00
|
|
|
const char* dir;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
cbs = var->GetValString();
|
|
|
|
dir = script->m_main->GetFilesDir();
|
2012-06-26 20:23:05 +00:00
|
|
|
PrepareFilename(cbs, dir);
|
2012-09-10 21:29:38 +00:00
|
|
|
filename = cbs;
|
|
|
|
//std function that removes file.
|
|
|
|
return (!remove(filename));
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "pendown(color, width)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotTypResult CScript::cPenDown(CBotVar* &var, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( var == 0 ) return CBotTypResult(CBotTypFloat);
|
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "pendown(color, width)".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rPenDown(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
int color;
|
|
|
|
float width;
|
|
|
|
Error err;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( pThis->GetType() == OBJECT_MOBILEdr )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( color < 0 ) color = 0;
|
|
|
|
if ( color > 17 ) color = 17;
|
|
|
|
pThis->SetTraceColor(color);
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
width = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( width < 0.1f ) width = 0.1f;
|
|
|
|
if ( width > 1.0f ) width = 1.0f;
|
|
|
|
pThis->SetTraceWidth(width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pThis->SetTraceDown(true);
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-09-10 21:29:38 +00:00
|
|
|
err = script->m_primaryTask->StartTaskPen(pThis->GetTraceDown(), pThis->GetTraceColor());
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( color < 0 ) color = 0;
|
|
|
|
if ( color > 17 ) color = 17;
|
|
|
|
pThis->SetTraceColor(color);
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( var != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
width = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( width < 0.1f ) width = 0.1f;
|
|
|
|
if ( width > 1.0f ) width = 1.0f;
|
|
|
|
pThis->SetTraceWidth(width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pThis->SetTraceDown(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "penup()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rPenUp(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
Error err;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( pThis->GetType() == OBJECT_MOBILEdr )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
|
|
|
pThis->SetTraceDown(false);
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-09-10 21:29:38 +00:00
|
|
|
err = script->m_primaryTask->StartTaskPen(pThis->GetTraceDown(), pThis->GetTraceColor());
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pThis->SetTraceDown(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "pencolor()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rPenColor(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
int color;
|
|
|
|
Error err;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( pThis->GetType() == OBJECT_MOBILEdr )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( script->m_primaryTask == 0 ) // no task in progress?
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( color < 0 ) color = 0;
|
|
|
|
if ( color > 17 ) color = 17;
|
|
|
|
pThis->SetTraceColor(color);
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
script->m_primaryTask = new CTaskManager(script->m_object);
|
2012-09-10 21:29:38 +00:00
|
|
|
err = script->m_primaryTask->StartTaskPen(pThis->GetTraceDown(), pThis->GetTraceColor());
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
delete script->m_primaryTask;
|
|
|
|
script->m_primaryTask = 0;
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Process(script, result, exception);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color = var->GetValInt();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( color < 0 ) color = 0;
|
|
|
|
if ( color > 17 ) color = 17;
|
|
|
|
pThis->SetTraceColor(color);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "penwidth()".
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CObject* pThis = static_cast<CObject *>(user);
|
2012-06-26 20:23:05 +00:00
|
|
|
float width;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
width = var->GetValFloat();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( width < 0.1f ) width = 0.1f;
|
|
|
|
if ( width > 1.0f ) width = 1.0f;
|
|
|
|
pThis->SetTraceWidth(width);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Object's constructor.
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
CScript::CScript(CObject* object, CTaskManager** secondaryTask)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2013-02-16 21:37:43 +00:00
|
|
|
m_engine = Gfx::CEngine::GetInstancePointer();
|
|
|
|
m_main = CRobotMain::GetInstancePointer();
|
|
|
|
m_terrain = m_main->GetTerrain();
|
|
|
|
m_water = m_engine->GetWater();
|
2012-12-26 19:58:02 +00:00
|
|
|
m_botProg = nullptr;
|
2012-09-10 21:29:38 +00:00
|
|
|
m_object = object;
|
2012-12-26 19:58:02 +00:00
|
|
|
m_primaryTask = nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
m_secondaryTask = secondaryTask;
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
m_interface = m_main->GetInterface();
|
|
|
|
m_displayText = m_main->GetDisplayText();
|
2012-09-29 18:27:23 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
m_ipf = CBOT_IPF;
|
|
|
|
m_errMode = ERM_STOP;
|
|
|
|
m_len = 0;
|
2012-12-26 19:58:02 +00:00
|
|
|
m_script = nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
m_bRun = false;
|
|
|
|
m_bStepMode = false;
|
|
|
|
m_bCompile = false;
|
|
|
|
m_title[0] = 0;
|
|
|
|
m_cursor1 = 0;
|
|
|
|
m_cursor2 = 0;
|
|
|
|
m_filename[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initializes all functions for module CBOT.
|
|
|
|
|
|
|
|
void CScript::InitFonctions()
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotProgram::AddFunction("sin", rSin, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("cos", rCos, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("tan", rTan, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("asin", raSin, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("acos", raCos, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("atan", raTan, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("sqrt", rSqrt, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("pow", rPow, CScript::cTwoFloat);
|
|
|
|
CBotProgram::AddFunction("rand", rRand, CScript::cNull);
|
|
|
|
CBotProgram::AddFunction("abs", rAbs, CScript::cOneFloat);
|
|
|
|
|
|
|
|
CBotProgram::AddFunction("retobject", rGetObject, CScript::cGetObject);
|
|
|
|
CBotProgram::AddFunction("search", rSearch, CScript::cSearch);
|
|
|
|
CBotProgram::AddFunction("radar", rRadar, CScript::cRadar);
|
|
|
|
CBotProgram::AddFunction("detect", rDetect, CScript::cDetect);
|
|
|
|
CBotProgram::AddFunction("direction", rDirection, CScript::cDirection);
|
|
|
|
CBotProgram::AddFunction("produce", rProduce, CScript::cProduce);
|
|
|
|
CBotProgram::AddFunction("distance", rDistance, CScript::cDistance);
|
|
|
|
CBotProgram::AddFunction("distance2d",rDistance2d,CScript::cDistance);
|
|
|
|
CBotProgram::AddFunction("space", rSpace, CScript::cSpace);
|
|
|
|
CBotProgram::AddFunction("flatground",rFlatGround,CScript::cFlatGround);
|
|
|
|
CBotProgram::AddFunction("wait", rWait, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("move", rMove, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("turn", rTurn, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("goto", rGoto, CScript::cGoto);
|
|
|
|
CBotProgram::AddFunction("find", rFind, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("grab", rGrab, CScript::cGrabDrop);
|
|
|
|
CBotProgram::AddFunction("drop", rDrop, CScript::cGrabDrop);
|
|
|
|
CBotProgram::AddFunction("sniff", rSniff, CScript::cNull);
|
|
|
|
CBotProgram::AddFunction("receive", rReceive, CScript::cReceive);
|
|
|
|
CBotProgram::AddFunction("send", rSend, CScript::cSend);
|
|
|
|
CBotProgram::AddFunction("deleteinfo",rDeleteInfo,CScript::cDeleteInfo);
|
|
|
|
CBotProgram::AddFunction("testinfo", rTestInfo, CScript::cTestInfo);
|
|
|
|
CBotProgram::AddFunction("thump", rThump, CScript::cNull);
|
|
|
|
CBotProgram::AddFunction("recycle", rRecycle, CScript::cNull);
|
|
|
|
CBotProgram::AddFunction("shield", rShield, CScript::cShield);
|
|
|
|
CBotProgram::AddFunction("fire", rFire, CScript::cFire);
|
2013-02-13 01:32:41 +00:00
|
|
|
CBotProgram::AddFunction("aim", rAim, CScript::cAim);
|
2012-09-10 21:29:38 +00:00
|
|
|
CBotProgram::AddFunction("motor", rMotor, CScript::cMotor);
|
|
|
|
CBotProgram::AddFunction("jet", rJet, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("topo", rTopo, CScript::cTopo);
|
|
|
|
CBotProgram::AddFunction("message", rMessage, CScript::cMessage);
|
|
|
|
CBotProgram::AddFunction("cmdline", rCmdline, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("ismovie", rIsMovie, CScript::cNull);
|
|
|
|
CBotProgram::AddFunction("errmode", rErrMode, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("ipf", rIPF, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("abstime", rAbsTime, CScript::cNull);
|
|
|
|
CBotProgram::AddFunction("deletefile",rDeleteFile,CScript::cString);
|
|
|
|
CBotProgram::AddFunction("pendown", rPenDown, CScript::cPenDown);
|
|
|
|
CBotProgram::AddFunction("penup", rPenUp, CScript::cNull);
|
|
|
|
CBotProgram::AddFunction("pencolor", rPenColor, CScript::cOneFloat);
|
|
|
|
CBotProgram::AddFunction("penwidth", rPenWidth, CScript::cOneFloat);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Object's destructor.
|
|
|
|
|
|
|
|
CScript::~CScript()
|
|
|
|
{
|
|
|
|
delete m_botProg;
|
2012-12-28 12:37:08 +00:00
|
|
|
m_botProg = nullptr;
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
delete m_primaryTask;
|
2012-12-28 12:37:08 +00:00
|
|
|
m_primaryTask = nullptr;
|
|
|
|
|
|
|
|
delete[] m_script;
|
|
|
|
m_script = nullptr;
|
2012-12-26 19:58:02 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
m_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gives the script editable block of text.
|
|
|
|
|
2012-09-18 20:33:28 +00:00
|
|
|
void CScript::PutScript(Ui::CEdit* edit, const char* name)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-12-28 12:37:08 +00:00
|
|
|
if ( m_script == nullptr )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
New(edit, name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edit->SetText(m_script);
|
|
|
|
edit->SetCursor(m_cursor2, m_cursor1);
|
|
|
|
edit->ShowSelect();
|
|
|
|
}
|
|
|
|
edit->SetFocus(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The script takes a paved text.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::GetScript(Ui::CEdit* edit)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
2012-12-28 12:37:08 +00:00
|
|
|
delete[] m_script;
|
|
|
|
m_script = nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
len = edit->GetTextLength();
|
2012-12-28 12:37:08 +00:00
|
|
|
m_script = new char[len+1];
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
edit->GetText(m_script, len+1);
|
|
|
|
edit->GetCursor(m_cursor2, m_cursor1);
|
|
|
|
m_len = strlen(m_script);
|
|
|
|
|
|
|
|
if ( !CheckToken() )
|
|
|
|
{
|
|
|
|
edit->SetCursor(m_cursor2, m_cursor1);
|
|
|
|
edit->ShowSelect();
|
|
|
|
edit->SetFocus(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !Compile() )
|
|
|
|
{
|
|
|
|
edit->SetCursor(m_cursor2, m_cursor1);
|
|
|
|
edit->ShowSelect();
|
|
|
|
edit->SetFocus(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicates whether a program is compiled correctly.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bool CScript::GetCompile()
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
return m_bCompile;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicates whether the program is empty.
|
|
|
|
|
|
|
|
bool CScript::IsEmpty()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i=0 ; i<m_len ; i++ )
|
|
|
|
{
|
|
|
|
if ( m_script[i] != ' ' &&
|
|
|
|
m_script[i] != '\n' ) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks if a program does not contain the prohibited instructions
|
|
|
|
// and if it contains well at least once every mandatory instructions.
|
|
|
|
|
|
|
|
bool CScript::CheckToken()
|
|
|
|
{
|
|
|
|
CBotToken* bt;
|
|
|
|
CBotString bs;
|
|
|
|
const char* token;
|
2012-09-10 21:29:38 +00:00
|
|
|
int error, cursor1, cursor2, i;
|
2012-06-26 20:23:05 +00:00
|
|
|
char used[100];
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( !m_object->GetCheckToken() ) return true;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
m_error = 0;
|
|
|
|
m_title[0] = 0;
|
|
|
|
m_token[0] = 0;
|
|
|
|
m_bCompile = false;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
for ( i=0 ; i<m_main->GetObligatoryToken() ; i++ )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
used[i] = 0; // token not used
|
|
|
|
}
|
|
|
|
|
|
|
|
bt = CBotToken::CompileTokens(m_script, error);
|
|
|
|
while ( bt != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
bs = bt->GetString();
|
2012-06-26 20:23:05 +00:00
|
|
|
token = bs;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
cursor1 = bt->GetStart();
|
|
|
|
cursor2 = bt->GetEnd();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
i = m_main->IsObligatoryToken(token);
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( i != -1 )
|
|
|
|
{
|
|
|
|
used[i] = 1; // token used
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( !m_main->IsProhibitedToken(token) )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
m_error = ERR_PROHIBITEDTOKEN;
|
|
|
|
m_cursor1 = cursor1;
|
|
|
|
m_cursor2 = cursor2;
|
|
|
|
strcpy(m_title, "<erreur>");
|
|
|
|
CBotToken::Delete(bt);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bt = bt->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// At least once every obligatory instruction?
|
2012-09-10 21:29:38 +00:00
|
|
|
for ( i=0 ; i<m_main->GetObligatoryToken() ; i++ )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
if ( used[i] == 0 ) // token not used?
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
strcpy(m_token, m_main->GetObligatoryToken(i));
|
2012-06-26 20:23:05 +00:00
|
|
|
m_error = ERR_OBLIGATORYTOKEN;
|
|
|
|
strcpy(m_title, "<erreur>");
|
|
|
|
CBotToken::Delete(bt);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CBotToken::Delete(bt);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compile the script of a paved text.
|
|
|
|
|
|
|
|
bool CScript::Compile()
|
|
|
|
{
|
|
|
|
CBotStringArray liste;
|
|
|
|
int i;
|
|
|
|
const char* p;
|
|
|
|
|
|
|
|
m_error = 0;
|
|
|
|
m_cursor1 = 0;
|
|
|
|
m_cursor2 = 0;
|
|
|
|
m_title[0] = 0;
|
|
|
|
m_bCompile = false;
|
|
|
|
|
|
|
|
if ( IsEmpty() ) // program exist?
|
|
|
|
{
|
|
|
|
delete m_botProg;
|
|
|
|
m_botProg = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_botProg == 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
m_botProg = new CBotProgram(m_object->GetBotVar());
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_botProg->Compile(m_script, liste, this) )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( liste.GetSize() == 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
strcpy(m_title, "<sans nom>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = liste[0];
|
|
|
|
i = 0;
|
|
|
|
while ( true )
|
|
|
|
{
|
|
|
|
if ( p[i] == 0 || p[i] == '(' ) break;
|
|
|
|
if ( i >= 20 )
|
|
|
|
{
|
|
|
|
m_title[i++] = '.';
|
|
|
|
m_title[i++] = '.';
|
|
|
|
m_title[i++] = '.';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_title[i] = p[i];
|
|
|
|
i ++;
|
|
|
|
}
|
|
|
|
m_title[i] = 0;
|
|
|
|
}
|
|
|
|
m_bCompile = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_botProg->GetError(m_error, m_cursor1, m_cursor2);
|
|
|
|
if ( m_cursor1 < 0 || m_cursor1 > m_len ||
|
|
|
|
m_cursor2 < 0 || m_cursor2 > m_len )
|
|
|
|
{
|
|
|
|
m_cursor1 = 0;
|
|
|
|
m_cursor2 = 0;
|
|
|
|
}
|
|
|
|
if ( m_error == 0 )
|
|
|
|
{
|
|
|
|
m_cursor1 = m_cursor2 = 0;
|
|
|
|
}
|
|
|
|
strcpy(m_title, "<erreur>");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the title of the script.
|
|
|
|
|
|
|
|
void CScript::GetTitle(char* buffer)
|
|
|
|
{
|
|
|
|
strcpy(buffer, m_title);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Choice of mode of execution.
|
|
|
|
|
|
|
|
void CScript::SetStepMode(bool bStep)
|
|
|
|
{
|
|
|
|
m_bStepMode = bStep;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Runs the program from the beginning.
|
|
|
|
|
|
|
|
bool CScript::Run()
|
|
|
|
{
|
|
|
|
if( m_botProg == 0 ) return false;
|
2012-12-28 12:37:08 +00:00
|
|
|
if ( m_script == nullptr || m_len == 0 ) return false;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( !m_botProg->Start(m_title) ) return false;
|
|
|
|
|
|
|
|
m_object->SetRunScript(this);
|
|
|
|
m_bRun = true;
|
|
|
|
m_bContinue = false;
|
|
|
|
m_ipf = CBOT_IPF;
|
|
|
|
m_errMode = ERM_STOP;
|
|
|
|
|
|
|
|
if ( m_bStepMode ) // step by step mode?
|
|
|
|
{
|
|
|
|
Event newEvent;
|
2012-09-10 21:29:38 +00:00
|
|
|
memset(&newEvent, 0, sizeof(Event));
|
2012-06-26 20:23:05 +00:00
|
|
|
Step(newEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continues the execution of current program.
|
|
|
|
// Returns true when execution is finished.
|
|
|
|
|
|
|
|
bool CScript::Continue(const Event &event)
|
|
|
|
{
|
|
|
|
if( m_botProg == 0 ) return true;
|
|
|
|
if ( !m_bRun ) return true;
|
|
|
|
|
|
|
|
m_event = event;
|
|
|
|
|
|
|
|
if ( m_bStepMode ) // step by step mode?
|
|
|
|
{
|
|
|
|
if ( m_bContinue ) // instuction "move", "goto", etc. ?
|
|
|
|
{
|
|
|
|
if ( m_botProg->Run(m_object, 0) )
|
|
|
|
{
|
|
|
|
m_botProg->GetError(m_error, m_cursor1, m_cursor2);
|
|
|
|
if ( m_cursor1 < 0 || m_cursor1 > m_len ||
|
|
|
|
m_cursor2 < 0 || m_cursor2 > m_len )
|
|
|
|
{
|
|
|
|
m_cursor1 = 0;
|
|
|
|
m_cursor2 = 0;
|
|
|
|
}
|
|
|
|
if ( m_error == 0 )
|
|
|
|
{
|
|
|
|
m_cursor1 = m_cursor2 = 0;
|
|
|
|
}
|
|
|
|
m_bRun = false;
|
|
|
|
|
|
|
|
if ( m_error != 0 && m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
char s[100];
|
|
|
|
GetError(s);
|
2012-09-10 21:29:38 +00:00
|
|
|
m_displayText->DisplayText(s, m_object, 10.0f, Ui::TT_ERROR);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
m_engine->SetPause(true); // gives pause
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ( !m_bContinue )
|
|
|
|
{
|
|
|
|
m_engine->SetPause(true); // gives pause
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_botProg->Run(m_object, m_ipf) )
|
|
|
|
{
|
|
|
|
m_botProg->GetError(m_error, m_cursor1, m_cursor2);
|
|
|
|
if ( m_cursor1 < 0 || m_cursor1 > m_len ||
|
|
|
|
m_cursor2 < 0 || m_cursor2 > m_len )
|
|
|
|
{
|
|
|
|
m_cursor1 = 0;
|
|
|
|
m_cursor2 = 0;
|
|
|
|
}
|
|
|
|
if ( m_error == 0 )
|
|
|
|
{
|
|
|
|
m_cursor1 = m_cursor2 = 0;
|
|
|
|
}
|
|
|
|
m_bRun = false;
|
|
|
|
|
|
|
|
if ( m_error != 0 && m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
char s[100];
|
|
|
|
GetError(s);
|
2012-09-10 21:29:38 +00:00
|
|
|
m_displayText->DisplayText(s, m_object, 10.0f, Ui::TT_ERROR);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continues the execution of current program.
|
|
|
|
// Returns true when execution is finished.
|
|
|
|
|
|
|
|
bool CScript::Step(const Event &event)
|
|
|
|
{
|
|
|
|
if( m_botProg == 0 ) return true;
|
|
|
|
if ( !m_bRun ) return true;
|
|
|
|
if ( !m_bStepMode ) return false;
|
|
|
|
|
|
|
|
m_engine->SetPause(false);
|
2012-09-15 16:50:51 +00:00
|
|
|
// TODO: m_app StepSimulation??? m_engine->StepSimulation(0.01f); // advance of 10ms
|
2012-06-26 20:23:05 +00:00
|
|
|
m_engine->SetPause(true);
|
|
|
|
|
|
|
|
m_event = event;
|
|
|
|
|
|
|
|
if ( m_botProg->Run(m_object, 0) ) // step mode
|
|
|
|
{
|
|
|
|
m_botProg->GetError(m_error, m_cursor1, m_cursor2);
|
|
|
|
if ( m_cursor1 < 0 || m_cursor1 > m_len ||
|
|
|
|
m_cursor2 < 0 || m_cursor2 > m_len )
|
|
|
|
{
|
|
|
|
m_cursor1 = 0;
|
|
|
|
m_cursor2 = 0;
|
|
|
|
}
|
|
|
|
if ( m_error == 0 )
|
|
|
|
{
|
|
|
|
m_cursor1 = m_cursor2 = 0;
|
|
|
|
}
|
|
|
|
m_bRun = false;
|
|
|
|
|
|
|
|
if ( m_error != 0 && m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
char s[100];
|
|
|
|
GetError(s);
|
2012-09-10 21:29:38 +00:00
|
|
|
m_displayText->DisplayText(s, m_object, 10.0f, Ui::TT_ERROR);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_bContinue ) // instuction "move", "goto", etc. ?
|
|
|
|
{
|
|
|
|
m_engine->SetPause(false); // removes the pause
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stops the program.
|
|
|
|
|
|
|
|
void CScript::Stop()
|
|
|
|
{
|
|
|
|
if ( !m_bRun ) return;
|
|
|
|
|
|
|
|
if( m_botProg != 0 )
|
|
|
|
{
|
|
|
|
m_botProg->Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_primaryTask != 0 )
|
|
|
|
{
|
|
|
|
m_primaryTask->Abort();
|
|
|
|
delete m_primaryTask;
|
|
|
|
m_primaryTask = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_bRun = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicates whether the program runs.
|
|
|
|
|
|
|
|
bool CScript::IsRunning()
|
|
|
|
{
|
|
|
|
return m_bRun;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicates whether the program continues a step.
|
|
|
|
|
|
|
|
bool CScript::IsContinue()
|
|
|
|
{
|
|
|
|
return m_bContinue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gives the position of the cursor during the execution.
|
|
|
|
|
|
|
|
bool CScript::GetCursor(int &cursor1, int &cursor2)
|
|
|
|
{
|
|
|
|
const char* funcName;
|
|
|
|
|
|
|
|
cursor1 = cursor2 = 0;
|
|
|
|
|
|
|
|
if( m_botProg == 0 ) return false;
|
|
|
|
if ( !m_bRun ) return false;
|
|
|
|
|
|
|
|
m_botProg->GetRunPos(funcName, cursor1, cursor2);
|
|
|
|
if ( cursor1 < 0 || cursor1 > m_len ||
|
|
|
|
cursor2 < 0 || cursor2 > m_len )
|
|
|
|
{
|
|
|
|
cursor1 = 0;
|
|
|
|
cursor2 = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Put of the variables in a list.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, int &rankList)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotString bs;
|
|
|
|
CBotVar *svar, *pStatic;
|
|
|
|
char varName[100];
|
|
|
|
char buffer[100];
|
|
|
|
const char *p;
|
|
|
|
int index, type;
|
|
|
|
|
|
|
|
if ( var == 0 && baseName[0] != 0 )
|
|
|
|
{
|
|
|
|
sprintf(buffer, "%s = null;", baseName);
|
|
|
|
list->SetName(rankList++, buffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
while ( var != 0 )
|
|
|
|
{
|
|
|
|
var->Maj(NULL, false);
|
2012-09-10 21:29:38 +00:00
|
|
|
pStatic = var->GetStaticVar(); // finds the static element
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bs = pStatic->GetName(); // variable name
|
2012-06-26 20:23:05 +00:00
|
|
|
p = bs;
|
|
|
|
//? if ( strcmp(p, "this") == 0 )
|
|
|
|
//? {
|
2012-09-10 21:29:38 +00:00
|
|
|
//? var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
//? continue;
|
|
|
|
//? }
|
|
|
|
|
|
|
|
if ( baseName[0] == 0 )
|
|
|
|
{
|
|
|
|
sprintf(varName, "%s", p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( bArray )
|
|
|
|
{
|
|
|
|
sprintf(varName, "%s[%d]", baseName, index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(varName, "%s.%s", baseName, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
type = pStatic->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
if ( type < CBotTypBoolean )
|
|
|
|
{
|
|
|
|
CBotString value;
|
2012-09-10 21:29:38 +00:00
|
|
|
value = pStatic->GetValString();
|
2012-06-26 20:23:05 +00:00
|
|
|
p = value;
|
|
|
|
sprintf(buffer, "%s = %s;", varName, p);
|
|
|
|
list->SetName(rankList++, buffer);
|
|
|
|
}
|
|
|
|
else if ( type == CBotTypString )
|
|
|
|
{
|
|
|
|
CBotString value;
|
2012-09-10 21:29:38 +00:00
|
|
|
value = pStatic->GetValString();
|
2012-06-26 20:23:05 +00:00
|
|
|
p = value;
|
|
|
|
sprintf(buffer, "%s = \"%s\";", varName, p);
|
|
|
|
list->SetName(rankList++, buffer);
|
|
|
|
}
|
|
|
|
else if ( type == CBotTypArrayPointer )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
svar = pStatic->GetItemList();
|
2012-06-26 20:23:05 +00:00
|
|
|
PutList(varName, true, svar, list, rankList);
|
|
|
|
}
|
|
|
|
else if ( type == CBotTypClass ||
|
|
|
|
type == CBotTypPointer )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
svar = pStatic->GetItemList();
|
2012-06-26 20:23:05 +00:00
|
|
|
PutList(varName, false, svar, list, rankList);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(buffer, "%s = ?;", varName);
|
|
|
|
list->SetName(rankList++, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
index ++;
|
2012-09-10 21:29:38 +00:00
|
|
|
var = var->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fills a list with variables.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
void CScript::UpdateList(Ui::CList* list)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotVar *var;
|
|
|
|
const char *progName, *funcName;
|
|
|
|
int total, select, level, cursor1, cursor2, rank;
|
|
|
|
|
|
|
|
if( m_botProg == 0 ) return;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
total = list->GetTotal();
|
|
|
|
select = list->GetSelect();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
list->Flush(); // empty list
|
|
|
|
m_botProg->GetRunPos(progName, cursor1, cursor2);
|
|
|
|
if ( progName == 0 ) return;
|
|
|
|
|
|
|
|
level = 0;
|
|
|
|
rank = 0;
|
|
|
|
while ( true )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
var = m_botProg->GetStackVars(funcName, level--);
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( funcName != progName ) break;
|
|
|
|
|
|
|
|
PutList("", false, var, list, rank);
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( total == list->GetTotal() ) // same total?
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
list->SetSelect(select);
|
|
|
|
}
|
|
|
|
|
|
|
|
list->SetTooltip("");
|
2012-09-10 21:29:38 +00:00
|
|
|
list->SetState(Ui::STATE_ENABLE);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Colorize the text according to syntax.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
void CScript::ColorizeScript(Ui::CEdit* edit)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
CBotToken* bt;
|
|
|
|
CBotString bs;
|
|
|
|
const char* token;
|
2012-09-10 21:29:38 +00:00
|
|
|
int error, type, cursor1, cursor2;
|
|
|
|
Gfx::FontHighlight color;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
edit->ClearFormat();
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bt = CBotToken::CompileTokens(edit->GetText(), error);
|
2012-06-26 20:23:05 +00:00
|
|
|
while ( bt != 0 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
bs = bt->GetString();
|
2012-06-26 20:23:05 +00:00
|
|
|
token = bs;
|
2012-09-10 21:29:38 +00:00
|
|
|
type = bt->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
cursor1 = bt->GetStart();
|
|
|
|
cursor2 = bt->GetEnd();
|
|
|
|
color = Gfx::FONT_HIGHLIGHT_NONE;
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( type >= TokenKeyWord && type < TokenKeyWord+100 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color = Gfx::FONT_HIGHLIGHT_TOKEN;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
if ( type >= TokenKeyDeclare && type < TokenKeyDeclare+100 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color = Gfx::FONT_HIGHLIGHT_TYPE;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
if ( type >= TokenKeyVal && type < TokenKeyVal+100 )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color = Gfx::FONT_HIGHLIGHT_CONST;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
if ( type == TokenTypVar )
|
|
|
|
{
|
|
|
|
if ( IsType(token) )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color = Gfx::FONT_HIGHLIGHT_TYPE;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
else if ( IsFunction(token) )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color = Gfx::FONT_HIGHLIGHT_TOKEN;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( type == TokenTypDef )
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
color =Gfx::FONT_HIGHLIGHT_CONST;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2013-02-09 20:00:07 +00:00
|
|
|
if ( cursor1 < cursor2 && color != Gfx::FONT_HIGHLIGHT_NONE )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
edit->SetFormat(cursor1, cursor2, color);
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
bt = bt->GetNext();
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CBotToken::Delete(bt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Seeks a token at random in a script.
|
|
|
|
// Returns the index of the start of the token found, or -1.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
|
|
|
|
int SearchToken(char* script, const char* token)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
int lScript, lToken, i, iFound;
|
|
|
|
int found[100];
|
|
|
|
char* p;
|
|
|
|
|
|
|
|
lScript = strlen(script);
|
|
|
|
lToken = strlen(token);
|
|
|
|
iFound = 0;
|
|
|
|
for ( i=0 ; i<lScript-lToken ; i++ )
|
|
|
|
{
|
|
|
|
p = strstr(script+i, token);
|
|
|
|
if ( p != 0 )
|
|
|
|
{
|
|
|
|
found[iFound++] = p-script;
|
|
|
|
if ( iFound >= 100 ) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( iFound == 0 ) return -1;
|
|
|
|
return found[rand()%iFound];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Removes a token in a script.
|
|
|
|
|
|
|
|
void DeleteToken(char* script, int pos, int len)
|
|
|
|
{
|
|
|
|
while ( true )
|
|
|
|
{
|
|
|
|
script[pos] = script[pos+len];
|
|
|
|
if ( script[pos++] == 0 ) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inserts a token in a script.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
void InsertToken(char* script, int pos, const char* token)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
int lScript, lToken, i;
|
|
|
|
|
|
|
|
lScript = strlen(script);
|
|
|
|
lToken = strlen(token);
|
|
|
|
for ( i=lScript ; i>=pos ; i-- )
|
|
|
|
{
|
|
|
|
script[i+lToken] = script[i];
|
|
|
|
}
|
|
|
|
memcpy(script+pos, token, lToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Introduces a virus into a program.
|
|
|
|
|
|
|
|
bool CScript::IntroduceVirus()
|
|
|
|
{
|
|
|
|
int i, start, iFound;
|
|
|
|
int found[11*2];
|
|
|
|
char* newScript;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
const char* names[11*2] =
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
"==", "!=",
|
|
|
|
"!=", "==",
|
|
|
|
">", "<",
|
|
|
|
"<", ">",
|
|
|
|
"true", "false",
|
|
|
|
"false", "true",
|
|
|
|
"grab", "drop",
|
|
|
|
"drop", "grab",
|
|
|
|
"InFront", "Behind",
|
|
|
|
"Behind", "EnergyCell",
|
|
|
|
"EnergyCell", "InFront",
|
|
|
|
};
|
|
|
|
|
|
|
|
iFound = 0;
|
|
|
|
for ( i=0 ; i<11 ; i++ )
|
|
|
|
{
|
|
|
|
start = SearchToken(m_script, names[i*2]);
|
|
|
|
if ( start != -1 )
|
|
|
|
{
|
|
|
|
found[iFound++] = i*2;
|
|
|
|
found[iFound++] = start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( iFound == 0 ) return false;
|
|
|
|
|
|
|
|
i = (rand()%(iFound/2))*2;
|
|
|
|
start = found[i+1];
|
|
|
|
i = found[i+0];
|
|
|
|
|
2012-12-28 12:37:08 +00:00
|
|
|
newScript = new char[m_len+strlen(names[i+1])+1];
|
2012-06-26 20:23:05 +00:00
|
|
|
strcpy(newScript, m_script);
|
2012-12-28 12:37:08 +00:00
|
|
|
delete[] m_script;
|
2012-06-26 20:23:05 +00:00
|
|
|
m_script = newScript;
|
|
|
|
|
|
|
|
DeleteToken(m_script, start, strlen(names[i]));
|
|
|
|
InsertToken(m_script, start, names[i+1]);
|
|
|
|
m_len = strlen(m_script);
|
|
|
|
Compile(); // recompile with the virus
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the number of the error.
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
int CScript::GetError()
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
return m_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the text of the error.
|
|
|
|
|
|
|
|
void CScript::GetError(char* buffer)
|
|
|
|
{
|
|
|
|
if ( m_error == 0 )
|
|
|
|
{
|
|
|
|
buffer[0] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( m_error == ERR_OBLIGATORYTOKEN )
|
|
|
|
{
|
|
|
|
char s[100];
|
|
|
|
GetResource(RES_ERR, m_error, s);
|
|
|
|
sprintf(buffer, s, m_token);
|
|
|
|
}
|
|
|
|
else if ( m_error < 1000 )
|
|
|
|
{
|
|
|
|
GetResource(RES_ERR, m_error, buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetResource(RES_CBOT, m_error, buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// New program.
|
|
|
|
|
2012-09-18 20:33:28 +00:00
|
|
|
void CScript::New(Ui::CEdit* edit, const char* name)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
FILE *file = NULL;
|
|
|
|
char res[100];
|
|
|
|
char text[100];
|
|
|
|
char script[500];
|
|
|
|
char buffer[500];
|
|
|
|
char *sf;
|
|
|
|
int cursor1, cursor2, len, i, j;
|
|
|
|
|
|
|
|
GetResource(RES_TEXT, RT_SCRIPT_NEW, res);
|
|
|
|
if ( name[0] == 0 ) strcpy(text, res);
|
|
|
|
else strcpy(text, name);
|
|
|
|
|
|
|
|
sprintf(script, "extern void object::%s()\n{\n\t\n\t\n\t\n}\n", text);
|
|
|
|
edit->SetText(script, false);
|
|
|
|
|
|
|
|
if ( strcmp(text, res) == 0 )
|
|
|
|
{
|
|
|
|
cursor1 = 20;
|
|
|
|
cursor2 = 20+strlen(text); // update "New"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( edit->GetAutoIndent() )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
cursor1 = 20+strlen(text)+6;
|
|
|
|
cursor2 = cursor1; // cursor in { }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cursor1 = 20+strlen(text)+8;
|
|
|
|
cursor2 = cursor1; // cursor in { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
edit->SetCursor(cursor2, cursor1);
|
|
|
|
edit->ShowSelect();
|
|
|
|
edit->SetFocus(true);
|
2012-06-26 21:01:17 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
sf = m_main->GetScriptFile();
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( sf[0] != 0 ) // Load an empty program specific?
|
|
|
|
{
|
2012-09-29 18:27:23 +00:00
|
|
|
std::string filename = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, sf);
|
|
|
|
file = fopen(filename.c_str(), "rb");
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( file != NULL )
|
|
|
|
{
|
|
|
|
fseek(file, 0, SEEK_END);
|
|
|
|
len = ftell(file);
|
|
|
|
fseek(file, 0, SEEK_SET);
|
|
|
|
|
|
|
|
if ( len > 500-1 ) len = 500-1;
|
|
|
|
fread(buffer, 1, len, file);
|
|
|
|
buffer[len] = 0;
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
cursor1 = 0;
|
|
|
|
i = 0;
|
|
|
|
j = 0;
|
|
|
|
while ( true )
|
|
|
|
{
|
|
|
|
if ( buffer[i] == 0 ) break;
|
|
|
|
|
|
|
|
if ( buffer[i] == '\r' )
|
|
|
|
{
|
|
|
|
i ++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( buffer[i] == '\t' && edit->GetAutoIndent() )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
i ++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( buffer[i+0] == '%' &&
|
|
|
|
buffer[i+1] == 's' )
|
|
|
|
{
|
|
|
|
strcpy(script+j, text);
|
|
|
|
j += strlen(text);
|
|
|
|
i += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( buffer[i] == '#' )
|
|
|
|
{
|
|
|
|
cursor1 = j;
|
|
|
|
i ++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
script[j++] = buffer[i++];
|
|
|
|
}
|
|
|
|
script[j] = 0;
|
|
|
|
edit->SetText(script, false);
|
|
|
|
|
|
|
|
cursor2 = cursor1;
|
|
|
|
edit->SetCursor(cursor2, cursor1);
|
|
|
|
edit->ShowSelect();
|
|
|
|
edit->SetFocus(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorizeScript(edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Provided a script for all parts.
|
|
|
|
|
|
|
|
bool CScript::SendScript(char* text)
|
|
|
|
{
|
|
|
|
m_len = strlen(text);
|
2012-12-28 12:37:08 +00:00
|
|
|
m_script = new char[m_len+1];
|
2012-06-26 20:23:05 +00:00
|
|
|
strcpy(m_script, text);
|
|
|
|
if ( !CheckToken() ) return false;
|
|
|
|
if ( !Compile() ) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reads a script as a text file.
|
|
|
|
|
2012-09-15 16:50:51 +00:00
|
|
|
bool CScript::ReadScript(const char* filename)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
FILE* file;
|
2012-09-10 21:29:38 +00:00
|
|
|
Ui::CEdit* edit;
|
2012-10-11 21:09:29 +00:00
|
|
|
std::string name;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-10-11 21:09:29 +00:00
|
|
|
if ( strchr(filename, '/') == 0 ) //we're reading non user script
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-10-11 21:09:29 +00:00
|
|
|
name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-11 21:09:29 +00:00
|
|
|
name = filename;
|
|
|
|
//TODO: is this needed?
|
|
|
|
// UserDir(name, filename, "");
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-29 18:27:23 +00:00
|
|
|
file = fopen(name.c_str(), "rb");
|
2012-06-26 20:23:05 +00:00
|
|
|
if ( file == NULL ) return false;
|
|
|
|
fclose(file);
|
|
|
|
|
2012-12-28 12:37:08 +00:00
|
|
|
delete[] m_script;
|
|
|
|
m_script = nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9);
|
2012-09-10 21:29:38 +00:00
|
|
|
edit->SetMaxChar(Ui::EDITSTUDIOMAX);
|
|
|
|
edit->SetAutoIndent(m_engine->GetEditIndentMode());
|
2012-09-29 18:27:23 +00:00
|
|
|
edit->ReadText(name.c_str());
|
2012-06-26 20:23:05 +00:00
|
|
|
GetScript(edit);
|
|
|
|
m_interface->DeleteControl(EVENT_EDIT9);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Writes a script as a text file.
|
|
|
|
|
2012-09-15 16:50:51 +00:00
|
|
|
bool CScript::WriteScript(const char* filename)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-09-10 21:29:38 +00:00
|
|
|
Ui::CEdit* edit;
|
2012-10-11 21:09:29 +00:00
|
|
|
std::string name;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-10-11 21:09:29 +00:00
|
|
|
if ( strchr(filename, '/') == 0 ) //we're writing non user script
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-10-11 21:09:29 +00:00
|
|
|
name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-11 21:09:29 +00:00
|
|
|
name = filename;
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-12-28 12:37:08 +00:00
|
|
|
if ( m_script == nullptr )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-10-11 21:09:29 +00:00
|
|
|
remove(filename);
|
2012-06-26 20:23:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9);
|
2012-09-10 21:29:38 +00:00
|
|
|
edit->SetMaxChar(Ui::EDITSTUDIOMAX);
|
|
|
|
edit->SetAutoIndent(m_engine->GetEditIndentMode());
|
2012-06-26 20:23:05 +00:00
|
|
|
edit->SetText(m_script);
|
2012-09-29 18:27:23 +00:00
|
|
|
edit->WriteText(name.c_str());
|
2012-06-26 20:23:05 +00:00
|
|
|
m_interface->DeleteControl(EVENT_EDIT9);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Reads a stack of script by execution as a file.
|
|
|
|
|
|
|
|
bool CScript::ReadStack(FILE *file)
|
|
|
|
{
|
|
|
|
int nb;
|
|
|
|
|
|
|
|
fRead(&nb, sizeof(int), 1, file);
|
|
|
|
fRead(&m_ipf, sizeof(int), 1, file);
|
|
|
|
fRead(&m_errMode, sizeof(int), 1, file);
|
|
|
|
|
|
|
|
if ( m_botProg == 0 ) return false;
|
|
|
|
if ( !m_botProg->RestoreState(file) ) return false;
|
2012-06-26 21:01:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
m_object->SetRunScript(this);
|
|
|
|
m_bRun = true;
|
|
|
|
m_bContinue = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Writes a stack of script by execution as a file.
|
|
|
|
|
|
|
|
bool CScript::WriteStack(FILE *file)
|
|
|
|
{
|
|
|
|
int nb;
|
|
|
|
|
|
|
|
nb = 2;
|
|
|
|
fWrite(&nb, sizeof(int), 1, file);
|
|
|
|
fWrite(&m_ipf, sizeof(int), 1, file);
|
|
|
|
fWrite(&m_errMode, sizeof(int), 1, file);
|
|
|
|
|
|
|
|
return m_botProg->SaveState(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compares two scripts.
|
|
|
|
|
|
|
|
bool CScript::Compare(CScript* other)
|
|
|
|
{
|
|
|
|
if ( m_len != other->m_len ) return false;
|
|
|
|
|
|
|
|
return ( strcmp(m_script, other->m_script) == 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Management of the file name when the script is saved.
|
|
|
|
|
|
|
|
void CScript::SetFilename(char *filename)
|
|
|
|
{
|
|
|
|
strcpy(m_filename, filename);
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
char* CScript::GetFilename()
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
return m_filename;
|
|
|
|
}
|
|
|
|
|