… | |
… | |
454 | * refcounts and freeing the links. |
454 | * refcounts and freeing the links. |
455 | */ |
455 | */ |
456 | static void |
456 | static void |
457 | free_key_values (object *op) |
457 | free_key_values (object *op) |
458 | { |
458 | { |
459 | for (key_value *i = op->key_values; i != 0;) |
459 | for (key_value *i = op->key_values; i; ) |
460 | { |
460 | { |
461 | key_value *next = i->next; |
461 | key_value *next = i->next; |
462 | delete i; |
462 | delete i; |
463 | |
463 | |
464 | i = next; |
464 | i = next; |
465 | } |
465 | } |
466 | |
466 | |
467 | op->key_values = 0; |
467 | op->key_values = 0; |
468 | } |
468 | } |
469 | |
469 | |
470 | /* |
470 | object & |
471 | * copy_to first frees everything allocated by the dst object, |
471 | object::operator =(const object &src) |
472 | * and then copies the contents of itself into the second |
|
|
473 | * object, allocating what needs to be allocated. Basically, any |
|
|
474 | * data that is malloc'd needs to be re-malloc/copied. Otherwise, |
|
|
475 | * if the first object is freed, the pointers in the new object |
|
|
476 | * will point at garbage. |
|
|
477 | */ |
|
|
478 | void |
|
|
479 | object::copy_to (object *dst) |
|
|
480 | { |
472 | { |
481 | bool is_freed = QUERY_FLAG (dst, FLAG_FREED); |
473 | bool is_freed = flag [FLAG_FREED]; |
482 | bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED); |
474 | bool is_removed = flag [FLAG_REMOVED]; |
483 | |
475 | |
484 | *(object_copy *)dst = *this; |
476 | *(object_copy *)this = src; |
485 | |
477 | |
486 | if (is_freed) |
478 | flag [FLAG_FREED] = is_freed; |
487 | SET_FLAG (dst, FLAG_FREED); |
479 | flag [FLAG_REMOVED] = is_removed; |
488 | |
|
|
489 | if (is_removed) |
|
|
490 | SET_FLAG (dst, FLAG_REMOVED); |
|
|
491 | |
|
|
492 | if (speed < 0) |
|
|
493 | dst->speed_left = speed_left - rndm (); |
|
|
494 | |
480 | |
495 | /* Copy over key_values, if any. */ |
481 | /* Copy over key_values, if any. */ |
496 | if (key_values) |
482 | if (src.key_values) |
497 | { |
483 | { |
498 | key_value *tail = 0; |
484 | key_value *tail = 0; |
499 | key_value *i; |
|
|
500 | |
|
|
501 | dst->key_values = 0; |
485 | key_values = 0; |
502 | |
486 | |
503 | for (i = key_values; i; i = i->next) |
487 | for (key_value *i = src.key_values; i; i = i->next) |
504 | { |
488 | { |
505 | key_value *new_link = new key_value; |
489 | key_value *new_link = new key_value; |
506 | |
490 | |
507 | new_link->next = 0; |
491 | new_link->next = 0; |
508 | new_link->key = i->key; |
492 | new_link->key = i->key; |
509 | new_link->value = i->value; |
493 | new_link->value = i->value; |
510 | |
494 | |
511 | /* Try and be clever here, too. */ |
495 | /* Try and be clever here, too. */ |
512 | if (!dst->key_values) |
496 | if (!key_values) |
513 | { |
497 | { |
514 | dst->key_values = new_link; |
498 | key_values = new_link; |
515 | tail = new_link; |
499 | tail = new_link; |
516 | } |
500 | } |
517 | else |
501 | else |
518 | { |
502 | { |
519 | tail->next = new_link; |
503 | tail->next = new_link; |
520 | tail = new_link; |
504 | tail = new_link; |
521 | } |
505 | } |
522 | } |
506 | } |
523 | } |
507 | } |
|
|
508 | } |
|
|
509 | |
|
|
510 | /* |
|
|
511 | * copy_to first frees everything allocated by the dst object, |
|
|
512 | * and then copies the contents of itself into the second |
|
|
513 | * object, allocating what needs to be allocated. Basically, any |
|
|
514 | * data that is malloc'd needs to be re-malloc/copied. Otherwise, |
|
|
515 | * if the first object is freed, the pointers in the new object |
|
|
516 | * will point at garbage. |
|
|
517 | */ |
|
|
518 | void |
|
|
519 | object::copy_to (object *dst) |
|
|
520 | { |
|
|
521 | *dst = *this; |
|
|
522 | |
|
|
523 | if (speed < 0) |
|
|
524 | dst->speed_left = speed_left - rndm (); |
524 | |
525 | |
525 | dst->set_speed (dst->speed); |
526 | dst->set_speed (dst->speed); |
526 | } |
527 | } |
527 | |
528 | |
528 | void |
529 | void |
… | |
… | |
606 | * UP_OBJ_FACE: only the objects face has changed. |
607 | * UP_OBJ_FACE: only the objects face has changed. |
607 | */ |
608 | */ |
608 | void |
609 | void |
609 | update_object (object *op, int action) |
610 | update_object (object *op, int action) |
610 | { |
611 | { |
611 | MoveType move_on, move_off, move_block, move_slow; |
|
|
612 | |
|
|
613 | if (op == NULL) |
612 | if (op == NULL) |
614 | { |
613 | { |
615 | /* this should never happen */ |
614 | /* this should never happen */ |
616 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
615 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
617 | return; |
616 | return; |
… | |
… | |
1111 | return top; |
1110 | return top; |
1112 | } |
1111 | } |
1113 | } |
1112 | } |
1114 | |
1113 | |
1115 | return 0; |
1114 | return 0; |
|
|
1115 | } |
|
|
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 | } |
1116 | } |
1138 | } |
1117 | |
1139 | |
1118 | /* |
1140 | /* |
1119 | * 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 |
1120 | * job preparing multi-part monsters. |
1142 | * job preparing multi-part monsters. |
… | |
… | |
1152 | * just 'op' otherwise |
1174 | * just 'op' otherwise |
1153 | */ |
1175 | */ |
1154 | object * |
1176 | object * |
1155 | 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) |
1156 | { |
1178 | { |
|
|
1179 | assert (!op->flag [FLAG_FREED]); |
|
|
1180 | |
1157 | object *tmp, *top, *floor = NULL; |
1181 | object *tmp, *top, *floor = NULL; |
1158 | |
1182 | |
1159 | if (QUERY_FLAG (op, FLAG_FREED)) |
|
|
1160 | { |
|
|
1161 | LOG (llevError, "Trying to insert freed object!\n"); |
|
|
1162 | return NULL; |
|
|
1163 | } |
|
|
1164 | |
|
|
1165 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
|
|
1166 | LOG (llevError, "Trying to insert already inserted object %s\n", op->debug_desc ()); |
|
|
1167 | |
|
|
1168 | op->remove (); |
1183 | op->remove (); |
1169 | |
1184 | |
1170 | if (!m) |
1185 | #if 0 |
1171 | { |
1186 | if (!m->active != !op->active) |
1172 | char *dump = dump_object (op); |
1187 | if (m->active) |
1173 | LOG (llevError, "Trying to insert in null-map!\n%s\n", dump); |
1188 | op->activate_recursive (); |
1174 | free (dump); |
1189 | else |
1175 | return op; |
1190 | op->deactivate_recursive (); |
1176 | } |
1191 | #endif |
1177 | |
1192 | |
1178 | if (out_of_map (m, op->x, op->y)) |
1193 | if (out_of_map (m, op->x, op->y)) |
1179 | { |
1194 | { |
1180 | char *dump = dump_object (op); |
|
|
1181 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", dump); |
1195 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", op->debug_desc ()); |
1182 | #ifdef MANY_CORES |
1196 | #ifdef MANY_CORES |
1183 | /* Better to catch this here, as otherwise the next use of this object |
1197 | /* Better to catch this here, as otherwise the next use of this object |
1184 | * is likely to cause a crash. Better to find out where it is getting |
1198 | * is likely to cause a crash. Better to find out where it is getting |
1185 | * improperly inserted. |
1199 | * improperly inserted. |
1186 | */ |
1200 | */ |
1187 | abort (); |
1201 | abort (); |
1188 | #endif |
1202 | #endif |
1189 | free (dump); |
|
|
1190 | return op; |
1203 | return op; |
1191 | } |
1204 | } |
1192 | |
1205 | |
1193 | if (object *more = op->more) |
1206 | if (object *more = op->more) |
1194 | { |
1207 | { |
… | |
… | |
1291 | * looks like instead of lots of conditions here. |
1304 | * looks like instead of lots of conditions here. |
1292 | * makes things faster, and effectively the same result. |
1305 | * makes things faster, and effectively the same result. |
1293 | */ |
1306 | */ |
1294 | |
1307 | |
1295 | /* Have object 'fall below' other objects that block view. |
1308 | /* Have object 'fall below' other objects that block view. |
1296 | * Unless those objects are exits, type 66 |
1309 | * Unless those objects are exits. |
1297 | * If INS_ON_TOP is used, don't do this processing |
1310 | * If INS_ON_TOP is used, don't do this processing |
1298 | * Need to find the object that in fact blocks view, otherwise |
1311 | * Need to find the object that in fact blocks view, otherwise |
1299 | * stacking is a bit odd. |
1312 | * stacking is a bit odd. |
1300 | */ |
1313 | */ |
1301 | if (!(flag & INS_ON_TOP) |
1314 | if (!(flag & INS_ON_TOP) |
1302 | && ms.flags () & P_BLOCKSVIEW |
1315 | && ms.flags () & P_BLOCKSVIEW |
1303 | && (op->face && !op->face->visibility)) |
1316 | && (op->face && !faces [op->face].visibility)) |
1304 | { |
1317 | { |
1305 | for (last = top; last != floor; last = last->below) |
1318 | for (last = top; last != floor; last = last->below) |
1306 | if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) |
1319 | if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) |
1307 | break; |
1320 | break; |
1308 | |
1321 | |
… | |
… | |
1434 | } |
1447 | } |
1435 | |
1448 | |
1436 | object * |
1449 | object * |
1437 | object::insert_at (object *where, object *originator, int flags) |
1450 | object::insert_at (object *where, object *originator, int flags) |
1438 | { |
1451 | { |
1439 | where->map->insert (this, where->x, where->y, originator, flags); |
1452 | return where->map->insert (this, where->x, where->y, originator, flags); |
1440 | } |
1453 | } |
1441 | |
1454 | |
1442 | /* |
1455 | /* |
1443 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
1456 | * 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 |
1457 | * is returned contains nr objects, and the remaining parts contains |
… | |
… | |
1484 | * the amount of an object. If the amount reaches 0, the object |
1497 | * the amount of an object. If the amount reaches 0, the object |
1485 | * is subsequently removed and freed. |
1498 | * is subsequently removed and freed. |
1486 | * |
1499 | * |
1487 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1500 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1488 | */ |
1501 | */ |
1489 | |
|
|
1490 | object * |
1502 | object * |
1491 | decrease_ob_nr (object *op, uint32 i) |
1503 | decrease_ob_nr (object *op, uint32 i) |
1492 | { |
1504 | { |
1493 | object *tmp; |
1505 | object *tmp; |
1494 | |
1506 | |
… | |
… | |
1569 | |
1581 | |
1570 | /* |
1582 | /* |
1571 | * add_weight(object, weight) adds the specified weight to an object, |
1583 | * add_weight(object, weight) adds the specified weight to an object, |
1572 | * and also updates how much the environment(s) is/are carrying. |
1584 | * and also updates how much the environment(s) is/are carrying. |
1573 | */ |
1585 | */ |
1574 | |
|
|
1575 | void |
1586 | void |
1576 | add_weight (object *op, signed long weight) |
1587 | add_weight (object *op, signed long weight) |
1577 | { |
1588 | { |
1578 | while (op != NULL) |
1589 | while (op != NULL) |
1579 | { |
1590 | { |
… | |
… | |
1611 | * inside the object environment. |
1622 | * inside the object environment. |
1612 | * |
1623 | * |
1613 | * The function returns now pointer to inserted item, and return value can |
1624 | * The function returns now pointer to inserted item, and return value can |
1614 | * be != op, if items are merged. -Tero |
1625 | * be != op, if items are merged. -Tero |
1615 | */ |
1626 | */ |
1616 | |
|
|
1617 | object * |
1627 | object * |
1618 | object::insert (object *op) |
1628 | object::insert (object *op) |
1619 | { |
1629 | { |
1620 | object *tmp, *otmp; |
1630 | object *tmp, *otmp; |
1621 | |
1631 | |
… | |
… | |
2414 | return link->value; |
2424 | return link->value; |
2415 | |
2425 | |
2416 | return 0; |
2426 | return 0; |
2417 | } |
2427 | } |
2418 | |
2428 | |
2419 | |
|
|
2420 | /* |
2429 | /* |
2421 | * Updates the canonical_key in op to value. |
2430 | * Updates the canonical_key in op to value. |
2422 | * |
2431 | * |
2423 | * canonical_key is a shared string (value doesn't have to be). |
2432 | * canonical_key is a shared string (value doesn't have to be). |
2424 | * |
2433 | * |