MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ReadInventory

Method ReadInventory

Descent3/Inventory.cpp:1058–1142  ·  view source on GitHub ↗

restores the inventory from file (returns number of bytes read)

Source from the content-addressed store, hash-verified

1056
1057// restores the inventory from file (returns number of bytes read)
1058int Inventory::ReadInventory(CFILE *file) {
1059 int start_pos = cftell(file);
1060
1061 int num_items = cf_ReadInt(file);
1062 count = num_items;
1063 root = NULL;
1064 char temp[512];
1065
1066 int t, i, otype;
1067
1068 if (num_items > 0) {
1069 inven_item *item, *prev;
1070
1071 while (num_items > 0) {
1072 t = cf_ReadInt(file);
1073 otype = cf_ReadInt(file);
1074 i = cf_ReadInt(file);
1075
1076 // make sure the object is valid
1077 if (i == -1) {
1078 object *obj = ObjGet(t);
1079 ASSERT(obj);
1080 if (!obj) {
1081 mprintf(0, "Invalid object restoring inventory\n");
1082 // skip this object
1083 cf_ReadInt(file);
1084 cf_ReadInt(file);
1085 cf_ReadInt(file);
1086 cf_ReadString(temp, 512, file);
1087 cf_ReadString(temp, 512, file);
1088 cf_ReadString(temp, 512, file);
1089 cf_ReadInt(file);
1090 num_items--;
1091 count--;
1092 continue;
1093 }
1094 }
1095
1096 if (root == NULL) {
1097 // there are no items in the list...time to add
1098 root = new inven_item;
1099 item = root;
1100 root->next = root;
1101 root->prev = root;
1102 } else {
1103 item = new inven_item;
1104
1105 prev = root->prev;
1106
1107 item->prev = prev;
1108 prev->next = item;
1109 item->next = root;
1110 root->prev = item;
1111 }
1112
1113 item->type = t;
1114 item->id = i;
1115 item->otype = otype;

Callers 1

LGSPlayersFunction · 0.80

Calls 4

cftellFunction · 0.85
cf_ReadIntFunction · 0.85
ObjGetFunction · 0.85
cf_ReadStringFunction · 0.85

Tested by

no test coverage detected