ScummVM API documentation
obj_manager.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_CORE_OBJ_MANAGER_H
23 #define NUVIE_CORE_OBJ_MANAGER_H
24 
25 #include "ultima/shared/std/containers.h"
26 #include "ultima/nuvie/misc/iavl_tree.h"
27 #include "ultima/nuvie/core/tile_manager.h"
28 #include "ultima/nuvie/misc/u6_llist.h"
29 #include "ultima/nuvie/core/obj.h"
30 
31 namespace Ultima {
32 namespace Nuvie {
33 
34 //class U6LList;
35 class Configuration;
36 class EggManager;
37 class UseCode;
38 class NuvieIO;
39 class MapCoord;
40 class Actor;
41 
42 //is_passable return codes
43 #define OBJ_NO_OBJ 0
44 #define OBJ_NOT_PASSABLE 1
45 #define OBJ_PASSABLE 2
46 
47 #define OBJ_WEIGHT_INCLUDE_CONTAINER_ITEMS true
48 #define OBJ_WEIGHT_EXCLUDE_CONTAINER_ITEMS false
49 
50 #define OBJ_WEIGHT_DO_SCALE true
51 #define OBJ_WEIGHT_DONT_SCALE false
52 
53 #define OBJ_WEIGHT_EXCLUDE_QTY false
54 
55 #define OBJ_ADD_TOP true
56 
57 #define OBJ_SHOW_PREFIX true
58 
59 #define OBJ_TEMP_INIT 255 // this is used to stop temporary objects from being cleaned upon startup.
60 
61 #define OBJ_SEARCH_TOP true
62 #define OBJ_INCLUDE_IGNORED true
63 #define OBJ_EXCLUDE_IGNORED false
64 
65 struct ObjTreeNode {
66  iAVLKey key;
67  U6LList *obj_list;
68 };
69 
70 Obj *new_obj(uint16 obj_n, uint8 frame_n, uint16 x, uint16 y, uint16 z);
71 void delete_obj(Obj *obj);
72 
73 void clean_obj_tree_node(void *node);
74 
75 class ObjManager {
76  const Configuration *config;
77  int game_type;
78  EggManager *egg_manager;
79  TileManager *tile_manager;
80 //chunk object trees.
81  iAVLTree *surface[64];
82  iAVLTree *dungeon[5];
83 
84  uint16 obj_to_tile[1024]; //maps object number (index) to tile number.
85  uint8 obj_weight[1024];
86  uint8 obj_stackable[1024];
87  U6LList *actor_inventories[256];
88 
89  bool show_eggs;
90  uint16 egg_tile_num;
91 
92  UseCode *usecode;
93 
94  Std::list<Obj *> temp_obj_list;
95  Std::list<Obj *> tile_obj_list; // SE single instance 'map tile' objects
96  uint16 last_obj_blk_x, last_obj_blk_y;
97  uint8 last_obj_blk_z;
98 
99  uint16 obj_save_count;
100 
101  bool custom_actor_tiles;
102 
103 public:
104 
105  ObjManager(const Configuration *cfg, TileManager *tm, EggManager *em);
106  ~ObjManager();
107 
108  bool use_custom_actor_tiles() {
109  return custom_actor_tiles;
110  }
111  bool is_showing_eggs() {
112  return show_eggs;
113  }
114  void set_show_eggs(bool value) {
115  show_eggs = value;
116  }
117 
118  bool loadObjs();
119  bool load_super_chunk(NuvieIO *chunk_buf, uint8 level, uint8 chunk_offset);
120  void startObjs();
121  void clean();
122  void clean_actor_inventories();
123 
124  bool save_super_chunk(NuvieIO *save_buf, uint8 level, uint8 chunk_offset);
125  bool save_eggs(NuvieIO *save_buf);
126  bool save_inventories(NuvieIO *save_buf);
127  bool save_obj(NuvieIO *save_buf, Obj *obj, uint16 parent_objblk_n);
128 
129  void set_usecode(UseCode *uc) {
130  usecode = uc;
131  }
132  UseCode *get_usecode() {
133  return usecode;
134  }
135  EggManager *get_egg_manager() {
136  return egg_manager;
137  }
138 
139 //U6LList *get_obj_superchunk(uint16 x, uint16 y, uint8 level);
140  bool is_boundary(uint16 x, uint16 y, uint8 level, uint8 boundary_type = TILEFLAG_BOUNDARY, Obj *excluded_obj = nullptr);
141 //bool is_door(Obj * obj);
142  bool is_damaging(uint16 x, uint16 y, uint8 level);
143  uint8 is_passable(uint16 x, uint16 y, uint8 level);
144  bool is_forced_passable(uint16 x, uint16 y, uint8 level);
145  bool is_stackable(const Obj *obj) const;
146  bool is_breakable(const Obj *obj);
147  bool can_store_obj(const Obj *target, Obj *src) const; // Bag, open chest, spellbook.
148  bool can_get_obj(Obj *obj) const;
149  bool has_reduced_weight(uint16 obj_n) const;
150  bool has_reduced_weight(const Obj *obj) const {
151  return has_reduced_weight(obj->obj_n);
152  }
153  bool has_toptile(const Obj *obj) const;
154  bool obj_is_damaging(const Obj *obj, Actor *actor = nullptr); // if actor, it will damage and display text
155  bool is_door(uint16 x, uint16 y, uint8 level);
156 
157  U6LList *get_obj_list(uint16 x, uint16 y, uint8 level) const;
158 
159  Tile *get_obj_tile(uint16 obj_n, uint8 frame_n);
160  const Tile *get_obj_tile(uint16 x, uint16 y, uint8 level, bool top_obj = true);
161  const Tile *get_obj_dmg_tile(uint16 x, uint16 y, uint8 level);
162  Obj *get_obj(uint16 x, uint16 y, uint8 level, bool top_obj = OBJ_SEARCH_TOP, bool include_ignored_objects = OBJ_EXCLUDE_IGNORED, Obj *excluded_obj = nullptr);
163  Obj *get_obj_of_type_from_location_inc_multi_tile(uint16 obj_n, uint16 x, uint16 y, uint8 z);
164  Obj *get_obj_of_type_from_location_inc_multi_tile(uint16 obj_n, sint16 quality, sint32 qty, uint16 x, uint16 y, uint8 z);
165  Obj *get_obj_of_type_from_location(uint16 obj_n, uint16 x, uint16 y, uint8 z);
166  Obj *get_obj_of_type_from_location(uint16 obj_n, sint16 quality, sint32 qty, uint16 x, uint16 y, uint8 z);
167  Obj *get_objBasedAt(uint16 x, uint16 y, uint8 level, bool top_obj, bool include_ignored_objects = true, Obj *excluded_obj = nullptr);
168  Obj *get_tile_obj(uint16 obj_n);
169 
170  uint16 get_obj_tile_num(uint16 obj_num) const;
171  inline bool is_corpse(const Obj *obj) const;
172  uint16 get_obj_tile_num(const Obj *obj) const;
173  void set_obj_tile_num(uint16 obj_num, uint16 tile_num);
174 
175  U6LList *get_actor_inventory(uint16 actor_num);
176  bool actor_has_inventory(uint16 actor_num);
177 
178  Obj *find_next_obj(uint8 level, Obj *prev_obj, bool match_frame_n = OBJ_NOMATCH_FRAME_N, bool match_quality = OBJ_MATCH_QUALITY);
179  Obj *find_obj(uint8 level, uint16 obj_n, uint8 quality, bool match_quality = OBJ_MATCH_QUALITY, uint16 frame_n = 0, bool match_frame_n = OBJ_NOMATCH_FRAME_N, Obj **prev_obj = nullptr);
180 
181  bool move(Obj *obj, uint16 x, uint16 y, uint8 level);
182  bool add_obj(Obj *obj, bool addOnTop = false);
183  bool remove_obj_from_map(Obj *obj);
184  bool remove_obj_type_from_location(uint16 obj_n, uint16 x, uint16 y, uint8 z);
185 
186 
187  Obj *copy_obj(const Obj *obj);
188  const char *look_obj(Obj *obj, bool show_prefix = false);
189  Obj *get_obj_from_stack(Obj *obj, uint32 count);
190 
191  bool list_add_obj(U6LList *list, Obj *obj, bool stack_objects = true, uint32 pos = 0);
192 
193  const char *get_obj_name(Obj *obj);
194  const char *get_obj_name(uint16 obj_n);
195  const char *get_obj_name(uint16 obj_n, uint8 frame_n);
196 
197  float get_obj_weight(const Obj *obj, bool include_container_items = OBJ_WEIGHT_INCLUDE_CONTAINER_ITEMS, bool scale = true, bool include_qty = true) const;
198  uint8 get_obj_weight_unscaled(uint16 obj_n) const {
199  return obj_weight[obj_n];
200  }
201  float get_obj_weight(uint16 obj_n) const;
202 
203  void animate_forwards(Obj *obj, uint32 loop_count = 1);
204  void animate_backwards(Obj *obj, uint32 loop_count = 1);
205 
206  void update(uint16 x, uint16 y, uint8 z, bool teleport = false);
207 
208  bool unlink_from_engine(Obj *obj, bool run_usecode = true);
209 
210  bool moveto_map(Obj *obj, MapCoord location);
211  bool moveto_inventory(Obj *obj, uint16 actor_num);
212  bool moveto_inventory(Obj *obj, Actor *actor);
213  bool moveto_container(Obj *obj, Obj *container_obj, bool stack = true);
214 
215 protected:
216 
217  void remove_obj(Obj *obj);
218 
219  bool load_basetile();
220  bool load_weight_table();
221 
222 
223  bool addObjToContainer(U6LList *list, Obj *obj);
224  Obj *loadObj(NuvieIO *buf);
225  iAVLTree *get_obj_tree(uint16 x, uint16 y, uint8 level) const;
226 
227  iAVLKey get_obj_tree_key(Obj *obj) const;
228  iAVLKey get_obj_tree_key(uint16 x, uint16 y, uint8 level) const;
229 //inline U6LList *ObjManager::get_schunk_list(uint16 x, uint16 y, uint8 level);
230 
231  bool temp_obj_list_add(Obj *obj);
232  bool temp_obj_list_remove(Obj *obj);
233  void temp_obj_list_clean_level(uint8 z);
234  void temp_obj_list_clean_area(uint16 x, uint16 y);
235 
236  void remove_temp_obj(Obj *tmp_obj);
237 
238  inline Obj *find_obj_in_tree(uint16 obj_n, uint8 quality, bool match_quality, uint8 frame_n, bool match_frame_n, Obj **prev_obj, iAVLTree *obj_tree);
239  inline void start_obj_usecode(iAVLTree *obj_tree);
240  inline void print_egg_tree(iAVLTree *obj_tree);
241 
242 public:
243  void print_object_list();
244  void print_egg_list();
245  void print_obj(const Obj *obj, bool in_container, uint8 indent = 0);
246 };
247 
248 } // End of namespace Nuvie
249 } // End of namespace Ultima
250 
251 #endif
Definition: iavl_tree.h:50
Definition: actor.h:178
Definition: egg_manager.h:45
Definition: obj.h:84
Definition: configuration.h:61
Definition: usecode.h:151
Definition: list.h:39
Definition: tile_manager.h:145
Definition: detection.h:27
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: iavl_tree.h:31
Definition: u6_llist.h:46
Definition: map.h:84
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
Definition: containers.h:200
Definition: obj_manager.h:75
Definition: tile_manager.h:113
Definition: obj_manager.h:65
Definition: nuvie_io.h:32