ScummVM API documentation
obj.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_H
23 #define NUVIE_CORE_OBJ_H
24 
25 #include "ultima/nuvie/core/nuvie_defs.h"
26 #include "ultima/nuvie/misc/u6_llist.h"
27 
28 namespace Ultima {
29 namespace Nuvie {
30 
31 class Actor;
32 
33 #define NO_OBJ_STATUS 0
34 
35 // obj status bit flags
36 #define OBJ_STATUS_OK_TO_TAKE 0x1
37 //#define OBJ_STATUS_SEEN_EGG 0x2 // something to do with eggs <- not sure about this one.
38 #define OBJ_STATUS_INVISIBLE 0x2 // I think this is correct
39 #define OBJ_STATUS_CHARMED 0x4 // objlist.txt says 'charmed'
40 
41 
42 // position: A 2 bit field, so can't use plain | to check / |= to set these.
43 // FIXME: check to make sure we don't do this anywhere anymore
44 #define OBJ_STATUS_ON_MAP 0x0
45 #define OBJ_STATUS_IN_CONTAINER 0x8
46 #define OBJ_STATUS_IN_INVENTORY 0x10
47 #define OBJ_STATUS_READIED 0x18
48 #define OBJ_STATUS_MASK_GET 0x18
49 #define OBJ_STATUS_MASK_SET 0xE7
50 
51 #define OBJ_STATUS_TEMPORARY 0x20
52 #define OBJ_STATUS_EGG_ACTIVE 0x40 // something to do with eggs
53 #define OBJ_STATUS_BROKEN 0x40
54 #define OBJ_STATUS_MUTANT 0x40
55 #define OBJ_STATUS_CURSED 0x40
56 #define OBJ_STATUS_LIT 0x80
57 
58 
59 //first 3 bits of nuvie_status code object location
60 //in the nuvie engine.
61 
62 //Nuvie engine obj locations
63 #define OBJ_LOC_NONE 0
64 #define OBJ_LOC_INV 1
65 #define OBJ_LOC_MAP 2
66 #define OBJ_LOC_READIED 3
67 #define OBJ_LOC_CONT 4
68 
69 #define NUVIE_OBJ_STATUS_LOC_MASK_GET 0x7
70 #define NUVIE_OBJ_STATUS_LOC_MASK_SET 0xf8
71 
72 #define NUVIE_OBJ_STATUS_SCRIPTING 0x8
73 #define NUVIE_OBJ_STATUS_ACTOR_OBJ 0x10
74 
75 #define OBJ_MATCH_QUALITY true
76 #define OBJ_NOMATCH_QUALITY false
77 
78 #define OBJ_MATCH_FRAME_N true
79 #define OBJ_NOMATCH_FRAME_N false
80 
81 //We use this in Obj::is_in_inventory()
82 #define OBJ_DONT_CHECK_PARENT false
83 
84 class Obj {
85  uint8 nuvie_status;
86 
87 public:
88  //uint16 objblk_n;
89 
90  uint16 obj_n;
91  uint8 frame_n;
92  uint8 status;
93  uint16 x;
94  uint16 y;
95  uint8 z;
96 
97  uint16 qty;
98  uint8 quality;
99  void *parent; //either an Obj pointer or an Actor pointer depending on engine_loc.
100  U6LList *container;
101 
102 public:
103  Obj();
104  Obj(Obj *sobj);
105 
106  bool is_script_obj() const {
107  return (nuvie_status & NUVIE_OBJ_STATUS_SCRIPTING);
108  }
109  bool is_actor_obj() const {
110  return (nuvie_status & NUVIE_OBJ_STATUS_ACTOR_OBJ);
111  }
112 
113  bool is_ok_to_take() const;
114  bool is_invisible() const {
115  return (status & OBJ_STATUS_INVISIBLE);
116  }
117  bool is_charmed() const {
118  return (status & OBJ_STATUS_CHARMED);
119  }
120  bool is_temporary() const {
121  return (status & OBJ_STATUS_TEMPORARY);
122  }
123  bool is_egg_active() const {
124  return (status & OBJ_STATUS_EGG_ACTIVE);
125  }
126  bool is_broken() const {
127  return (status & OBJ_STATUS_BROKEN);
128  }
129  bool is_mutant() const {
130  return (status & OBJ_STATUS_MUTANT);
131  }
132  bool is_cursed() const {
133  return (status & OBJ_STATUS_CURSED);
134  }
135  bool is_lit() const {
136  return (status & OBJ_STATUS_LIT);
137  }
138 
139  bool is_on_map() const {
140  return ((nuvie_status & NUVIE_OBJ_STATUS_LOC_MASK_GET) == OBJ_LOC_MAP);
141  }
142  bool is_in_container() const {
143  return ((nuvie_status & NUVIE_OBJ_STATUS_LOC_MASK_GET) == OBJ_LOC_CONT);
144  }
145  bool is_in_inventory(bool check_parent = true) const;
146 
147  bool is_readied() const {
148  return ((nuvie_status & NUVIE_OBJ_STATUS_LOC_MASK_GET) == OBJ_LOC_READIED);
149  }
150 
151  bool has_container() const {
152  return (container != nullptr);
153  }
154  void make_container();
155  Obj *get_container_obj(bool recursive = false);
156  uint32 container_count_objects() const;
157 
158  uint8 get_engine_loc() const;
159  Actor *get_actor_holding_obj();
160 
161  void set_on_map(U6LList *map_list);
162  void set_in_container(Obj *container_obj);
163  void set_in_inventory();
164 
165  void set_invisible(bool flag);
166 
167  void set_temporary(bool flag = true);
168 
169  void set_ok_to_take(bool flag, bool recursive = false);
170 
171  void readied();
172  void set_noloc();
173  void set_in_script(bool flag);
174  void set_actor_obj(bool flag);
175 
176  void add(Obj *obj, bool stack = false, bool addAtTail = false);
177 
178  bool remove(Obj *obj);
179 
180  Obj *find_in_container(uint16 obj_n, uint8 quality, bool match_quality = OBJ_MATCH_QUALITY, uint8 frame_n = 0, bool match_frame_n = OBJ_NOMATCH_FRAME_N, Obj **prev_obj = nullptr) const;
181 
182  uint32 get_total_qty(uint16 match_obj_n);
183 
184 protected:
185 
186  void add_and_stack(Obj *obj, bool addAtTail = false);
187 
188 };
189 
190 } // End of namespace Nuvie
191 } // End of namespace Ultima
192 
193 #endif
Definition: actor.h:178
Definition: obj.h:84
Definition: detection.h:27
Definition: u6_llist.h:46