Line data Source code
1 0 : /* 2 : 3 : ShipEntityScriptMethods.m 4 : 5 : 6 : Oolite 7 : Copyright (C) 2004-2013 Giles C Williams and contributors 8 : 9 : This program is free software; you can redistribute it and/or 10 : modify it under the terms of the GNU General Public License 11 : as published by the Free Software Foundation; either version 2 12 : of the License, or (at your option) any later version. 13 : 14 : This program is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU General Public License for more details. 18 : 19 : You should have received a copy of the GNU General Public License 20 : along with this program; if not, write to the Free Software 21 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 : MA 02110-1301, USA. 23 : 24 : */ 25 : 26 : #import "ShipEntityScriptMethods.h" 27 : #import "Universe.h" 28 : #import "OOCollectionExtractors.h" 29 : 30 : 31 0 : static 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