+void IdleState::Enter(AIController &ctrl, Entity &e) const {
+ e.GetSteering()
+ .SetAcceleration(0.5f)
+ .SetSpeed(0.01f)
+ .Enable(Steering::HALT)
+ .SetWanderParams(1.0f, 1.1f, 1.0f)
+ ;
+ ctrl.CueDecision(10.0f, 5.0f);
+}
+
+void IdleState::Update(AIController &ctrl, Entity &e, float) const {
+ if (ctrl.MayThink()) {
+ const Player *player = ctrl.ClosestVisiblePlayer(e);
+ if (player) {
+ e.GetSteering().SetTargetEntity(player->GetEntity());
+ ctrl.SetState(chase, e);
+ return;
+ }
+ }
+
+ if (!ctrl.DecisionDue()) return;
+
+ unsigned int d = ctrl.Decide(10);
+ if (d < 2) {
+ // .2 chance to start going
+ ctrl.SetState(roam, e);
+ } else if (d < 5) {
+ // .3 chance of looking around
+ e.GetSteering().Disable(Steering::HALT).Enable(Steering::WANDER);
+ } else {
+ // .5 chance of doing nothing
+ e.GetSteering().Disable(Steering::WANDER).Enable(Steering::HALT);
+ }
+ ctrl.CueDecision(10.0f, 5.0f);