Removed CTaskManager

master
krzys-h 2015-08-15 20:29:59 +02:00
parent 7fe8199c96
commit 856c5baa0e
107 changed files with 324 additions and 909 deletions

View File

@ -188,7 +188,6 @@ set(BASE_SOURCES
object/task/taskgoto.cpp
object/task/taskgungoal.cpp
object/task/taskinfo.cpp
object/task/taskmanager.cpp
object/task/taskmanip.cpp
object/task/taskpen.cpp
object/task/taskrecover.cpp

View File

@ -75,7 +75,6 @@
#include "object/task/task.h"
#include "object/task/taskbuild.h"
#include "object/task/taskmanager.h"
#include "object/task/taskmanip.h"
#include "physics/physics.h"

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// auto.h
#pragma once

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autobase.h
#pragma once
@ -119,4 +117,3 @@ protected:
Gfx::Color m_bgCloudDown;
std::set<CObject*> m_cargoObjects;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autoconvert.h
#pragma once
@ -70,4 +68,3 @@ protected:
bool m_bSoundClose = false;
int m_soundChannel = 0;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autoderrick.h
#pragma once
@ -72,4 +70,3 @@ protected:
int m_soundChannel = 0;
bool m_bSoundFall = false;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autodestroyer.h
#pragma once
@ -69,4 +67,3 @@ protected:
float m_lastParticle = 0.0f;
bool m_bExplo = false;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autoegg.h
#pragma once
@ -73,4 +71,3 @@ protected:
float m_progress = 0.0f;
float m_speed = 0.0f;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autofactory.h
#pragma once

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autoflag.h
#pragma once
@ -44,4 +42,3 @@ protected:
int m_param = 0;
float m_progress = 0.0f;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autohouston.h
#pragma once
@ -64,4 +62,3 @@ protected:
HustonLens m_lens[HUSTONMAXLENS];
int m_lensTotal = 0;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autojostle.h
#pragma once
@ -50,4 +48,3 @@ protected:
float m_lastParticle = 0.0f;
Error m_error = ERR_OK;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autolabo.h
#pragma once

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// automush.h
#pragma once
@ -61,4 +59,3 @@ protected:
float m_speed = 0.0f;
float m_lastParticle = 0.0f;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autonest.h
#pragma once
@ -62,4 +60,3 @@ protected:
float m_lastParticle = 0.0f;
Math::Vector m_cargoPos;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autonuclearplant.h
#pragma once
@ -69,4 +67,3 @@ protected:
Math::Vector m_pos;
int m_channelSound = 0;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autoportico.h
#pragma once
@ -69,4 +67,3 @@ protected:
int m_param = 0;
int m_soundChannel = 0;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autopowercaptor.h
#pragma once
@ -65,4 +63,3 @@ protected:
Math::Vector m_pos;
int m_channelSound = 0;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autopowerplant.h
#pragma once
@ -73,4 +71,3 @@ protected:
float m_lastParticle = 0.0f;
int m_partiSphere = 0;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autopowerstation.h
#pragma once
@ -57,4 +55,3 @@ protected:
bool m_bLastVirus = false;
float m_energyVirus = 0.0f;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autoradar.h
#pragma once
@ -64,4 +62,3 @@ protected:
float m_start = 0.0f;
int m_totalDetect = 0;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autorepair.h
#pragma once
@ -65,4 +63,3 @@ protected:
float m_timeVirus = 0.0f;
float m_lastParticle = 0.0f;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autoresearch.h
#pragma once

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autoroot.h
#pragma once
@ -44,4 +42,3 @@ protected:
float m_lastParticle = 0.0f;
Math::Vector m_center;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autotower.h
#pragma once
@ -75,4 +73,3 @@ protected:
float m_angleZfinal = 0.0f;
int m_partiStop[4] = {};
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// autovault.h
#pragma once
@ -75,4 +73,3 @@ protected:
Math::Vector m_keyPos[4];
int m_keyParti[4] = {};
};

View File

