*AlteOgre wrote:*

I propose a system where a number of factors determine the chance that an NPC will actually attack: motive, attack strength, vulnerability, numbers, aggressiveness ... maybe one more. All pretty straightforward logic and maths. These factors will also determine the criterium for a unit to fight to the death. I'll add the details later as I gtg now. :)

In addition to my earlier, brief, post, here's some further thoughts:

- A probability function will determine whether an NPC will attack a foe or not. If the calculated probability is low, the NPC may still attack, but the chance is just lower. A randomizer will determine whether or not the NPC actually attacks.

- There must always be a motive to attack. This factor is clearly dependent on faction background and eventual player alignment. NPC_Motive would be a parameter varying from 0 to 1. For NPCs the function is discrete: zero for allied or neutral foes, 1 for foes. For players, NPC_Motive will be a continuous function: 0 or lower for positive alignment values and between 0 and 1 for negative alignment values. The function can be asymptotic to 1.

- The relative attack strength (RAS) an NPC has and his relative vulnerability (RV) will be the most important factors determining the probability function. I propose to define these parameters like this: RAS = primary NPC weapon attack strength / target impact capacity & RV = target primary weapon attack strength / NPC impact capacity. The primary weapon of NPC and target can be defined as the weapon they either have in their hand or the strongest weapon they have in their main inventory slots. The attack strength can therefore vary between 1 and the (unechanted) maximum attack strength of any weapon in the mob (mithril crossbow iirc). The NPC or player impact capacity may be defined as the armour corrected health value of the subject. Simplified: impact capacity = actual (!) health value + armour points. Ideally, the actual damage protection value for armour will be used. The final parameter that will be used is the ratio between RAS and RV (= RS / RV), which will be the 'Relative Combat Strength' (RCS). This parameter, RCS, effectively is the ratio between actual attack and defensive capabilities of both NPC and its target. For equally strong units the resulting RCS will be 1, which will lead to a base attack probability of 50%. The lower the value of RCS, the lower the probability the NPC will attack its target. For low RCS values, approaching 0, the attach probability will approach 0. For high RCS values, between 1 and order-of-magnitude 100, the attach probability will approach 1. The continuous cumulative probability function that describes this behaviour is that of a log-normal distribution function.

- The ratio between friends and foes present in a potential combat situation is also of influence on the final decisive moment before an NPC chooses to flee or attack. Therefore there must also be an 'Supernumerary Factor' (SF), which is a multiplier dependent on the number of friendly units and the number of foes in the vicinity of the NPC (eventually also taking into account all RCS values ...?). With only one NPC and one target in the area, SF is equal to 1. When the NPC is outnumbered SF is below 1, and the probability is simply multiplied with SF. When the NPC feels he has the upperhand because of the presence of more friends, the SF is higher than 1, and the probability will be increased. A power law function with the probability as base and the SF in the power, seems a possible way to effectuate this parameter. It may prove to be difficult to determine the 'actual numbers', but given the recently announced new method for NPC to determine which foe to attack, my guess is that Mevans already has useful tools available to define a practicable way to calculate the SF.

- Finally, the aggressiveness is a faction/race/unit dependent multiplier that will either reduce or increase the probability of attack. This parameter will therefore be NPC type dependent and vary between 0 (guaranteed to flee!) and some positive number (depends on the probability funcion used). Like the Supernumerary Factor, the NPCs Aggressiveness can be used in some power law function of the probability. Low Aggressiveness reduces the probability and higher Aggressiveness increases the probability. I prefer there will be no guaranteed attack: very high Aggressiveness (Wargs, Spiders, Berserkers ...) will lead to very high probability of attack, but any outnumbered or underpowered creature will have a chance that it/he realizes an attack is futile and fleeing is the best option.

So ... that's a lot to figure out, code and tune ... but the result may be quite spectacular and game-changingly realistic. Simplification is possible, in many ways, fortunately. :)

Finally, also consider this:

If an NPC decides not to attack, he must retreat to safe distance. After some time, he will have to re-consider his decision, if the foe approaches again, or as soon as new foes show up. The logic that will govern this NPC decision making is also needed for the earlier proposal on NPC functionality that will govern their behaviour when they are seriously hurt (life threatening low health level) and when they find they cannot hurt their target.

*Edit: Sorry, forgot to mention the factor 'Menace', which would also be alignment dependent and basically be the parameter currently used to determine when an NPC attacks or flees: the more negative the alignment, the higher the probability an NPC will no attack.*