… | |
… | |
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 | |
194 | bool object::can_merge (object *ob1, object *ob2) |
194 | bool 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 | |
|
|
595 | object * |
|
|
596 | object::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 | */ |
… | |
… | |
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 | |
… | |
… | |
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 | { |