gothic-1-community-patch icon indicating copy to clipboard operation
gothic-1-community-patch copied to clipboard

NPCs don't draw weapon depending on armor

Open AmProsius opened this issue 5 years ago • 4 comments

Describe the bug NPCs draw their ranged weapon even if it is weaker than the armor of the enemy.

Expected behavior NPCs no longer draw their ranged weapon if it is weaker than the armor of the enemy, but switch to melee combat.

AmProsius avatar Dec 30 '20 08:12 AmProsius

https://github.com/AmProsius/gothic-1-community-patch/blob/d3c811be3efff371c697ca597f680097e51aa5a7/scriptbase/_work/Data/Scripts/Content/AI/B_Human/B_SelectWeapon.d#L409-L414

changed to

//######## Waffenbasierte Kampftaktik ?  ########
	PrintDebugNpc		(PD_ZS_CHECK,	"...Waffenbasierte Kampftaktik!");
	var C_ITEM FFWaffe;

	if Npc_HasReadiedRangedWeapon (slf) // nur wenn er normalerweise eine Fernwaffe gezogen hat
	{
		FFWaffe = Npc_GetReadiedWeapon(slf);
	};

	if ( (FFWaffe.mainflag==ITEM_KAT_FF) && (FFWaffe.damageTotal <= oth.protection [PROT_POINT]) && (FFWaffe.damageTotal > 0) && Npc_HasEquippedMeleeWeapon(slf) && !Npc_IsPlayer(oth) )
	{
		AI_RemoveWeapon(slf);
	};

	if (
	((Npc_GetDistToNpc(slf,oth)<HAI_DIST_MELEE) && (slf.fight_tactic!=FAI_HUMAN_RANGED))
	|| ( FFWaffe.damageTotal <= oth.protection [PROT_POINT] && (FFWaffe.damageTotal > 0) && (Npc_HasEquippedMeleeWeapon(slf) || Npc_HasReadiedMeleeWeapon(slf)) && !Npc_IsPlayer(oth) ) 
	)
	{
		PrintDebugNpc			(PD_ZS_CHECK,	"...Gegner in Nahkampfreichweite & kein purer Fernkämpfer oder meine Fernkampfwaffe ist schwächer als die Rüstung des Gegners!");

catalinstoian avatar Feb 13 '21 14:02 catalinstoian

Thanks for the fix. I think I spot an issue there. FFWaffe is not assigned if the NPC does not have a range weapon equipped. In that case (thanks to Daedalus' workings) the variable will hold the one from a previous function call (say, a ranged weapon from the last NPC using that function). In that case the if condition may render different truth values, than expected. This could cause an NPC that has no ranged weapon to draw no weapon at all.

To fix this issue, FFWaffe would have to be checked against Hlp_IsValidItem in a separate if-block.

szapp avatar Feb 13 '21 20:02 szapp

I think the fix as provided could have intended side-effects. I want to put it back to the drawing board before I implement it. Diego's fight against the troll is based on the idea, that he does not make damage. With this fix, he would now suddenly draw his sword and kill of the troll - possibly before the player has a chance to (figure out how to) shrink the troll.

The if-condition clearly states that NPCs that are ranged fighters do not use their melee weapons. Usually, they will have a strong ranged weapon anyway.

I don't see why we should fix this bug (and potentially cause inconsistencies, problems in the story), before we have a valid example where this is bug arises and poses a severe issue.

szapp avatar Mar 29 '21 16:03 szapp

I don't see why we should fix this bug (and potentially cause inconsistencies, problems in the story), before we have a valid example where this is bug arises and poses a severe issue.

I agree. I'll remove it from the current milestones until we find out how this issue affects the gameplay negatively.

AmProsius avatar Mar 29 '21 18:03 AmProsius