ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/map.h
(Generate patch)

Comparing deliantra/server/include/map.h (file contents):
Revision 1.139 by root, Wed May 4 07:41:14 2011 UTC vs.
Revision 1.157 by root, Sat Nov 17 23:40:01 2018 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002-2005 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002-2005 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 10 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25/* 26/*
26 * The maptile is allocated each time a new map is opened. 27 * The maptile is allocated each time a new map is opened.
50#define MAGIC_MAP_SIZE 50 51#define MAGIC_MAP_SIZE 50
51#define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2 52#define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2
52 53
53#define MAP_LAYERS 3 54#define MAP_LAYERS 3
54 55
55// tile map index 56// tile map index - toggling the lowest bit reverses direction
56enum { 57enum
58{
57 TILE_NORTH, 59 TILE_NORTH,
58 TILE_EAST,
59 TILE_SOUTH, 60 TILE_SOUTH,
60 TILE_WEST, 61 TILE_WEST,
62 TILE_EAST,
61 TILE_UP, 63 TILE_UP,
62 TILE_DOWN, 64 TILE_DOWN,
63 TILE_NUM, 65 TILE_NUM
64}; 66};
67
68#define REVERSE_TILE_DIR(dir) ((dir) ^ 1)
65 69
66/* Values for state below */ 70/* Values for state below */
67enum { 71enum
72{
68 MAP_SWAPPED, // header loaded, nothing else 73 MAP_SWAPPED, // header loaded, nothing else
69 MAP_INACTIVE, // in memory, linkable, but not active 74 MAP_INACTIVE, // in memory, linkable, but not active
70 MAP_ACTIVE, // running! 75 MAP_ACTIVE, // running!
71}; 76};
72 77
89 * should almost always be using out_of_map instead, which takes into account 94 * should almost always be using out_of_map instead, which takes into account
90 * map tiling. 95 * map tiling.
91 */ 96 */
92#define OUT_OF_REAL_MAP(M,X,Y) (!(IN_RANGE_EXC ((X), 0, (M)->width) && IN_RANGE_EXC ((Y), 0, (M)->height))) 97#define OUT_OF_REAL_MAP(M,X,Y) (!(IN_RANGE_EXC ((X), 0, (M)->width) && IN_RANGE_EXC ((Y), 0, (M)->height)))
93 98
94/* These are used in the MapLook flags element. They are not used in 99/* These are used in the mapspace flags element. They are not used in
95 * in the object flags structure. 100 * in the object flags structure.
96 */ 101 */
97#define P_BLOCKSVIEW 0x01 102#define P_BLOCKSVIEW 0x01
98#define P_NO_MAGIC 0x02 /* Spells (some) can't pass this object */ 103#define P_NO_MAGIC 0x02 /* Spells (some) can't pass this object */
99#define P_NO_CLERIC 0x04 /* no clerical spells cast here */ 104#define P_NO_CLERIC 0x04 /* no clerical spells cast here */
113 * function that does more of the work can hopefully be used to replace 118 * function that does more of the work can hopefully be used to replace
114 * lots of duplicate checks currently in the code. 119 * lots of duplicate checks currently in the code.
115 */ 120 */
116#define P_OUT_OF_MAP 0x10000 /* This space is outside the map */ 121#define P_OUT_OF_MAP 0x10000 /* This space is outside the map */
117#define P_NEW_MAP 0x20000 /* Coordinates passed result in a new tiled map */ 122#define P_NEW_MAP 0x20000 /* Coordinates passed result in a new tiled map */
123
124// persistent flags (pflags) in mapspace
125enum
126{
127 PF_VIS_UP = 0x01, // visible upwards, set by upmap, cleared by mapspace
128};
118 129
119/* Instead of having numerous arrays that have information on a 130/* Instead of having numerous arrays that have information on a
120 * particular space (was map, floor, floor2, map_ob), 131 * particular space (was map, floor, floor2, map_ob),
121 * have this structure take care of that information. 132 * have this structure take care of that information.
122 * This puts it all in one place, and should also make it easier 133 * This puts it all in one place, and should also make it easier
137 uint16_t ACC (RW, items_); // saturates at 64k 148 uint16_t ACC (RW, items_); // saturates at 64k
138 uint32_t ACC (RW, volume_); // ~dm³ (not cm³) (factor is actually 1024) 149 uint32_t ACC (RW, volume_); // ~dm³ (not cm³) (factor is actually 1024)
139 uint32_t ACC (RW, smell); // the last count a player was seen here, or 0 150 uint32_t ACC (RW, smell); // the last count a player was seen here, or 0
140 static uint32_t ACC (RW, smellcount); // global smell counter 151 static uint32_t ACC (RW, smellcount); // global smell counter
141 152
153 uint8_t pflags; // additional, persistent flags
142 uint32_t pad1_; // pad to 64 bytes on 64 bit systems 154 uint8_t pad [3]; // pad to 64 bytes on LP64 systems
143 155
144//-GPL 156//-GPL
145 157
146 void update_ (); 158 void update_ ();
147 MTH void update () 159 MTH void update ()
148 { 160 {
149 // we take advantage of the fact that 0x80 is the sign bit 161 // we take advantage of the fact that 0x80 is the sign bit
150 // to generate more efficient code on many cpus 162 // to generate more efficient code on many cpus
151 assert (sint8 (P_UPTODATE) < 0); 163 //assert (sint8 (P_UPTODATE) < 0);
152 assert (sint8 (-1 & ~P_UPTODATE) >= 0); 164 //assert (sint8 (-1 & ~P_UPTODATE) >= 0);
153 165
154 if (expect_false (sint8 (flags_) >= 0)) 166 if (expect_false (sint8 (flags_) >= 0))
155 update_ (); 167 update_ ();
156 168
157 // must be true by now (gcc seems content with only the second test) 169 // must be true by now (gcc seems content with only the second test)
158 assume (sint8 (flags_) < 0); 170 ecb_assume (sint8 (flags_) < 0);
159 assume (flags_ & P_UPTODATE); 171 ecb_assume (flags_ & P_UPTODATE);
160 } 172 }
161 173
162 MTH uint8 flags () 174 MTH uint8 flags ()
163 { 175 {
164 update (); 176 update ();
165 return flags_; 177 return flags_;
166 } 178 }
167 179
180 MTH void update_up ();
181
168 MTH void invalidate () 182 MTH void invalidate ()
169 { 183 {
170 flags_ = 0; 184 flags_ = 0;
171 } 185
186 if (pflags)
187 update_up ();
172 188 }
189
173 MTH object *player () 190 MTH object *player ()
174 { 191 {
175 object *op; 192 object *op;
176 193
177 if (flags () & P_PLAYER) 194 if (flags () & P_PLAYER)
188 update (); 205 update ();
189 return items_; 206 return items_;
190 } 207 }
191 208
192 // return the item volume on this mapspace in cm³ 209 // return the item volume on this mapspace in cm³
193 MTH uint64 volume () 210 MTH volume_t volume ()
194 { 211 {
195 update (); 212 update ();
196 return volume_ * 1024; 213 return volume_ * 1024;
197 } 214 }
198 215
214 int x0, y0; 231 int x0, y0;
215 int x1, y1; 232 int x1, y1;
216 int dx, dy; // offset to go from local coordinates to original tile */ 233 int dx, dy; // offset to go from local coordinates to original tile */
217}; 234};
218 235
236// (refcounted) list of objects on this map that need physics processing
237struct physics_queue
238: unordered_vector<object *>
239{
240 int i; // already processed
241 physics_queue ();
242 ~physics_queue ();
243 object *pop ();
244};
245
246#define PHYSICS_QUEUES 16 // "activity" at least every 16 ticks
247
219//+GPL 248//+GPL
220 249
221struct shopitems : zero_initialised 250struct shopitems : zero_initialised
222{ 251{
223 const char *name; /* name of the item in question, null if it is the default item */ 252 const char *name; /* name of the item in question, null if it is the default item */
224 const char *name_pl; /* plural name */ 253 const char *name_pl; /* plural name */
225 int typenum; /* itemtype number we need to match 0 if it is the default price */ 254 int typenum; /* itemtype number we need to match 0 if it is the default price */
226 sint8 strength; /* the degree of specialisation the shop has in this item, 255 sint8 strength; /* the degree of specialisation the shop has in this item,
227 * as a percentage from -100 to 100 */ 256 * as a percentage from -100 to 100 */
228 int index; /* being the size of the shopitems array. */ 257 int index; /* being the size of the shopitems array. */
229}; 258};
230 259
231// map I/O, what to load/save 260// map I/O, what to load/save
233 IO_HEADER = 0x01, // the "arch map" pseudo object 262 IO_HEADER = 0x01, // the "arch map" pseudo object
234 IO_OBJECTS = 0x02, // the non-unique objects 263 IO_OBJECTS = 0x02, // the non-unique objects
235 IO_UNIQUES = 0x04, // unique objects 264 IO_UNIQUES = 0x04, // unique objects
236}; 265};
237 266
238/* In general, code should always use the macros 267/* In general, code should always use the macros
239 * above (or functions in map.c) to access many of the 268 * above (or functions in map.c) to access many of the
240 * values in the map structure. Failure to do this will 269 * values in the map structure. Failure to do this will
241 * almost certainly break various features. You may think 270 * almost certainly break various features. You may think
242 * it is safe to look at width and height values directly 271 * it is safe to look at width and height values directly
243 * (or even through the macros), but doing so will completely 272 * (or even through the macros), but doing so will completely
244 * break map tiling. 273 * break map tiling.
252 region_ptr *regionmap; /* index to region */ 281 region_ptr *regionmap; /* index to region */
253 282
254 tstamp ACC (RW, last_access); /* last time this map was accessed somehow */ 283 tstamp ACC (RW, last_access); /* last time this map was accessed somehow */
255 284
256 shstr ACC (RW, name); /* Name of map as given by its creator */ 285 shstr ACC (RW, name); /* Name of map as given by its creator */
257 region_ptr ACC (RW, default_region); /* What jurisdiction in the game world this map is ruled by 286 region_ptr ACC (RW, default_region); /* What jurisdiction in the game world this map is ruled by
258 * points to the struct containing all the properties of 287 * points to the struct containing all the properties of
259 * the region */ 288 * the region */
260 double ACC (RW, reset_time); 289 double ACC (RW, reset_time);
261 uint32 ACC (RW, reset_timeout); /* How many seconds must elapse before this map 290 uint32 ACC (RW, reset_timeout); /* How many seconds must elapse before this map
262 * should be reset 291 * should be reset
263 */ 292 */
292 shstr ACC (RW, msg); /* Message map creator may have left */ 321 shstr ACC (RW, msg); /* Message map creator may have left */
293 shstr ACC (RW, maplore); /* Map lore information */ 322 shstr ACC (RW, maplore); /* Map lore information */
294 shstr ACC (RW, tile_path[TILE_NUM]); /* path to adjoining maps */ 323 shstr ACC (RW, tile_path[TILE_NUM]); /* path to adjoining maps */
295 maptile *ACC (RW, tile_map[TILE_NUM]); /* Next map, linked list */ 324 maptile *ACC (RW, tile_map[TILE_NUM]); /* Next map, linked list */
296 shstr ACC (RW, path); /* Filename of the map */ 325 shstr ACC (RW, path); /* Filename of the map */
297 uint64 ACC (RW, max_volume); // maximum volume for all items on a mapspace 326 volume_t ACC (RW, max_volume); // maximum volume for all items on a mapspace
298 int ACC (RW, max_items); // maximum number of items on a mapspace 327 int ACC (RW, max_items); // maximum number of items on a mapspace
299 328
300//-GPL 329//-GPL
330
331 physics_queue pq[PHYSICS_QUEUES];
332 MTH void queue_physics (object *ob, int after = 0);
333 MTH void queue_physics_at (int x, int y);
334 MTH int run_physics (tick_t tick, int max_objects);
335 MTH void activate_physics ();
301 336
302 // the maptile:: is neccessary here for the perl interface to work 337 // the maptile:: is neccessary here for the perl interface to work
303 MTH sint8 darklevel (sint8 outside = maptile::outdoor_darkness) const 338 MTH sint8 darklevel (sint8 outside = maptile::outdoor_darkness) const
304 { 339 {
305 return clamp (outdoor ? darkness + outside : darkness, 0, MAX_DARKNESS); 340 return clamp (outdoor ? darkness + outside : darkness, 0, MAX_DARKNESS);
371 406
372 MTH object *insert (object *op, int x, int y, object *originator = 0, int flags = 0); 407 MTH object *insert (object *op, int x, int y, object *originator = 0, int flags = 0);
373 408
374 MTH void touch () { last_access = runtime; } 409 MTH void touch () { last_access = runtime; }
375 410
411 // returns the map at given direction. if the map isn't linked yet,
412 // it will either return false (if load is false), or otherwise try to link
413 // it - if linking fails because the map is not loaded yet, it will
414 // start loading the map and return 0.
415 // thus, if you get 0, the map exists and load is true, then some later
416 // call (some tick or so later...) will eventually succeed.
376 MTH maptile *tile_available (int dir, bool load = true); 417 MTH maptile *tile_available (int dir, bool load = true);
377 418
378 // find the map that is at coordinate x|y relative to this map 419 // find the map that is at coordinate x|y relative to this map
379 // TODO: need a better way than passing by reference 420 // TODO: need a better way than passing by reference
380 // TODO: make perl interface 421 // TODO: make perl interface
487 return *this; 528 return *this;
488 } 529 }
489 530
490 mapxy &move (int dir) 531 mapxy &move (int dir)
491 { 532 {
492 return move (freearr_x [dir], freearr_y [dir]); 533 return move (DIRX (dir), DIRY (dir));
493 } 534 }
494 535
495 operator void *() const { return (void *)m; } 536 operator void *() const { return (void *)m; }
496 mapxy &operator =(const object *op) 537 mapxy &operator =(const object *op)
497 { 538 {
560 } \ 601 } \
561 } 602 }
562 603
563extern dynbuf mapwalk_buf; // can be used in simple non-recursive situations 604extern dynbuf mapwalk_buf; // can be used in simple non-recursive situations
564 605
606// special "grave" map used to store all removed objects
607// till they can be destroyed - saves a lot of checks in the rest
608// of the code
609struct freed_map
610: maptile
611{
612 freed_map ()
613 : maptile (3, 3)
614 {
615 path = "<freed objects map>";
616 name = "/internal/freed_objects_map";
617 no_drop = 1;
618 no_reset = 1;
619
620 state = MAP_ACTIVE;
621 }
622
623 ~freed_map ()
624 {
625 destroy ();
626 }
627};
628
629// initialised in common/shstr.C, due to shstr usage we need defined
630// initialisation order!
631extern struct freed_map freed_map; // freed objects are moved here to avoid crashes
632
565// loop over every space in the given maprect, 633// loop over every space in the given maprect,
566// setting m, nx, ny to the map and -coordinate and dx, dy to the offset relative to dx0,dy0 634// setting m, nx, ny to the map and -coordinate and dx, dy to the offset relative to dx0,dy0
567// the iterator code must be a single statement following this macro call, similar to "if" 635// the iterator code must be a single statement following this macro call, similar to "if"
568// "continue" will skip to the next space 636// "continue" will skip to the next space
569#define rect_mapwalk(rect,dx0,dy0) \ 637#define rect_mapwalk(rect,dx0,dy0) \

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines