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