Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPCs don't collect weapons after fight #3

Closed
AmProsius opened this issue Dec 30, 2020 · 2 comments · Fixed by #68
Closed

NPCs don't collect weapons after fight #3

AmProsius opened this issue Dec 30, 2020 · 2 comments · Fixed by #68
Labels
compatibility: difficult This issue is difficult to make compatible. impl: hook script func This issue requires hooking script functions. impl: modify engine func This issue requires modifying the machine code of engine functions. provided fix This issue has a fix provided in the comments. type: session fix The fix for this issues is persistent across a session. validation: validated This issue is still present even with Systempack/Union.
Milestone

Comments

@AmProsius
Copy link
Owner

AmProsius commented Dec 30, 2020

Describe the bug
NPCs don't always collect their weapons and loast ammunition when they regain consciousness after a lost fight.

Expected behavior
NPCs now always pick up their weapons and lost ammunition after a lost fight.

@catalinstoian
Copy link

catalinstoian commented Jan 9, 2021

func void B_RegainDroppedWeapon(var C_NPC slf)
{
//-------- fallgelassene Waffe aufheben... --------
Npc_PerceiveAll (slf);
if ( Wld_DetectItem (slf, ITEM_KAT_NF) || Wld_DetectItem (slf, ITEM_KAT_FF) )
{
if !Npc_IsPlayer(slf)
&& Npc_CanSeeItem(slf,item)
{
PrintDebugNpc(PD_ZS_CHECK, "...NSC hebt seine Waffen wieder auf!" );
AI_TakeItem (slf, item);
AI_EquipBestMeleeWeapon(slf);
AI_EquipBestRangedWeapon(slf);
};
};
};

changed to

func void B_RegainDroppedWeapon(var C_NPC slf)
{
	//-------- fallgelassene Waffe aufheben... --------
	Npc_PerceiveAll (slf);
	if ( Wld_DetectItem (slf, ITEM_KAT_NF) )
	{
		if	!Npc_IsPlayer(slf)
		&&	Npc_CanSeeItem(slf,item)
		&&	!Npc_HasEquippedMeleeWeapon(slf)
		{
			PrintDebugNpc(PD_ZS_CHECK, "...NSC hebt seine Nahkampf-Waffe wieder auf!" );
			AI_TakeItem (slf, item);
			AI_EquipBestMeleeWeapon(slf);
		};
	};
	Npc_PerceiveAll (slf);
	if ( Wld_DetectItem (slf, ITEM_KAT_FF) )
	{
		if	!Npc_IsPlayer(slf)
		&&	Npc_CanSeeItem(slf,item)
		&&	!Npc_HasEquippedRangedWeapon(slf)
		{
			PrintDebugNpc(PD_ZS_CHECK, "...NSC hebt seine Fernkampf-Waffe wieder auf!" );
			AI_TakeItem (slf, item);
			AI_EquipBestRangedWeapon(slf);
		};
	};
	Npc_PerceiveAll (slf);
	if ( Wld_DetectItem (slf, ITEM_KAT_MUN) )
	{
		if	!Npc_IsPlayer(slf)
		&&	Npc_CanSeeItem(slf,item)
		{
			PrintDebugNpc(PD_ZS_CHECK, "...NSC hebt seine Munition wieder auf!" );
			AI_TakeItem (slf, item);
		};
	};
};

szapp added a commit that referenced this issue Jan 16, 2021
@AmProsius AmProsius added type: session fix The fix for this issues is persistent across a session. and removed validation required labels Jan 17, 2021
@AmProsius AmProsius linked a pull request Jan 17, 2021 that will close this issue
@AmProsius AmProsius moved this from To Do to In Progress in v1.0.0 Jan 17, 2021
v1.0.0 automation moved this from In Progress to Done Jan 17, 2021
AmProsius added a commit that referenced this issue Jan 17, 2021
#3 correctly pick up weapons after fight
szapp added a commit that referenced this issue Jan 20, 2021
@AmProsius AmProsius added this to the v1.0.0 milestone Feb 13, 2021
@AmProsius AmProsius added provided fix This issue has a fix provided in the comments. validation: validated This issue is still present even with Systempack/Union. labels Mar 13, 2021
@szapp szapp added this to Hook Daedalus function in Fix templates Mar 15, 2021
@szapp szapp added impl: hook script func This issue requires hooking script functions. impl: modify engine func This issue requires modifying the machine code of engine functions. labels Mar 16, 2021
@szapp szapp moved this from Hook Daedalus function to NPC state in Fix templates Mar 16, 2021
@szapp szapp moved this from NPC state to NPC function in Fix templates Mar 17, 2021
@szapp
Copy link
Collaborator

