Oolite
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
28#import "Universe.h"
29
30static NSString* const kOOLogNoteAddShips = @"script.debug.note.addShips";
31
32@implementation ShipEntity (ScriptMethods)
33
34- (ShipEntity*)ejectShipOfType:(NSString*)shipKey
35{
36 ShipEntity* item = nil;
37
38 if (shipKey != nil) {
39 item = [[UNIVERSE newShipWithName:shipKey] autorelease];
40 if (item != nil)
41 [self dumpItem:item];
42 }
43
44 return item;
45}
46
47- (ShipEntity*)ejectShipOfRole:(NSString*)role
48{
49 ShipEntity* item = nil;
50
51 if (role != nil) {
52 item = [[UNIVERSE newShipWithRole:role] autorelease];
53 if (item != nil)
54 [self dumpItem:item];
55 }
56
57 return item;
58}
59
60- (NSArray*)spawnShipsWithRole:(NSString*)role count:(NSUInteger)count
61{
62 ShipEntity* ship = [self rootShipEntity]; // FIXME: (EMMSTRAN) implement an -absolutePosition method, use that in spawnShipWithRole:near:, and use self instead of root.
63 ShipEntity* spawned = nil;
64 NSMutableArray* result = nil;
65
66 if (count == 0)
67 return [NSArray array];
68
69 OOLog(kOOLogNoteAddShips, @"Spawning %zu x '%@' near %@ %d", count, role, [self shortDescription], [self universalID]);
70
71 result = [NSMutableArray arrayWithCapacity:count];
72
73 do {
74 spawned = [UNIVERSE spawnShipWithRole:role near:ship];
75 if (spawned != nil) {
77 if ([self isMissileFlagSet] && [[spawned shipInfoDictionary] oo_boolForKey:@"is_submunition"]) {
78 [spawned setOwner:[self owner]];
81 }
82 if ([spawned isMine]) {
83 [spawned setOwner:self];
84 }
85 [result addObject:spawned];
86 }
87 } while (--count);
88
89 return result;
90}
91
92@end
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned count
return nil
static NSString *const kOOLogNoteAddShips
ShipEntity * rootShipEntity()
Definition Entity.m:566
id owner()
Definition Entity.m:548
void addTarget:(Entity *targetEntity)
OOCargoType dumpItem:(ShipEntity *jetto)
float randomEjectaTemperature()
void setTemperature:(GLfloat value)
void setIsMissileFlag:(BOOL newValue)
void setOwner:(Entity *who_owns_entity)