Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOConstToString.m
Go to the documentation of this file.
1/*
2
3OOConstToString.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version );
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., ); Franklin Street, Fifth Floor, Boston,
21MA );-);, USA.
22
23*/
24
25#import "OOConstToString.h"
26#include <jsapi.h>
28
29#import "Universe.h"
30#import "PlayerEntity.h"
31#import "OOEquipmentType.h"
32
33#define CASE(foo) case foo: return @#foo;
34#define REVERSE_CASE(foo) if ([string isEqualToString:@#foo]) return foo;
35
36
37#define ENTRY(label, value) case label: return @#label;
38#define GALACTIC_HYPERSPACE_ENTRY(label, value) case GALACTIC_HYPERSPACE_##label: return @#label;
39#define DIFF_STRING_ENTRY(label, string) case label: return @string;
40
42{
43 switch (value)
44 {
45 #include "OOEntityStatus.tbl"
46 }
47 return @"UNDEFINED";
48}
49
50
52{
53 switch (value)
54 {
55 #include "OOBehaviour.tbl"
56 }
57
58 return @"** BEHAVIOUR UNKNOWN **";
59}
60
61
63{
64 switch (value)
65 {
66 #include "OOCompassMode.tbl"
67 }
68
69 return @"UNDEFINED";
70}
71
73{
74 switch (value)
75 {
76 #include "OOLongRangeChartMode.tbl"
77 }
78
79 return @"UNDEFINED";
80}
81
83{
84 switch (value)
85 {
86 #include "OOGalacticHyperspaceBehaviour.tbl"
87 }
88
89 return @"UNDEFINED";
90}
91
92
94{
95 switch (value)
96 {
97 #include "OOGUIScreenID.tbl"
98 }
99
100 return @"UNDEFINED";
101}
102
103
105{
106 switch (value)
107 {
108 #include "OOScanClass.tbl"
109 }
110
111 return @"UNDEFINED";
112}
113
114
116{
117 switch (value)
118 {
119 #include "OOShipDamageType.tbl"
120 }
121
122 return @"UNDEFINED";
123}
124
126{
127 switch (value)
128 {
129 #include "OOLegalStatusReason.tbl"
130 }
131
132 return @"UNDEFINED";
133}
134
135
136#undef ENTRY
137#undef GALACTIC_HYPERSPACE_ENTRY
138
139
140#define ENTRY(label, value) if ([string isEqualToString:@#label]) return label;
141#define GALACTIC_HYPERSPACE_ENTRY(label, value) if ([string isEqualToString:@#label]) return GALACTIC_HYPERSPACE_##label;
142
144{
145 #include "OOEntityStatus.tbl"
146
148}
149
150
152{
153 #include "OOCompassMode.tbl"
154
156}
157
158
160{
161 #include "OOGalacticHyperspaceBehaviour.tbl"
162
163 // Transparently (but inefficiently) support american spelling. FIXME: remove in EMMSTRAN.
164 if ([string hasPrefix:@"BEHAVIOR_"])
165 {
166 string = [string substringFromIndex:[@"BEHAVIOR_" length]];
167 string = [@"BEHAVIOUR_" stringByAppendingString:string];
169 }
170
172}
173
174
176{
177 #include "OOGUIScreenID.tbl"
178
180}
181
182
184{
185 #include "OOScanClass.tbl"
186
187 return kOOScanClassDefault;
188}
189
191{
192 #include "OOLongRangeChartMode.tbl"
193
195}
196
197#undef ENTRY
198#undef GALACTIC_HYPERSPACE_ENTRY
199
200
201NSString *RouteTypeToString(OORouteType routeType)
202{
203 switch (routeType)
204 {
208 }
209
210 return @"** ROUTE TYPE UNKNOWN **";
211}
212
213
215{
216 NSArray *strings = nil;
217 NSString *value = nil;
218
219 strings = [[UNIVERSE descriptions] objectForKey:@"government"];
220 if ([strings isKindOfClass:[NSArray class]] && government < [strings count])
221 {
222 value = [strings objectAtIndex:government];
223 if ([value isKindOfClass:[NSString class]]) return value;
224 }
225
226 return nil;
227}
228
229
231{
232 NSArray *strings = nil;
233 NSString *value = nil;
234
235 strings = [[UNIVERSE descriptions] objectForKey:@"economy"];
236 if ([strings isKindOfClass:[NSArray class]] && economy < [strings count])
237 {
238 value = [strings objectAtIndex:economy];
239 if ([value isKindOfClass:[NSString class]]) return value;
240 }
241
242 return nil;
243}
244
245
246NSString *JSTypeToString(int /* JSType */ type)
247{
248 switch ((JSType)type)
249 {
250 CASE(JSTYPE_VOID);
251 CASE(JSTYPE_OBJECT);
252 CASE(JSTYPE_FUNCTION);
253 CASE(JSTYPE_STRING);
254 CASE(JSTYPE_NUMBER);
255 CASE(JSTYPE_BOOLEAN);
256 CASE(JSTYPE_NULL);
257 CASE(JSTYPE_XML);
258 CASE(JSTYPE_LIMIT);
259 }
260 return [NSString stringWithFormat:@"unknown (%u)", type];
261}
262
263
265{
266 if (weapon == nil) {
267 return @"EQ_WEAPON_NONE";
268 } else {
269 return [weapon identifier];
270 }
271}
272
273
278
279
281{
282 return [weapon identifier];
283}
284
285
287{
289 if (w == nil)
290 {
291 if (![string hasPrefix:@"EQ_"])
292 {
293 w = [OOEquipmentType equipmentTypeWithIdentifier:[NSString stringWithFormat:@"EQ_%@",string]];
294 if (w != nil)
295 {
296 return w;
297 }
298 }
299 return [OOEquipmentType equipmentTypeWithIdentifier:@"EQ_WEAPON_NONE"];
300 }
301 return w;
302}
303
304
305/* Previous save games will have weapon types stored as ints to the
306 * various weapon types */
308{
309 if ([string intValue] > 0)
310 {
311 switch ([string intValue])
312 {
313 case 2:
314 return OOWeaponTypeFromEquipmentIdentifierSloppy(@"EQ_WEAPON_PULSE_LASER");
315 case 3:
316 return OOWeaponTypeFromEquipmentIdentifierSloppy(@"EQ_WEAPON_BEAM_LASER");
317 case 4:
318 return OOWeaponTypeFromEquipmentIdentifierSloppy(@"EQ_WEAPON_MINING_LASER");
319 case 5:
320 return OOWeaponTypeFromEquipmentIdentifierSloppy(@"EQ_WEAPON_MILITARY_LASER");
321 case 10:
322 return OOWeaponTypeFromEquipmentIdentifierSloppy(@"EQ_WEAPON_THARGOID_LASER");
323 default:
325 }
326 }
328}
329
330
332{
333 // there is no difference between the two any more
335}
336
337
339{
340 switch (cargo)
341 {
350 }
351 return @"Unknown cargo";
352}
353
354
356{
365
366 // Backwards compatibility.
367 if ([string isEqual:@"CARGO_CARRIED"]) return CARGO_RANDOM;
368
369 return kOOCargoTypeDefault;
370}
371
372
374{
375 switch (unit)
376 {
382
385 break;
386 }
387
388 return @"Unsupported energy unit";
389}
390
391
402
403
404NSString *OODisplayRatingStringFromKillCount(unsigned kills)
405{
406 enum { kRatingCount = 9 };
407
408 NSArray *ratingNames = nil;
409 const unsigned killThresholds[kRatingCount - 1] =
410 {
411 0x0008,
412 0x0010,
413 0x0020,
414 0x0040,
415 0x0080,
416 0x0200,
417 0x0A00,
418 0x1900
419 };
420 unsigned i;
421
422 ratingNames = [[UNIVERSE descriptions] oo_arrayForKey:@"rating"];
423 for (i = 0; i < kRatingCount - 1; ++i)
424 {
425 if (kills < killThresholds[i]) return [ratingNames oo_stringAtIndex:i];
426 }
427
428 return [ratingNames oo_stringAtIndex:kRatingCount - 1];
429}
430
431
432NSString *KillCountToRatingAndKillString(unsigned kills)
433{
434 return [NSString stringWithFormat:@"%@ (%u)", OODisplayRatingStringFromKillCount(kills), kills];
435}
436
437
438NSString *OODisplayStringFromLegalStatus(int legalStatus)
439{
440 enum { kStatusCount = 3 };
441
442 NSArray *statusNames = nil;
443 const int statusThresholds[kStatusCount - 1] =
444 {
445 1,
446 51
447 };
448 unsigned i;
449
450 statusNames = [[UNIVERSE descriptions] oo_arrayForKey:@"legal_status"];
451 for (i = 0; i != kStatusCount - 1; ++i)
452 {
453 if (legalStatus < statusThresholds[i]) return [statusNames oo_stringAtIndex:i];
454 }
455
456 return [statusNames oo_stringAtIndex:kStatusCount - 1];
457}
458
459
461{
462 NSArray *conditionNames = [[UNIVERSE descriptions] oo_arrayForKey:@"condition"];
463 return [conditionNames oo_stringAtIndex:alertCondition];
464}
465
466
468{
469 switch (setting)
470 {
471 case SHADERS_NOT_SUPPORTED: return DESC(@"shaderfx-not-available");
472 case SHADERS_OFF: return DESC(@"shaderfx-off");
473 case SHADERS_SIMPLE: return DESC(@"shaderfx-simple");
474 case SHADERS_FULL: return DESC(@"shaderfx-full");
475 }
476
477 return @"??";
478}
479
480
482{
483 switch (setting)
484 {
489 }
490
491 return @"UNDEFINED";
492}
493
494
504
505
506NSString *CommodityDisplayNameForSymbolicName(NSString *symbolicName)
507{
508 NSString *ret = [UNIVERSE descriptionForKey:[@"commodity-name " stringByAppendingString:[symbolicName lowercaseString]]];
509 return ret ? ret : symbolicName;
510}
511
512
513NSString *CommodityDisplayNameForCommodityArray(NSArray *commodityDefinition)
514{
515 return CommodityDisplayNameForSymbolicName([commodityDefinition oo_stringAtIndex:MARKET_NAME]);
516}
517
518
520{
521 switch (unit)
522 {
523 case UNITS_TONS: return DESC(@"cargo-tons-symbol");
524 case UNITS_KILOGRAMS: return DESC(@"cargo-kilograms-symbol");
525 case UNITS_GRAMS: return DESC(@"cargo-grams-symbol");
526 }
527
528 return @"??";
529}
530
531
533{
534 return DisplayStringForMassUnit([[UNIVERSE commodityMarket] massUnitForGood:commodity]);
535}
536
537
546
547
549{
550 switch (dockingClearanceStatus)
551 {
557 }
558
559 return @"DOCKING_CLEARANCE_STATUS_UNKNOWN";
560}
561
562
564{
565 switch (detail)
566 {
571 }
572
573 return @"DETAIL_LEVEL_UNKNOWN";
574}
575
576
OOEntityStatus
Definition Entity.h:60
@ kOOScanClassDefault
Definition Entity.h:326
@ kOOEntityStatusDefault
Definition Entity.h:325
OOScanClass
Definition Entity.h:71
@ kOOCargoTypeDefault
@ kOORouteTypeDefault
@ kOOEnergyUnitTypeDefault
OOWeaponType OOWeaponTypeFromEquipmentIdentifierStrict(NSString *string)
NSString * OOStringFromGraphicsDetail(OOGraphicsDetail detail)
#define CASE(foo)
OOWeaponType OOWeaponTypeFromString(NSString *string)
NSString * OOStringFromBehaviour(OOBehaviour value)
OOEnergyUnitType StringToEnergyUnitType(NSString *string)
NSString * CargoTypeToString(OOCargoType cargo)
NSString * OOStringFromLongRangeChartMode(OOLongRangeChartMode value)
NSString * OODisplayStringFromEconomyID(OOEconomyID economy)
OOWeaponType OOWeaponTypeFromEquipmentIdentifierLegacy(NSString *string)
OOGalacticHyperspaceBehaviour OOGalacticHyperspaceBehaviourFromString(NSString *string)
OOWeaponType OOWeaponTypeFromEquipmentIdentifierSloppy(NSString *string)
NSString * OOStringFromWeaponType(OOWeaponType weapon)
NSString * CommodityDisplayNameForSymbolicName(NSString *symbolicName)
NSString * DisplayStringForMassUnit(OOMassUnit unit)
OORouteType StringToRouteType(NSString *string)
OOShaderSetting OOShaderSettingFromString(NSString *string)
NSString * OOStringFromGUIScreenID(OOGUIScreenID value)
OOCargoType StringToCargoType(NSString *string)
NSString * OOEquipmentIdentifierFromWeaponType(OOWeaponType weapon)
#define REVERSE_CASE(foo)
NSString * OODisplayStringFromGovernmentID(OOGovernmentID government)
NSString * RouteTypeToString(OORouteType routeType)
OOScanClass OOScanClassFromString(NSString *string)
OOCompassMode OOCompassModeFromString(NSString *string)
NSString * OOStringFromEntityStatus(OOEntityStatus value)
OOEntityStatus OOEntityStatusFromString(NSString *string)
NSString * JSTypeToString(int type)
NSString * DockingClearanceStatusToString(OODockingClearanceStatus dockingClearanceStatus)
NSString * OOStringFromCompassMode(OOCompassMode value)
NSString * OOStringFromGalacticHyperspaceBehaviour(OOGalacticHyperspaceBehaviour value)
NSString * OODisplayRatingStringFromKillCount(unsigned kills)
NSString * OOStringFromShaderSetting(OOShaderSetting setting)
NSString * OOStringFromShipDamageType(OOShipDamageType value)
NSString * OODisplayStringFromAlertCondition(OOAlertCondition alertCondition)
NSString * OODisplayStringFromLegalStatus(int legalStatus)
OOGUIScreenID OOGUIScreenIDFromString(NSString *string)
NSString * EnergyUnitTypeToString(OOEnergyUnitType unit)
NSString * KillCountToRatingAndKillString(unsigned kills)
NSString * DisplayStringForMassUnitForCommodity(OOCommodityType commodity)
OOGraphicsDetail OOGraphicsDetailFromString(NSString *string)
NSString * OOStringFromLegalStatusReason(OOLegalStatusReason value)
NSString * CommodityDisplayNameForCommodityArray(NSArray *commodityDefinition)
NSString * OOStringFromScanClass(OOScanClass value)
NSString * OODisplayStringFromShaderSetting(OOShaderSetting setting)
OOLongRangeChartMode OOLongRangeChartModeFromString(NSString *string)
OOShaderSetting
Definition OOOpenGL.h:35
@ SHADERS_FULL
Definition OOOpenGL.h:40
@ SHADERS_SIMPLE
Definition OOOpenGL.h:39
@ SHADERS_OFF
Definition OOOpenGL.h:38
@ SHADERS_NOT_SUPPORTED
Definition OOOpenGL.h:37
@ kOOShaderSettingDefault
Definition OOOpenGL.h:261
unsigned count
return nil
OOLongRangeChartMode
Definition OOTypes.h:50
@ kOOLongRangeChartModeDefault
Definition OOTypes.h:53
NSString * OOCommodityType
Definition OOTypes.h:106
OORouteType
Definition OOTypes.h:33
@ OPTIMIZED_BY_NONE
Definition OOTypes.h:34
@ OPTIMIZED_BY_JUMPS
Definition OOTypes.h:35
@ OPTIMIZED_BY_TIME
Definition OOTypes.h:36
OOGraphicsDetail
Definition OOTypes.h:243
@ DETAIL_LEVEL_EXTRAS
Definition OOTypes.h:247
@ DETAIL_LEVEL_SHADERS
Definition OOTypes.h:246
@ DETAIL_LEVEL_MINIMUM
Definition OOTypes.h:244
@ DETAIL_LEVEL_NORMAL
Definition OOTypes.h:245
OOLegalStatusReason
Definition OOTypes.h:157
OOCompassMode
Definition OOTypes.h:145
OOCargoType
Definition OOTypes.h:69
@ CARGO_RANDOM
Definition OOTypes.h:75
@ CARGO_NOT_CARGO
Definition OOTypes.h:70
@ CARGO_THARGOID
Definition OOTypes.h:74
@ CARGO_CHARACTER
Definition OOTypes.h:77
@ CARGO_SLAVES
Definition OOTypes.h:71
@ CARGO_ALLOY
Definition OOTypes.h:72
@ CARGO_SCRIPTED_ITEM
Definition OOTypes.h:76
@ CARGO_MINERALS
Definition OOTypes.h:73
OOMassUnit
Definition OOTypes.h:123
@ UNITS_TONS
Definition OOTypes.h:124
@ UNITS_GRAMS
Definition OOTypes.h:126
@ UNITS_KILOGRAMS
Definition OOTypes.h:125
uint8_t OOGovernmentID
Definition OOTypes.h:206
OODockingClearanceStatus
Definition OOTypes.h:167
@ DOCKING_CLEARANCE_STATUS_TIMING_OUT
Definition OOTypes.h:172
@ DOCKING_CLEARANCE_STATUS_NOT_REQUIRED
Definition OOTypes.h:169
@ DOCKING_CLEARANCE_STATUS_GRANTED
Definition OOTypes.h:171
@ DOCKING_CLEARANCE_STATUS_NONE
Definition OOTypes.h:168
@ DOCKING_CLEARANCE_STATUS_REQUESTED
Definition OOTypes.h:170
OOEnergyUnitType
Definition OOTypes.h:131
@ ENERGY_UNIT_NORMAL
Definition OOTypes.h:137
@ ENERGY_UNIT_NAVAL_DAMAGED
Definition OOTypes.h:134
@ ENERGY_UNIT_NAVAL
Definition OOTypes.h:138
@ OLD_ENERGY_UNIT_NORMAL
Definition OOTypes.h:135
@ ENERGY_UNIT_NONE
Definition OOTypes.h:132
@ OLD_ENERGY_UNIT_NAVAL
Definition OOTypes.h:136
@ ENERGY_UNIT_NORMAL_DAMAGED
Definition OOTypes.h:133
uint8_t OOEconomyID
Definition OOTypes.h:207
@ kOOCompassModeDefault
Definition OOTypes.h:151
OOGalacticHyperspaceBehaviour
OOGUIScreenID
@ kOOGUIScreenIDDefault
@ kOOGalacticHyperspaceBehaviourDefault
OOAlertCondition
Definition ShipEntity.h:172
OOBehaviour
Definition ShipEntity.h:150
OOShipDamageType
Definition ShipEntity.h:183
#define UNIVERSE
Definition Universe.h:840
#define DESC(key)
Definition Universe.h:846
@ MARKET_NAME
Definition Universe.h:64
OOEquipmentType * equipmentTypeWithIdentifier:(NSString *identifier)
NSString * identifier()