… | |
… | |
166 | } |
166 | } |
167 | return 0; |
167 | return 0; |
168 | } |
168 | } |
169 | |
169 | |
170 | /* |
170 | /* |
171 | * Returns true if the given object can't fit in the given spot. |
171 | * Returns qthe blocking object if the given object can't fit in the given |
172 | * This is meant for multi space objects - for single space objecs, |
172 | * spot. This is meant for multi space objects - for single space objecs, |
173 | * just calling get_map_blocked and checking that against movement type |
173 | * just calling get_map_blocked and checking that against movement type |
174 | * of object. This function goes through all the parts of the |
174 | * of object. This function goes through all the parts of the multipart |
175 | * multipart object and makes sure they can be inserted. |
175 | * object and makes sure they can be inserted. |
176 | * |
176 | * |
177 | * While this doesn't call out of map, the get_map_flags does. |
177 | * While this doesn't call out of map, the get_map_flags does. |
178 | * |
178 | * |
179 | * This function has been used to deprecate arch_out_of_map - |
179 | * This function has been used to deprecate arch_out_of_map - |
180 | * this function also does that check, and since in most cases, |
180 | * this function also does that check, and since in most cases, |
… | |
… | |
191 | * |
191 | * |
192 | * Note this used to be arch_blocked, but with new movement |
192 | * Note this used to be arch_blocked, but with new movement |
193 | * code, we need to have actual object to check its move_type |
193 | * code, we need to have actual object to check its move_type |
194 | * against the move_block values. |
194 | * against the move_block values. |
195 | */ |
195 | */ |
196 | int |
196 | bool |
197 | ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) |
197 | object::blocked (maptile *m, int x, int y) const |
198 | { |
198 | { |
199 | archetype *tmp; |
199 | for (archetype *tmp = arch; tmp; tmp = (archetype *)tmp->more) |
200 | int flag; |
|
|
201 | maptile *m1; |
|
|
202 | sint16 sx, sy; |
|
|
203 | |
|
|
204 | if (!ob) |
|
|
205 | { |
|
|
206 | flag = get_map_flags (m, &m1, x, y, &sx, &sy); |
|
|
207 | if (flag & P_OUT_OF_MAP) |
|
|
208 | return P_OUT_OF_MAP; |
|
|
209 | |
|
|
210 | /* don't have object, so don't know what types would block */ |
|
|
211 | return m1->at (sx, sy).move_block; |
|
|
212 | } |
200 | { |
|
|
201 | mapxy pos (m, x + tmp->x, y + tmp->y); |
213 | |
202 | |
214 | for (tmp = ob->arch; tmp; tmp = (archetype *)tmp->more) |
203 | if (!pos.normalise ()) |
215 | { |
204 | return 1; |
216 | flag = get_map_flags (m, &m1, x + tmp->x, y + tmp->y, &sx, &sy); |
|
|
217 | |
205 | |
218 | if (flag & P_OUT_OF_MAP) |
206 | mapspace &ms = *pos; |
219 | return P_OUT_OF_MAP; |
207 | |
220 | if (flag & P_IS_ALIVE) |
208 | if (ms.flags () & P_IS_ALIVE) |
221 | return P_IS_ALIVE; |
209 | return 1; |
222 | |
210 | |
223 | mapspace &ms = m1->at (sx, sy); |
211 | /* However, often ob doesn't have any move type |
224 | |
212 | * (signifying non-moving objects) |
225 | /* find_first_free_spot() calls this function. However, often |
|
|
226 | * ob doesn't have any move type (when used to place exits) |
|
|
227 | * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. |
213 | * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. |
228 | */ |
214 | */ |
229 | |
|
|
230 | if (ob->move_type == 0 && ms.move_block != MOVE_ALL) |
215 | if (!move_type && ms.move_block != MOVE_ALL) |
231 | continue; |
216 | continue; |
232 | |
217 | |
233 | /* Note it is intentional that we check ob - the movement type of the |
218 | /* Note it is intentional that we check ob - the movement type of the |
234 | * head of the object should correspond for the entire object. |
219 | * head of the object should correspond for the entire object. |
235 | */ |
220 | */ |
236 | if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block)) |
221 | if (ms.blocks (move_type)) |
237 | return P_NO_PASS; |
222 | return 1; |
238 | } |
223 | } |
239 | |
224 | |
240 | return 0; |
225 | return 0; |
241 | } |
226 | } |
242 | |
227 | |
… | |
… | |
383 | if (!spaces) |
368 | if (!spaces) |
384 | return false; |
369 | return false; |
385 | |
370 | |
386 | for (int i = 0; i < size (); ++i) |
371 | for (int i = 0; i < size (); ++i) |
387 | { |
372 | { |
388 | int unique = 0; |
373 | bool unique = 0; |
|
|
374 | |
389 | for (object *op = spaces [i].bot; op; op = op->above) |
375 | for (object *op = spaces [i].bot; op; op = op->above) |
390 | { |
376 | { |
391 | if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) |
377 | unique |= op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]; |
392 | unique = 1; |
|
|
393 | |
378 | |
394 | if (!op->can_map_save ()) |
379 | if (expect_false (!op->can_map_save ())) |
395 | continue; |
380 | continue; |
396 | |
381 | |
397 | if (unique || op->flag [FLAG_UNIQUE]) |
382 | if (expect_false (unique || op->flag [FLAG_UNIQUE])) |
398 | { |
383 | { |
399 | if (flags & IO_UNIQUES) |
384 | if (flags & IO_UNIQUES) |
400 | op->write (f); |
385 | op->write (f); |
401 | } |
386 | } |
402 | else if (flags & IO_OBJECTS) |
387 | else if (expect_true (flags & IO_OBJECTS)) |
403 | op->write (f); |
388 | op->write (f); |
404 | } |
389 | } |
405 | } |
390 | } |
406 | |
391 | |
407 | coroapi::cede_to_tick (); |
392 | coroapi::cede_to_tick (); |
408 | |
393 | |
409 | return true; |
394 | return true; |
410 | } |
|
|
411 | |
|
|
412 | bool |
|
|
413 | maptile::_load_objects (const char *path, bool skip_header) |
|
|
414 | { |
|
|
415 | object_thawer f (path); |
|
|
416 | |
|
|
417 | if (!f) |
|
|
418 | return false; |
|
|
419 | |
|
|
420 | f.next (); |
|
|
421 | |
|
|
422 | if (skip_header) |
|
|
423 | for (;;) |
|
|
424 | { |
|
|
425 | keyword kw = f.kw; |
|
|
426 | f.skip (); |
|
|
427 | if (kw == KW_end) |
|
|
428 | break; |
|
|
429 | } |
|
|
430 | |
|
|
431 | return _load_objects (f); |
|
|
432 | } |
395 | } |
433 | |
396 | |
434 | bool |
397 | bool |
435 | maptile::_save_objects (const char *path, int flags) |
398 | maptile::_save_objects (const char *path, int flags) |
436 | { |
399 | { |
… | |
… | |
611 | bool |
574 | bool |
612 | maptile::_load_header (object_thawer &thawer) |
575 | maptile::_load_header (object_thawer &thawer) |
613 | { |
576 | { |
614 | for (;;) |
577 | for (;;) |
615 | { |
578 | { |
616 | thawer.next (); |
|
|
617 | |
|
|
618 | switch (thawer.kw) |
579 | switch (thawer.kw) |
619 | { |
580 | { |
620 | case KW_msg: |
581 | case KW_msg: |
621 | thawer.get_ml (KW_endmsg, msg); |
582 | thawer.get_ml (KW_endmsg, msg); |
622 | break; |
583 | break; |
… | |
… | |
677 | case KW_tile_path_2: thawer.get (tile_path [1]); break; |
638 | case KW_tile_path_2: thawer.get (tile_path [1]); break; |
678 | case KW_tile_path_3: thawer.get (tile_path [2]); break; |
639 | case KW_tile_path_3: thawer.get (tile_path [2]); break; |
679 | case KW_tile_path_4: thawer.get (tile_path [3]); break; |
640 | case KW_tile_path_4: thawer.get (tile_path [3]); break; |
680 | |
641 | |
681 | case KW_ERROR: |
642 | case KW_ERROR: |
682 | set_key (thawer.kw_str, thawer.value); |
643 | set_key_text (thawer.kw_str, thawer.value); |
683 | break; |
644 | break; |
684 | |
645 | |
685 | case KW_end: |
646 | case KW_end: |
|
|
647 | thawer.next (); |
686 | return true; |
648 | return true; |
687 | |
649 | |
688 | default: |
650 | default: |
689 | if (!thawer.parse_error ("map", 0)) |
651 | if (!thawer.parse_error ("map", 0)) |
690 | return false; |
652 | return false; |
691 | break; |
653 | break; |
692 | } |
654 | } |
|
|
655 | |
|
|
656 | thawer.next (); |
693 | } |
657 | } |
694 | |
658 | |
695 | abort (); |
659 | abort (); |
696 | } |
|
|
697 | |
|
|
698 | bool |
|
|
699 | maptile::_load_header (const char *path) |
|
|
700 | { |
|
|
701 | object_thawer thawer (path); |
|
|
702 | |
|
|
703 | if (!thawer) |
|
|
704 | return false; |
|
|
705 | |
|
|
706 | return _load_header (thawer); |
|
|
707 | } |
660 | } |
708 | |
661 | |
709 | /****************************************************************************** |
662 | /****************************************************************************** |
710 | * This is the start of unique map handling code |
663 | * This is the start of unique map handling code |
711 | *****************************************************************************/ |
664 | *****************************************************************************/ |
… | |
… | |
810 | * Remove and free all objects in the given map. |
763 | * Remove and free all objects in the given map. |
811 | */ |
764 | */ |
812 | void |
765 | void |
813 | maptile::clear () |
766 | maptile::clear () |
814 | { |
767 | { |
815 | sfree (regions, size ()); regions = 0; |
|
|
816 | delete [] regionmap; regionmap = 0; |
|
|
817 | |
|
|
818 | if (spaces) |
768 | if (spaces) |
819 | { |
769 | { |
820 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
770 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
821 | while (object *op = ms->bot) |
771 | while (object *op = ms->bot) |
822 | { |
772 | { |
|
|
773 | // manually remove, as to not trigger anything |
|
|
774 | if (ms->bot = op->above) |
|
|
775 | ms->bot->below = 0; |
|
|
776 | |
|
|
777 | op->flag [FLAG_REMOVED] = true; |
|
|
778 | |
823 | op = op->head_ (); |
779 | object *head = op->head_ (); |
|
|
780 | if (op == head) |
|
|
781 | { |
824 | op->destroy_inv (false); |
782 | op->destroy_inv (false); |
825 | op->destroy (); |
783 | op->destroy (); |
|
|
784 | } |
|
|
785 | else if (head->map != op->map) |
|
|
786 | { |
|
|
787 | LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ()); |
|
|
788 | head->destroy (); |
|
|
789 | } |
826 | } |
790 | } |
827 | |
791 | |
828 | sfree (spaces, size ()), spaces = 0; |
792 | sfree (spaces, size ()), spaces = 0; |
829 | } |
793 | } |
830 | |
794 | |
831 | if (buttons) |
795 | if (buttons) |
832 | free_objectlinkpt (buttons), buttons = 0; |
796 | free_objectlinkpt (buttons), buttons = 0; |
|
|
797 | |
|
|
798 | sfree (regions, size ()); regions = 0; |
|
|
799 | delete [] regionmap; regionmap = 0; |
833 | } |
800 | } |
834 | |
801 | |
835 | void |
802 | void |
836 | maptile::clear_header () |
803 | maptile::clear_header () |
837 | { |
804 | { |
… | |
… | |
889 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
856 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
890 | break; |
857 | break; |
891 | |
858 | |
892 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) |
859 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) |
893 | || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) |
860 | || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) |
894 | || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL) |
|
|
895 | || QUERY_FLAG (op, FLAG_UNIQUE) |
861 | || QUERY_FLAG (op, FLAG_UNIQUE) |
896 | || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) |
862 | || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) |
897 | || QUERY_FLAG (op, FLAG_UNPAID) |
863 | || QUERY_FLAG (op, FLAG_UNPAID) |
898 | || op->is_alive ()) |
864 | || op->is_alive ()) |
899 | ; // do not decay |
865 | ; // do not decay |
… | |
… | |
1358 | adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy) |
1324 | adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy) |
1359 | { |
1325 | { |
1360 | if (!map1 || !map2) |
1326 | if (!map1 || !map2) |
1361 | return 0; |
1327 | return 0; |
1362 | |
1328 | |
1363 | //TODO: this doesn't actually check corretcly when intermediate maps are not loaded |
1329 | //TODO: this doesn't actually check correctly when intermediate maps are not loaded |
1364 | //fix: compare paths instead (this is likely faster, too!) |
1330 | //fix: compare paths instead (this is likely faster, too!) |
1365 | if (map1 == map2) |
1331 | if (map1 == map2) |
1366 | { |
1332 | { |
1367 | *dx = 0; |
1333 | *dx = 0; |
1368 | *dy = 0; |
1334 | *dy = 0; |
… | |
… | |
1629 | { |
1595 | { |
1630 | if (!sound) |
1596 | if (!sound) |
1631 | return; |
1597 | return; |
1632 | |
1598 | |
1633 | for_all_players (pl) |
1599 | for_all_players (pl) |
1634 | if (pl->ob->map == this) |
1600 | if (pl->observe->map == this) |
1635 | if (client *ns = pl->ns) |
1601 | if (client *ns = pl->ns) |
1636 | { |
1602 | { |
1637 | int dx = x - pl->ob->x; |
1603 | int dx = x - pl->observe->x; |
1638 | int dy = y - pl->ob->y; |
1604 | int dy = y - pl->observe->y; |
1639 | |
1605 | |
1640 | int distance = idistance (dx, dy); |
1606 | int distance = idistance (dx, dy); |
1641 | |
1607 | |
1642 | if (distance <= MAX_SOUND_DISTANCE) |
1608 | if (distance <= MAX_SOUND_DISTANCE) |
1643 | ns->play_sound (sound, dx, dy); |
1609 | ns->play_sound (sound, dx, dy); |