ScummVM API documentation
u6_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_U6_USECODE_H
23 #define NUVIE_USECODE_U6_USECODE_H
24 
25 #include "ultima/nuvie/core/obj_manager.h"
26 #include "ultima/nuvie/core/timed_event.h"
27 #include "ultima/nuvie/usecode/usecode.h"
28 //object numbers
29 #include "ultima/nuvie/core/u6_objects.h"
30 
31 namespace Ultima {
32 namespace Nuvie {
33 
34 #define U6_LORD_BRITISH_ACTOR_NUM 5 /*change to U6_NPC_LORD_BRITISH?*/
35 #define U6_SHERRY_ACTOR_NUM 9
36 #define U6_BEHLEM_ACTOR_NUM 164
37 
38 #define U6_LORD_BRITISH_ORB_CHECK_FLAG 0x20 // this is set if the player has asked LB about the orb of moons
39 
40 class U6UseCode;
41 class CallBack;
42 class Configuration;
43 class MsgScroll;
44 
45 // U6ObjectType properties
46 #define OBJTYPE_NONE 0x0000
47 #define OBJTYPE_FOOD 0x0001 /* food or drink */
48 #define OBJTYPE_CONTAINER 0x0002 /* must be set on empty bag,crate,backpack */
49 #define OBJTYPE_BOOK 0x0004 /* has book data (signs, paintings, books) */
50 
51 #define TORCH_LIGHT_LEVEL 3
52 
53 struct U6ObjectType { // object properties & usecode
54  bool (U6UseCode::*usefunc)(Obj *, UseCodeEvent); // usecode function
55  uint16 obj_n; // type
56  uint8 frame_n; // 0xFF matches any frame
57  uint8 dist; // distance to trigger (depends on event, usually 0)
58  UseCodeEvent trigger; // accepted event(s)
59  uint16 flags; // properties (OBJTYPE)
60 };
61 
62 typedef enum {
63  LAT,
64  LON
65 } U6UseCodeLatLonEnum;
66 
67 class U6UseCode: public UseCode, public CallBack {
68 public:
69 
70  U6UseCode(Game *g, const Configuration *cfg);
71  ~U6UseCode() override;
72 
73  bool use_obj(Obj *obj, Actor *actor) override;
74  bool look_obj(Obj *obj, Actor *actor) override;
75  bool pass_obj(Obj *obj, Actor *actor, uint16 x, uint16 y) override;
76  bool search_obj(Obj *obj, Actor *actor) override;
77  bool move_obj(Obj *obj, sint16 rel_x, sint16 rel_y) override;
78  bool load_obj(Obj *obj) override;
79  bool message_obj(Obj *obj, CallbackMessage msg, void *msg_data) override;
80  bool ready_obj(Obj *obj, Actor *actor) override;
81  bool get_obj(Obj *obj, Actor *actor) override;
82  bool drop_obj(Obj *obj, Actor *actor, uint16 x, uint16 y, uint16 qty = 0) override;
83 
84  bool has_usecode(Obj *obj, UseCodeEvent ev = USE_EVENT_USE) override;
85  bool has_usecode(Actor *actor, UseCodeEvent ev = USE_EVENT_USE) override;
86  bool cannot_unready(const Obj *obj) const override;
87 
88  bool is_door(const Obj *obj) const {
89  return (obj->obj_n >= 297 && obj->obj_n <= 300);
90  }
91  bool is_unlocked_door(const Obj *obj) const override {
92  return (is_door(obj) && obj->frame_n != 9 && obj->frame_n != 11);
93  }
94  bool is_locked_door(const Obj *obj) const override {
95  return (is_door(obj) && (obj->frame_n == 9 || obj->frame_n == 11));
96  }
97  bool is_magically_locked_door(const Obj *obj) const {
98  return (is_door(obj) && (obj->frame_n == 13 || obj->frame_n == 15));
99  }
100  bool is_closed_door(const Obj *obj) const override {
101  return (is_door(obj) && obj->frame_n > 3);
102  }
103 
104  bool is_chest(const Obj *obj) const override {
105  return (obj->obj_n == OBJ_U6_CHEST);
106  }
107  bool is_closed_chest(const Obj *obj) const {
108  return (is_chest(obj) && obj->frame_n > 0);
109  }
110  bool is_locked_chest(const Obj *obj) const {
111  return (is_chest(obj) && obj->frame_n == 2);
112  }
113  bool is_magically_locked_chest(const Obj *obj) const {
114  return (is_chest(obj) && obj->frame_n == 3);
115  }
116  void unlock_chest(Obj *obj) {
117  if (is_locked_chest(obj)) obj->frame_n = 1;
118  return;
119  }
120  void lock_chest(Obj *obj) {
121  if (is_chest(obj) && obj->frame_n == 1) obj->frame_n = 2;
122  return;
123  }
124 
125  bool is_locked(const Obj *obj) const {
126  return (is_locked_door(obj) || is_locked_chest(obj));
127  }
128  bool is_magically_locked(const Obj *obj) const {
129  return (is_magically_locked_door(obj) || is_magically_locked_chest(obj));
130  }
131  void unlock(Obj *obj);
132  void lock(Obj *obj);
133 
134  bool is_food(const Obj *obj) const override;
135  bool is_container(const Obj *obj) const override;
136  bool is_container(uint16 obj_n, uint8 frame_n) const override;
137  bool is_readable(const Obj *obj) const override;
138 
139  uint16 callback(uint16 msg, CallBack *caller, void *data = nullptr) override;
140 
141 protected:
142  bool uc_event(const U6ObjectType *type, UseCodeEvent ev, Obj *obj);
143  inline const U6ObjectType *get_object_type(uint16 n, uint8 f, UseCodeEvent ev = 0) const;
144 
145 public:
146 // usecode
147  bool use_orb(Obj *obj, UseCodeEvent ev);
148  bool use_moonstone(Obj *obj, UseCodeEvent ev);
149  bool use_door(Obj *obj, UseCodeEvent ev);
150  bool use_secret_door(Obj *obj, UseCodeEvent ev);
151  bool use_ladder(Obj *obj, UseCodeEvent ev);
152  bool use_passthrough(Obj *obj, UseCodeEvent ev);
153  bool use_switch(Obj *obj, UseCodeEvent ev);
154  bool use_crank(Obj *obj, UseCodeEvent ev);
155  bool use_food(Obj *obj, UseCodeEvent ev);
156  bool use_firedevice(Obj *obj, UseCodeEvent ev);
157  bool use_fan(Obj *obj, UseCodeEvent ev);
158  bool use_sextant(Obj *obj, UseCodeEvent ev);
159  bool use_staff(Obj *obj, UseCodeEvent ev);
160  bool use_container(Obj *obj, UseCodeEvent ev);
161  bool use_rune(Obj *obj, UseCodeEvent ev);
162  bool use_vortex_cube(Obj *obj, UseCodeEvent ev);
163  bool use_key(Obj *obj, UseCodeEvent ev);
164  bool use_boat(Obj *obj, UseCodeEvent ev);
165  inline Obj *use_boat_find_center(Obj *obj);
166  inline bool use_boat_find_land(uint16 *x, uint16 *y, uint8 *z);
167  bool use_balloon_plans(Obj *obj, UseCodeEvent ev);
168  bool use_balloon(Obj *obj, UseCodeEvent ev);
169  bool use_cow(Obj *obj, UseCodeEvent ev);
170  bool use_well(Obj *obj, UseCodeEvent ev);
171  bool fill_bucket(uint16 filled_bucket_obj_n);
172  bool use_churn(Obj *obj, UseCodeEvent ev);
173  bool use_beehive(Obj *obj, UseCodeEvent ev);
174  bool use_horse(Obj *obj, UseCodeEvent ev);
175  bool use_potion(Obj *obj, UseCodeEvent ev);
176  bool use_bell(Obj *obj, UseCodeEvent ev);
177  bool use_fishing_pole(Obj *obj, UseCodeEvent ev);
178  bool use_shovel(Obj *obj, UseCodeEvent ev);
179  bool use_fountain(Obj *obj, UseCodeEvent ev);
180  bool use_rubber_ducky(Obj *obj, UseCodeEvent ev);
181  bool use_crystal_ball(Obj *obj, UseCodeEvent ev);
182  bool use_harpsichord(Obj *obj, UseCodeEvent ev);
183  bool play_instrument(Obj *obj, UseCodeEvent ev);
184  bool look_mirror(Obj *obj, UseCodeEvent ev);
185  bool look_sign(Obj *obj, UseCodeEvent ev);
186  bool look_clock(Obj *obj, UseCodeEvent ev);
187  bool pass_quest_barrier(Obj *obj, UseCodeEvent ev);
188  bool enter_dungeon(Obj *obj, UseCodeEvent ev);
189  bool enter_moongate(Obj *obj, UseCodeEvent ev);
190 // bool search_container(Obj *obj, UseCodeEvent ev);
191  bool use_powder_keg(Obj *obj, UseCodeEvent ev);
192  bool use_cannon(Obj *obj, UseCodeEvent ev);
193  bool use_egg(Obj *obj, UseCodeEvent ev);
194  bool sundial(Obj *obj, UseCodeEvent ev);
195  bool torch(Obj *obj, UseCodeEvent ev);
196  bool use_spellbook(Obj *obj, UseCodeEvent ev);
197  bool use_peer_gem(Obj *obj, UseCodeEvent ev);
198  bool magic_ring(Obj *obj, UseCodeEvent ev);
199  bool storm_cloak(Obj *obj, UseCodeEvent ev);
200  bool amulet_of_submission(Obj *obj, UseCodeEvent ev);
201  bool gargish_vocabulary(Obj *obj, UseCodeEvent ev);
202  bool holy_flame(Obj *obj, UseCodeEvent ev);
203 
204 protected:
205 // supplementary
206  void remove_gargoyle_egg(uint16 x, uint16 y, uint8 z);
207  Obj *drawbridge_find(Obj *crank_obj);
208  void drawbridge_open(uint16 x, uint16 y, uint8 level, uint16 b_width);
209  void drawbridge_close(uint16 x, uint16 y, uint8 level, uint16 b_width);
210  void drawbridge_remove(uint16 x, uint16 y, uint8 level, uint16 *bridge_width);
211  bool use_firedevice_message(Obj *obj, bool lit);
212  void lock_door(Obj *obj);
213  void unlock_door(Obj *obj);
214  Obj *bell_find(Obj *chain_obj);
215  void sundial_set_shadow(Obj *sundial, uint8 hour);
216  void extinguish_torch(Obj *obj);
217  void light_torch(Obj *obj);
218  bool process_effects(Obj *container_obj, Actor *actor) override;
219  sint16 parseLatLongString(U6UseCodeLatLonEnum mode, Std::string *input);
220 
221  inline bool use_find_water(uint16 *x, uint16 *y, uint8 *z);
222  inline bool lock_pick_dex_check();
223 };
224 
225 } // End of namespace Nuvie
226 } // End of namespace Ultima
227 
228 #endif
Definition: actor.h:178
Definition: obj.h:84
Definition: configuration.h:61
Definition: usecode.h:151
Definition: u6_usecode.h:53
Definition: detection.h:27
Definition: call_back.h:50
Definition: string.h:30
Definition: u6_usecode.h:67
Definition: game.h:73