1 year since early access and spearmen still don't use spears by default, it's disrupting a number of mods

Users who are viewing this thread

Oh I forgot to tell people that they can get this behaviour back :grin:

Just go to config and chnage
<OneHandedThrustBonus>3.34</OneHandedThrustBonus>
<TwoHandedThrustBonus>3.34</TwoHandedThrustBonus>
<ThrustModifier>0.3</ThrustModifier>
into
<OneHandedThrustBonus>1</OneHandedThrustBonus>
<TwoHandedThrustBonus>1</TwoHandedThrustBonus>
<ThrustModifier>1</ThrustModifier>

However cav is going to spam lances at point blank range vs other cav if you revert back.

As for realism in spearman behaviour, spearman should switch to secondary weapons once enemy gets close enough because sword and co are much batter at point blank range (IRL, in RBM we buff spears to the point where they are viable in point blank range), problem is that this would take total of 1 second in bannerlord, however it would be interesting if second rank kept using polearms while first rank switched to shorter weapons.
Hmm... Then why isn't this part of RBM, may I ask?
 
Hmm... Then why isn't this part of RBM, may I ask?
It is, just go to config file of combat module and change 3 values. I reverted back to more vanilla behaviour in RBM because cavlary was poking each other with lances at point blank range even though they had axes and maces available and because infantry was preferring spears over heavy axes (and sometimes over maces too) when they were fighting heavily armored enemies. Also RBM unit overhaul uses lots of always spear soldiers in tier 4 and lower so you can have spear experience anyway, tier 5 is supposed to be anti heavy.
 
Though not ideal, that's great! I'll let the phalanx modders know how to do this.

EDIT: Wait, but will the spearmen switch to their sidearms when enemies get close? Because that is also a goal of the phalanx modders.
 
Last edited:
Though not ideal, that's great! I'll let the phalanx modders know how to do this.

EDIT: Wait, but will the spearmen switch to their sidearms when enemies get close? Because that is also a goal of the phalanx modders.
No. That behaviour is in the engine. I can imagine that weapon switching would be doable for entire formation by this method at least to some degree, but guys in front switching to swords from pikes while being part of the same formation like rest of the pikeman is not possible to my knowledge.

Essentially you need to either increase or reduce "percieved" damage of the weapon to manipulate the behaviour. For example if polearm has same damage as other melee weapons it is preferred. If it has only 30-50% of damage in comparison, other melee weapons are preferred. When I talk about damage I mean the damage that is written in inventory, that is what the game cares about when deciding weapon. This weapon damage can be modified either by modyfying craftingpieces (in xml) or by modifying formula for thrust and swing. However final damage can be then modified again when armor penetration (or later stage) is calculated, these changes to damage are not shown in inventory / game encyclopedia and are not considered by AI. So technically you could press button (command) to lets say double thrust damage and reduce final damage by 50% in order to get same damage but different behaviour.

As example you can look at the code of combat module on our github. We increased damage in xml to achieve 80-120 damage with spears (same was done for other 1h weapons), then we reduced thrust damage calculation to 30% and then we multiplied final damage by 3.34 to achieve same damage with "swingy" weapon preference.
[HarmonyPatch(typeof(CombatStatCalculator))]
[HarmonyPatch("CalculateStrikeMagnitudeForThrust")]
class CalculateStrikeMagnitudeForThrustPatch
{
static bool Prefix(float thrustWeaponSpeed, float weaponWeight, float extraLinearSpeed, bool isThrown, ref float __result)
{
float combinedSpeed = thrustWeaponSpeed + extraLinearSpeed;
if (combinedSpeed > 0f)
{
if (!isThrown)
{
weaponWeight += 2.5f;
}
float kineticEnergy = 0.5f * weaponWeight * combinedSpeed * combinedSpeed;
float handLimit = 0.5f * weaponWeight * thrustWeaponSpeed * thrustWeaponSpeed * 1.5f;
if (kineticEnergy > handLimit)
{
kineticEnergy = handLimit;
}
__result = 0.125f * kineticEnergy * XmlConfig.dict["Global.ThrustModifier"];
return false;
}
__result = 0f;
return false;
}
}

