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.116 by root, Thu Nov 5 15:57:15 2009 UTC vs.
Revision 1.127 by root, Sat Jan 16 17:57:32 2010 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 (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002-2005,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002-2005,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * 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 9 * the terms of the Affero GNU General Public License as published by the
93/* These are used in the MapLook flags element. They are not used in 93/* These are used in the MapLook flags element. They are not used in
94 * in the object flags structure. 94 * in the object flags structure.
95 */ 95 */
96#define P_BLOCKSVIEW 0x01 96#define P_BLOCKSVIEW 0x01
97#define P_NO_MAGIC 0x02 /* Spells (some) can't pass this object */ 97#define P_NO_MAGIC 0x02 /* Spells (some) can't pass this object */
98#define P_PLAYER 0x04 /* a player (or something seeing these objects) is on this mapspace */ 98#define P_NO_CLERIC 0x04 /* no clerical spells cast here */
99#define P_SAFE 0x08 /* If this is set the map tile is a safe space, 99#define P_SAFE 0x08 /* If this is set the map tile is a safe space,
100 * that means, nothing harmful can be done, 100 * that means, nothing harmful can be done,
101 * such as: bombs, potion usage, alchemy, spells 101 * such as: bombs, potion usage, alchemy, spells
102 * this was introduced to make shops safer 102 * this was introduced to make shops safer
103 * but is useful in other situations */ 103 * but is useful in other situations */
104
105#define P_PLAYER 0x10 /* a player (or something seeing these objects) is on this mapspace */
104#define P_IS_ALIVE 0x10 /* something alive is on this space */ 106#define P_IS_ALIVE 0x20 /* something alive is on this space */
105#define P_NO_CLERIC 0x20 /* no clerical spells cast here */
106
107#define P_UPTODATE 0x80 /* this space is up to date */ 107#define P_UPTODATE 0x80 // this space is up to date
108 108
109/* The following two values are not stored in the MapLook flags, but instead 109/* The following two values are not stored in the MapLook flags, but instead
110 * used in the get_map_flags value - that function is used to return 110 * used in the get_map_flags value - that function is used to return
111 * the flag value, as well as other conditions - using a more general 111 * the flag value, as well as other conditions - using a more general
112 * function that does more of the work can hopefully be used to replace 112 * function that does more of the work can hopefully be used to replace
123 */ 123 */
124INTERFACE_CLASS (mapspace) 124INTERFACE_CLASS (mapspace)
125struct mapspace 125struct mapspace
126{ 126{
127 object *ACC (RW, bot); 127 object *ACC (RW, bot);
128 object *ACC (RW, top); /* lowest/highest object on this space */ 128 object *ACC (RW, top); /* lowest/highest object on this space */
129 object *ACC (RW, faces_obj[MAP_LAYERS]);/* face objects for the 3 layers */ 129 object *ACC (RW, faces_obj[MAP_LAYERS]);/* face objects for the 3 layers */
130 uint32_t smell; // the last count a player was seen here, or 0
131 static uint32_t smellcount; // global smell counter
132 uint8 flags_; /* flags about this space (see the P_ values above) */ 130 uint8 flags_; /* flags about this space (see the P_ values above) */
133 sint8 ACC (RW, light); /* How much light this space provides */ 131 sint8 ACC (RW, light); /* How much light this space provides */
134 MoveType ACC (RW, move_block); /* What movement types this space blocks */ 132 MoveType ACC (RW, move_block); /* What movement types this space blocks */
135 MoveType ACC (RW, move_slow); /* What movement types this space slows */ 133 MoveType ACC (RW, move_slow); /* What movement types this space slows */
136 MoveType ACC (RW, move_on); /* What movement types are activated */ 134 MoveType ACC (RW, move_on); /* What movement types are activated */
137 MoveType ACC (RW, move_off); /* What movement types are activated */ 135 MoveType ACC (RW, move_off); /* What movement types are activated */
136 uint16_t ACC (RW, items_); // saturates at 64k
137 uint32_t ACC (RW, volume_); // ~dm³ (not cm³) (factor is actually 1024)
138 uint32_t ACC (RW, smell); // the last count a player was seen here, or 0
139 static uint32_t ACC (RW, smellcount); // global smell counter
140
141 uint32_t pad1_, pad2_; // pad to 64 bytes on 64 bit systems
138 142
139//-GPL 143//-GPL
140 144
141 void update_ (); 145 void update_ ();
142 MTH void update () 146 MTH void update ()
143 { 147 {
144 if (expect_false (!(flags_ & P_UPTODATE))) 148 // we take advantage of the fact that 0x80 is the sign bit
149 // to generate more efficient code on many cpus
150 assert (sint8 (P_UPTODATE) < 0);
151 assert (sint8 (-1 & ~P_UPTODATE) >= 0);
152
153 if (expect_false (sint8 (flags_) >= 0))
145 update_ (); 154 update_ ();
155
156 // must be true by now (gcc seems content with only the second test)
157 assume (sint8 (flags_) < 0);
158 assume (flags_ & P_UPTODATE);
146 } 159 }
147 160
148 MTH uint8 flags () 161 MTH uint8 flags ()
149 { 162 {
150 update (); 163 update ();
167 op = 0; 180 op = 0;
168 181
169 return op; 182 return op;
170 } 183 }
171 184
185 MTH uint32 items()
186 {
187 update ();
188 return items_;
189 }
190
172 // return the item volume on this mapspace in cm³ 191 // return the item volume on this mapspace in cm³
173 MTH uint64 volume () const; 192 MTH uint64 volume ()
193 {
194 update ();
195 return volume_ * 1024;
196 }
174 197
175 bool blocks (MoveType mt) const 198 bool blocks (MoveType mt) const
176 { 199 {
177 return move_block && (mt & move_block) == mt; 200 return move_block && (mt & move_block) == mt;
178 } 201 }
181 { 204 {
182 return blocks (op->move_type); 205 return blocks (op->move_type);
183 } 206 }
184}; 207};
185 208
186// a rectangular area of a map 209// a rectangular area of a map, used my split_to_tiles/unordered_mapwalk
187struct maprect 210struct maprect
188{ 211{
189 maptile *m; 212 maptile *m;
190 int x0, y0; 213 int x0, y0;
191 int x1, y1; 214 int x1, y1;
258 static sint8 outdoor_darkness; /* the global darkness level outside */ 281 static sint8 outdoor_darkness; /* the global darkness level outside */
259 282
260 uint16 ACC (RW, enter_x); /* enter_x and enter_y are default entrance location */ 283 uint16 ACC (RW, enter_x); /* enter_x and enter_y are default entrance location */
261 uint16 ACC (RW, enter_y); /* on the map if none are set in the exit */ 284 uint16 ACC (RW, enter_y); /* on the map if none are set in the exit */
262 oblinkpt *buttons; /* Linked list of linked lists of buttons */ 285 oblinkpt *buttons; /* Linked list of linked lists of buttons */
263 sint16 ACC (RW, temp); /* base temperature of this tile (F) */
264 sint16 ACC (RW, pressure); /* barometric pressure (mb) */
265 sint8 ACC (RW, humid); /* humitidy of this tile */
266 sint8 ACC (RW, windspeed); /* windspeed of this tile */
267 sint8 ACC (RW, winddir); /* direction of wind */
268 sint8 ACC (RW, sky); /* sky conditions */
269 int ACC (RW, worldpartx), ACC (RW, worldparty); /*Highly fasten conversion between worldmap and weathermap */
270 struct shopitems *shopitems; /* a semi-colon seperated list of item-types the map's shop will trade in */ 286 struct shopitems *shopitems; /* a semi-colon seperated list of item-types the map's shop will trade in */
271 shstr ACC (RW, shoprace); /* the preffered race of the local shopkeeper */ 287 shstr ACC (RW, shoprace); /* the preffered race of the local shopkeeper */
272 double ACC (RW, shopgreed); /* how much our shopkeeper overcharges */ 288 double ACC (RW, shopgreed); /* how much our shopkeeper overcharges */
273 sint64 ACC (RW, shopmin); /* minimum price a shop will trade for */ 289 sint64 ACC (RW, shopmin); /* minimum price a shop will trade for */
274 sint64 ACC (RW, shopmax); /* maximum price a shop will offer */ 290 sint64 ACC (RW, shopmax); /* maximum price a shop will offer */
275 shstr ACC (RW, msg); /* Message map creator may have left */ 291 shstr ACC (RW, msg); /* Message map creator may have left */
276 shstr ACC (RW, maplore); /* Map lore information */ 292 shstr ACC (RW, maplore); /* Map lore information */
277 shstr ACC (RW, tile_path[4]); /* path to adjoining maps */ 293 shstr ACC (RW, tile_path[4]); /* path to adjoining maps */
278 maptile *ACC (RW, tile_map[4]); /* Next map, linked list */ 294 maptile *ACC (RW, tile_map[4]); /* Next map, linked list */
279 shstr ACC (RW, path); /* Filename of the map */ 295 shstr ACC (RW, path); /* Filename of the map */
280 int ACC (RW, max_nrof); // maximum nrof of any single item on a mapspace
281 uint64 ACC (RW, max_volume); // maximum volume for all items on a mapspace 296 uint64 ACC (RW, max_volume); // maximum volume for all items on a mapspace
297 int ACC (RW, max_items); // maximum number of items on a mapspace
282 298
283//-GPL 299//-GPL
284 300
285 // the maptile:: is neccessary here for the perl interface to work 301 // the maptile:: is neccessary here for the perl interface to work
286 MTH sint8 darklevel (sint8 outside = maptile::outdoor_darkness) const 302 MTH sint8 darklevel (sint8 outside = maptile::outdoor_darkness) const
296 // allocates all (empty) mapspace 312 // allocates all (empty) mapspace
297 MTH void alloc (); 313 MTH void alloc ();
298 // deallocates the mapspaces (and destroys all objects) 314 // deallocates the mapspaces (and destroys all objects)
299 MTH void clear (); 315 MTH void clear ();
300 316
317 MTH void post_load (); // update cached values in mapspaces etc.
301 MTH void fix_auto_apply (); 318 MTH void fix_auto_apply ();
302 MTH void do_decay_objects (); 319 MTH void do_decay_objects ();
303 MTH void update_buttons (); 320 MTH void update_buttons ();
304 MTH int change_map_light (int change); 321 MTH int change_map_light (int change);
305 MTH int estimate_difficulty () const; 322 MTH int estimate_difficulty () const;
306 323
307 MTH void play_sound (faceidx sound, int x, int y) const; 324 MTH void play_sound (faceidx sound, int x, int y) const;
308 MTH void say_msg (const char *msg, int x, int y) const; 325 MTH void say_msg (const_utf8_string msg, int x, int y) const;
309 326
310 // connected links 327 // connected links
311 oblinkpt *find_link (shstr_tmp id); 328 oblinkpt *find_link (shstr_tmp id);
312 MTH void trigger (shstr_tmp id, int state = 1, object *activator = 0, object *originator = 0); 329 MTH void trigger (shstr_tmp id, int state = 1, object *activator = 0, object *originator = 0);
313 330
331 bool _load_objects (object_thawer &thawer); 348 bool _load_objects (object_thawer &thawer);
332 MTH bool _load_objects (object_thawer *thawer) { return _load_objects (*thawer); } 349 MTH bool _load_objects (object_thawer *thawer) { return _load_objects (*thawer); }
333 350
334 // save objects into the given file (uses IO_ flags) 351 // save objects into the given file (uses IO_ flags)
335 bool _save_objects (object_freezer &freezer, int flags); 352 bool _save_objects (object_freezer &freezer, int flags);
336 MTH bool _save_objects (const char *path, int flags); 353 MTH bool _save_objects (const_octet_string path, int flags);
337 354
338 // save the header pseudo object _only_ 355 // save the header pseudo object _only_
339 bool _save_header (object_freezer &freezer); 356 bool _save_header (object_freezer &freezer);
340 MTH bool _save_header (const char *path); 357 MTH bool _save_header (const_octet_string path);
341 358
342 maptile (); 359 maptile ();
343 maptile (int w, int h); 360 maptile (int w, int h);
344 ~maptile (); 361 ~maptile ();
345 362
372 } 389 }
373 390
374 void make_map_floor (char **layout, char *floorstyle, random_map_params *RP); 391 void make_map_floor (char **layout, char *floorstyle, random_map_params *RP);
375 bool generate_random_map (random_map_params *RP); 392 bool generate_random_map (random_map_params *RP);
376 393
377 static maptile *find_async (const char *path, maptile *original = 0, bool load = true);//PERL 394 static maptile *find_async (const_utf8_string path, maptile *original = 0, bool load = true);//PERL
378 static maptile *find_sync (const char *path, maptile *original = 0);//PERL 395 static maptile *find_sync (const_utf8_string path, maptile *original = 0);//PERL
379 static maptile *find_style_sync (const char *dir, const char *file = 0);//PERL 396 static maptile *find_style_sync (const_utf8_string dir, const_utf8_string file = 0);//PERL
380 object *pick_random_object (rand_gen &gen = rndm) const; 397 object *pick_random_object (rand_gen &gen = rndm) const;
381 398
382 mapspace &at (uint32 x, uint32 y) const { return spaces [x * height + y]; } 399 mapspace &at (uint32 x, uint32 y) const { return spaces [x * height + y]; }
383 400
384 // return an array of maprects corresponding 401 // return an array of maprects corresponding

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines