OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
scriptslave.h
1/*
2===========================================================================
3Copyright (C) 2025 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// scriptslave.h: Standard scripted objects. Controlled by scriptmaster. These objects
24// are bmodel objects created in the editor and controlled by an external
25// text based script. Commands are interpretted on by one and executed
26// upon a signal from the script master. The base script object can
27// perform several different relative and specific rotations and translations
28// and can cause other parts of the script to be executed when touched, damaged,
29// touched, or used.
30//
31
32#pragma once
33
34#include "g_local.h"
35#include "entity.h"
36#include "trigger.h"
37#include "mover.h"
38#include "script.h"
39#include "scriptmaster.h"
40#include "misc.h"
41#include "bspline.h"
42#include "spline.h"
43
44class ScriptSlave : public Mover
45{
46protected:
47 float attack_finished;
48
49 int dmg;
50 int dmg_means_of_death;
51
52public:
53 qboolean commandswaiting;
54
55 Vector TotalRotation;
56 Vector NewAngles;
57 Vector NewPos;
58 Vector ForwardDir;
59 float speed;
60
61 Waypoint *waypoint;
62 float traveltime;
63 BSpline *splinePath;
64 float splineTime;
65
66 cSpline<4, 512> *m_pCurPath;
67 int m_iCurNode;
68
69 float m_fCurSpeed;
70 float m_fIdealSpeed;
71 Vector m_vIdealPosition;
72 Vector m_vIdealDir;
73 float m_fIdealAccel;
74 float m_fIdealDistance;
75 float m_fLookAhead;
76
77 qboolean splineangles;
78 qboolean ignoreangles;
79 qboolean ignorevelocity;
80 float m_fFollowRelativeYaw;
81 qboolean moving; // is the script object currently moving?
82
83protected:
84 void CheckNewOrders(void);
85 void NewMove(void);
86
87 CLASS_PROTOTYPE(ScriptSlave);
88
89 ScriptSlave();
90 ~ScriptSlave();
91
92 void BindEvent(Event *ev);
93 void EventUnbind(Event *ev);
94 void DoMove(Event *ev);
95 void WaitMove(Event *ev);
96 void Stop(Event *ev);
97 void ThreadMove(Event *ev);
98 void MoveEnd(Event *ev);
99 void SetAnglesEvent(Event *ev);
100 void SetAngleEvent(Event *ev);
101 void SetModelEvent(Event *ev);
102 void TriggerEvent(Event *ev) override;
103 void GotoNextWaypoint(Event *ev);
104 void JumpTo(Event *ev);
105 void MoveToEvent(Event *ev);
106 void SetSpeed(Event *ev);
107 void SetTime(Event *ev);
108 void MoveUp(Event *ev);
109 void MoveDown(Event *ev);
110 void MoveNorth(Event *ev);
111 void MoveSouth(Event *ev);
112 void MoveEast(Event *ev);
113 void MoveWest(Event *ev);
114 void MoveForward(Event *ev);
115 void MoveBackward(Event *ev);
116 void MoveLeft(Event *ev);
117 void MoveRight(Event *ev);
118 void MoveOffset(Event *ev);
119 void RotateXdownto(Event *ev);
120 void RotateYdownto(Event *ev);
121 void RotateZdownto(Event *ev);
122 void RotateAxisdownto(Event *ev);
123 void RotateXupto(Event *ev);
124 void RotateYupto(Event *ev);
125 void RotateZupto(Event *ev);
126 void RotateAxisupto(Event *ev);
127 void Rotateupto(Event *ev);
128 void Rotatedownto(Event *ev);
129 void Rotateto(Event *ev);
130 void RotateXdown(Event *ev);
131 void RotateYdown(Event *ev);
132 void RotateZdown(Event *ev);
133 void RotateAxisdown(Event *ev);
134 void RotateXup(Event *ev);
135 void RotateYup(Event *ev);
136 void RotateZup(Event *ev);
137 void RotateAxisup(Event *ev);
138 void RotateX(Event *ev);
139 void RotateY(Event *ev);
140 void RotateZ(Event *ev);
141 void RotateAxis(Event *ev);
142 void TouchFunc(Event *ev);
143 void BlockFunc(Event *ev);
144 void TriggerFunc(Event *ev);
145 void UseFunc(Event *ev);
146 void DamageFunc(Event *ev);
147 void SetDamage(Event *ev);
148 void SetMeansOfDeath(Event *ev);
149 void FollowPath(Event *ev);
150 void FollowPathRelativeYaw(Event *ev); // Added in 2.0
151 void EndPath(Event *ev);
152 void FollowingPath(Event *ev);
153 void CreatePath(SplinePath *path, splinetype_t type);
154 void Explode(Event *ev);
155 void NotShootable(Event *ev);
156 void OpenPortal(Event *ev);
157 void ClosePortal(Event *ev);
158 void PhysicsOn(Event *ev);
159 void PhysicsOff(Event *ev);
160 void PhysicsVelocity(Event *ev);
161 void EventFlyPath(Event *ev);
162 void EventModifyFlyPath(Event *ev);
163 void EventNormalAngles(Event *ev); // Added in 2.0
164 void SetupPath(cSpline<4, 512> *pPath, SimpleEntity *se);
165
166 void Archive(Archiver& arc) override;
167};
168
169inline void ScriptSlave::Archive(Archiver& arc)
170{
171 int tempInt;
172
173 Mover::Archive(arc);
174
175 arc.ArchiveFloat(&attack_finished);
176 arc.ArchiveInteger(&dmg);
177 arc.ArchiveInteger(&dmg_means_of_death);
178
179 arc.ArchiveBoolean(&commandswaiting);
180 arc.ArchiveVector(&TotalRotation);
181 arc.ArchiveVector(&NewAngles);
182 arc.ArchiveVector(&NewPos);
183 arc.ArchiveVector(&ForwardDir);
184 arc.ArchiveFloat(&speed);
185 arc.ArchiveObjectPointer((Class **)&waypoint);
186 arc.ArchiveFloat(&traveltime);
187
188 if (arc.Saving()) {
189 // if it exists, archive it, otherwise place a special NULL ptr tag
190 if (splinePath) {
191 tempInt = ARCHIVE_POINTER_VALID;
192 } else {
193 tempInt = ARCHIVE_POINTER_NULL;
194 }
195 arc.ArchiveInteger(&tempInt);
196 if (tempInt == ARCHIVE_POINTER_VALID) {
197 splinePath->Archive(arc);
198 }
199 } else {
200 arc.ArchiveInteger(&tempInt);
201 if (tempInt == ARCHIVE_POINTER_VALID) {
202 splinePath = new BSpline;
203 splinePath->Archive(arc);
204 } else {
205 splinePath = NULL;
206 }
207 }
208 arc.ArchiveFloat(&splineTime);
209 arc.ArchiveBoolean(&splineangles);
210 arc.ArchiveBoolean(&ignoreangles);
211 arc.ArchiveBoolean(&ignorevelocity);
212 arc.ArchiveBoolean(&moving);
213
214 if (arc.Saving()) {
215 // if it exists, archive it, otherwise place a special NULL ptr tag
216 if (m_pCurPath) {
217 tempInt = ARCHIVE_POINTER_VALID;
218 } else {
219 tempInt = ARCHIVE_POINTER_NULL;
220 }
221 arc.ArchiveInteger(&tempInt);
222 if (tempInt == ARCHIVE_POINTER_VALID) {
223 m_pCurPath->Archive(arc);
224 }
225 } else {
226 arc.ArchiveInteger(&tempInt);
227 if (tempInt == ARCHIVE_POINTER_VALID) {
228 m_pCurPath = new cSpline<4, 512>;
229 m_pCurPath->Archive(arc);
230 } else {
231 m_pCurPath = NULL;
232 }
233 }
234
235 arc.ArchiveInteger(&m_iCurNode);
236 arc.ArchiveFloat(&m_fCurSpeed);
237 arc.ArchiveFloat(&m_fIdealSpeed);
238 arc.ArchiveVector(&m_vIdealPosition);
239 arc.ArchiveVector(&m_vIdealDir);
240 arc.ArchiveFloat(&m_fIdealAccel);
241 arc.ArchiveFloat(&m_fIdealDistance);
242 arc.ArchiveFloat(&m_fLookAhead);
243 arc.ArchiveFloat(&m_fFollowRelativeYaw);
244}
245
246class ScriptModel : public ScriptSlave
247{
248private:
249 void GibEvent(Event *ev);
250
251public:
252 CLASS_PROTOTYPE(ScriptModel);
253
254 ScriptModel();
255 void SetAngleEvent(Event *ev);
256 void SetModelEvent(Event *ev);
257 void SetAnimEvent(Event *ev);
258 void AnimDoneEvent(Event *ev);
259 void MoveAnimEvent(Event *ev);
260 void MovingFromAnimEvent(Event *ev);
261
262 void Archive(Archiver& arc) override;
263};
264
265inline void ScriptModel::Archive(Archiver& arc)
266{
267 ScriptSlave::Archive(arc);
268}
269
270class ScriptModelRealDamage : public ScriptModel
271{
272public:
273 CLASS_PROTOTYPE(ScriptModelRealDamage);
274
275 ScriptModelRealDamage();
276 void EventDamage(Event *ev);
277
278 void Archive(Archiver& arc) override;
279};
280
281inline void ScriptModelRealDamage::Archive(Archiver& arc)
282{
283 ScriptModel::Archive(arc);
284}
285
286class ScriptOrigin : public ScriptSlave
287{
288public:
289 CLASS_PROTOTYPE(ScriptOrigin);
290 ScriptOrigin();
291
292 void SetAngleEvent(Event *ev); // Added in 2.30
293 void GetAngleEvent(Event *ev); // Added in 2.30
294};
295
296class ScriptSkyOrigin : public ScriptSlave
297{
298public:
299 CLASS_PROTOTYPE(ScriptSkyOrigin);
300 ScriptSkyOrigin();
301};
302
303class ScriptSimpleStrafingGunfire : public ScriptSlave
304{
305protected:
306 qboolean isOn;
307 float fireDelay;
308 float range;
309 Vector spread;
310 float damage;
311 float knockback;
312 float throughWood;
313 float throughMetal;
314 int bulletCount;
315 int tracerCount;
316 int tracerFrequency;
317 str projectileModel;
318
319public:
320 CLASS_PROTOTYPE(ScriptSimpleStrafingGunfire);
321
322 ScriptSimpleStrafingGunfire();
323
324 void Archive(Archiver& arc) override;
325
326protected:
327 void GunFire(Event *ev);
328
329private:
330 void GunOn(Event *ev);
331 void GunOff(Event *ev);
332 void SetFireDelay(Event *ev);
333 void SetRange(Event *ev);
334 void SetSpread(Event *ev);
335 void SetDamage(Event *ev);
336 void SetKnockback(Event *ev);
337 void SetThroughWood(Event *ev);
338 void SetThroughMetal(Event *ev);
339 void SetBulletCount(Event *ev);
340 void SetTracerFreq(Event *ev);
341 void SetProjectileModel(Event *ev);
342};
343
344inline void ScriptSimpleStrafingGunfire::SetFireDelay(Event *ev)
345{
346 fireDelay = ev->GetFloat(1);
347}
348
349inline void ScriptSimpleStrafingGunfire::SetRange(Event *ev)
350{
351 range = ev->GetFloat(1);
352}
353
354inline void ScriptSimpleStrafingGunfire::SetSpread(Event *ev)
355{
356 spread.x = ev->GetFloat(1);
357 spread.y = ev->GetFloat(2);
358}
359
360inline void ScriptSimpleStrafingGunfire::SetDamage(Event *ev)
361{
362 damage = ev->GetFloat(1);
363}
364
365inline void ScriptSimpleStrafingGunfire::SetKnockback(Event *ev)
366{
367 knockback = ev->GetFloat(1);
368}
369
370inline void ScriptSimpleStrafingGunfire::SetThroughWood(Event *ev)
371{
372 throughWood = ev->GetFloat(1);
373}
374
375inline void ScriptSimpleStrafingGunfire::SetThroughMetal(Event *ev)
376{
377 throughMetal = ev->GetFloat(1);
378}
379
380inline void ScriptSimpleStrafingGunfire::SetBulletCount(Event *ev)
381{
382 bulletCount = ev->GetInteger(1);
383}
384
385inline void ScriptSimpleStrafingGunfire::SetTracerFreq(Event *ev)
386{
387 tracerFrequency = ev->GetInteger(1);
388 tracerCount = 0;
389}
390
391inline void ScriptSimpleStrafingGunfire::SetProjectileModel(Event *ev)
392{
393 projectileModel = ev->GetString(1);
394}
395
396class ScriptAimedStrafingGunfire : public ScriptSimpleStrafingGunfire
397{
398private:
399 Entity *aimTarget;
400
401public:
402 CLASS_PROTOTYPE(ScriptAimedStrafingGunfire);
403
404 ScriptAimedStrafingGunfire();
405
406 void Archive(Archiver& arc) override;
407
408 void GunFire(Event *ev);
409 void SetAimTarget(Event *ev);
410};
411
412inline void ScriptAimedStrafingGunfire::SetAimTarget(Event *ev)
413{
414 aimTarget = ev->GetEntity(1);
415}
Definition archive.h:86
Definition bspline.h:237
Definition class.h:276
Definition entity.h:203
Definition listener.h:246
Definition simpleentity.h:42
Definition bspline.h:492
Definition vector.h:61
Definition misc.h:320
Definition spline.h:33
Definition str.h:77