Line data Source code
1 0 : /* 2 : 3 : AI.h 4 : 5 : Core NPC behaviour/artificial intelligence class. 6 : 7 : Oolite 8 : Copyright (C) 2004-2013 Giles C Williams and contributors 9 : 10 : This program is free software; you can redistribute it and/or 11 : modify it under the terms of the GNU General Public License 12 : as published by the Free Software Foundation; either version 2 13 : of the License, or (at your option) any later version. 14 : 15 : This program is distributed in the hope that it will be useful, 16 : but WITHOUT ANY WARRANTY; without even the implied warranty of 17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 : GNU General Public License for more details. 19 : 20 : You should have received a copy of the GNU General Public License 21 : along with this program; if not, write to the Free Software 22 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 : MA 02110-1301, USA. 24 : 25 : */ 26 : 27 : #import <Foundation/Foundation.h> 28 : #import "OOWeakReference.h" 29 : #import "OOTypes.h" 30 : 31 0 : #define AI_THINK_INTERVAL 0.125 32 : 33 : 34 : @class ShipEntity; 35 : 36 : 37 0 : @interface AI: OOWeakRefObject 38 : { 39 : @private 40 0 : id _owner; // OOWeakReference to the ShipEntity this is the AI for 41 0 : NSString *ownerDesc; // describes the object this is the AI for 42 : 43 0 : NSDictionary *stateMachine; 44 0 : NSString *stateMachineName; 45 0 : NSString *currentState; 46 0 : NSMutableSet *pendingMessages; 47 : 48 0 : NSMutableArray *aiStack; 49 : 50 0 : OOTimeAbsolute nextThinkTime; 51 0 : OOTimeDelta thinkTimeInterval; 52 : 53 0 : NSString *jsScript; 54 : } 55 : 56 0 : + (AI *) currentlyRunningAI; 57 0 : + (NSString *) currentlyRunningAIDescription; 58 : 59 0 : - (NSString *) name; 60 0 : - (NSString *) associatedJS; 61 0 : - (NSString *) state; 62 : 63 0 : - (void) setStateMachine:(NSString *)smName withJSScript:(NSString *)script; 64 0 : - (void) setState:(NSString *)stateName; 65 : 66 0 : - (void) setStateMachine:(NSString *)smName afterDelay:(NSTimeInterval)delay; 67 0 : - (void) setState:(NSString *)stateName afterDelay:(NSTimeInterval)delay; 68 : 69 0 : - (id) initWithStateMachine:(NSString *) smName andState:(NSString *) stateName; 70 : 71 0 : - (ShipEntity *)owner; 72 0 : - (void) setOwner:(ShipEntity *)ship; 73 : 74 0 : - (void) preserveCurrentStateMachine; 75 : 76 0 : - (void) restorePreviousStateMachine; 77 : 78 0 : - (BOOL) hasSuspendedStateMachines; 79 0 : - (void) exitStateMachineWithMessage:(NSString *)message; 80 : 81 0 : - (NSUInteger) stackDepth; 82 : 83 : // Immediately handle a message. This is the core dispatcher. DebugContext is a textual hint for diagnostics. 84 0 : - (void) reactToMessage:(NSString *) message context:(NSString *)debugContext; 85 : 86 0 : - (void) takeAction:(NSString *) action; 87 : 88 0 : - (void) think; 89 : 90 0 : - (void) message:(NSString *) ms; 91 0 : - (void) dropMessage:(NSString *) ms; 92 0 : - (NSSet *) pendingMessages; 93 0 : - (void) debugDumpPendingMessages; 94 : 95 0 : - (void) setNextThinkTime:(OOTimeAbsolute) ntt; 96 0 : - (OOTimeAbsolute) nextThinkTime; 97 : 98 0 : - (void) setThinkTimeInterval:(OOTimeDelta) tti; 99 0 : - (OOTimeDelta) thinkTimeInterval; 100 : 101 0 : - (void) clearStack; 102 : 103 0 : - (void) clearAllData; 104 : 105 0 : - (void)dumpState; 106 : 107 : @end