60 UIView *injected = (IS_DUALHEAD() ? self.parentController.view : UIVIEW_HW_SDLVIEW); |
60 UIView *injected = (IS_DUALHEAD() ? self.parentController.view : UIVIEW_HW_SDLVIEW); |
61 [injected addSubview:self.overlayController.view]; |
61 [injected addSubview:self.overlayController.view]; |
62 } |
62 } |
63 |
63 |
64 // main routine for calling the actual game engine |
64 // main routine for calling the actual game engine |
65 -(void) startGameEngine { |
65 -(void) engineLaunch { |
66 const char *gameArgs[11]; |
66 const char *gameArgs[11]; |
67 NSInteger width, height; |
67 NSInteger width, height; |
68 NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort]; |
68 NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort]; |
69 NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
69 NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
70 NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
70 NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
156 [userDefaults synchronize]; |
156 [userDefaults synchronize]; |
157 |
157 |
158 [AudioManagerController pauseBackgroundMusic]; |
158 [AudioManagerController pauseBackgroundMusic]; |
159 |
159 |
160 // SYSTEMS ARE GO!! |
160 // SYSTEMS ARE GO!! |
161 [self startGameEngine]; |
161 [self engineLaunch]; |
162 |
162 |
163 // remove completed games notification |
163 // remove completed games notification |
164 [userDefaults setObject:@"" forKey:@"savedGamePath"]; |
164 [userDefaults setObject:@"" forKey:@"savedGamePath"]; |
165 [userDefaults synchronize]; |
165 [userDefaults synchronize]; |
166 |
166 |
182 |
182 |
183 [AudioManagerController playBackgroundMusic]; |
183 [AudioManagerController playBackgroundMusic]; |
184 } |
184 } |
185 |
185 |
186 // set up variables for a local game |
186 // set up variables for a local game |
187 -(void) startLocalGame:(NSDictionary *)withDictionary { |
187 -(void) startLocalGame:(NSDictionary *)withOptions { |
188 self.gameType = gtLocal; |
188 self.gameType = gtLocal; |
189 |
189 |
190 NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; |
190 NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; |
191 [outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"]; |
191 [outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"]; |
192 NSString *path = [[NSString alloc] initWithFormat:@"%@%@.hws",SAVES_DIRECTORY(),[outputFormatter stringFromDate:[NSDate date]]]; |
192 NSString *path = [[NSString alloc] initWithFormat:@"%@%@.hws",SAVES_DIRECTORY(),[outputFormatter stringFromDate:[NSDate date]]]; |
196 |
196 |
197 // in the rare case in which a savefile with the same name exists the older one must be removed (or it gets corrupted) |
197 // in the rare case in which a savefile with the same name exists the older one must be removed (or it gets corrupted) |
198 if ([[NSFileManager defaultManager] fileExistsAtPath:self.savePath]) |
198 if ([[NSFileManager defaultManager] fileExistsAtPath:self.savePath]) |
199 [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
199 [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
200 |
200 |
201 [self.engineProtocol spawnThread:self.savePath withOptions:withDictionary]; |
201 [self.engineProtocol spawnThread:self.savePath withOptions:withOptions]; |
202 [self prepareEngineLaunch]; |
202 [self prepareEngineLaunch]; |
203 } |
203 } |
204 |
204 |
205 // set up variables for a save game |
205 // set up variables for a save game |
206 -(void) startSaveGame:(NSString *)atPath { |
206 -(void) startSaveGame:(NSString *)atPath { |
207 self.gameType = gtSave; |
207 self.gameType = gtSave; |
208 self.savePath = atPath; |
208 self.savePath = atPath; |
209 |
209 |
210 [self.engineProtocol spawnThread:self.savePath]; |
210 [self.engineProtocol spawnThread:self.savePath]; |
|
211 [self prepareEngineLaunch]; |
|
212 } |
|
213 |
|
214 -(void) startMissionGame:(NSString *)withScript { |
|
215 self.gameType = gtMission; |
|
216 self.savePath = nil; |
|
217 |
|
218 NSDictionary *config = [NSDictionary dictionaryWithObject:withScript forKey:@"mission_command"]; |
|
219 [self.engineProtocol spawnThread:nil withOptions:config]; |
211 [self prepareEngineLaunch]; |
220 [self prepareEngineLaunch]; |
212 } |
221 } |
213 |
222 |
214 -(void) gameHasEndedWithStats:(NSArray *)stats { |
223 -(void) gameHasEndedWithStats:(NSArray *)stats { |
215 // wrap this around a retain/realse to prevent being deallocated too soon |
224 // wrap this around a retain/realse to prevent being deallocated too soon |