Last active
February 16, 2023 03:41
-
-
Save daftmugi/2bb21fec91ebf7841872a9e27a2909a3 to your computer and use it in GitHub Desktop.
#6257: Add auto-search bodies option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git game/Entity.cpp game/Entity.cpp | |
index 80f9492..5d08c08 100644 | |
--- game/Entity.cpp | |
+++ game/Entity.cpp | |
@@ -11339,6 +11339,30 @@ void idEntity::Event_AddItemToInv(idEntity* ent) | |
ent->AddToInventory(this); | |
} | |
+bool idEntity::AddAttachmentsToInventory( idPlayer* player ) | |
+{ | |
+ // NOTE: m_Attachments might not include a key, purse, or other item attached | |
+ // using "bind" or "bindToJoint", so iterate through children instead. | |
+ | |
+ if (GetBindMaster() != NULL) { | |
+ // Not a BindMaster, so don't iterate through its children. | |
+ // No items can be added to the player's inventory. | |
+ return false; | |
+ } | |
+ | |
+ bool didAddItem = false; | |
+ | |
+ idList<idEntity *> children; | |
+ GetTeamChildren(&children); | |
+ for (int i = 0 ; i < children.Num() ; i++) { | |
+ idEntity* child = children[i]; | |
+ if (child && player->AddToInventory(child)) | |
+ didAddItem = true; | |
+ } | |
+ | |
+ return didAddItem; | |
+} | |
+ | |
CInventoryItemPtr idEntity::AddToInventory(idEntity *ent) | |
{ | |
// Sanity check | |
diff --git game/Entity.h game/Entity.h | |
index 70af3c9..e30e2ce 100644 | |
--- game/Entity.h | |
+++ game/Entity.h | |
@@ -1112,6 +1112,12 @@ public: | |
*/ | |
const bool CanBePickedUp(); | |
+ /** | |
+ * Daft Mugi #6257: Auto-search bodies | |
+ * Returns true, if any of the items attached to the entity were added to the player's inventory. | |
+ */ | |
+ virtual bool AddAttachmentsToInventory( idPlayer* player ); | |
+ | |
/** | |
* AddToInventory will add an entity to the inventory. The item is only | |
* added if the appropriate spawnargs are set, otherwise it will be rejected | |
diff --git game/Player.cpp game/Player.cpp | |
index c74f401..a621246 100644 | |
--- game/Player.cpp | |
+++ game/Player.cpp | |
@@ -11565,6 +11565,21 @@ void idPlayer::PerformFrob(EImpulseState impulseState, idEntity* target, bool al | |
} | |
} | |
+ // If attachment, such as head, get its body. | |
+ idEntity* body = target->IsType(idAFAttachment::Type) ? | |
+ static_cast<idAFAttachment*>(target)->GetBindMaster() : | |
+ target; | |
+ | |
+ // NOTE: The body being looted might not be an idAI. | |
+ if (body && body->IsType(idAFEntity_Base::Type)) | |
+ { | |
+ // Daft Mugi #6257 | |
+ // If looted body this time, do not pick up. | |
+ if (cv_tdm_autosearch_bodies.GetBool() | |
+ && body->AddAttachmentsToInventory(this)) | |
+ return; | |
+ } | |
+ | |
gameLocal.m_Grabber->Update(this, false, true); // preservePosition = true #4149 | |
} | |
} | |
diff --git game/gamesys/SysCvar.cpp game/gamesys/SysCvar.cpp | |
index 7250eb4..b97cf56 100644 | |
--- game/gamesys/SysCvar.cpp | |
+++ game/gamesys/SysCvar.cpp | |
@@ -260,6 +260,9 @@ idCVar cv_tdm_jump_relaxation_time( "tdm_jump_relaxation_time", "4", CVAR_FL | |
idCVar cv_tdm_footfalls_movetype_specific( "tdm_footfall_sounds_movetype_specific", "1", CVAR_GAME | CVAR_ARCHIVE | CVAR_BOOL, "Set to 1 to use move-type dependent foot fall sounds." ); | |
+// Daft Mugi #6257: Auto-search bodies | |
+idCVar cv_tdm_autosearch_bodies( "tdm_autosearch_bodies", "0", CVAR_GAME | CVAR_ARCHIVE | CVAR_BOOL, "Set to 1 to auto-search bodies." ); | |
+ | |
// Dark Mod crouching | |
idCVar cv_tdm_crouch_toggle( "tdm_toggle_crouch", "1", CVAR_GAME | CVAR_ARCHIVE | CVAR_BOOL, "Set to 1 to make crouching toggleable." ); | |
idCVar cv_tdm_crouch_toggle_hold_time( "tdm_crouch_toggle_hold_time", "400", CVAR_GAME | CVAR_ARCHIVE | CVAR_FLOAT, "The time in milliseconds to hold crouch while on a rope/ladder for starting to slide down." ); | |
diff --git game/gamesys/SysCvar.h game/gamesys/SysCvar.h | |
index e1c58e8..8a57802 100644 | |
--- game/gamesys/SysCvar.h | |
+++ game/gamesys/SysCvar.h | |
@@ -218,6 +218,9 @@ extern idCVar cv_ai_search_type; // grayman #4220 - control type of search | |
extern idCVar cv_force_savegame_load; | |
extern idCVar cv_savegame_compress; | |
+// Daft Mugi #6257: Auto-search bodies | |
+extern idCVar cv_tdm_autosearch_bodies; | |
+ | |
// angua: TDM toggle crouch | |
extern idCVar cv_tdm_crouch_toggle; | |
extern idCVar cv_tdm_crouch_toggle_hold_time; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I originally wrote and tested this on "William Steele 1: In the North". That mission uses
*_attachX
to attach purses, keys, etc.Then, testing on "Full Moon Fever" revealed differences. One of the guards had a key attached using
bind
andbindToJoint
, som_Attachments
did not find the key. UsingGetTeamChildren()
instead fixed this issue. Also, this mission has a dead body with a key that is not anidAI
, soidAFEntity_Base
had to be used.