szapp commented Mar 19, 2021

/*
* This function essentially replaces (not technically!) the function 'B_RegainDroppedWeapon'
*/
func void G1CP_003_RegainDroppedWeapon_Logic(var C_Npc slf) {
Npc_PerceiveAll(slf);
// Define possibly missing symbols locally
const int ITEM_KAT_NF = 1<<1;
const int ITEM_KAT_FF = 1<<2;
const int ITEM_KAT_MUN = 1<<3;
// Melee weapon
if (Wld_DetectItem(slf, ITEM_KAT_NF)) {
if (Npc_GetDistToItem(slf, item) < 5000) // Prevent walking off too far
&& (G1CP_Npc_CanSeeItemFreeLOS(slf, item)) // Does not have to face it, only line of sight
&& (!Npc_HasEquippedMeleeWeapon(slf)) {
AI_TakeItem(slf, item);
AI_Function_NI(slf, EquipWeapon, slf, Hlp_GetInstanceID(item)); // Equip this exact weapon in particular
};
};
// Ranged weapon
if (Wld_DetectItem(slf, ITEM_KAT_FF)) {
if (Npc_GetDistToItem(slf, item) < 5000)
&& (G1CP_Npc_CanSeeItemFreeLOS(slf, item))
&& (!Npc_HasEquippedRangedWeapon(slf)) {
AI_TakeItem(slf, item);
AI_Function_NI(slf, EquipWeapon, slf, Hlp_GetInstanceID(item));
};
};
// Ammunition (just a bonus)
if (Wld_DetectItem(slf, ITEM_KAT_MUN)) {
if (Npc_GetDistToItem(slf, item) < 5000)
&& (G1CP_Npc_CanSeeItemFreeLOS(slf, item)) {
AI_TakeItem(slf, item);
};
};
};

It seems like a made a mistake with the distances here. 5000 corresponds to 50 meters, which is way too far. Something like 300 as found in the function below seems more reasonable.

func void ZS_AssessBody_RecoverWeapon ()
{
PrintDebugNpc (PD_ZS_FRAME, "ZS_AssessBody_RecoverWeapon");
B_SetPerception (self);
//-------- nach der evtl. fallengelassenen Waffe suchen --------
Npc_PerceiveAll (self);
if (( Wld_DetectItem (self,ITEM_KAT_NF) || Wld_DetectItem (self,ITEM_KAT_FF) )
&& Npc_GetDistToItem(self,item) < 300 )
{
PrintDebugNpc (PD_ZS_CHECK, "...Nah- oder Fernkampfwaffe gefunden!" );
B_SayOverlay (self, NULL, "$ITakeYourWeapon");
AI_TakeItem (self, item);
AI_EquipBestMeleeWeapon(self);
AI_EquipBestRangedWeapon(self);
};
//-------- Heilen ! --------
AI_StartState (self, ZS_HealSelf, 1, "");
};

@szapp szapp reopened this Mar 19, 2021
v1.0.0 automation moved this from Done to In Progress Mar 19, 2021
@szapp szapp self-assigned this Mar 19, 2021
@szapp szapp added this to To Do in v1.1.0 via automation Mar 21, 2021
@szapp szapp moved this from In Progress to Done in v1.0.0 Mar 21, 2021
@szapp szapp moved this from To Do to In Progress in v1.1.0 Mar 21, 2021
@szapp szapp added the compatibility: difficult This issue is difficult to make compatible. label Mar 21, 2021
szapp added a commit that referenced this issue Mar 28, 2021
@szapp szapp closed this as completed Mar 28, 2021
v1.1.0 automation moved this from In Progress to Done Mar 28, 2021
@szapp szapp removed their assignment Mar 29, 2021
szapp added a commit that referenced this issue Apr 1, 2021
szapp added a commit that referenced this issue Apr 20, 2021
@szapp szapp moved this from Modify NPC function to Some NPC Test? (Todo adjust name) in Fix templates Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility: difficult This issue is difficult to make compatible. impl: hook script func This issue requires hooking script functions. impl: modify engine func This issue requires modifying the machine code of engine functions. provided fix This issue has a fix provided in the comments. type: session fix The fix for this issues is persistent across a session. validation: validated This issue is still present even with Systempack/Union.
Projects
Fix templates
NPC manual test (TODO rename)
v1.0.0
  
Done
v1.1.0
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants