1 /* 2 ** actor.h 3 ** 4 **--------------------------------------------------------------------------- 5 ** Copyright 2011 Braden Obrzut 6 ** All rights reserved. 7 ** 8 ** Redistribution and use in source and binary forms, with or without 9 ** modification, are permitted provided that the following conditions 10 ** are met: 11 ** 12 ** 1. Redistributions of source code must retain the above copyright 13 ** notice, this list of conditions and the following disclaimer. 14 ** 2. Redistributions in binary form must reproduce the above copyright 15 ** notice, this list of conditions and the following disclaimer in the 16 ** documentation and/or other materials provided with the distribution. 17 ** 3. The name of the author may not be used to endorse or promote products 18 ** derived from this software without specific prior written permission. 19 ** 20 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 **--------------------------------------------------------------------------- 31 ** 32 ** 33 */ 34 35 #ifndef __ACTOR_H__ 36 #define __ACTOR_H__ 37 38 #include "wl_def.h" 39 #include "actordef.h" 40 #include "gamemap.h" 41 #include "linkedlist.h" 42 #include "name.h" 43 #include "dobject.h" 44 #include "tflags.h" 45 #include "thinker.h" 46 47 enum 48 { 49 AMETA_BASE = 0x12000, 50 51 AMETA_Damage, 52 AMETA_DropItems, 53 AMETA_SecretDeathSound, 54 AMETA_GibHealth, 55 AMETA_DefaultHealth1, 56 AMETA_DefaultHealth2, 57 AMETA_DefaultHealth3, 58 AMETA_DefaultHealth4, 59 AMETA_DefaultHealth5, 60 AMETA_DefaultHealth6, 61 AMETA_DefaultHealth7, 62 AMETA_DefaultHealth8, 63 AMETA_DefaultHealth9, 64 AMETA_ConversationID 65 }; 66 67 enum 68 { 69 SPAWN_AllowReplacement = 1, 70 SPAWN_Patrol = 2 71 }; 72 73 typedef TFlags<ActorFlag> ActorFlags; 74 DEFINE_TFLAGS_OPERATORS (ActorFlags) 75 76 class player_t; 77 class ClassDef; 78 class AInventory; 79 namespace Dialog { struct Page; } 80 class AActor : public Thinker, 81 public EmbeddedList<AActor>::Node 82 { 83 typedef EmbeddedList<AActor>::Node ActorLink; 84 85 DECLARE_CLASS(AActor, Thinker) 86 HAS_OBJECT_POINTERS 87 88 public: 89 struct DropItem 90 { 91 public: 92 FName className; 93 unsigned int amount; 94 uint8_t probability; 95 }; 96 typedef LinkedList<DropItem> DropList; 97 98 void AddInventory(AInventory *item); BeginPlay()99 virtual void BeginPlay() {} 100 void ClearCounters(); 101 virtual void Destroy(); 102 virtual void Die(); 103 void EnterZone(const MapZone *zone); 104 AInventory *FindInventory(const ClassDef *cls); 105 const Frame *FindState(const FName &name) const; 106 static void FinishSpawningActors(); 107 int GetDamage(); 108 const AActor *GetDefault() const; 109 DropList *GetDropList() const; GetZone()110 const MapZone *GetZone() const { return soundZone; } 111 bool GiveInventory(const ClassDef *cls, int amount=0, bool allowreplacement=true); 112 bool IsFast() const; PostBeginPlay()113 virtual void PostBeginPlay() {} 114 void RemoveFromWorld(); 115 virtual void RemoveInventory(AInventory *item); 116 void Serialize(FArchive &arc); 117 void SetState(const Frame *state, bool norun=false); 118 static AActor *Spawn(const ClassDef *type, fixed x, fixed y, fixed z, int flags); 119 virtual void Tick(); Touch(AActor * toucher)120 virtual void Touch(AActor *toucher) {} 121 122 void PrintInventory(); 123 124 static PointerIndexTable<ExpressionNode> damageExpressions; 125 static PointerIndexTable<DropList> dropItems; 126 127 // Basic properties from objtype 128 ActorFlags flags; 129 130 int32_t distance; // if negative, wait for that door to open 131 dirtype dir; 132 133 #pragma pack(push, 1) 134 // MSVC and older versions of GCC don't support constant union parts 135 // We do this instead of just using a regular word since writing to tilex/y 136 // indicates an error. 137 #if !defined(_MSC_VER) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 6) 138 #define COORD_PART const word 139 #else 140 #define COORD_PART word 141 #endif 142 union 143 { 144 fixed x; 145 #ifdef __BIG_ENDIAN__ 146 struct { COORD_PART tilex; COORD_PART fracx; }; 147 #else 148 struct { COORD_PART fracx; COORD_PART tilex; }; 149 #endif 150 }; 151 union 152 { 153 fixed y; 154 #ifdef __BIG_ENDIAN__ 155 struct { COORD_PART tiley; COORD_PART fracy; }; 156 #else 157 struct { COORD_PART fracy; COORD_PART tiley; }; 158 #endif 159 }; 160 #pragma pack(pop) 161 fixed velx, vely; 162 163 angle_t angle; 164 angle_t pitch; 165 int32_t health; 166 int32_t speed, runspeed; 167 int points; 168 fixed radius; 169 fixed projectilepassheight; 170 171 const Frame *state; 172 unsigned int sprite; 173 fixed scaleX, scaleY; 174 short ticcount; 175 176 short viewx; 177 word viewheight; 178 fixed transx,transy; // in global coord 179 180 FTextureID overheadIcon; 181 182 uint16_t sighttime; 183 uint8_t sightrandom; 184 fixed missilefrequency; 185 uint16_t minmissilechance; 186 short movecount; // Emulation of Doom's movecount 187 fixed meleerange; 188 uint16_t painchance; 189 FNameNoInit activesound, attacksound, deathsound, painsound, seesound; 190 191 const Frame *SpawnState, *SeeState, *PathState, *PainState, *MeleeState, *MissileState; 192 short temp1,hidden; 193 fixed killerx,killery; // For deathcam 194 195 player_t *player; // Only valid with APlayerPawn 196 197 TObjPtr<AInventory> inventory; 198 199 const Dialog::Page *conversation; 200 201 static EmbeddedList<AActor>::List actors; 202 typedef EmbeddedList<AActor>::Iterator Iterator; GetIterator()203 static Iterator GetIterator() { return Iterator(actors); } 204 protected: 205 void Init(); 206 207 const MapZone *soundZone; 208 }; 209 210 // Old save compatibility 211 // FIXME: Remove for 1.4 212 class AActorProxy : public Thinker 213 { DECLARE_CLASS(AActorProxy,Thinker)214 DECLARE_CLASS(AActorProxy, Thinker) 215 216 public: 217 void Tick() {} 218 219 void Serialize(FArchive &arc); 220 221 TObjPtr<AActor> actualObject; 222 }; 223 224 #endif 225