Oolite 1.91.0.7604-240417-a536cbe
Loading...
Searching...
No Matches
OOAIDebugInspectorModule.m
Go to the documentation of this file.
1/*
2
3OOAIDebugInspectorModule.m
4
5
6Oolite Debug Bundle
7
8Copyright © 2007-2013 Jens Ayton
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the “Software”), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27
28*/
29
31#import "AI.h"
32#import "ShipEntity.h"
33#import "Universe.h"
35#import "OOConstToString.h"
36
37
38@implementation OOAIDebugInspectorModule
39
40- (void) update
41{
42 AI *object = [self object];
43 NSString *placeholder = InspectorUnknownValueString();
44 NSSet *pending = nil;
45 NSString *pendingDesc = nil;
46
47 [_stateMachineNameField setStringValue:[object name] ?: placeholder];
48 [_stateField setStringValue:[object state] ?: placeholder];
49 if (object != nil)
50 {
51 [_stackDepthField setIntegerValue:[object stackDepth]];
52 [_timeToThinkField setStringValue:[NSString stringWithFormat:@"%.1f", [object nextThinkTime] - [UNIVERSE getTime]]];
53 [_behaviourField setStringValue:OOStringFromBehaviour([[object owner] behaviour])];
54 [_frustrationField setDoubleValue:[[object owner] frustration]];
55 }
56 else
57 {
58 [_stackDepthField setStringValue:placeholder];
59 [_timeToThinkField setStringValue:placeholder];
60 [_behaviourField setStringValue:placeholder];
61 [_frustrationField setStringValue:placeholder];
62 }
63
64 pending = [object pendingMessages];
65 if ([pending count] == 0)
66 {
67 pendingDesc = @"none";
68 }
69 else
70 {
71 pendingDesc = [[[pending allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] componentsJoinedByString:@", "];
72 pendingDesc = [NSString stringWithFormat:@"%lu: %@", [pending count], pendingDesc];
73 }
74
75 [_pendingMessagesField setStringValue:pendingDesc];
76}
77
78
79- (IBAction) thinkNow:sender
80{
81 [[self object] setNextThinkTime:[UNIVERSE getTime]];
82}
83
84
85- (IBAction) dumpPendingMessages:sender
86{
87 [[self object] debugDumpPendingMessages];
88}
89
90@end
91
92
93@implementation AI (OOAIDebugInspectorModule)
94
95- (NSString *) inspBasicIdentityLine
96{
97 if ([self owner] != nil) return [NSString stringWithFormat:@"AI for %@", [[self owner] inspBasicIdentityLine]];
98 return [super inspBasicIdentityLine];
99}
100
101
102- (NSArray *) debugInspectorModules
103{
104 return [[super debugInspectorModules] arrayByAddingInspectorModuleOfClass:[OOAIDebugInspectorModule class]
105 forObject:(id)self];
106}
107
108@end
NSString * InspectorUnknownValueString(void)
unsigned count
return nil
Definition AI.h:38
NSUInteger stackDepth()
Definition AI.m:382
NSMutableSet * pendingMessages
Definition AI.h:46
NSString * name()
Definition AI.m:364
ShipEntity * owner()
Definition AI.m:184
OOTimeAbsolute nextThinkTime
Definition AI.h:50
NSString * state()
Definition AI.m:376
NSString * inspBasicIdentityLine()
GLfloat frustration
Definition ShipEntity.h:348
OOBehaviour behaviour
Definition ShipEntity.h:211