Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
ShipEntityScriptMethods.m
Go to the documentation of this file.
1/*
2
3ShipEntityScriptMethods.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27#import "Universe.h"
29
30
31static NSString * const kOOLogNoteAddShips = @"script.debug.note.addShips";
32
33
34@implementation ShipEntity (ScriptMethods)
35
36- (ShipEntity *) ejectShipOfType:(NSString *)shipKey
37{
38 ShipEntity *item = nil;
39
40 if (shipKey != nil)
41 {
42 item = [[UNIVERSE newShipWithName:shipKey] autorelease];
43 if (item != nil) [self dumpItem:item];
44 }
45
46 return item;
47}
48
49
50- (ShipEntity *) ejectShipOfRole:(NSString *)role
51{
52 ShipEntity *item = nil;
53
54 if (role != nil)
55 {
56 item = [[UNIVERSE newShipWithRole:role] autorelease];
57 if (item != nil) [self dumpItem:item];
58 }
59
60 return item;
61}
62
63
64- (NSArray *) spawnShipsWithRole:(NSString *)role count:(NSUInteger)count
65{
66 ShipEntity *ship = [self rootShipEntity]; // FIXME: (EMMSTRAN) implement an -absolutePosition method, use that in spawnShipWithRole:near:, and use self instead of root.
67 ShipEntity *spawned = nil;
68 NSMutableArray *result = nil;
69
70 if (count == 0) return [NSArray array];
71
72 OOLog(kOOLogNoteAddShips, @"Spawning %ld x '%@' near %@ %d", count, role, [self shortDescription], [self universalID]);
73
74 result = [NSMutableArray arrayWithCapacity:count];
75
76 do
77 {
78 spawned = [UNIVERSE spawnShipWithRole:role near:ship];
79 if (spawned != nil)
80 {
81 [spawned setTemperature:[self randomEjectaTemperature]];
82 if ([self isMissileFlagSet] && [[spawned shipInfoDictionary] oo_boolForKey:@"is_submunition"])
83 {
84 [spawned setOwner:[self owner]];
85 [spawned addTarget:[self primaryTarget]];
86 [spawned setIsMissileFlag:YES];
87 }
88 [result addObject:spawned];
89 }
90 }
91 while (--count);
92
93 return result;
94}
95
96@end
#define OOLog(class, format,...)
Definition OOLogging.h:88
unsigned count
return nil
static NSString *const kOOLogNoteAddShips
static NSString *const kOOLogNoteAddShips
void addTarget:(Entity *targetEntity)
OOCargoType dumpItem:(ShipEntity *jetto)
void setTemperature:(GLfloat value)
void setIsMissileFlag:(BOOL newValue)
void setOwner:(Entity *who_owns_entity)