2014-12-20 17:45:46 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
2021-09-11 13:52:34 +00:00
|
|
|
* Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam
|
2015-08-22 14:40:02 +00:00
|
|
|
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
2014-12-20 17:45:46 +00:00
|
|
|
*
|
|
|
|
* 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://gnu.org/licenses
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script/scriptfunc.h"
|
|
|
|
|
2015-11-22 17:29:25 +00:00
|
|
|
#include "CBot/CBot.h"
|
2015-11-15 16:37:53 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
#include "app/app.h"
|
|
|
|
|
2015-08-15 12:02:07 +00:00
|
|
|
#include "common/global.h"
|
2015-07-05 11:00:48 +00:00
|
|
|
#include "common/logger.h"
|
2015-08-02 11:09:48 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
#include "common/resources/inputstream.h"
|
2015-07-19 20:34:41 +00:00
|
|
|
#include "common/resources/outputstream.h"
|
2014-12-20 17:45:46 +00:00
|
|
|
#include "common/resources/resourcemanager.h"
|
|
|
|
|
2022-02-26 02:53:39 +00:00
|
|
|
#include "graphics/engine/engine.h"
|
2014-12-20 17:45:46 +00:00
|
|
|
#include "graphics/engine/terrain.h"
|
|
|
|
#include "graphics/engine/water.h"
|
|
|
|
|
2015-08-13 09:47:32 +00:00
|
|
|
#include "level/robotmain.h"
|
|
|
|
|
|
|
|
#include "level/parser/parser.h"
|
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
#include "math/all.h"
|
|
|
|
|
|
|
|
#include "object/object.h"
|
2015-06-20 18:02:40 +00:00
|
|
|
#include "object/object_manager.h"
|
2014-12-20 17:45:46 +00:00
|
|
|
|
|
|
|
#include "object/auto/auto.h"
|
|
|
|
#include "object/auto/autobase.h"
|
2015-08-02 11:09:48 +00:00
|
|
|
#include "object/auto/autofactory.h"
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2015-08-13 16:54:44 +00:00
|
|
|
#include "object/interface/destroyable_object.h"
|
2015-08-10 16:16:00 +00:00
|
|
|
#include "object/interface/programmable_object.h"
|
2015-08-10 11:46:39 +00:00
|
|
|
#include "object/interface/task_executor_object.h"
|
2015-08-13 08:49:26 +00:00
|
|
|
#include "object/interface/trace_drawing_object.h"
|
2015-08-10 11:46:39 +00:00
|
|
|
|
2015-08-17 11:19:21 +00:00
|
|
|
#include "object/subclass/base_alien.h"
|
2015-08-02 11:09:48 +00:00
|
|
|
#include "object/subclass/exchange_post.h"
|
2015-08-17 12:06:31 +00:00
|
|
|
#include "object/subclass/shielder.h"
|
2015-08-02 11:09:48 +00:00
|
|
|
|
2015-08-17 09:44:05 +00:00
|
|
|
#include "object/task/taskinfo.h"
|
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
#include "physics/physics.h"
|
|
|
|
|
|
|
|
#include "script/cbottoken.h"
|
|
|
|
#include "script/script.h"
|
|
|
|
|
|
|
|
#include "sound/sound.h"
|
|
|
|
|
|
|
|
#include "ui/displaytext.h"
|
|
|
|
|
2022-09-14 23:14:29 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2015-12-26 13:19:24 +00:00
|
|
|
using namespace CBot;
|
2015-06-25 17:05:56 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotTypResult CScriptFunctions::cClassNull(CBotVar* thisclass, CBotVar* &var)
|
|
|
|
{
|
2015-12-20 17:35:52 +00:00
|
|
|
return cNull(var, nullptr);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cClassOneFloat(CBotVar* thisclass, CBotVar* &var)
|
|
|
|
{
|
2015-12-20 17:35:52 +00:00
|
|
|
return cOneFloat(var, nullptr);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 06:01:42 +00:00
|
|
|
// Compile a parameter of type "point".
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2018-04-20 09:20:56 +00:00
|
|
|
static CBotTypResult cPoint(CBotVar* &var, void* user)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() <= CBotTypDouble )
|
|
|
|
{
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
//? if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
//? if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
//? var = var->GetNext();
|
|
|
|
return CBotTypResult(0);
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() == CBotTypClass )
|
|
|
|
{
|
|
|
|
if ( !var->IsElemOfClass("point") ) return CBotTypResult(CBotErrBadParam);
|
|
|
|
var = var->GetNext();
|
|
|
|
return CBotTypResult(0);
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotErrBadParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compiling a procedure with a single "point".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cOnePoint(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gives a parameter of type "point".
|
|
|
|
|
2022-01-03 23:11:20 +00:00
|
|
|
static bool GetPoint(CBotVar* &var, int& exception, glm::vec3& pos)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
CBotVar *pX, *pY, *pZ;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() <= CBotTypDouble )
|
|
|
|
{
|
|
|
|
pos.x = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
pos.z = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
pos.y = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pX = var->GetItem("x");
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( pX == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
exception = CBotErrUndefItem; return true;
|
|
|
|
}
|
|
|
|
pos.x = pX->GetValFloat()*g_unit;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
pY = var->GetItem("y");
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( pY == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
exception = CBotErrUndefItem; return true;
|
|
|
|
}
|
|
|
|
pos.z = pY->GetValFloat()*g_unit; // attention y -> z !
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
pZ = var->GetItem("z");
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( pZ == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
exception = CBotErrUndefItem; return true;
|
|
|
|
}
|
|
|
|
pos.y = pZ->GetValFloat()*g_unit; // attention z -> y !
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "endmission(result, delay)"
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cEndMission(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "endmission(result, delay)"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rEndMission(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
Error ended;
|
|
|
|
float delay;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-13 16:53:56 +00:00
|
|
|
ended = static_cast<Error>(var->GetValInt());
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
delay = var->GetValFloat();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2016-04-08 18:56:09 +00:00
|
|
|
CRobotMain::GetInstancePointer()->SetMissionResultFromScript(ended, delay);
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "playmusic(filename, repeat)"
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cPlayMusic(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "playmusic(filename, repeat)"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
std::string filename;
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string cbs;
|
2014-12-20 17:45:46 +00:00
|
|
|
bool repeat;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
cbs = var->GetValString();
|
|
|
|
filename = std::string(cbs);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
repeat = var->GetValInt();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CApplication::GetInstancePointer()->GetSound()->StopMusic();
|
|
|
|
CApplication::GetInstancePointer()->GetSound()->PlayMusic(filename, repeat);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "stopmusic()"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rStopMusic(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
CApplication::GetInstancePointer()->GetSound()->StopMusic();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "getbuild()"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rGetBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-07-13 15:38:19 +00:00
|
|
|
result->SetValInt(CRobotMain::GetInstancePointer()->GetEnableBuild());
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "getresearchenable()"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rGetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-07-13 15:38:19 +00:00
|
|
|
result->SetValInt(CRobotMain::GetInstancePointer()->GetEnableResearch());
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "getresearchdone()"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rGetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2015-07-13 16:53:56 +00:00
|
|
|
result->SetValInt(CRobotMain::GetInstancePointer()->GetDoneResearch(pThis->GetTeam()));
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "setbuild()"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rSetBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-07-13 15:38:19 +00:00
|
|
|
CRobotMain::GetInstancePointer()->SetEnableBuild(var->GetValInt());
|
2014-12-20 17:45:46 +00:00
|
|
|
CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "setresearchenable()"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rSetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-07-13 15:38:19 +00:00
|
|
|
CRobotMain::GetInstancePointer()->SetEnableResearch(var->GetValInt());
|
2014-12-20 17:45:46 +00:00
|
|
|
CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "setresearchdone()"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rSetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2015-07-13 16:53:56 +00:00
|
|
|
CRobotMain::GetInstancePointer()->SetDoneResearch(var->GetValInt(), pThis->GetTeam());
|
2014-12-20 17:45:46 +00:00
|
|
|
CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "retobject(rank)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cGetObject(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypPointer, "object");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "retobjectbyid(rank)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rGetObjectById(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
CObject* pObj;
|
|
|
|
int rank;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
rank = var->GetValInt();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 18:09:53 +00:00
|
|
|
pObj = static_cast<CObject*>(CObjectManager::GetInstancePointer()->GetObjectById(rank));
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( pObj == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
result->SetPointer(nullptr);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->SetPointer(pObj->GetBotVar());
|
|
|
|
}
|
2015-07-12 13:09:32 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "retobject(rank)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
CObject* pObj;
|
|
|
|
int rank;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
rank = var->GetValInt();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-21 16:06:55 +00:00
|
|
|
pObj = CObjectManager::GetInstancePointer()->GetObjectByRank(rank);
|
|
|
|
if ( pObj == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
result->SetPointer(nullptr);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->SetPointer(pObj->GetBotVar());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
// Compilation of instruction "isbusy( object )"
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cIsBusy(CBot::CBotVar* &var, void* user)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2017-11-17 11:00:49 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypBoolean);
|
|
|
|
}
|
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
// Instruction "isbusy( object )"
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
bool CScriptFunctions::rIsBusy(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2015-07-13 16:53:56 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
CObject* obj = static_cast<CObject*>(var->GetUserPtr());
|
|
|
|
if (obj == nullptr)
|
|
|
|
{
|
|
|
|
exception = ERR_WRONG_OBJ;
|
|
|
|
result->SetValInt(ERR_WRONG_OBJ);
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-15 18:29:48 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CAuto* automat = obj->GetAuto();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-13 16:53:56 +00:00
|
|
|
if ( pThis->GetTeam() != obj->GetTeam() && obj->GetTeam() != 0 )
|
|
|
|
{
|
|
|
|
exception = ERR_ENEMY_OBJECT;
|
|
|
|
result->SetValInt(ERR_ENEMY_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( automat != nullptr )
|
|
|
|
result->SetValInt(automat->GetBusy());
|
|
|
|
else
|
|
|
|
exception = ERR_WRONG_OBJ;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
bool CScriptFunctions::rDestroy(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2015-07-13 16:53:56 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-11-30 19:41:44 +00:00
|
|
|
CObject* obj;
|
|
|
|
if (var == nullptr)
|
|
|
|
obj = CObjectManager::GetInstancePointer()->FindNearest(pThis, OBJECT_DESTROYER);
|
|
|
|
else
|
|
|
|
obj = static_cast<CObject*>(var->GetUserPtr());
|
2020-06-16 19:02:52 +00:00
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
if (obj == nullptr)
|
|
|
|
{
|
|
|
|
exception = ERR_WRONG_OBJ;
|
|
|
|
result->SetValInt(ERR_WRONG_OBJ);
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-15 18:29:48 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CAuto* automat = obj->GetAuto();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-13 16:53:56 +00:00
|
|
|
if ( pThis->GetTeam() != obj->GetTeam() && obj->GetTeam() != 0 )
|
|
|
|
{
|
|
|
|
exception = ERR_ENEMY_OBJECT;
|
|
|
|
result->SetValInt(ERR_ENEMY_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-19 19:53:08 +00:00
|
|
|
if ( obj->GetType() == OBJECT_DESTROYER )
|
2014-12-20 17:45:46 +00:00
|
|
|
err = automat->StartAction(0);
|
2015-06-25 17:05:56 +00:00
|
|
|
else
|
2014-12-20 17:45:46 +00:00
|
|
|
err = ERR_WRONG_OBJ;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-05-22 09:10:35 +00:00
|
|
|
result->SetValInt(err); // indicates the error or ok
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-07-13 16:53:56 +00:00
|
|
|
if ( script->m_errMode == ERM_STOP )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
// Compilation of instruction "factory(cat[, program , object])"
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2017-11-17 10:32:50 +00:00
|
|
|
CBotTypResult CScriptFunctions::cFactory(CBotVar* &var, void* user)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2017-11-17 11:00:49 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2017-11-17 10:32:50 +00:00
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
2017-11-17 11:00:49 +00:00
|
|
|
if ( var->GetType() != CBotTypPointer ) return CBotTypResult(CBotErrBadParam);
|
2017-11-17 10:32:50 +00:00
|
|
|
var = var->GetNext();
|
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
// Instruction "factory(cat[, program , object])"
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2017-11-17 10:32:50 +00:00
|
|
|
bool CScriptFunctions::rFactory(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2015-07-13 16:40:13 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
ObjectType type = static_cast<ObjectType>(var->GetValInt());
|
|
|
|
var = var->GetNext();
|
2020-05-15 18:29:48 +00:00
|
|
|
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string program;
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2017-11-17 11:00:49 +00:00
|
|
|
{
|
2015-12-20 15:19:10 +00:00
|
|
|
program = var->GetValString();
|
2017-11-17 11:00:49 +00:00
|
|
|
var = var->GetNext();
|
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
else
|
|
|
|
program = "";
|
2020-05-15 18:29:48 +00:00
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
CObject* factory;
|
|
|
|
if (var == nullptr)
|
|
|
|
factory = CObjectManager::GetInstancePointer()->FindNearest(pThis, OBJECT_FACTORY);
|
|
|
|
else
|
|
|
|
factory = static_cast<CObject*>(var->GetUserPtr());
|
2020-05-15 18:29:48 +00:00
|
|
|
|
2015-06-25 17:05:56 +00:00
|
|
|
if (factory == nullptr)
|
|
|
|
{
|
2017-11-17 11:00:49 +00:00
|
|
|
exception = ERR_WRONG_OBJ;
|
|
|
|
result->SetValInt(ERR_WRONG_OBJ);
|
2014-12-20 17:45:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-13 16:53:56 +00:00
|
|
|
if ( pThis->GetTeam() != factory->GetTeam() && factory->GetTeam() != 0 )
|
|
|
|
{
|
|
|
|
exception = ERR_ENEMY_OBJECT;
|
|
|
|
result->SetValInt(ERR_ENEMY_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-19 19:53:08 +00:00
|
|
|
if ( factory->GetType() == OBJECT_FACTORY )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
CAutoFactory* automat = static_cast<CAutoFactory*>(factory->GetAuto());
|
2015-06-25 17:05:56 +00:00
|
|
|
if (automat == nullptr)
|
|
|
|
{
|
2015-08-12 14:54:44 +00:00
|
|
|
exception = ERR_UNKNOWN;
|
|
|
|
result->SetValInt(ERR_UNKNOWN);
|
2017-11-17 10:32:50 +00:00
|
|
|
GetLogger()->Error("in factory() - automat is nullptr");
|
2014-12-20 17:45:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-13 16:13:28 +00:00
|
|
|
err = CRobotMain::GetInstancePointer()->CanFactoryError(type, factory->GetTeam());
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-13 15:38:19 +00:00
|
|
|
if ( err == ERR_OK )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( automat != nullptr )
|
|
|
|
{
|
|
|
|
err = automat->StartAction(type);
|
|
|
|
if ( err == ERR_OK ) automat->SetProgram(program);
|
|
|
|
}
|
|
|
|
else
|
2015-08-12 14:54:44 +00:00
|
|
|
err = ERR_UNKNOWN;
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err = ERR_WRONG_OBJ;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-05-22 09:10:35 +00:00
|
|
|
result->SetValInt(err); // indicates the error or ok
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-07-13 16:53:56 +00:00
|
|
|
if ( script->m_errMode == ERM_STOP )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
// Compilation of instruction "research(type[, object])"
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
CBotTypResult CScriptFunctions::cResearch(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
|
|
|
if ( var->GetType() != CBotTypPointer ) return CBotTypResult(CBotErrBadParam);
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
// Instruction "research(type[, object])"
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
bool CScriptFunctions::rResearch(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2015-07-13 16:53:56 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
ResearchType type = static_cast<ResearchType>(var->GetValInt());
|
2017-11-17 11:00:49 +00:00
|
|
|
var = var->GetNext();
|
2020-05-15 18:29:48 +00:00
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
CObject* center;
|
|
|
|
if (var == nullptr)
|
|
|
|
center = CObjectManager::GetInstancePointer()->FindNearest(pThis, OBJECT_RESEARCH);
|
|
|
|
else
|
|
|
|
center = static_cast<CObject*>(var->GetUserPtr());
|
2020-05-15 18:29:48 +00:00
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
if (center == nullptr)
|
|
|
|
{
|
|
|
|
exception = ERR_WRONG_OBJ;
|
|
|
|
result->SetValInt(ERR_WRONG_OBJ);
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-15 18:29:48 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CAuto* automat = center->GetAuto();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-13 16:53:56 +00:00
|
|
|
if ( pThis->GetTeam() != center->GetTeam() && center->GetTeam() != 0 )
|
|
|
|
{
|
|
|
|
exception = ERR_ENEMY_OBJECT;
|
|
|
|
result->SetValInt(ERR_ENEMY_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-19 19:53:08 +00:00
|
|
|
if ( center->GetType() == OBJECT_RESEARCH ||
|
|
|
|
center->GetType() == OBJECT_LABO )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
if ( type == RESEARCH_iPAW ||
|
2020-12-31 04:00:33 +00:00
|
|
|
type == RESEARCH_iGUN ||
|
|
|
|
type == RESEARCH_TARGET )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-07-19 19:53:08 +00:00
|
|
|
if ( center->GetType() != OBJECT_LABO )
|
2014-12-20 17:45:46 +00:00
|
|
|
err = ERR_WRONG_OBJ;
|
|
|
|
else
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-19 19:53:08 +00:00
|
|
|
if ( center->GetType() != OBJECT_RESEARCH )
|
2014-12-20 17:45:46 +00:00
|
|
|
err = ERR_WRONG_OBJ;
|
|
|
|
else
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
if ( ok )
|
|
|
|
{
|
2015-07-13 15:38:19 +00:00
|
|
|
bool bEnable = CRobotMain::GetInstancePointer()->IsResearchEnabled(type);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( bEnable )
|
|
|
|
{
|
|
|
|
if ( automat != nullptr )
|
|
|
|
{
|
|
|
|
err = automat->StartAction(type);
|
|
|
|
}
|
|
|
|
else
|
2015-08-12 14:54:44 +00:00
|
|
|
err = ERR_UNKNOWN;
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
err = ERR_BUILD_DISABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err = ERR_WRONG_OBJ;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-05-22 09:10:35 +00:00
|
|
|
result->SetValInt(err); // indicates the error or ok
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-07-13 16:53:56 +00:00
|
|
|
if( script->m_errMode == ERM_STOP )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-19 23:31:11 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
// Instruction "takeoff(object)"
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2017-11-17 10:32:50 +00:00
|
|
|
bool CScriptFunctions::rTakeOff(CBotVar* var, CBotVar* result, int& exception, void* user)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2015-07-13 16:53:56 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2017-11-30 19:41:44 +00:00
|
|
|
CObject* base;
|
|
|
|
if (var == nullptr)
|
|
|
|
base = CObjectManager::GetInstancePointer()->FindNearest(pThis, OBJECT_BASE);
|
|
|
|
else
|
|
|
|
base = static_cast<CObject*>(var->GetUserPtr());
|
2020-06-16 19:02:52 +00:00
|
|
|
|
2017-11-17 11:00:49 +00:00
|
|
|
if (base == nullptr)
|
|
|
|
{
|
|
|
|
exception = ERR_WRONG_OBJ;
|
|
|
|
result->SetValInt(ERR_WRONG_OBJ);
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-15 18:29:48 +00:00
|
|
|
|
2015-07-19 19:53:08 +00:00
|
|
|
CAuto* automat = base->GetAuto();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-19 19:53:08 +00:00
|
|
|
if ( pThis->GetTeam() != base->GetTeam() && base->GetTeam() != 0 )
|
2015-07-13 16:53:56 +00:00
|
|
|
{
|
|
|
|
exception = ERR_ENEMY_OBJECT;
|
|
|
|
result->SetValInt(ERR_ENEMY_OBJECT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-19 19:53:08 +00:00
|
|
|
if ( base->GetType() == OBJECT_BASE )
|
2014-12-20 17:45:46 +00:00
|
|
|
err = (static_cast<CAutoBase*>(automat))->TakeOff(false);
|
2015-06-25 17:05:56 +00:00
|
|
|
else
|
2014-12-20 17:45:46 +00:00
|
|
|
err = ERR_WRONG_OBJ;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-05-22 09:10:35 +00:00
|
|
|
result->SetValInt(err); // indicates the error or ok
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-07-13 16:53:56 +00:00
|
|
|
if ( script->m_errMode == ERM_STOP )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-13 16:54:44 +00:00
|
|
|
// Compilation of the instruction "delete(rank[, exploType])".
|
2014-12-20 17:45:46 +00:00
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cDelete(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-13 16:54:44 +00:00
|
|
|
if ( var->GetType() != CBotTypInt ) return CBotTypResult(CBotErrBadNum);
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( var->GetType() != CBotTypInt ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
2015-08-13 16:54:44 +00:00
|
|
|
// Instruction "delete(rank[, exploType])".
|
2014-12-20 17:45:46 +00:00
|
|
|
|
|
|
|
bool CScriptFunctions::rDelete(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-13 16:54:44 +00:00
|
|
|
int rank;
|
|
|
|
DestructionType exploType = DestructionType::Explosion;
|
2015-06-21 09:16:09 +00:00
|
|
|
|
2015-08-13 16:54:44 +00:00
|
|
|
rank = var->GetValInt();
|
2016-01-30 16:41:54 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-13 16:54:44 +00:00
|
|
|
exploType = static_cast<DestructionType>(var->GetValInt());
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-21 09:16:09 +00:00
|
|
|
|
|
|
|
CObject* obj = CObjectManager::GetInstancePointer()->GetObjectById(rank);
|
2020-09-14 19:19:16 +00:00
|
|
|
if ( obj == nullptr || (obj->Implements(ObjectInterfaceType::Old) && dynamic_cast<COldObject&>(*obj).IsDying()) )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-15 13:41:31 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
bool deleteSelf = (obj == script->m_object);
|
|
|
|
|
2015-08-13 16:54:44 +00:00
|
|
|
if ( exploType != DestructionType::NoEffect && obj->Implements(ObjectInterfaceType::Destroyable) )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2020-09-14 19:19:16 +00:00
|
|
|
dynamic_cast<CDestroyableObject&>(*obj).DestroyObject(static_cast<DestructionType>(exploType));
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-29 16:16:57 +00:00
|
|
|
if (obj->Implements(ObjectInterfaceType::Slotted))
|
2017-05-23 18:19:47 +00:00
|
|
|
{
|
2022-01-29 16:16:57 +00:00
|
|
|
CSlottedObject* slotted = dynamic_cast<CSlottedObject*>(obj);
|
|
|
|
for (int slotNum = slotted->GetNumSlots() - 1; slotNum >= 0; slotNum--)
|
|
|
|
{
|
|
|
|
CObject* sub = slotted->GetSlotContainedObject(slotNum);
|
|
|
|
if (sub != nullptr)
|
|
|
|
{
|
|
|
|
slotted->SetSlotContainedObject(slotNum, nullptr);
|
|
|
|
CObjectManager::GetInstancePointer()->DeleteObject(sub);
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 18:19:47 +00:00
|
|
|
}
|
2015-06-21 09:16:09 +00:00
|
|
|
CObjectManager::GetInstancePointer()->DeleteObject(obj);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2020-08-15 13:41:31 +00:00
|
|
|
// Returning "false" here makes sure the program doesn't try to keep executing
|
|
|
|
// if the robot just destroyed itself using delete(this.id)
|
|
|
|
// See issue #925
|
|
|
|
return !deleteSelf;
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2017-06-03 18:05:54 +00:00
|
|
|
|
2020-08-15 13:41:31 +00:00
|
|
|
return true;
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 09:20:56 +00:00
|
|
|
static CBotTypResult compileSearch(CBotVar* &var, void* user, CBotTypResult returnValue)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
|
|
|
{
|
2017-05-25 06:01:42 +00:00
|
|
|
CBotTypResult type = var->GetTypResult().GetTypElem();
|
|
|
|
if ( type.GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadParam); // type
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2017-05-25 06:01:42 +00:00
|
|
|
else if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // type
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-05-25 06:01:42 +00:00
|
|
|
if ( var == nullptr ) return returnValue;
|
|
|
|
|
|
|
|
CBotTypResult ret = cPoint(var, user); // pos
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
|
|
|
|
|
|
|
if ( var == nullptr ) return returnValue;
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // min
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var == nullptr ) return returnValue;
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // max
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var == nullptr ) return returnValue;
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // sense
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var == nullptr ) return returnValue;
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // filter
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var == nullptr ) return returnValue;
|
|
|
|
return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 06:01:42 +00:00
|
|
|
// Compilation of "search(type, pos, min, max, sens, filter)".
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2017-05-25 06:01:42 +00:00
|
|
|
CBotTypResult CScriptFunctions::cSearch(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
return compileSearch(var, user, CBotTypResult(CBotTypPointer, "object"));
|
|
|
|
}
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cSearchAll(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
return compileSearch(var, user, CBotTypResult(CBotTypArrayPointer, CBotTypResult(CBotTypPointer, "object")));
|
|
|
|
}
|
|
|
|
|
2022-01-03 23:11:20 +00:00
|
|
|
static bool runSearch(CBotVar* var, glm::vec3 pos, int& exception, std::function<bool(std::vector<ObjectType>, glm::vec3, float, float, bool, RadarFilter)> code)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
CBotVar* array;
|
2017-05-25 06:01:42 +00:00
|
|
|
RadarFilter filter;
|
|
|
|
float minDist, maxDist, sens;
|
2014-12-20 19:36:09 +00:00
|
|
|
int type;
|
2017-05-25 06:01:42 +00:00
|
|
|
bool bArray = false;
|
|
|
|
|
|
|
|
type = OBJECT_NULL;
|
|
|
|
array = nullptr;
|
|
|
|
minDist = 0.0f*g_unit;
|
|
|
|
maxDist = 1000.0f*g_unit;
|
|
|
|
sens = 1.0f;
|
|
|
|
filter = FILTER_NONE;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2017-05-25 06:01:42 +00:00
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
|
|
|
{
|
|
|
|
array = var->GetItemList();
|
|
|
|
bArray = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = var->GetValInt();
|
|
|
|
bArray = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
|
|
|
if ( !GetPoint(var, exception, pos) ) return false;
|
|
|
|
|
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
|
|
|
minDist = var->GetValFloat();
|
|
|
|
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
|
|
|
maxDist = var->GetValFloat();
|
|
|
|
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
|
|
|
sens = var->GetValFloat();
|
|
|
|
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
|
|
|
filter = static_cast<RadarFilter>(var->GetValInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 19:36:09 +00:00
|
|
|
std::vector<ObjectType> type_v;
|
2015-06-25 17:05:56 +00:00
|
|
|
if (bArray)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
while ( array != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2017-12-21 13:44:43 +00:00
|
|
|
if (array->GetValInt() == OBJECT_MOBILEpr)
|
|
|
|
{
|
|
|
|
type_v.push_back(OBJECT_MOBILEwt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEtt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEft);
|
|
|
|
type_v.push_back(OBJECT_MOBILEit);
|
2018-12-23 06:04:06 +00:00
|
|
|
type_v.push_back(OBJECT_MOBILErp);
|
|
|
|
type_v.push_back(OBJECT_MOBILEst);
|
2017-12-21 13:44:43 +00:00
|
|
|
}
|
2014-12-20 19:36:09 +00:00
|
|
|
type_v.push_back(static_cast<ObjectType>(array->GetValInt()));
|
|
|
|
array = array->GetNext();
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-25 17:05:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-21 13:44:43 +00:00
|
|
|
if (type != OBJECT_NULL && type != OBJECT_MOBILEpr)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2014-12-20 19:36:09 +00:00
|
|
|
type_v.push_back(static_cast<ObjectType>(type));
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2017-12-21 13:44:43 +00:00
|
|
|
else if (type == OBJECT_MOBILEpr)
|
|
|
|
{
|
|
|
|
type_v.push_back(OBJECT_MOBILEwt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEtt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEft);
|
|
|
|
type_v.push_back(OBJECT_MOBILEit);
|
2018-12-23 06:04:06 +00:00
|
|
|
type_v.push_back(OBJECT_MOBILErp);
|
|
|
|
type_v.push_back(OBJECT_MOBILEst);
|
2017-12-21 13:44:43 +00:00
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-05-25 06:01:42 +00:00
|
|
|
return code(type_v, pos, minDist, maxDist, sens < 0, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptFunctions::rSearch(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2022-01-03 23:11:20 +00:00
|
|
|
return runSearch(var, pThis->GetPosition(), exception, [&result, pThis](std::vector<ObjectType> types, glm::vec3 pos, float minDist, float maxDist, bool furthest, RadarFilter filter)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2017-05-25 06:01:42 +00:00
|
|
|
CObject* pBest = CObjectManager::GetInstancePointer()->Radar(pThis, pos, 0.0f, types, 0.0f, Math::PI*2.0f, minDist, maxDist, furthest, filter, true);
|
|
|
|
|
|
|
|
if ( pBest == nullptr )
|
|
|
|
{
|
|
|
|
result->SetPointer(nullptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->SetPointer(pBest->GetBotVar());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptFunctions::rSearchAll(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
|
|
|
|
2022-01-03 23:11:20 +00:00
|
|
|
return runSearch(var, pThis->GetPosition(), exception, [&result, pThis](std::vector<ObjectType> types, glm::vec3 pos, float minDist, float maxDist, bool furthest, RadarFilter filter)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2017-05-25 06:01:42 +00:00
|
|
|
std::vector<CObject*> best = CObjectManager::GetInstancePointer()->RadarAll(pThis, pos, 0.0f, types, 0.0f, Math::PI*2.0f, minDist, maxDist, furthest, filter, true);
|
2015-07-12 13:09:32 +00:00
|
|
|
|
2017-05-25 06:01:42 +00:00
|
|
|
int i = 0;
|
|
|
|
result->SetInit(CBotVar::InitType::DEF);
|
|
|
|
for (CObject* obj : best)
|
|
|
|
{
|
|
|
|
result->GetItem(i++, true)->SetPointer(obj->GetBotVar());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-20 09:20:56 +00:00
|
|
|
static CBotTypResult compileRadar(CBotVar* &var, void* user, CBotTypResult returnValue)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-11-22 13:10:45 +00:00
|
|
|
if ( var == nullptr ) return returnValue;
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
|
|
|
{
|
2020-05-07 22:12:50 +00:00
|
|
|
CBotTypResult type = var->GetTypResult().GetTypElem();
|
|
|
|
if ( type.GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadParam); //type
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2020-05-07 22:04:17 +00:00
|
|
|
else if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadParam); // type
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-11-22 13:10:45 +00:00
|
|
|
if ( var == nullptr ) return returnValue;
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // angle
|
|
|
|
var = var->GetNext();
|
2015-11-22 13:10:45 +00:00
|
|
|
if ( var == nullptr ) return returnValue;
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // focus
|
|
|
|
var = var->GetNext();
|
2015-11-22 13:10:45 +00:00
|
|
|
if ( var == nullptr ) return returnValue;
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // min
|
|
|
|
var = var->GetNext();
|
2015-11-22 13:10:45 +00:00
|
|
|
if ( var == nullptr ) return returnValue;
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // max
|
|
|
|
var = var->GetNext();
|
2015-11-22 13:10:45 +00:00
|
|
|
if ( var == nullptr ) return returnValue;
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // sense
|
|
|
|
var = var->GetNext();
|
2015-11-22 13:10:45 +00:00
|
|
|
if ( var == nullptr ) return returnValue;
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // filter
|
|
|
|
var = var->GetNext();
|
2015-11-22 13:10:45 +00:00
|
|
|
if ( var == nullptr ) return returnValue;
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
2015-11-22 13:10:45 +00:00
|
|
|
CBotTypResult CScriptFunctions::cRadarAll(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
return compileRadar(var, user, CBotTypResult(CBotTypArrayPointer, CBotTypResult(CBotTypPointer, "object")));
|
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
|
2015-11-22 13:10:45 +00:00
|
|
|
// Compilation of instruction "radar(type, angle, focus, min, max, sens)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cRadar(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
return compileRadar(var, user, CBotTypResult(CBotTypPointer, "object"));
|
|
|
|
}
|
|
|
|
|
2018-04-20 09:20:56 +00:00
|
|
|
static bool runRadar(CBotVar* var, std::function<bool(std::vector<ObjectType>, float, float, float, float, bool, RadarFilter)> code)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
CBotVar* array;
|
|
|
|
RadarFilter filter;
|
2014-12-20 19:36:09 +00:00
|
|
|
float minDist, maxDist, sens, angle, focus;
|
|
|
|
int type;
|
2014-12-20 17:45:46 +00:00
|
|
|
bool bArray = false;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
type = OBJECT_NULL;
|
2015-08-17 20:40:52 +00:00
|
|
|
array = nullptr;
|
2014-12-20 17:45:46 +00:00
|
|
|
angle = 0.0f;
|
|
|
|
focus = Math::PI*2.0f;
|
|
|
|
minDist = 0.0f*g_unit;
|
|
|
|
maxDist = 1000.0f*g_unit;
|
|
|
|
sens = 1.0f;
|
|
|
|
filter = FILTER_NONE;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
|
|
|
{
|
|
|
|
array = var->GetItemList();
|
|
|
|
bArray = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = var->GetValInt();
|
|
|
|
bArray = false;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
angle = -var->GetValFloat()*Math::PI/180.0f;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
focus = var->GetValFloat()*Math::PI/180.0f;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-01-08 17:56:26 +00:00
|
|
|
minDist = var->GetValFloat();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-01-08 17:56:26 +00:00
|
|
|
maxDist = var->GetValFloat();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
sens = var->GetValFloat();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
filter = static_cast<RadarFilter>(var->GetValInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 19:36:09 +00:00
|
|
|
std::vector<ObjectType> type_v;
|
2015-06-25 17:05:56 +00:00
|
|
|
if (bArray)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
while ( array != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2017-12-21 00:49:56 +00:00
|
|
|
if (array->GetValInt() == OBJECT_MOBILEpr)
|
|
|
|
{
|
|
|
|
type_v.push_back(OBJECT_MOBILEwt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEtt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEft);
|
|
|
|
type_v.push_back(OBJECT_MOBILEit);
|
2018-12-23 06:04:06 +00:00
|
|
|
type_v.push_back(OBJECT_MOBILErp);
|
|
|
|
type_v.push_back(OBJECT_MOBILEst);
|
2017-12-21 00:49:56 +00:00
|
|
|
}
|
2014-12-20 19:36:09 +00:00
|
|
|
type_v.push_back(static_cast<ObjectType>(array->GetValInt()));
|
|
|
|
array = array->GetNext();
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-25 17:05:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-21 00:49:56 +00:00
|
|
|
if (type != OBJECT_NULL && type != OBJECT_MOBILEpr)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2014-12-20 19:36:09 +00:00
|
|
|
type_v.push_back(static_cast<ObjectType>(type));
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2017-12-21 00:49:56 +00:00
|
|
|
else if (type == OBJECT_MOBILEpr)
|
|
|
|
{
|
|
|
|
type_v.push_back(OBJECT_MOBILEwt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEtt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEft);
|
|
|
|
type_v.push_back(OBJECT_MOBILEit);
|
2018-12-23 06:04:06 +00:00
|
|
|
type_v.push_back(OBJECT_MOBILErp);
|
|
|
|
type_v.push_back(OBJECT_MOBILEst);
|
2017-12-21 00:49:56 +00:00
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-11-22 13:10:45 +00:00
|
|
|
return code(type_v, angle, focus, minDist, maxDist, sens < 0, filter);
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-11-22 13:10:45 +00:00
|
|
|
// Instruction "radar(type, angle, focus, min, max, sens, filter)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rRadar(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
return runRadar(var, [&result, user](std::vector<ObjectType> types, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-11-22 13:10:45 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
|
|
|
CObject* best = CObjectManager::GetInstancePointer()->Radar(pThis, types, angle, focus, minDist, maxDist, furthest, filter, true);
|
|
|
|
|
|
|
|
if (best == nullptr)
|
|
|
|
{
|
|
|
|
result->SetPointer(nullptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->SetPointer(best->GetBotVar());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptFunctions::rRadarAll(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
return runRadar(var, [&result, user](std::vector<ObjectType> types, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-11-22 13:10:45 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
|
|
|
std::vector<CObject*> best = CObjectManager::GetInstancePointer()->RadarAll(pThis, types, angle, focus, minDist, maxDist, furthest, filter, true);
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
result->SetInit(CBotVar::InitType::DEF);
|
|
|
|
for (CObject* obj : best)
|
|
|
|
{
|
|
|
|
result->GetItem(i++, true)->SetPointer(obj->GetBotVar());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Monitoring a task.
|
|
|
|
|
2015-08-15 18:29:59 +00:00
|
|
|
bool CScriptFunctions::WaitForForegroundTask(CScript* script, CBotVar* result, int &exception)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-15 18:29:59 +00:00
|
|
|
assert(script->m_taskExecutor->IsForegroundTask());
|
|
|
|
Error err = script->m_taskExecutor->GetForegroundTask()->IsEnded();
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_CONTINUE ) // task terminated?
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
script->m_bContinue = false;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err == ERR_STOP ) err = ERR_OK;
|
|
|
|
result->SetValInt(err); // indicates the error or ok
|
2015-08-15 18:29:59 +00:00
|
|
|
if ( ShouldTaskStop(err, script->m_errMode) )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true; // it's all over
|
|
|
|
}
|
|
|
|
|
|
|
|
script->m_bContinue = true;
|
|
|
|
return false; // not done
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptFunctions::WaitForBackgroundTask(CScript* script, CBotVar* result, int &exception)
|
|
|
|
{
|
|
|
|
assert(script->m_taskExecutor->IsBackgroundTask());
|
|
|
|
Error err = script->m_taskExecutor->GetBackgroundTask()->IsEnded();
|
|
|
|
if ( err != ERR_CONTINUE ) // task terminated?
|
|
|
|
{
|
|
|
|
script->m_taskExecutor->StopBackgroundTask();
|
|
|
|
|
|
|
|
script->m_bContinue = false;
|
|
|
|
|
|
|
|
if ( err == ERR_STOP ) err = ERR_OK;
|
|
|
|
result->SetValInt(err); // indicates the error or ok
|
|
|
|
if ( ShouldTaskStop(err, script->m_errMode) )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true; // it's all over
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
script->m_bContinue = true;
|
|
|
|
return false; // not done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns true if error code means real error and exception must be thrown
|
|
|
|
|
2015-08-15 18:29:59 +00:00
|
|
|
bool CScriptFunctions::ShouldTaskStop(Error err, int errMode)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
// aim impossible - not a real error
|
|
|
|
if ( err == ERR_AIM_IMPOSSIBLE )
|
|
|
|
return false;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK && errMode == ERM_STOP )
|
|
|
|
return true;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "detect(type)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cDetect(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypBoolean);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "detect(type)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rDetect(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 19:36:09 +00:00
|
|
|
CObject *pBest;
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotVar* array;
|
2014-12-20 19:36:09 +00:00
|
|
|
int type;
|
2014-12-20 17:45:46 +00:00
|
|
|
bool bArray = false;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
type = OBJECT_NULL;
|
2015-08-17 20:40:52 +00:00
|
|
|
array = nullptr;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( var->GetType() == CBotTypArrayPointer )
|
|
|
|
{
|
|
|
|
array = var->GetItemList();
|
|
|
|
bArray = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = var->GetValInt();
|
|
|
|
bArray = false;
|
|
|
|
}
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 19:36:09 +00:00
|
|
|
std::vector<ObjectType> type_v;
|
2015-06-25 17:05:56 +00:00
|
|
|
if (bArray)
|
2014-12-20 19:36:09 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
while ( array != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2017-12-21 13:44:43 +00:00
|
|
|
if (array->GetValInt() == OBJECT_MOBILEpr)
|
|
|
|
{
|
|
|
|
type_v.push_back(OBJECT_MOBILEwt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEtt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEft);
|
|
|
|
type_v.push_back(OBJECT_MOBILEit);
|
2018-12-23 06:04:06 +00:00
|
|
|
type_v.push_back(OBJECT_MOBILErp);
|
|
|
|
type_v.push_back(OBJECT_MOBILEst);
|
2017-12-21 13:44:43 +00:00
|
|
|
}
|
2014-12-20 19:36:09 +00:00
|
|
|
type_v.push_back(static_cast<ObjectType>(array->GetValInt()));
|
|
|
|
array = array->GetNext();
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-25 17:05:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-21 13:44:43 +00:00
|
|
|
if (type != OBJECT_NULL && type != OBJECT_MOBILEpr)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2014-12-20 19:36:09 +00:00
|
|
|
type_v.push_back(static_cast<ObjectType>(type));
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2017-12-21 13:44:43 +00:00
|
|
|
else if (type == OBJECT_MOBILEpr)
|
|
|
|
{
|
|
|
|
type_v.push_back(OBJECT_MOBILEwt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEtt);
|
|
|
|
type_v.push_back(OBJECT_MOBILEft);
|
|
|
|
type_v.push_back(OBJECT_MOBILEit);
|
2018-12-23 06:04:06 +00:00
|
|
|
type_v.push_back(OBJECT_MOBILErp);
|
|
|
|
type_v.push_back(OBJECT_MOBILEst);
|
2017-12-21 13:44:43 +00:00
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 19:36:09 +00:00
|
|
|
pBest = CObjectManager::GetInstancePointer()->Radar(pThis, type_v, 0.0f, 45.0f*Math::PI/180.0f, 0.0f, 20.0f, false, FILTER_NONE, true);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-11 21:13:57 +00:00
|
|
|
if (pThis->Implements(ObjectInterfaceType::Old))
|
|
|
|
{
|
|
|
|
script->m_main->StartDetectEffect(dynamic_cast<COldObject*>(pThis), pBest);
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( pBest == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
script->m_returnValue = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
script->m_returnValue = 1.0f;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskWait(0.3f);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
if ( !WaitForForegroundTask(script, result, exception) ) return false; // not finished
|
2015-08-17 09:44:05 +00:00
|
|
|
result->SetValFloat(*script->m_returnValue);
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "direction(pos)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cDirection(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "direction(pos)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rDirection(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 iPos, oPos;
|
2014-12-20 17:45:46 +00:00
|
|
|
float a, g;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( !GetPoint(var, exception, oPos) ) return true;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-12 09:01:16 +00:00
|
|
|
iPos = pThis->GetPosition();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-14 19:29:13 +00:00
|
|
|
a = pThis->GetRotationY();
|
2014-12-20 17:45:46 +00:00
|
|
|
g = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW !
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValFloat(-Math::Direction(a, g)*180.0f/Math::PI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "canbuild ( category );"
|
|
|
|
// returns true if this building can be built
|
|
|
|
|
|
|
|
bool CScriptFunctions::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2015-07-22 15:08:51 +00:00
|
|
|
ObjectType category = static_cast<ObjectType>(var->GetValInt());
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-13 16:13:28 +00:00
|
|
|
result->SetValInt(CRobotMain::GetInstancePointer()->CanBuild(category, pThis->GetTeam()));
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-22 15:08:51 +00:00
|
|
|
bool CScriptFunctions::rCanResearch(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
ResearchType research = static_cast<ResearchType>(var->GetValInt());
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
result->SetValInt(CRobotMain::GetInstancePointer()->IsResearchEnabled(research));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptFunctions::rResearched(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2015-07-22 15:08:51 +00:00
|
|
|
ResearchType research = static_cast<ResearchType>(var->GetValInt());
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
result->SetValInt(CRobotMain::GetInstancePointer()->IsResearchDone(research, pThis->GetTeam()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptFunctions::rBuildingEnabled(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
ObjectType category = static_cast<ObjectType>(var->GetValInt());
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
result->SetValInt(CRobotMain::GetInstancePointer()->IsBuildingEnabled(category));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
// Instruction "build(type)"
|
|
|
|
// draws error if can not build (wher errormode stop), otherwise 0 <- error
|
|
|
|
|
|
|
|
bool CScriptFunctions::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
ObjectType oType;
|
|
|
|
ObjectType category;
|
2015-07-13 15:38:19 +00:00
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
oType = pThis->GetType();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-11-16 17:43:45 +00:00
|
|
|
if ( oType != OBJECT_MOBILEfb && // allowed only for builder bots && humans
|
|
|
|
oType != OBJECT_MOBILEtb &&
|
|
|
|
oType != OBJECT_MOBILEwb &&
|
|
|
|
oType != OBJECT_MOBILEib &&
|
2015-07-13 15:38:19 +00:00
|
|
|
oType != OBJECT_HUMAN &&
|
|
|
|
oType != OBJECT_TECH )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-12 14:54:44 +00:00
|
|
|
err = ERR_WRONG_BOT; // Wrong object
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
category = static_cast<ObjectType>(var->GetValInt()); // get category parameter
|
2015-07-13 16:13:28 +00:00
|
|
|
err = CRobotMain::GetInstancePointer()->CanBuildError(category, pThis->GetTeam());
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if (err == ERR_OK && !script->m_taskExecutor->IsForegroundTask()) // if we can build
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskBuild(category);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if (err != ERR_OK)
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-19 23:31:11 +00:00
|
|
|
result->SetValInt(err); // indicates the error or ok
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 01:31:17 +00:00
|
|
|
// Instruction "flag(color)"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rFlag(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
|
|
|
ObjectType oType;
|
|
|
|
int color;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() )
|
|
|
|
{
|
|
|
|
oType = pThis->GetType();
|
|
|
|
if ( oType != OBJECT_MOBILEfs && // allowed only for sniffer bots && humans
|
|
|
|
oType != OBJECT_MOBILEts &&
|
|
|
|
oType != OBJECT_MOBILEws &&
|
|
|
|
oType != OBJECT_MOBILEis &&
|
|
|
|
oType != OBJECT_HUMAN &&
|
|
|
|
oType != OBJECT_TECH )
|
|
|
|
{
|
|
|
|
err = ERR_WRONG_BOT; // Wrong object
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( var == nullptr )
|
|
|
|
{
|
|
|
|
color = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color = var->GetValInt();
|
|
|
|
if ( color < 0 || color > static_cast<int>(TraceColor::Violet) ) color = 0;
|
|
|
|
}
|
|
|
|
err = script->m_taskExecutor->StartTaskFlag(TFL_CREATE, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return WaitForForegroundTask(script, result, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "deflag()"
|
|
|
|
|
|
|
|
bool CScriptFunctions::rDeflag(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
|
|
|
ObjectType oType;
|
|
|
|
Error err;
|
|
|
|
|
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() )
|
|
|
|
{
|
|
|
|
oType = pThis->GetType();
|
|
|
|
if ( oType != OBJECT_MOBILEfs && // allowed only for sniffer bots && humans
|
|
|
|
oType != OBJECT_MOBILEts &&
|
|
|
|
oType != OBJECT_MOBILEws &&
|
|
|
|
oType != OBJECT_MOBILEis &&
|
|
|
|
oType != OBJECT_HUMAN &&
|
|
|
|
oType != OBJECT_TECH )
|
|
|
|
{
|
|
|
|
err = ERR_WRONG_BOT; // Wrong object
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err = script->m_taskExecutor->StartTaskFlag(TFL_DELETE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return WaitForForegroundTask(script, result, exception);
|
|
|
|
}
|
|
|
|
|
2021-08-23 23:21:42 +00:00
|
|
|
// Compilation of the instruction "produce(pos, angle, type[, scriptName[, power[, team]]])"
|
2014-12-20 17:45:46 +00:00
|
|
|
// or "produce(type[, power])".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cProduce(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() <= CBotTypDouble )
|
|
|
|
{
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2021-08-23 23:21:42 +00:00
|
|
|
|
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
2021-08-23 23:21:42 +00:00
|
|
|
// Instruction "produce(pos, angle, type[, scriptName[, power[, team]]])"
|
2014-12-20 17:45:46 +00:00
|
|
|
// or "produce(type[, power])".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* me = script->m_object;
|
2015-08-25 08:49:59 +00:00
|
|
|
std::string name = "";
|
2021-08-23 23:21:42 +00:00
|
|
|
|
|
|
|
ObjectCreateParams params;
|
|
|
|
params.angle = 0.0f;
|
|
|
|
params.type = OBJECT_NULL;
|
|
|
|
params.power = 0.0f;
|
|
|
|
params.team = 0;
|
2015-06-20 17:27:43 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() <= CBotTypDouble )
|
|
|
|
{
|
2021-08-23 23:21:42 +00:00
|
|
|
params.type = static_cast<ObjectType>(var->GetValInt());
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-20 17:27:43 +00:00
|
|
|
|
2021-08-23 23:21:42 +00:00
|
|
|
params.pos = me->GetPosition();
|
2015-06-20 17:27:43 +00:00
|
|
|
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 rotation = me->GetRotation() + me->GetTilt();
|
2021-08-23 23:21:42 +00:00
|
|
|
params.angle = rotation.y;
|
2015-06-20 17:27:43 +00:00
|
|
|
|
2015-06-25 17:05:56 +00:00
|
|
|
if ( var != nullptr )
|
2021-08-23 23:21:42 +00:00
|
|
|
params.power = var->GetValFloat();
|
2014-12-20 17:45:46 +00:00
|
|
|
else
|
2021-08-23 23:21:42 +00:00
|
|
|
params.power = -1.0f;
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-23 23:21:42 +00:00
|
|
|
if ( !GetPoint(var, exception, params.pos) ) return true;
|
2015-06-20 17:27:43 +00:00
|
|
|
|
2021-08-23 23:21:42 +00:00
|
|
|
params.angle = var->GetValFloat()*Math::PI/180.0f;
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-20 17:27:43 +00:00
|
|
|
|
2021-08-23 23:21:42 +00:00
|
|
|
params.type = static_cast<ObjectType>(var->GetValInt());
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-20 17:27:43 +00:00
|
|
|
|
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-12-20 15:19:10 +00:00
|
|
|
name = var->GetValString();
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-20 17:27:43 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2021-08-23 23:21:42 +00:00
|
|
|
params.power = var->GetValFloat();
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
|
|
|
params.team = var->GetValInt();
|
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-23 23:21:42 +00:00
|
|
|
params.power = -1.0f;
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-23 23:21:42 +00:00
|
|
|
params.power = -1.0f;
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-20 17:27:43 +00:00
|
|
|
|
|
|
|
CObject* object = nullptr;
|
|
|
|
|
2021-08-23 23:21:42 +00:00
|
|
|
if ( params.type == OBJECT_ANT ||
|
|
|
|
params.type == OBJECT_SPIDER ||
|
|
|
|
params.type == OBJECT_BEE ||
|
|
|
|
params.type == OBJECT_WORM )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2021-08-23 23:21:42 +00:00
|
|
|
object = CObjectManager::GetInstancePointer()->CreateObject(params);
|
2021-08-24 22:09:58 +00:00
|
|
|
params.type = OBJECT_EGG;
|
|
|
|
CObjectManager::GetInstancePointer()->CreateObject(params);
|
2015-08-10 21:20:36 +00:00
|
|
|
if (object->Implements(ObjectInterfaceType::Programmable))
|
|
|
|
{
|
2020-09-14 19:19:16 +00:00
|
|
|
dynamic_cast<CProgrammableObject&>(*object).SetActivity(false);
|
2015-08-10 21:20:36 +00:00
|
|
|
}
|
2015-06-20 17:27:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-23 23:21:42 +00:00
|
|
|
if ((params.type == OBJECT_POWER || params.type == OBJECT_ATOMIC) && params.power == -1.0f)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2021-08-23 23:21:42 +00:00
|
|
|
params.power = 1.0f;
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2021-08-23 23:21:42 +00:00
|
|
|
bool exists = IsValidObjectTypeId(params.type) && params.type != OBJECT_NULL && params.type != OBJECT_MAX && params.type != OBJECT_MOBILEpr;
|
2020-07-19 08:55:55 +00:00
|
|
|
if (exists)
|
|
|
|
{
|
2021-08-23 23:21:42 +00:00
|
|
|
object = CObjectManager::GetInstancePointer()->CreateObject(params);
|
2020-07-19 08:55:55 +00:00
|
|
|
}
|
2015-08-25 08:49:59 +00:00
|
|
|
if (object == nullptr)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
result->SetValInt(1); // error
|
|
|
|
return true;
|
|
|
|
}
|
2021-08-23 23:21:42 +00:00
|
|
|
if (params.type == OBJECT_MOBILEdr)
|
2015-07-14 11:42:47 +00:00
|
|
|
{
|
|
|
|
assert(object->Implements(ObjectInterfaceType::Old)); // TODO: temporary hack
|
2020-09-14 19:19:16 +00:00
|
|
|
dynamic_cast<COldObject&>(*object).SetManual(true);
|
2015-07-14 11:42:47 +00:00
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
script->m_main->CreateShortcuts();
|
|
|
|
}
|
2015-06-20 17:27:43 +00:00
|
|
|
|
2015-08-25 08:49:59 +00:00
|
|
|
if (!name.empty())
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-05 17:27:26 +00:00
|
|
|
std::string name2 = InjectLevelPathsForCurrentLevel(name, "ai");
|
2015-07-10 18:38:44 +00:00
|
|
|
if (object->Implements(ObjectInterfaceType::Programmable))
|
2015-03-29 12:21:02 +00:00
|
|
|
{
|
2015-08-15 19:29:08 +00:00
|
|
|
CProgramStorageObject* programStorage = dynamic_cast<CProgramStorageObject*>(object);
|
|
|
|
Program* program = programStorage->AddProgram();
|
|
|
|
programStorage->ReadProgram(program, name2.c_str());
|
2016-11-11 12:37:39 +00:00
|
|
|
program->readOnly = true;
|
2015-08-29 14:52:07 +00:00
|
|
|
program->filename = name;
|
2020-09-14 19:19:16 +00:00
|
|
|
dynamic_cast<CProgrammableObject&>(*object).RunProgram(program);
|
2015-03-29 12:21:02 +00:00
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-20 17:27:43 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(0); // no error
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "distance(p1, p2)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cDistance(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "distance(p1, p2)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rDistance(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 p1, p2;
|
2014-12-20 17:45:46 +00:00
|
|
|
float value;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( !GetPoint(var, exception, p1) ) return true;
|
|
|
|
if ( !GetPoint(var, exception, p2) ) return true;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2022-01-04 19:43:36 +00:00
|
|
|
value = glm::distance(p1, p2);
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValFloat(value/g_unit);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "distance2d(p1, p2)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rDistance2d(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 p1, p2;
|
2014-12-20 17:45:46 +00:00
|
|
|
float value;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( !GetPoint(var, exception, p1) ) return true;
|
|
|
|
if ( !GetPoint(var, exception, p2) ) return true;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
value = Math::DistanceProjected(p1, p2);
|
|
|
|
result->SetValFloat(value/g_unit);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compilation of the instruction "space(center, rMin, rMax, dist)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cSpace(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2014-12-20 17:45:46 +00:00
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypIntrinsic, "point");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "space(center, rMin, rMax, dist)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rSpace(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotVar* pSub;
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 center;
|
2014-12-20 17:45:46 +00:00
|
|
|
float rMin, rMax, dist;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
rMin = 10.0f*g_unit;
|
|
|
|
rMax = 50.0f*g_unit;
|
|
|
|
dist = 4.0f*g_unit;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-07-12 09:01:16 +00:00
|
|
|
center = pThis->GetPosition();
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !GetPoint(var, exception, center) ) return true;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
rMin = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
rMax = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
dist = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-14 22:04:54 +00:00
|
|
|
|
|
|
|
bool success = script->m_main->FreeSpace(center, rMin, rMax, dist, pThis);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( result != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
pSub = result->GetItemList();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( pSub != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2022-08-14 22:04:54 +00:00
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
pSub->SetValFloat(center.x / g_unit);
|
|
|
|
pSub = pSub->GetNext(); // "y"
|
|
|
|
pSub->SetValFloat(center.z / g_unit);
|
|
|
|
pSub = pSub->GetNext(); // "z"
|
|
|
|
pSub->SetValFloat(center.y / g_unit);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pSub->SetValFloat(center.x);
|
|
|
|
pSub = pSub->GetNext(); // "y"
|
|
|
|
pSub->SetValFloat(center.y);
|
|
|
|
pSub = pSub->GetNext(); // "z"
|
|
|
|
pSub->SetValFloat(center.z);
|
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-22 16:26:05 +00:00
|
|
|
CBotTypResult CScriptFunctions::cFlatSpace(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2015-07-22 16:26:05 +00:00
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2015-07-22 16:26:05 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2015-07-22 16:26:05 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2015-07-22 16:26:05 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypIntrinsic, "point");
|
2015-07-22 16:26:05 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-07-22 16:26:05 +00:00
|
|
|
return CBotTypResult(CBotTypIntrinsic, "point");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptFunctions::rFlatSpace(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2015-07-22 16:26:05 +00:00
|
|
|
CBotVar* pSub;
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 center;
|
2015-07-22 16:26:05 +00:00
|
|
|
float flatMin, rMin, rMax, dist;
|
|
|
|
|
|
|
|
rMin = 10.0f*g_unit;
|
|
|
|
rMax = 50.0f*g_unit;
|
|
|
|
dist = 4.0f*g_unit;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !GetPoint(var, exception, center) ) return true;
|
|
|
|
|
|
|
|
flatMin = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2015-07-22 16:26:05 +00:00
|
|
|
{
|
|
|
|
rMin = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2015-07-22 16:26:05 +00:00
|
|
|
{
|
|
|
|
rMax = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2015-07-22 16:26:05 +00:00
|
|
|
{
|
|
|
|
dist = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
script->m_main->FlatFreeSpace(center, flatMin, rMin, rMax, dist, pThis);
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( result != nullptr )
|
2015-07-22 16:26:05 +00:00
|
|
|
{
|
|
|
|
pSub = result->GetItemList();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( pSub != nullptr )
|
2015-07-22 16:26:05 +00:00
|
|
|
{
|
|
|
|
pSub->SetValFloat(center.x/g_unit);
|
|
|
|
pSub = pSub->GetNext(); // "y"
|
|
|
|
pSub->SetValFloat(center.z/g_unit);
|
|
|
|
pSub = pSub->GetNext(); // "z"
|
|
|
|
pSub->SetValFloat(center.y/g_unit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
|
|
|
|
// Compilation of the instruction "flatground(center, rMax)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cFlatGround(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "flatground(center, rMax)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rFlatGround(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 center;
|
2014-12-20 17:45:46 +00:00
|
|
|
float rMax, dist;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( !GetPoint(var, exception, center) ) return true;
|
|
|
|
rMax = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
dist = script->m_main->GetFlatZoneRadius(center, rMax, pThis);
|
|
|
|
result->SetValFloat(dist/g_unit);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Instruction "wait(t)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rWait(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
float value;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
value = var->GetValFloat();
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskWait(value);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "move(dist)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rMove(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
float value;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
value = var->GetValFloat();
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskAdvance(value*g_unit);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "turn(angle)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rTurn(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
float value;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
value = var->GetValFloat();
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskTurn(-value*Math::PI/180.0f);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "goto(pos, altitude, crash, goal)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cGoto(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "goto(pos, altitude, mode)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rGoto(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 pos;
|
2014-12-20 17:45:46 +00:00
|
|
|
TaskGotoGoal goal;
|
|
|
|
TaskGotoCrash crash;
|
|
|
|
float altitude;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( !GetPoint(var, exception, pos) ) return true;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
goal = TGG_DEFAULT;
|
|
|
|
crash = TGC_DEFAULT;
|
|
|
|
altitude = 0.0f*g_unit;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
altitude = var->GetValFloat()*g_unit;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
goal = static_cast<TaskGotoGoal>(var->GetValInt());
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
crash = static_cast<TaskGotoCrash>(var->GetValInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskGoto(pos, altitude, goal, crash);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation "grab/drop(oper)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cGrabDrop(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "grab(oper)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rGrab(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
ObjectType oType;
|
|
|
|
TaskManipArm type;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
type = TMA_FFRONT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = static_cast<TaskManipArm>(var->GetValInt());
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
oType = pThis->GetType();
|
|
|
|
if ( oType == OBJECT_HUMAN ||
|
|
|
|
oType == OBJECT_TECH )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskTake();
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskManip(TMO_GRAB, type);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "drop(oper)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rDrop(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
ObjectType oType;
|
|
|
|
TaskManipArm type;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) type = TMA_FFRONT;
|
2014-12-20 17:45:46 +00:00
|
|
|
else type = static_cast<TaskManipArm>(var->GetValInt());
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
oType = pThis->GetType();
|
|
|
|
if ( oType == OBJECT_HUMAN ||
|
|
|
|
oType == OBJECT_TECH )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskTake();
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskManip(TMO_DROP, type);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "sniff()".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rSniff(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskSearch();
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "receive(nom, power)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cReceive(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "receive(nom, power)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string p;
|
2015-08-17 09:44:05 +00:00
|
|
|
float power;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-12-20 15:19:10 +00:00
|
|
|
p = var->GetValString();
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
power = 10.0f*g_unit;
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
power = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-12-20 15:19:10 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskInfo(p.c_str(), 0.0f, power, false);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2022-09-14 23:14:29 +00:00
|
|
|
result->SetValFloat(nanf(""));
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-17 09:44:05 +00:00
|
|
|
|
2020-09-14 19:19:16 +00:00
|
|
|
CExchangePost* exchangePost = dynamic_cast<CTaskInfo&>(*script->m_taskExecutor->GetForegroundTask()).FindExchangePost(power);
|
2015-08-17 09:44:05 +00:00
|
|
|
script->m_returnValue = exchangePost->GetInfoValue(p);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
if ( !WaitForForegroundTask(script, result, exception) ) return false; // not finished
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 09:44:05 +00:00
|
|
|
if ( script->m_returnValue == boost::none )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2022-09-14 23:14:29 +00:00
|
|
|
result->SetValFloat(nanf(""));
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-17 09:44:05 +00:00
|
|
|
result->SetValFloat(*script->m_returnValue);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "send(nom, value, power)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cSend(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "send(nom, value, power)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string p;
|
2014-12-20 17:45:46 +00:00
|
|
|
float value, power;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-12-20 15:19:10 +00:00
|
|
|
p = var->GetValString();
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
value = var->GetValFloat();
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
power = 10.0f*g_unit;
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
power = var->GetValFloat()*g_unit;
|
|
|
|
var = var->GetNext();
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-12-20 15:19:10 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskInfo(p.c_str(), value, power, true);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Seeks the nearest information terminal.
|
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
CExchangePost* CScriptFunctions::FindExchangePost(CObject* object, float power)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-06-27 21:22:55 +00:00
|
|
|
CObject* exchangePost = CObjectManager::GetInstancePointer()->FindNearest(object, OBJECT_INFO, power/g_unit);
|
|
|
|
return dynamic_cast<CExchangePost*>(exchangePost);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
// Compilation of the instruction "deleteinfo(name, power)".
|
2014-12-20 17:45:46 +00:00
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cDeleteInfo(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypBoolean);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-27 21:22:55 +00:00
|
|
|
return CBotTypResult(CBotTypBoolean);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
// Instruction "deleteinfo(name, power)".
|
2014-12-20 17:45:46 +00:00
|
|
|
|
|
|
|
bool CScriptFunctions::rDeleteInfo(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string infoName = var->GetValString();
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
float power = 10.0f*g_unit;
|
|
|
|
if (var != nullptr)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
power = var->GetValFloat()*g_unit;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
CExchangePost* exchangePost = FindExchangePost(pThis, power);
|
|
|
|
if (exchangePost == nullptr)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-06-27 21:22:55 +00:00
|
|
|
result->SetValInt(false);
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
bool infoDeleted = exchangePost->DeleteInfo(infoName);
|
|
|
|
result->SetValInt(infoDeleted);
|
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "testinfo(nom, power)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cTestInfo(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypBoolean);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypBoolean);
|
|
|
|
}
|
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
// Instruction "testinfo(name, power)".
|
2014-12-20 17:45:46 +00:00
|
|
|
|
|
|
|
bool CScriptFunctions::rTestInfo(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string infoName = var->GetValString();
|
2014-12-20 17:45:46 +00:00
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
float power = 10.0f*g_unit;
|
|
|
|
if (var != nullptr)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
power = var->GetValFloat()*g_unit;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
CExchangePost* exchangePost = FindExchangePost(pThis, power);
|
|
|
|
if (exchangePost == nullptr)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
result->SetValInt(false);
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
bool foundInfo = exchangePost->HasInfo(infoName);
|
|
|
|
result->SetValInt(foundInfo);
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "thump()".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rThump(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskTerraform();
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "recycle()".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rRecycle(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskRecover();
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation "shield(oper, radius)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cShield(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "shield(oper, radius)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rShield(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
float oper, radius;
|
|
|
|
Error err;
|
2015-05-28 12:03:05 +00:00
|
|
|
|
|
|
|
// only shielder can use shield()
|
|
|
|
if (pThis->GetType() != OBJECT_MOBILErs)
|
|
|
|
{
|
2015-08-12 14:54:44 +00:00
|
|
|
result->SetValInt(ERR_WRONG_BOT); // return error
|
2015-05-28 12:03:05 +00:00
|
|
|
if (script->m_errMode == ERM_STOP)
|
|
|
|
{
|
2015-08-12 14:54:44 +00:00
|
|
|
exception = ERR_WRONG_BOT;
|
2015-05-28 12:03:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
oper = var->GetValFloat(); // 0=down, 1=up
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
radius = var->GetValFloat();
|
|
|
|
if ( radius < 10.0f ) radius = 10.0f;
|
|
|
|
if ( radius > 25.0f ) radius = 25.0f;
|
|
|
|
radius = (radius-10.0f)/15.0f;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsBackgroundTask() ) // shield folds?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( oper == 0.0f ) // down?
|
|
|
|
{
|
|
|
|
result->SetValInt(1); // shows the error
|
|
|
|
}
|
|
|
|
else // up ?
|
|
|
|
{
|
2020-09-14 19:19:16 +00:00
|
|
|
dynamic_cast<CShielder&>(*pThis).SetShieldRadius(radius);
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskShield(TSM_UP, 1000.0f);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopBackgroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // shield deployed?
|
|
|
|
{
|
|
|
|
if ( oper == 0.0f ) // down?
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StartTaskShield(TSM_DOWN, 0.0f);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else // up?
|
|
|
|
{
|
|
|
|
//? result->SetValInt(1); // shows the error
|
2020-09-14 19:19:16 +00:00
|
|
|
dynamic_cast<CShielder&>(*pThis).SetShieldRadius(radius);
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StartTaskShield(TSM_UPDATE, 0.0f);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation "fire(delay)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cFire(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
ObjectType type;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
type = pThis->GetType();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( type == OBJECT_ANT )
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotTypResult ret = cPoint(var, user);
|
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else if ( type == OBJECT_SPIDER )
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "fire(delay)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rFire(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
float delay;
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 impact;
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
|
|
|
ObjectType type;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
type = pThis->GetType();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( type == OBJECT_ANT )
|
|
|
|
{
|
|
|
|
if ( !GetPoint(var, exception, impact) ) return true;
|
2015-06-29 20:45:38 +00:00
|
|
|
float waterLevel = Gfx::CEngine::GetInstancePointer()->GetWater()->GetLevel();
|
|
|
|
impact.y += waterLevel;
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskFireAnt(impact);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else if ( type == OBJECT_SPIDER )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskSpiderExplo();
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) delay = 0.0f;
|
2014-12-20 17:45:46 +00:00
|
|
|
else delay = var->GetValFloat();
|
|
|
|
if ( delay < 0.0f ) delay = -delay;
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskFire(delay);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
2018-04-19 23:31:11 +00:00
|
|
|
result->SetValInt(err); // indicates the error or ok
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2017-05-22 09:11:42 +00:00
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "aim(x, y)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cAim(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "aim(dir)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rAim(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
float x, y;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-15 18:29:59 +00:00
|
|
|
if ( !script->m_taskExecutor->IsBackgroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
x = var->GetValFloat();
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
var == nullptr ? y=0.0f : y=var->GetValFloat();
|
2015-08-10 11:46:39 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskGunGoal(x*Math::PI/180.0f, y*Math::PI/180.0f);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err == ERR_AIM_IMPOSSIBLE )
|
|
|
|
{
|
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
}
|
|
|
|
else if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-15 18:29:59 +00:00
|
|
|
script->m_taskExecutor->StopBackgroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForBackgroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "motor(left, right)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cMotor(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotTypFloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "motor(left, right)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rMotor(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
|
|
|
CPhysics* physics = (static_cast<CScript*>(user)->m_object)->GetPhysics();
|
2014-12-20 17:45:46 +00:00
|
|
|
float left, right, speed, turn;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
left = var->GetValFloat();
|
|
|
|
var = var->GetNext();
|
|
|
|
right = var->GetValFloat();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
speed = (left+right)/2.0f;
|
|
|
|
if ( speed < -1.0f ) speed = -1.0f;
|
|
|
|
if ( speed > 1.0f ) speed = 1.0f;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
turn = left-right;
|
|
|
|
if ( turn < -1.0f ) turn = -1.0f;
|
|
|
|
if ( turn > 1.0f ) turn = 1.0f;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2020-09-14 19:19:16 +00:00
|
|
|
if ( dynamic_cast<CBaseAlien*>(pThis) != nullptr && dynamic_cast<CBaseAlien&>(*pThis).GetFixed() ) // ant on the back?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
speed = 0.0f;
|
|
|
|
turn = 0.0f;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
physics->SetMotorSpeedX(speed); // forward/backward
|
|
|
|
physics->SetMotorSpeedZ(turn); // turns
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "jet(power)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rJet(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CPhysics* physics = (static_cast<CScript*>(user)->m_object)->GetPhysics();
|
2014-12-20 17:45:46 +00:00
|
|
|
float value;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
value = var->GetValFloat();
|
2015-06-25 17:05:56 +00:00
|
|
|
if ( value > 1.0f ) value = 1.0f;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
physics->SetMotorSpeedY(value);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "topo(pos)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cTopo(CBotVar* &var, void* user)
|
|
|
|
{
|
|
|
|
CBotTypResult ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2017-05-25 06:01:42 +00:00
|
|
|
ret = cPoint(var, user);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( ret.GetType() != 0 ) return ret;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "topo(pos)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rTopo(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 pos;
|
2014-12-20 17:45:46 +00:00
|
|
|
float level;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
exception = 0;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( !GetPoint(var, exception, pos) ) return true;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
level = script->m_terrain->GetFloorLevel(pos);
|
|
|
|
level -= script->m_water->GetLevel();
|
|
|
|
result->SetValFloat(level/g_unit);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "message(string, type)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cMessage(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() != CBotTypString &&
|
2022-08-13 15:18:14 +00:00
|
|
|
var->GetType() != CBotTypBoolean &&
|
2014-12-20 17:45:46 +00:00
|
|
|
var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "message(string, type)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string p;
|
2014-12-20 17:45:46 +00:00
|
|
|
Ui::TextType type;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-12-20 15:19:10 +00:00
|
|
|
p = var->GetValString();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
type = Ui::TT_MESSAGE;
|
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
type = static_cast<Ui::TextType>(var->GetValInt());
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-12-20 15:19:10 +00:00
|
|
|
script->m_main->GetDisplayText()->DisplayText(p.c_str(), script->m_object, 10.0f, type);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "cmdline(rank)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rCmdline(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* pThis = static_cast<CScript*>(user)->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
float value;
|
|
|
|
int rank;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-10 21:20:36 +00:00
|
|
|
assert(pThis->Implements(ObjectInterfaceType::Programmable));
|
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
rank = var->GetValInt();
|
2020-09-14 19:19:16 +00:00
|
|
|
value = dynamic_cast<CProgrammableObject&>(*pThis).GetCmdLine(rank);
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValFloat(value);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "ismovie()".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rIsMovie(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
float value;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
value = script->m_main->GetMovieLock()?1.0f:0.0f;
|
|
|
|
result->SetValFloat(value);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "errmode(mode)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rErrMode(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
int value;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
value = var->GetValInt();
|
|
|
|
if ( value < 0 ) value = 0;
|
|
|
|
if ( value > 1 ) value = 1;
|
|
|
|
script->m_errMode = value;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "ipf(num)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rIPF(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
int value;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
value = var->GetValInt();
|
|
|
|
if ( value < 1 ) value = 1;
|
|
|
|
if ( value > 10000 ) value = 10000;
|
|
|
|
script->m_ipf = value;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "abstime()".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rAbsTime(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2014-12-20 17:45:46 +00:00
|
|
|
float value;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
value = script->m_main->GetGameTime();
|
|
|
|
result->SetValFloat(value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction "pendown(color, width)".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cPenDown(CBotVar* &var, void* user)
|
|
|
|
{
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotErrOverParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "pendown(color, width)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rPenDown(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
int color;
|
|
|
|
float width;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-13 08:49:26 +00:00
|
|
|
if (!pThis->Implements(ObjectInterfaceType::TraceDrawing))
|
|
|
|
{
|
|
|
|
result->SetValInt(ERR_WRONG_OBJ);
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = ERR_WRONG_OBJ;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(pThis);
|
2015-06-29 20:45:38 +00:00
|
|
|
|
2015-07-14 11:42:47 +00:00
|
|
|
exception = 0;
|
|
|
|
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-07-14 11:42:47 +00:00
|
|
|
color = var->GetValInt();
|
|
|
|
if ( color < 0 ) color = 0;
|
|
|
|
if ( color > static_cast<int>(TraceColor::Max) ) color = static_cast<int>(TraceColor::Max);
|
2015-08-13 08:49:26 +00:00
|
|
|
traceDrawing->SetTraceColor(static_cast<TraceColor>(color));
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-14 11:42:47 +00:00
|
|
|
var = var->GetNext();
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-07-14 11:42:47 +00:00
|
|
|
width = var->GetValFloat();
|
|
|
|
if ( width < 0.1f ) width = 0.1f;
|
|
|
|
if ( width > 1.0f ) width = 1.0f;
|
2015-08-13 08:49:26 +00:00
|
|
|
traceDrawing->SetTraceWidth(width);
|
2015-07-14 11:42:47 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-13 08:49:26 +00:00
|
|
|
traceDrawing->SetTraceDown(true);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-14 11:42:47 +00:00
|
|
|
if ( pThis->GetType() == OBJECT_MOBILEdr )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2015-07-14 11:42:47 +00:00
|
|
|
{
|
2015-08-13 08:49:26 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskPen(traceDrawing->GetTraceDown(), traceDrawing->GetTraceColor());
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "penup()".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rPenUp(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-14 11:42:47 +00:00
|
|
|
exception = 0;
|
|
|
|
|
2015-08-13 08:49:26 +00:00
|
|
|
if (!pThis->Implements(ObjectInterfaceType::TraceDrawing))
|
|
|
|
{
|
|
|
|
result->SetValInt(ERR_WRONG_OBJ);
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = ERR_WRONG_OBJ;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(pThis);
|
|
|
|
traceDrawing->SetTraceDown(false);
|
2015-07-14 11:42:47 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( pThis->GetType() == OBJECT_MOBILEdr )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-13 08:49:26 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskPen(traceDrawing->GetTraceDown(), traceDrawing->GetTraceColor());
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "pencolor()".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rPenColor(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-11 15:51:39 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
int color;
|
|
|
|
Error err;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-14 11:42:47 +00:00
|
|
|
exception = 0;
|
|
|
|
|
2015-08-13 08:49:26 +00:00
|
|
|
if (!pThis->Implements(ObjectInterfaceType::TraceDrawing))
|
|
|
|
{
|
|
|
|
result->SetValInt(ERR_WRONG_OBJ);
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = ERR_WRONG_OBJ;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(pThis);
|
|
|
|
|
2015-07-14 11:42:47 +00:00
|
|
|
color = var->GetValInt();
|
|
|
|
if ( color < 0 ) color = 0;
|
|
|
|
if ( color > static_cast<int>(TraceColor::Max) ) color = static_cast<int>(TraceColor::Max);
|
2015-08-13 08:49:26 +00:00
|
|
|
traceDrawing->SetTraceColor(static_cast<TraceColor>(color));
|
2015-07-14 11:42:47 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( pThis->GetType() == OBJECT_MOBILEdr )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
2015-08-13 08:49:26 +00:00
|
|
|
err = script->m_taskExecutor->StartTaskPen(traceDrawing->GetTraceDown(), traceDrawing->GetTraceColor());
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( err != ERR_OK )
|
|
|
|
{
|
2015-08-10 11:46:39 +00:00
|
|
|
script->m_taskExecutor->StopForegroundTask();
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(err); // shows the error
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = err;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 18:29:59 +00:00
|
|
|
return WaitForForegroundTask(script, result, exception);
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "penwidth()".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2015-08-13 08:49:26 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
|
|
|
CObject* pThis = script->m_object;
|
2014-12-20 17:45:46 +00:00
|
|
|
float width;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-13 08:49:26 +00:00
|
|
|
exception = 0;
|
|
|
|
|
|
|
|
if (!pThis->Implements(ObjectInterfaceType::TraceDrawing))
|
|
|
|
{
|
|
|
|
result->SetValInt(ERR_WRONG_OBJ);
|
|
|
|
if ( script->m_errMode == ERM_STOP )
|
|
|
|
{
|
|
|
|
exception = ERR_WRONG_OBJ;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CTraceDrawingObject* traceDrawing = dynamic_cast<CTraceDrawingObject*>(pThis);
|
2015-06-29 20:45:38 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
width = var->GetValFloat();
|
|
|
|
if ( width < 0.1f ) width = 0.1f;
|
|
|
|
if ( width > 1.0f ) width = 1.0f;
|
2015-08-13 08:49:26 +00:00
|
|
|
traceDrawing->SetTraceWidth(width);
|
2014-12-20 17:45:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compilation of the instruction with one object parameter
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cOneObject(CBotVar* &var, void* user)
|
|
|
|
{
|
2017-11-30 19:41:44 +00:00
|
|
|
if ( var != nullptr )
|
|
|
|
{
|
|
|
|
var = var->GetNext();
|
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
|
2020-06-16 19:02:52 +00:00
|
|
|
}
|
2017-11-30 19:41:44 +00:00
|
|
|
else
|
|
|
|
return CBotTypResult(CBotTypFloat);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(CBotErrOverParam);
|
2020-06-16 19:02:52 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Instruction "camerafocus(object)".
|
|
|
|
|
|
|
|
bool CScriptFunctions::rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user)
|
|
|
|
{
|
2017-11-30 19:41:44 +00:00
|
|
|
CScript* script = static_cast<CScript*>(user);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2017-11-30 19:41:44 +00:00
|
|
|
CObject* object;
|
|
|
|
if (var == nullptr)
|
|
|
|
object = script->m_object;
|
|
|
|
else
|
|
|
|
object = static_cast<CObject*>(var->GetUserPtr());
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
script->m_main->SelectObject(object, false);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
result->SetValInt(ERR_OK);
|
|
|
|
exception = ERR_OK;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-19 20:34:41 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
// Compilation of class "point".
|
|
|
|
|
|
|
|
CBotTypResult CScriptFunctions::cPointConstructor(CBotVar* pThis, CBotVar* &var)
|
|
|
|
{
|
|
|
|
if ( !pThis->IsElemOfClass("point") ) return CBotTypResult(CBotErrBadNum);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(0); // ok if no parameter
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
// First parameter (x):
|
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
// Second parameter (y):
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
// Third parameter (z):
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( var == nullptr ) // only 2 parameters?
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
return CBotTypResult(0); // this function returns void
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
|
|
|
var = var->GetNext();
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return CBotTypResult(0); // this function returns void
|
|
|
|
}
|
|
|
|
|
|
|
|
//Execution of the class "point".
|
|
|
|
|
2015-07-13 16:40:13 +00:00
|
|
|
bool CScriptFunctions::rPointConstructor(CBotVar* pThis, CBotVar* var, CBotVar* pResult, int& Exception, void* user)
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
CBotVar *pX, *pY, *pZ;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( var == nullptr ) return true; // constructor with no parameters is ok
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble )
|
|
|
|
{
|
|
|
|
Exception = CBotErrBadNum; return false;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
pX = pThis->GetItem("x");
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( pX == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
Exception = CBotErrUndefItem; return false;
|
|
|
|
}
|
|
|
|
pX->SetValFloat( var->GetValFloat() );
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( var == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
Exception = CBotErrLowParam; return false;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
if ( var->GetType() > CBotTypDouble )
|
|
|
|
{
|
|
|
|
Exception = CBotErrBadNum; return false;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
pY = pThis->GetItem("y");
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( pY == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
Exception = CBotErrUndefItem; return false;
|
|
|
|
}
|
|
|
|
pY->SetValFloat( var->GetValFloat() );
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( var == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
return true; // ok with only two parameters
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
pZ = pThis->GetItem("z");
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( pZ == nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
Exception = CBotErrUndefItem; return false;
|
|
|
|
}
|
|
|
|
pZ->SetValFloat( var->GetValFloat() );
|
|
|
|
var = var->GetNext();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-16 10:43:42 +00:00
|
|
|
if ( var != nullptr )
|
2014-12-20 17:45:46 +00:00
|
|
|
{
|
|
|
|
Exception = CBotErrOverParam; return false;
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
return true; // no interruption
|
|
|
|
}
|
|
|
|
|
2015-12-20 17:35:52 +00:00
|
|
|
class CBotFileColobot : public CBotFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static int m_numFilesOpen;
|
|
|
|
|
|
|
|
CBotFileColobot(const std::string& filename, CBotFileAccessHandler::OpenMode mode)
|
|
|
|
{
|
|
|
|
if (mode == CBotFileAccessHandler::OpenMode::Read)
|
|
|
|
{
|
2022-02-26 17:48:51 +00:00
|
|
|
auto is = std::make_unique<CInputStream>(filename);
|
2015-12-20 17:35:52 +00:00
|
|
|
if (is->is_open())
|
|
|
|
{
|
|
|
|
m_file = std::move(is);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == CBotFileAccessHandler::OpenMode::Write)
|
|
|
|
{
|
2022-02-26 17:48:51 +00:00
|
|
|
auto os = std::make_unique<COutputStream>(filename);
|
2015-12-20 17:35:52 +00:00
|
|
|
if (os->is_open())
|
|
|
|
{
|
|
|
|
m_file = std::move(os);
|
|
|
|
}
|
|
|
|
}
|
2016-09-30 15:03:13 +00:00
|
|
|
else if (mode == CBotFileAccessHandler::OpenMode::Append)
|
|
|
|
{
|
2022-02-26 17:48:51 +00:00
|
|
|
auto os = std::make_unique<COutputStream>(filename, std::ios_base::app);
|
2016-09-30 15:03:13 +00:00
|
|
|
if (os->is_open())
|
|
|
|
{
|
|
|
|
m_file = std::move(os);
|
|
|
|
}
|
|
|
|
}
|
2015-12-20 17:35:52 +00:00
|
|
|
|
|
|
|
if (Opened())
|
|
|
|
{
|
2016-09-30 15:08:37 +00:00
|
|
|
GetLogger()->Info("CBot open file '%s', mode '%c'\n", filename.c_str(), mode);
|
2015-12-20 17:35:52 +00:00
|
|
|
m_numFilesOpen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-19 10:51:41 +00:00
|
|
|
~CBotFileColobot() override
|
2015-12-20 17:35:52 +00:00
|
|
|
{
|
|
|
|
if (Opened())
|
|
|
|
{
|
2016-09-30 15:08:37 +00:00
|
|
|
GetLogger()->Info("CBot close file\n");
|
2015-12-20 17:35:52 +00:00
|
|
|
m_numFilesOpen--;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ios* file = m_file.get();
|
|
|
|
CInputStream* is = dynamic_cast<CInputStream*>(file);
|
|
|
|
if(is != nullptr) is->close();
|
|
|
|
COutputStream* os = dynamic_cast<COutputStream*>(file);
|
|
|
|
if(os != nullptr) os->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Opened() override
|
|
|
|
{
|
|
|
|
return m_file != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Errored() override
|
|
|
|
{
|
|
|
|
return m_file->bad();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool IsEOF() override
|
|
|
|
{
|
|
|
|
return m_file->eof();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string ReadLine() override
|
|
|
|
{
|
|
|
|
CInputStream* is = dynamic_cast<CInputStream*>(m_file.get());
|
|
|
|
assert(is != nullptr);
|
|
|
|
|
|
|
|
std::string line;
|
|
|
|
std::getline(*is, line);
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Write(const std::string& s) override
|
|
|
|
{
|
|
|
|
COutputStream* os = dynamic_cast<COutputStream*>(m_file.get());
|
|
|
|
assert(os != nullptr);
|
|
|
|
|
|
|
|
*os << s;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<std::ios> m_file;
|
|
|
|
};
|
|
|
|
int CBotFileColobot::m_numFilesOpen = 0;
|
|
|
|
|
|
|
|
class CBotFileAccessHandlerColobot : public CBotFileAccessHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual std::unique_ptr<CBotFile> OpenFile(const std::string& filename, OpenMode mode) override
|
|
|
|
{
|
2022-02-26 17:48:51 +00:00
|
|
|
return std::make_unique<CBotFileColobot>(PrepareFilename(filename), mode);
|
2015-12-20 17:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool DeleteFile(const std::string& filename) override
|
|
|
|
{
|
2016-09-30 15:08:37 +00:00
|
|
|
std::string fname = PrepareFilename(filename);
|
|
|
|
GetLogger()->Info("CBot delete file '%s'\n", fname.c_str());
|
|
|
|
return CResourceManager::Remove(fname);
|
2015-12-20 17:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static std::string PrepareFilename(const std::string& filename)
|
|
|
|
{
|
2021-09-04 18:34:02 +00:00
|
|
|
CResourceManager::CreateNewDirectory("files");
|
2015-12-20 17:35:52 +00:00
|
|
|
return "files/" + filename;
|
|
|
|
}
|
|
|
|
};
|
2014-12-20 17:45:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initializes all functions for module CBOT.
|
|
|
|
|
|
|
|
void CScriptFunctions::Init()
|
|
|
|
{
|
|
|
|
CBotProgram::Init();
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
for (int i = 0; i < OBJECT_MAX; i++)
|
|
|
|
{
|
|
|
|
ObjectType type = static_cast<ObjectType>(i);
|
|
|
|
const char* token = GetObjectName(type);
|
|
|
|
if (token[0] != 0)
|
|
|
|
CBotProgram::DefineNum(token, type);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
token = GetObjectAlias(type);
|
|
|
|
if (token[0] != 0)
|
|
|
|
CBotProgram::DefineNum(token, type);
|
|
|
|
}
|
2015-07-07 17:01:18 +00:00
|
|
|
CBotProgram::DefineNum("Any", OBJECT_NULL);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-07-14 11:42:47 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(TraceColor::Max); i++)
|
|
|
|
{
|
|
|
|
TraceColor color = static_cast<TraceColor>(i);
|
|
|
|
CBotProgram::DefineNum(TraceColorName(color).c_str(), static_cast<int>(color));
|
|
|
|
}
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotProgram::DefineNum("InFront", TMA_FFRONT);
|
|
|
|
CBotProgram::DefineNum("Behind", TMA_FBACK);
|
|
|
|
CBotProgram::DefineNum("EnergyCell", TMA_POWER);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotProgram::DefineNum("DisplayError", Ui::TT_ERROR);
|
|
|
|
CBotProgram::DefineNum("DisplayWarning", Ui::TT_WARNING);
|
|
|
|
CBotProgram::DefineNum("DisplayInfo", Ui::TT_INFO);
|
|
|
|
CBotProgram::DefineNum("DisplayMessage", Ui::TT_MESSAGE);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotProgram::DefineNum("FilterNone", FILTER_NONE);
|
|
|
|
CBotProgram::DefineNum("FilterOnlyLanding", FILTER_ONLYLANDING);
|
2015-07-07 16:54:36 +00:00
|
|
|
CBotProgram::DefineNum("FilterOnlyFlying", FILTER_ONLYFLYING);
|
|
|
|
CBotProgram::DefineNum("FilterFriendly", FILTER_FRIENDLY);
|
|
|
|
CBotProgram::DefineNum("FilterEnemy", FILTER_ENEMY);
|
|
|
|
CBotProgram::DefineNum("FilterNeutral", FILTER_NEUTRAL);
|
|
|
|
|
2015-08-13 16:54:44 +00:00
|
|
|
CBotProgram::DefineNum("DestructionNone", static_cast<int>(DestructionType::NoEffect));
|
|
|
|
CBotProgram::DefineNum("DestructionExplosion", static_cast<int>(DestructionType::Explosion));
|
|
|
|
CBotProgram::DefineNum("DestructionExplosionWater", static_cast<int>(DestructionType::ExplosionWater));
|
|
|
|
CBotProgram::DefineNum("DestructionBurn", static_cast<int>(DestructionType::Burn));
|
|
|
|
CBotProgram::DefineNum("DestructionDrowned", static_cast<int>(DestructionType::Drowned));
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotProgram::DefineNum("ResultNotEnded", ERR_MISSION_NOTERM);
|
|
|
|
CBotProgram::DefineNum("ResultLost", INFO_LOST);
|
|
|
|
CBotProgram::DefineNum("ResultLostQuick", INFO_LOSTq);
|
|
|
|
CBotProgram::DefineNum("ResultWin", ERR_OK);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2015-08-03 18:23:35 +00:00
|
|
|
// NOTE: The Build___ constants are for use only with getbuild() and setbuild() for MissionController, not for normal players
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotProgram::DefineNum("BuildBotFactory", BUILD_FACTORY);
|
|
|
|
CBotProgram::DefineNum("BuildDerrick", BUILD_DERRICK);
|
|
|
|
CBotProgram::DefineNum("BuildConverter", BUILD_CONVERT);
|
|
|
|
CBotProgram::DefineNum("BuildRadarStation", BUILD_RADAR);
|
|
|
|
CBotProgram::DefineNum("BuildPowerPlant", BUILD_ENERGY);
|
|
|
|
CBotProgram::DefineNum("BuildNuclearPlant", BUILD_NUCLEAR);
|
|
|
|
CBotProgram::DefineNum("BuildPowerStation", BUILD_STATION);
|
|
|
|
CBotProgram::DefineNum("BuildRepairCenter", BUILD_REPAIR);
|
|
|
|
CBotProgram::DefineNum("BuildDefenseTower", BUILD_TOWER);
|
|
|
|
CBotProgram::DefineNum("BuildResearchCenter", BUILD_RESEARCH);
|
|
|
|
CBotProgram::DefineNum("BuildAutoLab", BUILD_LABO);
|
|
|
|
CBotProgram::DefineNum("BuildPowerCaptor", BUILD_PARA);
|
|
|
|
CBotProgram::DefineNum("BuildExchangePost", BUILD_INFO);
|
2020-08-08 18:51:56 +00:00
|
|
|
CBotProgram::DefineNum("BuildVault", BUILD_SAFE);
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotProgram::DefineNum("BuildDestroyer", BUILD_DESTROYER);
|
|
|
|
CBotProgram::DefineNum("FlatGround", BUILD_GFLAT);
|
|
|
|
CBotProgram::DefineNum("UseFlags", BUILD_FLAG);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotProgram::DefineNum("ResearchTracked", RESEARCH_TANK);
|
|
|
|
CBotProgram::DefineNum("ResearchWinged", RESEARCH_FLY);
|
|
|
|
CBotProgram::DefineNum("ResearchShooter", RESEARCH_CANON);
|
|
|
|
CBotProgram::DefineNum("ResearchDefenseTower", RESEARCH_TOWER);
|
|
|
|
CBotProgram::DefineNum("ResearchNuclearPlant", RESEARCH_ATOMIC);
|
|
|
|
CBotProgram::DefineNum("ResearchThumper", RESEARCH_THUMP);
|
|
|
|
CBotProgram::DefineNum("ResearchShielder", RESEARCH_SHIELD);
|
|
|
|
CBotProgram::DefineNum("ResearchPhazerShooter", RESEARCH_PHAZER);
|
|
|
|
CBotProgram::DefineNum("ResearchLegged", RESEARCH_iPAW);
|
|
|
|
CBotProgram::DefineNum("ResearchOrgaShooter", RESEARCH_iGUN);
|
|
|
|
CBotProgram::DefineNum("ResearchRecycler", RESEARCH_RECYCLER);
|
|
|
|
CBotProgram::DefineNum("ResearchSubber", RESEARCH_SUBM);
|
|
|
|
CBotProgram::DefineNum("ResearchSniffer", RESEARCH_SNIFFER);
|
2017-11-22 23:11:29 +00:00
|
|
|
CBotProgram::DefineNum("ResearchBuilder", RESEARCH_BUILDER);
|
2018-07-12 22:03:20 +00:00
|
|
|
CBotProgram::DefineNum("ResearchTarget", RESEARCH_TARGET);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotProgram::DefineNum("PolskiPortalColobota", 1337);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
CBotClass* bc;
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
// Add the class Point.
|
2015-10-03 20:05:14 +00:00
|
|
|
bc = CBotClass::Create("point", nullptr, true); // intrinsic class
|
2014-12-20 17:45:46 +00:00
|
|
|
bc->AddItem("x", CBotTypFloat);
|
|
|
|
bc->AddItem("y", CBotTypFloat);
|
|
|
|
bc->AddItem("z", CBotTypFloat);
|
2015-12-20 17:35:52 +00:00
|
|
|
bc->AddFunction("point", rPointConstructor, cPointConstructor);
|
2015-06-24 21:25:02 +00:00
|
|
|
|
2014-12-20 17:45:46 +00:00
|
|
|
// Adds the class Object.
|
2015-10-03 20:05:14 +00:00
|
|
|
bc = CBotClass::Create("object", nullptr);
|
2015-12-21 22:07:40 +00:00
|
|
|
bc->AddItem("category", CBotTypResult(CBotTypInt), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("position", CBotTypResult(CBotTypClass, "point"), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("orientation", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("pitch", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("roll", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("energyLevel", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("shieldLevel", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("temperature", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("altitude", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("lifeTime", CBotTypResult(CBotTypFloat), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("energyCell", CBotTypResult(CBotTypPointer, "object"), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("load", CBotTypResult(CBotTypPointer, "object"), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("id", CBotTypResult(CBotTypInt), CBotVar::ProtectionLevel::ReadOnly);
|
|
|
|
bc->AddItem("team", CBotTypResult(CBotTypInt), CBotVar::ProtectionLevel::ReadOnly);
|
2018-12-27 22:29:39 +00:00
|
|
|
bc->AddItem("dead", CBotTypResult(CBotTypBoolean), CBotVar::ProtectionLevel::ReadOnly);
|
2015-12-21 22:07:40 +00:00
|
|
|
bc->AddItem("velocity", CBotTypResult(CBotTypClass, "point"), CBotVar::ProtectionLevel::ReadOnly);
|
2015-12-20 17:35:52 +00:00
|
|
|
|
|
|
|
CBotProgram::AddFunction("endmission",rEndMission,cEndMission);
|
|
|
|
CBotProgram::AddFunction("playmusic", rPlayMusic ,cPlayMusic);
|
|
|
|
CBotProgram::AddFunction("stopmusic", rStopMusic ,cNull);
|
|
|
|
|
|
|
|
CBotProgram::AddFunction("getbuild", rGetBuild, cNull);
|
|
|
|
CBotProgram::AddFunction("getresearchenable", rGetResearchEnable, cNull);
|
|
|
|
CBotProgram::AddFunction("getresearchdone", rGetResearchDone, cNull);
|
|
|
|
CBotProgram::AddFunction("setbuild", rSetBuild, cOneInt);
|
|
|
|
CBotProgram::AddFunction("setresearchenable", rSetResearchEnable, cOneInt);
|
|
|
|
CBotProgram::AddFunction("setresearchdone", rSetResearchDone, cOneInt);
|
|
|
|
|
|
|
|
CBotProgram::AddFunction("canbuild", rCanBuild, cOneIntReturnBool);
|
|
|
|
CBotProgram::AddFunction("canresearch", rCanResearch, cOneIntReturnBool);
|
|
|
|
CBotProgram::AddFunction("researched", rResearched, cOneIntReturnBool);
|
|
|
|
CBotProgram::AddFunction("buildingenabled", rBuildingEnabled, cOneIntReturnBool);
|
|
|
|
|
|
|
|
CBotProgram::AddFunction("build", rBuild, cOneInt);
|
2020-08-15 01:31:17 +00:00
|
|
|
CBotProgram::AddFunction("flag", rFlag, cGrabDrop);
|
|
|
|
CBotProgram::AddFunction("deflag", rDeflag, cNull);
|
2015-12-20 17:35:52 +00:00
|
|
|
|
|
|
|
CBotProgram::AddFunction("retobject", rGetObject, cGetObject);
|
|
|
|
CBotProgram::AddFunction("retobjectbyid", rGetObjectById, cGetObject);
|
|
|
|
CBotProgram::AddFunction("delete", rDelete, cDelete);
|
|
|
|
CBotProgram::AddFunction("search", rSearch, cSearch);
|
2017-05-25 06:01:42 +00:00
|
|
|
CBotProgram::AddFunction("searchall", rSearchAll, cSearchAll);
|
2015-12-20 17:35:52 +00:00
|
|
|
CBotProgram::AddFunction("radar", rRadar, cRadar);
|
|
|
|
CBotProgram::AddFunction("radarall", rRadarAll, cRadarAll);
|
|
|
|
CBotProgram::AddFunction("detect", rDetect, cDetect);
|
|
|
|
CBotProgram::AddFunction("direction", rDirection, cDirection);
|
|
|
|
CBotProgram::AddFunction("produce", rProduce, cProduce);
|
|
|
|
CBotProgram::AddFunction("distance", rDistance, cDistance);
|
|
|
|
CBotProgram::AddFunction("distance2d",rDistance2d,cDistance);
|
|
|
|
CBotProgram::AddFunction("space", rSpace, cSpace);
|
|
|
|
CBotProgram::AddFunction("flatspace", rFlatSpace, cFlatSpace);
|
|
|
|
CBotProgram::AddFunction("flatground",rFlatGround,cFlatGround);
|
|
|
|
CBotProgram::AddFunction("wait", rWait, cOneFloat);
|
|
|
|
CBotProgram::AddFunction("move", rMove, cOneFloat);
|
|
|
|
CBotProgram::AddFunction("turn", rTurn, cOneFloat);
|
|
|
|
CBotProgram::AddFunction("goto", rGoto, cGoto);
|
|
|
|
CBotProgram::AddFunction("grab", rGrab, cGrabDrop);
|
|
|
|
CBotProgram::AddFunction("drop", rDrop, cGrabDrop);
|
|
|
|
CBotProgram::AddFunction("sniff", rSniff, cNull);
|
|
|
|
CBotProgram::AddFunction("receive", rReceive, cReceive);
|
|
|
|
CBotProgram::AddFunction("send", rSend, cSend);
|
|
|
|
CBotProgram::AddFunction("deleteinfo",rDeleteInfo,cDeleteInfo);
|
|
|
|
CBotProgram::AddFunction("testinfo", rTestInfo, cTestInfo);
|
|
|
|
CBotProgram::AddFunction("thump", rThump, cNull);
|
|
|
|
CBotProgram::AddFunction("recycle", rRecycle, cNull);
|
|
|
|
CBotProgram::AddFunction("shield", rShield, cShield);
|
|
|
|
CBotProgram::AddFunction("fire", rFire, cFire);
|
|
|
|
CBotProgram::AddFunction("aim", rAim, cAim);
|
|
|
|
CBotProgram::AddFunction("motor", rMotor, cMotor);
|
|
|
|
CBotProgram::AddFunction("jet", rJet, cOneFloat);
|
|
|
|
CBotProgram::AddFunction("topo", rTopo, cTopo);
|
|
|
|
CBotProgram::AddFunction("message", rMessage, cMessage);
|
|
|
|
CBotProgram::AddFunction("cmdline", rCmdline, cOneFloat);
|
|
|
|
CBotProgram::AddFunction("ismovie", rIsMovie, cNull);
|
|
|
|
CBotProgram::AddFunction("errmode", rErrMode, cOneFloat);
|
|
|
|
CBotProgram::AddFunction("ipf", rIPF, cOneFloat);
|
|
|
|
CBotProgram::AddFunction("abstime", rAbsTime, cNull);
|
|
|
|
CBotProgram::AddFunction("pendown", rPenDown, cPenDown);
|
|
|
|
CBotProgram::AddFunction("penup", rPenUp, cNull);
|
|
|
|
CBotProgram::AddFunction("pencolor", rPenColor, cOneFloat);
|
|
|
|
CBotProgram::AddFunction("penwidth", rPenWidth, cOneFloat);
|
2017-11-17 10:32:50 +00:00
|
|
|
CBotProgram::AddFunction("factory", rFactory, cFactory);
|
2015-12-26 13:19:24 +00:00
|
|
|
CBotProgram::AddFunction("camerafocus", rCameraFocus, cOneObject);
|
2017-11-17 11:00:49 +00:00
|
|
|
CBotProgram::AddFunction("takeoff", rTakeOff, cOneObject);
|
|
|
|
CBotProgram::AddFunction("isbusy", rIsBusy, cIsBusy);
|
|
|
|
CBotProgram::AddFunction("research", rResearch, cResearch);
|
|
|
|
CBotProgram::AddFunction("destroy", rDestroy, cOneObject);
|
2015-12-20 17:35:52 +00:00
|
|
|
|
2022-02-26 17:48:51 +00:00
|
|
|
SetFileAccessHandler(std::make_unique<CBotFileAccessHandlerColobot>());
|
2015-06-27 21:22:55 +00:00
|
|
|
}
|
2015-07-22 11:24:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Updates the class Object.
|
|
|
|
|
|
|
|
void CScriptFunctions::uObject(CBotVar* botThis, void* user)
|
|
|
|
{
|
|
|
|
CPhysics* physics;
|
|
|
|
CBotVar *pVar, *pSub;
|
|
|
|
ObjectType type;
|
2022-01-03 23:11:20 +00:00
|
|
|
glm::vec3 pos;
|
2015-07-22 11:24:16 +00:00
|
|
|
float value;
|
|
|
|
|
|
|
|
if ( user == nullptr ) return;
|
|
|
|
|
2015-08-11 15:51:39 +00:00
|
|
|
CObject* obj = static_cast<CObject*>(user);
|
|
|
|
assert(obj->Implements(ObjectInterfaceType::Old));
|
|
|
|
COldObject* object = static_cast<COldObject*>(obj);
|
2015-07-22 11:24:16 +00:00
|
|
|
|
|
|
|
physics = object->GetPhysics();
|
|
|
|
|
|
|
|
// Updates the object's type.
|
|
|
|
pVar = botThis->GetItemList(); // "category"
|
|
|
|
type = object->GetType();
|
|
|
|
pVar->SetValInt(type, object->GetName());
|
|
|
|
|
|
|
|
// Updates the position of the object.
|
|
|
|
pVar = pVar->GetNext(); // "position"
|
|
|
|
if (IsObjectBeingTransported(object))
|
|
|
|
{
|
|
|
|
pSub = pVar->GetItemList(); // "x"
|
2022-09-14 23:14:29 +00:00
|
|
|
pSub->SetValFloat(nanf(""));
|
2015-07-22 11:24:16 +00:00
|
|
|
pSub = pSub->GetNext(); // "y"
|
2022-09-14 23:14:29 +00:00
|
|
|
pSub->SetValFloat(nanf(""));
|
2015-07-22 11:24:16 +00:00
|
|
|
pSub = pSub->GetNext(); // "z"
|
2022-09-14 23:14:29 +00:00
|
|
|
pSub->SetValFloat(nanf(""));
|
2015-07-22 11:24:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = object->GetPosition();
|
|
|
|
float waterLevel = Gfx::CEngine::GetInstancePointer()->GetWater()->GetLevel();
|
|
|
|
pos.y -= waterLevel; // relative to sea level!
|
|
|
|
pSub = pVar->GetItemList(); // "x"
|
|
|
|
pSub->SetValFloat(pos.x/g_unit);
|
|
|
|
pSub = pSub->GetNext(); // "y"
|
|
|
|
pSub->SetValFloat(pos.z/g_unit);
|
|
|
|
pSub = pSub->GetNext(); // "z"
|
|
|
|
pSub->SetValFloat(pos.y/g_unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the angle.
|
|
|
|
pos = object->GetRotation();
|
|
|
|
pos += object->GetTilt();
|
|
|
|
pVar = pVar->GetNext(); // "orientation"
|
2015-08-03 21:10:24 +00:00
|
|
|
pVar->SetValFloat(Math::NormAngle(2*Math::PI - pos.y)*180.0f/Math::PI);
|
2015-07-22 11:24:16 +00:00
|
|
|
pVar = pVar->GetNext(); // "pitch"
|
2019-01-06 06:09:57 +00:00
|
|
|
pVar->SetValFloat((Math::NormAngle(pos.z + Math::PI) - Math::PI)*180.0f/Math::PI);
|
2015-07-22 11:24:16 +00:00
|
|
|
pVar = pVar->GetNext(); // "roll"
|
2019-01-06 06:09:57 +00:00
|
|
|
pVar->SetValFloat((Math::NormAngle(pos.x + Math::PI) - Math::PI)*180.0f/Math::PI);
|
2015-07-22 11:24:16 +00:00
|
|
|
|
|
|
|
// Updates the energy level of the object.
|
|
|
|
pVar = pVar->GetNext(); // "energyLevel"
|
2015-08-24 19:14:19 +00:00
|
|
|
value = object->GetEnergyLevel();
|
2015-07-22 11:24:16 +00:00
|
|
|
pVar->SetValFloat(value);
|
|
|
|
|
|
|
|
// Updates the shield level of the object.
|
|
|
|
pVar = pVar->GetNext(); // "shieldLevel"
|
2015-08-13 11:41:25 +00:00
|
|
|
if ( !obj->Implements(ObjectInterfaceType::Shielded) ) value = 1.0f;
|
|
|
|
else value = dynamic_cast<CShieldedObject*>(object)->GetShield();
|
2015-07-22 11:24:16 +00:00
|
|
|
pVar->SetValFloat(value);
|
|
|
|
|
|
|
|
// Updates the temperature of the reactor.
|
|
|
|
pVar = pVar->GetNext(); // "temperature"
|
2015-08-13 08:49:26 +00:00
|
|
|
if ( !obj->Implements(ObjectInterfaceType::JetFlying) ) value = 0.0f;
|
|
|
|
else value = 1.0f-dynamic_cast<CJetFlyingObject*>(object)->GetReactorRange();
|
2015-07-22 11:24:16 +00:00
|
|
|
pVar->SetValFloat(value);
|
|
|
|
|
|
|
|
// Updates the height above the ground.
|
|
|
|
pVar = pVar->GetNext(); // "altitude"
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( physics == nullptr ) value = 0.0f;
|
2015-07-22 11:24:16 +00:00
|
|
|
else value = physics->GetFloorHeight();
|
|
|
|
pVar->SetValFloat(value/g_unit);
|
|
|
|
|
|
|
|
// Updates the lifetime of the object.
|
|
|
|
pVar = pVar->GetNext(); // "lifeTime"
|
|
|
|
value = object->GetAbsTime();
|
|
|
|
pVar->SetValFloat(value);
|
|
|
|
|
|
|
|
// Updates the type of battery.
|
|
|
|
pVar = pVar->GetNext(); // "energyCell"
|
2022-01-29 16:16:57 +00:00
|
|
|
CSlottedObject *asSlotted = object->Implements(ObjectInterfaceType::Slotted) ? dynamic_cast<CSlottedObject*>(object) : nullptr;
|
|
|
|
if (asSlotted != nullptr && asSlotted->MapPseudoSlot(CSlottedObject::Pseudoslot::POWER) >= 0)
|
2015-07-22 11:24:16 +00:00
|
|
|
{
|
2022-01-29 16:16:57 +00:00
|
|
|
CObject *power = asSlotted->GetSlotContainedObjectReq(CSlottedObject::Pseudoslot::POWER);
|
2015-07-22 11:24:16 +00:00
|
|
|
if (power == nullptr)
|
|
|
|
{
|
|
|
|
pVar->SetPointer(nullptr);
|
|
|
|
}
|
|
|
|
else if (power->Implements(ObjectInterfaceType::Old))
|
|
|
|
{
|
2015-08-13 08:49:26 +00:00
|
|
|
pVar->SetPointer(power->GetBotVar());
|
2015-07-22 11:24:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the transported object's type.
|
|
|
|
pVar = pVar->GetNext(); // "load"
|
2022-01-29 16:16:57 +00:00
|
|
|
if (asSlotted != nullptr && asSlotted->MapPseudoSlot(CSlottedObject::Pseudoslot::CARRYING) >= 0)
|
2015-07-22 11:24:16 +00:00
|
|
|
{
|
2022-01-29 16:16:57 +00:00
|
|
|
CObject* cargo = asSlotted->GetSlotContainedObjectReq(CSlottedObject::Pseudoslot::CARRYING);
|
2015-07-22 11:24:16 +00:00
|
|
|
if (cargo == nullptr)
|
|
|
|
{
|
|
|
|
pVar->SetPointer(nullptr);
|
|
|
|
}
|
|
|
|
else if (cargo->Implements(ObjectInterfaceType::Old))
|
|
|
|
{
|
2015-08-13 08:49:26 +00:00
|
|
|
pVar->SetPointer(cargo->GetBotVar());
|
2015-07-22 11:24:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pVar = pVar->GetNext(); // "id"
|
|
|
|
value = object->GetID();
|
|
|
|
pVar->SetValInt(value);
|
|
|
|
|
|
|
|
pVar = pVar->GetNext(); // "team"
|
|
|
|
value = object->GetTeam();
|
|
|
|
pVar->SetValInt(value);
|
2015-07-22 11:46:13 +00:00
|
|
|
|
2018-12-27 22:29:39 +00:00
|
|
|
pVar = pVar->GetNext(); // "dead"
|
|
|
|
value = object->IsDying();
|
|
|
|
pVar->SetValInt(value);
|
|
|
|
|
2015-07-22 11:46:13 +00:00
|
|
|
// Updates the velocity of the object.
|
|
|
|
pVar = pVar->GetNext(); // "velocity"
|
2015-07-22 14:16:16 +00:00
|
|
|
if (IsObjectBeingTransported(object) || physics == nullptr)
|
2015-07-22 11:46:13 +00:00
|
|
|
{
|
|
|
|
pSub = pVar->GetItemList(); // "x"
|
2022-09-14 23:14:29 +00:00
|
|
|
pSub->SetValFloat(nanf(""));
|
2015-07-22 11:46:13 +00:00
|
|
|
pSub = pSub->GetNext(); // "y"
|
2022-09-14 23:14:29 +00:00
|
|
|
pSub->SetValFloat(nanf(""));
|
2015-07-22 11:46:13 +00:00
|
|
|
pSub = pSub->GetNext(); // "z"
|
2022-09-14 23:14:29 +00:00
|
|
|
pSub->SetValFloat(nanf(""));
|
2015-07-22 11:46:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-05 18:12:35 +00:00
|
|
|
glm::mat4 matRotate;
|
2015-07-22 11:46:13 +00:00
|
|
|
Math::LoadRotationZXYMatrix(matRotate, object->GetRotation());
|
|
|
|
pos = physics->GetLinMotion(MO_CURSPEED);
|
2022-01-04 23:35:41 +00:00
|
|
|
pos = Math::Transform(matRotate, pos);
|
2015-07-22 11:46:13 +00:00
|
|
|
|
|
|
|
pSub = pVar->GetItemList(); // "x"
|
|
|
|
pSub->SetValFloat(pos.x/g_unit);
|
|
|
|
pSub = pSub->GetNext(); // "y"
|
|
|
|
pSub->SetValFloat(pos.z/g_unit);
|
|
|
|
pSub = pSub->GetNext(); // "z"
|
|
|
|
pSub->SetValFloat(pos.y/g_unit);
|
|
|
|
}
|
2015-07-22 11:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CBotVar* CScriptFunctions::CreateObjectVar(CObject* obj)
|
|
|
|
{
|
|
|
|
CBotClass* bc = CBotClass::Find("object");
|
2015-08-17 20:40:52 +00:00
|
|
|
if ( bc != nullptr )
|
2015-07-22 11:24:16 +00:00
|
|
|
{
|
2015-12-31 15:54:13 +00:00
|
|
|
bc->SetUpdateFunc(CScriptFunctions::uObject);
|
2015-07-22 11:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CBotVar* botVar = CBotVar::Create("", CBotTypResult(CBotTypClass, "object"));
|
|
|
|
botVar->SetUserPtr(obj);
|
|
|
|
botVar->SetIdent(obj->GetID());
|
|
|
|
return botVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptFunctions::DestroyObjectVar(CBotVar* botVar, bool permanent)
|
|
|
|
{
|
|
|
|
if ( botVar == nullptr ) return;
|
|
|
|
|
|
|
|
botVar->SetUserPtr(OBJECTDELETED);
|
2015-10-03 20:05:14 +00:00
|
|
|
if (permanent)
|
|
|
|
CBotVar::Destroy(botVar);
|
2015-07-22 11:24:16 +00:00
|
|
|
}
|
2015-12-20 17:35:52 +00:00
|
|
|
|
|
|
|
bool CScriptFunctions::CheckOpenFiles()
|
|
|
|
{
|
|
|
|
return CBotFileColobot::m_numFilesOpen > 0;
|
2016-01-23 19:58:03 +00:00
|
|
|
}
|