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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.27 by root, Mon Sep 11 12:08:45 2006 UTC vs.
Revision 1.29 by root, Mon Sep 11 12:38:36 2006 UTC

1
2/*
3 * static char *rcsid_object_c =
4 * "$Id: object.C,v 1.27 2006/09/11 12:08:45 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
43int nrofallocobjects = 0; 37int nrofallocobjects = 0;
44 38
45object *objects; /* Pointer to the list of used objects */ 39object *objects; /* Pointer to the list of used objects */
46object *active_objects; /* List of active objects that need to be processed */ 40object *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 */
254signed long 248long
255sum_weight (object *op) 249sum_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)
893 * that is being removed. 887 * that is being removed.
894 */ 888 */
895 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) 889 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE)
896 update_now = 1; 890 update_now = 1;
897 else if (action == UP_OBJ_FACE) 891 else if (action == UP_OBJ_FACE)
898 /* Nothing to do for that case */; 892 /* Nothing to do for that case */ ;
899 else 893 else
900 LOG (llevError, "update_object called with invalid action: %d\n", action); 894 LOG (llevError, "update_object called with invalid action: %d\n", action);
901 895
902 if (update_now) 896 if (update_now)
903 { 897 {
907 901
908 if (op->more != NULL) 902 if (op->more != NULL)
909 update_object (op->more, action); 903 update_object (op->more, action);
910} 904}
911 905
912static unordered_vector<object *> mortals; 906static unordered_vector < object *>mortals;
913static std::vector<object *> freed; 907static
908std::vector < object *>
909 freed;
914 910
915void object::free_mortals () 911void object::free_mortals ()
916{ 912{
917 for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end (); ) 913 for (unordered_vector < object *>::iterator i = mortals.begin (); i != mortals.end ();)
918 if (!(*i)->refcount) 914 if (!(*i)->refcount)
919 { 915 {
920 freed.push_back (*i); 916 freed.push_back (*i);
921 mortals.erase (i); 917 mortals.erase (i);
922 } 918 }
972 objects = next; 968 objects = next;
973} 969}
974 970
975object *object::create () 971object *object::create ()
976{ 972{
977 object *op; 973 object *
974 op;
978 975
979 if (freed.empty ()) 976 if (freed.empty ())
980 op = new object; 977 op = new object;
978
981 else 979 else
982 { 980 {
983 // highly annoying, but the only way to get it stable right now 981 // highly annoying, but the only way to get it stable right now
984 op = freed.back (); freed.pop_back (); 982 op = freed.back ();
983 freed.pop_back ();
985 op->~object (); 984 op->~object ();
986 new ((void *)op) object; 985 new ((void *) op) object;
987 } 986 }
988 987
989 op->link (); 988 op->link ();
990 return op; 989 return op;
991} 990}
1000 * 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
1001 * inventory to the ground. 1000 * inventory to the ground.
1002 */ 1001 */
1003void object::free (bool free_inventory) 1002void object::free (bool free_inventory)
1004{ 1003{
1004 if (QUERY_FLAG (this, FLAG_FREED))
1005 return;
1006
1005 if (!QUERY_FLAG (this, FLAG_REMOVED)) 1007 if (!QUERY_FLAG (this, FLAG_REMOVED))
1006 { 1008 remove_ob (this);
1007 LOG (llevDebug, "Free object called with non removed object\n");
1008 dump_object (this);
1009#ifdef MANY_CORES
1010 abort ();
1011#endif
1012 }
1013 1009
1014 if (QUERY_FLAG (this, FLAG_FRIENDLY)) 1010 if (QUERY_FLAG (this, FLAG_FRIENDLY))
1015 {
1016 LOG (llevMonster, "Warning: tried to free friendly object.\n");
1017 remove_friendly_object (this); 1011 remove_friendly_object (this);
1018 }
1019 1012
1020 if (QUERY_FLAG (this, FLAG_FREED)) 1013 SET_FLAG (this, FLAG_FREED);
1021 {
1022 dump_object (this);
1023 LOG (llevError, "Trying to free freed object.\n%s\n", errmsg);
1024 return;
1025 }
1026 1014
1027 if (more) 1015 if (more)
1028 { 1016 {
1029 more->free (free_inventory); 1017 more->free (free_inventory);
1030 more = 0; 1018 more = 0;
1036 * if some form of movement is allowed, let objects 1024 * if some form of movement is allowed, let objects
1037 * drop on that space. 1025 * drop on that space.
1038 */ 1026 */
1039 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))
1040 { 1028 {
1041 object * 1029 object *op = inv;
1042 op = inv;
1043 1030
1044 while (op) 1031 while (op)
1045 { 1032 {
1046 object *
1047 tmp = op->below; 1033 object *tmp = op->below;
1048
1049 remove_ob (op);
1050 op->free (free_inventory); 1034 op->free (free_inventory);
1051 op = tmp; 1035 op = tmp;
1052 } 1036 }
1053 } 1037 }
1054 else 1038 else
1055 { /* Put objects in inventory onto this space */ 1039 { /* Put objects in inventory onto this space */
1056 object * 1040 object *op = inv;
1057 op = inv;
1058 1041
1059 while (op) 1042 while (op)
1060 { 1043 {
1061 object *
1062 tmp = op->below; 1044 object *tmp = op->below;
1063 1045
1064 remove_ob (op); 1046 remove_ob (op);
1065 1047
1066 if (QUERY_FLAG (op, FLAG_STARTEQUIP) 1048 if (QUERY_FLAG (op, FLAG_STARTEQUIP)
1067 || 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))
1084 speed = 0; 1066 speed = 0;
1085 update_ob_speed (this); 1067 update_ob_speed (this);
1086 1068
1087 unlink (); 1069 unlink ();
1088 1070
1089 SET_FLAG (this, FLAG_FREED);
1090
1091 mortals.push_back (this); 1071 mortals.push_back (this);
1092} 1072}
1093 1073
1094/* 1074/*
1095 * sub_weight() recursively (outwards) subtracts a number from the 1075 * sub_weight() recursively (outwards) subtracts a number from the
1120 */ 1100 */
1121 1101
1122void 1102void
1123remove_ob (object *op) 1103remove_ob (object *op)
1124{ 1104{
1125 object *tmp, *last = NULL;
1126 object *otmp; 1105 object *
1106 tmp, *
1107 last = NULL;
1108 object *
1109 otmp;
1127 1110
1128 tag_t tag; 1111 tag_t
1112 tag;
1113 int
1129 int check_walk_off; 1114 check_walk_off;
1130 mapstruct *m; 1115 mapstruct *
1116 m;
1131 1117
1132 sint16 x, y; 1118 sint16
1119 x,
1120 y;
1133 1121
1134 if (QUERY_FLAG (op, FLAG_REMOVED)) 1122 if (QUERY_FLAG (op, FLAG_REMOVED))
1135 { 1123 return;
1136 dump_object (op);
1137 LOG (llevError, "Trying to remove removed object.\n%s\n", errmsg);
1138 1124
1139 /* Changed it to always dump core in this case. As has been learned 1125 SET_FLAG (op, FLAG_REMOVED);
1140 * in the past, trying to recover from errors almost always
1141 * make things worse, and this is a real error here - something
1142 * that should not happen.
1143 * Yes, if this was a mission critical app, trying to do something
1144 * to recover may make sense, but that is because failure of the app
1145 * may have other disastrous problems. Cf runs out of a script
1146 * so is easily enough restarted without any real problems.
1147 * MSW 2001-07-01
1148 */
1149 abort ();
1150 }
1151 1126
1152 if (op->more != NULL) 1127 if (op->more != NULL)
1153 remove_ob (op->more); 1128 remove_ob (op->more);
1154
1155 SET_FLAG (op, FLAG_REMOVED);
1156 1129
1157 /* 1130 /*
1158 * In this case, the object to be removed is in someones 1131 * In this case, the object to be removed is in someones
1159 * inventory. 1132 * inventory.
1160 */ 1133 */
1186 */ 1159 */
1187 op->x = op->env->x, op->y = op->env->y; 1160 op->x = op->env->x, op->y = op->env->y;
1188 op->map = op->env->map; 1161 op->map = op->env->map;
1189 op->above = NULL, op->below = NULL; 1162 op->above = NULL, op->below = NULL;
1190 op->env = NULL; 1163 op->env = NULL;
1191 return; 1164 }
1165 else if (op->map)
1192 } 1166 {
1193
1194 /* If we get here, we are removing it from a map */
1195 if (op->map == NULL)
1196 return;
1197
1198 x = op->x; 1167 x = op->x;
1199 y = op->y; 1168 y = op->y;
1200 m = get_map_from_coord (op->map, &x, &y); 1169 m = get_map_from_coord (op->map, &x, &y);
1201 1170
1202 if (!m) 1171 if (!m)
1203 { 1172 {
1204 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",
1205 op->map->path, op->x, op->y); 1174 op->map->path, op->x, op->y);
1206 /* 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.
1207 * it seems if we get into this case, something is probablye 1176 * it seems if we get into this case, something is probablye
1208 * 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
1209 */ 1188 */
1210 abort ();
1211 }
1212 if (op->map != m)
1213 {
1214 LOG (llevDebug, "remove_ob: Object not really on map it claimed to be on? %s != %s, %d,%d != %d,%d\n",
1215 op->map->path, m->path, op->x, op->y, x, y);
1216 }
1217 1189
1218 /* Re did the following section of code - it looks like it had
1219 * lots of logic for things we no longer care about
1220 */
1221
1222 /* link the object above us */ 1190 /* link the object above us */
1223 if (op->above) 1191 if (op->above)
1224 op->above->below = op->below; 1192 op->above->below = op->below;
1225 else 1193 else
1226 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 */
1227 1195
1228 /* Relink the object below us, if there is one */ 1196 /* Relink the object below us, if there is one */
1229 if (op->below) 1197 if (op->below)
1230 op->below->above = op->above; 1198 op->below->above = op->above;
1231 else 1199 else
1232 { 1200 {
1233 /* 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
1234 * use translated coordinates in case some oddness with map tiling is 1202 * use translated coordinates in case some oddness with map tiling is
1235 * evident 1203 * evident
1236 */
1237 if (GET_MAP_OB (m, x, y) != op)
1238 {
1239 dump_object (op);
1240 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",
1241 errmsg);
1242 dump_object (GET_MAP_OB (m, x, y));
1243 LOG (llevError, "%s\n", errmsg);
1244 }
1245
1246 SET_MAP_OB (m, x, y, op->above); /* goes on above it. */
1247 }
1248
1249 op->above = NULL;
1250 op->below = NULL;
1251
1252 if (op->map->in_memory == MAP_SAVING)
1253 return;
1254
1255 tag = op->count;
1256 check_walk_off = !QUERY_FLAG (op, FLAG_NO_APPLY);
1257
1258 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
1259 {
1260 /* No point updating the players look faces if he is the object
1261 * being removed.
1262 */
1263
1264 if (tmp->type == PLAYER && tmp != op)
1265 {
1266 /* If a container that the player is currently using somehow gets
1267 * removed (most likely destroyed), update the player view
1268 * appropriately.
1269 */ 1204 */
1270 if (tmp->container == op) 1205 if (GET_MAP_OB (m, x, y) != op)
1271 { 1206 {
1272 CLEAR_FLAG (op, FLAG_APPLIED); 1207 dump_object (op);
1273 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);
1274 } 1212 }
1275 1213
1276 tmp->contr->socket.update_look = 1; 1214 SET_MAP_OB (m, x, y, op->above); /* goes on above it. */
1277 }
1278 /* See if player moving off should effect something */
1279 if (check_walk_off && ((op->move_type & tmp->move_off) && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0))
1280 { 1215 }
1281 move_apply (tmp, op, NULL);
1282 1216
1283 if (was_destroyed (op, tag)) 1217 op->above = 0;
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)
1284 { 1233 {
1285 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;
1286 } 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 }
1287 } 1256 }
1288 1257
1289 /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ 1258 /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */
1290 1259
1291 if (tmp->above == tmp) 1260 if (tmp->above == tmp)
1292 tmp->above = NULL; 1261 tmp->above = NULL;
1293 1262
1294 last = tmp; 1263 last = tmp;
1295 } 1264 }
1296 1265
1297 /* last == NULL of there are no objects on this space */ 1266 /* last == NULL of there are no objects on this space */
1298 if (last == NULL) 1267 if (last == NULL)
1299 { 1268 {
1300 /* set P_NEED_UPDATE, otherwise update_position will complain. In theory, 1269 /* set P_NEED_UPDATE, otherwise update_position will complain. In theory,
1301 * 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
1302 * 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
1303 * be correct anyways. 1272 * be correct anyways.
1304 */ 1273 */
1305 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);
1306 update_position (op->map, op->x, op->y); 1275 update_position (op->map, op->x, op->y);
1307 } 1276 }
1308 else 1277 else
1309 update_object (last, UP_OBJ_REMOVE); 1278 update_object (last, UP_OBJ_REMOVE);
1310 1279
1311 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0)) 1280 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0))
1312 update_all_los (op->map, op->x, op->y); 1281 update_all_los (op->map, op->x, op->y);
1282 }
1313} 1283}
1314 1284
1315/* 1285/*
1316 * merge_ob(op,top): 1286 * merge_ob(op,top):
1317 * 1287 *
1324object * 1294object *
1325merge_ob (object *op, object *top) 1295merge_ob (object *op, object *top)
1326{ 1296{
1327 if (!op->nrof) 1297 if (!op->nrof)
1328 return 0; 1298 return 0;
1299
1329 if (top == NULL) 1300 if (top == NULL)
1330 for (top = op; top != NULL && top->above != NULL; top = top->above); 1301 for (top = op; top != NULL && top->above != NULL; top = top->above);
1302
1331 for (; top != NULL; top = top->below) 1303 for (; top != NULL; top = top->below)
1332 { 1304 {
1333 if (top == op) 1305 if (top == op)
1334 continue; 1306 continue;
1335 if (CAN_MERGE (op, top)) 1307 if (CAN_MERGE (op, top))
1341 remove_ob (op); 1313 remove_ob (op);
1342 free_object (op); 1314 free_object (op);
1343 return top; 1315 return top;
1344 } 1316 }
1345 } 1317 }
1318
1346 return NULL; 1319 return NULL;
1347} 1320}
1348 1321
1349/* 1322/*
1350 * 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
1351 * job preparing multi-part monsters 1324 * job preparing multi-part monsters
1352 */ 1325 */
1353object * 1326object *
1354insert_ob_in_map_at (object *op, mapstruct *m, object *originator, int flag, int x, int y) 1327insert_ob_in_map_at (object *op, mapstruct *m, object *originator, int flag, int x, int y)
1355{ 1328{
1356 object * 1329 object *tmp;
1357 tmp;
1358 1330
1359 if (op->head) 1331 if (op->head)
1360 op = op->head; 1332 op = op->head;
1333
1361 for (tmp = op; tmp; tmp = tmp->more) 1334 for (tmp = op; tmp; tmp = tmp->more)
1362 { 1335 {
1363 tmp->x = x + tmp->arch->clone.x; 1336 tmp->x = x + tmp->arch->clone.x;
1364 tmp->y = y + tmp->arch->clone.y; 1337 tmp->y = y + tmp->arch->clone.y;
1365 } 1338 }
1339
1366 return insert_ob_in_map (op, m, originator, flag); 1340 return insert_ob_in_map (op, m, originator, flag);
1367} 1341}
1368 1342
1369/* 1343/*
1370 * insert_ob_in_map (op, map, originator, flag): 1344 * insert_ob_in_map (op, map, originator, flag):
1661 * op is the object to insert it under: supplies x and the map. 1635 * op is the object to insert it under: supplies x and the map.
1662 */ 1636 */
1663void 1637void
1664replace_insert_ob_in_map (const char *arch_string, object *op) 1638replace_insert_ob_in_map (const char *arch_string, object *op)
1665{ 1639{
1666 object *tmp; 1640 object *
1641 tmp;
1667 object *tmp1; 1642 object *
1643 tmp1;
1668 1644
1669 /* first search for itself and remove any old instances */ 1645 /* first search for itself and remove any old instances */
1670 1646
1671 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 1647 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
1672 { 1648 {
1703 if (orig_ob->nrof < nr) 1679 if (orig_ob->nrof < nr)
1704 { 1680 {
1705 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);
1706 return NULL; 1682 return NULL;
1707 } 1683 }
1684
1708 newob = object_create_clone (orig_ob); 1685 newob = object_create_clone (orig_ob);
1686
1709 if ((orig_ob->nrof -= nr) < 1) 1687 if ((orig_ob->nrof -= nr) < 1)
1710 { 1688 {
1711 if (!is_removed) 1689 if (!is_removed)
1712 remove_ob (orig_ob); 1690 remove_ob (orig_ob);
1713 free_object2 (orig_ob, 1); 1691 free_object2 (orig_ob, 1);
1721 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.");
1722 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");
1723 return NULL; 1701 return NULL;
1724 } 1702 }
1725 } 1703 }
1704
1726 newob->nrof = nr; 1705 newob->nrof = nr;
1727 1706
1728 return newob; 1707 return newob;
1729} 1708}
1730 1709
1737 */ 1716 */
1738 1717
1739object * 1718object *
1740decrease_ob_nr (object *op, uint32 i) 1719decrease_ob_nr (object *op, uint32 i)
1741{ 1720{
1742 object * 1721 object *tmp;
1743 tmp;
1744 player * 1722 player *pl;
1745 pl;
1746 1723
1747 if (i == 0) /* objects with op->nrof require this check */ 1724 if (i == 0) /* objects with op->nrof require this check */
1748 return op; 1725 return op;
1749 1726
1750 if (i > op->nrof) 1727 if (i > op->nrof)
1751 i = op->nrof; 1728 i = op->nrof;
1752 1729
1753 if (QUERY_FLAG (op, FLAG_REMOVED)) 1730 if (QUERY_FLAG (op, FLAG_REMOVED))
1754 {
1755 op->nrof -= i; 1731 op->nrof -= i;
1756 }
1757 else if (op->env != NULL) 1732 else if (op->env != NULL)
1758 { 1733 {
1759 /* is this object in the players inventory, or sub container 1734 /* is this object in the players inventory, or sub container
1760 * therein? 1735 * therein?
1761 */ 1736 */
1796 } 1771 }
1797 } 1772 }
1798 } 1773 }
1799 else 1774 else
1800 { 1775 {
1801 object *
1802 above = op->above; 1776 object *above = op->above;
1803 1777
1804 if (i < op->nrof) 1778 if (i < op->nrof)
1805 {
1806 op->nrof -= i; 1779 op->nrof -= i;
1807 }
1808 else 1780 else
1809 { 1781 {
1810 remove_ob (op); 1782 remove_ob (op);
1811 op->nrof = 0; 1783 op->nrof = 0;
1812 } 1784 }
1785
1813 /* Since we just removed op, op->above is null */ 1786 /* Since we just removed op, op->above is null */
1814 for (tmp = above; tmp != NULL; tmp = tmp->above) 1787 for (tmp = above; tmp != NULL; tmp = tmp->above)
1815 if (tmp->type == PLAYER) 1788 if (tmp->type == PLAYER)
1816 { 1789 {
1817 if (op->nrof) 1790 if (op->nrof)
1820 esrv_del_item (tmp->contr, op->count); 1793 esrv_del_item (tmp->contr, op->count);
1821 } 1794 }
1822 } 1795 }
1823 1796
1824 if (op->nrof) 1797 if (op->nrof)
1825 {
1826 return op; 1798 return op;
1827 }
1828 else 1799 else
1829 { 1800 {
1830 free_object (op); 1801 free_object (op);
1831 return NULL; 1802 return NULL;
1832 } 1803 }
1841add_weight (object *op, signed long weight) 1812add_weight (object *op, signed long weight)
1842{ 1813{
1843 while (op != NULL) 1814 while (op != NULL)
1844 { 1815 {
1845 if (op->type == CONTAINER) 1816 if (op->type == CONTAINER)
1846 {
1847 weight = (signed long) (weight * (100 - op->stats.Str) / 100); 1817 weight = (signed long) (weight * (100 - op->stats.Str) / 100);
1848 } 1818
1849 op->carrying += weight; 1819 op->carrying += weight;
1850 op = op->env; 1820 op = op->env;
1851 } 1821 }
1852} 1822}
1853 1823
1876 { 1846 {
1877 dump_object (op); 1847 dump_object (op);
1878 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);
1879 return op; 1849 return op;
1880 } 1850 }
1851
1881 if (where == NULL) 1852 if (where == NULL)
1882 { 1853 {
1883 dump_object (op); 1854 dump_object (op);
1884 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);
1885 return op; 1856 return op;
1886 } 1857 }
1858
1887 if (where->head) 1859 if (where->head)
1888 { 1860 {
1889 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");
1890 where = where->head; 1862 where = where->head;
1891 } 1863 }
1864
1892 if (op->more) 1865 if (op->more)
1893 { 1866 {
1894 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);
1895 return op; 1868 return op;
1896 } 1869 }
1870
1897 CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); 1871 CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL);
1898 CLEAR_FLAG (op, FLAG_REMOVED); 1872 CLEAR_FLAG (op, FLAG_REMOVED);
1899 if (op->nrof) 1873 if (op->nrof)
1900 { 1874 {
1901 for (tmp = where->inv; tmp != NULL; tmp = tmp->below) 1875 for (tmp = where->inv; tmp != NULL; tmp = tmp->below)
1986 */ 1960 */
1987 1961
1988int 1962int
1989check_move_on (object *op, object *originator) 1963check_move_on (object *op, object *originator)
1990{ 1964{
1991 object *tmp; 1965 object *
1992 tag_t tag; 1966 tmp;
1993 mapstruct *m = op->map; 1967 tag_t
1968 tag;
1969 mapstruct *
1970 m = op->map;
1971 int
1994 int x = op->x, y = op->y; 1972 x = op->x, y = op->y;
1995 1973
1996 MoveType move_on, move_slow, move_block; 1974 MoveType
1975 move_on,
1976 move_slow,
1977 move_block;
1997 1978
1998 if (QUERY_FLAG (op, FLAG_NO_APPLY)) 1979 if (QUERY_FLAG (op, FLAG_NO_APPLY))
1999 return 0; 1980 return 0;
2000 1981
2001 tag = op->count; 1982 tag = op->count;
2049 { 2030 {
2050 if ((!op->move_type && tmp->move_slow & MOVE_WALK) || 2031 if ((!op->move_type && tmp->move_slow & MOVE_WALK) ||
2051 ((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))
2052 { 2033 {
2053 2034
2035 float
2054 float diff = tmp->move_slow_penalty * FABS (op->speed); 2036 diff = tmp->move_slow_penalty * FABS (op->speed);
2055 2037
2056 if (op->type == PLAYER) 2038 if (op->type == PLAYER)
2057 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)) ||
2058 (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)))
2059 diff /= 4.0; 2041 diff /= 4.0;
2378find_dir (mapstruct *m, int x, int y, object *exclude) 2360find_dir (mapstruct *m, int x, int y, object *exclude)
2379{ 2361{
2380 int 2362 int
2381 i, 2363 i,
2382 max = SIZEOFFREE, mflags; 2364 max = SIZEOFFREE, mflags;
2383 sint16 2365
2384 nx, 2366 sint16 nx, ny;
2385 ny;
2386 object * 2367 object *
2387 tmp; 2368 tmp;
2388 mapstruct * 2369 mapstruct *
2389 mp; 2370 mp;
2390 MoveType 2371
2391 blocked, 2372 MoveType blocked, move_type;
2392 move_type;
2393 2373
2394 if (exclude && exclude->head) 2374 if (exclude && exclude->head)
2395 { 2375 {
2396 exclude = exclude->head; 2376 exclude = exclude->head;
2397 move_type = exclude->move_type; 2377 move_type = exclude->move_type;
2604 2584
2605 2585
2606int 2586int
2607can_see_monsterP (mapstruct *m, int x, int y, int dir) 2587can_see_monsterP (mapstruct *m, int x, int y, int dir)
2608{ 2588{
2609 sint16 2589 sint16 dx, dy;
2610 dx,
2611 dy;
2612 int 2590 int
2613 mflags; 2591 mflags;
2614 2592
2615 if (dir < 0) 2593 if (dir < 0)
2616 return 0; /* exit condition: invalid direction */ 2594 return 0; /* exit condition: invalid direction */
2747 fprintf (tempfile, obstr); 2725 fprintf (tempfile, obstr);
2748 fclose (tempfile); 2726 fclose (tempfile);
2749 2727
2750 op = get_object (); 2728 op = get_object ();
2751 2729
2752 object_thawer 2730 object_thawer thawer (filename);
2753 thawer (filename);
2754 2731
2755 if (thawer) 2732 if (thawer)
2756 load_object (thawer, op, 0); 2733 load_object (thawer, op, 0);
2757 2734
2758 LOG (llevDebug, " load str completed, object=%s\n", &op->name); 2735 LOG (llevDebug, " load str completed, object=%s\n", &op->name);
2882 if (last) 2859 if (last)
2883 last->next = field->next; 2860 last->next = field->next;
2884 else 2861 else
2885 op->key_values = field->next; 2862 op->key_values = field->next;
2886 2863
2887 delete
2888 field; 2864 delete field;
2889 } 2865 }
2890 } 2866 }
2891 return TRUE; 2867 return TRUE;
2892 } 2868 }
2893 /* IF we get here, key doesn't exist */ 2869 /* IF we get here, key doesn't exist */
2928 * Returns TRUE on success. 2904 * Returns TRUE on success.
2929 */ 2905 */
2930int 2906int
2931set_ob_key_value (object *op, const char *key, const char *value, int add_key) 2907set_ob_key_value (object *op, const char *key, const char *value, int add_key)
2932{ 2908{
2933 shstr
2934 key_ (key); 2909 shstr key_ (key);
2935 2910
2936 return set_ob_key_value_s (op, key_, value, add_key); 2911 return set_ob_key_value_s (op, key_, value, add_key);
2937} 2912}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines