128 } |
128 } |
129 |
129 |
130 // unpacks scheme data from the selected scheme.plist to a sequence of engine commands |
130 // unpacks scheme data from the selected scheme.plist to a sequence of engine commands |
131 -(NSInteger) provideScheme:(NSString *)schemeName { |
131 -(NSInteger) provideScheme:(NSString *)schemeName { |
132 NSString *schemePath = [[NSString alloc] initWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),schemeName]; |
132 NSString *schemePath = [[NSString alloc] initWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),schemeName]; |
133 NSArray *scheme = [[NSArray alloc] initWithContentsOfFile:schemePath]; |
133 NSDictionary *schemeDictionary = [[NSDictionary alloc] initWithContentsOfFile:schemePath]; |
134 [schemePath release]; |
134 [schemePath release]; |
|
135 NSArray *basicArray = [schemeDictionary objectForKey:@"basic"]; |
|
136 NSArray *gamemodArray = [schemeDictionary objectForKey:@"gamemod"]; |
135 int result = 0; |
137 int result = 0; |
136 int i = 0; |
138 int i = 0; |
137 |
139 |
138 if ([[scheme objectAtIndex:i++] boolValue]) |
140 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
139 result |= 0x00000001; |
141 result |= 0x00000001; |
140 if ([[scheme objectAtIndex:i++] boolValue]) |
142 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
141 result |= 0x00000010; |
143 result |= 0x00000010; |
142 if ([[scheme objectAtIndex:i++] boolValue]) |
144 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
143 result |= 0x00000004; |
145 result |= 0x00000004; |
144 if ([[scheme objectAtIndex:i++] boolValue]) |
146 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
145 result |= 0x00000008; |
147 result |= 0x00000008; |
146 if ([[scheme objectAtIndex:i++] boolValue]) |
148 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
147 result |= 0x00000020; |
149 result |= 0x00000020; |
148 if ([[scheme objectAtIndex:i++] boolValue]) |
150 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
149 result |= 0x00000040; |
151 result |= 0x00000040; |
150 if ([[scheme objectAtIndex:i++] boolValue]) |
152 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
151 result |= 0x00000080; |
153 result |= 0x00000080; |
152 if ([[scheme objectAtIndex:i++] boolValue]) |
154 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
153 result |= 0x00000100; |
155 result |= 0x00000100; |
154 if ([[scheme objectAtIndex:i++] boolValue]) |
156 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
155 result |= 0x00000200; |
157 result |= 0x00000200; |
156 if ([[scheme objectAtIndex:i++] boolValue]) |
158 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
157 result |= 0x00000400; |
159 result |= 0x00000400; |
158 if ([[scheme objectAtIndex:i++] boolValue]) |
160 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
159 result |= 0x00000800; |
161 result |= 0x00000800; |
160 if ([[scheme objectAtIndex:i++] boolValue]) |
162 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
161 result |= 0x00002000; |
163 result |= 0x00002000; |
162 if ([[scheme objectAtIndex:i++] boolValue]) |
164 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
163 result |= 0x00004000; |
165 result |= 0x00004000; |
164 if ([[scheme objectAtIndex:i++] boolValue]) |
166 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
165 result |= 0x00008000; |
167 result |= 0x00008000; |
166 if ([[scheme objectAtIndex:i++] boolValue]) |
168 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
167 result |= 0x00010000; |
169 result |= 0x00010000; |
168 if ([[scheme objectAtIndex:i++] boolValue]) |
170 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
169 result |= 0x00020000; |
171 result |= 0x00020000; |
170 if ([[scheme objectAtIndex:i++] boolValue]) |
172 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
171 result |= 0x00080000; |
173 result |= 0x00080000; |
172 if ([[scheme objectAtIndex:i++] boolValue]) |
174 if ([[gamemodArray objectAtIndex:i++] boolValue]) |
173 result |= 0x00100000; |
175 result |= 0x00100000; |
174 |
176 |
175 NSString *flags = [[NSString alloc] initWithFormat:@"e$gmflags %d",result]; |
177 NSString *flags = [[NSString alloc] initWithFormat:@"e$gmflags %d",result]; |
176 [self sendToEngine:flags]; |
178 [self sendToEngine:flags]; |
177 [flags release]; |
179 [flags release]; |
178 |
180 |
179 NSString *dmgMod = [[NSString alloc] initWithFormat:@"e$damagepct %d",[[scheme objectAtIndex:i++] intValue]]; |
181 i = 0; |
|
182 NSString *dmgMod = [[NSString alloc] initWithFormat:@"e$damagepct %d",[[basicArray objectAtIndex:i++] intValue]]; |
180 [self sendToEngine:dmgMod]; |
183 [self sendToEngine:dmgMod]; |
181 [dmgMod release]; |
184 [dmgMod release]; |
182 |
185 |
183 NSString *turnTime = [[NSString alloc] initWithFormat:@"e$turntime %d",[[scheme objectAtIndex:i++] intValue] * 1000]; |
186 NSString *turnTime = [[NSString alloc] initWithFormat:@"e$turntime %d",[[basicArray objectAtIndex:i++] intValue] * 1000]; |
184 [self sendToEngine:turnTime]; |
187 [self sendToEngine:turnTime]; |
185 [turnTime release]; |
188 [turnTime release]; |
186 |
189 |
187 result = [[scheme objectAtIndex:i++] intValue]; // initial health |
190 result = [[basicArray objectAtIndex:i++] intValue]; // initial health |
188 |
191 |
189 NSString *sdTime = [[NSString alloc] initWithFormat:@"e$sd_turns %d",[[scheme objectAtIndex:i++] intValue]]; |
192 NSString *sdTime = [[NSString alloc] initWithFormat:@"e$sd_turns %d",[[basicArray objectAtIndex:i++] intValue]]; |
190 [self sendToEngine:sdTime]; |
193 [self sendToEngine:sdTime]; |
191 [sdTime release]; |
194 [sdTime release]; |
192 |
195 |
193 NSString *crateDrops = [[NSString alloc] initWithFormat:@"e$casefreq %d",[[scheme objectAtIndex:i++] intValue]]; |
196 NSString *crateDrops = [[NSString alloc] initWithFormat:@"e$casefreq %d",[[basicArray objectAtIndex:i++] intValue]]; |
194 [self sendToEngine:crateDrops]; |
197 [self sendToEngine:crateDrops]; |
195 [crateDrops release]; |
198 [crateDrops release]; |
196 |
199 |
197 NSString *minesTime = [[NSString alloc] initWithFormat:@"e$minestime %d",[[scheme objectAtIndex:i++] intValue] * 1000]; |
200 NSString *minesTime = [[NSString alloc] initWithFormat:@"e$minestime %d",[[basicArray objectAtIndex:i++] intValue] * 1000]; |
198 [self sendToEngine:minesTime]; |
201 [self sendToEngine:minesTime]; |
199 [minesTime release]; |
202 [minesTime release]; |
200 |
203 |
201 NSString *minesNumber = [[NSString alloc] initWithFormat:@"e$landadds %d",[[scheme objectAtIndex:i++] intValue]]; |
204 NSString *minesNumber = [[NSString alloc] initWithFormat:@"e$landadds %d",[[basicArray objectAtIndex:i++] intValue]]; |
202 [self sendToEngine:minesNumber]; |
205 [self sendToEngine:minesNumber]; |
203 [minesNumber release]; |
206 [minesNumber release]; |
204 |
207 |
205 |
208 NSString *dudMines = [[NSString alloc] initWithFormat:@"e$minedudpct %d",[[basicArray objectAtIndex:i++] intValue]]; |
206 NSString *dudMines = [[NSString alloc] initWithFormat:@"e$minedudpct %d",[[scheme objectAtIndex:i++] intValue]]; |
|
207 [self sendToEngine:dudMines]; |
209 [self sendToEngine:dudMines]; |
208 [dudMines release]; |
210 [dudMines release]; |
209 |
211 |
210 NSString *explosives = [[NSString alloc] initWithFormat:@"e$explosives %d",[[scheme objectAtIndex:i++] intValue]]; |
212 NSString *explosives = [[NSString alloc] initWithFormat:@"e$explosives %d",[[basicArray objectAtIndex:i++] intValue]]; |
211 [self sendToEngine:explosives]; |
213 [self sendToEngine:explosives]; |
212 [explosives release]; |
214 [explosives release]; |
213 |
215 |
214 [scheme release]; |
216 [schemeDictionary release]; |
215 return result; |
217 return result; |
216 } |
218 } |
217 |
219 |
218 #pragma mark - |
220 #pragma mark - |
219 #pragma mark Thread/Network relevant code |
221 #pragma mark Thread/Network relevant code |