1 #ifndef VIRTOBJ_DEFINE 2 #define VIRTOBJ_DEFINE 3 4 /* 5 * atanks - obliterate each other with oversize weapons 6 * Copyright (C) 2003 Thomas Hudson 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 * */ 22 23 #ifndef _PURE 24 #define _PURE =0 25 #endif // _PURE 26 27 #include "main.h" 28 #include "text.h" 29 30 31 /// @enum ePhysType 32 /// @brief Determine which kind of physics should be used 33 enum ePhysType 34 { 35 PT_NORMAL = 0, //!< No special processing, just a normal curve shot and impact. 36 PT_FUNKY_FLOAT, //!< Funky bomb-lets ignore gravitation. 37 PT_DIGGING, //!< Burrowers and the like dig through dirt in a reverse curve. 38 PT_ROLLING, //!< Roll over the surface. 39 PT_DIRTBOUNCE, //!< Dirt debris bounces off of dirt and all walls. 40 PT_SMOKE, //!< Smoke reacts on nothing but repulsor shields. 41 PT_NONE, //!< Special values for age caused detonation triggering. 42 }; 43 44 45 #ifndef HAS_PLAYER 46 class PLAYER; 47 #endif // HAS_PLAYER 48 49 class VIRTUAL_OBJECT 50 { 51 public: 52 53 /* ----------------------------------- 54 * --- Constructors and destructor --- 55 * ----------------------------------- 56 */ 57 explicit VIRTUAL_OBJECT(); 58 virtual ~VIRTUAL_OBJECT(); 59 60 61 /* ---------------------- 62 * --- Public methods --- 63 * ---------------------- 64 */ 65 66 /* --- non-inline methods --- */ 67 void addUpdateArea (int32_t left, int32_t top, 68 int32_t width, int32_t height); 69 virtual void applyPhysics (); 70 virtual void draw (); 71 virtual void initialise (); 72 void setUpdateArea (int32_t left, int32_t top, 73 int32_t width, int32_t height); 74 void update (); 75 76 /* --- inline methods --- */ requireUpdate()77 void requireUpdate () { needsUpdate.store(true, ATOMIC_WRITE); } 78 79 /* --- pure virtual (abstract) methods --- */ 80 virtual eClasses getClass () _PURE; 81 82 83 /* ------------------------------ 84 * --- templated list getters --- 85 * ------------------------------ 86 */ 87 88 /// @brief If not nullptr, set @a prev_ to the predecessor of this. 89 template<typename obj_T> getPrev(obj_T ** prev_)90 void getPrev(obj_T** prev_) 91 { 92 obj_T* prev_obj = static_cast<obj_T*>(prev); 93 if (prev_) 94 *prev_ = prev_obj; 95 } 96 97 /// @brief If not nullptr, set @a next_ to the successor of this. 98 template<typename obj_T> getNext(obj_T ** next_)99 void getNext(obj_T** next_) 100 { 101 obj_T* next_obj = static_cast<obj_T*>(next); 102 if (next_) 103 *next_ = next_obj; 104 } 105 106 /* ---------------------- 107 * --- Public members --- 108 * ---------------------- 109 */ 110 111 bool destroy = false; 112 VIRTUAL_OBJECT* next = nullptr; 113 PLAYER* player = nullptr; 114 VIRTUAL_OBJECT* prev = nullptr; 115 double x = 0.; 116 double y = 0.; 117 118 protected: 119 120 121 /* ------------------------- 122 * --- Protected methods --- 123 * ------------------------- 124 */ 125 getBitmap()126 BITMAP* getBitmap() const { return bitmap; } hasBitmap()127 bool hasBitmap() const { return (bitmap != nullptr); } 128 void setBitmap(BITMAP* bitmap_); 129 130 131 /* ------------------------- 132 * --- Protected members --- 133 * ------------------------- 134 */ 135 136 int32_t age = 0; 137 alignType align = LEFT; 138 int32_t angle = 0; 139 BOX dim_cur; 140 BOX dim_old; 141 int32_t height = 0; 142 int32_t maxAge = -1; 143 ePhysType physType = PT_NORMAL; // Special physics processing? 144 int32_t width = 0; 145 double xv = 0.; 146 double yv = 0.; 147 148 private: 149 150 /* ----------------------- 151 * --- Private members --- 152 * ----------------------- 153 */ 154 155 BITMAP* bitmap = nullptr; 156 abool_t needsUpdate; 157 }; 158 159 /// === Shorten the usage of virtual objects === 160 typedef VIRTUAL_OBJECT vobj_t; 161 162 #endif // VIRTOBJ_DEFINE 163