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-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 "CBot/CBot.h"
28 
29 #include <memory>
30 #include <string>
31 #include <boost/optional.hpp>
32 
33 
34 class COldObject;
36 class CRobotMain;
37 class CScriptFunctions;
38 
39 namespace Ui
40 {
41 class CEdit;
42 class CInterface;
43 class CList;
44 } /* Ui */
45 
46 namespace Gfx
47 {
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(COldObject* object);
63  ~CScript();
64 
65  void PutScript(Ui::CEdit* edit, const char* name);
66  bool GetScript(Ui::CEdit* edit);
67  bool GetCompile();
68 
69  const std::string& GetTitle();
70 
71  void SetStepMode(bool bStep);
72  bool GetStepMode();
73  bool Run();
74  bool Continue();
75  bool Step();
76  void Stop();
77  bool IsRunning();
78  bool IsContinue();
79  bool GetCursor(int &cursor1, int &cursor2);
80  void UpdateList(Ui::CList* list);
81  static void ColorizeScript(Ui::CEdit* edit, int rangeStart = 0, int rangeEnd = std::numeric_limits<int>::max());
82  bool IntroduceVirus();
83 
84  int GetError();
85  void GetError(std::string& error);
86 
87  void New(Ui::CEdit* edit, const char* name);
88  bool SendScript(const char* text);
89  bool ReadScript(const char* filename);
90  bool WriteScript(const char* filename);
91  bool ReadStack(FILE *file);
92  bool WriteStack(FILE *file);
93  bool Compare(CScript* other);
94 
95  void SetFilename(const std::string &filename);
96  const std::string& GetFilename();
97 
98 protected:
99  bool IsEmpty();
100  bool CheckToken();
101  bool Compile();
102 
103 protected:
104  COldObject* m_object = nullptr;
105  CTaskExecutorObject* m_taskExecutor = nullptr;
106 
107  Gfx::CEngine* m_engine = nullptr;
108  Ui::CInterface* m_interface = nullptr;
109  std::unique_ptr<CBot::CBotProgram> m_botProg;
110  CRobotMain* m_main = nullptr;
111  Gfx::CTerrain* m_terrain = nullptr;
112  Gfx::CWater* m_water = nullptr;
113 
114  int m_ipf = 0; // number of instructions/second
115  int m_errMode = 0; // what to do in case of error
116  int m_len = 0; // length of the script (without <0>)
117  std::unique_ptr<char[]> m_script; // script ends with <0>
118  bool m_bRun = false; // program during execution?
119  bool m_bStepMode = false; // step by step
120  bool m_bContinue = false; // external function to continue
121  bool m_bCompile = false; // compilation ok?
122  std::string m_title = ""; // script title
123  std::string m_mainFunction = "";
124  std::string m_filename = ""; // file name
125  std::string m_token = ""; // missing instruction
126  int m_tokenUsed = 0, m_tokenAllowed = 0;
127  CBot::CBotError m_error = CBot::CBotNoErr; // error (0=ok)
128  int m_cursor1 = 0;
129  int m_cursor2 = 0;
130  boost::optional<float> m_returnValue = boost::none;
131 };
Public interface of CBot language interpreter. CBot.h is the only file that should be included by any...
Definition: robotmain.h:108
Interface for objects that can execute tasks.
Definition: task_executor_object.h:36
Definition: list.h:41
Definition: old_object.h:79
Definition: robotmain.h:159
CBotError
This enum contains possible CBot error values. Values in range 5000-5999 are compile errors...
Definition: CBotEnums.h:190
Terrain loader/generator and manager.
Definition: terrain.h:147
Namespace for (new) graphics code.
Definition: app.h:49
The graphics engine.
Definition: engine.h:585
Definition: scriptfunc.h:44
Definition: script.h:58
Water manager/renderer.
Definition: water.h:72
Definition: edit.h:112
Definition: interface.h:59