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.64 by root, Tue Dec 12 21:39:56 2006 UTC vs.
Revision 1.73 by root, Wed Dec 20 01:19:11 2006 UTC

29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/uio.h> 30#include <sys/uio.h>
31#include <object.h> 31#include <object.h>
32#include <funcpoint.h> 32#include <funcpoint.h>
33#include <loader.h> 33#include <loader.h>
34
35#include <bitset>
34 36
35int nrofallocobjects = 0; 37int nrofallocobjects = 0;
36static UUID uuid; 38static UUID uuid;
37const uint64 UUID_SKIP = 1<<19; 39const uint64 UUID_SKIP = 1<<19;
38 40
183 * 185 *
184 * Note that this function appears a lot longer than the macro it 186 * Note that this function appears a lot longer than the macro it
185 * replaces - this is mostly for clarity - a decent compiler should hopefully 187 * replaces - this is mostly for clarity - a decent compiler should hopefully
186 * reduce this to the same efficiency. 188 * reduce this to the same efficiency.
187 * 189 *
188 * Check nrof variable *before* calling CAN_MERGE() 190 * Check nrof variable *before* calling can_merge()
189 * 191 *
190 * Improvements made with merge: Better checking on potion, and also 192 * Improvements made with merge: Better checking on potion, and also
191 * check weight 193 * check weight
192 */ 194 */
193 195
194bool object::can_merge (object *ob1, object *ob2) 196bool object::can_merge_slow (object *ob1, object *ob2)
195{ 197{
196 /* A couple quicksanity checks */ 198 /* A couple quicksanity checks */
197 if ((ob1 == ob2) || (ob1->type != ob2->type)) 199 if (ob1 == ob2
200 || ob1->type != ob2->type
201 || ob1->speed != ob2->speed
202 || ob1->value != ob2->value
203 || ob1->name != ob2->name)
198 return 0; 204 return 0;
199 205
200 if (ob1->speed != ob2->speed) 206 //TODO: this ain't working well, use nicer and correct overflow check
201 return 0;
202
203 /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that 207 /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that
204 * value could not be stored in a sint32 (which unfortunately sometimes is 208 * value could not be stored in a sint32 (which unfortunately sometimes is
205 * used to store nrof). 209 * used to store nrof).
206 */ 210 */
207 if (ob1->nrof + ob2->nrof >= 1UL << 31) 211 if (ob1->nrof + ob2->nrof >= 1UL << 31)
217 SET_FLAG (ob1, FLAG_BEEN_APPLIED); 221 SET_FLAG (ob1, FLAG_BEEN_APPLIED);
218 222
219 if (QUERY_FLAG (ob2, FLAG_IDENTIFIED)) 223 if (QUERY_FLAG (ob2, FLAG_IDENTIFIED))
220 SET_FLAG (ob2, FLAG_BEEN_APPLIED); 224 SET_FLAG (ob2, FLAG_BEEN_APPLIED);
221 225
222 226 if ((ob1->flags ^ ob2->flags).reset (FLAG_INV_LOCKED).reset (FLAG_CLIENT_SENT).any ()
223 /* the 0x400000 on flags2 is FLAG_INV_LOCK. I don't think something 227 || ob1->arch != ob2->arch
224 * being locked in inventory should prevent merging.
225 * 0x4 in flags3 is CLIENT_SENT
226 */
227 if ((ob1->arch != ob2->arch) ||
228 (ob1->flags[0] != ob2->flags[0]) ||
229 (ob1->flags[1] != ob2->flags[1]) ||
230 ((ob1->flags[2] & ~0x400000) != (ob2->flags[2] & ~0x400000)) ||
231 ((ob1->flags[3] & ~0x4) != (ob2->flags[3] & ~0x4)) ||
232 (ob1->name != ob2->name) || 228 || ob1->name != ob2->name
233 (ob1->title != ob2->title) || 229 || ob1->title != ob2->title
234 (ob1->msg != ob2->msg) || 230 || ob1->msg != ob2->msg
235 (ob1->weight != ob2->weight) || 231 || ob1->weight != ob2->weight
236 (memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) != 0) || 232 || memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist))
237 (memcmp (&ob1->stats, &ob2->stats, sizeof (ob1->stats)) != 0) || 233 || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats) )
238 (ob1->attacktype != ob2->attacktype) || 234 || ob1->attacktype != ob2->attacktype
239 (ob1->magic != ob2->magic) || 235 || ob1->magic != ob2->magic
240 (ob1->slaying != ob2->slaying) || 236 || ob1->slaying != ob2->slaying
241 (ob1->skill != ob2->skill) || 237 || ob1->skill != ob2->skill
242 (ob1->value != ob2->value) || 238 || ob1->value != ob2->value
243 (ob1->animation_id != ob2->animation_id) || 239 || ob1->animation_id != ob2->animation_id
244 (ob1->client_type != ob2->client_type) || 240 || ob1->client_type != ob2->client_type
245 (ob1->materialname != ob2->materialname) || 241 || ob1->materialname != ob2->materialname
246 (ob1->lore != ob2->lore) || 242 || ob1->lore != ob2->lore
247 (ob1->subtype != ob2->subtype) || 243 || ob1->subtype != ob2->subtype
248 (ob1->move_type != ob2->move_type) || 244 || ob1->move_type != ob2->move_type
249 (ob1->move_block != ob2->move_block) || 245 || ob1->move_block != ob2->move_block
250 (ob1->move_allow != ob2->move_allow) || 246 || ob1->move_allow != ob2->move_allow
251 (ob1->move_on != ob2->move_on) || 247 || ob1->move_on != ob2->move_on
252 (ob1->move_off != ob2->move_off) || (ob1->move_slow != ob2->move_slow) || (ob1->move_slow_penalty != ob2->move_slow_penalty)) 248 || ob1->move_off != ob2->move_off
249 || ob1->move_slow != ob2->move_slow
250 || ob1->move_slow_penalty != ob2->move_slow_penalty)
253 return 0; 251 return 0;
254 252
255 /* This is really a spellbook check - really, we should 253 /* This is really a spellbook check - really, we should
256 * check all objects in the inventory. 254 * check all objects in the inventory.
257 */ 255 */
260 /* if one object has inventory but the other doesn't, not equiv */ 258 /* if one object has inventory but the other doesn't, not equiv */
261 if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv)) 259 if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv))
262 return 0; 260 return 0;
263 261
264 /* Now check to see if the two inventory objects could merge */ 262 /* Now check to see if the two inventory objects could merge */
265 if (!CAN_MERGE (ob1->inv, ob2->inv)) 263 if (!object::can_merge (ob1->inv, ob2->inv))
266 return 0; 264 return 0;
267 265
268 /* inventory ok - still need to check rest of this object to see 266 /* inventory ok - still need to check rest of this object to see
269 * if it is valid. 267 * if it is valid.
270 */ 268 */
588 } 586 }
589 587
590 update_ob_speed (dst); 588 update_ob_speed (dst);
591} 589}
592 590
591object *
592object::clone ()
593{
594 object *neu = create ();
595 copy_to (neu);
596 return neu;
597}
598
593/* 599/*
594 * If an object with the IS_TURNABLE() flag needs to be turned due 600 * If an object with the IS_TURNABLE() flag needs to be turned due
595 * to the closest player being on the other side, this function can 601 * to the closest player being on the other side, this function can
596 * be called to update the face variable, _and_ how it looks on the map. 602 * be called to update the face variable, _and_ how it looks on the map.
597 */ 603 */
1130 { 1136 {
1131 CLEAR_FLAG (this, FLAG_APPLIED); 1137 CLEAR_FLAG (this, FLAG_APPLIED);
1132 tmp->container = 0; 1138 tmp->container = 0;
1133 } 1139 }
1134 1140
1135 tmp->contr->socket.update_look = 1; 1141 tmp->contr->socket->floorbox_update ();
1136 } 1142 }
1137 1143
1138 /* See if player moving off should effect something */ 1144 /* See if player moving off should effect something */
1139 if (check_walk_off 1145 if (check_walk_off
1140 && ((move_type & tmp->move_off) 1146 && ((move_type & tmp->move_off)
1192 1198
1193 for (; top != NULL; top = top->below) 1199 for (; top != NULL; top = top->below)
1194 { 1200 {
1195 if (top == op) 1201 if (top == op)
1196 continue; 1202 continue;
1197 if (CAN_MERGE (op, top)) 1203
1204 if (object::can_merge (op, top))
1198 { 1205 {
1199 top->nrof += op->nrof; 1206 top->nrof += op->nrof;
1200 1207
1201/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ 1208/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/
1202 op->weight = 0; /* Don't want any adjustements now */ 1209 op->weight = 0; /* Don't want any adjustements now */
1335 1342
1336 /* this has to be done after we translate the coordinates. 1343 /* this has to be done after we translate the coordinates.
1337 */ 1344 */
1338 if (op->nrof && !(flag & INS_NO_MERGE)) 1345 if (op->nrof && !(flag & INS_NO_MERGE))
1339 for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) 1346 for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above)
1340 if (CAN_MERGE (op, tmp)) 1347 if (object::can_merge (op, tmp))
1341 { 1348 {
1342 op->nrof += tmp->nrof; 1349 op->nrof += tmp->nrof;
1343 tmp->destroy (); 1350 tmp->destroy ();
1344 } 1351 }
1345 1352
1476 * it, so save a few ticks and start from there. 1483 * it, so save a few ticks and start from there.
1477 */ 1484 */
1478 if (!(flag & INS_MAP_LOAD)) 1485 if (!(flag & INS_MAP_LOAD))
1479 for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 1486 for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
1480 if (tmp->type == PLAYER) 1487 if (tmp->type == PLAYER)
1481 tmp->contr->socket.update_look = 1; 1488 tmp->contr->socket->floorbox_update ();
1482 1489
1483 /* If this object glows, it may affect lighting conditions that are 1490 /* If this object glows, it may affect lighting conditions that are
1484 * visible to others on this map. But update_all_los is really 1491 * visible to others on this map. But update_all_los is really
1485 * an inefficient way to do this, as it means los for all players 1492 * an inefficient way to do this, as it means los for all players
1486 * on the map will get recalculated. The players could very well 1493 * on the map will get recalculated. The players could very well
1494 1501
1495 /* updates flags (blocked, alive, no magic, etc) for this map space */ 1502 /* updates flags (blocked, alive, no magic, etc) for this map space */
1496 update_object (op, UP_OBJ_INSERT); 1503 update_object (op, UP_OBJ_INSERT);
1497 1504
1498 /* Don't know if moving this to the end will break anything. However, 1505 /* Don't know if moving this to the end will break anything. However,
1499 * we want to have update_look set above before calling this. 1506 * we want to have floorbox_update called before calling this.
1500 * 1507 *
1501 * check_move_on() must be after this because code called from 1508 * check_move_on() must be after this because code called from
1502 * check_move_on() depends on correct map flags (so functions like 1509 * check_move_on() depends on correct map flags (so functions like
1503 * blocked() and wall() work properly), and these flags are updated by 1510 * blocked() and wall() work properly), and these flags are updated by
1504 * update_object(). 1511 * update_object().
1607 if (i > op->nrof) 1614 if (i > op->nrof)
1608 i = op->nrof; 1615 i = op->nrof;
1609 1616
1610 if (QUERY_FLAG (op, FLAG_REMOVED)) 1617 if (QUERY_FLAG (op, FLAG_REMOVED))
1611 op->nrof -= i; 1618 op->nrof -= i;
1612 else if (op->env != NULL) 1619 else if (op->env)
1613 { 1620 {
1614 /* is this object in the players inventory, or sub container 1621 /* is this object in the players inventory, or sub container
1615 * therein? 1622 * therein?
1616 */ 1623 */
1617 tmp = is_player_inv (op->env); 1624 tmp = is_player_inv (op->env);
1623 */ 1630 */
1624 if (!tmp) 1631 if (!tmp)
1625 { 1632 {
1626 for (pl = first_player; pl; pl = pl->next) 1633 for (pl = first_player; pl; pl = pl->next)
1627 if (pl->ob->container == op->env) 1634 if (pl->ob->container == op->env)
1635 {
1636 tmp = pl->ob;
1628 break; 1637 break;
1629 if (pl) 1638 }
1630 tmp = pl->ob;
1631 else
1632 tmp = NULL;
1633 } 1639 }
1634 1640
1635 if (i < op->nrof) 1641 if (i < op->nrof)
1636 { 1642 {
1637 sub_weight (op->env, op->weight * i); 1643 sub_weight (op->env, op->weight * i);
1638 op->nrof -= i; 1644 op->nrof -= i;
1639 if (tmp) 1645 if (tmp)
1640 {
1641 esrv_send_item (tmp, op); 1646 esrv_send_item (tmp, op);
1642 }
1643 } 1647 }
1644 else 1648 else
1645 { 1649 {
1646 op->remove (); 1650 op->remove ();
1647 op->nrof = 0; 1651 op->nrof = 0;
1648 if (tmp) 1652 if (tmp)
1649 {
1650 esrv_del_item (tmp->contr, op->count); 1653 esrv_del_item (tmp->contr, op->count);
1651 }
1652 } 1654 }
1653 } 1655 }
1654 else 1656 else
1655 { 1657 {
1656 object *above = op->above; 1658 object *above = op->above;
1662 op->remove (); 1664 op->remove ();
1663 op->nrof = 0; 1665 op->nrof = 0;
1664 } 1666 }
1665 1667
1666 /* Since we just removed op, op->above is null */ 1668 /* Since we just removed op, op->above is null */
1667 for (tmp = above; tmp != NULL; tmp = tmp->above) 1669 for (tmp = above; tmp; tmp = tmp->above)
1668 if (tmp->type == PLAYER) 1670 if (tmp->type == PLAYER)
1669 { 1671 {
1670 if (op->nrof) 1672 if (op->nrof)
1671 esrv_send_item (tmp, op); 1673 esrv_send_item (tmp, op);
1672 else 1674 else
1677 if (op->nrof) 1679 if (op->nrof)
1678 return op; 1680 return op;
1679 else 1681 else
1680 { 1682 {
1681 op->destroy (); 1683 op->destroy ();
1682 return NULL; 1684 return 0;
1683 } 1685 }
1684} 1686}
1685 1687
1686/* 1688/*
1687 * add_weight(object, weight) adds the specified weight to an object, 1689 * add_weight(object, weight) adds the specified weight to an object,
1747 CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); 1749 CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL);
1748 CLEAR_FLAG (op, FLAG_REMOVED); 1750 CLEAR_FLAG (op, FLAG_REMOVED);
1749 if (op->nrof) 1751 if (op->nrof)
1750 { 1752 {
1751 for (tmp = inv; tmp != NULL; tmp = tmp->below) 1753 for (tmp = inv; tmp != NULL; tmp = tmp->below)
1752 if (CAN_MERGE (tmp, op)) 1754 if (object::can_merge (tmp, op))
1753 { 1755 {
1754 /* return the original object and remove inserted object 1756 /* return the original object and remove inserted object
1755 (client needs the original object) */ 1757 (client needs the original object) */
1756 tmp->nrof += op->nrof; 1758 tmp->nrof += op->nrof;
1757 /* Weight handling gets pretty funky. Since we are adding to 1759 /* Weight handling gets pretty funky. Since we are adding to
2518 src = src->head; 2520 src = src->head;
2519 2521
2520 prev = 0; 2522 prev = 0;
2521 for (part = src; part; part = part->more) 2523 for (part = src; part; part = part->more)
2522 { 2524 {
2523 tmp = object::create (); 2525 tmp = part->clone ();
2524 part->copy_to (tmp);
2525 tmp->x -= src->x; 2526 tmp->x -= src->x;
2526 tmp->y -= src->y; 2527 tmp->y -= src->y;
2527 2528
2528 if (!part->head) 2529 if (!part->head)
2529 { 2530 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines