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

Comparing deliantra/server/common/map.C (file contents):
Revision 1.97 by root, Sat Mar 17 21:13:21 2007 UTC vs.
Revision 1.104 by root, Fri May 18 00:09:16 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
174 * let the player through (inventory checkers for example) 174 * let the player through (inventory checkers for example)
175 */ 175 */
176 if (!(mflags & P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK (ob, blocked)) 176 if (!(mflags & P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK (ob, blocked))
177 return 0; 177 return 0;
178 178
179 if (ob->head != NULL)
180 ob = ob->head; 179 ob = ob->head_ ();
181 180
182 /* We basically go through the stack of objects, and if there is 181 /* We basically go through the stack of objects, and if there is
183 * some other object that has NO_PASS or FLAG_ALIVE set, return 182 * some other object that has NO_PASS or FLAG_ALIVE set, return
184 * true. If we get through the entire stack, that must mean 183 * true. If we get through the entire stack, that must mean
185 * ob is blocking it, so return 0. 184 * ob is blocking it, so return 0.
215 else 214 else
216 { 215 {
217 /* Broke apart a big nasty if into several here to make 216 /* Broke apart a big nasty if into several here to make
218 * this more readable. first check - if the space blocks 217 * this more readable. first check - if the space blocks
219 * movement, can't move here. 218 * movement, can't move here.
220 * second - if a monster, can't move there, unles it is a 219 * second - if a monster, can't move there, unless it is a
221 * hidden dm 220 * hidden dm
222 */ 221 */
223 if (OB_MOVE_BLOCK (ob, tmp)) 222 if (OB_MOVE_BLOCK (ob, tmp))
224 return 1; 223 return 1;
225 if (QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->head != ob && tmp != ob && 224
226 tmp->type != DOOR && !(QUERY_FLAG (tmp, FLAG_WIZ) && tmp->contr->hidden)) 225 if (tmp->flag [FLAG_ALIVE]
226 && tmp->head_ () != ob
227 && tmp != ob
228 && tmp->type != DOOR
229 && !(tmp->flag [FLAG_WIZ] && tmp->contr->hidden))
227 return 1; 230 return 1;
228 } 231 }
229 232
230 } 233 }
231 return 0; 234 return 0;
344} 347}
345 348
346/* link_multipart_objects go through all the objects on the map looking 349/* link_multipart_objects go through all the objects on the map looking
347 * for objects whose arch says they are multipart yet according to the 350 * for objects whose arch says they are multipart yet according to the
348 * info we have, they only have the head (as would be expected when 351 * info we have, they only have the head (as would be expected when
349 * they are saved). We do have to look for the old maps that did save 352 * they are saved).
350 * the more sections and not re-add sections for them.
351 */ 353 */
352void 354void
353maptile::link_multipart_objects () 355maptile::link_multipart_objects ()
354{ 356{
355 if (!spaces) 357 if (!spaces)
356 return; 358 return;
357 359
358 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 360 for (mapspace *ms = spaces + size (); ms-- > spaces; )
359 for (object *tmp = ms->bot; tmp; tmp = tmp->above) 361 for (object *op = ms->bot; op; op = op->above)
360 { 362 {
361 /* already multipart - don't do anything more */ 363 /* already multipart - don't do anything more */
362 if (!tmp->head && !tmp->more) 364 if (op->head_ () == op && !op->more && op->arch->more)
363 { 365 {
364 /* If there is nothing more to this object, this for loop 366 op->remove ();
365 * won't do anything. 367 op->expand_tail ();
366 */
367 archetype *at;
368 object *last, *op;
369 for (at = tmp->arch->more, last = tmp;
370 at;
371 at = at->more, last = op)
372 {
373 op = arch_to_object (at);
374
375 /* update x,y coordinates */
376 op->x += tmp->x;
377 op->y += tmp->y;
378 op->head = tmp;
379 op->map = this;
380 last->more = op;
381 op->name = tmp->name;
382 op->title = tmp->title;
383
384 /* we could link all the parts onto tmp, and then just
385 * call insert_ob_in_map once, but the effect is the same,
386 * as insert_ob_in_map will call itself with each part, and
387 * the coding is simpler to just to it here with each part.
388 */
389 insert_ob_in_map (op, op->map, tmp, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); 368 insert (op, op->x, op->y, 0, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON);
390 }
391 } 369 }
392 } 370 }
393} 371}
394 372
395/* 373/*
399bool 377bool
400maptile::_load_objects (object_thawer &f) 378maptile::_load_objects (object_thawer &f)
401{ 379{
402 for (;;) 380 for (;;)
403 { 381 {
404 coroapi::cede_every (1000); // cede once in a while 382 coroapi::cede_to_tick_every (100); // cede once in a while
405 383
406 switch (f.kw) 384 switch (f.kw)
407 { 385 {
408 case KW_arch: 386 case KW_arch:
409 if (object *op = object::read (f, this)) 387 if (object *op = object::read (f, this))
432} 410}
433 411
434void 412void
435maptile::activate () 413maptile::activate ()
436{ 414{
415 active = true;
416
437 if (!spaces) 417 if (spaces)
438 return;
439
440 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 418 for (mapspace *ms = spaces + size (); ms-- > spaces; )
441 for (object *op = ms->bot; op; op = op->above) 419 for (object *op = ms->bot; op; op = op->above)
442 op->activate_recursive (); 420 op->activate_recursive ();
443} 421}
444 422
445void 423void
446maptile::deactivate () 424maptile::deactivate ()
447{ 425{
426 active = false;
427
448 if (!spaces) 428 if (spaces)
449 return;
450
451 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 429 for (mapspace *ms = spaces + size (); ms-- > spaces; )
452 for (object *op = ms->bot; op; op = op->above) 430 for (object *op = ms->bot; op; op = op->above)
453 op->deactivate_recursive (); 431 op->deactivate_recursive ();
454} 432}
455 433
456bool 434bool
457maptile::_save_objects (object_freezer &f, int flags) 435maptile::_save_objects (object_freezer &f, int flags)
458{ 436{
459 coroapi::cede (); 437 coroapi::cede_to_tick ();
460 438
461 if (flags & IO_HEADER) 439 if (flags & IO_HEADER)
462 _save_header (f); 440 _save_header (f);
463 441
464 if (!spaces) 442 if (!spaces)
465 return false; 443 return false;
466 444
467 for (int i = 0; i < size (); ++i) 445 for (int i = 0; i < size (); ++i)
468 { 446 {
469#if 0 // disabled, there still seem to be races somewhere
470 static int cede_count = 0;
471
472 if (cede_count >= 500)
473 {
474 cede_count = 0;
475 coroapi::cede ();
476 }
477#endif
478
479 int unique = 0; 447 int unique = 0;
480 for (object *op = spaces [i].bot; op; op = op->above) 448 for (object *op = spaces [i].bot; op; op = op->above)
481 { 449 {
482 // count per-object, but cede only when modification-safe
483 cede_count++;
484
485 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) 450 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
486 unique = 1; 451 unique = 1;
487 452
488 if (!op->can_map_save ()) 453 if (!op->can_map_save ())
489 continue; 454 continue;
496 else if (flags & IO_OBJECTS) 461 else if (flags & IO_OBJECTS)
497 op->write (f); 462 op->write (f);
498 } 463 }
499 } 464 }
500 465
501 coroapi::cede (); 466 coroapi::cede_to_tick ();
502 467
503 return true; 468 return true;
504} 469}
505 470
506bool 471bool
811 object *above = op->above; 776 object *above = op->above;
812 777
813 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 778 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
814 unique = 1; 779 unique = 1;
815 780
816 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 781 if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
817 { 782 {
818 op->destroy_inv (false); 783 op->destroy_inv (false);
819 op->destroy (); 784 op->destroy ();
820 } 785 }
821 786
906 if (spaces) 871 if (spaces)
907 { 872 {
908 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 873 for (mapspace *ms = spaces + size (); ms-- > spaces; )
909 while (object *op = ms->bot) 874 while (object *op = ms->bot)
910 { 875 {
911 if (op->head)
912 op = op->head; 876 op = op->head_ ();
913
914 op->destroy_inv (false); 877 op->destroy_inv (false);
915 op->destroy (); 878 op->destroy ();
916 } 879 }
917 880
918 sfree (spaces, size ()), spaces = 0; 881 sfree (spaces, size ()), spaces = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines