2014-10-14 13:11:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2012-10-17 19:55:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file object/brain.h
|
|
|
|
|
* \brief CBrain - dispatches commands to objects
|
|
|
|
|
*/
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2012-10-17 19:55:45 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
#include "common/event.h"
|
2012-09-13 20:14:40 +00:00
|
|
|
|
#include "common/misc.h"
|
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
#include "object/object.h"
|
|
|
|
|
#include "object/task/taskmanip.h"
|
|
|
|
|
#include "object/task/taskflag.h"
|
|
|
|
|
#include "object/task/taskshield.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CObject;
|
|
|
|
|
class CPhysics;
|
|
|
|
|
class CMotion;
|
|
|
|
|
class CTaskManager;
|
|
|
|
|
class CScript;
|
|
|
|
|
class CRobotMain;
|
2012-09-10 21:29:38 +00:00
|
|
|
|
class CSoundInterface;
|
2014-11-10 13:16:32 +00:00
|
|
|
|
class CLevelParserLine;
|
2012-09-10 21:29:38 +00:00
|
|
|
|
|
2012-09-13 20:14:40 +00:00
|
|
|
|
namespace Ui {
|
|
|
|
|
class CStudio;
|
|
|
|
|
class CInterface;
|
|
|
|
|
class CWindow;
|
|
|
|
|
}
|
2012-09-10 21:29:38 +00:00
|
|
|
|
|
2012-09-13 20:14:40 +00:00
|
|
|
|
namespace Gfx {
|
2012-09-10 21:29:38 +00:00
|
|
|
|
class CEngine;
|
|
|
|
|
class CTerrain;
|
|
|
|
|
class CWater;
|
|
|
|
|
class CCamera;
|
2012-09-13 20:14:40 +00:00
|
|
|
|
class CParticle;
|
2013-05-26 15:47:54 +00:00
|
|
|
|
} /* Gfx */
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int BRAINMAXSCRIPT = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum TraceOper
|
|
|
|
|
{
|
|
|
|
|
TO_STOP = 0, // stop
|
|
|
|
|
TO_ADVANCE = 1, // advance
|
|
|
|
|
TO_RECEDE = 2, // back
|
|
|
|
|
TO_TURN = 3, // rotate
|
|
|
|
|
TO_PEN = 4, // color change
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct TraceRecord
|
|
|
|
|
{
|
|
|
|
|
TraceOper oper;
|
|
|
|
|
float param;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CBrain
|
|
|
|
|
{
|
|
|
|
|
public:
|
2013-02-16 21:37:43 +00:00
|
|
|
|
CBrain(CObject* object);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
~CBrain();
|
|
|
|
|
|
|
|
|
|
void DeleteObject(bool bAll=false);
|
|
|
|
|
|
|
|
|
|
void SetPhysics(CPhysics* physics);
|
|
|
|
|
void SetMotion(CMotion* motion);
|
|
|
|
|
|
|
|
|
|
bool EventProcess(const Event &event);
|
|
|
|
|
bool CreateInterface(bool bSelect);
|
|
|
|
|
|
2014-11-10 13:16:32 +00:00
|
|
|
|
bool Write(CLevelParserLine* line);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
bool Read(char *line);
|
|
|
|
|
|
|
|
|
|
bool IsBusy();
|
|
|
|
|
void SetActivity(bool bMode);
|
2012-09-10 21:29:38 +00:00
|
|
|
|
bool GetActivity();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
bool IsProgram();
|
|
|
|
|
bool ProgramExist(int rank);
|
|
|
|
|
void RunProgram(int rank);
|
|
|
|
|
int FreeProgram();
|
2012-09-10 21:29:38 +00:00
|
|
|
|
int GetProgram();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
void StopProgram();
|
|
|
|
|
void StopTask();
|
2014-10-07 19:40:51 +00:00
|
|
|
|
void StopSecondaryTask();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
bool IntroduceVirus();
|
|
|
|
|
void SetActiveVirus(bool bActive);
|
2012-09-10 21:29:38 +00:00
|
|
|
|
bool GetActiveVirus();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
void SetScriptRun(int rank);
|
2012-09-10 21:29:38 +00:00
|
|
|
|
int GetScriptRun();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
void SetScriptName(int rank, char *name);
|
2012-09-10 21:29:38 +00:00
|
|
|
|
char* GetScriptName(int rank);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
void SetSoluceName(char *name);
|
2012-09-10 21:29:38 +00:00
|
|
|
|
char* GetSoluceName();
|
2013-05-19 14:25:53 +00:00
|
|
|
|
bool SendProgram(int rank, const char* buffer);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
bool ReadSoluce(char* filename);
|
2012-09-10 21:29:38 +00:00
|
|
|
|
bool ReadProgram(int rank, const char* filename);
|
|
|
|
|
bool GetCompile(int rank);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
bool WriteProgram(int rank, char* filename);
|
|
|
|
|
bool ReadStack(FILE *file);
|
|
|
|
|
bool WriteStack(FILE *file);
|
|
|
|
|
|
|
|
|
|
Error StartTaskTake();
|
|
|
|
|
Error StartTaskManip(TaskManipOrder order, TaskManipArm arm);
|
|
|
|
|
Error StartTaskFlag(TaskFlagOrder order, int rank);
|
|
|
|
|
Error StartTaskBuild(ObjectType type);
|
|
|
|
|
Error StartTaskSearch();
|
|
|
|
|
Error StartTaskTerraform();
|
2014-08-10 15:57:41 +00:00
|
|
|
|
Error StartTaskPen(bool down, int color);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
Error StartTaskRecover();
|
|
|
|
|
Error StartTaskShield(TaskShieldMode mode);
|
|
|
|
|
Error StartTaskFire(float delay);
|
|
|
|
|
Error StartTaskFireAnt(Math::Vector impact);
|
2013-03-26 14:33:54 +00:00
|
|
|
|
Error StartTaskSpiderExplo();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
Error StartTaskGunGoal(float dirV, float dirH);
|
|
|
|
|
Error StartTaskReset(Math::Vector goal, Math::Vector angle);
|
|
|
|
|
|
|
|
|
|
void UpdateInterface(float rTime);
|
|
|
|
|
void UpdateInterface();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool EventFrame(const Event &event);
|
|
|
|
|
|
|
|
|
|
void StartEditScript(int rank, char* name);
|
|
|
|
|
void StopEditScript(bool bCancel);
|
|
|
|
|
|
|
|
|
|
Error EndedTask();
|
|
|
|
|
|
|
|
|
|
void GroundFlat();
|
|
|
|
|
void ColorFlag(int color);
|
|
|
|
|
|
2012-09-13 20:14:40 +00:00
|
|
|
|
void UpdateScript(Ui::CWindow *pw);
|
2012-09-10 21:29:38 +00:00
|
|
|
|
int GetSelScript();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
void BlinkScript(bool bEnable);
|
|
|
|
|
|
2012-09-13 20:14:40 +00:00
|
|
|
|
void CheckInterface(Ui::CWindow *pw, EventType event, bool bState);
|
|
|
|
|
void EnableInterface(Ui::CWindow *pw, EventType event, bool bState);
|
|
|
|
|
void DeadInterface(Ui::CWindow *pw, EventType event, bool bState);
|
|
|
|
|
void DefaultEnter(Ui::CWindow *pw, EventType event, bool bState=true);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
void TraceRecordStart();
|
|
|
|
|
void TraceRecordFrame();
|
|
|
|
|
void TraceRecordStop();
|
|
|
|
|
bool TraceRecordOper(TraceOper oper, float param);
|
|
|
|
|
bool TraceRecordPut(char *buffer, int max, TraceOper oper, float param);
|
|
|
|
|
|
|
|
|
|
protected:
|
2012-09-10 21:29:38 +00:00
|
|
|
|
Gfx::CEngine* m_engine;
|
|
|
|
|
Gfx::CTerrain* m_terrain;
|
|
|
|
|
Gfx::CWater* m_water;
|
|
|
|
|
Gfx::CCamera* m_camera;
|
2012-09-13 20:14:40 +00:00
|
|
|
|
Gfx::CParticle* m_particle;
|
2012-09-10 21:29:38 +00:00
|
|
|
|
CObject* m_object;
|
|
|
|
|
CPhysics* m_physics;
|
|
|
|
|
CMotion* m_motion;
|
2012-09-13 20:14:40 +00:00
|
|
|
|
Ui::CInterface* m_interface;
|
2012-09-10 21:29:38 +00:00
|
|
|
|
CRobotMain* m_main;
|
2012-09-15 13:33:08 +00:00
|
|
|
|
Ui::CStudio* m_studio;
|
2012-09-10 21:29:38 +00:00
|
|
|
|
CSoundInterface* m_sound;
|
2012-09-13 20:14:40 +00:00
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
|
CTaskManager* m_primaryTask;
|
|
|
|
|
CTaskManager* m_secondaryTask;
|
|
|
|
|
|
|
|
|
|
CScript* m_script[BRAINMAXSCRIPT];
|
|
|
|
|
int m_selScript; // rank of the selected script
|
|
|
|
|
int m_program; // rank of the executed program / -1
|
|
|
|
|
bool m_bActivity;
|
|
|
|
|
bool m_bBurn;
|
|
|
|
|
bool m_bActiveVirus;
|
|
|
|
|
|
|
|
|
|
int m_scriptRun;
|
|
|
|
|
char m_scriptName[BRAINMAXSCRIPT][50];
|
|
|
|
|
char m_soluceName[50];
|
|
|
|
|
|
|
|
|
|
EventType m_buttonAxe;
|
|
|
|
|
EventType m_manipStyle;
|
|
|
|
|
EventType m_defaultEnter;
|
|
|
|
|
EventType m_interfaceEvent[100];
|
|
|
|
|
|
|
|
|
|
CObject* m_antTarget;
|
|
|
|
|
CObject* m_beeBullet;
|
|
|
|
|
float m_beeBulletSpeed;
|
|
|
|
|
Math::Vector m_startPos;
|
|
|
|
|
float m_time;
|
|
|
|
|
float m_burnTime;
|
|
|
|
|
float m_lastUpdateTime;
|
|
|
|
|
float m_lastHumanTime;
|
|
|
|
|
float m_lastSpiderTime;
|
|
|
|
|
float m_lastWormTime;
|
|
|
|
|
float m_lastBulletTime;
|
|
|
|
|
float m_lastAlarmTime;
|
|
|
|
|
int m_soundChannelAlarm;
|
|
|
|
|
int m_flagColor;
|
|
|
|
|
|
|
|
|
|
bool m_bTraceRecord;
|
|
|
|
|
TraceOper m_traceOper;
|
|
|
|
|
Math::Vector m_tracePos;
|
|
|
|
|
float m_traceAngle;
|
|
|
|
|
int m_traceColor;
|
|
|
|
|
int m_traceRecordIndex;
|
|
|
|
|
TraceRecord* m_traceRecordBuffer;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
};
|
|
|
|
|
|