1 /* 2 * Copyright (C) 1998-1999 Jeffrey S. Freedman 3 * Copyright (C) 2000-2013 The Exult Team 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 */ 19 20 #ifndef INCL_EGG 21 #define INCL_EGG 1 22 23 class Egg_object; 24 class Animator; 25 class Monster_actor; 26 class Missile_launcher; 27 28 #include "iregobjs.h" 29 #include "ignore_unused_variable_warning.h" 30 31 using Egg_object_shared = std::shared_ptr<Egg_object>; 32 33 /* 34 * Here's a class for eggs and paths; i.e., objects that generally aren't 35 * visible. 36 */ 37 class Egglike_game_object : public Ireg_game_object { 38 public: 39 Egglike_game_object(int shapenum, int framenum, 40 unsigned int tilex, 41 unsigned int tiley, unsigned int lft = 0) Ireg_game_object(shapenum,framenum,tilex,tiley,lft)42 : Ireg_game_object(shapenum, framenum, tilex, tiley, lft) 43 { } 44 // Render. 45 void paint() override; 46 // Can this be clicked on? 47 bool is_findable() override; 48 }; 49 50 /* 51 * An "egg" is a special object that activates under certain 52 * circumstances. 53 */ 54 class Egg_object : public Egglike_game_object { 55 static Game_object_shared editing; // Egg being edited by ExultStudio. 56 protected: 57 unsigned char type; // One of the below types. 58 unsigned char probability; // 1-100, chance of egg activating. 59 unsigned char criteria: 3; // How it's activated. See below. 60 unsigned distance: 6; // Distance for activation (0-31). 61 unsigned flags: 4; // Formed from below flags. 62 unsigned short data1, data2, data3; // More data, dep. on type. 63 TileRect area; // Active area. 64 unsigned char solid_area; // 1 if area is solid, 0 if outline. 65 Animator *animator; // Controls animation. 66 void init_field(unsigned char ty); 67 static Egg_object_shared create_egg(bool animated, 68 int shnum, int frnum, unsigned int tx, 69 unsigned int ty, unsigned int tz, 70 unsigned short itype, 71 unsigned char prob, short data1, short data2, short data3, 72 const char *str1 = nullptr); 73 public: 74 friend class Button_egg; 75 enum Egg_types { // Types of eggs: 76 monster = 1, 77 jukebox = 2, 78 soundsfx = 3, 79 voice = 4, 80 usecode = 5, 81 missile = 6, 82 teleport = 7, 83 weather = 8, 84 path = 9, 85 button = 10, 86 intermap = 11, 87 // Our own: 88 fire_field = 128, 89 sleep_field = 129, 90 poison_field = 130, 91 caltrops_field = 131, 92 campfire_field = 132, 93 mirror_object = 133 94 }; 95 enum Egg_flag_shifts { 96 nocturnal = 0, 97 once = 1, 98 hatched = 2, 99 auto_reset = 3 100 }; 101 enum Egg_criteria { 102 cached_in = 0, // Activated when chunk read in? 103 party_near = 1, 104 avatar_near = 2, // Avatar steps into area. 105 avatar_far = 3, // Avatar steps outside area. 106 avatar_footpad = 4, // Avatar must step on it. 107 party_footpad = 5, 108 something_on = 6, // Something placed on/near it. 109 external_criteria = 7 // Appears on Isle of Avatar. Guessing 110 // these set off all nearby. 111 }; 112 static Egg_object_shared create_egg(const unsigned char *entry, int entlen, 113 bool animated, int shnum, int frnum, unsigned int tx, 114 unsigned int ty, unsigned int tz); 115 // Create normal eggs. 116 Egg_object(int shapenum, int framenum, unsigned int tilex, 117 unsigned int tiley, unsigned int lft, 118 unsigned short itype, 119 unsigned char prob, short d1, short d2, short d3 = 0); 120 // Ctor. for fields: 121 Egg_object(int shapenum, int framenum, unsigned int tilex, 122 unsigned int tiley, unsigned int lft, 123 unsigned char ty); 124 ~Egg_object() override; 125 virtual void set_area(); // Set up active area. get_distance()126 int get_distance() const { 127 return distance; 128 } get_criteria()129 int get_criteria() const { 130 return criteria; 131 } get_type()132 int get_type() const { 133 return type; 134 } get_str1()135 virtual const char *get_str1() const { 136 return ""; 137 } set_str1(const char * s)138 virtual void set_str1(const char *s) { 139 ignore_unused_variable_warning(s); 140 } 141 // Can this be clicked on? 142 bool is_findable() override; 143 virtual void set(int crit, int dist); 144 // Can it be activated? 145 virtual bool is_active(Game_object *obj, 146 int tx, int ty, int tz, int from_tx, int from_ty); 147 get_area()148 TileRect get_area() const { // Get active area. 149 return area; 150 } is_solid_area()151 int is_solid_area() const { 152 return solid_area; 153 } 154 void set_animator(Animator *a); 155 void stop_animation(); 156 void paint() override; 157 // Run usecode function. 158 void activate(int event = 1) override; 159 bool edit() override; // Edit in ExultStudio. 160 // Saved from ExultStudio. 161 static void update_from_studio(unsigned char *data, int datalen); hatch_now(Game_object * obj,bool must)162 virtual void hatch_now(Game_object *obj, bool must) { 163 ignore_unused_variable_warning(obj, must); 164 } 165 virtual void hatch(Game_object *obj, bool must = false); 166 void print_debug(); 167 static void set_weather(int weather, int len = 15, 168 Game_object *egg = nullptr); 169 // Move to new abs. location. 170 void move(int newtx, int newty, int newlift, int newmap = -1) override; 171 // Remove/delete this object. 172 void remove_this(Game_object_shared *keep = nullptr) override; is_egg()173 int is_egg() const override { // An egg? 174 return 1; 175 } 176 // Write out to IREG file. 177 void write_ireg(ODataSource *out) override; 178 // Get size of IREG. Returns -1 if can't write to buffer 179 int get_ireg_size() override; 180 reset()181 virtual void reset() { 182 flags &= ~(1 << hatched); 183 } 184 as_egg()185 Egg_object *as_egg() override { 186 return this; 187 } 188 189 }; 190 191 /* 192 * Fields are activated like eggs. 193 */ 194 195 class Field_object : public Egg_object { 196 bool field_effect(Actor *actor);// Apply field. 197 public: 198 Field_object(int shapenum, int framenum, unsigned int tilex, 199 unsigned int tiley, unsigned int lft, unsigned char ty); 200 void paint() override; 201 // Run usecode function. 202 void activate(int event = 1) override; 203 void hatch(Game_object *obj, bool must = false) override; 204 // Write out to IREG file. 205 void write_ireg(ODataSource *out) override; 206 // Get size of IREG. Returns -1 if can't write to buffer 207 int get_ireg_size() override; is_findable()208 bool is_findable() override { 209 return Ireg_game_object::is_findable(); 210 } edit()211 bool edit() override { 212 return Ireg_game_object::edit(); 213 } update_from_studio(unsigned char * data,int datalen)214 static void update_from_studio(unsigned char *data, int datalen) { 215 Ireg_game_object::update_from_studio(data, datalen); 216 } 217 }; 218 219 /* 220 * Mirrors are handled like eggs. 221 */ 222 223 class Mirror_object : public Egg_object { 224 public: 225 Mirror_object(int shapenum, int framenum, unsigned int tilex, 226 unsigned int tiley, unsigned int lft); 227 228 // Run usecode function. 229 void activate(int event = 1) override; 230 void hatch(Game_object *obj, bool must = false) override; 231 232 // Can it be activated? 233 bool is_active(Game_object *obj, 234 int tx, int ty, int tz, int from_tx, int from_ty) override; 235 236 void set_area() override; // Set up active area. 237 238 // Render. 239 void paint() override; 240 // Can this be clicked on? is_findable()241 bool is_findable() override { 242 return Ireg_game_object::is_findable(); 243 } 244 245 void write_ireg(ODataSource *out) override; 246 // Get size of IREG. Returns -1 if can't write to buffer 247 int get_ireg_size() override; edit()248 bool edit() override { 249 return Ireg_game_object::edit(); 250 } update_from_studio(unsigned char * data,int datalen)251 static void update_from_studio(unsigned char *data, int datalen) { 252 Ireg_game_object::update_from_studio(data, datalen); 253 } 254 }; 255 #endif 256