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