Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOShipDebugInspectorModule.m
Go to the documentation of this file.
1/*
2
3OOShipDebugInspectorModule.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
34#import "ShipEntity.h"
35#import "OODebugInspector.h"
36#import "AI.h"
37#import "OORoleSet.h"
38#import "OOShipGroup.h"
39#import "OOConstToString.h"
40
41
42@interface ShipEntity (DebugRawAccess)
43
45
46@end
47
48
49@implementation OOShipDebugInspectorModule
50
51- (void) update
52{
53 ShipEntity *object = [self object];
54 NSString *primaryRole = [object primaryRole];
55 NSMutableSet *roles = nil;
56 NSString *placeholder = InspectorUnknownValueString();
57 AI *objAI = nil;
58 NSString *desc = nil;
59 float level;
60 int fuel;
61
62 roles = [[[[object roleSet] roles] mutableCopy] autorelease];
63 [roles removeObject:primaryRole];
64
65 [_primaryRoleField setStringValue:primaryRole ?: placeholder];
66 if ([roles count] != 0)
67 {
68 desc = [[[roles allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] componentsJoinedByString:@", "];
69 [_otherRolesField setStringValue:desc];
70 }
71 else
72 {
73 [_otherRolesField setStringValue:placeholder];
74 }
75 [_targetField setStringValue:[object inspTargetLine] ?: placeholder];
76 objAI = [object getAI];
77 if (objAI != nil)
78 {
79 desc = [objAI name];
80 if ([desc hasSuffix:@".plist"]) desc = [desc stringByDeletingPathExtension];
81 desc = [NSString stringWithFormat:@"%@: %@", desc, [objAI state]];
82 [_AIField setStringValue:desc];
83 }
84 else
85 {
86 [_AIField setStringValue:placeholder];
87 }
88 [_reportAIMessagesCheckBox setState:[object reportAIMessages]];
89 [_scriptField setStringValue:[[object script] name] ?: placeholder];
90
91 [_groupField setStringValue:[[object group] inspDescription] ?: placeholder];
92 [_escortGroupField setStringValue:[[object rawEscortGroup] inspDescription] ?: placeholder];
93
94 if (object != nil)
95 {
96 level = [object laserHeatLevel];
97 [_laserTempField setStringValue:[NSString stringWithFormat:@"%.2f", level]];
98 [_laserTempIndicator setFloatValue:level * 100.0];
99 level = [object hullHeatLevel];
100 [_cabinTempField setStringValue:[NSString stringWithFormat:@"%.2f", level]];
101 [_cabinTempIndicator setFloatValue:level * 100.0];
102 fuel = [object fuel];
103 [_fuelField setStringValue:[NSString stringWithFormat:@"%.1f", (float)fuel / 10.0f]];
104 [_fuelIndicator setIntValue:fuel];
105 }
106 else
107 {
108 [_laserTempField setStringValue:placeholder];
109 [_laserTempIndicator setFloatValue:0];
110 [_cabinTempField setStringValue:placeholder];
111 [_cabinTempIndicator setFloatValue:0];
112 [_fuelField setStringValue:placeholder];
113 [_fuelIndicator setFloatValue:0];
114 }
115}
116
117
118- (IBAction) inspectPlayer:sender
119{
120 [[self object] inspect];
121}
122
123
124- (IBAction) inspectTarget:sender
125{
126 [[[self object] primaryTarget] inspect];
127}
128
129
130- (IBAction) inspectAI:sender
131{
132 [[[self object] getAI] inspect];
133}
134
135
136- (IBAction) inspectGroup:sender
137{
138 [[[self object] group] inspect];
139}
140
141
142- (IBAction) inspectEscortGroup:sender
143{
144 [[[self object] rawEscortGroup] inspect];
145}
146
147
148- (IBAction) takeReportAIMessagesFrom:sender
149{
150 [[self object] setReportAIMessages:[(NSButton *)sender state]];
151}
152
153@end
154
155
156@implementation ShipEntity (OOShipDebugInspectorModule)
157
158- (NSArray *) debugInspectorModules
159{
160 return [[super debugInspectorModules] arrayByAddingInspectorModuleOfClass:[OOShipDebugInspectorModule class]
161 forObject:(id)self];
162}
163
164@end
NSString * InspectorUnknownValueString(void)
unsigned count
return nil
OOShipGroup * rawEscortGroup()
Definition AI.h:38
NSString * name()
Definition AI.m:364
NSString * state()
Definition AI.m:376
NSArray * debugInspectorModules()
NSString * name
Definition OOJSScript.h:37
NSSet * roles()
Definition OORoleSet.m:171
unsigned reportAIMessages
Definition ShipEntity.h:255
OORoleSet * roleSet
Definition ShipEntity.h:332
NSString * primaryRole
Definition ShipEntity.h:333
OOShipGroup * group()
OOFuelQuantity fuel
Definition ShipEntity.h:288
OOShipGroup * rawEscortGroup()
OOJSScript * script
Definition ShipEntity.h:222
GLfloat laserHeatLevel()
GLfloat hullHeatLevel()