reads an object returns 1 if read ok
| 1570 | // reads an object |
| 1571 | // returns 1 if read ok |
| 1572 | int ReadObject(CFILE *ifile, object *objp, int handle, int fileversion) { |
| 1573 | int type, id, old_id, i; |
| 1574 | int roomnum; |
| 1575 | float door_shields; |
| 1576 | char tempname[OBJ_NAME_LEN + 1] = ""; |
| 1577 | |
| 1578 | type = cf_ReadByte(ifile); |
| 1579 | |
| 1580 | if (fileversion >= 34) |
| 1581 | id = cf_ReadShort(ifile); |
| 1582 | else |
| 1583 | id = (uint8_t)cf_ReadByte(ifile); |
| 1584 | |
| 1585 | // Translate id |
| 1586 | old_id = id; |
| 1587 | switch (type) { |
| 1588 | case OBJ_ROBOT: |
| 1589 | case OBJ_POWERUP: |
| 1590 | case OBJ_BUILDING: |
| 1591 | case OBJ_CLUTTER: |
| 1592 | id = generic_xlate[id]; |
| 1593 | break; |
| 1594 | |
| 1595 | case OBJ_DOOR: |
| 1596 | id = door_xlate[id]; |
| 1597 | break; |
| 1598 | } |
| 1599 | // Check for object not found |
| 1600 | if (id == -1) { |
| 1601 | id = FindValidID(type); // find any valid id |
| 1602 | |
| 1603 | ASSERT(id != -1); |
| 1604 | |
| 1605 | #if (defined(EDITOR) || defined(NEWEDITOR)) |
| 1606 | if (GetFunctionMode() == EDITOR_MODE) { |
| 1607 | char *old_name = GetFailedXLateItemName((type == OBJ_DOOR) ? XT_DOOR : XT_GENERIC, old_id); |
| 1608 | char *new_name = (type == OBJ_DOOR) ? Doors[id].name : Object_info[id].name; |
| 1609 | OutrageMessageBox("Object %d (type %s) has undefined ID %d, \"%s\".\n\n" |
| 1610 | "This object will be converted to ID %d, \"%s\".", |
| 1611 | objp - Objects, Object_type_names[type], old_id, old_name, id, new_name); |
| 1612 | } |
| 1613 | #endif |
| 1614 | } |
| 1615 | |
| 1616 | // Convert un-allowed OEM objects |
| 1617 | if (IS_GENERIC(type)) { |
| 1618 | ConvertObject(&type, &id); |
| 1619 | } |
| 1620 | |
| 1621 | // Read the object's name |
| 1622 | if (fileversion >= 95) { |
| 1623 | cf_ReadString(tempname, sizeof(tempname), ifile); |
| 1624 | if (strlen(tempname)) { |
| 1625 | if (type == OBJ_PLAYER) { |
| 1626 | #if (defined(EDITOR) || defined(NEWEDITOR)) |
| 1627 | if (GetFunctionMode() == EDITOR_MODE) |
| 1628 | OutrageMessageBox("Object %d, Player %d has a name (\"%s\") which has been deleted.", objp - Objects, id, |
| 1629 | tempname); |
no test coverage detected