Colobot
robotmain.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-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.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 #include "app/pausemanager.h"
28 
29 #include "common/error.h"
30 #include "common/event.h"
31 #include "common/singleton.h"
32 
33 #include "graphics/engine/camera.h"
35 
36 #include "level/build_type.h"
37 #include "level/level_category.h"
38 #include "level/mainmovie.h"
39 #include "level/research_type.h"
40 
41 #include "object/drive_type.h"
42 #include "object/mission_type.h"
43 #include "object/object_type.h"
44 #include "object/tool_type.h"
45 
46 #include <deque>
47 #include <stdexcept>
48 
49 enum Phase
50 {
51  PHASE_WELCOME1,
52  PHASE_WELCOME2,
53  PHASE_WELCOME3,
54  PHASE_PLAYER_SELECT,
55  PHASE_APPERANCE,
56  PHASE_MAIN_MENU,
57  PHASE_LEVEL_LIST,
58  PHASE_SIMUL,
59  PHASE_SETUPd,
60  PHASE_SETUPg,
61  PHASE_SETUPp,
62  PHASE_SETUPc,
63  PHASE_SETUPs,
64  PHASE_SETUPds,
65  PHASE_SETUPgs,
66  PHASE_SETUPps,
67  PHASE_SETUPcs,
68  PHASE_SETUPss,
69  PHASE_WRITEs,
70  PHASE_READ,
71  PHASE_READs,
72  PHASE_WIN,
73  PHASE_LOST,
74  PHASE_QUIT_SCREEN,
75  PHASE_SATCOM,
76 };
77 std::string PhaseToString(Phase phase);
78 bool IsInSimulationConfigPhase(Phase phase);
79 bool IsPhaseWithWorld(Phase phase);
80 bool IsMainMenuPhase(Phase phase);
81 
82 
83 class CEventQueue;
84 class CSoundInterface;
85 class CLevelParserLine;
86 class CInput;
87 class CObjectManager;
88 class CSceneEndCondition;
90 class CPlayerProfile;
91 class CSettings;
92 class COldObject;
93 class CPauseManager;
94 struct ActivePause;
95 
96 namespace Gfx
97 {
98 class CEngine;
99 class CLightManager;
100 class CWater;
101 class CCloud;
102 class CLightning;
103 class CPlanet;
104 class CTerrain;
105 class CModelManager;
106 }
107 
108 namespace Ui
109 {
110 class CMainUserInterface;
111 class CMainShort;
112 class CMainMap;
113 class CInterface;
114 class CDisplayText;
115 class CDisplayInfo;
116 }
117 
119 {
120  ObjectType type = OBJECT_NULL;
121  std::string name = "";
122 };
123 
124 
125 const int MAXSHOWLIMIT = 5;
126 const int MAXSHOWPARTI = 200;
127 const float SHOWLIMITTIME = 20.0f;
128 
129 const int MAXSCENE = 999;
130 
131 struct ShowLimit
132 {
133  bool used = false;
134  Math::Vector pos;
135  float radius = 0.0f;
136  int total = 0;
137  int parti[MAXSHOWPARTI] = {};
138  CObject* link = nullptr;
139  float duration = 0.0f;
140  float time = 0.0f;
141 };
142 
143 
144 const int SATCOM_HUSTON = 0;
145 const int SATCOM_SAT = 1;
146 const int SATCOM_OBJECT = 2;
147 const int SATCOM_LOADING = 3;
148 const int SATCOM_PROG = 4;
149 const int SATCOM_SOLUCE = 5;
150 const int SATCOM_MAX = 6;
151 
152 class CRobotMain : public CSingleton<CRobotMain>
153 {
154 public:
155  CRobotMain();
156  virtual ~CRobotMain();
157 
158  Gfx::CCamera* GetCamera();
159  Gfx::CTerrain* GetTerrain();
160  Ui::CInterface* GetInterface();
161  Ui::CDisplayText* GetDisplayText();
162  CPauseManager* GetPauseManager();
163 
164  void ResetAfterVideoConfigChanged();
165  void ReloadAllTextures();
166 
167  void ChangePhase(Phase phase);
168  bool ProcessEvent(Event &event);
169  Phase GetPhase();
170 
171  bool CreateShortcuts();
172  void ScenePerso();
173 
174  void SetMovieLock(bool lock);
175  bool GetMovieLock();
176  bool GetInfoLock();
177  void SetSatComLock(bool lock);
178  bool GetSatComLock();
179  void SetEditLock(bool lock, bool edit);
180  bool GetEditLock();
181  void SetEditFull(bool full);
182  bool GetEditFull();
183  void SetFriendAim(bool friendAim);
184  bool GetFriendAim();
185 
186  void SetSpeed(float speed);
187  float GetSpeed();
188 
189  void UpdateShortcuts();
190  void SelectHuman();
191  CObject* SearchHuman();
192  CObject* SearchToto();
193  CObject* SearchNearest(Math::Vector pos, CObject* exclu);
194  bool SelectObject(CObject* obj, bool displayError=true);
195  CObject* GetSelectObject();
196  CObject* DeselectAll();
197 
198  void ResetObject();
199  void UpdateAudio(bool frame);
200  void SetEndMission(Error result, float delay);
201  Error CheckEndMission(bool frame);
202  Error CheckEndMissionForGroup(std::vector<CSceneEndCondition*>& endTakes);
203  int GetObligatoryToken();
204  char* GetObligatoryToken(int i);
205  int IsObligatoryToken(const char* token);
206  bool IsProhibitedToken(const char* token);
207  void UpdateMap();
208  bool GetShowMap();
209 
210  MainMovieType GetMainMovie();
211 
212  void FlushDisplayInfo();
213  void StartDisplayInfo(int index, bool movie);
214  void StartDisplayInfo(const std::string& filename, int index);
215  void StopDisplayInfo();
216  char* GetDisplayInfoName(int index);
217 
218  void StartSuspend();
219  void StopSuspend();
220 
221  float GetGameTime();
222 
223  const std::string& GetScriptName();
224  const std::string& GetScriptFile();
225  bool GetTrainerPilot();
226  bool GetFixScene();
227  bool GetShowSoluce();
228  bool GetSceneSoluce();
229  bool GetShowAll();
230  bool GetRadar();
231  MissionType GetMissionType();
232 
233  int GetGamerFace();
234  int GetGamerGlasses();
235  bool GetGamerOnlyHead();
236  float GetPersoAngle();
237 
238  void SetLevel(LevelCategory cat, int chap, int rank);
239  LevelCategory GetLevelCategory();
240  int GetLevelChap();
241  int GetLevelRank();
242  std::string GetCustomLevelDir();
243  void SetReadScene(std::string path);
244  void UpdateChapterPassed();
245 
246  void StartMusic();
247  void UpdatePause(PauseType pause);
248  void UpdatePauseMusic(PauseMusic music);
249  void ClearInterface();
250  void ChangeColor();
251 
252  float SearchNearestObject(Math::Vector center, CObject *exclu);
253  bool FreeSpace(Math::Vector &center, float minRadius, float maxRadius, float space, CObject *exclu);
254  bool FlatFreeSpace(Math::Vector &center, float minFlat, float minRadius, float maxRadius, float space, CObject *exclu);
255  float GetFlatZoneRadius(Math::Vector center, float maxRadius, CObject *exclu);
256  void HideDropZone(CObject* metal);
257  void ShowDropZone(CObject* metal, CObject* transporter);
258  void FlushShowLimit(int i);
259  void SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, Math::Vector pos,
260  float radius, float duration=SHOWLIMITTIME);
261  void StartShowLimit();
262  void FrameShowLimit(float rTime);
263 
264  void SaveAllScript();
265  void SaveOneScript(CObject *obj);
266  bool SaveFileStack(CObject *obj, FILE *file, int objRank);
267  bool ReadFileStack(CObject *obj, FILE *file, int objRank);
268 
269  void FlushNewScriptName();
270  void AddNewScriptName(ObjectType type, const std::string& name);
271  std::string GetNewScriptName(ObjectType type, int rank);
272 
273  void SelectPlayer(std::string playerName);
274  CPlayerProfile* GetPlayerProfile();
275 
276  bool IOIsBusy();
277  bool IOWriteScene(std::string filename, std::string filecbot, std::string filescreenshot, const std::string& info, bool emergencySave = false);
278  void IOWriteSceneFinished();
279  CObject* IOReadScene(std::string filename, std::string filecbot);
280  void IOWriteObject(CLevelParserLine *line, CObject* obj, const std::string& programDir, int objRank);
281  CObject* IOReadObject(CLevelParserLine *line, const std::string& programDir, const std::string& objCounterText, float objectProgress, int objRank = -1);
282 
283  int CreateSpot(Math::Vector pos, Gfx::Color color);
284 
285  CObject* GetSelect();
286 
287  void DisplayError(Error err, CObject* pObj, float time=10.0f);
288  void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f);
289 
290  void UpdateCustomLevelList();
291  std::string GetCustomLevelName(int id);
292  const std::vector<std::string>& GetCustomLevelList();
293 
295  bool IsLoading();
296 
297  void StartMissionTimer();
298 
299  void SetAutosave(bool enable);
300  bool GetAutosave();
301  void SetAutosaveInterval(int interval);
302  int GetAutosaveInterval();
303  void SetAutosaveSlots(int slots);
304  int GetAutosaveSlots();
305 
307  void SetExitAfterMission(bool exit);
308 
310  bool CanPlayerInteract();
311 
313  const std::string& GetTeamName(int id);
314 
316  bool IsTeamColorDefined(int id);
317 
319 
320  int GetEnableBuild();
321  void SetEnableBuild(int enableBuild);
323 
325  int GetEnableResearch();
326  void SetEnableResearch(int enableResearch);
328 
330  int GetDoneResearch(int team);
331  void SetDoneResearch(int doneResearch, int team);
333 
335 
336  bool IsBuildingEnabled(BuildType type);
337  bool IsBuildingEnabled(ObjectType type);
339  bool IsResearchEnabled(ResearchType type);
342  bool IsResearchDone(ResearchType type, int team);
344  void MarkResearchDone(ResearchType type, int team);
345 
347 
348  bool CanBuild(ObjectType type, int team);
349  Error CanBuildError(ObjectType type, int team);
351 
353 
354  bool CanFactory(ObjectType type, int team);
355  Error CanFactoryError(ObjectType type, int team);
357 
358  void RemoveFromSelectionHistory(CObject* object);
359 
361  float GetGlobalMagnifyDamage();
362 
363  void StartDetectEffect(COldObject* object, CObject* target);
364 
365  bool IsSelectable(CObject* obj);
366 
367 protected:
368  bool EventFrame(const Event &event);
369  bool EventObject(const Event &event);
370  void InitEye();
371 
372  void ShowSaveIndicator(bool show);
373 
374  void CreateScene(bool soluce, bool fixScene, bool resetObject);
375  void ResetCreate();
376 
377  void LevelLoadingError(const std::string& error, const std::runtime_error& exception, Phase exitPhase = PHASE_LEVEL_LIST);
378 
379  int CreateLight(Math::Vector direction, Gfx::Color color);
380  void HiliteClear();
381  void HiliteObject(Math::Point pos);
382  void HiliteFrame(float rTime);
383  void CreateTooltip(Math::Point pos, const std::string& text);
384  void ClearTooltip();
385  CObject* DetectObject(Math::Point pos);
386  void ChangeCamera();
387  void RemoteCamera(float pan, float zoom, float rTime);
388  void KeyCamera(EventType event, InputSlot key);
389  void AbortMovie();
390  void SelectOneObject(CObject* obj, bool displayError=true);
391  void HelpObject();
392  bool DeselectObject();
393  void DeleteAllObjects();
394  void UpdateInfoText();
395  void StartDisplayVisit(EventType event);
396  void FrameVisit(float rTime);
397  void StopDisplayVisit();
398  void ExecuteCmd(char *cmd);
399  void UpdateSpeedLabel();
400 
401  int AutosaveRotate(bool freeOne);
402  void Autosave();
403  bool DestroySelectedObject();
404  void PushToSelectionHistory(CObject* obj);
405  CObject* PopFromSelectionHistory();
406 
407  void CreateCodeBattleInterface();
408  void DestroyCodeBattleInterface();
409  void SetCodeBattleSpectatorMode(bool mode);
410  void UpdateDebugCrashSpheres();
411 
412 
413 protected:
414  CApplication* m_app = nullptr;
415  CEventQueue* m_eventQueue = nullptr;
416  Gfx::CEngine* m_engine = nullptr;
417  Gfx::CParticle* m_particle = nullptr;
418  Gfx::CWater* m_water = nullptr;
419  Gfx::CCloud* m_cloud = nullptr;
420  Gfx::CLightning* m_lightning = nullptr;
421  Gfx::CPlanet* m_planet = nullptr;
422  Gfx::COldModelManager* m_oldModelManager = nullptr;
423  Gfx::CLightManager* m_lightMan = nullptr;
424  CSoundInterface* m_sound = nullptr;
425  CInput* m_input = nullptr;
426  std::unique_ptr<CObjectManager> m_objMan;
427  std::unique_ptr<CMainMovie> m_movie;
428  std::unique_ptr<CPauseManager> m_pause;
429  std::unique_ptr<Gfx::CModelManager> m_modelManager;
430  std::unique_ptr<Gfx::CTerrain> m_terrain;
431  std::unique_ptr<Gfx::CCamera> m_camera;
432  std::unique_ptr<Ui::CMainUserInterface> m_ui;
433  std::unique_ptr<Ui::CMainShort> m_short;
434  std::unique_ptr<Ui::CMainMap> m_map;
435  std::unique_ptr<Ui::CInterface> m_interface;
436  std::unique_ptr<Ui::CDisplayInfo> m_displayInfo;
437  std::unique_ptr<Ui::CDisplayText> m_displayText;
438  std::unique_ptr<CSettings> m_settings;
439 
441  std::unique_ptr<CPlayerProfile> m_playerProfile;
442 
443 
445  float m_time = 0.0f;
447  float m_gameTime = 0.0f;
449  float m_gameTimeAbsolute = 0.0f;
450 
451  LevelCategory m_levelCategory;
452  int m_levelChap = 0;
453  int m_levelRank = 0;
454  std::string m_sceneReadPath;
455 
456  float m_winDelay = 0.0f;
457  float m_lostDelay = 0.0f;
458  bool m_fixScene = false; // scene fixed, no interraction
459  CObject* m_base = nullptr; // OBJECT_BASE exists in mission
460  CObject* m_selectObject = nullptr;
461 
462  Phase m_phase = PHASE_WELCOME1;
463  ActivePause* m_userPause = nullptr;
464  ActivePause* m_focusPause = nullptr;
465  ActivePause* m_freePhotoPause = nullptr;
466  bool m_cmdEdit = false;
467  ActivePause* m_cmdEditPause = nullptr;
468  bool m_selectInsect = false;
469  bool m_showSoluce = false;
470  bool m_showAll = false;
471  bool m_cheatRadar = false;
472  bool m_shortCut = false;
473  std::string m_audioTrack;
474  bool m_audioRepeat = false;
475  std::string m_satcomTrack;
476  bool m_satcomRepeat = false;
477  std::string m_editorTrack;
478  bool m_editorRepeat = false;
479  int m_movieInfoIndex = 0;
480 
481  CObject* m_controller = nullptr;
482 
483  MissionType m_missionType = MISSION_NORMAL;
484  bool m_immediatSatCom = false; // SatCom immediately?
485  bool m_beginSatCom = false; // messages SatCom poster?
486  bool m_lockedSatCom = false; // SatCom locked?
487  bool m_movieLock = false; // movie in progress?
488  bool m_satComLock = false; // call of SatCom is possible?
489  bool m_editLock = false; // edition in progress?
490  bool m_editFull = false; // edition in full screen?
491  bool m_hilite = false;
492  bool m_trainerPilot = false; // remote trainer?
493  bool m_friendAim = false;
494  bool m_resetCreate = false;
495  bool m_mapShow = false;
496  bool m_mapImage = false;
497  char m_mapFilename[100] = {};
498 
499  ActivePause* m_suspend = nullptr;
500  Gfx::CameraType m_suspendInitCamera = Gfx::CAM_TYPE_NULL;
501 
502  Math::Point m_tooltipPos;
503  std::string m_tooltipName;
504  float m_tooltipTime = 0.0f;
505 
506  char m_infoFilename[SATCOM_MAX][100] = {}; // names of text files
507  CObject* m_infoObject = nullptr;
508  int m_infoUsed = 0;
509  ActivePause* m_satcomMoviePause = nullptr;
510 
511  std::string m_scriptName = "";
512  std::string m_scriptFile = "";
513  int m_endingWinRank = 0;
514  int m_endingLostRank = 0;
515  bool m_winTerminate = false;
516 
517  float m_globalMagnifyDamage = 0.0f;
518 
519  bool m_exitAfterMission = false;
520 
521  bool m_codeBattleInit = false;
522  bool m_codeBattleStarted = false;
524  bool m_codeBattleSpectator = true;
525 
526  std::map<int, std::string> m_teamNames;
527 
528  std::vector<NewScriptName> m_newScriptName;
529 
530  float m_cameraPan = 0.0f;
531  float m_cameraZoom = 0.0f;
532 
533  EventType m_visitLast = EVENT_NULL;
534  CObject* m_visitObject = nullptr;
535  CObject* m_visitArrow = nullptr;
536  float m_visitTime = 0.0f;
537  float m_visitParticle = 0.0f;
538  Math::Vector m_visitPos;
539  Math::Vector m_visitPosArrow;
540  ActivePause* m_visitPause = nullptr;
541 
542  std::vector<std::unique_ptr<CSceneEndCondition>> m_endTake;
543  long m_endTakeResearch = 0;
544  float m_endTakeWinDelay = 0.0f;
545  float m_endTakeLostDelay = 0.0f;
546 
547  std::vector<std::unique_ptr<CAudioChangeCondition>> m_audioChange;
548 
549  int m_obligatoryTotal = 0;
550  char m_obligatoryToken[100][20] = {};
551  int m_prohibitedTotal = 0;
552  char m_prohibitedToken[100][20] = {};
553 
555  int m_build = 0;
557  long m_researchEnable = 0;
559  std::map<int, int> m_researchDone;
560 
561  Error m_missionResult = ERR_OK;
562 
563  ShowLimit m_showLimit[MAXSHOWLIMIT];
564 
565  Gfx::Color m_colorRefBot;
566  std::map<int, Gfx::Color> m_colorNewBot;
567  Gfx::Color m_colorRefAlien;
568  Gfx::Color m_colorNewAlien;
569  Gfx::Color m_colorRefGreen;
570  Gfx::Color m_colorNewGreen;
571  Gfx::Color m_colorRefWater;
572  Gfx::Color m_colorNewWater;
573  float m_colorShiftWater = 0.0f;
574 
575  bool m_missionTimerEnabled = false;
576  bool m_missionTimerStarted = false;
577  float m_missionTimer = 0.0f;
578 
579  bool m_autosave = false;
580  int m_autosaveInterval = 0;
581  int m_autosaveSlots = 0;
582  float m_autosaveLast = 0.0f;
583 
584  int m_shotSaving = 0;
585 
586  std::deque<CObject*> m_selectionHistory;
587  bool m_debugCrashSpheres;
588 };
CameraType
Type of camera.
Definition: camera.h:44
Definition: pausemanager.cpp:30
CSingleton base class for singletons.
ParticleType
Definition: particle.h:63
Definition: displaytext.h:51
Definition: robotmain.h:131
InputSlot
Available slots for input bindings NOTE: When adding new values, remember to also update keyTable in ...
Definition: key.h:79
Definition: robotmain.h:108
Camera handling - CCamera class.
Audio change condition.
Definition: scene_conditions.h:96
Definition: singleton.h:30
Manager for static models.
Definition: oldmodelmanager.h:54
Definition: old_object.h:79
Global event queue.
Definition: event.h:830
Manager for dynamic lights in 3D scene.
Definition: lightman.h:146
PauseType
Definition: pausemanager.h:35
ObjectType enum.
Definition: parserline.h:37
Definition: robotmain.h:152
Cloud layer renderer.
Definition: cloud.h:54
Lightning effect renderer.
Definition: lightning.h:55
Particle engine.
Definition: particle.h:223
Definition: settings.h:32
Planet manager.
Definition: planet.h:49
CMainMovie - control over movie sequences.
Scene end condition.
Definition: scene_conditions.h:73
2D point
Definition: point.h:50
Main application.
Definition: app.h:180
Camera moving in 3D scene.
Definition: camera.h:130
Management of pause modes.
Terrain loader/generator and manager.
Definition: terrain.h:145
Namespace for (new) graphics code.
Definition: app.h:49
Definition: player_profile.h:57
The graphics engine.
Definition: engine.h:619
std::unique_ptr< CPlayerProfile > m_playerProfile
Progress of loaded player.
Definition: robotmain.h:441
Event types, structs and event queue.
ObjectType
Type of game object.
Definition: object_type.h:33
Water manager/renderer.
Definition: water.h:72
Invalid event / no event.
Definition: event.h:47
Particle rendering - CParticle class (aka particle)
3D (3x1) vector
Definition: vector.h:53
Undefined.
Definition: camera.h:47
RGBA color.
Definition: color.h:39
Manages CObject instances.
Definition: object_manager.h:148
EventType
Type of event message.
Definition: event.h:41
Event sent by system, interface or game.
Definition: event.h:699
Definition: pausemanager.h:70
Definition: interface.h:59
Base class for all 3D in-game objects.
Definition: object.h:63
Sound plugin interface.
Definition: sound.h:60
Definition: robotmain.h:118
std::map< int, int > m_researchDone
Done researches for each team.
Definition: robotmain.h:559
Management of mouse, keyboard and joystick.
Definition: input.h:71