private static float MyComputeDamage(string weaponType, DamageTypes damageType, float magnitude, float armorEffectiveness, float absorbedDamageRatio, BasicCharacterObject player = null, bool isPlayerVictim = false)
{

float damage = 0f;
float armorReduction = 100f / (100f + armorEffectiveness * XmlConfig.dict["Global.ArmorMultiplier"]);
float mag_1h_thrust;
float mag_2h_thrust;
float mag_1h_sword_thrust;
float mag_2h_sword_thrust;

if (damageType == DamageTypes.Pierce)
{
mag_1h_thrust = magnitude * XmlConfig.dict["Global.OneHandedThrustBonus"];
mag_2h_thrust = magnitude * XmlConfig.dict["Global.TwoHandedThrustBonus"];
mag_1h_sword_thrust = magnitude * 1.15f * XmlConfig.dict["Global.OneHandedThrustBonus"];
mag_2h_sword_thrust = magnitude * 2.0f * XmlConfig.dict["Global.TwoHandedThrustBonus"];
}
else if (damageType == DamageTypes.Cut)
{
mag_1h_thrust = magnitude;
mag_2h_thrust = magnitude;
mag_1h_sword_thrust = magnitude * 1.35f;
mag_2h_sword_thrust = magnitude * 1.07f;
}
else
{
mag_1h_thrust = magnitude;
mag_2h_thrust = magnitude;
mag_1h_sword_thrust = magnitude;
mag_2h_sword_thrust = magnitude;
}

switch (weaponType)
{
case "OneHandedPolearm":
{
damage = weaponTypeDamage(XmlConfig.dict[weaponType + ".ExtraBluntFactorCut"], XmlConfig.dict[weaponType + ".ExtraBluntFactorPierce"], mag_1h_thrust, armorReduction, damageType, armorEffectiveness,
XmlConfig.dict[weaponType + ".ExtraArmorThresholdFactorCut"], XmlConfig.dict[weaponType + ".ExtraArmorThresholdFactorPierce"], player, isPlayerVictim);
break;
}
case "TwoHandedPolearm":
{
damage = weaponTypeDamage(XmlConfig.dict[weaponType + ".ExtraBluntFactorCut"], XmlConfig.dict[weaponType + ".ExtraBluntFactorPierce"], mag_2h_thrust, armorReduction, damageType, armorEffectiveness,
XmlConfig.dict[weaponType + ".ExtraArmorThresholdFactorCut"], XmlConfig.dict[weaponType + ".ExtraArmorThresholdFactorPierce"], player, isPlayerVictim);
break;
}
default:
{
damage = weaponTypeDamage(1f, 1f, magnitude, armorReduction, damageType, armorEffectiveness, 1f, 1f, player, isPlayerVictim);
break;
}
}

return damage * absorbedDamageRatio;
}

From Xmls:
<OneHandedThrustBonus>3.34</OneHandedThrustBonus>
<TwoHandedThrustBonus>3.34</TwoHandedThrustBonus>
<ThrustModifier>0.3</ThrustModifier>
 
Last edited:
Oh I forgot to tell people that they can get this behaviour back :grin:

Just go to config and chnage
<OneHandedThrustBonus>3.34</OneHandedThrustBonus>
<TwoHandedThrustBonus>3.34</TwoHandedThrustBonus>
<ThrustModifier>0.3</ThrustModifier>
into
<OneHandedThrustBonus>1</OneHandedThrustBonus>
<TwoHandedThrustBonus>1</TwoHandedThrustBonus>
<ThrustModifier>1</ThrustModifier>

However cav is going to spam lances at point blank range vs other cav if you revert back.

As for realism in spearman behaviour, spearman should switch to secondary weapons once enemy gets close enough because sword and co are much batter at point blank range (IRL, in RBM we buff spears to the point where they are viable in point blank range), problem is that this would take total of 1 second in bannerlord, however it would be interesting if second rank kept using polearms while first rank switched to shorter weapons.
I just tried this out and it was great. Is it possible to affect only infantry?

I can code behavior to make spearmen drop their spears when enemies get within a certain distance. That would fulfill the goal of having them switch to their sidearms to fight enemies that are very close.
 
I just tried this out and it was great. Is it possible to affect only infantry?

I can code behavior to make spearmen drop their spears when enemies get within a certain distance. That would fulfill the goal of having them switch to their sidearms to fight enemies that are very close.
They dont have to drop the weapons, they can just get damage nerf to the point of swapping them. As for infantry only, possibly, we did not experiment with this specific thing yet but we did some unit specific things like different behaviour for 2H polearm units. I recommend checking our github on the mod page (signature) for other features that might be interesting to you. Also I am not the main coder so my understanding of our code is mostly basic.
 
There's another way to make AI to use Spear.

1st point is what Philozoraptor mentioned. AI decides to use spear if its damage is way way better than the side weapon.

2nd point is Shieldwall. If the damage/speed of spear and sword/side weapon is just enough, AI will use side weapon as default weapon. For more detail.

Line formation: AI will use side weapon (default)
Shieldwall formation: AI will use spear
Charge: AI will use/switch to side weapon
Advance while on shieldwall formation: AI will advance while using spear

I recorded a demo for you guys. Here's the link:

Items used for this demo:
<equipment slot="Item0" id="Item.empire_sword_1_t2" />
<equipment slot="Item1" id="Item.southern_spear_3_t4" />
<equipment slot="Item2" id="Item.ironrim_kite_shield" />

Weapon stats used here are all native.

Note: Since AI only use spears on shieldwall, thats why I'm bugging Philozoraptor on his Improve Spear Performance mod.
 
So if you coders can get the logic from "Shieldwall Formation" why it uses spear if it has better stats, maybe you can apply that logic to other action (ex: spread, square, circle formation). Or lower the parameter of when Shieldwall formation use spears.
 
Back
Top Bottom