project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
changeset 6719 d2afc6b2d88e
parent 6709 018539298042
child 6822 206db098f8c5
equal deleted inserted replaced
6718:686ebfd50f56 6719:d2afc6b2d88e
   224 
   224 
   225     [self startGame:gtMission atPath:nil withOptions:missionLine];
   225     [self startGame:gtMission atPath:nil withOptions:missionLine];
   226     [missionLine release];
   226     [missionLine release];
   227 }
   227 }
   228 
   228 
       
   229 +(void) startSimpleGame {
       
   230     srand(time(0));
       
   231 
       
   232     // generate a seed
       
   233     CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
       
   234     NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
       
   235     CFRelease(uuid);
       
   236     NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed];
       
   237 
       
   238     // pick a random static map
       
   239     NSArray *listOfMaps = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL];
       
   240     NSString *mapName = [listOfMaps objectAtIndex:random()%[listOfMaps count]];
       
   241     NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg",MAPS_DIRECTORY(),mapName];
       
   242     NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL];
       
   243     [fileCfg release];
       
   244     NSArray *split = [contents componentsSeparatedByString:@"\n"];
       
   245     [contents release];
       
   246     NSString *themeCommand = [[NSString alloc] initWithFormat:@"etheme %@", [split objectAtIndex:0]];
       
   247     NSString *staticMapCommand = [[NSString alloc] initWithFormat:@"emap %@", mapName];
       
   248 
       
   249     // select teams with two different colors
       
   250     NSArray *colorArray = [HWUtils teamColors];
       
   251     NSInteger firstColorIndex, secondColorIndex;
       
   252     do {
       
   253         firstColorIndex = random()%[colorArray count];
       
   254         secondColorIndex = random()%[colorArray count];
       
   255     } while (firstColorIndex == secondColorIndex);
       
   256     unsigned int firstColor = [[colorArray objectAtIndex:firstColorIndex] intValue];
       
   257     unsigned int secondColor = [[colorArray objectAtIndex:secondColorIndex] intValue];
       
   258 
       
   259     NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:4],@"number",
       
   260                                                                            [NSNumber numberWithUnsignedInt:firstColor],@"color",
       
   261                                                                            @"Ninjas.plist",@"team",nil];
       
   262     NSDictionary *secondTeam = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:4],@"number",
       
   263                                                                             [NSNumber numberWithUnsignedInt:secondColor],@"color",
       
   264                                                                             @"Robots.plist",@"team",nil];
       
   265     NSArray *listOfTeams = [[NSArray alloc] initWithObjects:firstTeam,secondTeam,nil];
       
   266     [firstTeam release];
       
   267     [secondTeam release];
       
   268 
       
   269     // create the configuration
       
   270     NSDictionary *gameDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
       
   271                                     seedCmd,@"seed_command",
       
   272                                     @"e$template_filter 0",@"templatefilter_command",
       
   273                                     @"e$mapgen 0",@"mapgen_command",
       
   274                                     @"e$maze_size 0",@"mazesize_command",
       
   275                                     themeCommand,@"theme_command",
       
   276                                     staticMapCommand,@"staticmap_command",
       
   277                                     listOfTeams,@"teams_list",
       
   278                                     @"Default.plist",@"scheme",
       
   279                                     @"Default.plist",@"weapon",
       
   280                                     @"",@"mission_command",
       
   281                                     nil];
       
   282     [listOfTeams release];
       
   283     [staticMapCommand release];
       
   284     [themeCommand release];
       
   285     [seedCmd release];
       
   286 
       
   287     // launch game
       
   288     [GameInterfaceBridge startLocalGame:gameDictionary];
       
   289     [gameDictionary release];
       
   290 }
   229 
   291 
   230 @end
   292 @end