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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines