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 (QUERY_FLAG (tmp, FLAG_ALIVE) |
|
|
226 | && tmp->head_ () != ob |
|
|
227 | && tmp != ob |
|
|
228 | && tmp->type != DOOR |
|
|
229 | && !tmp->flag [FLAG_WIZ] |
|
|
230 | && tmp->contr->hidden) |
227 | return 1; |
231 | return 1; |
228 | } |
232 | } |
229 | |
233 | |
230 | } |
234 | } |
231 | return 0; |
235 | return 0; |
… | |
… | |
353 | { |
357 | { |
354 | if (!spaces) |
358 | if (!spaces) |
355 | return; |
359 | return; |
356 | |
360 | |
357 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
361 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
358 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
362 | for (object *op = ms->bot; op; op = op->above) |
359 | { |
363 | { |
360 | /* already multipart - don't do anything more */ |
364 | /* already multipart - don't do anything more */ |
361 | if (!tmp->head && !tmp->more) |
365 | if (op->head_ () == op && !op->more && op->arch->more) |
362 | { |
366 | { |
363 | /* If there is nothing more to this object, this for loop |
367 | op->remove (); |
364 | * won't do anything. |
368 | op->expand_tail (); |
365 | */ |
|
|
366 | archetype *at; |
|
|
367 | object *last, *op; |
|
|
368 | for (at = tmp->arch->more, last = tmp; |
|
|
369 | at; |
|
|
370 | at = at->more, last = op) |
|
|
371 | { |
|
|
372 | op = arch_to_object (at); |
|
|
373 | |
|
|
374 | /* update x,y coordinates */ |
|
|
375 | op->x += tmp->x; |
|
|
376 | op->y += tmp->y; |
|
|
377 | op->head = tmp; |
|
|
378 | op->map = this; |
|
|
379 | last->more = op; |
|
|
380 | op->name = tmp->name; |
|
|
381 | op->title = tmp->title; |
|
|
382 | |
|
|
383 | /* we could link all the parts onto tmp, and then just |
|
|
384 | * call insert_ob_in_map once, but the effect is the same, |
|
|
385 | * as insert_ob_in_map will call itself with each part, and |
|
|
386 | * the coding is simpler to just to it here with each part. |
|
|
387 | */ |
|
|
388 | insert_ob_in_map (op, op->map, tmp, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); |
369 | insert (op, op->x, op->y, 0, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); |
389 | } |
|
|
390 | } |
370 | } |
391 | } |
371 | } |
392 | } |
372 | } |
393 | |
373 | |
394 | /* |
374 | /* |
… | |
… | |
398 | bool |
378 | bool |
399 | maptile::_load_objects (object_thawer &f) |
379 | maptile::_load_objects (object_thawer &f) |
400 | { |
380 | { |
401 | for (;;) |
381 | for (;;) |
402 | { |
382 | { |
403 | coroapi::cede_every (1000); // cede once in a while |
383 | coroapi::cede_to_tick_every (100); // cede once in a while |
404 | |
384 | |
405 | switch (f.kw) |
385 | switch (f.kw) |
406 | { |
386 | { |
407 | case KW_arch: |
387 | case KW_arch: |
408 | if (object *op = object::read (f, this)) |
388 | if (object *op = object::read (f, this)) |
… | |
… | |
431 | } |
411 | } |
432 | |
412 | |
433 | void |
413 | void |
434 | maptile::activate () |
414 | maptile::activate () |
435 | { |
415 | { |
|
|
416 | active = true; |
|
|
417 | |
436 | if (!spaces) |
418 | if (spaces) |
437 | return; |
|
|
438 | |
|
|
439 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
419 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
440 | for (object *op = ms->bot; op; op = op->above) |
420 | for (object *op = ms->bot; op; op = op->above) |
441 | op->activate_recursive (); |
421 | op->activate_recursive (); |
442 | } |
422 | } |
443 | |
423 | |
444 | void |
424 | void |
445 | maptile::deactivate () |
425 | maptile::deactivate () |
446 | { |
426 | { |
|
|
427 | active = false; |
|
|
428 | |
447 | if (!spaces) |
429 | if (spaces) |
448 | return; |
|
|
449 | |
|
|
450 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
430 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
451 | for (object *op = ms->bot; op; op = op->above) |
431 | for (object *op = ms->bot; op; op = op->above) |
452 | op->deactivate_recursive (); |
432 | op->deactivate_recursive (); |
453 | } |
433 | } |
454 | |
434 | |
455 | bool |
435 | bool |
456 | maptile::_save_objects (object_freezer &f, int flags) |
436 | maptile::_save_objects (object_freezer &f, int flags) |
457 | { |
437 | { |
458 | coroapi::cede (); |
438 | coroapi::cede_to_tick (); |
459 | |
439 | |
460 | if (flags & IO_HEADER) |
440 | if (flags & IO_HEADER) |
461 | _save_header (f); |
441 | _save_header (f); |
462 | |
442 | |
463 | if (!spaces) |
443 | if (!spaces) |
… | |
… | |
482 | else if (flags & IO_OBJECTS) |
462 | else if (flags & IO_OBJECTS) |
483 | op->write (f); |
463 | op->write (f); |
484 | } |
464 | } |
485 | } |
465 | } |
486 | |
466 | |
487 | coroapi::cede (); |
467 | coroapi::cede_to_tick (); |
488 | |
468 | |
489 | return true; |
469 | return true; |
490 | } |
470 | } |
491 | |
471 | |
492 | bool |
472 | bool |
… | |
… | |
797 | object *above = op->above; |
777 | object *above = op->above; |
798 | |
778 | |
799 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
779 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
800 | unique = 1; |
780 | unique = 1; |
801 | |
781 | |
802 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
782 | if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
803 | { |
783 | { |
804 | op->destroy_inv (false); |
784 | op->destroy_inv (false); |
805 | op->destroy (); |
785 | op->destroy (); |
806 | } |
786 | } |
807 | |
787 | |
… | |
… | |
890 | free (regionmap), regionmap = 0; |
870 | free (regionmap), regionmap = 0; |
891 | |
871 | |
892 | if (spaces) |
872 | if (spaces) |
893 | { |
873 | { |
894 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
874 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
895 | while (object *op = ms->bot) |
875 | while (object *op = ms->bot->head_ ()) |
896 | { |
876 | { |
897 | if (op->head) |
|
|
898 | op = op->head; |
|
|
899 | |
|
|
900 | op->destroy_inv (false); |
877 | op->destroy_inv (false); |
901 | op->destroy (); |
878 | op->destroy (); |
902 | } |
879 | } |
903 | |
880 | |
904 | sfree (spaces, size ()), spaces = 0; |
881 | sfree (spaces, size ()), spaces = 0; |