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.25 by root, Mon Sep 11 01:16:20 2006 UTC vs.
Revision 1.27 by root, Mon Sep 11 12:08:45 2006 UTC

1 1
2/* 2/*
3 * static char *rcsid_object_c = 3 * static char *rcsid_object_c =
4 * "$Id: object.C,v 1.25 2006/09/11 01:16:20 root Exp $"; 4 * "$Id: object.C,v 1.27 2006/09/11 12:08:45 root Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
891 /* if the object is being removed, we can't make intelligent 891 /* if the object is being removed, we can't make intelligent
892 * decisions, because remove_ob can't really pass the object 892 * decisions, because remove_ob can't really pass the object
893 * that is being removed. 893 * that is being removed.
894 */ 894 */
895 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) 895 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE)
896 {
897 update_now = 1; 896 update_now = 1;
898 }
899 else if (action == UP_OBJ_FACE) 897 else if (action == UP_OBJ_FACE)
900 {
901 /* Nothing to do for that case */ 898 /* Nothing to do for that case */;
902 }
903 else 899 else
904 {
905 LOG (llevError, "update_object called with invalid action: %d\n", action); 900 LOG (llevError, "update_object called with invalid action: %d\n", action);
906 }
907 901
908 if (update_now) 902 if (update_now)
909 { 903 {
910 SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NO_ERROR | P_NEED_UPDATE); 904 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); 905 update_position (op->map, op->x, op->y);
1126 */ 1120 */
1127 1121
1128void 1122void
1129remove_ob (object *op) 1123remove_ob (object *op)
1130{ 1124{
1125 object *tmp, *last = NULL;
1131 object * 1126 object *otmp;
1132 tmp, * 1127
1133 last = NULL; 1128 tag_t tag;
1134 object *
1135 otmp;
1136 tag_t
1137 tag;
1138 int
1139 check_walk_off; 1129 int check_walk_off;
1140 mapstruct * 1130 mapstruct *m;
1141 m;
1142 sint16
1143 x,
1144 y;
1145 1131
1132 sint16 x, y;
1146 1133
1147 if (QUERY_FLAG (op, FLAG_REMOVED)) 1134 if (QUERY_FLAG (op, FLAG_REMOVED))
1148 { 1135 {
1149 dump_object (op); 1136 dump_object (op);
1150 LOG (llevError, "Trying to remove removed object.\n%s\n", errmsg); 1137 LOG (llevError, "Trying to remove removed object.\n%s\n", errmsg);
1159 * so is easily enough restarted without any real problems. 1146 * so is easily enough restarted without any real problems.
1160 * MSW 2001-07-01 1147 * MSW 2001-07-01
1161 */ 1148 */
1162 abort (); 1149 abort ();
1163 } 1150 }
1151
1164 if (op->more != NULL) 1152 if (op->more != NULL)
1165 remove_ob (op->more); 1153 remove_ob (op->more);
1166 1154
1167 SET_FLAG (op, FLAG_REMOVED); 1155 SET_FLAG (op, FLAG_REMOVED);
1168 1156
1237 else 1225 else
1238 SET_MAP_TOP (m, x, y, op->below); /* we were top, set new top */ 1226 SET_MAP_TOP (m, x, y, op->below); /* we were top, set new top */
1239 1227
1240 /* Relink the object below us, if there is one */ 1228 /* Relink the object below us, if there is one */
1241 if (op->below) 1229 if (op->below)
1242 {
1243 op->below->above = op->above; 1230 op->below->above = op->above;
1244 }
1245 else 1231 else
1246 { 1232 {
1247 /* Nothing below, which means we need to relink map object for this space 1233 /* Nothing below, which means we need to relink map object for this space
1248 * use translated coordinates in case some oddness with map tiling is 1234 * use translated coordinates in case some oddness with map tiling is
1249 * evident 1235 * evident
1254 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", 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",
1255 errmsg); 1241 errmsg);
1256 dump_object (GET_MAP_OB (m, x, y)); 1242 dump_object (GET_MAP_OB (m, x, y));
1257 LOG (llevError, "%s\n", errmsg); 1243 LOG (llevError, "%s\n", errmsg);
1258 } 1244 }
1245
1259 SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ 1246 SET_MAP_OB (m, x, y, op->above); /* goes on above it. */
1260 } 1247 }
1248
1261 op->above = NULL; 1249 op->above = NULL;
1262 op->below = NULL; 1250 op->below = NULL;
1263 1251
1264 if (op->map->in_memory == MAP_SAVING) 1252 if (op->map->in_memory == MAP_SAVING)
1265 return; 1253 return;
1266 1254
1267 tag = op->count; 1255 tag = op->count;
1268 check_walk_off = !QUERY_FLAG (op, FLAG_NO_APPLY); 1256 check_walk_off = !QUERY_FLAG (op, FLAG_NO_APPLY);
1257
1269 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1258 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
1270 { 1259 {
1271 /* No point updating the players look faces if he is the object 1260 /* No point updating the players look faces if he is the object
1272 * being removed. 1261 * being removed.
1273 */ 1262 */
1281 if (tmp->container == op) 1270 if (tmp->container == op)
1282 { 1271 {
1283 CLEAR_FLAG (op, FLAG_APPLIED); 1272 CLEAR_FLAG (op, FLAG_APPLIED);
1284 tmp->container = NULL; 1273 tmp->container = NULL;
1285 } 1274 }
1275
1286 tmp->contr->socket.update_look = 1; 1276 tmp->contr->socket.update_look = 1;
1287 } 1277 }
1288 /* See if player moving off should effect something */ 1278 /* See if player moving off should effect something */
1289 if (check_walk_off && ((op->move_type & tmp->move_off) && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0)) 1279 if (check_walk_off && ((op->move_type & tmp->move_off) && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0))
1290 { 1280 {
1291
1292 move_apply (tmp, op, NULL); 1281 move_apply (tmp, op, NULL);
1282
1293 if (was_destroyed (op, tag)) 1283 if (was_destroyed (op, tag))
1294 { 1284 {
1295 LOG (llevError, "BUG: remove_ob(): name %s, archname %s destroyed " "leaving object\n", &tmp->name, &tmp->arch->name); 1285 LOG (llevError, "BUG: remove_ob(): name %s, archname %s destroyed " "leaving object\n", &tmp->name, &tmp->arch->name);
1296 } 1286 }
1297 } 1287 }
1298 1288
1299 /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ 1289 /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */
1300 1290
1301 if (tmp->above == tmp) 1291 if (tmp->above == tmp)
1302 tmp->above = NULL; 1292 tmp->above = NULL;
1293
1303 last = tmp; 1294 last = tmp;
1304 } 1295 }
1296
1305 /* last == NULL of there are no objects on this space */ 1297 /* last == NULL of there are no objects on this space */
1306 if (last == NULL) 1298 if (last == NULL)
1307 { 1299 {
1308 /* set P_NEED_UPDATE, otherwise update_position will complain. In theory, 1300 /* set P_NEED_UPDATE, otherwise update_position will complain. In theory,
1309 * we could preserve the flags (GET_MAP_FLAGS), but update_position figures 1301 * we could preserve the flags (GET_MAP_FLAGS), but update_position figures
1316 else 1308 else
1317 update_object (last, UP_OBJ_REMOVE); 1309 update_object (last, UP_OBJ_REMOVE);
1318 1310
1319 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0)) 1311 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0))
1320 update_all_los (op->map, op->x, op->y); 1312 update_all_los (op->map, op->x, op->y);
1321
1322} 1313}
1323 1314
1324/* 1315/*
1325 * merge_ob(op,top): 1316 * merge_ob(op,top):
1326 * 1317 *
1438 1429
1439 if (op->more != NULL) 1430 if (op->more != NULL)
1440 { 1431 {
1441 /* The part may be on a different map. */ 1432 /* The part may be on a different map. */
1442 1433
1443 object *
1444 more = op->more; 1434 object *more = op->more;
1445 1435
1446 /* We really need the caller to normalize coordinates - if 1436 /* We really need the caller to normalize coordinates - if
1447 * we set the map, that doesn't work if the location is within 1437 * we set the map, that doesn't work if the location is within
1448 * a map and this is straddling an edge. So only if coordinate 1438 * a map and this is straddling an edge. So only if coordinate
1449 * is clear wrong do we normalize it. 1439 * is clear wrong do we normalize it.
1450 */ 1440 */
1451 if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) 1441 if (OUT_OF_REAL_MAP (more->map, more->x, more->y))
1452 {
1453 more->map = get_map_from_coord (m, &more->x, &more->y); 1442 more->map = get_map_from_coord (m, &more->x, &more->y);
1454 }
1455 else if (!more->map) 1443 else if (!more->map)
1456 { 1444 {
1457 /* For backwards compatibility - when not dealing with tiled maps, 1445 /* For backwards compatibility - when not dealing with tiled maps,
1458 * more->map should always point to the parent. 1446 * more->map should always point to the parent.
1459 */ 1447 */
1462 1450
1463 if (insert_ob_in_map (more, more->map, originator, flag) == NULL) 1451 if (insert_ob_in_map (more, more->map, originator, flag) == NULL)
1464 { 1452 {
1465 if (!op->head) 1453 if (!op->head)
1466 LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n"); 1454 LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n");
1455
1467 return NULL; 1456 return NULL;
1468 } 1457 }
1469 } 1458 }
1470 1459
1471 CLEAR_FLAG (op, FLAG_REMOVED); 1460 CLEAR_FLAG (op, FLAG_REMOVED);
1536 1525
1537 while (top != NULL) 1526 while (top != NULL)
1538 { 1527 {
1539 if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) 1528 if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR))
1540 floor = top; 1529 floor = top;
1530
1541 if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) 1531 if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR))
1542 { 1532 {
1543 /* We insert above top, so we want this object below this */ 1533 /* We insert above top, so we want this object below this */
1544 top = top->below; 1534 top = top->below;
1545 break; 1535 break;
1546 } 1536 }
1537
1547 last = top; 1538 last = top;
1548 top = top->above; 1539 top = top->above;
1549 } 1540 }
1541
1550 /* Don't want top to be NULL, so set it to the last valid object */ 1542 /* Don't want top to be NULL, so set it to the last valid object */
1551 top = last; 1543 top = last;
1552 1544
1553 /* We let update_position deal with figuring out what the space 1545 /* We let update_position deal with figuring out what the space
1554 * looks like instead of lots of conditions here. 1546 * looks like instead of lots of conditions here.
1633 * of effect may be sufficient. 1625 * of effect may be sufficient.
1634 */ 1626 */
1635 if (MAP_DARKNESS (op->map) && (op->glow_radius != 0)) 1627 if (MAP_DARKNESS (op->map) && (op->glow_radius != 0))
1636 update_all_los (op->map, op->x, op->y); 1628 update_all_los (op->map, op->x, op->y);
1637 1629
1638
1639 /* updates flags (blocked, alive, no magic, etc) for this map space */ 1630 /* updates flags (blocked, alive, no magic, etc) for this map space */
1640 update_object (op, UP_OBJ_INSERT); 1631 update_object (op, UP_OBJ_INSERT);
1641
1642 1632
1643 /* Don't know if moving this to the end will break anything. However, 1633 /* Don't know if moving this to the end will break anything. However,
1644 * we want to have update_look set above before calling this. 1634 * we want to have update_look set above before calling this.
1645 * 1635 *
1646 * check_move_on() must be after this because code called from 1636 * check_move_on() must be after this because code called from
1996 */ 1986 */
1997 1987
1998int 1988int
1999check_move_on (object *op, object *originator) 1989check_move_on (object *op, object *originator)
2000{ 1990{
2001 object * 1991 object *tmp;
2002 tmp; 1992 tag_t tag;
2003 tag_t 1993 mapstruct *m = op->map;
2004 tag;
2005 mapstruct *
2006 m = op->map;
2007 int
2008 x = op->x, y = op->y; 1994 int x = op->x, y = op->y;
2009 MoveType 1995
2010 move_on, 1996 MoveType move_on, move_slow, move_block;
2011 move_slow,
2012 move_block;
2013 1997
2014 if (QUERY_FLAG (op, FLAG_NO_APPLY)) 1998 if (QUERY_FLAG (op, FLAG_NO_APPLY))
2015 return 0; 1999 return 0;
2016 2000
2017 tag = op->count; 2001 tag = op->count;
2047 * we don't need to check all of them. 2031 * we don't need to check all of them.
2048 */ 2032 */
2049 if ((tmp->move_type & MOVE_FLY_LOW) && QUERY_FLAG (tmp, FLAG_NO_PICK)) 2033 if ((tmp->move_type & MOVE_FLY_LOW) && QUERY_FLAG (tmp, FLAG_NO_PICK))
2050 break; 2034 break;
2051 } 2035 }
2036
2052 for (; tmp != NULL; tmp = tmp->below) 2037 for (; tmp; tmp = tmp->below)
2053 { 2038 {
2054 if (tmp == op) 2039 if (tmp == op)
2055 continue; /* Can't apply yourself */ 2040 continue; /* Can't apply yourself */
2056 2041
2057 /* Check to see if one of the movement types should be slowed down. 2042 /* Check to see if one of the movement types should be slowed down.
2064 { 2049 {
2065 if ((!op->move_type && tmp->move_slow & MOVE_WALK) || 2050 if ((!op->move_type && tmp->move_slow & MOVE_WALK) ||
2066 ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0)) 2051 ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0))
2067 { 2052 {
2068 2053
2069 float
2070 diff;
2071
2072 diff = tmp->move_slow_penalty * FABS (op->speed); 2054 float diff = tmp->move_slow_penalty * FABS (op->speed);
2055
2073 if (op->type == PLAYER) 2056 if (op->type == PLAYER)
2074 {
2075 if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || 2057 if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) ||
2076 (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) 2058 (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN)))
2077 {
2078 diff /= 4.0; 2059 diff /= 4.0;
2079 } 2060
2080 }
2081 op->speed_left -= diff; 2061 op->speed_left -= diff;
2082 } 2062 }
2083 } 2063 }
2084 2064
2085 /* Basically same logic as above, except now for actual apply. */ 2065 /* Basically same logic as above, except now for actual apply. */
2086 if ((!op->move_type && tmp->move_on & MOVE_WALK) || 2066 if ((!op->move_type && tmp->move_on & MOVE_WALK) ||
2087 ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0)) 2067 ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0))
2088 { 2068 {
2089
2090 move_apply (tmp, op, originator); 2069 move_apply (tmp, op, originator);
2070
2091 if (was_destroyed (op, tag)) 2071 if (was_destroyed (op, tag))
2092 return 1; 2072 return 1;
2093 2073
2094 /* what the person/creature stepped onto has moved the object 2074 /* what the person/creature stepped onto has moved the object
2095 * someplace new. Don't process any further - if we did, 2075 * someplace new. Don't process any further - if we did,
2097 */ 2077 */
2098 if (op->map != m || op->x != x || op->y != y) 2078 if (op->map != m || op->x != x || op->y != y)
2099 return 0; 2079 return 0;
2100 } 2080 }
2101 } 2081 }
2082
2102 return 0; 2083 return 0;
2103} 2084}
2104 2085
2105/* 2086/*
2106 * present_arch(arch, map, x, y) searches for any objects with 2087 * present_arch(arch, map, x, y) searches for any objects with

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines