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.
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"
41 it_bridge_oxyd_active
,
43 it_burnable_invisible
,
44 it_burnable_fireproof
,
75 it_extinguisher_medium
,
76 it_extinguisher_empty
,
93 it_meditation_caldera
,
98 it_meditation_volcano
,
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
,
158 // for DAT compatibility only
164 /*! What may happen to an item _after_ it was activated? */
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
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
185 const char *name
; //!< Name of the item, e.g., "it-hammer"
187 int flags
; //!< Combination of ItemFlags
188 float radius
; //!< Radius, 0.0 = default
192 class Item
: public GridObject
{
196 /* ---------- Public methods ---------- */
198 void replace(std::string kind
);
200 /* ---------- Virtual functions ---------- */
201 virtual std::string
getClass() const;
202 virtual Value
getAttr(const std::string
&key
) const;
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
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
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
);
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
) {
284 return it
->get_traits().id
;
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); \
304 DEF_ITEMTRAITS(classname, kindname, kindid)
306 #define DEF_ITEMF(classname, kindname, kindid, flags) \
307 class classname : public Item { \
308 CLONEOBJ(classname); \
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