author | Wuzzy <Wuzzy2@mail.ru> |
Mon, 12 Feb 2018 22:22:27 +0100 | |
changeset 12988 | a15413d896c3 |
parent 11572 | 28afdaa159cb |
child 12872 | 00215a7ec5f5 |
permissions | -rw-r--r-- |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
1 |
/* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
6700 | 3 |
* Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com> |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
4 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
8 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
13 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
8427
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
17 |
*/ |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
18 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
19 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
20 |
#import "GameInterfaceBridge.h" |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
21 |
#import "EngineProtocolNetwork.h" |
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
22 |
#import "StatsPageViewController.h" |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
23 |
|
6832 | 24 |
|
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
25 |
static UIViewController *callingController; |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
26 |
|
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
27 |
@implementation GameInterfaceBridge |
6870
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
28 |
@synthesize blackView, savePath, port; |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
29 |
|
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
30 |
#pragma mark - |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
31 |
#pragma mark Instance methods for engine interaction |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
32 |
// prepares the controllers for hosting a game |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
33 |
-(void) earlyEngineLaunch:(NSDictionary *)optionsOrNil { |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
34 |
[self retain]; |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6866
diff
changeset
|
35 |
[[AudioManagerController mainManager] fadeOutBackgroundMusic]; |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
36 |
|
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
37 |
EngineProtocolNetwork *engineProtocol = [[EngineProtocolNetwork alloc] init]; |
6870
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
38 |
self.port = engineProtocol.enginePort; |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
39 |
engineProtocol.delegate = self; |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
40 |
[engineProtocol spawnThread:self.savePath withOptions:optionsOrNil]; |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
41 |
[engineProtocol release]; |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
42 |
|
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
43 |
// add a black view hiding the background |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
44 |
UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow]; |
6667
142fe596e75e
ios check for music preference also for fading methods
koda
parents:
6656
diff
changeset
|
45 |
self.blackView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
46 |
self.blackView.opaque = YES; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
47 |
self.blackView.backgroundColor = [UIColor blackColor]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
48 |
self.blackView.alpha = 0; |
6667
142fe596e75e
ios check for music preference also for fading methods
koda
parents:
6656
diff
changeset
|
49 |
self.blackView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
50 |
[UIView beginAnimations:@"fade out" context:NULL]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
51 |
[UIView setAnimationDuration:1]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
52 |
self.blackView.alpha = 1; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
53 |
[UIView commitAnimations]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
54 |
[thisWindow addSubview:self.blackView]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
55 |
[self.blackView release]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
56 |
|
6866
efdd2e4fc45c
ios: don't prompt restoring a game that didn't complete loading
koda
parents:
6832
diff
changeset
|
57 |
// keep the point of return for games that completed loading |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
58 |
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
59 |
[userDefaults setObject:self.savePath forKey:@"savedGamePath"]; |
6866
efdd2e4fc45c
ios: don't prompt restoring a game that didn't complete loading
koda
parents:
6832
diff
changeset
|
60 |
[userDefaults setObject:[NSNumber numberWithBool:NO] forKey:@"saveIsValid"]; |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
61 |
[userDefaults synchronize]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
62 |
|
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
63 |
// let's launch the engine using this -perfomSelector so that the runloop can deal with queued messages first |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
64 |
[self performSelector:@selector(engineLaunch) withObject:nil afterDelay:0.1f]; |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
65 |
} |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
66 |
|
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
67 |
// cleans up everything |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
68 |
-(void) lateEngineLaunch { |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
69 |
// notify views below that they are getting the spotlight again |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
70 |
[[[HedgewarsAppDelegate sharedAppDelegate] uiwindow] makeKeyAndVisible]; |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
71 |
[callingController viewWillAppear:YES]; |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
72 |
|
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
73 |
// remove completed games notification |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
74 |
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
75 |
[userDefaults setObject:@"" forKey:@"savedGamePath"]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
76 |
[userDefaults synchronize]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
77 |
|
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
78 |
// remove the cover view with a transition |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
79 |
self.blackView.alpha = 1; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
80 |
[UIView beginAnimations:@"fade in" context:NULL]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
81 |
[UIView setAnimationDuration:1]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
82 |
self.blackView.alpha = 0; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
83 |
[UIView commitAnimations]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
84 |
[self.blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
85 |
|
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
86 |
// can remove the savefile if the replay has ended |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
87 |
if ([HWUtils gameType] == gtSave) |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
88 |
[[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
89 |
|
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
90 |
// restart music and we're done |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6866
diff
changeset
|
91 |
[[AudioManagerController mainManager] fadeInBackgroundMusic]; |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
92 |
[HWUtils setGameStatus:gsNone]; |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
93 |
[HWUtils setGameType:gtNone]; |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
94 |
[self release]; |
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
95 |
} |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
96 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
97 |
// main routine for calling the actual game engine |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
98 |
-(void) engineLaunch { |
6209 | 99 |
CGFloat width, height; |
100 |
CGFloat screenScale = [[UIScreen mainScreen] safeScale]; |
|
6870
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
101 |
NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",self.port]; |
11199
3465047397da
- Fix for locale string passed to engine (like "ru-FR")
antonc27 <antonc27@mail.ru>
parents:
11116
diff
changeset
|
102 |
|
11219
c51ecb9bcf05
- Retrieving language ID moved to HWUtils
antonc27 <antonc27@mail.ru>
parents:
11206
diff
changeset
|
103 |
NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [HWUtils languageID]]; |
11199
3465047397da
- Fix for locale string passed to engine (like "ru-FR")
antonc27 <antonc27@mail.ru>
parents:
11116
diff
changeset
|
104 |
|
5206 | 105 |
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
106 |
|
6624
e049b5bb0ad1
BUUUUURN OBJC AMMOMENU BUUUURNhg diff! (on a separate note, this reduces the codesize by ~37k)
koda
parents:
6615
diff
changeset
|
107 |
CGRect screenBounds = [[UIScreen mainScreen] safeBounds]; |
e049b5bb0ad1
BUUUUURN OBJC AMMOMENU BUUUURNhg diff! (on a separate note, this reduces the codesize by ~37k)
koda
parents:
6615
diff
changeset
|
108 |
width = screenBounds.size.width; |
e049b5bb0ad1
BUUUUURN OBJC AMMOMENU BUUUURNhg diff! (on a separate note, this reduces the codesize by ~37k)
koda
parents:
6615
diff
changeset
|
109 |
height = screenBounds.size.height; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
110 |
|
6209 | 111 |
NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", (int)(width * screenScale)]; |
112 |
NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", (int)(height * screenScale)]; |
|
6344 | 113 |
NSString *resourcePath = [[NSString alloc] initWithFormat:@"%@/Data", [[NSBundle mainBundle] resourcePath]]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
114 |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6020
diff
changeset
|
115 |
NSString *modelId = [HWUtils modelType]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
116 |
NSInteger tmpQuality; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
117 |
if ([modelId hasPrefix:@"iPhone1"] || [modelId hasPrefix:@"iPod1,1"] || [modelId hasPrefix:@"iPod2,1"]) // = iPhone and iPhone 3G or iPod Touch or iPod Touch 2G |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
118 |
tmpQuality = 0x00000001 | 0x00000002 | 0x00000008 | 0x00000040; // rqLowRes | rqBlurryLand | rqSimpleRope | rqKillFlakes |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
119 |
else if ([modelId hasPrefix:@"iPhone2"] || [modelId hasPrefix:@"iPod3"]) // = iPhone 3GS or iPod Touch 3G |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
120 |
tmpQuality = 0x00000002 | 0x00000040; // rqBlurryLand | rqKillFlakes |
5709 | 121 |
else if ([modelId hasPrefix:@"iPad1"] || [modelId hasPrefix:@"iPod4"]) // = iPad 1G or iPod Touch 4G |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
122 |
tmpQuality = 0x00000002; // rqBlurryLand |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
123 |
else // = everything else |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
124 |
tmpQuality = 0; // full quality |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
125 |
|
6276
1e2f8da1860a
while formatting the ammomenu code i found out that it's simpler to move than i thought, and fixed a small glitch when animation was disabled
koda
parents:
6266
diff
changeset
|
126 |
// disable ammomenu animation |
1e2f8da1860a
while formatting the ammomenu code i found out that it's simpler to move than i thought, and fixed a small glitch when animation was disabled
koda
parents:
6266
diff
changeset
|
127 |
tmpQuality = tmpQuality | 0x00000080; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
128 |
// disable tooltips on iPhone |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
129 |
if (IS_IPAD() == NO) |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
130 |
tmpQuality = tmpQuality | 0x00000400; |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
131 |
NSString *rawQuality = [NSString stringWithFormat:@"%d",tmpQuality]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
132 |
NSString *documentsDirectory = DOCUMENTS_FOLDER(); |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
133 |
|
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
134 |
NSMutableArray *gameParameters = [[NSMutableArray alloc] initWithObjects: |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
135 |
@"--internal", |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
136 |
@"--port", ipcString, |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
137 |
@"--width", horizontalSize, |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
138 |
@"--height", verticalSize, |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
139 |
@"--raw-quality", rawQuality, |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
140 |
@"--locale", localeString, |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
141 |
@"--prefix", resourcePath, |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
142 |
@"--user-prefix", documentsDirectory, |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
143 |
nil]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
144 |
[verticalSize release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
145 |
[horizontalSize release]; |
6344 | 146 |
[resourcePath release]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
147 |
[localeString release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
148 |
[ipcString release]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
149 |
|
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
150 |
NSString *username = [settings objectForKey:@"username"]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
151 |
if ([username length] > 0) { |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
152 |
[gameParameters addObject:@"--nick"]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
153 |
[gameParameters addObject: username]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
154 |
} |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
155 |
|
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
156 |
if ([[settings objectForKey:@"sound"] boolValue] == NO) |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
157 |
[gameParameters addObject:@"--nosound"]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
158 |
|
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
159 |
if ([[settings objectForKey:@"music"] boolValue] == NO) |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
160 |
[gameParameters addObject:@"--nomusic"]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
161 |
|
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
162 |
if([[settings objectForKey:@"alternate"] boolValue] == YES) |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
163 |
[gameParameters addObject:@"--altdmg"]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
164 |
|
8427 | 165 |
#ifdef DEBUG |
166 |
[gameParameters addObject:@"--showfps"]; |
|
167 |
#endif |
|
168 |
||
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
169 |
if ([HWUtils gameType] == gtSave) |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
170 |
[gameParameters addObject:self.savePath]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
171 |
|
6247
6dfad55fd71c
unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents:
6246
diff
changeset
|
172 |
[HWUtils setGameStatus:gsLoading]; |
5194 | 173 |
|
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
174 |
int argc = [gameParameters count]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
175 |
const char **argv = (const char **)malloc(sizeof(const char*)*argc); |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
176 |
for (int i = 0; i < argc; i++) |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
177 |
argv[i] = strdup([[gameParameters objectAtIndex:i] UTF8String]); |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
178 |
[gameParameters release]; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
179 |
|
6265
a6944f94c19f
aaand remove also ipcport from the class interface as well
koda
parents:
6263
diff
changeset
|
180 |
// this is the pascal function that starts the game |
11094
595b5700ebac
- Fix for PascalImports and for GenLandPreview
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
181 |
RunEngine(argc, argv); |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
182 |
|
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
183 |
// cleanup |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
184 |
for (int i = 0; i < argc; i++) |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
185 |
free((void *)argv[i]); |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
186 |
free(argv); |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
187 |
|
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
7943
diff
changeset
|
188 |
// moar cleanup |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
189 |
[self lateEngineLaunch]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
190 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
191 |
|
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
192 |
-(void) dealloc { |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
193 |
releaseAndNil(blackView); |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
194 |
releaseAndNil(savePath); |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
195 |
[super dealloc]; |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
196 |
} |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
197 |
|
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
198 |
#pragma mark - |
6870
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
199 |
#pragma mark EngineProtocolDelegate methods |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
200 |
-(void) gameEndedWithStatistics:(NSArray *)stats { |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
201 |
if (stats != nil) { |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
202 |
StatsPageViewController *statsPage = [[StatsPageViewController alloc] init]; |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
203 |
statsPage.statsArray = stats; |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
204 |
statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
205 |
|
11116
102684240fe8
- Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents:
11094
diff
changeset
|
206 |
[callingController presentViewController:statsPage animated:YES completion:nil]; |
6870
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
207 |
[statsPage release]; |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
208 |
} |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
209 |
} |
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
210 |
|
f72cac290325
ios: refactor the code of the after-game statistics display using delegates
koda
parents:
6869
diff
changeset
|
211 |
#pragma mark - |
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
212 |
#pragma mark Class methods for setting up the engine from outsite |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
213 |
+(void) registerCallingController:(UIViewController *)controller { |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
214 |
callingController = controller; |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
215 |
} |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
216 |
|
6321 | 217 |
+(void) startGame:(TGameType) type atPath:(NSString *)path withOptions:(NSDictionary *)config { |
218 |
[HWUtils setGameType:type]; |
|
6337
84e7d1a5e3df
in class methods you can call [self alloc], as per objc specifications
koda
parents:
6321
diff
changeset
|
219 |
id bridge = [[self alloc] init]; |
6353
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
220 |
[bridge setSavePath:path]; |
d8f62c805619
restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents:
6337
diff
changeset
|
221 |
[bridge earlyEngineLaunch:config]; |
6321 | 222 |
[bridge release]; |
223 |
} |
|
224 |
||
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
225 |
+(void) startLocalGame:(NSDictionary *)withOptions { |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
226 |
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
227 |
[outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
228 |
NSString *savePath = [[NSString alloc] initWithFormat:@"%@%@.hws",SAVES_DIRECTORY(),[outputFormatter stringFromDate:[NSDate date]]]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
229 |
[outputFormatter release]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
230 |
|
6301
1259736c0134
engine interaction class refactoring, round 4 or 5, can't remember: this time use the class methods to create an instance object and operates on that, reducing the number of arguments between methods and simplifying memory management
koda
parents:
6276
diff
changeset
|
231 |
// in the rare case in which a savefile with the same name exists the older one must be removed (otherwise it gets corrupted) |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
232 |
if ([[NSFileManager defaultManager] fileExistsAtPath:savePath]) |
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
233 |
[[NSFileManager defaultManager] removeItemAtPath:savePath error:nil]; |
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
234 |
|
6321 | 235 |
[self startGame:gtLocal atPath:savePath withOptions:withOptions]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
236 |
[savePath release]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
237 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
238 |
|
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
239 |
+(void) startSaveGame:(NSString *)atPath { |
6321 | 240 |
[self startGame:gtSave atPath:atPath withOptions:nil]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
241 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
242 |
|
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
243 |
+(void) startMissionGame:(NSString *)withScript { |
11571
b709768e720c
- Small refactoring for seed command
antonc27 <antonc27@mail.ru>
parents:
11555
diff
changeset
|
244 |
NSString *seedCmd = [self seedCommand]; |
6084 | 245 |
NSString *missionPath = [[NSString alloc] initWithFormat:@"escript Missions/Training/%@.lua",withScript]; |
11555
b96080df19d0
- Send also some seed when loading missions on iOS (same behavior as on desktop)
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
246 |
NSDictionary *missionDict = [[NSDictionary alloc] initWithObjectsAndKeys:missionPath, @"mission_command", seedCmd, @"seed_command", nil]; |
6084 | 247 |
[missionPath release]; |
11571
b709768e720c
- Small refactoring for seed command
antonc27 <antonc27@mail.ru>
parents:
11555
diff
changeset
|
248 |
[seedCmd release]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
249 |
|
11555
b96080df19d0
- Send also some seed when loading missions on iOS (same behavior as on desktop)
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
250 |
[self startGame:gtMission atPath:nil withOptions:missionDict]; |
b96080df19d0
- Send also some seed when loading missions on iOS (same behavior as on desktop)
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
251 |
[missionDict release]; |
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
252 |
} |
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
253 |
|
11571
b709768e720c
- Small refactoring for seed command
antonc27 <antonc27@mail.ru>
parents:
11555
diff
changeset
|
254 |
+(NSString *) seedCommand { |
6719
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
255 |
// generate a seed |
11554
73e6a3d2f768
- Small refactoring for seed generation on iOS side
antonc27 <antonc27@mail.ru>
parents:
11219
diff
changeset
|
256 |
NSString *seed = [HWUtils seed]; |
6719
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
257 |
NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed]; |
7943 | 258 |
[seed release]; |
11571
b709768e720c
- Small refactoring for seed command
antonc27 <antonc27@mail.ru>
parents:
11555
diff
changeset
|
259 |
return seedCmd; |
b709768e720c
- Small refactoring for seed command
antonc27 <antonc27@mail.ru>
parents:
11555
diff
changeset
|
260 |
} |
b709768e720c
- Small refactoring for seed command
antonc27 <antonc27@mail.ru>
parents:
11555
diff
changeset
|
261 |
|
11572
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
262 |
+(void) startCampaignMissionGameWithScript:(NSString *)missionScriptName forCampaign:(NSString *)campaignName { |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
263 |
NSString *seedCmd = [self seedCommand]; |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
264 |
NSString *campaignMissionPath = [[NSString alloc] initWithFormat:@"escript Missions/Campaign/%@/%@", campaignName, missionScriptName]; |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
265 |
NSDictionary *campaignMissionDict = [[NSDictionary alloc] initWithObjectsAndKeys:campaignMissionPath, @"mission_command", seedCmd, @"seed_command", nil]; |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
266 |
[campaignMissionPath release]; |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
267 |
[seedCmd release]; |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
268 |
|
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
269 |
[self startGame:gtCampaign atPath:nil withOptions:campaignMissionDict]; |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
270 |
[campaignMissionDict release]; |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
271 |
} |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11571
diff
changeset
|
272 |
|
11571
b709768e720c
- Small refactoring for seed command
antonc27 <antonc27@mail.ru>
parents:
11555
diff
changeset
|
273 |
+(void) startSimpleGame { |
b709768e720c
- Small refactoring for seed command
antonc27 <antonc27@mail.ru>
parents:
11555
diff
changeset
|
274 |
NSString *seedCmd = [self seedCommand]; |
6719
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
275 |
|
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
276 |
// pick a random static map |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
277 |
NSArray *listOfMaps = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; |
11206
2e80c9861818
- Better random number generation for front-end: random() replaced with arc4random_uniform()
antonc27 <antonc27@mail.ru>
parents:
11199
diff
changeset
|
278 |
NSString *mapName = [listOfMaps objectAtIndex:arc4random_uniform((int)[listOfMaps count])]; |
6719
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
279 |
NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg",MAPS_DIRECTORY(),mapName]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
280 |
NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
281 |
[fileCfg release]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
282 |
NSArray *split = [contents componentsSeparatedByString:@"\n"]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
283 |
[contents release]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
284 |
NSString *themeCommand = [[NSString alloc] initWithFormat:@"etheme %@", [split objectAtIndex:0]]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
285 |
NSString *staticMapCommand = [[NSString alloc] initWithFormat:@"emap %@", mapName]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
286 |
|
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
287 |
// select teams with two different colors |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
288 |
NSArray *colorArray = [HWUtils teamColors]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
289 |
NSInteger firstColorIndex, secondColorIndex; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
290 |
do { |
11206
2e80c9861818
- Better random number generation for front-end: random() replaced with arc4random_uniform()
antonc27 <antonc27@mail.ru>
parents:
11199
diff
changeset
|
291 |
firstColorIndex = arc4random_uniform((int)[colorArray count]); |
2e80c9861818
- Better random number generation for front-end: random() replaced with arc4random_uniform()
antonc27 <antonc27@mail.ru>
parents:
11199
diff
changeset
|
292 |
secondColorIndex = arc4random_uniform((int)[colorArray count]); |
6719
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
293 |
} while (firstColorIndex == secondColorIndex); |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
294 |
unsigned int firstColor = [[colorArray objectAtIndex:firstColorIndex] intValue]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
295 |
unsigned int secondColor = [[colorArray objectAtIndex:secondColorIndex] intValue]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
296 |
|
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
297 |
NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:4],@"number", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
298 |
[NSNumber numberWithUnsignedInt:firstColor],@"color", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
299 |
@"Ninjas.plist",@"team",nil]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
300 |
NSDictionary *secondTeam = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:4],@"number", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
301 |
[NSNumber numberWithUnsignedInt:secondColor],@"color", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
302 |
@"Robots.plist",@"team",nil]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
303 |
NSArray *listOfTeams = [[NSArray alloc] initWithObjects:firstTeam,secondTeam,nil]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
304 |
[firstTeam release]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
305 |
[secondTeam release]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
306 |
|
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
307 |
// create the configuration |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
308 |
NSDictionary *gameDictionary = [[NSDictionary alloc] initWithObjectsAndKeys: |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
309 |
seedCmd,@"seed_command", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
310 |
@"e$template_filter 0",@"templatefilter_command", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
311 |
@"e$mapgen 0",@"mapgen_command", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
312 |
@"e$maze_size 0",@"mazesize_command", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
313 |
themeCommand,@"theme_command", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
314 |
staticMapCommand,@"staticmap_command", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
315 |
listOfTeams,@"teams_list", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
316 |
@"Default.plist",@"scheme", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
317 |
@"Default.plist",@"weapon", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
318 |
@"",@"mission_command", |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
319 |
nil]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
320 |
[listOfTeams release]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
321 |
[staticMapCommand release]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
322 |
[themeCommand release]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
323 |
[seedCmd release]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
324 |
|
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
325 |
// launch game |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
326 |
[GameInterfaceBridge startLocalGame:gameDictionary]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
327 |
[gameDictionary release]; |
d2afc6b2d88e
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
koda
parents:
6709
diff
changeset
|
328 |
} |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
329 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
330 |
@end |