author | koda |
Fri, 03 Sep 2010 02:03:44 +0200 | |
changeset 3823 | cca9bfb88a24 |
parent 3783 | 8e9daf967406 |
child 3829 | 81db3c85784b |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// CommodityFunctions.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 08/04/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#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
|
10 |
#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
|
11 |
#import <sys/sysctl.h> |
3547 | 12 |
#import <mach/mach.h> |
13 |
#import <mach/mach_host.h> |
|
3783 | 14 |
#import "AudioToolbox/AudioToolbox.h" |
3547 | 15 |
|
16 |
void createTeamNamed (NSString *nameWithoutExt) { |
|
17 |
NSString *teamsDirectory = TEAMS_DIRECTORY(); |
|
3697 | 18 |
|
3547 | 19 |
if (![[NSFileManager defaultManager] fileExistsAtPath: teamsDirectory]) { |
3697 | 20 |
[[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory |
21 |
withIntermediateDirectories:NO |
|
22 |
attributes:nil |
|
3547 | 23 |
error:NULL]; |
24 |
} |
|
3697 | 25 |
|
3547 | 26 |
NSMutableArray *hedgehogs = [[NSMutableArray alloc] initWithCapacity: MAX_HOGS]; |
3697 | 27 |
|
3547 | 28 |
for (int i = 0; i < MAX_HOGS; i++) { |
29 |
NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i]; |
|
30 |
NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:0],@"level", |
|
31 |
hogName,@"hogname", @"NoHat",@"hat", nil]; |
|
32 |
[hogName release]; |
|
33 |
[hedgehogs addObject:hog]; |
|
34 |
[hog release]; |
|
35 |
} |
|
3697 | 36 |
|
3660 | 37 |
NSDictionary *theTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"0",@"hash", |
3547 | 38 |
@"Statue",@"grave", @"Plane",@"fort", @"Default",@"voicepack", |
39 |
@"hedgewars",@"flag", hedgehogs,@"hedgehogs", nil]; |
|
40 |
[hedgehogs release]; |
|
3697 | 41 |
|
3547 | 42 |
NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", teamsDirectory, nameWithoutExt]; |
43 |
||
44 |
[theTeam writeToFile:teamFile atomically:YES]; |
|
45 |
[teamFile release]; |
|
46 |
[theTeam release]; |
|
47 |
} |
|
48 |
||
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
|
49 |
void createWeaponNamed (NSString *nameWithoutExt, int type) { |
3547 | 50 |
NSString *weaponsDirectory = WEAPONS_DIRECTORY(); |
51 |
||
52 |
if (![[NSFileManager defaultManager] fileExistsAtPath: weaponsDirectory]) { |
|
3697 | 53 |
[[NSFileManager defaultManager] createDirectoryAtPath:weaponsDirectory |
54 |
withIntermediateDirectories:NO |
|
55 |
attributes:nil |
|
3547 | 56 |
error:NULL]; |
57 |
} |
|
3697 | 58 |
|
3778 | 59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version", |
3823
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
64 |
@"939192942219912103223511100120100000021111010101",@"ammostore_initialqt", |
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
65 |
@"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
|
66 |
@"000000000000020550000004000700400000000020000000",@"ammostore_delay", |
3823
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
67 |
@"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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version", |
3823
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
72 |
@"999999999999999999299999999999999929999999990999",@"ammostore_initialqt", |
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
73 |
@"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
|
74 |
@"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
|
75 |
@"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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version", |
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
|
80 |
@"909000900000000000000900000000000000000000090000",@"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
|
81 |
@"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
|
82 |
@"000000000000020550000004000700400000000020000000",@"ammostore_delay", |
3823
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
83 |
@"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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version", |
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 |
@"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
|
89 |
@"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
|
90 |
@"000000000000000000000000000000000000000000000000",@"ammostore_delay", |
3823
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
91 |
@"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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version", |
3823
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
96 |
@"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
|
97 |
@"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
|
98 |
@"000000000000000550000004000700400000000020000000",@"ammostore_delay", |
3823
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
99 |
@"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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version", |
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 |
@"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
|
105 |
@"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
|
106 |
@"000000000000020550000004000700400000000020000000",@"ammostore_delay", |
3823
cca9bfb88a24
also remove sinegun from the ifrontend for whatever reason
koda
parents:
3783
diff
changeset
|
107 |
@"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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
} |
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 |
|
3547 | 114 |
NSString *weaponFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", weaponsDirectory, nameWithoutExt]; |
3697 | 115 |
|
3547 | 116 |
[theWeapon writeToFile:weaponFile atomically:YES]; |
117 |
[weaponFile release]; |
|
118 |
[theWeapon release]; |
|
119 |
} |
|
120 |
||
121 |
void createSchemeNamed (NSString *nameWithoutExt) { |
|
122 |
NSString *schemesDirectory = SCHEMES_DIRECTORY(); |
|
3697 | 123 |
|
3547 | 124 |
if (![[NSFileManager defaultManager] fileExistsAtPath: schemesDirectory]) { |
3697 | 125 |
[[NSFileManager defaultManager] createDirectoryAtPath:schemesDirectory |
126 |
withIntermediateDirectories:NO |
|
127 |
attributes:nil |
|
3547 | 128 |
error:NULL]; |
129 |
} |
|
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
|
130 |
|
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
|
131 |
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
|
132 |
[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
|
133 |
[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
|
134 |
[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
|
135 |
[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
|
136 |
[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
|
137 |
[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
|
138 |
[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
|
139 |
[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
|
140 |
[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
|
141 |
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
|
142 |
|
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 |
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
|
144 |
[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
|
145 |
[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
|
146 |
[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
|
147 |
[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
|
148 |
[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
|
149 |
[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
|
150 |
[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
|
151 |
[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
|
152 |
[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
|
153 |
[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
|
154 |
[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
|
155 |
[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
|
156 |
[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
|
157 |
[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
|
158 |
[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
|
159 |
[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
|
160 |
[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
|
161 |
[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
|
162 |
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
|
163 |
|
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 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
[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
|
169 |
[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
|
170 |
|
3547 | 171 |
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
|
172 |
|
3547 | 173 |
[theScheme writeToFile:schemeFile atomically:YES]; |
174 |
[schemeFile release]; |
|
175 |
[theScheme release]; |
|
176 |
} |
|
177 |
||
178 |
BOOL rotationManager (UIInterfaceOrientation interfaceOrientation) { |
|
3551 | 179 |
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) || |
3697 | 180 |
(interfaceOrientation == UIInterfaceOrientationLandscapeLeft); |
3547 | 181 |
} |
182 |
||
183 |
NSInteger randomPort () { |
|
184 |
srandom(time(NULL)); |
|
185 |
return (random() % 64511) + 1024; |
|
186 |
} |
|
187 |
||
188 |
void popError (const char *title, const char *message) { |
|
189 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithUTF8String:title] |
|
190 |
message:[NSString stringWithUTF8String:message] |
|
191 |
delegate:nil |
|
192 |
cancelButtonTitle:@"Ok" |
|
193 |
otherButtonTitles:nil]; |
|
194 |
[alert show]; |
|
195 |
[alert release]; |
|
196 |
} |
|
197 |
||
198 |
// by http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html |
|
199 |
void print_free_memory () { |
|
200 |
mach_port_t host_port; |
|
201 |
mach_msg_type_number_t host_size; |
|
202 |
vm_size_t pagesize; |
|
3697 | 203 |
|
3547 | 204 |
host_port = mach_host_self(); |
205 |
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t); |
|
3697 | 206 |
host_page_size(host_port, &pagesize); |
207 |
||
3547 | 208 |
vm_statistics_data_t vm_stat; |
3697 | 209 |
|
3547 | 210 |
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) |
211 |
DLog(@"Failed to fetch vm statistics"); |
|
3697 | 212 |
|
213 |
/* Stats in bytes */ |
|
3547 | 214 |
natural_t mem_used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pagesize; |
215 |
natural_t mem_free = vm_stat.free_count * pagesize; |
|
216 |
natural_t mem_total = mem_used + mem_free; |
|
217 |
DLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total); |
|
218 |
} |
|
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3660
diff
changeset
|
219 |
|
3670
4c673e57f0d7
use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents:
3668
diff
changeset
|
220 |
BOOL isPhone () { |
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3660
diff
changeset
|
221 |
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone); |
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3660
diff
changeset
|
222 |
} |
3670
4c673e57f0d7
use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents:
3668
diff
changeset
|
223 |
|
4c673e57f0d7
use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents:
3668
diff
changeset
|
224 |
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
|
225 |
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
|
226 |
// set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space |
3697 | 227 |
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
|
228 |
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
|
229 |
// 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
|
230 |
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
|
231 |
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
|
232 |
free(name); |
3697 | 233 |
|
3670
4c673e57f0d7
use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents:
3668
diff
changeset
|
234 |
return modelId; |
3697 | 235 |
} |
3783 | 236 |
|
237 |
void playSound (NSString *snd) { |
|
238 |
//Get the filename of the sound file: |
|
239 |
NSString *path = [NSString stringWithFormat:@"%@/%@.wav",[[NSBundle mainBundle] resourcePath],snd]; |
|
240 |
||
241 |
//declare a system sound id |
|
242 |
SystemSoundID soundID; |
|
243 |
||
244 |
//Get a URL for the sound file |
|
245 |
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; |
|
246 |
||
247 |
//Use audio sevices to create the sound |
|
248 |
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID); |
|
249 |
||
250 |
//Use audio services to play the sound |
|
251 |
AudioServicesPlaySystemSound(soundID); |
|
252 |
} |