ScummVM API documentation
usecode.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_USECODE_USECODE_H
23 #define NUVIE_USECODE_USECODE_H
24 
25 #include "ultima/shared/std/string.h"
26 #include "ultima/nuvie/misc/call_back.h"
27 #include "ultima/nuvie/misc/map_entity.h"
28 #include "ultima/nuvie/core/obj_manager.h"
29 #include "ultima/nuvie/core/player.h"
30 
31 namespace Ultima {
32 namespace Nuvie {
33 
34 // The game triggers one of these events on an object to activate its UseCode
35 // function(s). The return value meaning is different for each event.
36 #define USE_EVENT_USE 0x01 /* return value undefined */
37 #define USE_EVENT_LOOK 0x02 /* true: allow search, false: disallow search */
38 #define USE_EVENT_PASS 0x04 /* true: do normal move, false: object blocks */
39 #define USE_EVENT_MESSAGE 0x08 /* internal message or data return */
40 #define USE_EVENT_SEARCH 0x10 /*undefined (true = had objects?); might remove*/
41 //#define USE_EVENT_ON 0x20 /* post-move/idle */
42 #define USE_EVENT_MOVE 0x40 /* true: move object, false: don't move object */
43 #define USE_EVENT_LOAD 0x80 /* return value undefined */
44 #define USE_EVENT_READY 0x0100 /* true: object may be equipped */
45 #define USE_EVENT_GET 0x0200 /* true: do normal get */
46 #define USE_EVENT_DROP 0x0400 /* true: do normal drop */
47 #define USE_EVENT_INPUT_CANCEL 0x501 /* note this shares a bit with USE_EVENT_USE so it can pass through uc_event(). return undefined */
48 //#define USE_EVENT_NEAR 0x00 /* mirrors; might use ON with distance val */
49 //#define USE_EVENT_ATTACK 0x00 /* doors, chests, mirrors */
50 //#define USE_EVENT_ENTER 0x00 /* object enters view (clocks) */
51 //#define USE_EVENT_LEAVE 0x00 /* object leaves view */
52 
53 typedef uint16 UseCodeEvent;
54 
55 /* Events:
56  * USE
57  * Returns: undefined
58  * Use the object.
59  * actor_ref - the actor using it (the player actor typically)
60  *
61  * PASS (Quest Barrier)
62  * Returns: True if actor may move, False if object blocks
63  * Called when an actor attempts to step onto an object.
64  * actor_ref - actor trying to pass
65  * mapcoord_ref - location the actor is trying to pass (for multi-tile objects)
66  *
67  * LOOK (signs)
68  * Returns: True if an object can be searched
69  * Called when someone looks at the object. Some objects aren't searched (books
70  * for example) and should return false.
71  *
72  * MESSAGE (fumaroles, earthquakes?, powder kegs, clocks)
73  * An internal event from the engine. It must have been previously requested.
74  * Includes TIMED events, and DATA returns. Be careful that the object still
75  * exists.
76  *
77  * MOVE (cannons)
78  * Returns: True to push object to the new position
79  * Use this to perform special move functions for some objects. A cannon can be
80  * aimed with MOVE.
81  * mapcoord_ref - target location
82  *
83  * (UN)LOAD unimplemented (fumaroles)
84  * Returns: undefined
85  * Called when the object is cached in or out (or when it would have been in the
86  * original game... about 16 to 32 spaces away), and when new objects are created.
87  * It can be used to start timers, or to hatch eggs.
88  *
89  * Actor NEAR unimplemented (mirrors)
90  * Set something to happen when an actor moves close to or away from object.
91  * Distance will be used.
92  *
93  * Actor ON (chairs, traps) unimplemented
94  * Returns: undefined
95  * Called each turn for any objects in the view-area with actors standing on
96  * them.
97  *
98  * ENTER view-area unimplemented
99  *
100  * LEAVE view-area unimplemented
101  * Enter and leave will be used to start and stop sound effects. Distance will
102  * be used.
103  *
104  * (UN)READY (Amulet of Submission)
105  * Returns: True if the object may be worn, or removed
106  * This is called before the object is is equipped or removed. Check the
107  * object's flags to determine if it is being equipped or not. (if its readied
108  * flag is set it is being removed). Special un/ready functions can be created
109  * with this.
110  * actor_ref - the actor un/readying it
111  *
112  * ATTACK (doors, chests)
113  *
114  * DROP (breakables, torches)
115  * Returns: True to allow normal drop at the target.
116  * Special drop functions can be created with this.
117  * actor_ref - the actor dropping it
118  * mapcoord_ref - the desired drop target
119  *
120  * GET (torches, runes?)
121  * Returns: True if the actor can get the object.
122  * Special get functions can be created with this.
123  * actor_ref - the actor getting it
124  *
125  * SEARCH (graves, secret doors)
126  * Returns: True if the object contained other objects.
127  * FIXME: might remove this and add as a player action
128  *
129  */
130 
131 typedef enum {
132  USE,
133  GET,
134  MOVE
135 } UseCodeType;
136 
137 const char *useCodeTypeToString(UseCodeType type);
138 
139 class ActorManager;
140 class Configuration;
141 class Events;
142 class Game;
143 class Map;
144 class MsgScroll;
145 class MapCoord;
146 class Party;
147 class Player;
148 class Script;
149 class ScriptThread;
150 
151 class UseCode {
152 private:
153  ScriptThread *script_thread;
154 
155 protected:
156  Game *game;
157  const Configuration *config;
158  ObjManager *obj_manager;
159  Map *map;
160  Player *player;
161  MsgScroll *scroll;
162  ActorManager *actor_manager;
163  Party *party;
164  Script *script;
165 
166 // pass parameters to usecode functions via items (nullptr itemref is unset)
167  struct {
168  uint32 *uint_ref;
169  sint32 *sint_ref;
170  Obj *obj_ref;
171  Actor *actor_ref, *actor2_ref;
172  MapCoord *mapcoord_ref;
173  CallbackMessage *msg_ref;
174  Std::string *string_ref;
175  MapEntity *ent_ref;
176  char *data_ref;
177  } items;
178  void clear_items();
179 
180 public:
181 
182  UseCode(Game *g, const Configuration *cfg);
183  virtual ~UseCode();
184 
185  virtual bool init(ObjManager *om, Map *m, Player *p, MsgScroll *ms);
186 
187  bool use_obj(uint16 x, uint16 y, uint8 z, Obj *src_obj = nullptr);
188  bool use_obj(Obj *obj, Obj *src_obj = nullptr) {
189  return (use_obj(obj, player->get_actor())); // ??
190  }
191 
192  virtual bool use_obj(Obj *obj, Actor *actor);
193  virtual bool look_obj(Obj *obj, Actor *actor) {
194  return false;
195  }
196  virtual bool pass_obj(Obj *obj, Actor *actor, uint16 x, uint16 y) {
197  return false;
198  }
199  virtual bool search_obj(Obj *obj, Actor *actor) {
200  return false;
201  }
202  virtual bool move_obj(Obj *obj, sint16 rel_x, sint16 rel_y);
203  virtual bool load_obj(Obj *obj) {
204  return false;
205  }
206  virtual bool message_obj(Obj *obj, CallbackMessage msg, void *msg_data) {
207  return false;
208  }
209  virtual bool ready_obj(Obj *obj, Actor *actor);
210  virtual bool get_obj(Obj *obj, Actor *actor) {
211  return false;
212  }
213  virtual bool drop_obj(Obj *obj, Actor *actor, uint16 x, uint16 y, uint16 qty = 0) {
214  return false;
215  }
216 
217  virtual bool has_usecode(Obj *obj, UseCodeEvent ev = USE_EVENT_USE);
218  virtual bool has_usecode(Actor *actor, UseCodeEvent ev = USE_EVENT_USE) {
219  return false;
220  }
221  virtual bool has_lookcode(Obj *obj) {
222  return has_usecode(obj, USE_EVENT_LOOK);
223  }
224  virtual bool has_passcode(Obj *obj) {
225  return has_usecode(obj, USE_EVENT_PASS);
226  }
227  virtual bool has_movecode(Obj *obj) {
228  return has_usecode(obj, USE_EVENT_MOVE);
229  }
230  virtual bool has_loadcode(Obj *obj) {
231  return has_usecode(obj, USE_EVENT_LOAD);
232  }
233  virtual bool has_readycode(Obj *obj) {
234  return has_usecode(obj, USE_EVENT_READY);
235  }
236  virtual bool cannot_unready(const Obj *obj) const {
237  return false;
238  }
239  virtual bool has_getcode(Obj *obj) {
240  return has_usecode(obj, USE_EVENT_GET);
241  }
242  virtual bool has_dropcode(Obj *obj) {
243  return has_usecode(obj, USE_EVENT_DROP);
244  }
245 
246  bool is_door(const Obj *obj) const {
247  return (is_locked_door(obj) || is_unlocked_door(obj));
248  }
249  virtual bool is_locked_door(const Obj *obj) const {
250  return false;
251  }
252  virtual bool is_unlocked_door(const Obj *obj) const {
253  return false;
254  }
255  virtual bool is_closed_door(const Obj *obj) const {
256  return false;
257  }
258  virtual bool process_effects(Obj *container_obj, Actor *actor) {
259  return false;
260  }
261  virtual bool is_food(const Obj *obj) const {
262  return false;
263  }
264  virtual bool is_container(const Obj *obj) const;
265  virtual bool is_container(uint16 obj_n, uint8 frame_n) const {
266  return false;
267  }
268  virtual bool is_readable(const Obj *obj) const {
269  return false;
270  }
271  virtual bool is_chest(const Obj *obj) const {
272  return false;
273  }
274 
275  void set_itemref(sint32 *val) {
276  items.sint_ref = val;
277  }
278  void set_itemref(Obj *val) {
279  items.obj_ref = val;
280  }
281  void set_itemref(Actor *val, Actor *val2 = nullptr) {
282  items.actor_ref = val;
283  items.actor2_ref = val2;
284  }
285  void set_itemref(MapCoord *val) {
286  items.mapcoord_ref = val;
287  }
288 
289  Obj *get_obj_from_container(Obj *obj);
290  bool search_container(Obj *obj, bool show_string = true);
291  Obj *destroy_obj(Obj *obj, uint32 count = 0, bool run_usecode = true);
292  bool out_of_use_range(Obj *obj, bool check_enemies);
293 
294  ScriptThread *get_running_script();
295  bool is_script_running();
296 
297 protected:
298 
299  void toggle_frame(Obj *obj);
300  void dbg_print_event(UseCodeEvent event, Obj *obj);
301 
302 };
303 
304 } // End of namespace Nuvie
305 } // End of namespace Ultima
306 
307 #endif
Definition: actor.h:178
Definition: msg_scroll.h:93
Definition: obj.h:84
Definition: configuration.h:61
Definition: usecode.h:151
Definition: map.h:147
Definition: player.h:41
Definition: party.h:92
Definition: actor_manager.h:42
Definition: detection.h:27
Definition: map_entity.h:45
Definition: string.h:30
Definition: map.h:84
Definition: script.h:102
Definition: obj_manager.h:75
Definition: script.h:59
Definition: game.h:73