project_files/HedgewarsMobile/Classes/CommodityFunctions.m
author koda
Sun, 10 Oct 2010 22:32:01 +0200
changeset 3948 24daa33a3114
parent 3941 017b2b31e1c6
child 3971 5c82ee165ed5
permissions -rw-r--r--
some rethinking of initial menu presentation and initial orientation (also merging images should be threadsafe now)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
     1
/*
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
     4
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
     8
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    12
 * GNU General Public License for more details.
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    13
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    14
 * You should have received a copy of the GNU General Public License
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    15
 * along with this program; if not, write to the Free Software
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    17
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    18
 * File created on 08/04/2010.
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    19
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3823
diff changeset
    20
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
#import "CommodityFunctions.h"
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
    23
#import <sys/types.h>
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
    24
#import <sys/sysctl.h>
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
#import <mach/mach.h>
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
#import <mach/mach_host.h>
3783
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
    27
#import "AudioToolbox/AudioToolbox.h"
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3917
diff changeset
    28
#import "PascalImports.h"
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
void createTeamNamed (NSString *nameWithoutExt) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
    NSString *teamsDirectory = TEAMS_DIRECTORY();
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    32
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
    if (![[NSFileManager defaultManager] fileExistsAtPath: teamsDirectory]) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    34
        [[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    35
                                  withIntermediateDirectories:NO
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    36
                                                   attributes:nil
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
                                                        error:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    39
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3917
diff changeset
    40
    NSMutableArray *hedgehogs = [[NSMutableArray alloc] initWithCapacity: HW_getMaxNumberOfHogs()];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    41
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3917
diff changeset
    42
    for (int i = 0; i < HW_getMaxNumberOfHogs(); i++) {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
        NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
        NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:0],@"level",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
                             hogName,@"hogname", @"NoHat",@"hat", nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
        [hogName release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
        [hedgehogs addObject:hog];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
        [hog release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    50
3660
bc125bea5849 complete settings page rework
koda
parents: 3621
diff changeset
    51
    NSDictionary *theTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"0",@"hash",
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
                             @"Statue",@"grave", @"Plane",@"fort", @"Default",@"voicepack",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
                             @"hedgewars",@"flag", hedgehogs,@"hedgehogs", nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
    [hedgehogs release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    55
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", teamsDirectory, nameWithoutExt];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
    [theTeam writeToFile:teamFile atomically:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
    [teamFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
    [theTeam release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    63
void createWeaponNamed (NSString *nameWithoutExt, int type) {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
    NSString *weaponsDirectory = WEAPONS_DIRECTORY();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
    if (![[NSFileManager defaultManager] fileExistsAtPath: weaponsDirectory]) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    67
        [[NSFileManager defaultManager] createDirectoryAtPath:weaponsDirectory
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    68
                                  withIntermediateDirectories:NO
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    69
                                                   attributes:nil
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
                                                        error:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
    72
3778
2e61bb50cc57 add a nice group of hogs in lobby page
koda
parents: 3737
diff changeset
    73
    NSDictionary *theWeapon = nil;
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    74
    switch (type) {
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    75
        case 0: //default
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    76
            theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
3823
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
    77
                         @"939192942219912103223511100120100000021111010101",@"ammostore_initialqt",
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
    78
                         @"040504054160065554655446477657666666615551010111",@"ammostore_probability",
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    79
                         @"000000000000020550000004000700400000000020000000",@"ammostore_delay",
3823
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
    80
                         @"131111031211111112311411111111111111121111110111",@"ammostore_crate", nil];
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    81
            break;
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    82
        case 1: //crazy
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    83
            theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
3823
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
    84
                         @"999999999999999999299999999999999929999999990999",@"ammostore_initialqt",
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
    85
                         @"111111011111111111111111111111111111111111110111",@"ammostore_probability",
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    86
                         @"000000000000000000000000000000000000000000000000",@"ammostore_delay",
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    87
                         @"131111031211111112311411111111111111121111010111",@"ammostore_crate", nil];
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    88
            break;
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    89
        case 2: //pro mode
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    90
            theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
3878
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
    91
                         @"909000900000000000000900000000000000000000000000",@"ammostore_initialqt",
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    92
                         @"000000000000000000000000000000000000000000000000",@"ammostore_probability",
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    93
                         @"000000000000020550000004000700400000000020000000",@"ammostore_delay",
3823
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
    94
                         @"111111111111111111111111111111111111111110010111",@"ammostore_crate", nil];
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    95
            break;
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    96
        case 3: //shoppa
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    97
            theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    98
                         @"000000990000000000000000000000000000000000000000",@"ammostore_initialqt",
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
    99
                         @"444441004424440221011212122242200000000200040001",@"ammostore_probability",
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   100
                         @"000000000000000000000000000000000000000000000000",@"ammostore_delay",
3823
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
   101
                         @"111111111111111111111111111111111111111110110111",@"ammostore_crate", nil];
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   102
            break;
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   103
        case 4: //basketball
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   104
            theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
3823
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
   105
                         @"939192942219912103223511100120100000021111010100",@"ammostore_initialqt",
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   106
                         @"000000000000000000000000000000000000000000000000",@"ammostore_probability",
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   107
                         @"000000000000000550000004000700400000000020000000",@"ammostore_delay",
3823
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
   108
                         @"111111111111111111111111111111111111111111110111",@"ammostore_crate", nil];
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   109
            break;
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   110
        case 5: //minefield
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   111
            theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   112
                         @"000000990009000000030000000000000000000000000000",@"ammostore_initialqt",
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   113
                         @"000000000000000000000000000000000000000000000000",@"ammostore_probability",
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   114
                         @"000000000000020550000004000700400000000020000000",@"ammostore_delay",
3823
cca9bfb88a24 also remove sinegun from the ifrontend for whatever reason
koda
parents: 3783
diff changeset
   115
                         @"111111111111111111111111111111111111111111110111",@"ammostore_crate", nil];
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   116
            break;
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   117
        default:
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   118
            NSLog(@"Nope");
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   119
            break;
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   120
    }
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3697
diff changeset
   121
    
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
    NSString *weaponFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", weaponsDirectory, nameWithoutExt];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   123
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
    [theWeapon writeToFile:weaponFile atomically:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
    [weaponFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
    [theWeapon release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   129
void createSchemeNamed (NSString *nameWithoutExt) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
    NSString *schemesDirectory = SCHEMES_DIRECTORY();
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   131
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
    if (![[NSFileManager defaultManager] fileExistsAtPath: schemesDirectory]) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   133
        [[NSFileManager defaultManager] createDirectoryAtPath:schemesDirectory
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   134
                                  withIntermediateDirectories:NO
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   135
                                                   attributes:nil
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   136
                                                        error:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
    }
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   138
    
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   139
    NSMutableArray *basicArray  = [[NSMutableArray alloc] initWithObjects:
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   140
                                   [NSNumber numberWithInt:100],      //damagemodifier
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   141
                                   [NSNumber numberWithInt:45],       //turntime
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   142
                                   [NSNumber numberWithInt:100],      //initialhealth
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   143
                                   [NSNumber numberWithInt:15],       //suddendeathtimeout
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   144
                                   [NSNumber numberWithInt:5],        //cratedrops
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   145
                                   [NSNumber numberWithInt:3],        //minestime
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   146
                                   [NSNumber numberWithInt:4],        //mines
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   147
                                   [NSNumber numberWithInt:0],        //dudmines
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   148
                                   [NSNumber numberWithInt:2],        //explosives
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   149
                                   nil];
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   150
    
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   151
    NSMutableArray *gamemodArray= [[NSMutableArray alloc] initWithObjects:
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   152
                                   [NSNumber numberWithBool:NO],      //fortmode
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   153
                                   [NSNumber numberWithBool:NO],      //divideteam
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   154
                                   [NSNumber numberWithBool:NO],      //solidland
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   155
                                   [NSNumber numberWithBool:NO],      //addborder
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   156
                                   [NSNumber numberWithBool:NO],      //lowgravity
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   157
                                   [NSNumber numberWithBool:NO],      //lasersight
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   158
                                   [NSNumber numberWithBool:NO],      //invulnerable
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   159
                                   [NSNumber numberWithBool:YES],     //addmines
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   160
                                   [NSNumber numberWithBool:NO],      //vampirism
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   161
                                   [NSNumber numberWithBool:NO],      //karma
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   162
                                   [NSNumber numberWithBool:NO],      //artillery
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   163
                                   [NSNumber numberWithBool:YES],     //randomorder
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   164
                                   [NSNumber numberWithBool:NO],      //king
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   165
                                   [NSNumber numberWithBool:NO],      //placehedgehogs
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   166
                                   [NSNumber numberWithBool:NO],      //clansharesammo
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   167
                                   [NSNumber numberWithBool:NO],      //disablegirders
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   168
                                   [NSNumber numberWithBool:NO],      //disablelandobjects
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   169
                                   [NSNumber numberWithBool:NO],      //aisurvival
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   170
                                   nil];
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   171
    
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   172
    NSMutableDictionary *theScheme = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   173
                                      basicArray,@"basic",
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   174
                                      gamemodArray,@"gamemod",
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   175
                                      nil];
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   176
    [gamemodArray release];
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   177
    [basicArray release];
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   178
    
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   179
    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", schemesDirectory, nameWithoutExt];
3781
2bfda544ae48 modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents: 3778
diff changeset
   180
    
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   181
    [theScheme writeToFile:schemeFile atomically:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   182
    [schemeFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   183
    [theScheme release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   184
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   185
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3930
diff changeset
   186
BOOL inline rotationManager (UIInterfaceOrientation interfaceOrientation) {
3551
d4de36b3801a moar zoom, fixed fort mode, other glitches
koda
parents: 3547
diff changeset
   187
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) ||
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   188
           (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   189
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   190
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3930
diff changeset
   191
NSInteger inline randomPort () {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   192
    srandom(time(NULL));
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   193
    return (random() % 64511) + 1024;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   194
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   195
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   196
void popError (const char *title, const char *message) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   197
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithUTF8String:title]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   198
                                                    message:[NSString stringWithUTF8String:message]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   199
                                                   delegate:nil
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   200
                                          cancelButtonTitle:@"Ok"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   201
                                          otherButtonTitles:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   202
    [alert show];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   203
    [alert release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   204
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   205
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   206
// by http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   207
void print_free_memory () {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   208
    mach_port_t host_port;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   209
    mach_msg_type_number_t host_size;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   210
    vm_size_t pagesize;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   211
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   212
    host_port = mach_host_self();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   213
    host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   214
    host_page_size(host_port, &pagesize);
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   215
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   216
    vm_statistics_data_t vm_stat;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   217
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   218
    if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   219
        DLog(@"Failed to fetch vm statistics");
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   220
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   221
    /* Stats in bytes */
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   222
    natural_t mem_used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pagesize;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   223
    natural_t mem_free = vm_stat.free_count * pagesize;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   224
    natural_t mem_total = mem_used + mem_free;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   225
    DLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   226
}
3668
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3660
diff changeset
   227
