94 [self release]; |
94 [self release]; |
95 } |
95 } |
96 |
96 |
97 // main routine for calling the actual game engine |
97 // main routine for calling the actual game engine |
98 -(void) engineLaunch { |
98 -(void) engineLaunch { |
99 const char *gameArgs[11]; |
|
100 CGFloat width, height; |
99 CGFloat width, height; |
101 CGFloat screenScale = [[UIScreen mainScreen] safeScale]; |
100 CGFloat screenScale = [[UIScreen mainScreen] safeScale]; |
102 NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",self.port]; |
101 NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",self.port]; |
103 NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt",[[NSLocale preferredLanguages] objectAtIndex:0]]; |
102 NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt",[[NSLocale preferredLanguages] objectAtIndex:0]]; |
104 NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
103 NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
125 // disable ammomenu animation |
124 // disable ammomenu animation |
126 tmpQuality = tmpQuality | 0x00000080; |
125 tmpQuality = tmpQuality | 0x00000080; |
127 // disable tooltips on iPhone |
126 // disable tooltips on iPhone |
128 if (IS_IPAD() == NO) |
127 if (IS_IPAD() == NO) |
129 tmpQuality = tmpQuality | 0x00000400; |
128 tmpQuality = tmpQuality | 0x00000400; |
130 |
129 NSString *rawQuality = [NSString stringWithFormat:@"%d",tmpQuality]; |
131 // prevents using an empty nickname |
130 NSString *documentsDirectory = DOCUMENTS_FOLDER(); |
132 NSString *username = [settings objectForKey:@"username"]; |
131 |
133 if ([username length] == 0) |
132 NSMutableArray *gameParameters = [[NSMutableArray alloc] initWithObjects: |
134 username = [NSString stringWithFormat:@"MobileUser-%@",ipcString]; |
133 @"--internal", |
135 |
134 @"--port", ipcString, |
136 gameArgs[ 0] = [ipcString UTF8String]; //ipcPort |
135 @"--width", horizontalSize, |
137 gameArgs[ 1] = [horizontalSize UTF8String]; //cScreenWidth |
136 @"--height", verticalSize, |
138 gameArgs[ 2] = [verticalSize UTF8String]; //cScreenHeight |
137 @"--raw-quality", rawQuality, |
139 gameArgs[ 3] = [[NSString stringWithFormat:@"%d",tmpQuality] UTF8String]; //quality |
138 @"--locale", localeString, |
140 gameArgs[ 4] = [localeString UTF8String]; //cLocaleFName |
139 @"--prefix", resourcePath, |
141 gameArgs[ 5] = [username UTF8String]; //UserNick |
140 @"--user-prefix", documentsDirectory, |
142 gameArgs[ 6] = [[[settings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled |
141 nil]; |
143 gameArgs[ 7] = [[[settings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled |
|
144 gameArgs[ 8] = [[[settings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage |
|
145 gameArgs[ 9] = [resourcePath UTF8String]; //PathPrefix |
|
146 gameArgs[10] = ([HWUtils gameType] == gtSave) ? [self.savePath UTF8String] : NULL; //recordFileName |
|
147 |
|
148 [verticalSize release]; |
142 [verticalSize release]; |
149 [horizontalSize release]; |
143 [horizontalSize release]; |
150 [resourcePath release]; |
144 [resourcePath release]; |
151 [localeString release]; |
145 [localeString release]; |
152 [ipcString release]; |
146 [ipcString release]; |
153 |
147 |
|
148 NSString *username = [settings objectForKey:@"username"]; |
|
149 if ([username length] > 0) { |
|
150 [gameParameters addObject:@"--nick"]; |
|
151 [gameParameters addObject: username]; |
|
152 } |
|
153 |
|
154 if ([[settings objectForKey:@"sound"] boolValue] == NO) |
|
155 [gameParameters addObject:@"--nosound"]; |
|
156 |
|
157 if ([[settings objectForKey:@"music"] boolValue] == NO) |
|
158 [gameParameters addObject:@"--nomusic"]; |
|
159 |
|
160 if([[settings objectForKey:@"alternate"] boolValue] == YES) |
|
161 [gameParameters addObject:@"--altdmg"]; |
|
162 |
|
163 if ([HWUtils gameType] == gtSave) |
|
164 [gameParameters addObject:self.savePath]; |
|
165 |
154 [HWUtils setGameStatus:gsLoading]; |
166 [HWUtils setGameStatus:gsLoading]; |
155 |
167 |
|
168 int argc = [gameParameters count]; |
|
169 const char **argv = (const char **)malloc(sizeof(const char*)*argc); |
|
170 for (int i = 0; i < argc; i++) |
|
171 argv[i] = strdup([[gameParameters objectAtIndex:i] UTF8String]); |
|
172 [gameParameters release]; |
|
173 |
156 // this is the pascal function that starts the game |
174 // this is the pascal function that starts the game |
157 Game(gameArgs); |
175 Game(argc, argv); |
|
176 |
|
177 // cleanup |
|
178 for (int i = 0; i < argc; i++) |
|
179 free((void *)argv[i]); |
|
180 free(argv); |
|
181 |
|
182 // moar cleanup |
158 [self lateEngineLaunch]; |
183 [self lateEngineLaunch]; |
159 } |
184 } |
160 |
185 |
161 -(void) dealloc { |
186 -(void) dealloc { |
162 releaseAndNil(blackView); |
187 releaseAndNil(blackView); |