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.246 by root, Thu May 22 15:37:44 2008 UTC vs.
Revision 1.266 by root, Tue Dec 23 01:13:15 2008 UTC

186 || ob1->speed != ob2->speed 186 || ob1->speed != ob2->speed
187 || ob1->value != ob2->value 187 || ob1->value != ob2->value
188 || ob1->name != ob2->name) 188 || ob1->name != ob2->name)
189 return 0; 189 return 0;
190 190
191 /* Do not merge objects if nrof would overflow. First part checks 191 /* Do not merge objects if nrof would overflow, assume nrof
192 * for unsigned overflow (2c), second part checks whether the result 192 * is always 0 .. 2**31-1 */
193 * would fit into a 32 bit signed int, which is often used to hold 193 if (ob1->nrof > 0x7fffffff - ob2->nrof)
194 * nrof values.
195 */
196 if (~ob1->nrof < ob2->nrof || ob1->nrof + ob2->nrof > (1UL << 31))
197 return 0; 194 return 0;
198 195
199 /* If the objects have been identified, set the BEEN_APPLIED flag. 196 /* If the objects have been identified, set the BEEN_APPLIED flag.
200 * This is to the comparison of the flags below will be OK. We 197 * This is to the comparison of the flags below will be OK. We
201 * just can't ignore the been applied or identified flags, as they 198 * just can't ignore the been applied or identified flags, as they
235 || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats))) 232 || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats)))
236 return 0; 233 return 0;
237 234
238 if ((ob1->flag ^ ob2->flag) 235 if ((ob1->flag ^ ob2->flag)
239 .reset (FLAG_INV_LOCKED) 236 .reset (FLAG_INV_LOCKED)
240 .reset (FLAG_CLIENT_SENT)
241 .reset (FLAG_REMOVED) 237 .reset (FLAG_REMOVED)
242 .any ()) 238 .any ())
243 return 0; 239 return 0;
244 240
245 /* This is really a spellbook check - we should in general 241 /* This is really a spellbook check - we should in general
345 else 341 else
346 { 342 {
347 // maybe there is a player standing on the same mapspace 343 // maybe there is a player standing on the same mapspace
348 // this will catch the case where "this" is a player 344 // this will catch the case where "this" is a player
349 if (object *pl = ms ().player ()) 345 if (object *pl = ms ().player ())
346 if ((!pl->container && pl->contr->ns && !pl->contr->ns->update_look)
350 if (!pl->container || this == pl->container) 347 || this == pl->container)
351 return pl; 348 return pl;
352 } 349 }
353 } 350 }
354 351
355 return 0; 352 return 0;
639 } 636 }
640 637
641 if (speed < 0) 638 if (speed < 0)
642 dst->speed_left -= rndm (); 639 dst->speed_left -= rndm ();
643 640
644 dst->set_speed (dst->speed); 641 dst->activate ();
645} 642}
646 643
647void 644void
648object::instantiate () 645object::instantiate ()
649{ 646{
769 || (QUERY_FLAG (op, FLAG_DAMNED) && !(m.flags_ & P_NO_CLERIC)) 766 || (QUERY_FLAG (op, FLAG_DAMNED) && !(m.flags_ & P_NO_CLERIC))
770 || (m.move_on | op->move_on ) != m.move_on 767 || (m.move_on | op->move_on ) != m.move_on
771 || (m.move_off | op->move_off ) != m.move_off 768 || (m.move_off | op->move_off ) != m.move_off
772 || (m.move_slow | op->move_slow) != m.move_slow 769 || (m.move_slow | op->move_slow) != m.move_slow
773 /* This isn't perfect, but I don't expect a lot of objects to 770 /* This isn't perfect, but I don't expect a lot of objects to
774 * to have move_allow right now. 771 * have move_allow right now.
775 */ 772 */
776 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block 773 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block
777 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) 774 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp)
778 m.flags_ = 0; 775 m.invalidate ();
779 } 776 }
780 /* if the object is being removed, we can't make intelligent 777 /* if the object is being removed, we can't make intelligent
781 * decisions, because remove_ob can't really pass the object 778 * decisions, because remove_ob can't really pass the object
782 * that is being removed. 779 * that is being removed.
783 */ 780 */
784 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) 781 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE)
785 m.flags_ = 0; 782 m.invalidate ();
786 else if (action == UP_OBJ_FACE) 783 else if (action == UP_OBJ_FACE)
787 /* Nothing to do for that case */ ; 784 /* Nothing to do for that case */ ;
788 else 785 else
789 LOG (llevError, "update_object called with invalid action: %d\n", action); 786 LOG (llevError, "update_object called with invalid action: %d\n", action);
790 787
832object::activate () 829object::activate ()
833{ 830{
834 /* If already on active list, don't do anything */ 831 /* If already on active list, don't do anything */
835 if (active) 832 if (active)
836 return; 833 return;
834
835 if (has_active_speed () && flag [FLAG_FREED]) LOG (llevError | logBacktrace, "BUG: tried to activate freed object %s\n", debug_desc ());//D
836 if (has_active_speed () && flag [FLAG_DEBUG]) LOG (llevError | logBacktrace, "BUG: tried to activate DEBUG object %s\n", debug_desc ());//D temp
837 837
838 if (has_active_speed ()) 838 if (has_active_speed ())
839 actives.insert (this); 839 actives.insert (this);
840} 840}
841 841
909 || map->in_memory != MAP_ACTIVE 909 || map->in_memory != MAP_ACTIVE
910 || map->no_drop 910 || map->no_drop
911 || ms ().move_block == MOVE_ALL) 911 || ms ().move_block == MOVE_ALL)
912 { 912 {
913 while (inv) 913 while (inv)
914 {
915 inv->destroy_inv (false);
916 inv->destroy (); 914 inv->destroy ();
917 }
918 } 915 }
919 else 916 else
920 { /* Put objects in inventory onto this space */ 917 { /* Put objects in inventory onto this space */
921 while (inv) 918 while (inv)
922 { 919 {
926 || op->flag [FLAG_NO_DROP] 923 || op->flag [FLAG_NO_DROP]
927 || op->type == RUNE 924 || op->type == RUNE
928 || op->type == TRAP 925 || op->type == TRAP
929 || op->flag [FLAG_IS_A_TEMPLATE] 926 || op->flag [FLAG_IS_A_TEMPLATE]
930 || op->flag [FLAG_DESTROY_ON_DEATH]) 927 || op->flag [FLAG_DESTROY_ON_DEATH])
931 op->destroy (true); 928 op->destroy ();
932 else 929 else
933 map->insert (op, x, y); 930 map->insert (op, x, y);
934 } 931 }
935 } 932 }
936} 933}
1000 attacked_by = 0; 997 attacked_by = 0;
1001 current_weapon = 0; 998 current_weapon = 0;
1002} 999}
1003 1000
1004void 1001void
1005object::destroy (bool destroy_inventory) 1002object::destroy ()
1006{ 1003{
1007 if (destroyed ()) 1004 if (destroyed ())
1008 return; 1005 return;
1009 1006
1010 if (!is_head () && !head->destroyed ()) 1007 if (!is_head () && !head->destroyed ())
1011 { 1008 {
1012 LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); 1009 LOG (llevError | logBacktrace, "tried to destroy the tail of an object");
1013 head->destroy (destroy_inventory); 1010 head->destroy ();
1014 return; 1011 return;
1015 } 1012 }
1016 1013
1017 destroy_inv (!destroy_inventory); 1014 destroy_inv (false);
1018 1015
1019 if (is_head ()) 1016 if (is_head ())
1020 if (sound_destroy) 1017 if (sound_destroy)
1021 play_sound (sound_destroy); 1018 play_sound (sound_destroy);
1022 else if (flag [FLAG_MONSTER]) 1019 else if (flag [FLAG_MONSTER])
1058 if (object *pl = visible_to ()) 1055 if (object *pl = visible_to ())
1059 esrv_del_item (pl->contr, count); 1056 esrv_del_item (pl->contr, count);
1060 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed 1057 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed
1061 1058
1062 adjust_weight (env, -total_weight ()); 1059 adjust_weight (env, -total_weight ());
1060
1061 object *pl = in_player ();
1063 1062
1064 /* we set up values so that it could be inserted into 1063 /* we set up values so that it could be inserted into
1065 * the map, but we don't actually do that - it is up 1064 * the map, but we don't actually do that - it is up
1066 * to the caller to decide what we want to do. 1065 * to the caller to decide what we want to do.
1067 */ 1066 */
1079 1078
1080 /* NO_FIX_PLAYER is set when a great many changes are being 1079 /* NO_FIX_PLAYER is set when a great many changes are being
1081 * made to players inventory. If set, avoiding the call 1080 * made to players inventory. If set, avoiding the call
1082 * to save cpu time. 1081 * to save cpu time.
1083 */ 1082 */
1083 if (pl)
1084 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1084 if (pl->contr && !QUERY_FLAG (pl, FLAG_NO_FIX_PLAYER))
1085 {
1085 otmp->update_stats (); 1086 pl->update_stats ();
1087
1088 if (affects_los () && pl->is_on_map () && pl->map->darkness)
1089 update_all_los (pl->map, pl->x, pl->y);
1090 }
1086 } 1091 }
1087 else if (map) 1092 else if (map)
1088 { 1093 {
1089 map->dirty = true; 1094 map->dirty = true;
1090 mapspace &ms = this->ms (); 1095 mapspace &ms = this->ms ();
1117 *(below ? &below->above : &ms.bot) = above; 1122 *(below ? &below->above : &ms.bot) = above;
1118 1123
1119 above = 0; 1124 above = 0;
1120 below = 0; 1125 below = 0;
1121 1126
1127 ms.invalidate ();
1128
1122 if (map->in_memory == MAP_SAVING) 1129 if (map->in_memory == MAP_SAVING)
1123 return; 1130 return;
1124 1131
1125 int check_walk_off = !flag [FLAG_NO_APPLY]; 1132 int check_walk_off = !flag [FLAG_NO_APPLY];
1126 1133
1158 } 1165 }
1159 1166
1160 last = tmp; 1167 last = tmp;
1161 } 1168 }
1162 1169
1163 /* last == NULL if there are no objects on this space */ 1170 if (map->darkness && affects_los ())
1164 //TODO: this makes little sense, why only update the topmost object?
1165 if (!last)
1166 map->at (x, y).flags_ = 0;
1167 else
1168 update_object (last, UP_OBJ_REMOVE);
1169
1170 if (flag [FLAG_BLOCKSVIEW] || glow_radius)
1171 update_all_los (map, x, y); 1171 update_all_los (map, x, y);
1172 } 1172 }
1173} 1173}
1174 1174
1175/* 1175/*
1199 esrv_update_item (UPD_NROF, pl, top); 1199 esrv_update_item (UPD_NROF, pl, top);
1200 1200
1201 op->weight = 0; // cancel the addition above 1201 op->weight = 0; // cancel the addition above
1202 op->carrying = 0; // must be 0 already 1202 op->carrying = 0; // must be 0 already
1203 1203
1204 op->destroy (1); 1204 op->destroy ();
1205 1205
1206 return top; 1206 return top;
1207 } 1207 }
1208 1208
1209 return 0; 1209 return 0;
1271 * just 'op' otherwise 1271 * just 'op' otherwise
1272 */ 1272 */
1273object * 1273object *
1274insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1274insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1275{ 1275{
1276 if (op->is_on_map ())
1277 {
1278 LOG (llevError, "insert_ob_in_map called for object already on map");
1279 abort ();
1280 }
1281
1282 if (op->env)
1283 {
1284 LOG (llevError, "insert_ob_in_map called for object in an inventory (proceeding)");
1285 op->remove (); 1276 op->remove ();
1286 }
1287 1277
1288 if (op->face && !face_info (op->face))//D TODO: remove soon 1278 if (m == &freed_map)//D TODO: remove soon
1289 {//D 1279 {//D
1290 LOG (llevError | logBacktrace, "op->face out of bounds: %s", op->debug_desc ());//D 1280 LOG (llevError | logBacktrace, "tries to insret object on freed objects map: %s", op->debug_desc ());//D
1291 op->face = 1;//D
1292 }//D 1281 }//D
1293 1282
1294 /* Ideally, the caller figures this out. However, it complicates a lot 1283 /* Ideally, the caller figures this out. However, it complicates a lot
1295 * of areas of callers (eg, anything that uses find_free_spot would now 1284 * of areas of callers (eg, anything that uses find_free_spot would now
1296 * need extra work 1285 * need extra work
1297 */ 1286 */
1298 if (!xy_normalise (m, op->x, op->y)) 1287 if (!xy_normalise (m, op->x, op->y))
1299 { 1288 {
1300 op->head_ ()->destroy (1);// remove head_ once all tail object destroyers found 1289 op->head_ ()->destroy ();// remove head_ once all tail object destroyers found
1301 return 0; 1290 return 0;
1302 } 1291 }
1303 1292
1304 if (object *more = op->more) 1293 if (object *more = op->more)
1305 if (!insert_ob_in_map (more, m, originator, flag)) 1294 if (!insert_ob_in_map (more, m, originator, flag))
1318 { 1307 {
1319 // TODO: we actually want to update tmp, not op, 1308 // TODO: we actually want to update tmp, not op,
1320 // but some caller surely breaks when we return tmp 1309 // but some caller surely breaks when we return tmp
1321 // from here :/ 1310 // from here :/
1322 op->nrof += tmp->nrof; 1311 op->nrof += tmp->nrof;
1323 tmp->destroy (1); 1312 tmp->destroy ();
1324 } 1313 }
1325 1314
1326 CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ 1315 CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */
1327 CLEAR_FLAG (op, FLAG_INV_LOCKED); 1316 CLEAR_FLAG (op, FLAG_INV_LOCKED);
1328 1317
1458 * be far away from this change and not affected in any way - 1447 * be far away from this change and not affected in any way -
1459 * this should get redone to only look for players within range, 1448 * this should get redone to only look for players within range,
1460 * or just updating the P_UPTODATE for spaces within this area 1449 * or just updating the P_UPTODATE for spaces within this area
1461 * of effect may be sufficient. 1450 * of effect may be sufficient.
1462 */ 1451 */
1463 if (op->map->darkness && (op->glow_radius != 0)) 1452 if (op->affects_los () && op->map->darkness)
1453 {
1454 op->ms ().invalidate ();
1464 update_all_los (op->map, op->x, op->y); 1455 update_all_los (op->map, op->x, op->y);
1456 }
1465 1457
1466 /* updates flags (blocked, alive, no magic, etc) for this map space */ 1458 /* updates flags (blocked, alive, no magic, etc) for this map space */
1467 update_object (op, UP_OBJ_INSERT); 1459 update_object (op, UP_OBJ_INSERT);
1468 1460
1469 INVOKE_OBJECT (INSERT, op); 1461 INVOKE_OBJECT (INSERT, op);
1503{ 1495{
1504 /* first search for itself and remove any old instances */ 1496 /* first search for itself and remove any old instances */
1505 1497
1506 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) 1498 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above)
1507 if (!strcmp (tmp->arch->archname, arch_string)) /* same archetype */ 1499 if (!strcmp (tmp->arch->archname, arch_string)) /* same archetype */
1508 tmp->destroy (1); 1500 tmp->destroy ();
1509 1501
1510 object *tmp = arch_to_object (archetype::find (arch_string)); 1502 object *tmp = arch_to_object (archetype::find (arch_string));
1511 1503
1512 tmp->x = op->x; 1504 tmp->x = op->x;
1513 tmp->y = op->y; 1505 tmp->y = op->y;
1537 if (!nr) 1529 if (!nr)
1538 return true; 1530 return true;
1539 1531
1540 nr = min (nr, nrof); 1532 nr = min (nr, nrof);
1541 1533
1534 if (nrof > nr)
1535 {
1542 nrof -= nr; 1536 nrof -= nr;
1543
1544 if (nrof)
1545 {
1546 adjust_weight (env, -weight * nr); // carrying == 0 1537 adjust_weight (env, -weight * max (1, nr)); // carrying == 0
1547 1538
1548 if (object *pl = visible_to ()) 1539 if (object *pl = visible_to ())
1549 esrv_update_item (UPD_NROF, pl, this); 1540 esrv_update_item (UPD_NROF, pl, this);
1550 1541
1551 return true; 1542 return true;
1552 } 1543 }
1553 else 1544 else
1554 { 1545 {
1555 destroy (1); 1546 destroy ();
1556 return false; 1547 return false;
1557 } 1548 }
1558} 1549}
1559 1550
1560/* 1551/*
1637 if (object *pl = tmp->visible_to ()) 1628 if (object *pl = tmp->visible_to ())
1638 esrv_update_item (UPD_NROF, pl, tmp); 1629 esrv_update_item (UPD_NROF, pl, tmp);
1639 1630
1640 adjust_weight (this, op->total_weight ()); 1631 adjust_weight (this, op->total_weight ());
1641 1632
1642 op->destroy (1); 1633 op->destroy ();
1643 op = tmp; 1634 op = tmp;
1644 goto inserted; 1635 goto inserted;
1645 } 1636 }
1646 1637
1647 op->owner = 0; // it's his/hers now. period. 1638 op->owner = 0; // it's his/hers now. period.
1665 1656
1666 adjust_weight (this, op->total_weight ()); 1657 adjust_weight (this, op->total_weight ());
1667 1658
1668inserted: 1659inserted:
1669 /* reset the light list and los of the players on the map */ 1660 /* reset the light list and los of the players on the map */
1670 if (op->glow_radius && map && map->darkness) 1661 if (op->glow_radius && is_on_map () && map->darkness)
1662 {
1663 update_stats ();
1671 update_all_los (map, x, y); 1664 update_all_los (map, x, y);
1672 1665 }
1666 else if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER])
1673 // if this is a player's inventory, update stats 1667 // if this is a player's inventory, update stats
1674 if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER])
1675 update_stats (); 1668 update_stats ();
1676 1669
1677 INVOKE_OBJECT (INSERT, this); 1670 INVOKE_OBJECT (INSERT, this);
1678 1671
1679 return op; 1672 return op;
1981 * head of the object should correspond for the entire object. 1974 * head of the object should correspond for the entire object.
1982 */ 1975 */
1983 if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block)) 1976 if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block))
1984 continue; 1977 continue;
1985 1978
1986 if (ob->blocked (m, pos.x, pos.y)) 1979 if (ob->blocked (pos.m, pos.x, pos.y))
1987 continue; 1980 continue;
1988 1981
1989 altern [index++] = i; 1982 altern [index++] = i;
1990 } 1983 }
1991 1984
2558 return splay (tmp); 2551 return splay (tmp);
2559 2552
2560 return 0; 2553 return 0;
2561} 2554}
2562 2555
2563void 2556object *
2564object::force_add (const shstr name, int duration) 2557object::force_add (const shstr name, int duration)
2565{ 2558{
2566 if (object *force = force_find (name)) 2559 if (object *force = force_find (name))
2567 force->destroy (); 2560 force->destroy ();
2568 2561
2574 2567
2575 force->set_speed (duration ? 1.f / duration : 0.f); 2568 force->set_speed (duration ? 1.f / duration : 0.f);
2576 force->flag [FLAG_IS_USED_UP] = true; 2569 force->flag [FLAG_IS_USED_UP] = true;
2577 force->flag [FLAG_APPLIED] = true; 2570 force->flag [FLAG_APPLIED] = true;
2578 2571
2579 insert (force); 2572 return insert (force);
2580} 2573}
2581 2574
2582void 2575void
2583object::play_sound (faceidx sound) 2576object::play_sound (faceidx sound)
2584{ 2577{
2595 } 2588 }
2596 else 2589 else
2597 map->play_sound (sound, x, y); 2590 map->play_sound (sound, x, y);
2598} 2591}
2599 2592
2593void
2594object::make_noise ()
2595{
2596 // we do not model noise in the map, so instead put
2597 // a temporary light into the noise source
2598 // could use the map instead, but that's less reliable for our
2599 // goal, which is to make invisibility a bit harder to exploit
2600
2601 // currently only works sensibly for players
2602 if (!is_player ())
2603 return;
2604
2605 // find old force, or create new one
2606 object *force = force_find (shstr_noise_force);
2607
2608 if (force)
2609 force->speed = 1.f / 4; // patch old speed up
2610 else
2611 force_add (shstr_noise_force, 4);
2612}
2613

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines