ScummVM API documentation
map.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_MAP_H
23 #define NUVIE_CORE_MAP_H
24 
25 #include "ultima/shared/std/string.h"
26 #include "ultima/nuvie/core/obj_manager.h"
27 
28 namespace Ultima {
29 namespace Nuvie {
30 
31 class Configuration;
32 class U6LList;
33 class Actor;
34 class ActorManager;
35 class MapCoord;
36 class TileManager;
37 class Screen;
38 
39 #define MAP_ORIGINAL_TILE true
40 
41 enum LineTestFlags {
42  LT_HitActors = (1 << 0),
43  LT_HitUnpassable = (1 << 1),
44  LT_HitForcedPassable = (1 << 2),
45  LT_HitLocation = (1 << 3), /* hit location in Result */
46  LT_HitObjects = (1 << 4), /* hit any object */
47  LT_HitMissileBoundary = (1 << 5)
48 };
49 
51 public:
52  LineTestResult() { // clears properties not set by init() (SB-X)
53  hit_x = 0;
54  hit_y = 0;
55  hit_level = 0;
56  hitActor = nullptr;
57  hitObj = nullptr;
58  hitLoc = nullptr;
59  loc_to_hit = nullptr;
60  }
61  void init(int x, int y, uint8 level, Actor *actorHit, Obj *objHit) {
62  hit_x = x;
63  hit_y = y;
64  hit_level = level;
65  hitActor = actorHit;
66  hitObj = objHit;
67  }
68 
69  int hit_x; // x coord where object / actor was hit
70  int hit_y; // y coord where object / actor was hit
71  int pre_hit_x;
72  int pre_hit_y;
73  uint8 hit_level; // map level where object / actor was hit
74  Actor *hitActor;
75  Obj *hitObj;
76  MapCoord *hitLoc;
77  MapCoord *loc_to_hit; // set hitLoc if hit x,y (z changes)
78 };
79 
80 //typedef (*LineTestFilter)(int x, int y, int level, LineTestResult &Result);
81 
82 /* Map Location with 2D X,Y coordinates and plane (map number)
83  */
84 class MapCoord {
85 public:
86  union {
87  uint16 x;
88  sint16 sx;
89  };
90  union {
91  uint16 y;
92  sint16 sy;
93  };
94  uint8 z; // plane
95 
96  MapCoord(uint16 nx, uint16 ny, uint16 nz = 0) {
97  x = nx;
98  y = ny;
99  z = nz;
100  }
101  MapCoord(Obj *obj) {
102  x = obj->x;
103  y = obj->y;
104  z = obj->z;
105  }
106  MapCoord() : x(0), y(0), z(0) { }
107 
108  uint32 xdistance(const MapCoord &c2) const {
109  uint32 dist = abs(c2.x - x);
110  if (dist > 512)
111  dist = 1024 - dist;
112 
113  return dist;
114  }
115  uint32 ydistance(const MapCoord &c2) const {
116  return abs(c2.y - y);
117  }
118  // greatest 2D distance X or Y (estimate of shortest)
119  uint32 distance(const MapCoord &c2) const {
120  uint16 dx = xdistance(c2), dy = ydistance(c2);
121  return (dx >= dy ? dx : dy);
122  }
123  // get absolute coordinates for relative destination (dx,dy)
124  MapCoord abs_coords(sint16 dx, sint16 dy) const;
125  // location is on screen?
126  bool is_visible() const;
127  void print_d(DebugLevelType level) const {
128  DEBUG(1, level, "%d, %d, %d", x, y, z);
129  }
130  void print_h(DebugLevelType level) const {
131  DEBUG(1, level, "%x, %x, %x", x, y, z);
132  }
133  void print_s(DebugLevelType level) const {
134  DEBUG(1, level, "%d, %d", sx, sy);
135  }
136 
137  bool operator==(const MapCoord &c2) const {
138  return (x == c2.x && y == c2.y && z == c2.z);
139  }
140  bool operator!=(const MapCoord &c2) const {
141  return (!(*this == c2));
142  }
143 // MapCoord operator+(MapCoord &c2) { return(abs_coords(c2)); }
144 };
145 
146 
147 class Map {
148  const Configuration *config;
149  TileManager *tile_manager;
150  ObjManager *obj_manager;
151  ActorManager *actor_manager;
152 
153  uint8 *surface;
154  uint8 *dungeons[5];
155 
156  bool roof_mode;
157  uint16 *roof_surface;
158 
159 public:
160 
161  Map(const Configuration *cfg);
162  ~Map();
163 
164  void set_actor_manager(ActorManager *am) {
165  actor_manager = am;
166  }
167  Actor *get_actor(uint16 x, uint16 y, uint8 z, bool inc_surrounding_objs = true);
168 
169  bool loadMap(TileManager *tm, ObjManager *om);
170  byte *get_map_data(uint8 level);
171  uint16 *get_roof_data(uint8 level);
172  const Tile *get_tile(uint16 x, uint16 y, uint8 level, bool original_tile = false);
173  uint16 get_width(uint8 level) const;
174  bool is_passable(uint16 x, uint16 y, uint8 level);
175  bool is_water(uint16 x, uint16 y, uint16 level, bool ignore_objects = false);
176  bool is_boundary(uint16 x, uint16 y, uint8 level);
177  bool is_missile_boundary(uint16 x, uint16 y, uint8 level, Obj *excluded_obj = nullptr);
178  bool is_damaging(uint16 x, uint16 y, uint8 level, bool ignore_objects = false);
179  bool can_put_obj(uint16 x, uint16 y, uint8 level);
180  bool actor_at_location(uint16 x, uint16 y, uint8 level, bool inc_surrounding_objs = true);
181  uint8 get_impedance(uint16 x, uint16 y, uint8 level, bool ignore_objects = false);
182  const Tile *get_dmg_tile(uint16 x, uint16 y, uint8 level);
183  bool is_passable(uint16 x, uint16 y, uint8 level, NuvieDir dir);
184  bool is_passable(uint16 x1, uint16 y1, uint16 x2, uint16 y2, uint8 level);
185  bool is_passable_from_dir(uint16 x, uint16 y, uint8 level, NuvieDir dir);
186  bool has_roof(uint16 x, uint16 y, uint8 level) const;
187  void set_roof_mode(bool roofs);
188 
189  const char *look(uint16 x, uint16 y, uint8 level);
190 
191  bool lineTest(int start_x, int start_y, int end_x, int end_y, uint8 level,
192  uint8 flags, LineTestResult &Result, uint32 skip = 0, Obj *excluded_obj = nullptr, bool want_screen_space = false); // excluded_obj only works for LT_HitUnpassable
193 
194  bool testIntersection(int x, int y, uint8 level, uint8 flags, LineTestResult &Result, Obj *excluded_obj = nullptr); // excluded_obj only works for LT_HitUnpassable
195 
196  void saveRoofData();
197  Common::Path getRoofTilesetFilename() const;
198 
199 protected:
200  Common::Path getRoofDataFilename() const;
201  void insertSurfaceSuperChunk(const unsigned char *schunk_ptr, const unsigned char *chunk_data, uint8 schunk_num);
202  void insertSurfaceChunk(const unsigned char *chunk, uint16 x, uint16 y);
203 
204  void insertDungeonSuperChunk(const unsigned char *schunk_ptr, const unsigned char *chunk_data, uint8 level);
205  void insertDungeonChunk(const unsigned char *chunk, uint16 x, uint16 y, uint8 level);
206 
207 
208  void loadRoofData();
209 
210 };
211 
212 } // End of namespace Nuvie
213 } // End of namespace Ultima
214 
215 #endif
Definition: actor.h:178
Definition: obj.h:84
Definition: configuration.h:61
Definition: map.h:147
Definition: path.h:52
Definition: atari-screen.h:60
Definition: tile_manager.h:145
Definition: actor_manager.h:42
Definition: detection.h:27
Definition: map.h:50
Definition: map.h:84
Definition: obj_manager.h:75
Definition: tile_manager.h:113