   weightning actions
  I have this problem in my game, let's say theres a bunch of gangstas and everyone shoots everyone, every actor in my game has a goal, now how can i make actors decide what action will overweight other?  Say some thug has a goal to kill player, but could kill his defenders in the meantime, or he is attacked by others, how can it know if he will not succesfuly defend against an attack - so in that case he would go kamikaze-style against the target (as he has nothing else to do)?    
Quote:Original post by DelfiI have this problem in my game, let's say theres a bunch of gangstas and everyone shoots everyone, every actor in my game has a goal, now how can i make actors decide what action will overweight other?  Say some thug has a goal to kill player, but could kill his defenders in the meantime, or he is attacked by others, how can it know if he will not succesfuly defend against an attack - so in that case he would go kamikaze-style against the target (as he has nothing else to do)?You get to decide whatever weights you want.You might want to attack the first person detected on their line-of-sight sweep, perhaps always attacking the first person to the left.If you find all the nearby people, you can collect a tiny bit of information on them and use it to figure out the best target:* You might want to attack the weakest player, since they're most likely to die.* You might want to attack the one most likely to kill you (strongest weapon, best aim, etc), if survival is a goal.* You might want to attack the person closest to you, so your aim will be better.* You might want to attack the first person they see with some arbitrary attribute (blue eyes, lowest ID number, shortest name coming from a string comparison, random number generator, etc).You might decide to add or multiply factors, such as:score = ( likelyhood to kill me * 5 ) + (their health * 2 ) + distancefrob.   ;This is one of the more difficult parts of game programming because it must be made to fit the game specifics (and of you change something significantly you need to rebalance this part).For each 'gangsta' you have a situation specific to itself and to that point in time (depending on what is happening around it).The 'gangsta' has its own internal state - it may behave differently if it is wounded versus if it un-injured (especially if it looses abilities with damage).The 'gangsta' may have different primary goals (from the plot) which will cause it to react to things and prioritize its actions differently.There are the other game objects which are the 'external' situation.  The type, states and position of those other objects determine what risk or reward they might present to the 'gangsta'  --  ammo is good,  a hitman from the crips is bad, a bystander is something different....What you do is figure out what reactions your 'gangsta' is to have depending on what a current situation is.   What actions are possible, and which should be done to gain the greatest payoff(advantage) for the least risk(cost).A simplistic approach would be to have on big list of if-then statements to test a situation, and have the first tests be the ones of highest priority (which if triggered cause immediate action).A (a little) more complicated approach would be to determine a bunch of 'states'each with its own if-then rules which apply specificly to that state..  If 'gangsta' is wounded (a state), then finding health boosts and avoiding more damage is more important than inflicting damage (and when health is restored, the 'gangsta' would be then in a different state and act by THAT state's rule priorities).A much more complicated system is to evaluate alot more and have 'weights' calculated for each option and then pick the best one  (highest payoff vs risk ratio).   You could have weights shift (a table)  for specific things depending on the 'gangstas' state, to compensate.All mentioned above works with a decision made from the current situation and by only what is seen at that point in time.   There is a whole area of AI called 'Planners' which plan out tasks ahead of time to try to solve a situation and more advanced versions take 'uncertainty' (what isnt seen or what hasnt happened yet) into account and try to predict best results.A basic process outline :#1  analyse the current situation and determine all the factors of significance (count all the other 'gangstas' seen and determine how far away they are and what weapons they have,    what powerups are accessable,   etc..)#2  scan all the factors/options and assign priority and potential actionThis may include aggregates like counting all the enemies to see if its too risky to stay (add a retreat option...).#3 select the best option#4 carry out the best option#5 back to #1