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

Method AddObject

Descent3/Inventory.cpp:395–500  ·  view source on GitHub ↗

adds an object to the inventory (marked by it's objhandle)

Source from the content-addressed store, hash-verified

393
394// adds an object to the inventory (marked by it's objhandle)
395bool Inventory::AddObject(int object_handle, int flags, const char *description) {
396 // make sure we can fit another object
397 if (count >= MAX_UNIQUE_INVEN_ITEMS) {
398 mprintf(0, "Max unique count hit on add to inventory\n");
399 return false;
400 }
401
402 object *obj = ObjGet(object_handle);
403 if (!obj) {
404 mprintf(0, "INVEN: Invalid object trying to be added\n");
405 return false;
406 }
407
408 if (obj->flags & OF_INFORM_DESTROY_TO_LG) {
409 Level_goals.Inform(LIT_OBJECT, LGF_COMP_DESTROY, obj->handle);
410 }
411
412 bool in_as_dummy = false;
413 if (obj->type == OBJ_DUMMY) {
414 // type coming in is already dummy, un-dummy before adding it
415 ObjUnGhostObject(OBJNUM(obj));
416 in_as_dummy = true;
417 }
418
419 ASSERT(obj->type == OBJ_BUILDING || obj->type == OBJ_ROBOT || obj->type == OBJ_POWERUP || obj->type == OBJ_CLUTTER);
420
421 inven_item *current = root, *prev = root, *newnode;
422
423 if (count == 0) {
424 // there are no items in the list...time to add
425 root = new inven_item;
426 newnode = root;
427 root->next = root;
428 root->prev = root;
429 newnode->iflags = INVF_OBJECT;
430 newnode->count = 1;
431 } else {
432 newnode = new inven_item;
433
434 prev = root->prev;
435
436 newnode->prev = prev;
437 prev->next = newnode;
438 newnode->next = root;
439 root->prev = newnode;
440
441 newnode->iflags = INVF_OBJECT;
442 newnode->count = 1;
443 }
444
445 newnode->type = object_handle;
446 newnode->id = -1;
447 newnode->flags = 0;
448 newnode->otype = obj->type;
449 newnode->oid = obj->id;
450
451 if (Object_info[newnode->oid].description) {
452 newnode->description = mem_strdup(Object_info[newnode->oid].description);

Callers 3

ProcessTestKeysFunction · 0.80
msafe_CallFunctionFunction · 0.80
dInven_AddObjectFunction · 0.80

Calls 5

ObjGetFunction · 0.85
ObjUnGhostObjectFunction · 0.85
ObjGhostObjectFunction · 0.85
MultiSendGhostObjectFunction · 0.85
InformMethod · 0.80

Tested by

no test coverage detected