Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
robotmain.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/global.h"
26 #include "common/singleton.h"
27 
29 
30 #include "object/object.h"
31 #include "object/mainmovie.h"
32 
33 #include "app/pausemanager.h"
34 
35 #include <stdio.h>
36 
37 enum Phase
38 {
39  PHASE_INIT,
40  PHASE_TERM,
41  PHASE_NAME,
42  PHASE_PERSO,
43  PHASE_TRAINER,
44  PHASE_DEFI,
45  PHASE_MISSION,
46  PHASE_FREE,
47  PHASE_TEEN,
48  PHASE_USER,
49  PHASE_LOADING,
50  PHASE_SIMUL,
51  PHASE_MODEL,
52  PHASE_SETUPd,
53  PHASE_SETUPg,
54  PHASE_SETUPp,
55  PHASE_SETUPc,
56  PHASE_SETUPs,
57  PHASE_SETUPds,
58  PHASE_SETUPgs,
59  PHASE_SETUPps,
60  PHASE_SETUPcs,
61  PHASE_SETUPss,
62  PHASE_WRITE,
63  PHASE_READ,
64  PHASE_WRITEs,
65  PHASE_READs,
66  PHASE_WIN,
67  PHASE_LOST,
68  PHASE_WELCOME1,
69  PHASE_WELCOME2,
70  PHASE_WELCOME3,
71  PHASE_GENERIC,
72 };
73 
74 
75 class CEventQueue;
76 class CSoundInterface;
77 
78 namespace Gfx {
79 class CEngine;
80 class CLightManager;
81 class CWater;
82 class CCloud;
83 class CLightning;
84 class CPlanet;
85 class CTerrain;
86 }
87 
88 namespace Ui {
89 class CMainDialog;
90 class CMainShort;
91 class CMainMap;
92 class CInterface;
93 class CDisplayText;
94 class CDisplayInfo;
95 }
96 
97 
98 struct EndTake
99 {
100  Math::Vector pos;
101  float dist;
102  ObjectType type;
103  int min; // wins if >
104  int max; // wins if <
105  int lost; // lost if <=
106  float powermin; // wins if energy cell >=
107  float powermax; // wins if energy cell <=
108  ToolType tool;
109  DriveType drive;
110  bool immediat;
111  char message[100];
112 };
113 
115 {
116  Math::Vector pos;
117  float dist;
118  ObjectType type;
119  int min; // change if >
120  int max; // change if <
121  float powermin; // change if energy cell >=
122  float powermax; // change if energy cell <=
123  ToolType tool;
124  DriveType drive;
125  char music[100];
126  bool repeat;
127  bool changed;
128 };
129 
130 
131 const int MAXNEWSCRIPTNAME = 20;
132 
134 {
135  bool used;
136  ObjectType type;
137  char name[40];
138 };
139 
140 
141 const int MAXSHOWLIMIT = 5;
142 const int MAXSHOWPARTI = 200;
143 const float SHOWLIMITTIME = 20.0f;
144 
145 struct ShowLimit
146 {
147  bool used;
148  Math::Vector pos;
149  float radius;
150  int total;
151  int parti[MAXSHOWPARTI];
152  CObject* link;
153  float duration;
154  float time;
155 };
156 
157 
158 const int SATCOM_HUSTON = 0;
159 const int SATCOM_SAT = 1;
160 const int SATCOM_OBJECT = 2;
161 const int SATCOM_LOADING = 3;
162 const int SATCOM_PROG = 4;
163 const int SATCOM_SOLUCE = 5;
164 const int SATCOM_MAX = 6;
165 
166 
172 {
175  unsigned int primary, secondary;
176 
177  InputBinding(unsigned int p = KEY_INVALID, unsigned int s = KEY_INVALID)
178  : primary(p), secondary(s) {}
179 };
180 
186 {
188  int axis;
190  bool invert;
191 };
192 
194 const int AXIS_INVALID = -1;
195 
196 class CRobotMain : public CSingleton<CRobotMain>
197 {
198 public:
199  CRobotMain(CApplication* app, bool loadProfile);
200  virtual ~CRobotMain();
201 
202  Gfx::CCamera* GetCamera();
203  Gfx::CTerrain* GetTerrain();
204  Ui::CInterface* GetInterface();
205  Ui::CDisplayText* GetDisplayText();
206 
208  void LoadSceneOnStart(const std::string& name, int rank);
209 
210  void CreateIni();
211 
214 
216 
217  void SetInputBinding(InputSlot slot, InputBinding binding);
218  const InputBinding& GetInputBinding(InputSlot slot);
220 
222 
223  void SetJoyAxisBinding(JoyAxisSlot slot, JoyAxisBinding binding);
224  const JoyAxisBinding& GetJoyAxisBinding(JoyAxisSlot slot);
226 
228 
229  void SetJoystickDeadzone(float zone);
230  float GetJoystickDeadzone();
232 
234  void ResetKeyStates();
235 
236  void ChangePhase(Phase phase);
237  bool ProcessEvent(Event &event);
238 
239  bool CreateShortcuts();
240  void ScenePerso();
241 
242  void SetMovieLock(bool lock);
243  bool GetMovieLock();
244  bool GetInfoLock();
245  void SetSatComLock(bool lock);
246  bool GetSatComLock();
247  void SetEditLock(bool lock, bool edit);
248  bool GetEditLock();
249  void SetEditFull(bool full);
250  bool GetEditFull();
251  bool GetFreePhoto();
252  void SetFriendAim(bool friendAim);
253  bool GetFriendAim();
254 
255  void SetTracePrecision(float factor);
256  float GetTracePrecision();
257 
258  void ChangePause(PauseType pause);
259 
260  void SetSpeed(float speed);
261  float GetSpeed();
262 
263  void UpdateShortcuts();
264  void SelectHuman();
265  CObject* SearchHuman();
266  CObject* SearchToto();
267  CObject* SearchNearest(Math::Vector pos, CObject* pExclu);
268  bool SelectObject(CObject* pObj, bool displayError=true);
270  CObject* DeselectAll();
271  bool DeleteObject();
272 
273  void ResetObject();
274  void ResetCreate();
275  void UpdateAudio(bool frame);
276  void SetEndMission(Error result, float delay);
277  Error CheckEndMission(bool frame);
278  void CheckEndMessage(const char* message);
279  int GetObligatoryToken();
280  char* GetObligatoryToken(int i);
281  int IsObligatoryToken(const char* token);
282  bool IsProhibitedToken(const char* token);
283  void UpdateMap();
284  bool GetShowMap();
285 
286  MainMovieType GetMainMovie();
287 
288  void FlushDisplayInfo();
289  void StartDisplayInfo(int index, bool movie);
290  void StartDisplayInfo(const char *filename, int index);
291  void StopDisplayInfo();
292  char* GetDisplayInfoName(int index);
293  int GetDisplayInfoPosition(int index);
294  void SetDisplayInfoPosition(int index, int pos);
295 
296  void StartSuspend();
297  void StopSuspend();
298 
299  float GetGameTime();
300 
301  void SetFontSize(float size);
302  float GetFontSize();
303  void SetWindowPos(Math::Point pos);
304  Math::Point GetWindowPos();
305  void SetWindowDim(Math::Point dim);
306  Math::Point GetWindowDim();
307 
308  void SetIOPublic(bool mode);
309  bool GetIOPublic();
310  void SetIOPos(Math::Point pos);
311  Math::Point GetIOPos();
312  void SetIODim(Math::Point dim);
313  Math::Point GetIODim();
314 
315  char* GetTitle();
316  char* GetResume();
317  char* GetScriptName();
318  char* GetScriptFile();
319  bool GetTrainerPilot();
320  bool GetFixScene();
321  bool GetGlint();
322  bool GetSoluce4();
323  bool GetMovies();
324  bool GetNiceReset();
325  bool GetHimselfDamage();
326  bool GetShowSoluce();
327  bool GetSceneSoluce();
328  bool GetShowAll();
329  bool GetRadar();
330  const char* GetSavegameDir();
331  const char* GetPublicDir();
332  const char* GetFilesDir();
333  bool GetRetroMode();
334 
335  void SetGamerName(const char *name);
336  char* GetGamerName();
337  int GetGamerFace();
338  int GetGamerGlasses();
339  bool GetGamerOnlyHead();
340  float GetPersoAngle();
341 
342  void StartMusic();
343  void StartPauseMusic(PauseType pause);
344  void ClearInterface();
345  void ChangeColor();
346 
347  float SearchNearestObject(Math::Vector center, CObject *exclu);
348  bool FreeSpace(Math::Vector &center, float minRadius, float maxRadius, float space, CObject *exclu);
349  float GetFlatZoneRadius(Math::Vector center, float maxRadius, CObject *exclu);
350  void HideDropZone(CObject* metal);
351  void ShowDropZone(CObject* metal, CObject* truck);
352  void FlushShowLimit(int i);
353  void SetShowLimit(int i, Gfx::ParticleType parti, CObject *pObj, Math::Vector pos,
354  float radius, float duration=SHOWLIMITTIME);
355  void AdjustShowLimit(int i, Math::Vector pos);
356  void StartShowLimit();
357  void FrameShowLimit(float rTime);
358 
359  void CompileScript(bool soluce);
360  void LoadOneScript(CObject *pObj, int &nerror);
361  void LoadFileScript(CObject *pObj, const char* filename, int objRank, int &nerror);
362  void SaveAllScript();
363  void SaveOneScript(CObject *pObj);
364  void SaveFileScript(CObject *pObj, const char* filename, int objRank);
365  bool SaveFileStack(CObject *pObj, FILE *file, int objRank);
366  bool ReadFileStack(CObject *pObj, FILE *file, int objRank);
367 
368  bool FlushNewScriptName();
369  bool AddNewScriptName(ObjectType type, char *name);
370  char* GetNewScriptName(ObjectType type, int rank);
371 
372  void WriteFreeParam();
373  void ReadFreeParam();
374 
375  bool IsBusy();
376  bool IOWriteScene(const char *filename, const char *filecbot, char *info);
377  CObject* IOReadScene(const char *filename, const char *filecbot);
378  void IOWriteObject(FILE *file, CObject* pObj, const char *cmd);
379  CObject* IOReadObject(char *line, const char* filename, int objRank);
380 
381  int CreateSpot(Math::Vector pos, Gfx::Color color);
382 
383  void SetNumericLocale();
384  void RestoreNumericLocale();
385 
386  CObject* GetSelect();
387 
388  void DisplayError(Error err, CObject* pObj, float time=10.0f);
389  void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f);
390 
391 protected:
392  bool EventFrame(const Event &event);
393  bool EventObject(const Event &event);
394  void InitEye();
395 
396  void Convert();
397  void CreateScene(bool soluce, bool fixScene, bool resetObject);
398 
399  Math::Vector LookatPoint(Math::Vector eye, float angleH, float angleV, float length);
400  int CreateLight(Math::Vector direction, Gfx::Color color);
401  void HiliteClear();
402  void HiliteObject(Math::Point pos);
403  void HiliteFrame(float rTime);
404  void CreateTooltip(Math::Point pos, const std::string& text);
405  void ClearTooltip();
407  void ChangeCamera();
408  void RemoteCamera(float pan, float zoom, float rTime);
409  void KeyCamera(EventType event, unsigned int key);
410  void AbortMovie();
411  bool IsSelectable(CObject* pObj);
412  void SelectOneObject(CObject* pObj, bool displayError=true);
413  void HelpObject();
414  bool DeselectObject();
415  void DeleteAllObjects();
416  void UpdateInfoText();
417  CObject* SearchObject(ObjectType type);
418  void StartDisplayVisit(EventType event);
419  void FrameVisit(float rTime);
420  void StopDisplayVisit();
421  void ExecuteCmd(char *cmd);
422  bool TestGadgetQuantity(int rank);
423  void UpdateSpeedLabel();
424 
425 
426 protected:
427  CApplication* m_app;
428  CEventQueue* m_eventQueue;
429  CMainMovie* m_movie;
430  Gfx::CEngine* m_engine;
431  Gfx::CParticle* m_particle;
432  Gfx::CWater* m_water;
433  Gfx::CCloud* m_cloud;
434  Gfx::CLightning* m_lightning;
435  Gfx::CPlanet* m_planet;
436  Gfx::CLightManager* m_lightMan;
437  Gfx::CTerrain* m_terrain;
438  Gfx::CCamera* m_camera;
439  Ui::CMainDialog* m_dialog;
440  Ui::CMainShort* m_short;
441  Ui::CMainMap* m_map;
442  Ui::CInterface* m_interface;
443  Ui::CDisplayText* m_displayText;
444  Ui::CDisplayInfo* m_displayInfo;
445  CSoundInterface* m_sound;
446  CPauseManager* m_pause;
447 
449  InputBinding m_inputBindings[INPUT_SLOT_MAX];
450  JoyAxisBinding m_joyAxisBindings[JOY_AXIS_SLOT_MAX];
451  float m_joystickDeadzone;
456 
457 
458  float m_time;
459  float m_gameTime;
460  float m_checkEndTime;
461  float m_winDelay;
462  float m_lostDelay;
463  bool m_fixScene; // scene fixed, no interraction
464  bool m_base; // OBJECT_BASE exists in mission
465  Math::Point m_lastMousePos;
466  CObject* m_selectObject;
467 
468  Phase m_phase;
469  int m_cameraRank;
470  Gfx::Color m_color;
471  bool m_freePhoto;
472  bool m_cmdEdit;
473  bool m_showPos;
474  bool m_selectInsect;
475  bool m_showSoluce;
476  bool m_showAll;
477  bool m_cheatRadar;
478  bool m_shortCut;
479  std::string m_audioTrack;
480  bool m_audioRepeat;
481  std::string m_satcomTrack;
482  bool m_satcomRepeat;
483  std::string m_editorTrack;
484  bool m_editorRepeat;
485  int m_delayWriteMessage;
486  int m_movieInfoIndex;
487 
488  CObject* m_controller;
489 
490  // Level Checker flags
491  bool m_beginObject;
492  bool m_terrainGenerate;
493  bool m_terrainInitTextures;
494  bool m_terrainInit;
495  bool m_terrainCreate;
496 
497  int m_version; // Mission file version
498  bool m_retroStyle; // Retro
499  bool m_immediatSatCom; // SatCom immediately?
500  bool m_beginSatCom; // messages SatCom poster?
501  bool m_lockedSatCom; // SatCom locked?
502  bool m_movieLock; // movie in progress?
503  bool m_satComLock; // call of SatCom is possible?
504  bool m_editLock; // edition in progress?
505  bool m_editFull; // edition in full screen?
506  bool m_hilite;
507  bool m_trainerPilot; // remote trainer?
508  bool m_suspend;
509  bool m_friendAim;
510  bool m_resetCreate;
511  bool m_mapShow;
512  bool m_mapImage;
513  char m_mapFilename[100];
514 
515  Math::Point m_tooltipPos;
516  std::string m_tooltipName;
517  float m_tooltipTime;
518 
519  char m_infoFilename[SATCOM_MAX][100]; // names of text files
520  CObject* m_infoObject;
521  int m_infoIndex;
522  int m_infoPos[SATCOM_MAX];
523  int m_infoUsed;
524 
525  char m_title[100];
526  char m_resume[500];
527  char m_scriptName[100];
528  char m_scriptFile[100];
529  int m_endingWinRank;
530  int m_endingLostRank;
531  bool m_winTerminate;
532 
533  bool m_exitAfterMission;
534 
535  float m_fontSize;
536  Math::Point m_windowPos;
537  Math::Point m_windowDim;
538 
539  bool m_IOPublic;
540  Math::Point m_IOPos;
541  Math::Point m_IODim;
542 
543  NewScriptName m_newScriptName[MAXNEWSCRIPTNAME];
544 
545  float m_cameraPan;
546  float m_cameraZoom;
547 
548  EventType m_visitLast;
549  CObject* m_visitObject;
550  CObject* m_visitArrow;
551  float m_visitTime;
552  float m_visitParticle;
553  Math::Vector m_visitPos;
554  Math::Vector m_visitPosArrow;
555 
556  int m_endTakeTotal;
557  EndTake m_endTake[10];
558  long m_endTakeResearch;
559  bool m_endTakeNever;
560  float m_endTakeWinDelay;
561  float m_endTakeLostDelay;
562 
563  int m_audioChangeTotal;
564  AudioChange m_audioChange[10];
565 
566  int m_obligatoryTotal;
567  char m_obligatoryToken[100][20];
568  int m_prohibitedTotal;
569  char m_prohibitedToken[100][20];
570 
571  std::string m_gamerName;
572 
573  int m_freeBuild; // constructible buildings
574  int m_freeResearch; // researches possible
575 
576  Error m_missionResult;
577 
578  ShowLimit m_showLimit[MAXSHOWLIMIT];
579 
580  Gfx::Color m_colorRefBot;
581  Gfx::Color m_colorNewBot;
582  Gfx::Color m_colorRefAlien;
583  Gfx::Color m_colorNewAlien;
584  Gfx::Color m_colorRefGreen;
585  Gfx::Color m_colorNewGreen;
586  Gfx::Color m_colorRefWater;
587  Gfx::Color m_colorNewWater;
588  float m_colorShiftWater;
589 
590  std::string m_oldLocale;
591 };
592