Added reload of levels on F7 (Update levelpack) to ease the test of changes.
[enigmagame.git] / src / items.hh
blobe59c0bf8de2f8e06dccad488a180a3b79784e7f8
1 /*
2 * Copyright (C) 2002,2003,2004 Daniel Heck
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef ITEMS_HH_INCLUDED
20 #define ITEMS_HH_INCLUDED
22 #include "GridObject.hh"
24 namespace enigma {
26 enum ItemID {
27 it_INVALID = -1,
28 it_FIRST = 0,
29 it_none = 0,
30 it_1pkillstone,
31 it_2pkillstone,
32 it_bag,
33 it_banana,
34 it_bomb,
35 it_bomb_burning,
36 it_blocker,
37 it_bottle_idle,
38 it_bottle_broken,
39 it_brake,
40 it_bridge_oxyd,
41 it_bridge_oxyd_active,
42 it_brush,
43 it_burnable_invisible,
44 it_burnable_fireproof,
45 it_burnable_ignited,
46 it_burnable_burning,
47 it_burnable_ash,
48 it_burnable_oil,
49 it_cherry,
50 it_cherry_crushed,
51 it_coffee,
52 it_coin_s,
53 it_coin_m,
54 it_coin_l,
55 it_crack_i,
56 it_crack_s,
57 it_crack_m,
58 it_crack_l,
59 it_cross,
60 it_death,
61 it_debris,
62 it_debris_water,
63 it_document,
64 it_drop,
65 it_dynamite,
66 it_dummy,
67 it_easykeepstone,
68 it_easykillstone,
69 it_explosion_nil,
70 it_explosion_hollow,
71 it_explosion_crack,
72 it_explosion_debris,
73 it_exitsensor,
74 it_extinguisher,
75 it_extinguisher_medium,
76 it_extinguisher_empty,
77 it_extralife,
78 it_flag_black,
79 it_flag_white,
80 it_floppy,
81 it_glasses,
82 it_glasses_broken,
83 it_hammer,
84 it_hill,
85 it_hollow,
86 it_hstrip,
87 it_key,
88 it_landmine,
89 it_laserbeam,
90 it_magicwand,
91 it_magnet_off,
92 it_magnet_on,
93 it_meditation_caldera,
94 it_meditation_hollow,
95 it_meditation_dent,
96 it_meditation_bump,
97 it_meditation_hill,
98 it_meditation_volcano,
99 it_odometer,
100 it_pencil,
101 it_pin,
102 it_pipe_e, it_pipe_w, it_pipe_s, it_pipe_n,
103 it_pipe_es, it_pipe_ne, it_pipe_sw, it_pipe_nw,
104 it_pipe_ew, it_pipe_ns,
105 it_puller_n,
106 it_puller_e,
107 it_puller_s,
108 it_puller_w,
109 it_ring,
110 it_rubberband,
111 it_seed_wood,
112 it_seed_fake,
113 it_seed_volcano,
114 it_seed_hay,
115 it_sensor,
116 it_shogun_s,
117 it_shogun_m,
118 it_shogun_l,
119 it_signalfilter0,
120 it_signalfilter1,
121 it_spade,
122 it_spoon,
123 it_spring_keep,
124 it_spring_drop,
125 it_springboard,
126 it_squashed,
127 it_strip,
128 it_strip_w,
129 it_strip_s,
130 it_strip_sw,
131 it_strip_e,
132 it_strip_ew,
133 it_strip_es,
134 it_strip_esw,
135 it_strip_n,
136 it_strip_nw,
137 it_strip_ns,
138 it_strip_nsw,
139 it_strip_ne,
140 it_strip_new,
141 it_strip_nes,
142 it_strip_nesw,
143 it_surprise,
144 it_sword,
145 it_tinyhill,
146 it_tinyhollow,
147 it_trap,
148 it_trigger,
149 it_umbrella,
150 it_vortex_open,
151 it_vortex_closed,
152 it_vstrip,
153 it_weight,
154 it_wormhole_off,
155 it_wormhole_on,
156 it_wrench,
157 it_yinyang,
158 // for DAT compatibility only
159 it_inversesensor,
160 it_LAST,
161 it_COUNT
164 /*! What may happen to an item _after_ it was activated? */
165 enum ItemAction {
166 ITEM_DROP, //!< Drop it to the floor
167 ITEM_KILL, //!< Remove it from the inventory and dispose it
168 ITEM_KEEP, //!< Keep it in the inventory; do nothing further
171 enum ItemFlags {
172 itf_none = 0,
173 itf_static = 1, //!< Cannot be picked up - not liftable
174 itf_indestructible = 2, //!< Non standard handling of explosions - may well be destructible!
175 itf_animation = 4, //!< Use set_anim() instead of set_model()
176 itf_invisible = 8, //!< Item has no visible model
177 itf_inflammable = 16, //!< Burns when hit by laser beam
178 itf_norespawn = 32, //!< Don't respawn balls on top of this item
179 itf_fireproof = 64, //!< This item can't burn by fire
180 itf_portable = 128, //!< This static item can be added to the inventory
181 itf_freezable = 256, //!< This static item can be frozen and carried by an st_ice
184 struct ItemTraits {
185 const char *name; //!< Name of the item, e.g., "it-hammer"
186 ItemID id;
187 int flags; //!< Combination of ItemFlags
188 float radius; //!< Radius, 0.0 = default
191 class Stone;
192 class Item : public GridObject {
193 public:
194 Item();
196 /* ---------- Public methods ---------- */
197 void kill();
198 void replace(std::string kind);
200 /* ---------- Virtual functions ---------- */
201 virtual std::string getClass() const;
202 virtual Value getAttr(const std::string &key) const;
204 void init_model();
205 virtual void processLight(Direction d);
206 virtual double getFriction(ecl::V2 pos, double defaultFriction, Actor *a);
207 virtual ecl::V2 calcMouseforce(Actor *a, ecl::V2 mouseForce, ecl::V2 floorForce);
209 /* ---------- Item interface ---------- */
211 virtual Item *clone() = 0;
213 virtual const ItemTraits &get_traits() const = 0;
215 virtual bool isStatic() const; // not liftable
216 virtual bool isPortable() const;
217 virtual bool isFreezable() const;
219 /*! Return true if item completely covers the floor. In this
220 case the Floor::actor_contact() will not be called
221 automatically; this must be done from `Item::actor_hit' (if
222 at all). */
223 virtual bool covers_floor(ecl::V2 pos, Actor *a) const { return false; }
225 /*! Return the force an item exerts on actor `a'. This is
226 used by sloped and hills for force fields that are local to
227 the current field. For global force fields you have to
228 register a ForceField in the world. */
229 virtual void add_force(Actor *a, ecl::V2 &f);
231 virtual bool can_drop_at(GridPos p);
233 virtual void drop(Actor *a, GridPos p);
235 /*! Called when item is dropped by actor `a' */
236 virtual void on_drop(Actor *a);
238 /*! Called when item is picked up by actor `a' */
239 virtual void on_pickup(Actor *a);
241 /*! Called when stone above item changes. */
242 virtual void stone_change(Stone *st);
244 /*! Called when item is ``hit'' by a moving stone. */
245 virtual void on_stonehit(Stone *st);
247 /*! Called when item is ``hit'' by an actor. Return true if
248 the item should be picked up. */
249 virtual bool actor_hit(Actor *a);
251 /*! The model used for displaying this item in an
252 inventory. */
253 virtual std::string get_inventory_model();
255 /* Called when item is activated by the owner of `a'. */
256 virtual ItemAction activate(Actor* a, GridPos p);
258 virtual std::list<GridPos> warpSpreadPos(bool isWater);
259 protected:
260 virtual Object::ObjectType getObjectType() const {return Object::ITEM;}
262 // GridObject interface
263 virtual void set_model (const std::string &mname) {
264 display::SetModel(GridLoc(GRID_ITEMS, get_pos()), mname);
267 virtual display::Model *get_model () {
268 return display::GetModel(GridLoc(GRID_ITEMS, get_pos()));
271 virtual void kill_model (GridPos p) {
272 display::KillModel (GridLoc (GRID_ITEMS, p));
274 void transform(std::string kind);
275 // replace template method hook
276 virtual void setup_successor(Item *newitem) {}
279 /* -------------------- Inline functions -------------------- */
281 /*! Return unique item type identifier. */
282 inline ItemID get_id (Item *it) {
283 if (it)
284 return it->get_traits().id;
285 return it_none;
288 inline bool has_flags (Item *it, ItemFlags flags) {
289 return (it->get_traits().flags & flags) == flags;
292 /* -------------------- Functions -------------------- */
295 /* -------------------- Item Macros -------------------- */
297 #define DEF_ITEM(classname, kindname, kindid) \
298 class classname : public Item { \
299 CLONEOBJ(classname); \
300 DECL_ITEMTRAITS; \
301 public: \
302 classname() {} \
303 }; \
304 DEF_ITEMTRAITS(classname, kindname, kindid)
306 #define DEF_ITEMF(classname, kindname, kindid, flags) \
307 class classname : public Item { \
308 CLONEOBJ(classname); \
309 DECL_ITEMTRAITS; \
310 public: \
311 classname() {} \
312 }; \
313 DEF_ITEMTRAITSF(classname, kindname, kindid, flags)
315 #define DECL_ITEMTRAITS \
316 static ItemTraits traits; \
317 const ItemTraits &get_traits() const { return traits; }
319 #define DECL_ITEMTRAITS_ARRAY(n, subtype_expr) \
320 static ItemTraits traits[n]; \
321 const ItemTraits &get_traits() const { return traits[subtype_expr]; }
323 #define DEF_ITEMTRAITS(classname, name, id) \
324 ItemTraits classname::traits = { name, id, itf_none, 0.0 }
326 #define DEF_ITEMTRAITSF(classname, name, id, flags) \
327 ItemTraits classname::traits = { name, id, flags, 0.0 }
329 #define DEF_ITEMTRAITSR(classname, name, id, radius) \
330 ItemTraits classname::traits = { name, id, 0, radius }
332 } // namespace enigma
334 #endif