… | |
… | |
1112 | } |
1112 | } |
1113 | |
1113 | |
1114 | return 0; |
1114 | return 0; |
1115 | } |
1115 | } |
1116 | |
1116 | |
|
|
1117 | void |
|
|
1118 | object::expand_tail () |
|
|
1119 | { |
|
|
1120 | if (more) |
|
|
1121 | return; |
|
|
1122 | |
|
|
1123 | object *prev = this; |
|
|
1124 | |
|
|
1125 | for (archetype *at = arch->more; at; at = at->more) |
|
|
1126 | { |
|
|
1127 | object *op = arch_to_object (at); |
|
|
1128 | |
|
|
1129 | op->name = name; |
|
|
1130 | op->name_pl = name_pl; |
|
|
1131 | op->title = title; |
|
|
1132 | |
|
|
1133 | op->head = this; |
|
|
1134 | prev->more = op; |
|
|
1135 | |
|
|
1136 | prev = op; |
|
|
1137 | } |
|
|
1138 | } |
|
|
1139 | |
1117 | /* |
1140 | /* |
1118 | * same as insert_ob_in_map except it handles separate coordinates and does a clean |
1141 | * same as insert_ob_in_map except it handles separate coordinates and does a clean |
1119 | * job preparing multi-part monsters. |
1142 | * job preparing multi-part monsters. |
1120 | */ |
1143 | */ |
1121 | object * |
1144 | object * |
… | |
… | |
1151 | * just 'op' otherwise |
1174 | * just 'op' otherwise |
1152 | */ |
1175 | */ |
1153 | object * |
1176 | object * |
1154 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1177 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1155 | { |
1178 | { |
|
|
1179 | assert (!op->flag [FLAG_FREED]); |
|
|
1180 | |
1156 | object *tmp, *top, *floor = NULL; |
1181 | object *tmp, *top, *floor = NULL; |
1157 | |
1182 | |
1158 | if (QUERY_FLAG (op, FLAG_FREED)) |
|
|
1159 | { |
|
|
1160 | LOG (llevError, "Trying to insert freed object!\n"); |
|
|
1161 | return NULL; |
|
|
1162 | } |
|
|
1163 | |
|
|
1164 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
|
|
1165 | LOG (llevError, "Trying to insert already inserted object %s\n", op->debug_desc ()); |
|
|
1166 | |
|
|
1167 | op->remove (); |
1183 | op->remove (); |
1168 | |
1184 | |
1169 | if (!m) |
1185 | if (!m->active != !op->active) |
1170 | { |
1186 | if (m->active) |
1171 | char *dump = dump_object (op); |
1187 | op->activate_recursive (); |
1172 | LOG (llevError, "Trying to insert in null-map!\n%s\n", dump); |
1188 | else |
1173 | free (dump); |
1189 | op->deactivate_recursive (); |
1174 | return op; |
|
|
1175 | } |
|
|
1176 | |
1190 | |
1177 | if (out_of_map (m, op->x, op->y)) |
1191 | if (out_of_map (m, op->x, op->y)) |
1178 | { |
1192 | { |
1179 | char *dump = dump_object (op); |
|
|
1180 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", dump); |
1193 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", op->debug_desc ()); |
1181 | #ifdef MANY_CORES |
1194 | #ifdef MANY_CORES |
1182 | /* Better to catch this here, as otherwise the next use of this object |
1195 | /* Better to catch this here, as otherwise the next use of this object |
1183 | * is likely to cause a crash. Better to find out where it is getting |
1196 | * is likely to cause a crash. Better to find out where it is getting |
1184 | * improperly inserted. |
1197 | * improperly inserted. |
1185 | */ |
1198 | */ |
1186 | abort (); |
1199 | abort (); |
1187 | #endif |
1200 | #endif |
1188 | free (dump); |
|
|
1189 | return op; |
1201 | return op; |
1190 | } |
1202 | } |
1191 | |
1203 | |
1192 | if (object *more = op->more) |
1204 | if (object *more = op->more) |
1193 | { |
1205 | { |
… | |
… | |
1430 | tmp1->x = op->x; |
1442 | tmp1->x = op->x; |
1431 | tmp1->y = op->y; |
1443 | tmp1->y = op->y; |
1432 | insert_ob_in_map (tmp1, op->map, op, 0); |
1444 | insert_ob_in_map (tmp1, op->map, op, 0); |
1433 | } |
1445 | } |
1434 | |
1446 | |
1435 | // XXX: function not returning object* |
|
|
1436 | object * |
1447 | object * |
1437 | object::insert_at (object *where, object *originator, int flags) |
1448 | object::insert_at (object *where, object *originator, int flags) |
1438 | { |
1449 | { |
1439 | where->map->insert (this, where->x, where->y, originator, flags); |
1450 | return where->map->insert (this, where->x, where->y, originator, flags); |
1440 | } |
1451 | } |
1441 | |
1452 | |
1442 | /* |
1453 | /* |
1443 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
1454 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
1444 | * is returned contains nr objects, and the remaining parts contains |
1455 | * is returned contains nr objects, and the remaining parts contains |
… | |
… | |
1484 | * the amount of an object. If the amount reaches 0, the object |
1495 | * the amount of an object. If the amount reaches 0, the object |
1485 | * is subsequently removed and freed. |
1496 | * is subsequently removed and freed. |
1486 | * |
1497 | * |
1487 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1498 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1488 | */ |
1499 | */ |
1489 | |
|
|
1490 | object * |
1500 | object * |
1491 | decrease_ob_nr (object *op, uint32 i) |
1501 | decrease_ob_nr (object *op, uint32 i) |
1492 | { |
1502 | { |
1493 | object *tmp; |
1503 | object *tmp; |
1494 | |
1504 | |
… | |
… | |
1569 | |
1579 | |
1570 | /* |
1580 | /* |
1571 | * add_weight(object, weight) adds the specified weight to an object, |
1581 | * add_weight(object, weight) adds the specified weight to an object, |
1572 | * and also updates how much the environment(s) is/are carrying. |
1582 | * and also updates how much the environment(s) is/are carrying. |
1573 | */ |
1583 | */ |
1574 | |
|
|
1575 | void |
1584 | void |
1576 | add_weight (object *op, signed long weight) |
1585 | add_weight (object *op, signed long weight) |
1577 | { |
1586 | { |
1578 | while (op != NULL) |
1587 | while (op != NULL) |
1579 | { |
1588 | { |
… | |
… | |
1611 | * inside the object environment. |
1620 | * inside the object environment. |
1612 | * |
1621 | * |
1613 | * The function returns now pointer to inserted item, and return value can |
1622 | * The function returns now pointer to inserted item, and return value can |
1614 | * be != op, if items are merged. -Tero |
1623 | * be != op, if items are merged. -Tero |
1615 | */ |
1624 | */ |
1616 | |
|
|
1617 | object * |
1625 | object * |
1618 | object::insert (object *op) |
1626 | object::insert (object *op) |
1619 | { |
1627 | { |
1620 | object *tmp, *otmp; |
1628 | object *tmp, *otmp; |
1621 | |
1629 | |