… | |
… | |
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 | */ |
… | |
… | |
1200 | |
1202 | |
1201 | for (; top != NULL; top = top->below) |
1203 | for (; top != NULL; top = top->below) |
1202 | { |
1204 | { |
1203 | if (top == op) |
1205 | if (top == op) |
1204 | continue; |
1206 | continue; |
1205 | if (CAN_MERGE (op, top)) |
1207 | |
|
|
1208 | if (object::can_merge (op, top)) |
1206 | { |
1209 | { |
1207 | top->nrof += op->nrof; |
1210 | top->nrof += op->nrof; |
1208 | |
1211 | |
1209 | /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ |
1212 | /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ |
1210 | op->weight = 0; /* Don't want any adjustements now */ |
1213 | op->weight = 0; /* Don't want any adjustements now */ |
… | |
… | |
1343 | |
1346 | |
1344 | /* this has to be done after we translate the coordinates. |
1347 | /* this has to be done after we translate the coordinates. |
1345 | */ |
1348 | */ |
1346 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1349 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1347 | 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) |
1348 | if (CAN_MERGE (op, tmp)) |
1351 | if (object::can_merge (op, tmp)) |
1349 | { |
1352 | { |
1350 | op->nrof += tmp->nrof; |
1353 | op->nrof += tmp->nrof; |
1351 | tmp->destroy (); |
1354 | tmp->destroy (); |
1352 | } |
1355 | } |
1353 | |
1356 | |
… | |
… | |
1755 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1758 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1756 | CLEAR_FLAG (op, FLAG_REMOVED); |
1759 | CLEAR_FLAG (op, FLAG_REMOVED); |
1757 | if (op->nrof) |
1760 | if (op->nrof) |
1758 | { |
1761 | { |
1759 | for (tmp = inv; tmp != NULL; tmp = tmp->below) |
1762 | for (tmp = inv; tmp != NULL; tmp = tmp->below) |
1760 | if (CAN_MERGE (tmp, op)) |
1763 | if (object::can_merge (tmp, op)) |
1761 | { |
1764 | { |
1762 | /* return the original object and remove inserted object |
1765 | /* return the original object and remove inserted object |
1763 | (client needs the original object) */ |
1766 | (client needs the original object) */ |
1764 | tmp->nrof += op->nrof; |
1767 | tmp->nrof += op->nrof; |
1765 | /* Weight handling gets pretty funky. Since we are adding to |
1768 | /* Weight handling gets pretty funky. Since we are adding to |