1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_object_c = |
|
|
4 | * "$Id: object.C,v 1.24 2006/09/10 16:00:23 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
1 | |
7 | /* |
2 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
9 | |
4 | |
10 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
… | |
… | |
29 | |
24 | |
30 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
25 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
31 | sub/add_weight will transcend the environment updating the carrying |
26 | sub/add_weight will transcend the environment updating the carrying |
32 | variable. */ |
27 | variable. */ |
33 | #include <global.h> |
28 | #include <global.h> |
34 | #ifndef WIN32 /* ---win32 exclude headers */ |
|
|
35 | # include <stdio.h> |
29 | #include <stdio.h> |
36 | # include <sys/types.h> |
30 | #include <sys/types.h> |
37 | # include <sys/uio.h> |
31 | #include <sys/uio.h> |
38 | #endif /* win32 */ |
|
|
39 | #include <object.h> |
32 | #include <object.h> |
40 | #include <funcpoint.h> |
33 | #include <funcpoint.h> |
41 | #include <skills.h> |
34 | #include <skills.h> |
42 | #include <loader.h> |
35 | #include <loader.h> |
|
|
36 | |
43 | int nrofallocobjects = 0; |
37 | int nrofallocobjects = 0; |
44 | |
38 | |
45 | object *objects; /* Pointer to the list of used objects */ |
39 | object *objects; /* Pointer to the list of used objects */ |
46 | object *active_objects; /* List of active objects that need to be processed */ |
40 | object *active_objects; /* List of active objects that need to be processed */ |
47 | |
41 | |
… | |
… | |
214 | if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && FABS ((ob1)->speed) > MIN_ACTIVE_SPEED) |
208 | if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && FABS ((ob1)->speed) > MIN_ACTIVE_SPEED) |
215 | return 0; |
209 | return 0; |
216 | |
210 | |
217 | switch (ob1->type) |
211 | switch (ob1->type) |
218 | { |
212 | { |
219 | case SCROLL: |
213 | case SCROLL: |
220 | if (ob1->level != ob2->level) |
214 | if (ob1->level != ob2->level) |
221 | return 0; |
215 | return 0; |
222 | break; |
216 | break; |
223 | } |
217 | } |
224 | |
218 | |
225 | if (ob1->key_values != NULL || ob2->key_values != NULL) |
219 | if (ob1->key_values != NULL || ob2->key_values != NULL) |
226 | { |
220 | { |
227 | /* At least one of these has key_values. */ |
221 | /* At least one of these has key_values. */ |
… | |
… | |
249 | /* |
243 | /* |
250 | * sum_weight() is a recursive function which calculates the weight |
244 | * sum_weight() is a recursive function which calculates the weight |
251 | * an object is carrying. It goes through in figures out how much |
245 | * an object is carrying. It goes through in figures out how much |
252 | * containers are carrying, and sums it up. |
246 | * containers are carrying, and sums it up. |
253 | */ |
247 | */ |
254 | signed long |
248 | long |
255 | sum_weight (object *op) |
249 | sum_weight (object *op) |
256 | { |
250 | { |
257 | signed long sum; |
251 | long sum; |
258 | object *inv; |
252 | object *inv; |
259 | |
253 | |
260 | for (sum = 0, inv = op->inv; inv != NULL; inv = inv->below) |
254 | for (sum = 0, inv = op->inv; inv != NULL; inv = inv->below) |
261 | { |
255 | { |
262 | if (inv->inv) |
256 | if (inv->inv) |
… | |
… | |
507 | |
501 | |
508 | op->owner = owner; |
502 | op->owner = owner; |
509 | |
503 | |
510 | op->ownercount = owner->count; |
504 | op->ownercount = owner->count; |
511 | owner->refcount++; |
505 | owner->refcount++; |
512 | |
|
|
513 | } |
506 | } |
514 | |
507 | |
515 | /* Set the owner to clone's current owner and set the skill and experience |
508 | /* Set the owner to clone's current owner and set the skill and experience |
516 | * objects to clone's objects (typically those objects that where the owner's |
509 | * objects to clone's objects (typically those objects that where the owner's |
517 | * current skill and experience objects at the time when clone's owner was |
510 | * current skill and experience objects at the time when clone's owner was |
… | |
… | |
535 | if (clone->type == PLAYER) |
528 | if (clone->type == PLAYER) |
536 | owner = clone; |
529 | owner = clone; |
537 | else |
530 | else |
538 | return; |
531 | return; |
539 | } |
532 | } |
|
|
533 | |
540 | set_owner (op, owner); |
534 | set_owner (op, owner); |
541 | |
|
|
542 | } |
535 | } |
543 | |
536 | |
544 | /* Zero the key_values on op, decrementing the shared-string |
537 | /* Zero the key_values on op, decrementing the shared-string |
545 | * refcounts and freeing the links. |
538 | * refcounts and freeing the links. |
546 | */ |
539 | */ |
… | |
… | |
561 | void object::clear () |
554 | void object::clear () |
562 | { |
555 | { |
563 | attachable_base::clear (); |
556 | attachable_base::clear (); |
564 | |
557 | |
565 | free_key_values (this); |
558 | free_key_values (this); |
|
|
559 | |
|
|
560 | clear_owner (this); |
566 | |
561 | |
567 | name = 0; |
562 | name = 0; |
568 | name_pl = 0; |
563 | name_pl = 0; |
569 | title = 0; |
564 | title = 0; |
570 | race = 0; |
565 | race = 0; |
… | |
… | |
890 | /* if the object is being removed, we can't make intelligent |
885 | /* if the object is being removed, we can't make intelligent |
891 | * decisions, because remove_ob can't really pass the object |
886 | * decisions, because remove_ob can't really pass the object |
892 | * that is being removed. |
887 | * that is being removed. |
893 | */ |
888 | */ |
894 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
889 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
895 | { |
|
|
896 | update_now = 1; |
890 | update_now = 1; |
897 | } |
|
|
898 | else if (action == UP_OBJ_FACE) |
891 | else if (action == UP_OBJ_FACE) |
899 | { |
|
|
900 | /* Nothing to do for that case */ |
892 | /* Nothing to do for that case */ ; |
901 | } |
|
|
902 | else |
893 | else |
903 | { |
|
|
904 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
894 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
905 | } |
|
|
906 | |
895 | |
907 | if (update_now) |
896 | if (update_now) |
908 | { |
897 | { |
909 | SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NO_ERROR | P_NEED_UPDATE); |
898 | SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NO_ERROR | P_NEED_UPDATE); |
910 | update_position (op->map, op->x, op->y); |
899 | update_position (op->map, op->x, op->y); |
… | |
… | |
912 | |
901 | |
913 | if (op->more != NULL) |
902 | if (op->more != NULL) |
914 | update_object (op->more, action); |
903 | update_object (op->more, action); |
915 | } |
904 | } |
916 | |
905 | |
|
|
906 | static unordered_vector < object *>mortals; |
917 | static |
907 | static |
918 | std::vector < object *> |
908 | std::vector < object *> |
919 | mortals; |
909 | freed; |
920 | |
910 | |
921 | void object::free_mortals () |
911 | void object::free_mortals () |
922 | { |
912 | { |
923 | for (std::vector < object *>::iterator i = mortals.begin (); i != mortals.end (); ++i) |
913 | for (unordered_vector < object *>::iterator i = mortals.begin (); i != mortals.end ();) |
924 | delete * |
914 | if (!(*i)->refcount) |
|
|
915 | { |
|
|
916 | freed.push_back (*i); |
|
|
917 | mortals.erase (i); |
|
|
918 | } |
|
|
919 | else |
925 | i; |
920 | ++i; |
926 | |
|
|
927 | mortals.clear (); |
|
|
928 | } |
921 | } |
929 | |
922 | |
930 | object::object () |
923 | object::object () |
931 | { |
924 | { |
932 | SET_FLAG (this, FLAG_REMOVED); |
925 | SET_FLAG (this, FLAG_REMOVED); |
… | |
… | |
958 | { |
951 | { |
959 | count = 0; |
952 | count = 0; |
960 | |
953 | |
961 | /* Remove this object from the list of used objects */ |
954 | /* Remove this object from the list of used objects */ |
962 | if (prev) |
955 | if (prev) |
|
|
956 | { |
963 | prev->next = next; |
957 | prev->next = next; |
|
|
958 | prev = 0; |
|
|
959 | } |
|
|
960 | |
964 | if (next) |
961 | if (next) |
|
|
962 | { |
965 | next->prev = prev; |
963 | next->prev = prev; |
|
|
964 | next = 0; |
|
|
965 | } |
|
|
966 | |
966 | if (this == objects) |
967 | if (this == objects) |
967 | objects = next; |
968 | objects = next; |
968 | } |
969 | } |
969 | |
970 | |
970 | object *object::create () |
971 | object *object::create () |
971 | { |
972 | { |
972 | object * |
973 | object * |
|
|
974 | op; |
|
|
975 | |
|
|
976 | if (freed.empty ()) |
973 | op = new object; |
977 | op = new object; |
|
|
978 | |
|
|
979 | else |
|
|
980 | { |
|
|
981 | // highly annoying, but the only way to get it stable right now |
|
|
982 | op = freed.back (); |
|
|
983 | freed.pop_back (); |
|
|
984 | op->~object (); |
|
|
985 | new ((void *) op) object; |
|
|
986 | } |
974 | |
987 | |
975 | op->link (); |
988 | op->link (); |
976 | return op; |
989 | return op; |
977 | } |
990 | } |
978 | |
991 | |
… | |
… | |
986 | * If free_inventory is set, free inventory as well. Else drop items in |
999 | * If free_inventory is set, free inventory as well. Else drop items in |
987 | * inventory to the ground. |
1000 | * inventory to the ground. |
988 | */ |
1001 | */ |
989 | void object::free (bool free_inventory) |
1002 | void object::free (bool free_inventory) |
990 | { |
1003 | { |
|
|
1004 | if (QUERY_FLAG (this, FLAG_FREED)) |
|
|
1005 | return; |
|
|
1006 | |
991 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
1007 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
992 | { |
1008 | remove_ob (this); |
993 | LOG (llevDebug, "Free object called with non removed object\n"); |
|
|
994 | dump_object (this); |
|
|
995 | #ifdef MANY_CORES |
|
|
996 | abort (); |
|
|
997 | #endif |
|
|
998 | } |
|
|
999 | |
1009 | |
1000 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
1010 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
1001 | { |
|
|
1002 | LOG (llevMonster, "Warning: tried to free friendly object.\n"); |
|
|
1003 | remove_friendly_object (this); |
1011 | remove_friendly_object (this); |
1004 | } |
|
|
1005 | |
1012 | |
1006 | if (QUERY_FLAG (this, FLAG_FREED)) |
1013 | SET_FLAG (this, FLAG_FREED); |
1007 | { |
|
|
1008 | dump_object (this); |
|
|
1009 | LOG (llevError, "Trying to free freed object.\n%s\n", errmsg); |
|
|
1010 | return; |
|
|
1011 | } |
|
|
1012 | |
1014 | |
1013 | if (more) |
1015 | if (more) |
1014 | { |
1016 | { |
1015 | more->free (free_inventory); |
1017 | more->free (free_inventory); |
1016 | more = 0; |
1018 | more = 0; |
… | |
… | |
1022 | * if some form of movement is allowed, let objects |
1024 | * if some form of movement is allowed, let objects |
1023 | * drop on that space. |
1025 | * drop on that space. |
1024 | */ |
1026 | */ |
1025 | if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || (GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)) |
1027 | if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || (GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)) |
1026 | { |
1028 | { |
1027 | object * |
1029 | object *op = inv; |
1028 | op = inv; |
|
|
1029 | |
1030 | |
1030 | while (op) |
1031 | while (op) |
1031 | { |
1032 | { |
1032 | object * |
|
|
1033 | tmp = op->below; |
1033 | object *tmp = op->below; |
1034 | |
|
|
1035 | remove_ob (op); |
|
|
1036 | op->free (free_inventory); |
1034 | op->free (free_inventory); |
1037 | op = tmp; |
1035 | op = tmp; |
1038 | } |
1036 | } |
1039 | } |
1037 | } |
1040 | else |
1038 | else |
1041 | { /* Put objects in inventory onto this space */ |
1039 | { /* Put objects in inventory onto this space */ |
1042 | object * |
1040 | object *op = inv; |
1043 | op = inv; |
|
|
1044 | |
1041 | |
1045 | while (op) |
1042 | while (op) |
1046 | { |
1043 | { |
1047 | object * |
|
|
1048 | tmp = op->below; |
1044 | object *tmp = op->below; |
1049 | |
1045 | |
1050 | remove_ob (op); |
1046 | remove_ob (op); |
1051 | |
1047 | |
1052 | if (QUERY_FLAG (op, FLAG_STARTEQUIP) |
1048 | if (QUERY_FLAG (op, FLAG_STARTEQUIP) |
1053 | || QUERY_FLAG (op, FLAG_NO_DROP) || op->type == RUNE || op->type == TRAP || QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) |
1049 | || QUERY_FLAG (op, FLAG_NO_DROP) || op->type == RUNE || op->type == TRAP || QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) |
… | |
… | |
1062 | op = tmp; |
1058 | op = tmp; |
1063 | } |
1059 | } |
1064 | } |
1060 | } |
1065 | } |
1061 | } |
1066 | |
1062 | |
|
|
1063 | clear_owner (this); |
|
|
1064 | |
1067 | /* Remove object from the active list */ |
1065 | /* Remove object from the active list */ |
1068 | speed = 0; |
1066 | speed = 0; |
1069 | update_ob_speed (this); |
1067 | update_ob_speed (this); |
1070 | |
1068 | |
1071 | unlink (); |
1069 | unlink (); |
1072 | |
|
|
1073 | SET_FLAG (this, FLAG_FREED); |
|
|
1074 | |
1070 | |
1075 | mortals.push_back (this); |
1071 | mortals.push_back (this); |
1076 | } |
1072 | } |
1077 | |
1073 | |
1078 | /* |
1074 | /* |
… | |
… | |
1109 | object * |
1105 | object * |
1110 | tmp, * |
1106 | tmp, * |
1111 | last = NULL; |
1107 | last = NULL; |
1112 | object * |
1108 | object * |
1113 | otmp; |
1109 | otmp; |
|
|
1110 | |
1114 | tag_t |
1111 | tag_t |
1115 | tag; |
1112 | tag; |
1116 | int |
1113 | int |
1117 | check_walk_off; |
1114 | check_walk_off; |
1118 | mapstruct * |
1115 | mapstruct * |
1119 | m; |
1116 | m; |
|
|
1117 | |
1120 | sint16 |
1118 | sint16 |
1121 | x, |
1119 | x, |
1122 | y; |
1120 | y; |
1123 | |
1121 | |
1124 | |
|
|
1125 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1122 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1126 | { |
1123 | return; |
1127 | dump_object (op); |
|
|
1128 | LOG (llevError, "Trying to remove removed object.\n%s\n", errmsg); |
|
|
1129 | |
1124 | |
1130 | /* Changed it to always dump core in this case. As has been learned |
1125 | SET_FLAG (op, FLAG_REMOVED); |
1131 | * in the past, trying to recover from errors almost always |
1126 | |
1132 | * make things worse, and this is a real error here - something |
|
|
1133 | * that should not happen. |
|
|
1134 | * Yes, if this was a mission critical app, trying to do something |
|
|
1135 | * to recover may make sense, but that is because failure of the app |
|
|
1136 | * may have other disastrous problems. Cf runs out of a script |
|
|
1137 | * so is easily enough restarted without any real problems. |
|
|
1138 | * MSW 2001-07-01 |
|
|
1139 | */ |
|
|
1140 | abort (); |
|
|
1141 | } |
|
|
1142 | if (op->more != NULL) |
1127 | if (op->more != NULL) |
1143 | remove_ob (op->more); |
1128 | remove_ob (op->more); |
1144 | |
|
|
1145 | SET_FLAG (op, FLAG_REMOVED); |
|
|
1146 | |
1129 | |
1147 | /* |
1130 | /* |
1148 | * In this case, the object to be removed is in someones |
1131 | * In this case, the object to be removed is in someones |
1149 | * inventory. |
1132 | * inventory. |
1150 | */ |
1133 | */ |
… | |
… | |
1176 | */ |
1159 | */ |
1177 | op->x = op->env->x, op->y = op->env->y; |
1160 | op->x = op->env->x, op->y = op->env->y; |
1178 | op->map = op->env->map; |
1161 | op->map = op->env->map; |
1179 | op->above = NULL, op->below = NULL; |
1162 | op->above = NULL, op->below = NULL; |
1180 | op->env = NULL; |
1163 | op->env = NULL; |
1181 | return; |
1164 | } |
|
|
1165 | else if (op->map) |
1182 | } |
1166 | { |
1183 | |
|
|
1184 | /* If we get here, we are removing it from a map */ |
|
|
1185 | if (op->map == NULL) |
|
|
1186 | return; |
|
|
1187 | |
|
|
1188 | x = op->x; |
1167 | x = op->x; |
1189 | y = op->y; |
1168 | y = op->y; |
1190 | m = get_map_from_coord (op->map, &x, &y); |
1169 | m = get_map_from_coord (op->map, &x, &y); |
1191 | |
1170 | |
1192 | if (!m) |
1171 | if (!m) |
1193 | { |
1172 | { |
1194 | LOG (llevError, "remove_ob called when object was on map but appears to not be within valid coordinates? %s (%d,%d)\n", |
1173 | LOG (llevError, "remove_ob called when object was on map but appears to not be within valid coordinates? %s (%d,%d)\n", |
1195 | op->map->path, op->x, op->y); |
1174 | op->map->path, op->x, op->y); |
1196 | /* in old days, we used to set x and y to 0 and continue. |
1175 | /* in old days, we used to set x and y to 0 and continue. |
1197 | * it seems if we get into this case, something is probablye |
1176 | * it seems if we get into this case, something is probablye |
1198 | * screwed up and should be fixed. |
1177 | * screwed up and should be fixed. |
|
|
1178 | */ |
|
|
1179 | abort (); |
|
|
1180 | } |
|
|
1181 | |
|
|
1182 | if (op->map != m) |
|
|
1183 | LOG (llevDebug, "remove_ob: Object not really on map it claimed to be on? %s != %s, %d,%d != %d,%d\n", |
|
|
1184 | op->map->path, m->path, op->x, op->y, x, y); |
|
|
1185 | |
|
|
1186 | /* Re did the following section of code - it looks like it had |
|
|
1187 | * lots of logic for things we no longer care about |
1199 | */ |
1188 | */ |
1200 | abort (); |
|
|
1201 | } |
|
|
1202 | if (op->map != m) |
|
|
1203 | { |
|
|
1204 | LOG (llevDebug, "remove_ob: Object not really on map it claimed to be on? %s != %s, %d,%d != %d,%d\n", |
|
|
1205 | op->map->path, m->path, op->x, op->y, x, y); |
|
|
1206 | } |
|
|
1207 | |
1189 | |
1208 | /* Re did the following section of code - it looks like it had |
|
|
1209 | * lots of logic for things we no longer care about |
|
|
1210 | */ |
|
|
1211 | |
|
|
1212 | /* link the object above us */ |
1190 | /* link the object above us */ |
1213 | if (op->above) |
1191 | if (op->above) |
1214 | op->above->below = op->below; |
1192 | op->above->below = op->below; |
1215 | else |
1193 | else |
1216 | SET_MAP_TOP (m, x, y, op->below); /* we were top, set new top */ |
1194 | SET_MAP_TOP (m, x, y, op->below); /* we were top, set new top */ |
1217 | |
1195 | |
1218 | /* Relink the object below us, if there is one */ |
1196 | /* Relink the object below us, if there is one */ |
1219 | if (op->below) |
1197 | if (op->below) |
1220 | { |
|
|
1221 | op->below->above = op->above; |
1198 | op->below->above = op->above; |
1222 | } |
|
|
1223 | else |
1199 | else |
1224 | { |
1200 | { |
1225 | /* Nothing below, which means we need to relink map object for this space |
1201 | /* Nothing below, which means we need to relink map object for this space |
1226 | * use translated coordinates in case some oddness with map tiling is |
1202 | * use translated coordinates in case some oddness with map tiling is |
1227 | * evident |
1203 | * evident |
1228 | */ |
|
|
1229 | if (GET_MAP_OB (m, x, y) != op) |
|
|
1230 | { |
|
|
1231 | dump_object (op); |
|
|
1232 | LOG (llevError, "remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom?\n%s\n", |
|
|
1233 | errmsg); |
|
|
1234 | dump_object (GET_MAP_OB (m, x, y)); |
|
|
1235 | LOG (llevError, "%s\n", errmsg); |
|
|
1236 | } |
|
|
1237 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
|
|
1238 | } |
|
|
1239 | op->above = NULL; |
|
|
1240 | op->below = NULL; |
|
|
1241 | |
|
|
1242 | if (op->map->in_memory == MAP_SAVING) |
|
|
1243 | return; |
|
|
1244 | |
|
|
1245 | tag = op->count; |
|
|
1246 | check_walk_off = !QUERY_FLAG (op, FLAG_NO_APPLY); |
|
|
1247 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
|
|
1248 | { |
|
|
1249 | /* No point updating the players look faces if he is the object |
|
|
1250 | * being removed. |
|
|
1251 | */ |
|
|
1252 | |
|
|
1253 | if (tmp->type == PLAYER && tmp != op) |
|
|
1254 | { |
|
|
1255 | /* If a container that the player is currently using somehow gets |
|
|
1256 | * removed (most likely destroyed), update the player view |
|
|
1257 | * appropriately. |
|
|
1258 | */ |
1204 | */ |
1259 | if (tmp->container == op) |
1205 | if (GET_MAP_OB (m, x, y) != op) |
1260 | { |
1206 | { |
1261 | CLEAR_FLAG (op, FLAG_APPLIED); |
1207 | dump_object (op); |
1262 | tmp->container = NULL; |
1208 | LOG (llevError, |
|
|
1209 | "remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom?\n%s\n", errmsg); |
|
|
1210 | dump_object (GET_MAP_OB (m, x, y)); |
|
|
1211 | LOG (llevError, "%s\n", errmsg); |
1263 | } |
1212 | } |
1264 | tmp->contr->socket.update_look = 1; |
1213 | |
1265 | } |
1214 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
1266 | /* See if player moving off should effect something */ |
|
|
1267 | if (check_walk_off && ((op->move_type & tmp->move_off) && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
|
|
1268 | { |
1215 | } |
1269 | |
1216 | |
1270 | move_apply (tmp, op, NULL); |
1217 | op->above = 0; |
1271 | if (was_destroyed (op, tag)) |
1218 | op->below = 0; |
|
|
1219 | |
|
|
1220 | if (op->map->in_memory == MAP_SAVING) |
|
|
1221 | return; |
|
|
1222 | |
|
|
1223 | tag = op->count; |
|
|
1224 | check_walk_off = !QUERY_FLAG (op, FLAG_NO_APPLY); |
|
|
1225 | |
|
|
1226 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
|
|
1227 | { |
|
|
1228 | /* No point updating the players look faces if he is the object |
|
|
1229 | * being removed. |
|
|
1230 | */ |
|
|
1231 | |
|
|
1232 | if (tmp->type == PLAYER && tmp != op) |
1272 | { |
1233 | { |
1273 | LOG (llevError, "BUG: remove_ob(): name %s, archname %s destroyed " "leaving object\n", &tmp->name, &tmp->arch->name); |
1234 | /* If a container that the player is currently using somehow gets |
|
|
1235 | * removed (most likely destroyed), update the player view |
|
|
1236 | * appropriately. |
|
|
1237 | */ |
|
|
1238 | if (tmp->container == op) |
|
|
1239 | { |
|
|
1240 | CLEAR_FLAG (op, FLAG_APPLIED); |
|
|
1241 | tmp->container = NULL; |
|
|
1242 | } |
|
|
1243 | |
|
|
1244 | tmp->contr->socket.update_look = 1; |
1274 | } |
1245 | } |
|
|
1246 | |
|
|
1247 | /* See if player moving off should effect something */ |
|
|
1248 | if (check_walk_off && ((op->move_type & tmp->move_off) && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
|
|
1249 | { |
|
|
1250 | move_apply (tmp, op, NULL); |
|
|
1251 | |
|
|
1252 | if (was_destroyed (op, tag)) |
|
|
1253 | { |
|
|
1254 | LOG (llevError, "BUG: remove_ob(): name %s, archname %s destroyed " "leaving object\n", &tmp->name, &tmp->arch->name); |
|
|
1255 | } |
1275 | } |
1256 | } |
1276 | |
1257 | |
1277 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1258 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1278 | |
1259 | |
1279 | if (tmp->above == tmp) |
1260 | if (tmp->above == tmp) |
1280 | tmp->above = NULL; |
1261 | tmp->above = NULL; |
|
|
1262 | |
1281 | last = tmp; |
1263 | last = tmp; |
1282 | } |
1264 | } |
|
|
1265 | |
1283 | /* last == NULL of there are no objects on this space */ |
1266 | /* last == NULL of there are no objects on this space */ |
1284 | if (last == NULL) |
1267 | if (last == NULL) |
1285 | { |
1268 | { |
1286 | /* set P_NEED_UPDATE, otherwise update_position will complain. In theory, |
1269 | /* set P_NEED_UPDATE, otherwise update_position will complain. In theory, |
1287 | * we could preserve the flags (GET_MAP_FLAGS), but update_position figures |
1270 | * we could preserve the flags (GET_MAP_FLAGS), but update_position figures |
1288 | * those out anyways, and if there are any flags set right now, they won't |
1271 | * those out anyways, and if there are any flags set right now, they won't |
1289 | * be correct anyways. |
1272 | * be correct anyways. |
1290 | */ |
1273 | */ |
1291 | SET_MAP_FLAGS (op->map, op->x, op->y, P_NEED_UPDATE); |
1274 | SET_MAP_FLAGS (op->map, op->x, op->y, P_NEED_UPDATE); |
1292 | update_position (op->map, op->x, op->y); |
1275 | update_position (op->map, op->x, op->y); |
1293 | } |
1276 | } |
1294 | else |
1277 | else |
1295 | update_object (last, UP_OBJ_REMOVE); |
1278 | update_object (last, UP_OBJ_REMOVE); |
1296 | |
1279 | |
1297 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0)) |
1280 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0)) |
1298 | update_all_los (op->map, op->x, op->y); |
1281 | update_all_los (op->map, op->x, op->y); |
1299 | |
1282 | } |
1300 | } |
1283 | } |
1301 | |
1284 | |
1302 | /* |
1285 | /* |
1303 | * merge_ob(op,top): |
1286 | * merge_ob(op,top): |
1304 | * |
1287 | * |
… | |
… | |
1311 | object * |
1294 | object * |
1312 | merge_ob (object *op, object *top) |
1295 | merge_ob (object *op, object *top) |
1313 | { |
1296 | { |
1314 | if (!op->nrof) |
1297 | if (!op->nrof) |
1315 | return 0; |
1298 | return 0; |
|
|
1299 | |
1316 | if (top == NULL) |
1300 | if (top == NULL) |
1317 | for (top = op; top != NULL && top->above != NULL; top = top->above); |
1301 | for (top = op; top != NULL && top->above != NULL; top = top->above); |
|
|
1302 | |
1318 | for (; top != NULL; top = top->below) |
1303 | for (; top != NULL; top = top->below) |
1319 | { |
1304 | { |
1320 | if (top == op) |
1305 | if (top == op) |
1321 | continue; |
1306 | continue; |
1322 | if (CAN_MERGE (op, top)) |
1307 | if (CAN_MERGE (op, top)) |
… | |
… | |
1328 | remove_ob (op); |
1313 | remove_ob (op); |
1329 | free_object (op); |
1314 | free_object (op); |
1330 | return top; |
1315 | return top; |
1331 | } |
1316 | } |
1332 | } |
1317 | } |
|
|
1318 | |
1333 | return NULL; |
1319 | return NULL; |
1334 | } |
1320 | } |
1335 | |
1321 | |
1336 | /* |
1322 | /* |
1337 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1323 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1338 | * job preparing multi-part monsters |
1324 | * job preparing multi-part monsters |
1339 | */ |
1325 | */ |
1340 | object * |
1326 | object * |
1341 | insert_ob_in_map_at (object *op, mapstruct *m, object *originator, int flag, int x, int y) |
1327 | insert_ob_in_map_at (object *op, mapstruct *m, object *originator, int flag, int x, int y) |
1342 | { |
1328 | { |
1343 | object * |
1329 | object *tmp; |
1344 | tmp; |
|
|
1345 | |
1330 | |
1346 | if (op->head) |
1331 | if (op->head) |
1347 | op = op->head; |
1332 | op = op->head; |
|
|
1333 | |
1348 | for (tmp = op; tmp; tmp = tmp->more) |
1334 | for (tmp = op; tmp; tmp = tmp->more) |
1349 | { |
1335 | { |
1350 | tmp->x = x + tmp->arch->clone.x; |
1336 | tmp->x = x + tmp->arch->clone.x; |
1351 | tmp->y = y + tmp->arch->clone.y; |
1337 | tmp->y = y + tmp->arch->clone.y; |
1352 | } |
1338 | } |
|
|
1339 | |
1353 | return insert_ob_in_map (op, m, originator, flag); |
1340 | return insert_ob_in_map (op, m, originator, flag); |
1354 | } |
1341 | } |
1355 | |
1342 | |
1356 | /* |
1343 | /* |
1357 | * insert_ob_in_map (op, map, originator, flag): |
1344 | * insert_ob_in_map (op, map, originator, flag): |
… | |
… | |
1375 | */ |
1362 | */ |
1376 | |
1363 | |
1377 | object * |
1364 | object * |
1378 | insert_ob_in_map (object *op, mapstruct *m, object *originator, int flag) |
1365 | insert_ob_in_map (object *op, mapstruct *m, object *originator, int flag) |
1379 | { |
1366 | { |
1380 | object * |
1367 | object *tmp, *top, *floor = NULL; |
1381 | tmp, * |
1368 | sint16 x, y; |
1382 | top, * |
|
|
1383 | floor = NULL; |
|
|
1384 | sint16 |
|
|
1385 | x, |
|
|
1386 | y; |
|
|
1387 | |
1369 | |
1388 | if (QUERY_FLAG (op, FLAG_FREED)) |
1370 | if (QUERY_FLAG (op, FLAG_FREED)) |
1389 | { |
1371 | { |
1390 | LOG (llevError, "Trying to insert freed object!\n"); |
1372 | LOG (llevError, "Trying to insert freed object!\n"); |
1391 | return NULL; |
1373 | return NULL; |
1392 | } |
1374 | } |
|
|
1375 | |
1393 | if (m == NULL) |
1376 | if (m == NULL) |
1394 | { |
1377 | { |
1395 | dump_object (op); |
1378 | dump_object (op); |
1396 | LOG (llevError, "Trying to insert in null-map!\n%s\n", errmsg); |
1379 | LOG (llevError, "Trying to insert in null-map!\n%s\n", errmsg); |
1397 | return op; |
1380 | return op; |
1398 | } |
1381 | } |
|
|
1382 | |
1399 | if (out_of_map (m, op->x, op->y)) |
1383 | if (out_of_map (m, op->x, op->y)) |
1400 | { |
1384 | { |
1401 | dump_object (op); |
1385 | dump_object (op); |
1402 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", errmsg); |
1386 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", errmsg); |
1403 | #ifdef MANY_CORES |
1387 | #ifdef MANY_CORES |
… | |
… | |
1407 | */ |
1391 | */ |
1408 | abort (); |
1392 | abort (); |
1409 | #endif |
1393 | #endif |
1410 | return op; |
1394 | return op; |
1411 | } |
1395 | } |
|
|
1396 | |
1412 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1397 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1413 | { |
1398 | { |
1414 | dump_object (op); |
1399 | dump_object (op); |
1415 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", errmsg); |
1400 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", errmsg); |
1416 | return op; |
1401 | return op; |
1417 | } |
1402 | } |
|
|
1403 | |
1418 | if (op->more != NULL) |
1404 | if (op->more != NULL) |
1419 | { |
1405 | { |
1420 | /* The part may be on a different map. */ |
1406 | /* The part may be on a different map. */ |
1421 | |
1407 | |
1422 | object * |
|
|
1423 | more = op->more; |
1408 | object *more = op->more; |
1424 | |
1409 | |
1425 | /* We really need the caller to normalize coordinates - if |
1410 | /* We really need the caller to normalize coordinates - if |
1426 | * we set the map, that doesn't work if the location is within |
1411 | * we set the map, that doesn't work if the location is within |
1427 | * a map and this is straddling an edge. So only if coordinate |
1412 | * a map and this is straddling an edge. So only if coordinate |
1428 | * is clear wrong do we normalize it. |
1413 | * is clear wrong do we normalize it. |
1429 | */ |
1414 | */ |
1430 | if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) |
1415 | if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) |
1431 | { |
|
|
1432 | more->map = get_map_from_coord (m, &more->x, &more->y); |
1416 | more->map = get_map_from_coord (m, &more->x, &more->y); |
1433 | } |
|
|
1434 | else if (!more->map) |
1417 | else if (!more->map) |
1435 | { |
1418 | { |
1436 | /* For backwards compatibility - when not dealing with tiled maps, |
1419 | /* For backwards compatibility - when not dealing with tiled maps, |
1437 | * more->map should always point to the parent. |
1420 | * more->map should always point to the parent. |
1438 | */ |
1421 | */ |
… | |
… | |
1441 | |
1424 | |
1442 | if (insert_ob_in_map (more, more->map, originator, flag) == NULL) |
1425 | if (insert_ob_in_map (more, more->map, originator, flag) == NULL) |
1443 | { |
1426 | { |
1444 | if (!op->head) |
1427 | if (!op->head) |
1445 | LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n"); |
1428 | LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n"); |
|
|
1429 | |
1446 | return NULL; |
1430 | return NULL; |
1447 | } |
1431 | } |
1448 | } |
1432 | } |
|
|
1433 | |
1449 | CLEAR_FLAG (op, FLAG_REMOVED); |
1434 | CLEAR_FLAG (op, FLAG_REMOVED); |
1450 | |
1435 | |
1451 | /* Ideally, the caller figures this out. However, it complicates a lot |
1436 | /* Ideally, the caller figures this out. However, it complicates a lot |
1452 | * of areas of callers (eg, anything that uses find_free_spot would now |
1437 | * of areas of callers (eg, anything that uses find_free_spot would now |
1453 | * need extra work |
1438 | * need extra work |
… | |
… | |
1457 | y = op->y; |
1442 | y = op->y; |
1458 | |
1443 | |
1459 | /* this has to be done after we translate the coordinates. |
1444 | /* this has to be done after we translate the coordinates. |
1460 | */ |
1445 | */ |
1461 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1446 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1462 | { |
|
|
1463 | for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) |
1447 | for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) |
1464 | if (CAN_MERGE (op, tmp)) |
1448 | if (CAN_MERGE (op, tmp)) |
1465 | { |
1449 | { |
1466 | op->nrof += tmp->nrof; |
1450 | op->nrof += tmp->nrof; |
1467 | remove_ob (tmp); |
1451 | remove_ob (tmp); |
1468 | free_object (tmp); |
1452 | free_object (tmp); |
1469 | } |
1453 | } |
1470 | } |
|
|
1471 | |
1454 | |
1472 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1455 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1473 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
1456 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
|
|
1457 | |
1474 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1458 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1475 | CLEAR_FLAG (op, FLAG_NO_STEAL); |
1459 | CLEAR_FLAG (op, FLAG_NO_STEAL); |
1476 | |
1460 | |
1477 | if (flag & INS_BELOW_ORIGINATOR) |
1461 | if (flag & INS_BELOW_ORIGINATOR) |
1478 | { |
1462 | { |
1479 | if (originator->map != op->map || originator->x != op->x || originator->y != op->y) |
1463 | if (originator->map != op->map || originator->x != op->x || originator->y != op->y) |
1480 | { |
1464 | { |
1481 | LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n"); |
1465 | LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n"); |
1482 | abort (); |
1466 | abort (); |
1483 | } |
1467 | } |
|
|
1468 | |
1484 | op->above = originator; |
1469 | op->above = originator; |
1485 | op->below = originator->below; |
1470 | op->below = originator->below; |
|
|
1471 | |
1486 | if (op->below) |
1472 | if (op->below) |
1487 | op->below->above = op; |
1473 | op->below->above = op; |
1488 | else |
1474 | else |
1489 | SET_MAP_OB (op->map, op->x, op->y, op); |
1475 | SET_MAP_OB (op->map, op->x, op->y, op); |
|
|
1476 | |
1490 | /* since *below* originator, no need to update top */ |
1477 | /* since *below* originator, no need to update top */ |
1491 | originator->below = op; |
1478 | originator->below = op; |
1492 | } |
1479 | } |
1493 | else |
1480 | else |
1494 | { |
1481 | { |
1495 | /* If there are other objects, then */ |
1482 | /* If there are other objects, then */ |
1496 | if ((!(flag & INS_MAP_LOAD)) && ((top = GET_MAP_OB (op->map, op->x, op->y)) != NULL)) |
1483 | if ((!(flag & INS_MAP_LOAD)) && ((top = GET_MAP_OB (op->map, op->x, op->y)) != NULL)) |
1497 | { |
1484 | { |
1498 | object * |
|
|
1499 | last = NULL; |
1485 | object *last = NULL; |
1500 | |
1486 | |
1501 | /* |
1487 | /* |
1502 | * If there are multiple objects on this space, we do some trickier handling. |
1488 | * If there are multiple objects on this space, we do some trickier handling. |
1503 | * We've already dealt with merging if appropriate. |
1489 | * We've already dealt with merging if appropriate. |
1504 | * Generally, we want to put the new object on top. But if |
1490 | * Generally, we want to put the new object on top. But if |
… | |
… | |
1513 | |
1499 | |
1514 | while (top != NULL) |
1500 | while (top != NULL) |
1515 | { |
1501 | { |
1516 | if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) |
1502 | if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) |
1517 | floor = top; |
1503 | floor = top; |
|
|
1504 | |
1518 | if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) |
1505 | if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) |
1519 | { |
1506 | { |
1520 | /* We insert above top, so we want this object below this */ |
1507 | /* We insert above top, so we want this object below this */ |
1521 | top = top->below; |
1508 | top = top->below; |
1522 | break; |
1509 | break; |
1523 | } |
1510 | } |
|
|
1511 | |
1524 | last = top; |
1512 | last = top; |
1525 | top = top->above; |
1513 | top = top->above; |
1526 | } |
1514 | } |
|
|
1515 | |
1527 | /* Don't want top to be NULL, so set it to the last valid object */ |
1516 | /* Don't want top to be NULL, so set it to the last valid object */ |
1528 | top = last; |
1517 | top = last; |
1529 | |
1518 | |
1530 | /* We let update_position deal with figuring out what the space |
1519 | /* We let update_position deal with figuring out what the space |
1531 | * looks like instead of lots of conditions here. |
1520 | * looks like instead of lots of conditions here. |
… | |
… | |
1551 | */ |
1540 | */ |
1552 | if (last && last->below && last != floor) |
1541 | if (last && last->below && last != floor) |
1553 | top = last->below; |
1542 | top = last->below; |
1554 | } |
1543 | } |
1555 | } /* If objects on this space */ |
1544 | } /* If objects on this space */ |
|
|
1545 | |
1556 | if (flag & INS_MAP_LOAD) |
1546 | if (flag & INS_MAP_LOAD) |
1557 | top = GET_MAP_TOP (op->map, op->x, op->y); |
1547 | top = GET_MAP_TOP (op->map, op->x, op->y); |
|
|
1548 | |
1558 | if (flag & INS_ABOVE_FLOOR_ONLY) |
1549 | if (flag & INS_ABOVE_FLOOR_ONLY) |
1559 | top = floor; |
1550 | top = floor; |
1560 | |
1551 | |
1561 | /* Top is the object that our object (op) is going to get inserted above. |
1552 | /* Top is the object that our object (op) is going to get inserted above. |
1562 | */ |
1553 | */ |
1563 | |
1554 | |
1564 | /* First object on this space */ |
1555 | /* First object on this space */ |
1565 | if (!top) |
1556 | if (!top) |
1566 | { |
1557 | { |
1567 | op->above = GET_MAP_OB (op->map, op->x, op->y); |
1558 | op->above = GET_MAP_OB (op->map, op->x, op->y); |
|
|
1559 | |
1568 | if (op->above) |
1560 | if (op->above) |
1569 | op->above->below = op; |
1561 | op->above->below = op; |
|
|
1562 | |
1570 | op->below = NULL; |
1563 | op->below = NULL; |
1571 | SET_MAP_OB (op->map, op->x, op->y, op); |
1564 | SET_MAP_OB (op->map, op->x, op->y, op); |
1572 | } |
1565 | } |
1573 | else |
1566 | else |
1574 | { /* get inserted into the stack above top */ |
1567 | { /* get inserted into the stack above top */ |
1575 | op->above = top->above; |
1568 | op->above = top->above; |
|
|
1569 | |
1576 | if (op->above) |
1570 | if (op->above) |
1577 | op->above->below = op; |
1571 | op->above->below = op; |
|
|
1572 | |
1578 | op->below = top; |
1573 | op->below = top; |
1579 | top->above = op; |
1574 | top->above = op; |
1580 | } |
1575 | } |
|
|
1576 | |
1581 | if (op->above == NULL) |
1577 | if (op->above == NULL) |
1582 | SET_MAP_TOP (op->map, op->x, op->y, op); |
1578 | SET_MAP_TOP (op->map, op->x, op->y, op); |
1583 | } /* else not INS_BELOW_ORIGINATOR */ |
1579 | } /* else not INS_BELOW_ORIGINATOR */ |
1584 | |
1580 | |
1585 | if (op->type == PLAYER) |
1581 | if (op->type == PLAYER) |
… | |
… | |
1588 | /* If we have a floor, we know the player, if any, will be above |
1584 | /* If we have a floor, we know the player, if any, will be above |
1589 | * it, so save a few ticks and start from there. |
1585 | * it, so save a few ticks and start from there. |
1590 | */ |
1586 | */ |
1591 | if (!(flag & INS_MAP_LOAD)) |
1587 | if (!(flag & INS_MAP_LOAD)) |
1592 | for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1588 | for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1593 | { |
|
|
1594 | if (tmp->type == PLAYER) |
1589 | if (tmp->type == PLAYER) |
1595 | tmp->contr->socket.update_look = 1; |
1590 | tmp->contr->socket.update_look = 1; |
1596 | } |
|
|
1597 | |
1591 | |
1598 | /* If this object glows, it may affect lighting conditions that are |
1592 | /* If this object glows, it may affect lighting conditions that are |
1599 | * visible to others on this map. But update_all_los is really |
1593 | * visible to others on this map. But update_all_los is really |
1600 | * an inefficient way to do this, as it means los for all players |
1594 | * an inefficient way to do this, as it means los for all players |
1601 | * on the map will get recalculated. The players could very well |
1595 | * on the map will get recalculated. The players could very well |
… | |
… | |
1605 | * of effect may be sufficient. |
1599 | * of effect may be sufficient. |
1606 | */ |
1600 | */ |
1607 | if (MAP_DARKNESS (op->map) && (op->glow_radius != 0)) |
1601 | if (MAP_DARKNESS (op->map) && (op->glow_radius != 0)) |
1608 | update_all_los (op->map, op->x, op->y); |
1602 | update_all_los (op->map, op->x, op->y); |
1609 | |
1603 | |
1610 | |
|
|
1611 | /* updates flags (blocked, alive, no magic, etc) for this map space */ |
1604 | /* updates flags (blocked, alive, no magic, etc) for this map space */ |
1612 | update_object (op, UP_OBJ_INSERT); |
1605 | update_object (op, UP_OBJ_INSERT); |
1613 | |
|
|
1614 | |
1606 | |
1615 | /* Don't know if moving this to the end will break anything. However, |
1607 | /* Don't know if moving this to the end will break anything. However, |
1616 | * we want to have update_look set above before calling this. |
1608 | * we want to have update_look set above before calling this. |
1617 | * |
1609 | * |
1618 | * check_move_on() must be after this because code called from |
1610 | * check_move_on() must be after this because code called from |
… | |
… | |
1620 | * blocked() and wall() work properly), and these flags are updated by |
1612 | * blocked() and wall() work properly), and these flags are updated by |
1621 | * update_object(). |
1613 | * update_object(). |
1622 | */ |
1614 | */ |
1623 | |
1615 | |
1624 | /* if this is not the head or flag has been passed, don't check walk on status */ |
1616 | /* if this is not the head or flag has been passed, don't check walk on status */ |
1625 | |
|
|
1626 | if (!(flag & INS_NO_WALK_ON) && !op->head) |
1617 | if (!(flag & INS_NO_WALK_ON) && !op->head) |
1627 | { |
1618 | { |
1628 | if (check_move_on (op, originator)) |
1619 | if (check_move_on (op, originator)) |
1629 | return NULL; |
1620 | return NULL; |
1630 | |
1621 | |
… | |
… | |
1633 | */ |
1624 | */ |
1634 | for (tmp = op->more; tmp != NULL; tmp = tmp->more) |
1625 | for (tmp = op->more; tmp != NULL; tmp = tmp->more) |
1635 | if (check_move_on (tmp, originator)) |
1626 | if (check_move_on (tmp, originator)) |
1636 | return NULL; |
1627 | return NULL; |
1637 | } |
1628 | } |
|
|
1629 | |
1638 | return op; |
1630 | return op; |
1639 | } |
1631 | } |
1640 | |
1632 | |
1641 | /* this function inserts an object in the map, but if it |
1633 | /* this function inserts an object in the map, but if it |
1642 | * finds an object of its own type, it'll remove that one first. |
1634 | * finds an object of its own type, it'll remove that one first. |
… | |
… | |
1660 | free_object (tmp); |
1652 | free_object (tmp); |
1661 | } |
1653 | } |
1662 | } |
1654 | } |
1663 | |
1655 | |
1664 | tmp1 = arch_to_object (find_archetype (arch_string)); |
1656 | tmp1 = arch_to_object (find_archetype (arch_string)); |
1665 | |
|
|
1666 | |
1657 | |
1667 | tmp1->x = op->x; |
1658 | tmp1->x = op->x; |
1668 | tmp1->y = op->y; |
1659 | tmp1->y = op->y; |
1669 | insert_ob_in_map (tmp1, op->map, op, 0); |
1660 | insert_ob_in_map (tmp1, op->map, op, 0); |
1670 | } |
1661 | } |
… | |
… | |
1688 | if (orig_ob->nrof < nr) |
1679 | if (orig_ob->nrof < nr) |
1689 | { |
1680 | { |
1690 | sprintf (errmsg, "There are only %d %ss.", orig_ob->nrof ? orig_ob->nrof : 1, &orig_ob->name); |
1681 | sprintf (errmsg, "There are only %d %ss.", orig_ob->nrof ? orig_ob->nrof : 1, &orig_ob->name); |
1691 | return NULL; |
1682 | return NULL; |
1692 | } |
1683 | } |
|
|
1684 | |
1693 | newob = object_create_clone (orig_ob); |
1685 | newob = object_create_clone (orig_ob); |
|
|
1686 | |
1694 | if ((orig_ob->nrof -= nr) < 1) |
1687 | if ((orig_ob->nrof -= nr) < 1) |
1695 | { |
1688 | { |
1696 | if (!is_removed) |
1689 | if (!is_removed) |
1697 | remove_ob (orig_ob); |
1690 | remove_ob (orig_ob); |
1698 | free_object2 (orig_ob, 1); |
1691 | free_object2 (orig_ob, 1); |
… | |
… | |
1706 | strcpy (errmsg, "Tried to split object whose map is not in memory."); |
1699 | strcpy (errmsg, "Tried to split object whose map is not in memory."); |
1707 | LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n"); |
1700 | LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n"); |
1708 | return NULL; |
1701 | return NULL; |
1709 | } |
1702 | } |
1710 | } |
1703 | } |
|
|
1704 | |
1711 | newob->nrof = nr; |
1705 | newob->nrof = nr; |
1712 | |
1706 | |
1713 | return newob; |
1707 | return newob; |
1714 | } |
1708 | } |
1715 | |
1709 | |
… | |
… | |
1722 | */ |
1716 | */ |
1723 | |
1717 | |
1724 | object * |
1718 | object * |
1725 | decrease_ob_nr (object *op, uint32 i) |
1719 | decrease_ob_nr (object *op, uint32 i) |
1726 | { |
1720 | { |
1727 | object * |
1721 | object *tmp; |
1728 | tmp; |
|
|
1729 | player * |
1722 | player *pl; |
1730 | pl; |
|
|
1731 | |
1723 | |
1732 | if (i == 0) /* objects with op->nrof require this check */ |
1724 | if (i == 0) /* objects with op->nrof require this check */ |
1733 | return op; |
1725 | return op; |
1734 | |
1726 | |
1735 | if (i > op->nrof) |
1727 | if (i > op->nrof) |
1736 | i = op->nrof; |
1728 | i = op->nrof; |
1737 | |
1729 | |
1738 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1730 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1739 | { |
|
|
1740 | op->nrof -= i; |
1731 | op->nrof -= i; |
1741 | } |
|
|
1742 | else if (op->env != NULL) |
1732 | else if (op->env != NULL) |
1743 | { |
1733 | { |
1744 | /* is this object in the players inventory, or sub container |
1734 | /* is this object in the players inventory, or sub container |
1745 | * therein? |
1735 | * therein? |
1746 | */ |
1736 | */ |
… | |
… | |
1781 | } |
1771 | } |
1782 | } |
1772 | } |
1783 | } |
1773 | } |
1784 | else |
1774 | else |
1785 | { |
1775 | { |
1786 | object * |
|
|
1787 | above = op->above; |
1776 | object *above = op->above; |
1788 | |
1777 | |
1789 | if (i < op->nrof) |
1778 | if (i < op->nrof) |
1790 | { |
|
|
1791 | op->nrof -= i; |
1779 | op->nrof -= i; |
1792 | } |
|
|
1793 | else |
1780 | else |
1794 | { |
1781 | { |
1795 | remove_ob (op); |
1782 | remove_ob (op); |
1796 | op->nrof = 0; |
1783 | op->nrof = 0; |
1797 | } |
1784 | } |
|
|
1785 | |
1798 | /* Since we just removed op, op->above is null */ |
1786 | /* Since we just removed op, op->above is null */ |
1799 | for (tmp = above; tmp != NULL; tmp = tmp->above) |
1787 | for (tmp = above; tmp != NULL; tmp = tmp->above) |
1800 | if (tmp->type == PLAYER) |
1788 | if (tmp->type == PLAYER) |
1801 | { |
1789 | { |
1802 | if (op->nrof) |
1790 | if (op->nrof) |
… | |
… | |
1805 | esrv_del_item (tmp->contr, op->count); |
1793 | esrv_del_item (tmp->contr, op->count); |
1806 | } |
1794 | } |
1807 | } |
1795 | } |
1808 | |
1796 | |
1809 | if (op->nrof) |
1797 | if (op->nrof) |
1810 | { |
|
|
1811 | return op; |
1798 | return op; |
1812 | } |
|
|
1813 | else |
1799 | else |
1814 | { |
1800 | { |
1815 | free_object (op); |
1801 | free_object (op); |
1816 | return NULL; |
1802 | return NULL; |
1817 | } |
1803 | } |
… | |
… | |
1826 | add_weight (object *op, signed long weight) |
1812 | add_weight (object *op, signed long weight) |
1827 | { |
1813 | { |
1828 | while (op != NULL) |
1814 | while (op != NULL) |
1829 | { |
1815 | { |
1830 | if (op->type == CONTAINER) |
1816 | if (op->type == CONTAINER) |
1831 | { |
|
|
1832 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
1817 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
1833 | } |
1818 | |
1834 | op->carrying += weight; |
1819 | op->carrying += weight; |
1835 | op = op->env; |
1820 | op = op->env; |
1836 | } |
1821 | } |
1837 | } |
1822 | } |
1838 | |
1823 | |
… | |
… | |
1861 | { |
1846 | { |
1862 | dump_object (op); |
1847 | dump_object (op); |
1863 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", errmsg); |
1848 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", errmsg); |
1864 | return op; |
1849 | return op; |
1865 | } |
1850 | } |
|
|
1851 | |
1866 | if (where == NULL) |
1852 | if (where == NULL) |
1867 | { |
1853 | { |
1868 | dump_object (op); |
1854 | dump_object (op); |
1869 | LOG (llevError, "Trying to put object in NULL.\n%s\n", errmsg); |
1855 | LOG (llevError, "Trying to put object in NULL.\n%s\n", errmsg); |
1870 | return op; |
1856 | return op; |
1871 | } |
1857 | } |
|
|
1858 | |
1872 | if (where->head) |
1859 | if (where->head) |
1873 | { |
1860 | { |
1874 | LOG (llevDebug, "Warning: Tried to insert object wrong part of multipart object.\n"); |
1861 | LOG (llevDebug, "Warning: Tried to insert object wrong part of multipart object.\n"); |
1875 | where = where->head; |
1862 | where = where->head; |
1876 | } |
1863 | } |
|
|
1864 | |
1877 | if (op->more) |
1865 | if (op->more) |
1878 | { |
1866 | { |
1879 | LOG (llevError, "Tried to insert multipart object %s (%d)\n", &op->name, op->count); |
1867 | LOG (llevError, "Tried to insert multipart object %s (%d)\n", &op->name, op->count); |
1880 | return op; |
1868 | return op; |
1881 | } |
1869 | } |
|
|
1870 | |
1882 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1871 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1883 | CLEAR_FLAG (op, FLAG_REMOVED); |
1872 | CLEAR_FLAG (op, FLAG_REMOVED); |
1884 | if (op->nrof) |
1873 | if (op->nrof) |
1885 | { |
1874 | { |
1886 | for (tmp = where->inv; tmp != NULL; tmp = tmp->below) |
1875 | for (tmp = where->inv; tmp != NULL; tmp = tmp->below) |
… | |
… | |
1979 | tag; |
1968 | tag; |
1980 | mapstruct * |
1969 | mapstruct * |
1981 | m = op->map; |
1970 | m = op->map; |
1982 | int |
1971 | int |
1983 | x = op->x, y = op->y; |
1972 | x = op->x, y = op->y; |
|
|
1973 | |
1984 | MoveType |
1974 | MoveType |
1985 | move_on, |
1975 | move_on, |
1986 | move_slow, |
1976 | move_slow, |
1987 | move_block; |
1977 | move_block; |
1988 | |
1978 | |
… | |
… | |
2022 | * we don't need to check all of them. |
2012 | * we don't need to check all of them. |
2023 | */ |
2013 | */ |
2024 | if ((tmp->move_type & MOVE_FLY_LOW) && QUERY_FLAG (tmp, FLAG_NO_PICK)) |
2014 | if ((tmp->move_type & MOVE_FLY_LOW) && QUERY_FLAG (tmp, FLAG_NO_PICK)) |
2025 | break; |
2015 | break; |
2026 | } |
2016 | } |
|
|
2017 | |
2027 | for (; tmp != NULL; tmp = tmp->below) |
2018 | for (; tmp; tmp = tmp->below) |
2028 | { |
2019 | { |
2029 | if (tmp == op) |
2020 | if (tmp == op) |
2030 | continue; /* Can't apply yourself */ |
2021 | continue; /* Can't apply yourself */ |
2031 | |
2022 | |
2032 | /* Check to see if one of the movement types should be slowed down. |
2023 | /* Check to see if one of the movement types should be slowed down. |
… | |
… | |
2040 | if ((!op->move_type && tmp->move_slow & MOVE_WALK) || |
2031 | if ((!op->move_type && tmp->move_slow & MOVE_WALK) || |
2041 | ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0)) |
2032 | ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0)) |
2042 | { |
2033 | { |
2043 | |
2034 | |
2044 | float |
2035 | float |
2045 | diff; |
|
|
2046 | |
|
|
2047 | diff = tmp->move_slow_penalty * FABS (op->speed); |
2036 | diff = tmp->move_slow_penalty * FABS (op->speed); |
|
|
2037 | |
2048 | if (op->type == PLAYER) |
2038 | if (op->type == PLAYER) |
2049 | { |
|
|
2050 | if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || |
2039 | if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || |
2051 | (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) |
2040 | (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) |
2052 | { |
|
|
2053 | diff /= 4.0; |
2041 | diff /= 4.0; |
2054 | } |
2042 | |
2055 | } |
|
|
2056 | op->speed_left -= diff; |
2043 | op->speed_left -= diff; |
2057 | } |
2044 | } |
2058 | } |
2045 | } |
2059 | |
2046 | |
2060 | /* Basically same logic as above, except now for actual apply. */ |
2047 | /* Basically same logic as above, except now for actual apply. */ |
2061 | if ((!op->move_type && tmp->move_on & MOVE_WALK) || |
2048 | if ((!op->move_type && tmp->move_on & MOVE_WALK) || |
2062 | ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0)) |
2049 | ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0)) |
2063 | { |
2050 | { |
2064 | |
|
|
2065 | move_apply (tmp, op, originator); |
2051 | move_apply (tmp, op, originator); |
|
|
2052 | |
2066 | if (was_destroyed (op, tag)) |
2053 | if (was_destroyed (op, tag)) |
2067 | return 1; |
2054 | return 1; |
2068 | |
2055 | |
2069 | /* what the person/creature stepped onto has moved the object |
2056 | /* what the person/creature stepped onto has moved the object |
2070 | * someplace new. Don't process any further - if we did, |
2057 | * someplace new. Don't process any further - if we did, |
… | |
… | |
2072 | */ |
2059 | */ |
2073 | if (op->map != m || op->x != x || op->y != y) |
2060 | if (op->map != m || op->x != x || op->y != y) |
2074 | return 0; |
2061 | return 0; |
2075 | } |
2062 | } |
2076 | } |
2063 | } |
|
|
2064 | |
2077 | return 0; |
2065 | return 0; |
2078 | } |
2066 | } |
2079 | |
2067 | |
2080 | /* |
2068 | /* |
2081 | * present_arch(arch, map, x, y) searches for any objects with |
2069 | * present_arch(arch, map, x, y) searches for any objects with |
… | |
… | |
2372 | find_dir (mapstruct *m, int x, int y, object *exclude) |
2360 | find_dir (mapstruct *m, int x, int y, object *exclude) |
2373 | { |
2361 | { |
2374 | int |
2362 | int |
2375 | i, |
2363 | i, |
2376 | max = SIZEOFFREE, mflags; |
2364 | max = SIZEOFFREE, mflags; |
2377 | sint16 |
2365 | |
2378 | nx, |
2366 | sint16 nx, ny; |
2379 | ny; |
|
|
2380 | object * |
2367 | object * |
2381 | tmp; |
2368 | tmp; |
2382 | mapstruct * |
2369 | mapstruct * |
2383 | mp; |
2370 | mp; |
2384 | MoveType |
2371 | |
2385 | blocked, |
2372 | MoveType blocked, move_type; |
2386 | move_type; |
|
|
2387 | |
2373 | |
2388 | if (exclude && exclude->head) |
2374 | if (exclude && exclude->head) |
2389 | { |
2375 | { |
2390 | exclude = exclude->head; |
2376 | exclude = exclude->head; |
2391 | move_type = exclude->move_type; |
2377 | move_type = exclude->move_type; |
… | |
… | |
2598 | |
2584 | |
2599 | |
2585 | |
2600 | int |
2586 | int |
2601 | can_see_monsterP (mapstruct *m, int x, int y, int dir) |
2587 | can_see_monsterP (mapstruct *m, int x, int y, int dir) |
2602 | { |
2588 | { |
2603 | sint16 |
2589 | sint16 dx, dy; |
2604 | dx, |
|
|
2605 | dy; |
|
|
2606 | int |
2590 | int |
2607 | mflags; |
2591 | mflags; |
2608 | |
2592 | |
2609 | if (dir < 0) |
2593 | if (dir < 0) |
2610 | return 0; /* exit condition: invalid direction */ |
2594 | return 0; /* exit condition: invalid direction */ |
… | |
… | |
2741 | fprintf (tempfile, obstr); |
2725 | fprintf (tempfile, obstr); |
2742 | fclose (tempfile); |
2726 | fclose (tempfile); |
2743 | |
2727 | |
2744 | op = get_object (); |
2728 | op = get_object (); |
2745 | |
2729 | |
2746 | object_thawer |
2730 | object_thawer thawer (filename); |
2747 | thawer (filename); |
|
|
2748 | |
2731 | |
2749 | if (thawer) |
2732 | if (thawer) |
2750 | load_object (thawer, op, 0); |
2733 | load_object (thawer, op, 0); |
2751 | |
2734 | |
2752 | LOG (llevDebug, " load str completed, object=%s\n", &op->name); |
2735 | LOG (llevDebug, " load str completed, object=%s\n", &op->name); |
… | |
… | |
2876 | if (last) |
2859 | if (last) |
2877 | last->next = field->next; |
2860 | last->next = field->next; |
2878 | else |
2861 | else |
2879 | op->key_values = field->next; |
2862 | op->key_values = field->next; |
2880 | |
2863 | |
2881 | delete |
|
|
2882 | field; |
2864 | delete field; |
2883 | } |
2865 | } |
2884 | } |
2866 | } |
2885 | return TRUE; |
2867 | return TRUE; |
2886 | } |
2868 | } |
2887 | /* IF we get here, key doesn't exist */ |
2869 | /* IF we get here, key doesn't exist */ |
… | |
… | |
2922 | * Returns TRUE on success. |
2904 | * Returns TRUE on success. |
2923 | */ |
2905 | */ |
2924 | int |
2906 | int |
2925 | set_ob_key_value (object *op, const char *key, const char *value, int add_key) |
2907 | set_ob_key_value (object *op, const char *key, const char *value, int add_key) |
2926 | { |
2908 | { |
2927 | shstr |
|
|
2928 | key_ (key); |
2909 | shstr key_ (key); |
2929 | |
2910 | |
2930 | return set_ob_key_value_s (op, key_, value, add_key); |
2911 | return set_ob_key_value_s (op, key_, value, add_key); |
2931 | } |
2912 | } |