function onPlayerEnters() { scheduleevent(2 * this.aiPeriod, "AI"); // If they're asleep, wake them up! } function onAI() { if (players.size() <= 0) return; ai_execute(); cancelevents("AI"); scheduleevent(this.aiPeriod, "AI"); } function enterState(temp.state) { if (this.("ai_enter_"@ temp.state) != nil) this.("ai_enter_"@ temp.state)(); } function executeState(temp.state) { if (this.("ai_execute_"@ temp.state) != nil) this.("ai_execute_"@ temp.state)(); } function exitState(temp.state) { if (this.("ai_exit_"@ temp.state) != nil) this.("ai_exit_"@ temp.state)(); } function changeState(temp.state) { if (this.currentState == temp.state) return; this.exitState(this.currentState); this.previousState = this.currentState; this.currentState = temp.state; this.enterState(this.currentState); cancelevents("AI"); scheduleevent(this.aiPeriod, "AI"); } function ai_execute() { this.executeState(this.globalState); this.executeState(this.currentState); }