project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
branchios-revival
changeset 11206 2e80c9861818
parent 11199 3465047397da
child 11219 c51ecb9bcf05
equal deleted inserted replaced
11205:9fd7b8d3cf4d 11206:2e80c9861818
   250     [self startGame:gtMission atPath:nil withOptions:missionLine];
   250     [self startGame:gtMission atPath:nil withOptions:missionLine];
   251     [missionLine release];
   251     [missionLine release];
   252 }
   252 }
   253 
   253 
   254 +(void) startSimpleGame {
   254 +(void) startSimpleGame {
   255     srand(time(0));
       
   256 
       
   257     // generate a seed
   255     // generate a seed
   258     CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
   256     CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
   259     NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
   257     NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
   260     CFRelease(uuid);
   258     CFRelease(uuid);
   261     NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed];
   259     NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed];
   262     [seed release];
   260     [seed release];
   263 
   261 
   264     // pick a random static map
   262     // pick a random static map
   265     NSArray *listOfMaps = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL];
   263     NSArray *listOfMaps = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL];
   266     NSString *mapName = [listOfMaps objectAtIndex:random()%[listOfMaps count]];
   264     NSString *mapName = [listOfMaps objectAtIndex:arc4random_uniform((int)[listOfMaps count])];
   267     NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg",MAPS_DIRECTORY(),mapName];
   265     NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg",MAPS_DIRECTORY(),mapName];
   268     NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL];
   266     NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL];
   269     [fileCfg release];
   267     [fileCfg release];
   270     NSArray *split = [contents componentsSeparatedByString:@"\n"];
   268     NSArray *split = [contents componentsSeparatedByString:@"\n"];
   271     [contents release];
   269     [contents release];
   274 
   272 
   275     // select teams with two different colors
   273     // select teams with two different colors
   276     NSArray *colorArray = [HWUtils teamColors];
   274     NSArray *colorArray = [HWUtils teamColors];
   277     NSInteger firstColorIndex, secondColorIndex;
   275     NSInteger firstColorIndex, secondColorIndex;
   278     do {
   276     do {
   279         firstColorIndex = random()%[colorArray count];
   277         firstColorIndex = arc4random_uniform((int)[colorArray count]);
   280         secondColorIndex = random()%[colorArray count];
   278         secondColorIndex = arc4random_uniform((int)[colorArray count]);
   281     } while (firstColorIndex == secondColorIndex);
   279     } while (firstColorIndex == secondColorIndex);
   282     unsigned int firstColor = [[colorArray objectAtIndex:firstColorIndex] intValue];
   280     unsigned int firstColor = [[colorArray objectAtIndex:firstColorIndex] intValue];
   283     unsigned int secondColor = [[colorArray objectAtIndex:secondColorIndex] intValue];
   281     unsigned int secondColor = [[colorArray objectAtIndex:secondColorIndex] intValue];
   284 
   282 
   285     NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:4],@"number",
   283     NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:4],@"number",