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

Method Use

Descent3/Inventory.cpp:693–826  ·  view source on GitHub ↗

uses an item in the inventory (returns false if the item doesn't exist)

Source from the content-addressed store, hash-verified

691
692// uses an item in the inventory (returns false if the item doesn't exist)
693bool Inventory::Use(int type, int id, object *parent) {
694 inven_item *node;
695
696 node = FindItem(type, id);
697
698 if (!node)
699 return false;
700
701 if (!(node->iflags & INVF_USEABLE))
702 return false;
703
704 bool multiplayer = (bool)((Game_mode & GM_MULTI) != 0);
705 bool client;
706 bool server;
707 bool ret = false;
708
709 if (multiplayer) {
710 if (Netgame.local_role & LR_SERVER) {
711 client = false;
712 server = true;
713 } else {
714 client = true;
715 server = false;
716 }
717 } else {
718 client = false;
719 server = false;
720 }
721
722 if (client) {
723 // OK, we're a client in a multiplayer game, so send a request to the server to use this Item
724 SendRequestToServerToUse(node->type, node->id);
725
726 return false;
727 }
728
729 // If we got here, then we are either the server in a multiplayer game, or in a single player game
730
731 // get player object (needed when we recreate the object)
732 object *player;
733 ASSERT(parent);
734 player = parent;
735
736 if (player == NULL) {
737 Int3();
738 return false;
739 }
740
741 // if type is OBJ_WEAPON then it's a countermeasure
742 if (type == OBJ_WEAPON) {
743 mprintf(0, "CounterMeasures: Use\n");
744 // countermeasure
745 CreateCountermeasureFromObject(player, id);
746 Remove(node->type, node->id);
747 ret = true;
748 } else {
749 mprintf(0, "Inventory: Use\n");
750 // regular

Callers 2

dInven_UseFunction · 0.80
dInven_UseObjHandleFunction · 0.80

Calls 10

ObjGetFunction · 0.85
ObjUnGhostObjectFunction · 0.85
MultiSendGhostObjectFunction · 0.85
ObjCreateFunction · 0.85
SetObjectControlTypeFunction · 0.85
MultiSendObjectFunction · 0.85
InitObjectScriptsFunction · 0.85
Osiris_CallEventFunction · 0.85
SetObjectDeadFlagFunction · 0.85

Tested by

no test coverage detected