From ede06c1a28e9cf8009171696dcec3272a68b05ef Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sun, 15 Jun 2014 22:22:17 -0700 Subject: [PATCH] Working on AI behaviors --- moonlight/js/moonlight-skulk.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/moonlight/js/moonlight-skulk.js b/moonlight/js/moonlight-skulk.js index 79e0cb5..75177b0 100644 --- a/moonlight/js/moonlight-skulk.js +++ b/moonlight/js/moonlight-skulk.js @@ -923,14 +923,13 @@ var AISprite = function(game, x, y, key, frame) { } } - if ( hasState(this, STATE_ALERTED) ) { if ( this.sprite_group == "townsfolk-guard" ) { this.action_chaseplayer(); } else { this.action_reportplayer(); } - } else if ( hasState(this, (STATE_CONCERNED | STATE_LOSTHIM)) ) { + } else if ( hasAnyState(this, [STATE_CONCERNED, STATE_LOSTHIM]) ) { this.action_huntplayer(); } else { this.action_wander(); @@ -1199,6 +1198,16 @@ function exchangeState(spr, state1, state2) addState(spr, state2); } +function hasAnyState(spr, states) +{ + var hasstate = false; + states.forEach(function(x) { + if ( hasState(spr, x) ) + hasstate = true; + }, this); + return hasstate; +} + function hasState(spr, state) { if ( (spr.state & state) == state )