@ -20,8 +20,23 @@
#include "object/implementation/task_executor_impl.h"
#include "object/object.h"
#include "object/old_object.h"
#include "object/task/taskmanager.h"
#include "object/task/taskadvance.h"
#include "object/task/taskbuild.h"
#include "object/task/taskdeletemark.h"
#include "object/task/taskfire.h"
#include "object/task/taskfireant.h"
#include "object/task/taskgungoal.h"
#include "object/task/taskinfo.h"
#include "object/task/taskpen.h"
#include "object/task/taskrecover.h"
#include "object/task/tasksearch.h"
#include "object/task/taskspiderexplo.h"
#include "object/task/tasktake.h"
#include "object/task/taskterraform.h"
#include "object/task/taskturn.h"
#include "object/task/taskwait.h"
CTaskExecutorObjectImpl::CTaskExecutorObjectImpl(ObjectInterfaceTypes& types, CObject* object)
: CTaskExecutorObject(types)
@ -33,7 +48,7 @@ CTaskExecutorObjectImpl::~CTaskExecutorObjectImpl()
bool CTaskExecutorObjectImpl::EventProcess(const Event &event)
{
// NOTE: This function CAN'T BE CALLED BETWEEN CTaskManager::EventProcess AND CScriptFunctions::Process, otherwise weird stuff may happen to scripts (they'll be stuck executing the same task over and over again)
// NOTE: This function CAN'T BE CALLED BETWEEN CTask::EventProcess AND CScriptFunctions::Process, otherwise weird stuff may happen to scripts (they'll be stuck executing the same task over and over again)
EndedTask();
if ( m_foregroundTask != nullptr )
@ -59,12 +74,12 @@ bool CTaskExecutorObjectImpl::IsBackgroundTask()
return m_backgroundTask != nullptr;
}
CTaskManager* CTaskExecutorObjectImpl::GetForegroundTask()
CForegroundTask* CTaskExecutorObjectImpl::GetForegroundTask()
{
return m_foregroundTask.get();
}
CTaskManager* CTaskExecutorObjectImpl::GetBackgroundTask()
CBackgroundTask* CTaskExecutorObjectImpl::GetBackgroundTask()
{
return m_backgroundTask.get();
}
@ -118,3 +133,144 @@ Error CTaskExecutorObjectImpl::EndedTask()
return ERR_STOP;
}
template<typename TaskType, typename... Args>
Error CTaskExecutorObjectImpl::StartForegroundTask(Args&&... args)
{
static_assert(std::is_base_of<CForegroundTask, TaskType>::value, "not a foreground task");
StopForegroundTask();
assert(m_object->Implements(ObjectInterfaceType::Old)); //TODO
std::unique_ptr<TaskType> task = MakeUnique<TaskType>(dynamic_cast<COldObject*>(m_object));
Error err = task->Start(std::forward<Args>(args)...);
if (err == ERR_OK)
m_foregroundTask = std::move(task);
m_object->UpdateInterface();
return err;
}
template<typename TaskType, typename... Args>
Error CTaskExecutorObjectImpl::StartBackgroundTask(Args&&... args)
{
static_assert(std::is_base_of<CBackgroundTask, TaskType>::value, "not a background task");
Error err;
TaskType* task = dynamic_cast<TaskType*>(m_backgroundTask.get());
if (task != nullptr)
{
err = task->Start(std::forward<Args>(args)...);
if (err != ERR_OK)
m_backgroundTask.reset();
return err;
}
else
{
m_backgroundTask.reset(); // In case the old task was of a different type
assert(m_object->Implements(ObjectInterfaceType::Old)); //TODO
std::unique_ptr<TaskType> newTask = MakeUnique<TaskType>(dynamic_cast<COldObject*>(m_object));
err = newTask->Start(std::forward<Args>(args)...);
if (err == ERR_OK)
m_backgroundTask = std::move(newTask);
}
m_object->UpdateInterface();
return err;
}
Error CTaskExecutorObjectImpl::StartTaskTake()
{
return StartForegroundTask<CTaskTake>();
}
Error CTaskExecutorObjectImpl::StartTaskManip(TaskManipOrder order, TaskManipArm arm)
{
return StartForegroundTask<CTaskManip>(order, arm);
}
Error CTaskExecutorObjectImpl::StartTaskFlag(TaskFlagOrder order, int rank)
{
return StartForegroundTask<CTaskFlag>(order, rank);
}
Error CTaskExecutorObjectImpl::StartTaskBuild(ObjectType type)
{
return StartForegroundTask<CTaskBuild>(type);
}
Error CTaskExecutorObjectImpl::StartTaskSearch()
{
return StartForegroundTask<CTaskSearch>();
}
Error CTaskExecutorObjectImpl::StartTaskDeleteMark()
{
return StartForegroundTask<CTaskDeleteMark>();
}
Error CTaskExecutorObjectImpl::StartTaskTerraform()
{
return StartForegroundTask<CTaskTerraform>();
}
Error CTaskExecutorObjectImpl::StartTaskRecover()
{
return StartForegroundTask<CTaskRecover>();
}
Error CTaskExecutorObjectImpl::StartTaskFire(float delay)
{
return StartForegroundTask<CTaskFire>(delay);
}
Error CTaskExecutorObjectImpl::StartTaskFireAnt(Math::Vector impact)
{
return StartForegroundTask<CTaskFireAnt>(impact);
}
Error CTaskExecutorObjectImpl::StartTaskSpiderExplo()
{
return StartForegroundTask<CTaskSpiderExplo>();
}
Error CTaskExecutorObjectImpl::StartTaskPen(bool down, TraceColor color)
{
return StartForegroundTask<CTaskPen>(down, color);
}
Error CTaskExecutorObjectImpl::StartTaskWait(float time)
{
return StartForegroundTask<CTaskWait>(time);
}
Error CTaskExecutorObjectImpl::StartTaskAdvance(float length)
{
return StartForegroundTask<CTaskAdvance>(length);
}
Error CTaskExecutorObjectImpl::StartTaskTurn(float angle)
{
return StartForegroundTask<CTaskTurn>(angle);
}
Error CTaskExecutorObjectImpl::StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode)
{
return StartForegroundTask<CTaskGoto>(pos, altitude, goalMode, crashMode);
}
Error CTaskExecutorObjectImpl::StartTaskInfo(const char *name, float value, float power, bool bSend)
{
return StartForegroundTask<CTaskInfo>(name, value, power, bSend);
}
Error CTaskExecutorObjectImpl::StartTaskShield(TaskShieldMode mode, float delay)
{
return StartBackgroundTask<CTaskShield>(mode, delay);
}
Error CTaskExecutorObjectImpl::StartTaskGunGoal(float dirV, float dirH)
{
return StartBackgroundTask<CTaskGunGoal>(dirV, dirH);
}

View File

@ -24,7 +24,6 @@
#include <memory>
class CObject;
class CTaskManager;
class CTaskExecutorObjectImpl : public CTaskExecutorObject
{
@ -37,40 +36,46 @@ public:
bool IsForegroundTask() override;
bool IsBackgroundTask() override;
CTaskManager* GetForegroundTask() override;
CTaskManager* GetBackgroundTask() override;
CForegroundTask* GetForegroundTask() override;
CBackgroundTask* GetBackgroundTask() override;
void StopForegroundTask() override;
void StopBackgroundTask() override;
Error StartTaskTake() { return ERR_WRONG_BOT; }
Error StartTaskManip(TaskManipOrder order, TaskManipArm arm) { return ERR_WRONG_BOT; }
Error StartTaskFlag(TaskFlagOrder order, int rank) { return ERR_WRONG_BOT; }
Error StartTaskBuild(ObjectType type) { return ERR_WRONG_BOT; }
Error StartTaskSearch() { return ERR_WRONG_BOT; }
Error StartTaskDeleteMark() { return ERR_WRONG_BOT; }
Error StartTaskTerraform() { return ERR_WRONG_BOT; }
Error StartTaskRecover() { return ERR_WRONG_BOT; }
Error StartTaskFire(float delay) { return ERR_WRONG_BOT; }
Error StartTaskFireAnt(Math::Vector impact) { return ERR_WRONG_BOT; }
Error StartTaskSpiderExplo() { return ERR_WRONG_BOT; }
Error StartTaskPen(bool down, TraceColor color = TraceColor::Default) { return ERR_WRONG_BOT; }
Error StartTaskTake() override;
Error StartTaskManip(TaskManipOrder order, TaskManipArm arm) override;
Error StartTaskFlag(TaskFlagOrder order, int rank) override;
Error StartTaskBuild(ObjectType type) override;
Error StartTaskSearch() override;
Error StartTaskDeleteMark() override;
Error StartTaskTerraform() override;
Error StartTaskRecover() override;
Error StartTaskFire(float delay) override;
Error StartTaskFireAnt(Math::Vector impact) override;
Error StartTaskSpiderExplo() override;
Error StartTaskPen(bool down, TraceColor color = TraceColor::Default) override;
Error StartTaskWait(float time) { return ERR_UNKNOWN; }
Error StartTaskAdvance(float length) { return ERR_UNKNOWN; }
Error StartTaskTurn(float angle) { return ERR_UNKNOWN; }
Error StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode) { return ERR_UNKNOWN; }
Error StartTaskInfo(const char *name, float value, float power, bool bSend) { return ERR_UNKNOWN; }
Error StartTaskWait(float time) override;
Error StartTaskAdvance(float length) override;
Error StartTaskTurn(float angle) override;
Error StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode) override;
Error StartTaskInfo(const char *name, float value, float power, bool bSend) override;
Error StartTaskShield(TaskShieldMode mode, float delay = 1000.0f) { return ERR_WRONG_BOT; }
Error StartTaskGunGoal(float dirV, float dirH) { return ERR_WRONG_BOT; }
Error StartTaskShield(TaskShieldMode mode, float delay = 1000.0f) override;
Error StartTaskGunGoal(float dirV, float dirH) override;
private:
Error EndedTask();
template<typename TaskType, typename... Args>
Error StartForegroundTask(Args&&... args);
template<typename TaskType, typename... Args>
Error StartBackgroundTask(Args&&... args);
protected:
std::unique_ptr<CTaskManager> m_foregroundTask;
std::unique_ptr<CTaskManager> m_backgroundTask;
std::unique_ptr<CForegroundTask> m_foregroundTask;
std::unique_ptr<CBackgroundTask> m_backgroundTask;
private:
CObject* m_object;

