OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
actorenemy.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// actorenemy.h
24
25#pragma once
26
27#include "g_local.h"
28#include "class.h"
29#include "archive.h"
30
31class Actor;
32class Sentient;
33
34class ActorEnemy : public Class
35{
36public:
37 int m_iAddTime;
38 int m_iNextEnemyTime; // Added in 2.0
39 float m_fLastLookTime;
40 float m_fVisibility;
41 float m_fTotalVisibility;
42 int m_iThreat;
43 SafePtr<Sentient> m_pEnemy;
44 float m_fCurrentRangeSquared;
45 Vector m_vLastKnownPos;
46 int m_iLastSightChangeTime;
47 bool m_bVisible;
48
49 float UpdateVisibility(Actor *pSelf, bool *pbInFovAndRange, bool *pbVisible);
50 int UpdateThreat(Actor *pSelf);
51 Sentient *GetEnemy(void) const;
52 float GetVisibility(void) const;
53 int GetThreat(void) const;
54 float GetRangeSquared(void) const;
55
56 void Archive(Archiver&) override;
57
58protected:
59 float UpdateLMRF(Actor *pSelf, bool *pbInFovAndRange, bool *pbVisible);
60};
61
62inline void ActorEnemy::Archive(Archiver& arc)
63{
64 Class::Archive(arc);
65
66 arc.ArchiveInteger(&m_iAddTime);
67 arc.ArchiveFloat(&m_fLastLookTime);
68 arc.ArchiveFloat(&m_fVisibility);
69 arc.ArchiveFloat(&m_fTotalVisibility);
70 arc.ArchiveInteger(&m_iThreat);
71 arc.ArchiveSafePointer(&m_pEnemy);
72 arc.ArchiveFloat(&m_fCurrentRangeSquared);
73 arc.ArchiveVector(&m_vLastKnownPos);
74 arc.ArchiveInteger(&m_iLastSightChangeTime);
75 arc.ArchiveBool(&m_bVisible);
76}
77
78inline Sentient *ActorEnemy::GetEnemy(void) const
79{
80 return m_pEnemy;
81}
82
83inline float ActorEnemy::GetVisibility(void) const
84{
85 return m_fVisibility;
86}
87
88inline int ActorEnemy::GetThreat(void) const
89{
90 return m_iThreat;
91}
92
93inline float ActorEnemy::GetRangeSquared(void) const
94{
95 return m_fCurrentRangeSquared;
96}
97
98class ActorEnemySet : public Class
99{
100protected:
101 Container<ActorEnemy> m_Enemies;
102 int m_iCheckCount;
103 SafePtr<Sentient> m_pCurrentEnemy;
104 float m_fCurrentVisibility;
105 int m_iCurrentThreat;
106
107public:
108 ActorEnemySet();
109
110 ActorEnemy *AddPotentialEnemy(Sentient *pEnemy);
111 void FlagBadEnemy(Sentient *pEnemy);
112 void CheckEnemies(Actor *pSelf);
113 Sentient *GetCurrentEnemy(void) const;
114 float GetCurrentVisibility(void) const;
115 int GetCurrentThreat(void) const;
116 qboolean IsEnemyConfirmed(void) const;
117 bool HasAlternateEnemy(void) const;
118 void RemoveAll(void);
119 void ConfirmEnemy(Actor *pSelf, Sentient *pEnemy);
120 void ConfirmEnemyIfCanSeeSharerOrEnemy(Actor *pSelf, Actor *pSharer, Sentient *pEnemy);
121 bool CaresAboutPerfectInfo(Sentient *pEnemy);
122
123 void Archive(Archiver& arc) override;
124};
125
126inline Sentient *ActorEnemySet::GetCurrentEnemy(void) const
127{
128 return m_pCurrentEnemy;
129}
130
131inline float ActorEnemySet::GetCurrentVisibility(void) const
132{
133 return m_fCurrentVisibility;
134}
135
136inline int ActorEnemySet::GetCurrentThreat(void) const
137{
138 return m_iCurrentThreat;
139}
140
141inline qboolean ActorEnemySet::IsEnemyConfirmed(void) const
142{
143 return m_fCurrentVisibility > 0.999f;
144}
145
146inline void ActorEnemySet::Archive(Archiver& arc)
147{
148 Class::Archive(arc);
149
150 m_Enemies.Archive(arc);
151 arc.ArchiveInteger(&m_iCheckCount);
152 arc.ArchiveSafePointer(&m_pCurrentEnemy);
153 arc.ArchiveFloat(&m_fCurrentVisibility);
154 arc.ArchiveInteger(&m_iCurrentThreat);
155}
Definition actorenemy.h:35
Definition actor.h:585
Definition archive.h:86
Definition container.h:85
Definition safeptr.h:160
Definition sentient.h:95
Definition vector.h:61