OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
simpleactor.h
1/*
2===========================================================================
3Copyright (C) 2015 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// simpleactor.h: Base class for character AI.
24
25#pragma once
26
27#include "weapon.h"
28#include "sentient.h"
29#include "container.h"
30#include "stack.h"
31#include "navigate.h"
32#include "scriptmaster.h"
33#include "characterstate.h"
34#include "actorpath.h"
35
36enum eEmotionMode {
37 EMOTION_NONE,
38 EMOTION_NEUTRAL,
39 EMOTION_WORRY,
40 EMOTION_PANIC,
41 EMOTION_FEAR,
42 EMOTION_DISGUST,
43 EMOTION_ANGER,
44 EMOTION_AIMING,
45 EMOTION_DETERMINED,
46 EMOTION_DEAD,
47 EMOTION_CURIOUS
48};
49
50enum eAnimMode {
51 ANIM_MODE_NONE,
52 ANIM_MODE_NORMAL,
53 ANIM_MODE_PATH,
54 ANIM_MODE_PATH_GOAL,
55 ANIM_MODE_DEST,
56 ANIM_MODE_SCRIPTED,
57 ANIM_MODE_NOCLIP,
58 ANIM_MODE_FALLING_PATH,
59 ANIM_MODE_FROZEN,
60 ANIM_MODE_ATTACHED,
61};
62
63enum eAnimWeightType {
64 ANIM_WEIGHT_NONE,
65 ANIM_WEIGHT_MOTION,
66 ANIM_WEIGHT_ACTION,
67 ANIM_WEIGHT_CROSSBLEND_1,
68 ANIM_WEIGHT_CROSSBLEND_2,
69 ANIM_WEIGHT_CROSSBLEND_DIALOG,
70 ANIM_WEIGHT_SAY,
71 ANIM_WEIGHT_AIM,
72 ANIM_WEIGHT_LASTFRAME,
73};
74
75class SimpleActor;
76
77typedef SafePtr<SimpleActor> SimpleActorPtr;
78
79class SimpleActor : public Sentient
80{
81public:
82 int m_eAnimMode;
83 ScriptThreadLabel m_Anim;
84 SafePtr<ScriptThread> m_pAnimThread;
85 int m_eNextAnimMode;
86 const_str m_csNextAnimString;
87 ScriptThreadLabel m_NextAnimLabel;
88 bool m_bNextForceStart;
89 float m_fCrouchWeight;
90 bool m_YawAchieved;
91 float m_DesiredYaw;
92 bool m_bHasDesiredLookDest;
93 bool m_bHasDesiredLookAngles;
94 Vector m_vDesiredLookDest;
95 Vector m_DesiredLookAngles;
96 Vector m_DesiredGunDir;
97 ActorPath m_Path;
98 float m_Dest[3];
99 float m_NoClipDest[3];
100 float path_failed_time;
101 float m_fPathGoalTime;
102 bool m_bStartPathGoalEndAnim;
103 const_str m_csPathGoalEndAnimScript;
104 qboolean m_walking;
105 qboolean m_groundPlane;
106 vec3_t m_groundPlaneNormal;
107 Vector watch_offset;
108 bool m_bThink;
109 int m_PainTime;
110 eEmotionMode m_eEmotionMode;
111 float m_fAimLimit_up;
112 float m_fAimLimit_down;
113 int m_ChangeMotionAnimIndex;
114 int m_ChangeActionAnimIndex;
115 int m_ChangeSayAnimIndex;
116
117protected:
118 unsigned int m_weightType[MAX_FRAMEINFOS];
119 float m_weightBase[MAX_FRAMEINFOS];
120 float m_weightCrossBlend[MAX_FRAMEINFOS];
121 bool m_AnimMotionHigh;
122 bool m_AnimActionHigh;
123 bool m_AnimDialogHigh;
124
125public:
126 int hit_obstacle_time;
127 float obstacle_vel[2];
128 const_str m_csAnimName;
129 const_str m_csSayAnim;
130 const_str m_csUpperAnim;
131 const_str m_csCurrentPosition;
132 int m_bPathErrorTime;
133 class PathNode *m_NearestNode;
134 Vector m_vNearestNodePos;
135 short m_bUpdateAnimDoneFlags;
136 float m_maxspeed;
137 const_str m_csMood;
138 const_str m_csIdleMood;
139 int m_iMotionSlot;
140 int m_iActionSlot;
141 int m_iSaySlot;
142 bool m_bLevelMotionAnim;
143 bool m_bLevelActionAnim;
144 byte m_bLevelSayAnim;
145 byte m_bNextLevelSayAnim;
146 bool m_bMotionAnimSet;
147 bool m_bActionAnimSet;
148 bool m_bSayAnimSet;
149 bool m_bAimAnimSet;
150 int m_iVoiceTime;
151 bool m_bDoAI;
152 ScriptThreadLabel m_PainHandler;
153 ScriptThreadLabel m_DeathHandler;
154 ScriptThreadLabel m_AttackHandler;
155 ScriptThreadLabel m_SniperHandler;
156 float m_fCrossblendTime;
157
158public:
159 CLASS_PROTOTYPE(SimpleActor);
160
161 SimpleActor();
162 ~SimpleActor();
163
164 void Archive(Archiver &arc) override;
165 virtual void SetMoveInfo(mmove_t *mm);
166 virtual void GetMoveInfo(mmove_t *mm);
167 bool CanSeeFrom(vec3_t pos, Entity *ent);
168 virtual bool CanTarget(void);
169 virtual bool IsImmortal(void);
170 bool DoesTheoreticPathExist(Vector vDestPos, float fMaxPath);
171 void
172 SetPath(Vector vDestPos, const char *description, int iMaxDirtyTime, float *vLeashHome, float fLeashDistSquared);
173 void SetPath(SimpleEntity *pDestNode, const char *description, int iMaxDirtyTime);
174 void SetPathWithinDistance(Vector vDestPos, char *description, float fMaxPath, int iMaxDirtyTime);
175 void FindPathAway(vec3_t vAwayFrom, vec2_t vDirPreferred, float fMinSafeDist);
176 void ClearPath(void);
177 bool PathComplete(void) const;
178 bool PathExists(void) const;
179 bool PathIsValid(void) const;
180 bool PathAvoidsSquadMates(void) const;
181 void ShortenPathToAvoidSquadMates(void);
182 PathInfo *CurrentPathNode(void) const;
183 PathInfo *LastPathNode(void) const;
184 float PathDist(void) const;
185 bool PathHasCompleteLookahead(void) const;
186 Vector PathGoal(void) const;
187 const float *PathDelta(void) const;
188 bool PathGoalSlowdownStarted(void) const;
189 void SetDest(vec3_t dest);
190 void StopTurning(void);
191 void SetDesiredYaw(float yaw);
192 void SetDesiredYawDir(const vec2_t vec);
193 void SetDesiredYawDest(const vec3_t vec);
194 void UpdateEmotion(void);
195 int GetEmotionAnim(void);
196 int GetMotionSlot(int slot);
197 int GetActionSlot(int slot);
198 int GetSaySlot(void);
199 void StartCrossBlendAnimSlot(int slot);
200 void StartMotionAnimSlot(int slot, int anim, float weight);
201 void StartAimMotionAnimSlot(int slot, int anim);
202 void StartActionAnimSlot(int anim);
203 void StartSayAnimSlot(int anim);
204 void StartAimAnimSlot(int slot, int anim);
205 void SetBlendedWeight(int slot);
206 void EventSetAnimLength(Event *ev);
207 void UpdateNormalAnimSlot(int slot);
208 void UpdateCrossBlendAnimSlot(int slot);
209 void UpdateCrossBlendDialogAnimSlot(int slot);
210 void UpdateSayAnimSlot(int slot);
211 void UpdateLastFrameSlot(int slot);
212 void UpdateAnimSlot(int slot);
213 void StopAllAnimating(void);
214 void ChangeMotionAnim(void);
215 void ChangeActionAnim(void);
216 void ChangeSayAnim(void);
217 void StopAnimating(int slot);
218 void AnimFinished(int slot) override;
219 void UpdateAim(void);
220 void UpdateAimMotion(void);
221 void EventAIOn(Event *ev);
222 void EventAIOff(Event *ev);
223 void EventGetWeaponGroup(Event *ev);
224 void EventGetWeaponType(Event *ev);
225 void EventGetPainHandler(Event *ev);
226 void EventSetPainHandler(Event *ev);
227 void EventGetDeathHandler(Event *ev);
228 void EventSetDeathHandler(Event *ev);
229 void EventGetAttackHandler(Event *ev);
230 void EventSetAttackHandler(Event *ev);
231 void EventGetSniperHandler(Event *ev);
232 void EventSetSniperHandler(Event *ev);
233 void EventSetCrossblendTime(Event *ev);
234 void EventGetCrossblendTime(Event *ev);
235 void EventSetEmotion(Event *ev);
236 void EventGetPosition(Event *ev);
237 void EventSetPosition(Event *ev);
238 void EventGetAnimMode(Event *ev);
239 void EventSetAnimMode(Event *ev);
240 void EventSetAnimFinal(Event *ev);
241 void EventNoAnimLerp(Event *ev); // Added in 2.0
242 const_str GetRunAnim(void);
243 const_str GetWalkAnim(void);
244 void DesiredAnimation(int eAnimMode, const_str csAnimString);
245 void StartAnimation(int eAnimMode, const_str csAnimString);
246 void DesiredAnimation(int eAnimMode, ScriptThreadLabel AnimLabel);
247 void StartAnimation(int eAnimMode, ScriptThreadLabel AnimLabel);
248 void ContinueAnimationAllowNoPath(void);
249 void ContinueAnimation(void);
250 void SetPathGoalEndAnim(const_str csEndAnim);
251 bool UpdateSelectedAnimation(void);
252 void Anim_Attack(void);
253 void Anim_Suppress(void); // Added in 2.0
254 void Anim_Sniper(void);
255 void Anim_Aim(void);
256 void Anim_Shoot(void);
257 void Anim_Idle(void);
258 void Anim_Crouch(void);
259 void Anim_Prone(void);
260 void Anim_Stand(void);
261 void Anim_Cower(void);
262 void Anim_Killed(void);
263 void Anim_StartPain(void);
264 void Anim_Pain(void);
265 void Anim_CrouchRunTo(int eAnimMode);
266 void Anim_CrouchWalkTo(int eAnimMode);
267 void Anim_StandRunTo(int eAnimMode);
268 void Anim_StandWalkTo(int eAnimMode);
269 void Anim_RunTo(int eAnimMode);
270 void Anim_WalkTo(int eAnimMode);
271 void Anim_RunAwayFiring(int eAnimMode);
272 void Anim_RunToShooting(int eAnimMode);
273 void Anim_RunToAlarm(int eAnimMode);
274 void Anim_RunToCasual(int eAnimMode);
275 void Anim_RunToCover(int eAnimMode);
276 void Anim_RunToDanger(int eAnimMode);
277 void Anim_RunToDive(int eAnimMode);
278 void Anim_RunToFlee(int eAnimMode);
279 void Anim_RunToInOpen(int eAnimMode);
280 void Anim_Emotion(eEmotionMode eEmotMode);
281 void Anim_Say(const_str csSayAnimScript, int iMinTimeSinceLastSay, bool bCanInterrupt);
282 void Anim_FullBody(const_str csFullBodyAnim, int eAnimMode);
283 virtual const char *DumpCallTrace(const char *pszFmt, ...) const;
284};
285
286inline void SimpleActor::StartAnimation(int eAnimMode, const_str csAnimString)
287{
288 m_eNextAnimMode = eAnimMode;
289 m_csNextAnimString = csAnimString;
290 m_bNextForceStart = true;
291}
292
293inline void SimpleActor::DesiredAnimation(int eAnimMode, const_str csAnimString)
294{
295 m_eNextAnimMode = eAnimMode;
296 m_csNextAnimString = csAnimString;
297 m_bNextForceStart = false;
298}
299
300inline void SimpleActor::StartAnimation(int eAnimMode, ScriptThreadLabel AnimLabel)
301{
302 m_eNextAnimMode = eAnimMode;
303 m_csNextAnimString = STRING_NULL;
304 m_NextAnimLabel = AnimLabel;
305 m_bNextForceStart = true;
306}
307
308inline void SimpleActor::DesiredAnimation(int eAnimMode, ScriptThreadLabel AnimLabel)
309{
310 m_eNextAnimMode = eAnimMode;
311 m_csNextAnimString = STRING_NULL;
312 m_NextAnimLabel = AnimLabel;
313 m_bNextForceStart = false;
314}
315
316inline void SimpleActor::ContinueAnimationAllowNoPath(void)
317{
318 if (m_eNextAnimMode < ANIM_MODE_NONE) {
319 m_eNextAnimMode = m_eAnimMode;
320 m_csNextAnimString = STRING_NULL;
321 m_NextAnimLabel = m_Anim;
322 m_bNextForceStart = false;
323 }
324}
325
326inline void SimpleActor::ContinueAnimation(void)
327{
328 ContinueAnimationAllowNoPath();
329
330 if ((m_eNextAnimMode == ANIM_MODE_PATH || m_eNextAnimMode == ANIM_MODE_PATH_GOAL) && !PathExists()) {
331 assert(!"ContinueAnimation() called on a pathed animation, but no path exists");
332 Anim_Stand();
333 }
334}
335
336inline void SimpleActor::SetPathGoalEndAnim(const_str csEndAnim)
337{
338 m_csPathGoalEndAnimScript = csEndAnim;
339}
340
341inline void SimpleActor::Archive(Archiver& arc)
342{
343 int i;
344
345 Sentient::Archive(arc);
346
347 arc.ArchiveInteger(&m_eAnimMode);
348 m_Anim.Archive(arc);
349
350 arc.ArchiveBool(&m_bHasDesiredLookDest);
351 arc.ArchiveBool(&m_bHasDesiredLookAngles);
352 arc.ArchiveVector(&m_vDesiredLookDest);
353 arc.ArchiveVec3(m_DesiredLookAngles);
354 arc.ArchiveVec3(m_DesiredGunDir);
355
356 m_Path.Archive(arc);
357 arc.ArchiveVec3(m_Dest);
358 arc.ArchiveVec3(m_NoClipDest);
359
360 arc.ArchiveFloat(&path_failed_time);
361 arc.ArchiveFloat(&m_fPathGoalTime);
362 arc.ArchiveBool(&m_bStartPathGoalEndAnim);
363 Director.ArchiveString(arc, m_csPathGoalEndAnimScript);
364
365 arc.ArchiveInteger(&m_eNextAnimMode);
366 Director.ArchiveString(arc, m_csNextAnimString);
367 m_NextAnimLabel.Archive(arc);
368 arc.ArchiveBool(&m_bNextForceStart);
369
370 arc.ArchiveBoolean(&m_walking);
371 arc.ArchiveBoolean(&m_groundPlane);
372 arc.ArchiveVec3(m_groundPlaneNormal);
373
374 arc.ArchiveVector(&watch_offset);
375 arc.ArchiveBool(&m_bThink);
376 arc.ArchiveInteger(&m_PainTime);
377
378 arc.ArchiveBool(&m_bAimAnimSet);
379 arc.ArchiveBool(&m_bActionAnimSet);
380
381 Director.ArchiveString(arc, m_csMood);
382 Director.ArchiveString(arc, m_csIdleMood);
383
384 ArchiveEnum(m_eEmotionMode, eEmotionMode);
385
386 arc.ArchiveFloat(&m_fAimLimit_up);
387 arc.ArchiveFloat(&m_fAimLimit_down);
388
389 for (i = 0; i < MAX_FRAMEINFOS; i++) {
390 arc.ArchiveUnsigned(&m_weightType[i]);
391 }
392
393 for (i = 0; i < MAX_FRAMEINFOS; i++) {
394 arc.ArchiveFloat(&m_weightBase[i]);
395 }
396
397 for (i = 0; i < MAX_FRAMEINFOS; i++) {
398 arc.ArchiveFloat(&m_weightCrossBlend[i]);
399 }
400
401 arc.ArchiveBool(&m_AnimMotionHigh);
402 arc.ArchiveBool(&m_AnimActionHigh);
403 arc.ArchiveBool(&m_AnimDialogHigh);
404
405 arc.ArchiveVec2(obstacle_vel);
406
407 Director.ArchiveString(arc, m_csCurrentPosition);
408
409 arc.ArchiveBool(&m_bMotionAnimSet);
410 arc.ArchiveBool(&m_bDoAI);
411
412 arc.ArchiveFloat(&m_fCrossblendTime);
413
414 arc.ArchiveSafePointer(&m_pAnimThread);
415
416 arc.ArchiveBool(&m_YawAchieved);
417 arc.ArchiveFloat(&m_DesiredYaw);
418
419 arc.ArchiveInteger(&m_iVoiceTime);
420 arc.ArchiveBool(&m_bSayAnimSet);
421
422 arc.ArchiveInteger(&hit_obstacle_time);
423
424 Director.ArchiveString(arc, m_csAnimName);
425
426 arc.ArchiveInteger(&m_bPathErrorTime);
427 arc.ArchiveInteger(&m_iMotionSlot);
428 arc.ArchiveInteger(&m_iActionSlot);
429 arc.ArchiveInteger(&m_iSaySlot);
430
431 arc.ArchiveBool(&m_bLevelMotionAnim);
432 arc.ArchiveBool(&m_bLevelActionAnim);
433 arc.ArchiveByte(&m_bLevelSayAnim);
434 arc.ArchiveByte(&m_bNextLevelSayAnim);
435
436 Director.ArchiveString(arc, m_csSayAnim);
437 Director.ArchiveString(arc, m_csUpperAnim);
438
439 m_PainHandler.Archive(arc);
440 m_DeathHandler.Archive(arc);
441 m_AttackHandler.Archive(arc);
442 m_SniperHandler.Archive(arc);
443
444 arc.ArchiveObjectPointer((Class **)&m_NearestNode);
445 arc.ArchiveVector(&m_vNearestNodePos);
446
447 arc.ArchiveFloat(&m_fCrouchWeight);
448 arc.ArchiveFloat(&m_maxspeed);
449}
450
451inline void SimpleActor::StopTurning(void)
452{
453 m_YawAchieved = true;
454}
455
456inline void SimpleActor::SetDesiredYaw(float yaw)
457{
458 m_YawAchieved = false;
459 m_DesiredYaw = yaw;
460}
461
462inline void SimpleActor::SetDesiredYawDir(const vec2_t vec)
463{
464 SetDesiredYaw(vectoyaw(vec));
465}
466
467inline void SimpleActor::SetDesiredYawDest(const vec3_t vec)
468{
469 vec2_t facedir;
470 VectorSub2D(vec, origin, facedir);
471
472 if (facedir[0] || facedir[1]) {
473 SetDesiredYawDir(facedir);
474 }
475}
476
477inline void SimpleActor::SetDest(vec3_t dest)
478{
479 VectorCopy(dest, m_Dest);
480}
Definition actorpath.h:34
Definition archive.h:86
Definition listener.h:246
Definition navigate.h:99
Definition navigate.h:153
Definition safeptr.h:160
Definition gamescript.h:165
Definition simpleactor.h:80
Definition simpleentity.h:42
Definition vector.h:61