project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
author koda
Mon, 26 Mar 2012 03:24:50 +0200
changeset 6822 206db098f8c5
parent 6719 d2afc6b2d88e
child 6832 fae8fd118da9
permissions -rw-r--r--
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
e04da46ee43c the most important commit of the year
koda
parents: 6667
diff changeset
     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
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    17
 *
6700
e04da46ee43c the most important commit of the year
koda
parents: 6667
diff changeset
    18
 * File created on 18/04/2012.
5154
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
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    21
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    22
#import "GameInterfaceBridge.h"
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    23
#import "EngineProtocolNetwork.h"
5158
4941df038b95 stats implemented once again! refactoring complete \o/
koda
parents: 5157
diff changeset
    24
#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
    25
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
    26
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
    27
5154
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    28
@implementation GameInterfaceBridge
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
    29
@synthesize blackView, savePath, proto;
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
    30
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 -
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
#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
    33
// 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
    34
-(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
    35
    [self retain];
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6624
diff changeset
    36
    [AudioManagerController 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
    37
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
    38
    EngineProtocolNetwork *engineProtocol = [[EngineProtocolNetwork alloc] init];
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
    39
    self.proto = engineProtocol;
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
    40
    [engineProtocol release];
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
    [self.proto spawnThread:self.savePath withOptions: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
    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
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
    57
    // keep track of uncompleted games
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"];
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
    60
    [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
    61
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
    // 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
    63
    [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
    64
}
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
// 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
    67
-(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
    68
    // 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
    69
    [[[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
    70
    [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
    71
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
    72
    // 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
    73
    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
    74
    [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
    75
    [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
    76
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
    // 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
    78
    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
    79
    [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
    80
    [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
    81
    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
    82
    [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
    83
    [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
    84
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
    85
    // engine thread *should* be done by now
6365
c992df555afb fix accessing a released object
koda
parents: 6353
diff changeset
    86
    NSArray *stats = [[NSArray alloc] initWithArray:self.proto.statsArray copyItems:YES];
c992df555afb fix accessing a released object
koda
parents: 6353
diff changeset
    87
    if ([HWUtils gameStatus] == gsEnded && stats != nil) {
6709
018539298042 oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents: 6700
diff changeset
    88
        StatsPageViewController *statsPage = [[StatsPageViewController 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
    89
        statsPage.statsArray = stats;
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
    90
        statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
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
    91
        if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)])
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
            statsPage.modalPresentationStyle = UIModalPresentationPageSheet;
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
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
    94
        [callingController presentModalViewController:statsPage animated: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
    95
        [statsPage release];
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
    96
    }
6365
c992df555afb fix accessing a released object
koda
parents: 6353
diff changeset
    97
    [stats release];
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
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
    99
    // 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
   100
    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
   101
        [[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
   102
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
   103
    // restart music and we're done
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6624
diff changeset
   104
    [AudioManagerController 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
   105
    [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
   106
    [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
   107
    [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
   108
}
5154
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   109
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   110
// 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
   111
-(void) engineLaunch {
5156
641abe679bf0 work in progress yet again (can run some games now)
koda
parents: 5155
diff changeset
   112
    const char *gameArgs[11];
6209
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6084
diff changeset
   113
    CGFloat width, height;
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
   114
    NSInteger enginePort = self.proto.enginePort;
6209
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6084
diff changeset
   115
    CGFloat screenScale = [[UIScreen mainScreen] safeScale];
6321
5a0416e5a6de further engine interaction refactoring
koda
parents: 6301
diff changeset
   116
    NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",enginePort];
6527
d19c6af9fa48 finally hook the engine localization on ios
koda
parents: 6415
diff changeset
   117
    NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt",[[NSLocale preferredLanguages] objectAtIndex:0]];
5206
db775bddf771 settings.plist is no more, long live nsuserdefaults
koda
parents: 5195
diff changeset
   118
    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
   119
6624
e049b5bb0ad1 BUUUUURN OBJC AMMOMENU BUUUURNhg diff! (on a separate note, this reduces the codesize by ~37k)
koda
parents: 6615
diff changeset
   120
    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
   121
    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
   122
    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
   123
6209
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6084
diff changeset
   124
    NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", (int)(width * screenScale)];
074ab6ebcb3e restore runtime compatibility with ios 3.2
koda
parents: 6084
diff changeset
   125
    NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", (int)(height * screenScale)];
6344
cba81e10235c iOS works again (also native touch interface \o/)
koda
parents: 6328
diff changeset
   126
    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
   127
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
   128
    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
   129
    NSInteger tmpQuality;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   130
    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
   131
        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
   132
    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
   133
        tmpQuality = 0x00000002 | 0x00000040;                                           // rqBlurryLand | rqKillFlakes
5709
36cf87a4f6ae fix for retina display devices
koda
parents: 5696
diff changeset
   134
    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
   135
        tmpQuality = 0x00000002;                                                        // rqBlurryLand
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   136
    else                                                                                                        // = everything else
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   137
        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
   138
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
   139
    // 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
   140
    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
   141
    // 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
   142
    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
   143
        tmpQuality = tmpQuality | 0x00000400;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   144
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   145
    // prevents using an empty nickname
5206
db775bddf771 settings.plist is no more, long live nsuserdefaults
koda
parents: 5195
diff changeset
   146
    NSString *username = [settings objectForKey:@"username"];
5154
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   147
    if ([username length] == 0)
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   148
        username = [NSString stringWithFormat:@"MobileUser-%@",ipcString];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   149
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   150
    gameArgs[ 0] = [ipcString UTF8String];                                                      //ipcPort
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   151
    gameArgs[ 1] = [horizontalSize UTF8String];                                                 //cScreenWidth
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   152
    gameArgs[ 2] = [verticalSize UTF8String];                                                   //cScreenHeight
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   153
    gameArgs[ 3] = [[NSString stringWithFormat:@"%d",tmpQuality] UTF8String];                   //quality
6527
d19c6af9fa48 finally hook the engine localization on ios
koda
parents: 6415
diff changeset
   154
    gameArgs[ 4] = [localeString UTF8String];                                                   //cLocaleFName
5154
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   155
    gameArgs[ 5] = [username UTF8String];                                                       //UserNick
5206
db775bddf771 settings.plist is no more, long live nsuserdefaults
koda
parents: 5195
diff changeset
   156
    gameArgs[ 6] = [[[settings objectForKey:@"sound"] stringValue] UTF8String];                 //isSoundEnabled
db775bddf771 settings.plist is no more, long live nsuserdefaults
koda
parents: 5195
diff changeset
   157
    gameArgs[ 7] = [[[settings objectForKey:@"music"] stringValue] UTF8String];                 //isMusicEnabled
db775bddf771 settings.plist is no more, long live nsuserdefaults
koda
parents: 5195
diff changeset
   158
    gameArgs[ 8] = [[[settings objectForKey:@"alternate"] stringValue] UTF8String];             //cAltDamage
6344
cba81e10235c iOS works again (also native touch interface \o/)
koda
parents: 6328
diff changeset
   159
    gameArgs[ 9] = [resourcePath UTF8String];                                                   //PathPrefix
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
   160
    gameArgs[10] = ([HWUtils gameType] == gtSave) ? [self.savePath UTF8String] : NULL;          //recordFileName
5154
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   161
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   162
    [verticalSize release];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   163
    [horizontalSize release];
6344
cba81e10235c iOS works again (also native touch interface \o/)
koda
parents: 6328
diff changeset
   164
    [resourcePath release];
5154
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   165
    [localeString release];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   166
    [ipcString release];
5155
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   167
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
   168
    [HWUtils setGameStatus:gsLoading];
5194
851c6fbb44e6 small fix for starting the ios game
koda
parents: 5177
diff changeset
   169
6265
a6944f94c19f aaand remove also ipcport from the class interface as well
koda
parents: 6263
diff changeset
   170
    // this is the pascal function that starts the game
5155
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   171
    Game(gameArgs);
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
   172
    [self lateEngineLaunch];
5155
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   173
}
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   174
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
   175
-(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
   176
    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
   177
    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
   178
    releaseAndNil(proto);
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
   179
    [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
   180
}
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
   181
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
   182
#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
   183
#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
   184
+(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
   185
    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
   186
}
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
   187
6321
5a0416e5a6de further engine interaction refactoring
koda
parents: 6301
diff changeset
   188
+(void) startGame:(TGameType) type atPath:(NSString *)path withOptions:(NSDictionary *)config {
5a0416e5a6de further engine interaction refactoring
koda
parents: 6301
diff changeset
   189
    [HWUtils setGameType:type];
6337
84e7d1a5e3df in class methods you can call [self alloc], as per objc specifications
koda
parents: 6321
diff changeset
   190
    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
   191
    [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
   192
    [bridge earlyEngineLaunch:config];
6321
5a0416e5a6de further engine interaction refactoring
koda
parents: 6301
diff changeset
   193
    [bridge release];
5a0416e5a6de further engine interaction refactoring
koda
parents: 6301
diff changeset
   194
}
5a0416e5a6de further engine interaction refactoring
koda
parents: 6301
diff changeset
   195
6266
b02a1e92dba2 convert gameinterfacebridge in simple-to-use class methods
koda
parents: 6265
diff changeset
   196
+(void) startLocalGame:(NSDictionary *)withOptions {
5155
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   197
    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   198
    [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
   199
    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
   200
    [outputFormatter release];
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   201
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
   202
    // 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
   203
    if ([[NSFileManager defaultManager] fileExistsAtPath:savePath])
ec41637ceb64 don't keep track of the savepath and of engineprotocol objects
koda
parents: 6261
diff changeset
   204
        [[NSFileManager defaultManager] removeItemAtPath:savePath error:nil];
5158
4941df038b95 stats implemented once again! refactoring complete \o/
koda
parents: 5157
diff changeset
   205
6321
5a0416e5a6de further engine interaction refactoring
koda
parents: 6301
diff changeset
   206
    [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
   207
    [savePath release];
5155
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   208
}
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   209
6266
b02a1e92dba2 convert gameinterfacebridge in simple-to-use class methods
koda
parents: 6265
diff changeset
   210
+(void) startSaveGame:(NSString *)atPath {
6321
5a0416e5a6de further engine interaction refactoring
koda
parents: 6301
diff changeset
   211
    [self startGame:gtSave atPath:atPath withOptions:nil];
5155
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   212
}
f2165724605c more refactoring, less warnings, less stuff kept around
koda
parents: 5154
diff changeset
   213
6266
b02a1e92dba2 convert gameinterfacebridge in simple-to-use class methods
koda
parents: 6265
diff changeset
   214
+(void) startMissionGame:(NSString *)withScript {
6084
e692c0348e74 make the missions/trainings start
koda
parents: 6083
diff changeset
   215
    NSString *missionPath = [[NSString alloc] initWithFormat:@"escript Missions/Training/%@.lua",withScript];
6263
ec41637ceb64 don't keep track of the savepath and of engineprotocol objects
koda
parents: 6261
diff changeset
   216
    NSDictionary *missionLine = [[NSDictionary alloc] initWithObjectsAndKeys:missionPath,@"mission_command",nil];
6084
e692c0348e74 make the missions/trainings start
koda
parents: 6083
diff changeset
   217
    [missionPath release];
6263
ec41637ceb64 don't keep track of the savepath and of engineprotocol objects
koda
parents: 6261
diff changeset
   218
6321
5a0416e5a6de further engine interaction refactoring
koda
parents: 6301
diff changeset
   219
    [self startGame:gtMission atPath:nil withOptions:missionLine];
6263
ec41637ceb64 don't keep track of the savepath and of engineprotocol objects
koda
parents: 6261
diff changeset
   220
    [missionLine release];
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents: 6078
diff changeset
   221
}
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents: 6078
diff changeset
   222
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
   223
+(void) startSimpleGame {
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
   224
    srand(time(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
   225
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
   226
    // generate a seed
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
   227
    CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
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
   228
    NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
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
   229
    CFRelease(uuid);
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
   230
    NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed];
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
   231
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
   232
    // 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
   233
    NSArray *listOfMaps = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() 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
   234
    NSString *mapName = [listOfMaps objectAtIndex:random()%[listOfMaps count]];
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
   235
    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
   236
    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
   237
    [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
   238
    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
   239
    [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
   240
    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
   241
    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
   242
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
   243
    // 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
   244
    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
   245
    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
   246
    do {
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
   247
        firstColorIndex = random()%[colorArray count];
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
   248
        secondColorIndex = random()%[colorArray count];
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
   249
    } 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
   250
    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
   251
    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
   252
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
   253
    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
   254
                                                                           [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
   255
                                                                           @"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
   256
    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
   257
                                                                            [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
   258
                                                                            @"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
   259
    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
   260
    [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
   261
    [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
   262
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
   263
    // 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
   264
    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
   265
                                    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
   266
                                    @"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
   267
                                    @"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
   268
                                    @"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
   269
                                    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
   270
                                    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
   271
                                    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
   272
                                    @"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
   273
                                    @"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
   274
                                    @"",@"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
   275
                                    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
   276
    [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
   277
    [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
   278
    [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
   279
    [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
   280
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
    // 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
   282
    [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
   283
    [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
   284
}
5154
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   285
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   286
@end