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