118 // unpacks ammostore data from the selected ammo.plist to a sequence of engine commands |
118 // unpacks ammostore data from the selected ammo.plist to a sequence of engine commands |
119 -(void) provideAmmoData:(NSString *)ammostoreName forPlayingTeams:(NSInteger) numberOfTeams { |
119 -(void) provideAmmoData:(NSString *)ammostoreName forPlayingTeams:(NSInteger) numberOfTeams { |
120 NSString *weaponPath = [[NSString alloc] initWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),ammostoreName]; |
120 NSString *weaponPath = [[NSString alloc] initWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),ammostoreName]; |
121 NSDictionary *ammoData = [[NSDictionary alloc] initWithContentsOfFile:weaponPath]; |
121 NSDictionary *ammoData = [[NSDictionary alloc] initWithContentsOfFile:weaponPath]; |
122 [weaponPath release]; |
122 [weaponPath release]; |
|
123 |
|
124 // if we're loading an older version of ammos fill the engine message with 0s |
|
125 int diff = HW_getNumberOfWeapons() - [[ammoData objectForKey:@"ammostore_initialqt"] length]; |
123 NSString *update = @""; |
126 NSString *update = @""; |
124 |
127 while ([update length] < diff) |
125 // if we're loading an older version of ammos fill the engine message with 0s |
128 update = [update stringByAppendingString:@"0"]; |
126 int diff = HW_getNumberOfWeapons() - [[ammoData objectForKey:@"version"] intValue]; |
|
127 if (diff != 0) |
|
128 update = [NSString stringWithCharacters:(const unichar*)"0000000000000000000000000000000000" length:diff]; |
|
129 |
129 |
130 NSString *ammloadt = [[NSString alloc] initWithFormat:@"eammloadt %@%@", [ammoData objectForKey:@"ammostore_initialqt"], update]; |
130 NSString *ammloadt = [[NSString alloc] initWithFormat:@"eammloadt %@%@", [ammoData objectForKey:@"ammostore_initialqt"], update]; |
131 [self sendToEngine: ammloadt]; |
131 [self sendToEngine: ammloadt]; |
132 [ammloadt release]; |
132 [ammloadt release]; |
133 |
133 |
141 |
141 |
142 NSString *ammreinf = [[NSString alloc] initWithFormat:@"eammreinf %@%@", [ammoData objectForKey:@"ammostore_crate"], update]; |
142 NSString *ammreinf = [[NSString alloc] initWithFormat:@"eammreinf %@%@", [ammoData objectForKey:@"ammostore_crate"], update]; |
143 [self sendToEngine: ammreinf]; |
143 [self sendToEngine: ammreinf]; |
144 [ammreinf release]; |
144 [ammreinf release]; |
145 |
145 |
146 // sent twice so it applies to both teams |
146 // send this for each team so it applies the same ammostore to all teams |
147 NSString *ammstore = [[NSString alloc] initWithString:@"eammstore"]; |
147 NSString *ammstore = [[NSString alloc] initWithString:@"eammstore"]; |
148 for (int i = 0; i < numberOfTeams; i++) |
148 for (int i = 0; i < numberOfTeams; i++) |
149 [self sendToEngine: ammstore]; |
149 [self sendToEngine: ammstore]; |
150 [ammstore release]; |
150 [ammstore release]; |
151 |
151 |
408 } |
408 } |
409 break; |
409 break; |
410 case 'q': |
410 case 'q': |
411 // game ended, can remove the savefile |
411 // game ended, can remove the savefile |
412 [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
412 [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
413 // so update the relative viewcontroler |
413 // so update the relative viewcontroler and the overlay |
414 [[NSNotificationCenter defaultCenter] postNotificationName:@"removedSave" object:nil]; |
414 [[NSNotificationCenter defaultCenter] postNotificationName:@"removedSave" object:nil]; |
415 // and disable the overlay |
415 // and remove + disable the overlay |
|
416 [[NSNotificationCenter defaultCenter] postNotificationName:@"remove overlay" object:nil]; |
416 setGameRunning(NO); |
417 setGameRunning(NO); |
417 break; |
418 break; |
418 default: |
419 default: |
419 [self dumpRawData:buffer ofSize:msgSize]; |
420 [self dumpRawData:buffer ofSize:msgSize]; |
420 break; |
421 break; |