View File

@ -29,7 +29,7 @@
#include "object/task/taskmanip.h"
#include "object/task/taskshield.h"
class CTaskManager;
class CTask;
/**
* \class CTaskExecutorObject
@ -80,9 +80,9 @@ public:
virtual bool IsBackgroundTask() = 0;
//! Return the foreground task
virtual CTaskManager* GetForegroundTask() = 0;
virtual CForegroundTask* GetForegroundTask() = 0;
//! Return the background task
virtual CTaskManager* GetBackgroundTask() = 0;
virtual CBackgroundTask* GetBackgroundTask() = 0;
//! Stop foreground task
virtual void StopForegroundTask() = 0;

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// motion.h
#pragma once

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// motionant.h
#pragma once

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// motionbee.h
#pragma once

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// motionhuman.h
#pragma once
@ -94,4 +92,3 @@ protected:
float m_tired;
bool m_bDisplayPerso;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// motionlevelcontroller.h
#pragma once
@ -33,4 +31,3 @@ public:
void DeleteObject(bool bAll=false);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::COldModelManager* modelManager);
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// motionqueen.h
#pragma once

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// motionspider.h
#pragma once

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// motiontoto.h
#pragma once
@ -70,4 +68,3 @@ protected:
ObjectType m_type;
Math::Point m_mousePos;
};

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// motionworm.h
#pragma once
@ -62,4 +60,3 @@ protected:
bool m_bArmStop;
float m_lastParticle;
};

View File

@ -53,8 +53,6 @@
#include "object/subclass/exchange_post.h"
#include "object/task/taskmanager.h"
#include "physics/physics.h"
#include "script/cbottoken.h"
@ -3208,239 +3206,6 @@ void COldObject::SetScale(const Math::Vector& scale)
SetPartScale(0, scale);
}
// Move the manipulator arm.
Error COldObject::StartTaskTake()
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskTake();
UpdateInterface();
return err;
}
// Move the manipulator arm.
Error COldObject::StartTaskManip(TaskManipOrder order, TaskManipArm arm)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskManip(order, arm);
UpdateInterface();
return err;
}
// Puts or removes a flag.
Error COldObject::StartTaskFlag(TaskFlagOrder order, int rank)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskFlag(order, rank);
UpdateInterface();
return err;
}
// Built a building.
Error COldObject::StartTaskBuild(ObjectType type)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskBuild(type);
UpdateInterface();
return err;
}
// Probe the ground.
Error COldObject::StartTaskSearch()
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskSearch();
UpdateInterface();
return err;
}
// Delete mark on ground
Error COldObject::StartTaskDeleteMark()
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskDeleteMark();
UpdateInterface();
return err;
}
// Terraformed the ground.
Error COldObject::StartTaskTerraform()
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskTerraform();
UpdateInterface();
return err;
}
// Change pencil.
Error COldObject::StartTaskPen(bool down, TraceColor color)
{
auto motionVehicle = dynamic_cast<CMotionVehicle*>(m_motion.get());
assert(motionVehicle != nullptr);
if (color == TraceColor::Default)
color = GetTraceColor();
SetTraceDown(down);
SetTraceColor(color);
m_physics->SetMotorSpeedX(0.0f);
m_physics->SetMotorSpeedY(0.0f);
m_physics->SetMotorSpeedZ(0.0f);
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskPen(down, color);
UpdateInterface();
return err;
}
// Recovers a ruin.
Error COldObject::StartTaskRecover()
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskRecover();
UpdateInterface();
return err;
}
// Shoots.
Error COldObject::StartTaskFire(float delay)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskFire(delay);
UpdateInterface();
return err;
}
// Explodes spider.
Error COldObject::StartTaskSpiderExplo()
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskSpiderExplo();
UpdateInterface();
return err;
}
// Shoots to the ant.
Error COldObject::StartTaskFireAnt(Math::Vector impact)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskFireAnt(impact);
UpdateInterface();
return err;
}
Error COldObject::StartTaskWait(float time)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskWait(time);
UpdateInterface();
return err;
}
Error COldObject::StartTaskAdvance(float length)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskAdvance(length);
UpdateInterface();
return err;
}
Error COldObject::StartTaskTurn(float angle)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskTurn(angle);
UpdateInterface();
return err;
}
Error COldObject::StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskGoto(pos, altitude, goalMode, crashMode);
UpdateInterface();
return err;
}
Error COldObject::StartTaskInfo(const char *name, float value, float power, bool bSend)
{
StopForegroundTask();
m_foregroundTask = MakeUnique<CTaskManager>(this);
Error err = m_foregroundTask->StartTaskInfo(name, value, power, bSend);
UpdateInterface();
return err;
}
// Deploys the shield.
Error COldObject::StartTaskShield(TaskShieldMode mode, float delay)
{
if (m_backgroundTask == nullptr)
{
m_backgroundTask = MakeUnique<CTaskManager>(this);
}
Error err = m_backgroundTask->StartTaskShield(mode, delay);
UpdateInterface();
return err;
}
// Adjusts upward.
Error COldObject::StartTaskGunGoal(float dirV, float dirH)
{
StopBackgroundTask();
m_backgroundTask = MakeUnique<CTaskManager>(this);
Error err = m_backgroundTask->StartTaskGunGoal(dirV, dirH);
UpdateInterface();
return err;
}
void COldObject::UpdateInterface()
{
if (m_objectInterface != nullptr && GetSelect())

View File

@ -287,28 +287,6 @@ public:
void SetScale(const Math::Vector& scale) override;
Math::Vector GetScale() const override;
Error StartTaskTake() override;
Error StartTaskManip(TaskManipOrder order, TaskManipArm arm) override;
Error StartTaskFlag(TaskFlagOrder order, int rank) override;
Error StartTaskBuild(ObjectType type) override;
Error StartTaskSearch() override;
Error StartTaskDeleteMark() override;
Error StartTaskTerraform() override;
Error StartTaskRecover() override;
Error StartTaskFire(float delay) override;
Error StartTaskFireAnt(Math::Vector impact) override;
Error StartTaskSpiderExplo() override;
Error StartTaskPen(bool down, TraceColor color = TraceColor::Default) override;
Error StartTaskWait(float time) override;
Error StartTaskAdvance(float length) override;
Error StartTaskTurn(float angle) override;
Error StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode) override;
Error StartTaskInfo(const char *name, float value, float power, bool bSend) override;
Error StartTaskShield(TaskShieldMode mode, float delay = 1000.0f) override;
Error StartTaskGunGoal(float dirV, float dirH) override;
void UpdateInterface() override;
void StopProgram() override;

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// task.h
#pragma once
@ -73,6 +71,12 @@ public:
virtual bool IsBusy();
virtual bool Abort();
//! Returns true if you can control the robot while the task is executing
virtual bool IsPilot() = 0;
//! Returns true if this task is meant to be run as a background task
virtual bool IsBackground() = 0;
protected:
Gfx::CEngine* m_engine = nullptr;
Gfx::CLightManager* m_lightMan = nullptr;
@ -88,3 +92,21 @@ protected:
CMotion* m_motion = nullptr;
CPhysics* m_physics = nullptr;
};
class CForegroundTask : public CTask
{
public:
CForegroundTask(COldObject* object) : CTask(object) {}
bool IsBackground() final { return false; }
virtual bool IsPilot() { return false; }
};
class CBackgroundTask : public CTask
{
public:
CBackgroundTask(COldObject* object) : CTask(object) {}
bool IsBackground() final { return true; }
bool IsPilot() final { return true; }
};

View File

@ -35,7 +35,7 @@
// Object's constructor.
CTaskAdvance::CTaskAdvance(COldObject* object) : CTask(object)
CTaskAdvance::CTaskAdvance(COldObject* object) : CForegroundTask(object)
{
}
@ -147,4 +147,3 @@ Error CTaskAdvance::IsEnded()
}
return ERR_CONTINUE;
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskadvance.h
#pragma once
@ -28,7 +26,7 @@
class CTaskAdvance : public CTask
class CTaskAdvance : public CForegroundTask
{
public:
CTaskAdvance(COldObject* object);
@ -49,4 +47,3 @@ protected:
float m_fixTime = 0.0f;
bool m_bError = false;
};

View File

@ -47,7 +47,7 @@
// Object's constructor.
CTaskBuild::CTaskBuild(COldObject* object) : CTask(object)
CTaskBuild::CTaskBuild(COldObject* object) : CForegroundTask(object)
{
int i;

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskbuild.h
#pragma once
@ -49,7 +47,7 @@ enum TaskBuildPhase
class CTaskBuild : public CTask
class CTaskBuild : public CForegroundTask
{
public:
CTaskBuild(COldObject* object);
@ -89,4 +87,3 @@ protected:
int m_lightRank[TBMAXLIGHT] = {}; // lights for the effects
int m_soundChannel = 0;
};

View File

@ -35,7 +35,7 @@
#include "physics/physics.h"
CTaskDeleteMark::CTaskDeleteMark(COldObject* object) : CTask(object)
CTaskDeleteMark::CTaskDeleteMark(COldObject* object) : CForegroundTask(object)
{
m_bExecuted = false;
}

View File

@ -17,15 +17,13 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// tasksearch.h
#pragma once
#include "object/task/task.h"
class CTaskDeleteMark : public CTask
class CTaskDeleteMark : public CForegroundTask
{
public:
CTaskDeleteMark(COldObject* object);

View File

@ -38,7 +38,7 @@ const float ENERGY_FIREi = (0.10f/2.5f); // energy consumed/organic
// Object's constructor.
CTaskFire::CTaskFire(COldObject* object) : CTask(object)
CTaskFire::CTaskFire(COldObject* object) : CForegroundTask(object)
{
m_soundChannel = -1;
@ -387,3 +387,8 @@ bool CTaskFire::Abort()
//? m_camera->StopCentering(m_object, 1.0f);
return true;
}
bool CTaskFire::IsPilot()
{
return true;
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskfire.h
#pragma once
@ -26,7 +24,7 @@
class CTaskFire : public CTask
class CTaskFire : public CForegroundTask
{
public:
CTaskFire(COldObject* object);
@ -37,6 +35,7 @@ public:
Error Start(float delay);
Error IsEnded();
bool Abort();
bool IsPilot();
protected:
float m_delay = 0.0f;
@ -50,4 +49,3 @@ protected:
float m_lastSound = 0.0f;
int m_soundChannel = 0;
};

View File

@ -35,7 +35,7 @@
// Object's constructor.
CTaskFireAnt::CTaskFireAnt(COldObject* object) : CTask(object)
CTaskFireAnt::CTaskFireAnt(COldObject* object) : CForegroundTask(object)
{
m_phase = TFA_NULL;
}
@ -212,4 +212,3 @@ bool CTaskFireAnt::Abort()
m_motion->SetAction(-1);
return true;
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskfireant.h
#pragma once
@ -38,7 +36,7 @@ enum TaskFireAnt
class CTaskFireAnt : public CTask
class CTaskFireAnt : public CForegroundTask
{
public:
CTaskFireAnt(COldObject* object);
@ -63,4 +61,3 @@ protected:
float m_time = 0.0f;
float m_lastParticle = 0.0f;
};

View File

@ -40,7 +40,7 @@
// Object's constructor.
CTaskFlag::CTaskFlag(COldObject* object) : CTask(object)
CTaskFlag::CTaskFlag(COldObject* object) : CForegroundTask(object)
{
}

View File

@ -16,7 +16,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
// taskflag.h
#pragma once
@ -37,7 +36,7 @@ enum TaskFlagOrder
class CTaskFlag : public CTask
class CTaskFlag : public CForegroundTask
{
public:
CTaskFlag(COldObject* object);
@ -60,4 +59,3 @@ protected:
float m_time = 0.0f;
bool m_bError = false;
};

View File

@ -53,7 +53,7 @@ const float SAFETY_MARGIN = 0.5f; // Smallest distance between two objects
// Object's constructor.
CTaskGoto::CTaskGoto(COldObject* object) : CTask(object)
CTaskGoto::CTaskGoto(COldObject* object) : CForegroundTask(object)
{
m_bmArray = 0;
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskgoto.h
#pragma once
@ -75,7 +73,7 @@ enum TaskGotoPhase
class CTaskGoto : public CTask
class CTaskGoto : public CForegroundTask
{
public:
CTaskGoto(COldObject* object);
@ -160,4 +158,3 @@ protected:
float m_leakTime = 0.0f;
bool m_bLeakRecede = false;
};

View File

@ -27,7 +27,7 @@
// Object's constructor.
CTaskGunGoal::CTaskGunGoal(COldObject* object) : CTask(object)
CTaskGunGoal::CTaskGunGoal(COldObject* object) : CBackgroundTask(object)
{
m_aimImpossible = false;
}
@ -164,4 +164,3 @@ bool CTaskGunGoal::Abort()
{
return true;
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskgungoal.h
#pragma once
@ -26,7 +24,7 @@
class CTaskGunGoal : public CTask
class CTaskGunGoal : public CBackgroundTask
{
public:
CTaskGunGoal(COldObject* object);
@ -48,4 +46,3 @@ protected:
bool m_aimImpossible = false; // set to true if impossible aim was set
};

View File

@ -34,7 +34,7 @@
// Object's constructor.
CTaskInfo::CTaskInfo(COldObject* object) : CTask(object)
CTaskInfo::CTaskInfo(COldObject* object) : CForegroundTask(object)
, m_progress(0.0f)
, m_speed(0.0f)
, m_time(0.0f)

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskinfo.h
#pragma once
@ -26,7 +24,7 @@
class CExchangePost;
class CTaskInfo : public CTask
class CTaskInfo : public CForegroundTask
{
public:
CTaskInfo(COldObject* object);
@ -47,4 +45,3 @@ protected:
float m_time = 0.0f;
bool m_error = false;
};

View File

@ -1,263 +0,0 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* 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 "object/task/taskmanager.h"
#include "common/make_unique.h"
#include "object/old_object.h"
#include "object/task/taskadvance.h"
#include "object/task/taskbuild.h"
#include "object/task/taskdeletemark.h"
#include "object/task/taskfire.h"
#include "object/task/taskfireant.h"
#include "object/task/taskgungoal.h"
#include "object/task/taskinfo.h"
#include "object/task/taskpen.h"
#include "object/task/taskrecover.h"
#include "object/task/tasksearch.h"
#include "object/task/taskspiderexplo.h"
#include "object/task/tasktake.h"
#include "object/task/taskterraform.h"
#include "object/task/taskturn.h"
#include "object/task/taskwait.h"
// Object's constructor.
CTaskManager::CTaskManager(COldObject* object)
: m_object(object),
m_bPilot(false)
{
}
// Object's destructor.
CTaskManager::~CTaskManager()
{
}
template<typename TaskType, typename... Args>
Error CTaskManager::StartTask(Args&&... args)
{
auto task = MakeUnique<TaskType>(m_object);
auto* taskPtr = task.get();
m_task = std::move(task);
return taskPtr->Start(std::forward<Args>(args)...);
}
// Waits for a while.
Error CTaskManager::StartTaskWait(float time)
{
return StartTask<CTaskWait>(time);
}
// Advance straight ahead a certain distance.
Error CTaskManager::StartTaskAdvance(float length)
{
return StartTask<CTaskAdvance>(length);
}
// Turns through an certain angle.
Error CTaskManager::StartTaskTurn(float angle)
{
return StartTask<CTaskTurn>(angle);
}
// Reaches a given position.
Error CTaskManager::StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode)
{
return StartTask<CTaskGoto>(pos, altitude, goalMode, crashMode);
}
// Move the manipulator arm.
Error CTaskManager::StartTaskTake()
{
return StartTask<CTaskTake>();
}
// Move the manipulator arm.
Error CTaskManager::StartTaskManip(TaskManipOrder order, TaskManipArm arm)
{
return StartTask<CTaskManip>(order, arm);
}
// Puts or removes a flag.
Error CTaskManager::StartTaskFlag(TaskFlagOrder order, int rank)
{
return StartTask<CTaskFlag>(order, rank);
}
// Builds a building.
Error CTaskManager::StartTaskBuild(ObjectType type)
{
return StartTask<CTaskBuild>(type);
}
// Probe the ground.
Error CTaskManager::StartTaskSearch()
{
return StartTask<CTaskSearch>();
}
// Delete mark on ground
Error CTaskManager::StartTaskDeleteMark()
{
return StartTask<CTaskDeleteMark>();
}
// Reads an information terminal.
Error CTaskManager::StartTaskInfo(const char *name, float value, float power, bool bSend)
{
return StartTask<CTaskInfo>(name, value, power, bSend);
}
// Terraforms the ground.
Error CTaskManager::StartTaskTerraform()
{
return StartTask<CTaskTerraform>();
}
// Changes the pencil.
Error CTaskManager::StartTaskPen(bool bDown, TraceColor color)
{
return StartTask<CTaskPen>(bDown, color);
}
// Recovers a ruin.
Error CTaskManager::StartTaskRecover()
{
return StartTask<CTaskRecover>();
}
// Deploys the shield.
Error CTaskManager::StartTaskShield(TaskShieldMode mode, float delay)
{
if (mode == TSM_UP || mode == TSM_START)
{
return StartTask<CTaskShield>(mode, delay);
}
else if (m_task != nullptr)
{
// TODO: is this static_cast really safe?
return (static_cast<CTaskShield*>(m_task.get()))->Start(mode, delay);
}
return ERR_UNKNOWN;
}
// Shoots.
Error CTaskManager::StartTaskFire(float delay)
{
m_bPilot = true;
return StartTask<CTaskFire>(delay);
}
// Shoots with the ant.
Error CTaskManager::StartTaskFireAnt(Math::Vector impact)
{
return StartTask<CTaskFireAnt>(impact);
}
// Adjusts higher.
Error CTaskManager::StartTaskGunGoal(float dirV, float dirH)
{
return StartTask<CTaskGunGoal>(dirV, dirH);
}
// Suicide of the spider.
Error CTaskManager::StartTaskSpiderExplo()
{
return StartTask<CTaskSpiderExplo>();
}
// Management of an event.
bool CTaskManager::EventProcess(const Event &event)
{
if (m_task == nullptr)
return false;
return m_task->EventProcess(event);
}
// Indicates whether the action is finished.
Error CTaskManager::IsEnded()
{
if (m_task == nullptr)
return ERR_UNKNOWN;
return m_task->IsEnded();
}
// Indicates whether the action is pending.
bool CTaskManager::IsBusy()
{
if (m_task == nullptr)
return false;
return m_task->IsBusy();
}
// Indicates whether it is possible to control the robot
// during the execution of the current task.
bool CTaskManager::IsPilot()
{
return m_bPilot;
}
// Suddenly ends the current action.
bool CTaskManager::Abort()
{
if (m_task == nullptr)
return false;
return m_task->Abort();
}

View File

@ -1,75 +0,0 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* 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
*/
// taskmanager.h
#pragma once
#include "object/interface/trace_drawing_object.h"
#include "object/task/task.h"
#include "object/task/taskflag.h"
#include "object/task/taskgoto.h"
#include "object/task/taskmanip.h"
#include "object/task/taskshield.h"
#include <memory>
class CTaskManager
{
public:
CTaskManager(COldObject* object);
~CTaskManager();
Error StartTaskWait(float time);
Error StartTaskAdvance(float length);
Error StartTaskTurn(float angle);
Error StartTaskGoto(Math::Vector pos, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode);
Error StartTaskTake();
Error StartTaskManip(TaskManipOrder order, TaskManipArm arm);
Error StartTaskFlag(TaskFlagOrder order, int rank);
Error StartTaskBuild(ObjectType type);
Error StartTaskSearch();
Error StartTaskDeleteMark();
Error StartTaskInfo(const char *name, float value, float power, bool bSend);
Error StartTaskTerraform();
Error StartTaskPen(bool bDown, TraceColor color);
Error StartTaskRecover();
Error StartTaskShield(TaskShieldMode mode, float delay);
Error StartTaskFire(float delay);
Error StartTaskFireAnt(Math::Vector impact);
Error StartTaskGunGoal(float dirV, float dirH);
Error StartTaskSpiderExplo();
bool EventProcess(const Event &event);
Error IsEnded();
bool IsBusy();
bool IsPilot();
bool Abort();
protected:
template<typename TaskType, typename... Args>
Error StartTask(Args&&... args);
protected:
std::unique_ptr<CTask> m_task;
COldObject* m_object = nullptr;
bool m_bPilot = false;
};

