… | |
… | |
221 | SET_FLAG (ob1, FLAG_BEEN_APPLIED); |
221 | SET_FLAG (ob1, FLAG_BEEN_APPLIED); |
222 | |
222 | |
223 | if (QUERY_FLAG (ob2, FLAG_IDENTIFIED)) |
223 | if (QUERY_FLAG (ob2, FLAG_IDENTIFIED)) |
224 | SET_FLAG (ob2, FLAG_BEEN_APPLIED); |
224 | SET_FLAG (ob2, FLAG_BEEN_APPLIED); |
225 | |
225 | |
226 | if ((ob1->flags ^ ob2->flags).reset (FLAG_INV_LOCKED).reset (FLAG_CLIENT_SENT).any () |
226 | if ((ob1->flag ^ ob2->flag).reset (FLAG_INV_LOCKED).reset (FLAG_CLIENT_SENT).any () |
227 | || ob1->arch != ob2->arch |
227 | || ob1->arch != ob2->arch |
228 | || ob1->name != ob2->name |
228 | || ob1->name != ob2->name |
229 | || ob1->title != ob2->title |
229 | || ob1->title != ob2->title |
230 | || ob1->msg != ob2->msg |
230 | || ob1->msg != ob2->msg |
231 | || ob1->weight != ob2->weight |
231 | || ob1->weight != ob2->weight |
… | |
… | |
467 | } |
467 | } |
468 | |
468 | |
469 | op->key_values = 0; |
469 | op->key_values = 0; |
470 | } |
470 | } |
471 | |
471 | |
472 | void object::clear () |
|
|
473 | { |
|
|
474 | attachable_base::clear (); |
|
|
475 | |
|
|
476 | free_key_values (this); |
|
|
477 | |
|
|
478 | owner = 0; |
|
|
479 | name = 0; |
|
|
480 | name_pl = 0; |
|
|
481 | title = 0; |
|
|
482 | race = 0; |
|
|
483 | slaying = 0; |
|
|
484 | skill = 0; |
|
|
485 | msg = 0; |
|
|
486 | lore = 0; |
|
|
487 | custom_name = 0; |
|
|
488 | materialname = 0; |
|
|
489 | contr = 0; |
|
|
490 | below = 0; |
|
|
491 | above = 0; |
|
|
492 | inv = 0; |
|
|
493 | container = 0; |
|
|
494 | env = 0; |
|
|
495 | more = 0; |
|
|
496 | head = 0; |
|
|
497 | map = 0; |
|
|
498 | active_next = 0; |
|
|
499 | active_prev = 0; |
|
|
500 | |
|
|
501 | memset (static_cast<object_pod *>(this), 0, sizeof (object_pod)); |
|
|
502 | |
|
|
503 | SET_FLAG (this, FLAG_REMOVED); |
|
|
504 | |
|
|
505 | /* What is not cleared is next, prev, and count */ |
|
|
506 | |
|
|
507 | expmul = 1.0; |
|
|
508 | face = blank_face; |
|
|
509 | |
|
|
510 | if (settings.casting_time) |
|
|
511 | casting_time = -1; |
|
|
512 | } |
|
|
513 | |
|
|
514 | /* |
472 | /* |
515 | * copy_to first frees everything allocated by the dst object, |
473 | * copy_to first frees everything allocated by the dst object, |
516 | * and then copies the contents of itself into the second |
474 | * and then copies the contents of itself into the second |
517 | * object, allocating what needs to be allocated. Basically, any |
475 | * object, allocating what needs to be allocated. Basically, any |
518 | * data that is malloc'd needs to be re-malloc/copied. Otherwise, |
476 | * data that is malloc'd needs to be re-malloc/copied. Otherwise, |
… | |
… | |
524 | { |
482 | { |
525 | bool is_freed = QUERY_FLAG (dst, FLAG_FREED); |
483 | bool is_freed = QUERY_FLAG (dst, FLAG_FREED); |
526 | bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED); |
484 | bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED); |
527 | |
485 | |
528 | *(object_copy *)dst = *this; |
486 | *(object_copy *)dst = *this; |
529 | *(object_pod *)dst = *this; |
|
|
530 | |
487 | |
531 | if (self || cb) |
488 | if (self || cb) |
532 | INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); |
489 | INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); |
533 | |
490 | |
534 | if (is_freed) |
491 | if (is_freed) |
… | |
… | |
694 | op->active_next = NULL; |
651 | op->active_next = NULL; |
695 | op->active_prev = NULL; |
652 | op->active_prev = NULL; |
696 | } |
653 | } |
697 | |
654 | |
698 | /* |
655 | /* |
699 | * update_object() updates the array which represents the map. |
656 | * update_object() updates the the map. |
700 | * It takes into account invisible objects (and represent squares covered |
657 | * It takes into account invisible objects (and represent squares covered |
701 | * by invisible objects by whatever is below them (unless it's another |
658 | * by invisible objects by whatever is below them (unless it's another |
702 | * invisible object, etc...) |
659 | * invisible object, etc...) |
703 | * If the object being updated is beneath a player, the look-window |
660 | * If the object being updated is beneath a player, the look-window |
704 | * of that player is updated (this might be a suboptimal way of |
661 | * of that player is updated (this might be a suboptimal way of |
705 | * updating that window, though, since update_object() is called _often_) |
662 | * updating that window, though, since update_object() is called _often_) |
706 | * |
663 | * |
707 | * action is a hint of what the caller believes need to be done. |
664 | * action is a hint of what the caller believes need to be done. |
708 | * For example, if the only thing that has changed is the face (due to |
|
|
709 | * an animation), we don't need to call update_position until that actually |
|
|
710 | * comes into view of a player. OTOH, many other things, like addition/removal |
|
|
711 | * of walls or living creatures may need us to update the flags now. |
|
|
712 | * current action are: |
665 | * current action are: |
713 | * UP_OBJ_INSERT: op was inserted |
666 | * UP_OBJ_INSERT: op was inserted |
714 | * UP_OBJ_REMOVE: op was removed |
667 | * UP_OBJ_REMOVE: op was removed |
715 | * UP_OBJ_CHANGE: object has somehow changed. In this case, we always update |
668 | * UP_OBJ_CHANGE: object has somehow changed. In this case, we always update |
716 | * as that is easier than trying to look at what may have changed. |
669 | * as that is easier than trying to look at what may have changed. |
717 | * UP_OBJ_FACE: only the objects face has changed. |
670 | * UP_OBJ_FACE: only the objects face has changed. |
718 | */ |
671 | */ |
719 | |
|
|
720 | void |
672 | void |
721 | update_object (object *op, int action) |
673 | update_object (object *op, int action) |
722 | { |
674 | { |
723 | int update_now = 0, flags; |
|
|
724 | MoveType move_on, move_off, move_block, move_slow; |
675 | MoveType move_on, move_off, move_block, move_slow; |
725 | |
676 | |
726 | if (op == NULL) |
677 | if (op == NULL) |
727 | { |
678 | { |
728 | /* this should never happen */ |
679 | /* this should never happen */ |
729 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
680 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
730 | return; |
681 | return; |
731 | } |
682 | } |
732 | |
683 | |
733 | if (op->env != NULL) |
684 | if (op->env) |
734 | { |
685 | { |
735 | /* Animation is currently handled by client, so nothing |
686 | /* Animation is currently handled by client, so nothing |
736 | * to do in this case. |
687 | * to do in this case. |
737 | */ |
688 | */ |
738 | return; |
689 | return; |
… | |
… | |
752 | abort (); |
703 | abort (); |
753 | #endif |
704 | #endif |
754 | return; |
705 | return; |
755 | } |
706 | } |
756 | |
707 | |
757 | flags = GET_MAP_FLAGS (op->map, op->x, op->y); |
708 | mapspace &m = op->ms (); |
758 | SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NEED_UPDATE); |
|
|
759 | move_slow = GET_MAP_MOVE_SLOW (op->map, op->x, op->y); |
|
|
760 | move_on = GET_MAP_MOVE_ON (op->map, op->x, op->y); |
|
|
761 | move_block = GET_MAP_MOVE_BLOCK (op->map, op->x, op->y); |
|
|
762 | move_off = GET_MAP_MOVE_OFF (op->map, op->x, op->y); |
|
|
763 | |
709 | |
|
|
710 | if (m.flags_ & P_NEED_UPDATE) |
|
|
711 | /* nop */; |
764 | if (action == UP_OBJ_INSERT) |
712 | else if (action == UP_OBJ_INSERT) |
765 | { |
713 | { |
|
|
714 | // this is likely overkill, TODO: revisit (schmorp) |
766 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(flags & P_BLOCKSVIEW)) |
715 | if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) |
767 | update_now = 1; |
|
|
768 | |
|
|
769 | if (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(flags & P_NO_MAGIC)) |
716 | || (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(m.flags_ & P_NO_MAGIC)) |
770 | update_now = 1; |
717 | || (op->type == PLAYER && !(m.flags_ & P_PLAYER)) |
771 | |
718 | || (op->type == SAFE_GROUND && !(m.flags_ & P_SAFE)) |
|
|
719 | || (QUERY_FLAG (op, FLAG_ALIVE) && !(m.flags_ & P_IS_ALIVE)) |
772 | if (QUERY_FLAG (op, FLAG_DAMNED) && !(flags & P_NO_CLERIC)) |
720 | || (QUERY_FLAG (op, FLAG_DAMNED) && !(m.flags_ & P_NO_CLERIC)) |
773 | update_now = 1; |
|
|
774 | |
|
|
775 | if (QUERY_FLAG (op, FLAG_ALIVE) && !(flags & P_IS_ALIVE)) |
|
|
776 | update_now = 1; |
|
|
777 | |
|
|
778 | if (op->type == SAFE_GROUND && !(flags & P_SAFE)) |
|
|
779 | update_now = 1; |
|
|
780 | |
|
|
781 | if ((move_on | op->move_on) != move_on) |
721 | || (m.move_on | op->move_on ) != m.move_on |
782 | update_now = 1; |
|
|
783 | |
|
|
784 | if ((move_off | op->move_off) != move_off) |
722 | || (m.move_off | op->move_off ) != m.move_off |
785 | update_now = 1; |
723 | || (m.move_slow | op->move_slow) != m.move_slow |
786 | |
|
|
787 | /* This isn't perfect, but I don't expect a lot of objects to |
724 | /* This isn't perfect, but I don't expect a lot of objects to |
788 | * to have move_allow right now. |
725 | * to have move_allow right now. |
789 | */ |
726 | */ |
790 | if (((move_block | op->move_block) & ~op->move_allow) != move_block) |
727 | || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block |
791 | update_now = 1; |
728 | || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) |
792 | |
729 | m.flags_ = P_NEED_UPDATE; |
793 | if ((move_slow | op->move_slow) != move_slow) |
|
|
794 | update_now = 1; |
|
|
795 | } |
730 | } |
796 | |
|
|
797 | /* if the object is being removed, we can't make intelligent |
731 | /* if the object is being removed, we can't make intelligent |
798 | * decisions, because remove_ob can't really pass the object |
732 | * decisions, because remove_ob can't really pass the object |
799 | * that is being removed. |
733 | * that is being removed. |
800 | */ |
734 | */ |
801 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
735 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
802 | update_now = 1; |
736 | m.flags_ = P_NEED_UPDATE; |
803 | else if (action == UP_OBJ_FACE) |
737 | else if (action == UP_OBJ_FACE) |
804 | /* Nothing to do for that case */ ; |
738 | /* Nothing to do for that case */ ; |
805 | else |
739 | else |
806 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
740 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
807 | |
741 | |
808 | if (update_now) |
|
|
809 | { |
|
|
810 | SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NO_ERROR | P_NEED_UPDATE); |
|
|
811 | update_position (op->map, op->x, op->y); |
|
|
812 | } |
|
|
813 | |
|
|
814 | if (op->more != NULL) |
742 | if (op->more) |
815 | update_object (op->more, action); |
743 | update_object (op->more, action); |
816 | } |
744 | } |
817 | |
745 | |
818 | object::vector object::mortals; |
746 | object::vector object::mortals; |
819 | object::vector object::objects; // not yet used |
747 | object::vector object::objects; // not yet used |
… | |
… | |
1041 | /* NO_FIX_PLAYER is set when a great many changes are being |
969 | /* NO_FIX_PLAYER is set when a great many changes are being |
1042 | * made to players inventory. If set, avoiding the call |
970 | * made to players inventory. If set, avoiding the call |
1043 | * to save cpu time. |
971 | * to save cpu time. |
1044 | */ |
972 | */ |
1045 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
973 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1046 | fix_player (otmp); |
974 | otmp->update_stats (); |
1047 | |
975 | |
1048 | if (above != NULL) |
976 | if (above != NULL) |
1049 | above->below = below; |
977 | above->below = below; |
1050 | else |
978 | else |
1051 | env->inv = below; |
979 | env->inv = below; |
… | |
… | |
1070 | |
998 | |
1071 | /* link the object above us */ |
999 | /* link the object above us */ |
1072 | if (above) |
1000 | if (above) |
1073 | above->below = below; |
1001 | above->below = below; |
1074 | else |
1002 | else |
1075 | SET_MAP_TOP (map, x, y, below); /* we were top, set new top */ |
1003 | map->at (x, y).top = below; /* we were top, set new top */ |
1076 | |
1004 | |
1077 | /* Relink the object below us, if there is one */ |
1005 | /* Relink the object below us, if there is one */ |
1078 | if (below) |
1006 | if (below) |
1079 | below->above = above; |
1007 | below->above = above; |
1080 | else |
1008 | else |
… | |
… | |
1092 | dump = dump_object (GET_MAP_OB (map, x, y)); |
1020 | dump = dump_object (GET_MAP_OB (map, x, y)); |
1093 | LOG (llevError, "%s\n", dump); |
1021 | LOG (llevError, "%s\n", dump); |
1094 | free (dump); |
1022 | free (dump); |
1095 | } |
1023 | } |
1096 | |
1024 | |
1097 | SET_MAP_OB (map, x, y, above); /* goes on above it. */ |
1025 | map->at (x, y).bottom = above; /* goes on above it. */ |
1098 | } |
1026 | } |
1099 | |
1027 | |
1100 | above = 0; |
1028 | above = 0; |
1101 | below = 0; |
1029 | below = 0; |
1102 | |
1030 | |
… | |
… | |
1121 | { |
1049 | { |
1122 | CLEAR_FLAG (this, FLAG_APPLIED); |
1050 | CLEAR_FLAG (this, FLAG_APPLIED); |
1123 | tmp->container = 0; |
1051 | tmp->container = 0; |
1124 | } |
1052 | } |
1125 | |
1053 | |
1126 | tmp->contr->socket->floorbox_update (); |
1054 | tmp->contr->ns->floorbox_update (); |
1127 | } |
1055 | } |
1128 | |
1056 | |
1129 | /* See if player moving off should effect something */ |
1057 | /* See if player moving off should effect something */ |
1130 | if (check_walk_off |
1058 | if (check_walk_off |
1131 | && ((move_type & tmp->move_off) |
1059 | && ((move_type & tmp->move_off) |
… | |
… | |
1145 | last = tmp; |
1073 | last = tmp; |
1146 | } |
1074 | } |
1147 | |
1075 | |
1148 | /* last == NULL of there are no objects on this space */ |
1076 | /* last == NULL of there are no objects on this space */ |
1149 | if (!last) |
1077 | if (!last) |
1150 | { |
1078 | map->at (x, y).flags_ = P_NEED_UPDATE; |
1151 | /* set P_NEED_UPDATE, otherwise update_position will complain. In theory, |
|
|
1152 | * we could preserve the flags (GET_MAP_FLAGS), but update_position figures |
|
|
1153 | * those out anyways, and if there are any flags set right now, they won't |
|
|
1154 | * be correct anyways. |
|
|
1155 | */ |
|
|
1156 | SET_MAP_FLAGS (map, x, y, P_NEED_UPDATE); |
|
|
1157 | update_position (map, x, y); |
|
|
1158 | } |
|
|
1159 | else |
1079 | else |
1160 | update_object (last, UP_OBJ_REMOVE); |
1080 | update_object (last, UP_OBJ_REMOVE); |
1161 | |
1081 | |
1162 | if (QUERY_FLAG (this, FLAG_BLOCKSVIEW) || glow_radius) |
1082 | if (QUERY_FLAG (this, FLAG_BLOCKSVIEW) || glow_radius) |
1163 | update_all_los (map, x, y); |
1083 | update_all_los (map, x, y); |
… | |
… | |
1353 | op->below = originator->below; |
1273 | op->below = originator->below; |
1354 | |
1274 | |
1355 | if (op->below) |
1275 | if (op->below) |
1356 | op->below->above = op; |
1276 | op->below->above = op; |
1357 | else |
1277 | else |
1358 | SET_MAP_OB (op->map, op->x, op->y, op); |
1278 | op->ms ().bottom = op; |
1359 | |
1279 | |
1360 | /* since *below* originator, no need to update top */ |
1280 | /* since *below* originator, no need to update top */ |
1361 | originator->below = op; |
1281 | originator->below = op; |
1362 | } |
1282 | } |
1363 | else |
1283 | else |
… | |
… | |
1409 | * If INS_ON_TOP is used, don't do this processing |
1329 | * If INS_ON_TOP is used, don't do this processing |
1410 | * Need to find the object that in fact blocks view, otherwise |
1330 | * Need to find the object that in fact blocks view, otherwise |
1411 | * stacking is a bit odd. |
1331 | * stacking is a bit odd. |
1412 | */ |
1332 | */ |
1413 | if (!(flag & INS_ON_TOP) && |
1333 | if (!(flag & INS_ON_TOP) && |
1414 | (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_BLOCKSVIEW) && (op->face && !op->face->visibility)) |
1334 | (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_BLOCKSVIEW) && (op->face && !op->face->visibility)) |
1415 | { |
1335 | { |
1416 | for (last = top; last != floor; last = last->below) |
1336 | for (last = top; last != floor; last = last->below) |
1417 | if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) |
1337 | if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) |
1418 | break; |
1338 | break; |
1419 | /* Check to see if we found the object that blocks view, |
1339 | /* Check to see if we found the object that blocks view, |
… | |
… | |
1442 | |
1362 | |
1443 | if (op->above) |
1363 | if (op->above) |
1444 | op->above->below = op; |
1364 | op->above->below = op; |
1445 | |
1365 | |
1446 | op->below = NULL; |
1366 | op->below = NULL; |
1447 | SET_MAP_OB (op->map, op->x, op->y, op); |
1367 | op->ms ().bottom = op; |
1448 | } |
1368 | } |
1449 | else |
1369 | else |
1450 | { /* get inserted into the stack above top */ |
1370 | { /* get inserted into the stack above top */ |
1451 | op->above = top->above; |
1371 | op->above = top->above; |
1452 | |
1372 | |
… | |
… | |
1456 | op->below = top; |
1376 | op->below = top; |
1457 | top->above = op; |
1377 | top->above = op; |
1458 | } |
1378 | } |
1459 | |
1379 | |
1460 | if (op->above == NULL) |
1380 | if (op->above == NULL) |
1461 | SET_MAP_TOP (op->map, op->x, op->y, op); |
1381 | op->ms ().top = op; |
1462 | } /* else not INS_BELOW_ORIGINATOR */ |
1382 | } /* else not INS_BELOW_ORIGINATOR */ |
1463 | |
1383 | |
1464 | if (op->type == PLAYER) |
1384 | if (op->type == PLAYER) |
1465 | op->contr->do_los = 1; |
1385 | op->contr->do_los = 1; |
1466 | |
1386 | |
1467 | /* If we have a floor, we know the player, if any, will be above |
1387 | /* If we have a floor, we know the player, if any, will be above |
1468 | * it, so save a few ticks and start from there. |
1388 | * it, so save a few ticks and start from there. |
1469 | */ |
1389 | */ |
1470 | if (!(flag & INS_MAP_LOAD)) |
1390 | if (!(flag & INS_MAP_LOAD)) |
1471 | for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1391 | if (object *pl = op->ms ().player ()) |
1472 | if (tmp->type == PLAYER) |
|
|
1473 | tmp->contr->socket->floorbox_update (); |
1392 | pl->contr->ns->floorbox_update (); |
1474 | |
1393 | |
1475 | /* If this object glows, it may affect lighting conditions that are |
1394 | /* If this object glows, it may affect lighting conditions that are |
1476 | * visible to others on this map. But update_all_los is really |
1395 | * visible to others on this map. But update_all_los is really |
1477 | * an inefficient way to do this, as it means los for all players |
1396 | * an inefficient way to do this, as it means los for all players |
1478 | * on the map will get recalculated. The players could very well |
1397 | * on the map will get recalculated. The players could very well |
… | |
… | |
1512 | |
1431 | |
1513 | return op; |
1432 | return op; |
1514 | } |
1433 | } |
1515 | |
1434 | |
1516 | /* this function inserts an object in the map, but if it |
1435 | /* this function inserts an object in the map, but if it |
1517 | * finds an object of its own type, it'll remove that one first. |
1436 | * finds an object of its own type, it'll remove that one first. |
1518 | * op is the object to insert it under: supplies x and the map. |
1437 | * op is the object to insert it under: supplies x and the map. |
1519 | */ |
1438 | */ |
1520 | void |
1439 | void |
1521 | replace_insert_ob_in_map (const char *arch_string, object *op) |
1440 | replace_insert_ob_in_map (const char *arch_string, object *op) |
1522 | { |
1441 | { |
1523 | object * |
1442 | object *tmp, *tmp1; |
1524 | tmp; |
|
|
1525 | object * |
|
|
1526 | tmp1; |
|
|
1527 | |
1443 | |
1528 | /* first search for itself and remove any old instances */ |
1444 | /* first search for itself and remove any old instances */ |
1529 | |
1445 | |
1530 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1446 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1531 | if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ |
1447 | if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ |
… | |
… | |
1589 | |
1505 | |
1590 | object * |
1506 | object * |
1591 | decrease_ob_nr (object *op, uint32 i) |
1507 | decrease_ob_nr (object *op, uint32 i) |
1592 | { |
1508 | { |
1593 | object *tmp; |
1509 | object *tmp; |
1594 | player *pl; |
|
|
1595 | |
1510 | |
1596 | if (i == 0) /* objects with op->nrof require this check */ |
1511 | if (i == 0) /* objects with op->nrof require this check */ |
1597 | return op; |
1512 | return op; |
1598 | |
1513 | |
1599 | if (i > op->nrof) |
1514 | if (i > op->nrof) |
… | |
… | |
1612 | * IMO, searching through all the players will mostly |
1527 | * IMO, searching through all the players will mostly |
1613 | * likely be quicker than following op->env to the map, |
1528 | * likely be quicker than following op->env to the map, |
1614 | * and then searching the map for a player. |
1529 | * and then searching the map for a player. |
1615 | */ |
1530 | */ |
1616 | if (!tmp) |
1531 | if (!tmp) |
1617 | { |
1532 | for_all_players (pl) |
1618 | for (pl = first_player; pl; pl = pl->next) |
|
|
1619 | if (pl->ob->container == op->env) |
1533 | if (pl->ob->container == op->env) |
1620 | { |
1534 | { |
1621 | tmp = pl->ob; |
1535 | tmp = pl->ob; |
1622 | break; |
1536 | break; |
1623 | } |
1537 | } |
1624 | } |
|
|
1625 | |
1538 | |
1626 | if (i < op->nrof) |
1539 | if (i < op->nrof) |
1627 | { |
1540 | { |
1628 | sub_weight (op->env, op->weight * i); |
1541 | sub_weight (op->env, op->weight * i); |
1629 | op->nrof -= i; |
1542 | op->nrof -= i; |
… | |
… | |
1765 | add_weight (this, (op->weight + op->carrying)); |
1678 | add_weight (this, (op->weight + op->carrying)); |
1766 | |
1679 | |
1767 | otmp = this->in_player (); |
1680 | otmp = this->in_player (); |
1768 | if (otmp && otmp->contr) |
1681 | if (otmp && otmp->contr) |
1769 | if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1682 | if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1770 | fix_player (otmp); |
1683 | otmp->update_stats (); |
1771 | |
1684 | |
1772 | op->map = 0; |
1685 | op->map = 0; |
1773 | op->env = this; |
1686 | op->env = this; |
1774 | op->above = 0; |
1687 | op->above = 0; |
1775 | op->below = 0; |
1688 | op->below = 0; |
… | |
… | |
2241 | mp = m; |
2154 | mp = m; |
2242 | nx = x + freearr_x[i]; |
2155 | nx = x + freearr_x[i]; |
2243 | ny = y + freearr_y[i]; |
2156 | ny = y + freearr_y[i]; |
2244 | |
2157 | |
2245 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
2158 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
|
|
2159 | |
2246 | if (mflags & P_OUT_OF_MAP) |
2160 | if (mflags & P_OUT_OF_MAP) |
2247 | { |
|
|
2248 | max = maxfree[i]; |
2161 | max = maxfree[i]; |
2249 | } |
|
|
2250 | else |
2162 | else |
2251 | { |
2163 | { |
2252 | blocked = GET_MAP_MOVE_BLOCK (mp, nx, ny); |
2164 | blocked = GET_MAP_MOVE_BLOCK (mp, nx, ny); |
2253 | |
2165 | |
2254 | if ((move_type & blocked) == move_type) |
2166 | if ((move_type & blocked) == move_type) |
2255 | { |
|
|
2256 | max = maxfree[i]; |
2167 | max = maxfree[i]; |
2257 | } |
|
|
2258 | else if (mflags & P_IS_ALIVE) |
2168 | else if (mflags & P_IS_ALIVE) |
2259 | { |
2169 | { |
2260 | for (tmp = GET_MAP_OB (mp, nx, ny); tmp != NULL; tmp = tmp->above) |
2170 | for (tmp = GET_MAP_OB (mp, nx, ny); tmp; tmp = tmp->above) |
2261 | { |
|
|
2262 | if ((QUERY_FLAG (tmp, FLAG_MONSTER) || tmp->type == PLAYER) && (tmp != exclude || (tmp->head && tmp->head != exclude))) |
2171 | if ((QUERY_FLAG (tmp, FLAG_MONSTER) || tmp->type == PLAYER) && (tmp != exclude || (tmp->head && tmp->head != exclude))) |
2263 | { |
|
|
2264 | break; |
2172 | break; |
2265 | } |
2173 | |
2266 | } |
|
|
2267 | if (tmp) |
2174 | if (tmp) |
2268 | { |
|
|
2269 | return freedir[i]; |
2175 | return freedir[i]; |
2270 | } |
|
|
2271 | } |
2176 | } |
2272 | } |
2177 | } |
2273 | } |
2178 | } |
|
|
2179 | |
2274 | return 0; |
2180 | return 0; |
2275 | } |
2181 | } |
2276 | |
2182 | |
2277 | /* |
2183 | /* |
2278 | * distance(object 1, object 2) will return the square of the |
2184 | * distance(object 1, object 2) will return the square of the |
… | |
… | |
2280 | */ |
2186 | */ |
2281 | |
2187 | |
2282 | int |
2188 | int |
2283 | distance (const object *ob1, const object *ob2) |
2189 | distance (const object *ob1, const object *ob2) |
2284 | { |
2190 | { |
2285 | int |
2191 | int i; |
2286 | i; |
|
|
2287 | |
2192 | |
2288 | i = (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y); |
2193 | i = (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y); |
2289 | return i; |
2194 | return i; |
2290 | } |
2195 | } |
2291 | |
2196 | |
… | |
… | |
2296 | */ |
2201 | */ |
2297 | |
2202 | |
2298 | int |
2203 | int |
2299 | find_dir_2 (int x, int y) |
2204 | find_dir_2 (int x, int y) |
2300 | { |
2205 | { |
2301 | int |
2206 | int q; |
2302 | q; |
|
|
2303 | |
2207 | |
2304 | if (y) |
2208 | if (y) |
2305 | q = x * 100 / y; |
2209 | q = x * 100 / y; |
2306 | else if (x) |
2210 | else if (x) |
2307 | q = -300 * x; |
2211 | q = -300 * x; |
… | |
… | |
2433 | * find a path to that monster that we found. If not, |
2337 | * find a path to that monster that we found. If not, |
2434 | * we don't bother going toward it. Returns 1 if we |
2338 | * we don't bother going toward it. Returns 1 if we |
2435 | * can see a direct way to get it |
2339 | * can see a direct way to get it |
2436 | * Modified to be map tile aware -.MSW |
2340 | * Modified to be map tile aware -.MSW |
2437 | */ |
2341 | */ |
2438 | |
|
|
2439 | |
|
|
2440 | int |
2342 | int |
2441 | can_see_monsterP (maptile *m, int x, int y, int dir) |
2343 | can_see_monsterP (maptile *m, int x, int y, int dir) |
2442 | { |
2344 | { |
2443 | sint16 dx, dy; |
2345 | sint16 dx, dy; |
2444 | int |
|
|
2445 | mflags; |
2346 | int mflags; |
2446 | |
2347 | |
2447 | if (dir < 0) |
2348 | if (dir < 0) |
2448 | return 0; /* exit condition: invalid direction */ |
2349 | return 0; /* exit condition: invalid direction */ |
2449 | |
2350 | |
2450 | dx = x + freearr_x[dir]; |
2351 | dx = x + freearr_x[dir]; |
… | |
… | |
2463 | return 0; |
2364 | return 0; |
2464 | |
2365 | |
2465 | /* yes, can see. */ |
2366 | /* yes, can see. */ |
2466 | if (dir < 9) |
2367 | if (dir < 9) |
2467 | return 1; |
2368 | return 1; |
|
|
2369 | |
2468 | return can_see_monsterP (m, x, y, reduction_dir[dir][0]) | |
2370 | return can_see_monsterP (m, x, y, reduction_dir[dir][0]) |
2469 | can_see_monsterP (m, x, y, reduction_dir[dir][1]) | can_see_monsterP (m, x, y, reduction_dir[dir][2]); |
2371 | | can_see_monsterP (m, x, y, reduction_dir[dir][1]) |
|
|
2372 | | can_see_monsterP (m, x, y, reduction_dir[dir][2]); |
2470 | } |
2373 | } |
2471 | |
|
|
2472 | |
|
|
2473 | |
2374 | |
2474 | /* |
2375 | /* |
2475 | * can_pick(picker, item): finds out if an object is possible to be |
2376 | * can_pick(picker, item): finds out if an object is possible to be |
2476 | * picked up by the picker. Returnes 1 if it can be |
2377 | * picked up by the picker. Returnes 1 if it can be |
2477 | * picked up, otherwise 0. |
2378 | * picked up, otherwise 0. |
… | |
… | |
2488 | return /*QUERY_FLAG(who,FLAG_WIZ)|| */ |
2389 | return /*QUERY_FLAG(who,FLAG_WIZ)|| */ |
2489 | (item->weight > 0 && !QUERY_FLAG (item, FLAG_NO_PICK) && |
2390 | (item->weight > 0 && !QUERY_FLAG (item, FLAG_NO_PICK) && |
2490 | !QUERY_FLAG (item, FLAG_ALIVE) && !item->invisible && (who->type == PLAYER || item->weight < who->weight / 3)); |
2391 | !QUERY_FLAG (item, FLAG_ALIVE) && !item->invisible && (who->type == PLAYER || item->weight < who->weight / 3)); |
2491 | } |
2392 | } |
2492 | |
2393 | |
2493 | |
|
|
2494 | /* |
2394 | /* |
2495 | * create clone from object to another |
2395 | * create clone from object to another |
2496 | */ |
2396 | */ |
2497 | object * |
2397 | object * |
2498 | object_create_clone (object *asrc) |
2398 | object_create_clone (object *asrc) |
… | |
… | |
2517 | { |
2417 | { |
2518 | dst = tmp; |
2418 | dst = tmp; |
2519 | tmp->head = 0; |
2419 | tmp->head = 0; |
2520 | } |
2420 | } |
2521 | else |
2421 | else |
2522 | { |
|
|
2523 | tmp->head = dst; |
2422 | tmp->head = dst; |
2524 | } |
|
|
2525 | |
2423 | |
2526 | tmp->more = 0; |
2424 | tmp->more = 0; |
2527 | |
2425 | |
2528 | if (prev) |
2426 | if (prev) |
2529 | prev->more = tmp; |
2427 | prev->more = tmp; |