author | koda |
Thu, 12 May 2011 23:00:26 +0200 | |
changeset 5207 | 4c9ae0f484da |
parent 5206 | db775bddf771 |
child 5376 | ea8a74951948 |
permissions | -rw-r--r-- |
4281 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
4281 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 12/11/2010. |
|
19 |
*/ |
|
20 |
||
21 |
||
22 |
#import "CreationChamber.h" |
|
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
23 |
#import "hwconsts.h" |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
24 |
|
5206 | 25 |
void createSettings () { |
26 |
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
|
27 |
[settings setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"]; |
|
28 |
[settings setObject:[NSNumber numberWithBool:YES] forKey:@"music"]; |
|
29 |
[settings setObject:[NSNumber numberWithBool:YES] forKey:@"sound"]; |
|
30 |
[settings setObject:[NSNumber numberWithBool:NO] forKey:@"classic_menu"]; |
|
31 |
[settings setObject:[NSNumber numberWithBool:YES] forKey:@"enhanced"]; |
|
32 |
[settings setObject:[NSNumber numberWithBool:YES] forKey:@"multitasking"]; |
|
5207
4c9ae0f484da
some general tweaks (more intelligent use of macros and more caching)
koda
parents:
5206
diff
changeset
|
33 |
|
4c9ae0f484da
some general tweaks (more intelligent use of macros and more caching)
koda
parents:
5206
diff
changeset
|
34 |
// don't overwrite these two strings when present |
4c9ae0f484da
some general tweaks (more intelligent use of macros and more caching)
koda
parents:
5206
diff
changeset
|
35 |
if ([settings objectForKey:@"username"] == nil) |
4c9ae0f484da
some general tweaks (more intelligent use of macros and more caching)
koda
parents:
5206
diff
changeset
|
36 |
[settings setObject:@"" forKey:@"username"]; |
4c9ae0f484da
some general tweaks (more intelligent use of macros and more caching)
koda
parents:
5206
diff
changeset
|
37 |
if ([settings objectForKey:@"password"] == nil) |
4c9ae0f484da
some general tweaks (more intelligent use of macros and more caching)
koda
parents:
5206
diff
changeset
|
38 |
[settings setObject:@"" forKey:@"password"]; |
5206 | 39 |
|
40 |
[settings synchronize]; |
|
41 |
} |
|
4281 | 42 |
|
43 |
void createTeamNamed (NSString *nameWithoutExt) { |
|
44 |
NSString *teamsDirectory = TEAMS_DIRECTORY(); |
|
45 |
||
46 |
if (![[NSFileManager defaultManager] fileExistsAtPath: teamsDirectory]) { |
|
47 |
[[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory |
|
48 |
withIntermediateDirectories:NO |
|
49 |
attributes:nil |
|
50 |
error:NULL]; |
|
51 |
} |
|
52 |
||
53 |
NSMutableArray *hedgehogs = [[NSMutableArray alloc] initWithCapacity: HW_getMaxNumberOfHogs()]; |
|
54 |
||
55 |
for (int i = 0; i < HW_getMaxNumberOfHogs(); i++) { |
|
56 |
NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i]; |
|
57 |
NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys: |
|
58 |
[NSNumber numberWithInt:0],@"level", |
|
59 |
hogName,@"hogname", |
|
60 |
@"NoHat",@"hat", |
|
61 |
nil]; |
|
62 |
[hogName release]; |
|
63 |
[hedgehogs addObject:hog]; |
|
64 |
[hog release]; |
|
65 |
} |
|
66 |
||
67 |
NSDictionary *theTeam = [[NSDictionary alloc] initWithObjectsAndKeys: |
|
68 |
@"0",@"hash", |
|
69 |
@"Statue",@"grave", |
|
70 |
@"Plane",@"fort", |
|
71 |
@"Default",@"voicepack", |
|
72 |
@"hedgewars",@"flag", |
|
73 |
hedgehogs,@"hedgehogs", |
|
74 |
nil]; |
|
75 |
[hedgehogs release]; |
|
76 |
||
77 |
NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", teamsDirectory, nameWithoutExt]; |
|
78 |
||
79 |
[theTeam writeToFile:teamFile atomically:YES]; |
|
80 |
[teamFile release]; |
|
81 |
[theTeam release]; |
|
82 |
} |
|
83 |
||
84 |
void createWeaponNamed (NSString *nameWithoutExt, int type) { |
|
85 |
NSString *weaponsDirectory = WEAPONS_DIRECTORY(); |
|
86 |
||
87 |
if (![[NSFileManager defaultManager] fileExistsAtPath: weaponsDirectory]) { |
|
88 |
[[NSFileManager defaultManager] createDirectoryAtPath:weaponsDirectory |
|
89 |
withIntermediateDirectories:NO |
|
90 |
attributes:nil |
|
91 |
error:NULL]; |
|
92 |
} |
|
93 |
||
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
94 |
NSInteger ammolineSize = HW_getNumberOfWeapons(); |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
95 |
NSString *qt, *prob, *delay, *crate; |
4281 | 96 |
switch (type) { |
4607 | 97 |
default: //default |
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
98 |
qt = [[NSString alloc] initWithBytes:AMMOLINE_DEFAULT_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
99 |
prob = [[NSString alloc] initWithBytes:AMMOLINE_DEFAULT_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
100 |
delay = [[NSString alloc] initWithBytes:AMMOLINE_DEFAULT_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
101 |
crate = [[NSString alloc] initWithBytes:AMMOLINE_DEFAULT_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
4281 | 102 |
break; |
103 |
case 1: //crazy |
|
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
104 |
qt = [[NSString alloc] initWithBytes:AMMOLINE_CRAZY_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
105 |
prob = [[NSString alloc] initWithBytes:AMMOLINE_CRAZY_PROB length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
106 |
delay = [[NSString alloc] initWithBytes:AMMOLINE_CRAZY_DELAY length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
107 |
crate = [[NSString alloc] initWithBytes:AMMOLINE_CRAZY_CRATE length:ammolineSize encoding:NSUTF8StringEncoding]; |
4281 | 108 |
break; |
109 |
case 2: //pro mode |
|
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
110 |
qt = [[NSString alloc] initWithBytes:AMMOLINE_PROMODE_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
111 |
prob = [[NSString alloc] initWithBytes:AMMOLINE_PROMODE_PROB length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
112 |
delay = [[NSString alloc] initWithBytes:AMMOLINE_PROMODE_DELAY length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
113 |
crate = [[NSString alloc] initWithBytes:AMMOLINE_PROMODE_CRATE length:ammolineSize encoding:NSUTF8StringEncoding]; |
4281 | 114 |
break; |
115 |
case 3: //shoppa |
|
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
116 |
qt = [[NSString alloc] initWithBytes:AMMOLINE_SHOPPA_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
117 |
prob = [[NSString alloc] initWithBytes:AMMOLINE_SHOPPA_PROB length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
118 |
delay = [[NSString alloc] initWithBytes:AMMOLINE_SHOPPA_DELAY length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
119 |
crate = [[NSString alloc] initWithBytes:AMMOLINE_SHOPPA_CRATE length:ammolineSize encoding:NSUTF8StringEncoding]; |
4281 | 120 |
break; |
121 |
case 4: //clean slate |
|
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
122 |
qt = [[NSString alloc] initWithBytes:AMMOLINE_CLEAN_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
123 |
prob = [[NSString alloc] initWithBytes:AMMOLINE_CLEAN_PROB length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
124 |
delay = [[NSString alloc] initWithBytes:AMMOLINE_CLEAN_DELAY length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
125 |
crate = [[NSString alloc] initWithBytes:AMMOLINE_CLEAN_CRATE length:ammolineSize encoding:NSUTF8StringEncoding]; |
4281 | 126 |
break; |
127 |
case 5: //minefield |
|
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
128 |
qt = [[NSString alloc] initWithBytes:AMMOLINE_MINES_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
129 |
prob = [[NSString alloc] initWithBytes:AMMOLINE_MINES_PROB length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
130 |
delay = [[NSString alloc] initWithBytes:AMMOLINE_MINES_DELAY length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
131 |
crate = [[NSString alloc] initWithBytes:AMMOLINE_MINES_CRATE length:ammolineSize encoding:NSUTF8StringEncoding]; |
4284
57a501a69e5f
update iFrontend with new schemes and weaps, fix up smaller glitches
koda
parents:
4281
diff
changeset
|
132 |
break; |
57a501a69e5f
update iFrontend with new schemes and weaps, fix up smaller glitches
koda
parents:
4281
diff
changeset
|
133 |
case 6: //thinking with portals |
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
134 |
qt = [[NSString alloc] initWithBytes:AMMOLINE_PORTALS_QT length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
135 |
prob = [[NSString alloc] initWithBytes:AMMOLINE_PORTALS_PROB length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
136 |
delay = [[NSString alloc] initWithBytes:AMMOLINE_PORTALS_DELAY length:ammolineSize encoding:NSUTF8StringEncoding]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
137 |
crate = [[NSString alloc] initWithBytes:AMMOLINE_PORTALS_CRATE length:ammolineSize encoding:NSUTF8StringEncoding]; |
4281 | 138 |
break; |
139 |
} |
|
140 |
||
5200
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
141 |
NSDictionary *theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys: qt,@"ammostore_initialqt", |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
142 |
prob,@"ammostore_probability", delay,@"ammostore_delay", crate,@"ammostore_crate", nil]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
143 |
[qt release]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
144 |
[prob release]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
145 |
[delay release]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
146 |
[crate release]; |
7440fe992e73
* move ammo lines from .cpp.in to .h so that it is readable from the ios frontend (and who knows, maybe from other frontends as well)
koda
parents:
5185
diff
changeset
|
147 |
|
4281 | 148 |
NSString *weaponFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", weaponsDirectory, nameWithoutExt]; |
149 |
[theWeapon writeToFile:weaponFile atomically:YES]; |
|
150 |
[weaponFile release]; |
|
151 |
[theWeapon release]; |
|
152 |
} |
|
153 |
||
154 |
void createSchemeNamed (NSString *nameWithoutExt) { |
|
155 |
NSString *schemesDirectory = SCHEMES_DIRECTORY(); |
|
156 |
||
157 |
if (![[NSFileManager defaultManager] fileExistsAtPath: schemesDirectory]) { |
|
158 |
[[NSFileManager defaultManager] createDirectoryAtPath:schemesDirectory |
|
159 |
withIntermediateDirectories:NO |
|
160 |
attributes:nil |
|
161 |
error:NULL]; |
|
162 |
} |
|
163 |
||
5181 | 164 |
// load data to get the size of the arrays and their default values |
5185
7607a64e1853
remove the trailing _en from scheme data and use the macros available instead of creating a string every time
koda
parents:
5181
diff
changeset
|
165 |
NSArray *basicSettings = [[NSArray alloc] initWithContentsOfFile:BASICFLAGS_FILE()]; |
5181 | 166 |
NSMutableArray *basicArray = [[NSMutableArray alloc] initWithCapacity:[basicSettings count]]; |
167 |
for (NSDictionary *basicDict in basicSettings) |
|
168 |
[basicArray addObject:[basicDict objectForKey:@"default"]]; |
|
169 |
[basicSettings release]; |
|
4281 | 170 |
|
5185
7607a64e1853
remove the trailing _en from scheme data and use the macros available instead of creating a string every time
koda
parents:
5181
diff
changeset
|
171 |
NSArray *mods = [[NSArray alloc] initWithContentsOfFile:GAMEMODS_FILE()]; |
5181 | 172 |
NSMutableArray *gamemodArray= [[NSMutableArray alloc] initWithCapacity:[mods count]]; |
173 |
for (int i = 0; i < [mods count]; i++) |
|
174 |
[gamemodArray addObject:[NSNumber numberWithBool:NO]]; |
|
175 |
[mods release]; |
|
176 |
||
177 |
// workaround for randomorder that has to be set to YES |
|
178 |
[gamemodArray replaceObjectAtIndex:11 withObject:[NSNumber numberWithBool:YES]]; |
|
179 |
||
4281 | 180 |
NSMutableDictionary *theScheme = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
181 |
basicArray,@"basic", |
|
182 |
gamemodArray,@"gamemod", |
|
183 |
nil]; |
|
184 |
[gamemodArray release]; |
|
185 |
[basicArray release]; |
|
186 |
||
187 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", schemesDirectory, nameWithoutExt]; |
|
188 |
||
189 |
[theScheme writeToFile:schemeFile atomically:YES]; |
|
190 |
[schemeFile release]; |
|
191 |
[theScheme release]; |
|
192 |
} |