OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
scriptmaster.h
1/*
2===========================================================================
3Copyright (C) 2023 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// scriptmaster.h: Handle events, parse scripts, spawn at the beginning of the map
24
25#pragma once
26
27#include "class.h"
28#include "listener.h"
29#include "scriptvm.h"
30#include <con_timer.h>
31
32#define MAX_COMMANDS 20
33#define MAX_EXECUTION_TIME 3000
34
35void Showmenu(const str& name, qboolean bForce);
36void Hidemenu(const str& name, qboolean bForce);
37
38#define MAX_VAR_STACK 1024
39#define MAX_FASTEVENT 10
40
41class ScriptMaster : public Listener
42{
43 friend class ScriptThread;
44
45public:
46 // VM recursions
47 int stackCount;
48
49 // Global stack (not needed anymore)
50#if 0
51 ScriptVariable avar_Stack[ MAX_VAR_STACK+1 ]; // Global variables stack
52 Event fastEvent[ MAX_FASTEVENT+1 ]; // Event that will be executed
53
54 ScriptVariable *pTop; // Top variable on the stack
55#endif
56
57 // Command variables
58 unsigned int cmdCount; // cmd count
59 int cmdTime; // Elapsed VM execution time
60 int maxTime; // Maximum VM execution time
61
62 // Thread variables
63 SafePtr<ScriptThread> m_PreviousThread; // parm.previousthread
64 SafePtr<ScriptThread> m_CurrentThread; // current running thread
65
66 con_map<const_str, GameScript *> m_GameScripts; // compiled gamescripts
67
68 // Miscellaneous
69 Container<str> m_menus; // Script menus
70 con_timer timerList; // waiting threads list
71 con_arrayset<str, str> StringDict; // const strings (improve performance)
72 int iPaused; // num times paused
73
74protected:
75 static const char *ConstStrings[];
76
77protected:
78 void InitConstStrings(void);
79 void CloseGameScript();
80 GameScript *GetGameScriptInternal(str& filename);
81 void ExecuteRunning();
82 void Cache(Event *ev);
83 void RegisterAliasAndCache(Event *ev);
84 void RegisterAlias(Event *ev);
85
86public:
87 CLASS_PROTOTYPE(ScriptMaster);
88
89 ScriptMaster();
90 virtual ~ScriptMaster();
91
92 //
93 // Thread executions
94 //
95 ScriptThread *CreateThread(GameScript *scr, str label, Listener *self = NULL);
96 ScriptThread *CreateThread(str filename, str label, Listener *self = NULL);
97 void ExecuteThread(GameScript *scr, str label = "");
98 void ExecuteThread(str filename, str label = "");
99 void ExecuteThread(GameScript *scr, str label, Event &parms);
100 void ExecuteThread(str filename, str label, Event &parms);
101 ScriptThread *CreateScriptThread(ScriptClass *scriptClass, unsigned char *m_pCodePos);
102 ScriptThread *CreateScriptThread(GameScript *scr, Listener *self, const_str label);
103 ScriptThread *CreateScriptThread(GameScript *scr, Listener *self, str label);
104 ScriptThread *CreateScriptThread(ScriptClass *scriptClass, const_str label);
105 ScriptThread *CreateScriptThread(ScriptClass *scriptClass, str label);
106 void Reset(qboolean samemap = false);
107 ScriptThread *PreviousThread(void);
108 ScriptThread *CurrentThread(void);
109 ScriptThread *CurrentScriptThread(void);
110 ScriptClass *CurrentScriptClass(void);
111
112 GameScript *GetGameScript(const_str filename, qboolean recompile = false);
113 GameScript *GetGameScript(str filename, qboolean recompile = false);
114 GameScript *GetScript(const_str filename, qboolean recompile = false);
115 GameScript *GetScript(str filename, qboolean recompile = false);
116
117 void SetTime(int time);
118
119 void AddTiming(ScriptThread *thread, int time);
120 void RemoveTiming(ScriptThread *thread);
121 const_str AddString(const char *s);
122 const_str AddString(str& s);
123 const_str GetString(const char *s);
124 const_str GetString(str s);
125 str & GetString(const_str s);
126
127 void ArchiveString(Archiver& arc, const_str& s);
128
129 void Pause();
130 void Unpause();
131 void AllowPause(bool allow);
132 void AddMenu(str name);
133 void RemoveMenu(str name);
134 void LoadMenus(void);
135 void Archive(Archiver& arc) override;
136
137 GameScript *GetTempScript(const char *data);
138
139 void PrintStatus(void);
140 void PrintThread(int iThreadNum);
141};
142
143extern Event EV_RegisterAlias;
144extern Event EV_RegisterAliasAndCache;
145extern Event EV_Cache;
146
147extern qboolean disable_team_change;
148extern qboolean disable_team_spectate;
149extern str vision_current;
150
151extern Event EV_ScriptThread_Trace;
152extern Event EV_ScriptThread_SightTrace;
153extern Event EV_ScriptThread_VisionSetNaked;
154extern Event EV_ScriptThread_CancelWaiting;
155
156extern con_set<str, ScriptThreadLabel> m_scriptCmds;
157extern ScriptMaster Director;
158
159typedef enum scriptedEvType_e {
160 SE_DEFAULT,
161 SE_CONNECTED,
162 SE_DISCONNECTED,
163 SE_SPAWN,
164 SE_DAMAGE,
165 SE_KILL,
166 SE_KEYPRESS,
167 SE_INTERMISSION,
168 SE_SERVERCOMMAND,
169 SE_CHANGETEAM,
170 SE_MAX
171
172} scriptedEvType_t;
173
174class ScriptEvent : public Class
175{
176public:
177 ScriptThreadLabel label;
178
179public:
180 CLASS_PROTOTYPE(ScriptEvent);
181
182 void Archive(Archiver& arc) override;
183
184 bool IsRegistered(void);
185 void Trigger(Event *ev);
186};
187
188inline void ScriptEvent::Archive(Archiver& arc)
189{
190 label.Archive(arc);
191}
192
193inline bool ScriptEvent::IsRegistered(void)
194{
195 return label.IsSet();
196}
197
198inline void ScriptEvent::Trigger(Event *ev)
199{
200 if (label.IsSet()) {
201 label.Execute(NULL, ev);
202 }
203
204 delete ev;
205}
206
207extern ScriptEvent scriptedEvents[];
Definition archive.h:86
Definition container.h:85
Definition listener.h:246
Definition gamescript.h:118
Definition safeptr.h:160
Definition scriptclass.h:35
Definition scriptmaster.h:175
Definition scriptmaster.h:42
Definition gamescript.h:165
Definition scriptvariable.h:75
Definition con_arrayset.h:94
Definition con_set.h:547
Definition con_set.h:119
Definition con_timer.h:4
Definition str.h:77