View File

@ -51,7 +51,7 @@ const float MARGIN_BEE = 5.0f; //OK 1.9
// Object's constructor.
CTaskManip::CTaskManip(COldObject* object) : CTask(object)
CTaskManip::CTaskManip(COldObject* object) : CForegroundTask(object)
{
m_arm = TMA_NEUTRAL;
m_hand = TMH_OPEN;

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskmanip.h
#pragma once
@ -58,7 +56,7 @@ enum TaskManipHand
class CTaskManip : public CTask
class CTaskManip : public CForegroundTask
{
public:
CTaskManip(COldObject* object);
@ -103,4 +101,3 @@ protected:
float m_timeLimit = 0.0f;
ObjectType m_cargoType = OBJECT_NULL;
};

View File

@ -25,12 +25,14 @@
#include "object/old_object.h"
#include "physics/physics.h"
#include "sound/sound.h"
// Object's constructor.
CTaskPen::CTaskPen(COldObject* object) : CTask(object)
CTaskPen::CTaskPen(COldObject* object) : CForegroundTask(object)
{
}
@ -136,6 +138,16 @@ Error CTaskPen::Start(bool bDown, TraceColor color)
ObjectType type;
int i;
if (color == TraceColor::Default)
color = m_object->GetTraceColor();
m_object->SetTraceDown(bDown);
m_object->SetTraceColor(color);
m_physics->SetMotorSpeedX(0.0f);
m_physics->SetMotorSpeedY(0.0f);
m_physics->SetMotorSpeedZ(0.0f);
m_bError = true; // operation impossible
type = m_object->GetType();

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskpen.h
#pragma once
@ -38,7 +36,7 @@ enum TaskPenPhase
class CTaskPen : public CTask
class CTaskPen : public CForegroundTask
{
public:
CTaskPen(COldObject* object);

View File

@ -43,7 +43,7 @@ const float RECOVER_DIST = 11.8f;
// Object's constructor.
CTaskRecover::CTaskRecover(COldObject* object) : CTask(object)
CTaskRecover::CTaskRecover(COldObject* object) : CForegroundTask(object)
{
m_ruin = 0;
m_soundChannel = -1;

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskrecover.h
#pragma once
@ -39,7 +37,7 @@ enum TaskRecoverPhase
class CTaskRecover : public CTask
class CTaskRecover : public CForegroundTask
{
public:
CTaskRecover(COldObject* object);
@ -67,4 +65,3 @@ protected:
Math::Vector m_recoverPos;
int m_soundChannel = 0;
};

View File

@ -35,7 +35,7 @@
// Object's constructor.
CTaskSearch::CTaskSearch(COldObject* object) : CTask(object)
CTaskSearch::CTaskSearch(COldObject* object) : CForegroundTask(object)
{
m_hand = TSH_UP;
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// tasksearch.h
#pragma once
@ -43,7 +41,7 @@ enum TaskSearchPhase
class CTaskSearch : public CTask
class CTaskSearch : public CForegroundTask
{
public:
CTaskSearch(COldObject* object);
@ -71,4 +69,3 @@ protected:
float m_finalAngle[3] = {};
bool m_bError = false;
};

View File

@ -44,7 +44,7 @@ const float ENERGY_TIME = 20.0f; // maximum duration if full battery
// Object's constructor.
CTaskShield::CTaskShield(COldObject* object) : CTask(object)
CTaskShield::CTaskShield(COldObject* object) : CBackgroundTask(object)
{
m_rankSphere = -1;
m_soundChannel = -1;

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskshield.h
#pragma once
@ -51,7 +49,7 @@ enum TaskShieldMode
class CTaskShield : public CTask
class CTaskShield : public CBackgroundTask
{
public:
CTaskShield(COldObject* object);
@ -86,4 +84,3 @@ protected:
int m_soundChannel = 0;
int m_effectLight = 0;
};

View File

@ -34,7 +34,7 @@
// Object's constructor.
CTaskSpiderExplo::CTaskSpiderExplo(COldObject* object) : CTask(object)
CTaskSpiderExplo::CTaskSpiderExplo(COldObject* object) : CForegroundTask(object)
{
m_time = 0.0f;
m_bError = false;
@ -107,4 +107,3 @@ bool CTaskSpiderExplo::Abort()
{
return true;
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskspiderexplo.h
#pragma once
@ -26,7 +24,7 @@
class CTaskSpiderExplo : public CTask
class CTaskSpiderExplo : public CForegroundTask
{
public:
CTaskSpiderExplo(COldObject* object);
@ -42,4 +40,3 @@ protected:
float m_time = 0.0f;
bool m_bError = false;
};

View File

@ -43,7 +43,7 @@
// Object's constructor.
CTaskTake::CTaskTake(COldObject* object) : CTask(object)
CTaskTake::CTaskTake(COldObject* object) : CForegroundTask(object)
{
m_arm = TTA_NEUTRAL;

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// tasktake.h
#pragma once
@ -44,7 +42,7 @@ enum TaskTakeArm
class CTaskTake : public CTask
class CTaskTake : public CForegroundTask
{
public:
CTaskTake(COldObject* object);
@ -75,4 +73,3 @@ protected:
float m_angle = 0.0f;
ObjectType m_cargoType = OBJECT_NULL;
};

View File

@ -45,7 +45,7 @@ const float ACTION_RADIUS = 400.0f;
// Object's constructor.
CTaskTerraform::CTaskTerraform(COldObject* object) : CTask(object)
CTaskTerraform::CTaskTerraform(COldObject* object) : CForegroundTask(object)
{
m_lastParticle = 0.0f;
m_soundChannel = -1;

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskterraform.h
#pragma once
@ -37,7 +35,7 @@ enum TaskTerraPhase
class CTaskTerraform : public CTask
class CTaskTerraform : public CForegroundTask
{
public:
CTaskTerraform(COldObject* object);
@ -62,4 +60,3 @@ protected:
bool m_bError = false;
Math::Vector m_terraPos;
};

View File

@ -31,7 +31,7 @@
// Object's constructor.
CTaskTurn::CTaskTurn(COldObject* object) : CTask(object)
CTaskTurn::CTaskTurn(COldObject* object) : CForegroundTask(object)
{
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskturn.h
#pragma once
@ -26,7 +24,7 @@
class CTaskTurn : public CTask
class CTaskTurn : public CForegroundTask
{
public:
CTaskTurn(COldObject* object);
@ -44,4 +42,3 @@ protected:
bool m_bLeft = false;
bool m_bError = false;
};

View File

@ -26,7 +26,7 @@
// Object's constructor.
CTaskWait::CTaskWait(COldObject* object) : CTask(object)
CTaskWait::CTaskWait(COldObject* object) : CForegroundTask(object)
{
}
@ -68,4 +68,3 @@ Error CTaskWait::IsEnded()
if ( m_bEnded ) return ERR_STOP;
return ERR_CONTINUE;
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// taskwait.h
#pragma once
@ -26,7 +24,7 @@
class CTaskWait : public CTask
class CTaskWait : public CForegroundTask
{
public:
CTaskWait(COldObject* object);
@ -42,4 +40,3 @@ protected:
float m_passTime = 0.0f;
bool m_bEnded = false;
};

View File

@ -54,8 +54,6 @@
#include "object/subclass/exchange_post.h"
#include "object/task/taskmanager.h"
#include "physics/physics.h"
#include "script/cbottoken.h"
@ -1174,11 +1172,10 @@ bool CScriptFunctions::rRadar(CBotVar* var, CBotVar* result, int& exception, voi
// Monitoring a task.
bool CScriptFunctions::Process(CScript* script, CBotVar* result, int &exception)
bool CScriptFunctions::WaitForForegroundTask(CScript* script, CBotVar* result, int &exception)
{
Error err;
err = script->m_taskExecutor->GetForegroundTask()->IsEnded();
assert(script->m_taskExecutor->IsForegroundTask());
Error err = script->m_taskExecutor->GetForegroundTask()->IsEnded();
if ( err != ERR_CONTINUE ) // task terminated?
{
script->m_taskExecutor->StopForegroundTask();
@ -1187,7 +1184,31 @@ bool CScriptFunctions::Process(CScript* script, CBotVar* result, int &exception)
if ( err == ERR_STOP ) err = ERR_OK;
result->SetValInt(err); // indicates the error or ok
if ( ShouldProcessStop(err, script->m_errMode) )
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) )
{
exception = err;
return false;
@ -1202,7 +1223,7 @@ bool CScriptFunctions::Process(CScript* script, CBotVar* result, int &exception)
// Returns true if error code means real error and exception must be thrown
bool CScriptFunctions::ShouldProcessStop(Error err, int errMode)
bool CScriptFunctions::ShouldTaskStop(Error err, int errMode)
{
// aim impossible - not a real error
if ( err == ERR_AIM_IMPOSSIBLE )
@ -1305,7 +1326,7 @@ bool CScriptFunctions::rDetect(CBotVar* var, CBotVar* result, int& exception, vo
return true;
}
}
if ( !Process(script, result, exception) ) return false; // not finished
if ( !WaitForForegroundTask(script, result, exception) ) return false; // not finished
result->SetValFloat(script->m_returnValue);
return true;
}
@ -1436,7 +1457,7 @@ bool CScriptFunctions::rBuild(CBotVar* var, CBotVar* result, int& exception, voi
return true;
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
@ -1880,7 +1901,7 @@ bool CScriptFunctions::rWait(CBotVar* var, CBotVar* result, int& exception, void
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Instruction "move(dist)".
@ -1909,7 +1930,7 @@ bool CScriptFunctions::rMove(CBotVar* var, CBotVar* result, int& exception, void
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Instruction "turn(angle)".
@ -1938,7 +1959,7 @@ bool CScriptFunctions::rTurn(CBotVar* var, CBotVar* result, int& exception, void
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Compilation of the instruction "goto(pos, altitude, crash, goal)".
@ -2018,7 +2039,7 @@ bool CScriptFunctions::rGoto(CBotVar* var, CBotVar* result, int& exception, void
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Compilation "grab/drop(oper)".
@ -2078,7 +2099,7 @@ bool CScriptFunctions::rGrab(CBotVar* var, CBotVar* result, int& exception, void
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Instruction "drop(oper)".
@ -2121,7 +2142,7 @@ bool CScriptFunctions::rDrop(CBotVar* var, CBotVar* result, int& exception, void
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Instruction "sniff()".
@ -2148,7 +2169,7 @@ bool CScriptFunctions::rSniff(CBotVar* var, CBotVar* result, int& exception, voi
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Compilation of the instruction "receive(nom, power)".
@ -2201,7 +2222,7 @@ bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, v
return true;
}
}
if ( !Process(script, result, exception) ) return false; // not finished
if ( !WaitForForegroundTask(script, result, exception) ) return false; // not finished
value = pThis->GetInfoReturn();
if ( std::isnan(value) )
@ -2276,7 +2297,7 @@ bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Seeks the nearest information terminal.
@ -2406,7 +2427,7 @@ bool CScriptFunctions::rThump(CBotVar* var, CBotVar* result, int& exception, voi
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Instruction "recycle()".
@ -2433,7 +2454,7 @@ bool CScriptFunctions::rRecycle(CBotVar* var, CBotVar* result, int& exception, v
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Compilation "shield(oper, radius)".
@ -2591,7 +2612,7 @@ bool CScriptFunctions::rFire(CBotVar* var, CBotVar* result, int& exception, void
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
// Compilation of the instruction "aim(x, y)".
@ -2621,7 +2642,7 @@ bool CScriptFunctions::rAim(CBotVar* var, CBotVar* result, int& exception, void*
exception = 0;
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
if ( !script->m_taskExecutor->IsBackgroundTask() ) // no task in progress?
{
x = var->GetValFloat();
var = var->GetNext();
@ -2633,12 +2654,12 @@ bool CScriptFunctions::rAim(CBotVar* var, CBotVar* result, int& exception, void*
}
else if ( err != ERR_OK )
{
script->m_taskExecutor->StopForegroundTask();
script->m_taskExecutor->StopBackgroundTask();
result->SetValInt(err); // shows the error
return true;
}
}
return Process(script, result, exception);
return WaitForBackgroundTask(script, result, exception);
}
// Compilation of the instruction "motor(left, right)".
@ -2926,7 +2947,7 @@ bool CScriptFunctions::rPenDown(CBotVar* var, CBotVar* result, int& exception, v
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
else
{
@ -2975,7 +2996,7 @@ bool CScriptFunctions::rPenUp(CBotVar* var, CBotVar* result, int& exception, voi
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
else
{
@ -3029,7 +3050,7 @@ bool CScriptFunctions::rPenColor(CBotVar* var, CBotVar* result, int& exception,
return true;
}
}
return Process(script, result, exception);
return WaitForForegroundTask(script, result, exception);
}
else
{

View File

@ -190,8 +190,9 @@ public:
static int m_numberOfOpenFiles;
private:
static bool Process(CScript* script, CBotVar* result, int &exception);
static bool ShouldProcessStop(Error err, int errMode);
static bool WaitForForegroundTask(CScript* script, CBotVar* result, int &exception);
static bool WaitForBackgroundTask(CScript* script, CBotVar* result, int &exception);
static bool ShouldTaskStop(Error err, int errMode);
static CExchangePost* FindExchangePost(CObject* object, float power);
static bool FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception);

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// check.h
#pragma once
#include "common/logger.h"

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// button.h
#pragma once
#include "ui/controls/control.h"
@ -54,4 +52,3 @@ protected:
};
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// check.h
#pragma once
#include "ui/controls/control.h"
@ -46,4 +44,3 @@ public:
};
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// color.h
#pragma once
#include "ui/controls/control.h"
@ -58,4 +56,3 @@ protected:
};
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// control.h
#pragma once
#include "common/event.h"
@ -145,4 +143,3 @@ protected:
};
} // namespace Ui

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// editvalue.h
#pragma once
@ -94,4 +92,3 @@ protected:
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// gauge.h
#pragma once
#include "ui/controls/control.h"
@ -47,4 +45,3 @@ protected:
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// group.h
#pragma once
@ -51,4 +49,3 @@ protected:
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// image.h
#pragma once
@ -53,4 +51,3 @@ protected:
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// interface.h
#pragma once
#include "common/event.h"

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// label.h
#pragma once
@ -44,4 +42,3 @@ public:
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// list.h
#pragma once
@ -129,4 +127,3 @@ protected:
} // namespace Ui

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// map.h
#pragma once
#include "ui/controls/control.h"
@ -145,4 +143,3 @@ protected:
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// scroll.h
#pragma once
@ -84,4 +82,3 @@ protected:
} // namespace Ui

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// shortcut.h
#pragma once
#include "ui/controls/control.h"
@ -49,4 +47,3 @@ protected:
}

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// slider.h
#pragma once
#include "ui/controls/control.h"

View File

@ -17,8 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
// target.h
#pragma once
#include "common/event.h"

Some files were not shown because too many files have changed in this diff Show More