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.67 by root, Thu Dec 14 04:30:32 2006 UTC

183 * 183 *
184 * Note that this function appears a lot longer than the macro it 184 * Note that this function appears a lot longer than the macro it
185 * replaces - this is mostly for clarity - a decent compiler should hopefully 185 * replaces - this is mostly for clarity - a decent compiler should hopefully
186 * reduce this to the same efficiency. 186 * reduce this to the same efficiency.
187 * 187 *
188 * Check nrof variable *before* calling CAN_MERGE() 188 * Check nrof variable *before* calling can_merge()
189 * 189 *
190 * Improvements made with merge: Better checking on potion, and also 190 * Improvements made with merge: Better checking on potion, and also
191 * check weight 191 * check weight
192 */ 192 */
193 193
194bool object::can_merge (object *ob1, object *ob2) 194bool object::can_merge_slow (object *ob1, object *ob2)
195{ 195{
196 /* A couple quicksanity checks */ 196 /* A couple quicksanity checks */
197 if ((ob1 == ob2) || (ob1->type != ob2->type)) 197 if (ob1 == ob2
198 || ob1->type != ob2->type
199 || ob1->speed != ob2->speed
200 || ob1->value != ob2->value
201 || ob1->name != ob2->name)
198 return 0; 202 return 0;
199 203
200 if (ob1->speed != ob2->speed) 204 //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 205 /* 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 206 * value could not be stored in a sint32 (which unfortunately sometimes is
205 * used to store nrof). 207 * used to store nrof).
206 */ 208 */
207 if (ob1->nrof + ob2->nrof >= 1UL << 31) 209 if (ob1->nrof + ob2->nrof >= 1UL << 31)
260 /* if one object has inventory but the other doesn't, not equiv */ 262 /* if one object has inventory but the other doesn't, not equiv */
261 if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv)) 263 if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv))
262 return 0; 264 return 0;
263 265
264 /* Now check to see if the two inventory objects could merge */ 266 /* Now check to see if the two inventory objects could merge */
265 if (!CAN_MERGE (ob1->inv, ob2->inv)) 267 if (!object::can_merge (ob1->inv, ob2->inv))
266 return 0; 268 return 0;
267 269
268 /* inventory ok - still need to check rest of this object to see 270 /* inventory ok - still need to check rest of this object to see
269 * if it is valid. 271 * if it is valid.
270 */ 272 */
588 } 590 }
589 591
590 update_ob_speed (dst); 592 update_ob_speed (dst);
591} 593}
592 594
595object *
596object::clone ()
597{
598 object *neu = create ();
599 copy_to (neu);
600 return neu;
601}
602
593/* 603/*
594 * If an object with the IS_TURNABLE() flag needs to be turned due 604 * 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 605 * 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. 606 * be called to update the face variable, _and_ how it looks on the map.
597 */ 607 */
1130 { 1140 {
1131 CLEAR_FLAG (this, FLAG_APPLIED); 1141 CLEAR_FLAG (this, FLAG_APPLIED);
1132 tmp->container = 0; 1142 tmp->container = 0;
1133 } 1143 }
1134 1144
1135 tmp->contr->socket.update_look = 1; 1145 tmp->contr->socket->update_look = 1;
1136 } 1146 }
1137 1147
1138 /* See if player moving off should effect something */ 1148 /* See if player moving off should effect something */
1139 if (check_walk_off 1149 if (check_walk_off
1140 && ((move_type & tmp->move_off) 1150 && ((move_type & tmp->move_off)
1192 1202
1193 for (; top != NULL; top = top->below) 1203 for (; top != NULL; top = top->below)
1194 { 1204 {
1195 if (top == op) 1205 if (top == op)
1196 continue; 1206 continue;
1197 if (CAN_MERGE (op, top)) 1207
1208 if (object::can_merge (op, top))
1198 { 1209 {
1199 top->nrof += op->nrof; 1210 top->nrof += op->nrof;
1200 1211
1201/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ 1212/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/
1202 op->weight = 0; /* Don't want any adjustements now */ 1213 op->weight = 0; /* Don't want any adjustements now */
1335 1346
1336 /* this has to be done after we translate the coordinates. 1347 /* this has to be done after we translate the coordinates.
1337 */ 1348 */
1338 if (op->nrof && !(flag & INS_NO_MERGE)) 1349 if (op->nrof && !(flag & INS_NO_MERGE))
1339 for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) 1350 for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above)
1340 if (CAN_MERGE (op, tmp)) 1351 if (object::can_merge (op, tmp))
1341 { 1352 {
1342 op->nrof += tmp->nrof; 1353 op->nrof += tmp->nrof;
1343 tmp->destroy (); 1354 tmp->destroy ();
1344 } 1355 }
1345 1356
1476 * it, so save a few ticks and start from there. 1487 * it, so save a few ticks and start from there.
1477 */ 1488 */
1478 if (!(flag & INS_MAP_LOAD)) 1489 if (!(flag & INS_MAP_LOAD))
1479 for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 1490 for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
1480 if (tmp->type == PLAYER) 1491 if (tmp->type == PLAYER)
1481 tmp->contr->socket.update_look = 1; 1492 tmp->contr->socket->update_look = 1;
1482 1493
1483 /* If this object glows, it may affect lighting conditions that are 1494 /* If this object glows, it may affect lighting conditions that are
1484 * visible to others on this map. But update_all_los is really 1495 * 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 1496 * 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 1497 * on the map will get recalculated. The players could very well
1747 CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); 1758 CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL);
1748 CLEAR_FLAG (op, FLAG_REMOVED); 1759 CLEAR_FLAG (op, FLAG_REMOVED);
1749 if (op->nrof) 1760 if (op->nrof)
1750 { 1761 {
1751 for (tmp = inv; tmp != NULL; tmp = tmp->below) 1762 for (tmp = inv; tmp != NULL; tmp = tmp->below)
1752 if (CAN_MERGE (tmp, op)) 1763 if (object::can_merge (tmp, op))
1753 { 1764 {
1754 /* return the original object and remove inserted object 1765 /* return the original object and remove inserted object
1755 (client needs the original object) */ 1766 (client needs the original object) */
1756 tmp->nrof += op->nrof; 1767 tmp->nrof += op->nrof;
1757 /* Weight handling gets pretty funky. Since we are adding to 1768 /* Weight handling gets pretty funky. Since we are adding to
2518 src = src->head; 2529 src = src->head;
2519 2530
2520 prev = 0; 2531 prev = 0;
2521 for (part = src; part; part = part->more) 2532 for (part = src; part; part = part->more)
2522 { 2533 {
2523 tmp = object::create (); 2534 tmp = part->clone ();
2524 part->copy_to (tmp);
2525 tmp->x -= src->x; 2535 tmp->x -= src->x;
2526 tmp->y -= src->y; 2536 tmp->y -= src->y;
2527 2537
2528 if (!part->head) 2538 if (!part->head)
2529 { 2539 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines