Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
brain.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "common/event.h"
29 #include "common/misc.h"
30 
31 #include "object/object.h"
32 #include "object/task/taskmanip.h"
33 #include "object/task/taskflag.h"
34 #include "object/task/taskshield.h"
35 
36 
37 class CObject;
38 class CPhysics;
39 class CMotion;
40 class CTaskManager;
41 class CScript;
42 class CRobotMain;
43 class CSoundInterface;
44 class CLevelParserLine;
45 
46 namespace Ui {
47 class CStudio;
48 class CInterface;
49 class CWindow;
50 }
51 
52 namespace Gfx {
53 class CEngine;
54 class CTerrain;
55 class CWater;
56 class CCamera;
57 class CParticle;
58 } /* Gfx */
59 
60 
61 
62 enum TraceOper
63 {
64  TO_STOP = 0, // stop
65  TO_ADVANCE = 1, // advance
66  TO_RECEDE = 2, // back
67  TO_TURN = 3, // rotate
68  TO_PEN = 4, // color change
69 };
70 
72 {
73  TraceOper oper;
74  float param;
75 };
76 
77 struct Program
78 {
79  CScript* script;
80  std::string filename;
81  bool readOnly;
82  bool runnable;
83 };
84 
85 
86 
87 class CBrain
88 {
89 public:
90  CBrain(CObject* object);
91  ~CBrain();
92 
93  void DeleteObject(bool bAll=false);
94 
95  void SetPhysics(CPhysics* physics);
96  void SetMotion(CMotion* motion);
97 
98  bool EventProcess(const Event &event);
99  bool CreateInterface(bool bSelect);
100 
101  bool Write(CLevelParserLine* line);
102  bool Read(CLevelParserLine* line);
103 
104  bool IsBusy();
105  void SetActivity(bool bMode);
106  bool GetActivity();
107  bool IsProgram();
108  void RunProgram(Program* program);
109  int GetProgram();
110  void StopProgram();
111  void StopTask();
112  void StopSecondaryTask();
113 
114  bool IntroduceVirus();
115  void SetActiveVirus(bool bActive);
116  bool GetActiveVirus();
117 
118  void SetScriptRun(Program* rank);
119  Program* GetScriptRun();
120  void SetSoluceName(char *name);
121  char* GetSoluceName();
122 
123  bool ReadSoluce(char* filename);
124  bool ReadProgram(Program* program, const char* filename);
125  bool GetCompile(Program* program);
126  bool WriteProgram(Program* program, char* filename);
127  bool ReadStack(FILE *file);
128  bool WriteStack(FILE *file);
129  const std::vector<Program*>& GetPrograms();
130 
131  Error StartTaskTake();
132  Error StartTaskManip(TaskManipOrder order, TaskManipArm arm);
133  Error StartTaskFlag(TaskFlagOrder order, int rank);
134  Error StartTaskBuild(ObjectType type);
135  Error StartTaskSearch();
136  Error StartTaskDeleteMark();
137  Error StartTaskTerraform();
138  Error StartTaskPen(bool down, int color);
139  Error StartTaskRecover();
140  Error StartTaskShield(TaskShieldMode mode);
141  Error StartTaskFire(float delay);
142  Error StartTaskFireAnt(Math::Vector impact);
143  Error StartTaskSpiderExplo();
144  Error StartTaskGunGoal(float dirV, float dirH);
145  Error StartTaskReset(Math::Vector goal, Math::Vector angle);
146 
147  void UpdateInterface(float rTime);
148  void UpdateInterface();
149 
150  Program* AddProgram();
151  bool AddProgram(Program* program);
152  void RemoveProgram(Program* program);
153  Program* CloneProgram(Program* program);
154 
155  Program* GetProgram(int index);
156  Program* GetOrAddProgram(int index);
157  int GetProgramIndex(Program* program);
158 
159 protected:
160  bool EventFrame(const Event &event);
161 
162  void StartEditScript(Program* program, char* name);
163  void StopEditScript(bool bCancel);
164 
165  Error EndedTask();
166 
167  void GroundFlat();
168  void ColorFlag(int color);
169 
170  void UpdateScript(Ui::CWindow *pw);
171  int GetSelScript();
172  void SetSelScript(int index);
173  void BlinkScript(bool bEnable);
174 
175  void CheckInterface(Ui::CWindow *pw, EventType event, bool bState);
176  void EnableInterface(Ui::CWindow *pw, EventType event, bool bState);
177  void DeadInterface(Ui::CWindow *pw, EventType event, bool bState);
178  void DefaultEnter(Ui::CWindow *pw, EventType event, bool bState=true);
179 
180  void TraceRecordStart();
181  void TraceRecordFrame();
182  void TraceRecordStop();
183  bool TraceRecordOper(TraceOper oper, float param);
184  bool TraceRecordPut(char *buffer, int max, TraceOper oper, float param);
185 
186 protected:
187  Gfx::CEngine* m_engine;
188  Gfx::CTerrain* m_terrain;
189  Gfx::CWater* m_water;
190  Gfx::CCamera* m_camera;
191  Gfx::CParticle* m_particle;
192  CObject* m_object;
193  CPhysics* m_physics;
194  CMotion* m_motion;
195  Ui::CInterface* m_interface;
196  CRobotMain* m_main;
197  Ui::CStudio* m_studio;
198  CSoundInterface* m_sound;
199 
200  CTaskManager* m_primaryTask;
201  CTaskManager* m_secondaryTask;
202 
203  std::vector<Program*> m_program;
204  Program* m_currentProgram;
205 
206  unsigned int m_selScript; // rank of the selected script
207 
208  bool m_bActivity;
209  bool m_bBurn;
210  bool m_bActiveVirus;
211 
212  Program* m_scriptRun;
213  char m_soluceName[50];
214 
215  EventType m_buttonAxe;
216  EventType m_manipStyle;
217  EventType m_defaultEnter;
218  EventType m_interfaceEvent[100];
219 
220  CObject* m_antTarget;
221  CObject* m_beeBullet;
222  float m_beeBulletSpeed;
223  Math::Vector m_startPos;
224  float m_time;
225  float m_burnTime;
226  float m_lastUpdateTime;
227  float m_lastHumanTime;
228  float m_lastSpiderTime;
229  float m_lastWormTime;
230  float m_lastBulletTime;
231  float m_lastAlarmTime;
232  int m_soundChannelAlarm;
233  int m_flagColor;
234 
235  bool m_bTraceRecord;
236  TraceOper m_traceOper;
237  Math::Vector m_tracePos;
238  float m_traceAngle;
239  int m_traceColor;
240  int m_traceRecordIndex;
241  TraceRecord* m_traceRecordBuffer;
242 };
243 
Definition: controller.h:32
Definition: physics.h:98
Definition: brain.h:71
Definition: parserline.h:33
Definition: robotmain.h:172
Particle engine.
Definition: particle.h:268
Definition: taskmanager.h:34
ObjectType
Type of game object.
Definition: object.h:51
Camera moving in 3D scene.
Definition: camera.h:133
Terrain loader/generator and manager.
Definition: terrain.h:222
Namespace for (new) graphics code.
Definition: app.h:49
Definition: motion.h:48
CObject - base class for all game objects.
The graphics engine.
Definition: engine.h:684
Event types, structs and event queue.
Definition: script.h:58
Error
Type of error or info message.
Definition: global.h:32
Water manager/renderer.
Definition: water.h:118
3D (3x1) vector
Definition: vector.h:52
EventType
Type of event message.
Definition: event.h:38
Event sent by system, interface or game.
Definition: event.h:678
Definition: window.h:56
Definition: interface.h:58
Definition: object.h:357
Sound plugin interface.
Definition: sound.h:151
Definition: studio.h:63
Definition: brain.h:77
Definition: brain.h:87