Implementing flexible logic?

Blitz3D Forums/Blitz3D Programming/Implementing flexible logic?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You could maybe give each character parameters that indicate their mood, in this case something like 'agression'. The agression field would then be a percentage in the range 0..100, that can be fed into the attack routine.
;-----------------------------------------------------------------------
;                              HandleCharacter()
;-----------------------------------------------------------------------
Function HandleCharacter( c.Character )

  if GameTime > TooLong then ChangeAgression( c, 1 )

  chance = random(100)

  If (chance < c\Agression) then 
    c\state = "attack"
  else 
    c\state = "wait"
  endif

End Function

;-----------------------------------------------------------------------
;                              ChangeAgression()
;-----------------------------------------------------------------------
Function ChangeAgression( c.Character, amount )

   newAgression = (c\Agression + amount)
   if ValueWithinRange(newAgression, 20, 80) then c\Agression = newAgression

End Function

;-----------------------------------------------------------------------
;                              ValueWithinRange()
;-----------------------------------------------------------------------
Function ValueWithinRange(val, min, max)
  
   return ((val >= min) and (val <= max))

End Function