Colobot
script.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 
30 #include "common/global.h"
31 
32 #include "CBot/CBotDll.h"
33 
34 
35 class CObject;
36 class CTaskManager;
37 class CRobotMain;
38 class CPauseManager;
39 class CScriptFunctions;
40 
41 namespace Ui{
42 class CEdit;
43 class CInterface;
44 class CList;
45 } /* Ui */
46 
47 namespace Gfx {
48 class CEngine;
49 class CTerrain;
50 class CWater;
51 } /* Gfx */
52 
53 
54 const int ERM_CONT = 0; // if error -> continue
55 const int ERM_STOP = 1; // if error -> stop
56 
57 
58 class CScript
59 {
60 friend class CScriptFunctions;
61 public:
62  CScript(CObject* object, CTaskManager** secondaryTask);
63  ~CScript();
64 
65  void PutScript(Ui::CEdit* edit, const char* name);
66  bool GetScript(Ui::CEdit* edit);
67  bool GetCompile();
68 
69  void GetTitle(char* buffer);
70 
71  void SetStepMode(bool bStep);
72  bool Run();
73  bool Continue(const Event &event);
74  bool Step(const Event &event);
75  void Stop();
76  bool IsRunning();
77  bool IsContinue();
78  bool GetCursor(int &cursor1, int &cursor2);
79  void UpdateList(Ui::CList* list);
80  void ColorizeScript(Ui::CEdit* edit);
81  bool IntroduceVirus();
82 
83  int GetError();
84  void GetError(std::string& error);
85 
86  void New(Ui::CEdit* edit, const char* name);
87  bool SendScript(const char* text);
88  bool ReadScript(const char* filename);
89  bool WriteScript(const char* filename);
90  bool ReadStack(FILE *file);
91  bool WriteStack(FILE *file);
92  bool Compare(CScript* other);
93 
94  void SetFilename(char *filename);
95  char* GetFilename();
96 
97 protected:
98  bool IsEmpty();
99  bool CheckToken();
100  bool Compile();
101 
102 protected:
103  Gfx::CEngine* m_engine;
104  Ui::CInterface* m_interface;
105  CBotProgram* m_botProg;
106  CRobotMain* m_main;
107  Gfx::CTerrain* m_terrain;
108  Gfx::CWater* m_water;
109  CTaskManager* m_primaryTask;
110  CTaskManager** m_secondaryTask;
111  CObject* m_object;
112  CPauseManager* m_pause;
113 
114  int m_ipf; // number of instructions/second
115  int m_errMode; // what to do in case of error
116  int m_len; // length of the script (without <0>)
117  char* m_script; // script ends with <0>
118  bool m_bRun; // program during execution?
119  bool m_bStepMode; // step by step
120  bool m_bContinue; // external function to continue
121  bool m_bCompile; // compilation ok?
122  char m_title[50]; // script title
123  char m_mainFunction[50];
124  char m_filename[50]; // file name
125  char m_token[50]; // missing instruction
126  int m_error; // error (0=ok)
127  int m_cursor1;
128  int m_cursor2;
129  Event m_event;
130  float m_returnValue;
131 };
132 
Definition: controller.h:32
Library for interpretation of CBOT language.
Definition: list.h:42
Some common, global definitions.
Definition: CBotDll.h:364
Definition: robotmain.h:172
Definition: taskmanager.h:34
Terrain loader/generator and manager.
Definition: terrain.h:222
Namespace for (new) graphics code.
Definition: app.h:49
The graphics engine.
Definition: engine.h:684
Definition: scriptfunc.h:38
Event types, structs and event queue.
Definition: script.h:58
Water manager/renderer.
Definition: water.h:118
Definition: edit.h:131
Event sent by system, interface or game.
Definition: event.h:678
Definition: pausemanager.h:44
Definition: interface.h:58
Definition: object.h:357