3930
8b00b4f93242 remove a useless field from weaponfile format
koda
parents: 3926
diff changeset
   228
BOOL inline isApplePhone () {
3668
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3660
diff changeset
   229
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3660
diff changeset
   230
}
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   231
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   232
NSString *modelType () {
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   233
    size_t size;
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   234
    // set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   235
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   236
    char *name = (char *)malloc(sizeof(char) * size);
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   237
    // get the platform name
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   238
    sysctlbyname("hw.machine", name, &size, NULL, 0);
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   239
    NSString *modelId = [NSString stringWithUTF8String:name];
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   240
    free(name);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   241
3670
4c673e57f0d7 use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents: 3668
diff changeset
   242
    return modelId;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3670
diff changeset
   243
}
3783
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   244
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   245
void playSound (NSString *snd) {
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   246
    //Get the filename of the sound file:
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   247
    NSString *path = [NSString stringWithFormat:@"%@/%@.wav",[[NSBundle mainBundle] resourcePath],snd];
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   248
    
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   249
    //declare a system sound id
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   250
    SystemSoundID soundID;
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   251
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   252
    //Get a URL for the sound file
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   253
    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   254
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   255
    //Use audio sevices to create the sound
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   256
    AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   257
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   258
    //Use audio services to play the sound
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3781
diff changeset
   259
    AudioServicesPlaySystemSound(soundID);
3917
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   260
}
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   261
3941
017b2b31e1c6 integrate nicely with external display
koda
parents: 3940
diff changeset
   262
NSArray inline *getAvailableColors(void) {
3917
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   263
    return [NSArray arrayWithObjects:[NSNumber numberWithUnsignedInt:0x4376e9],     // bluette
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   264
                                     [NSNumber numberWithUnsignedInt:0x3e9321],     // greeeen
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   265
                                     [NSNumber numberWithUnsignedInt:0xa23dbb],     // violett
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   266
                                     [NSNumber numberWithUnsignedInt:0xff9329],     // oranngy
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   267
                                     [NSNumber numberWithUnsignedInt:0xdd0000],     // reddish
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   268
                                     [NSNumber numberWithUnsignedInt:0x737373],     // graaaay
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   269
                                     [NSNumber numberWithUnsignedInt:0xbba23d],     // gold$$$
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   270
                                     [NSNumber numberWithUnsignedInt:0x3da2bb],     // cyannnn  
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   271
                                     nil];
4c243b1eac97 playing a bit with colors
koda
parents: 3878
diff changeset
   272
}