project_files/HedgewarsMobile/Classes/GameSetup.m
changeset 4000 ddc4a09889e7
parent 3996 eb549fd864a5
child 4003 ca0600ab38bf
equal deleted inserted replaced
3999:411e71912f4c 4000:ddc4a09889e7
   163     NSString *schemePath = [[NSString alloc] initWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),schemeName];
   163     NSString *schemePath = [[NSString alloc] initWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),schemeName];
   164     NSDictionary *schemeDictionary = [[NSDictionary alloc] initWithContentsOfFile:schemePath];
   164     NSDictionary *schemeDictionary = [[NSDictionary alloc] initWithContentsOfFile:schemePath];
   165     [schemePath release];
   165     [schemePath release];
   166     NSArray *basicArray = [schemeDictionary objectForKey:@"basic"];
   166     NSArray *basicArray = [schemeDictionary objectForKey:@"basic"];
   167     NSArray *gamemodArray = [schemeDictionary objectForKey:@"gamemod"];
   167     NSArray *gamemodArray = [schemeDictionary objectForKey:@"gamemod"];
       
   168     int i = 0;
   168     int result = 0;
   169     int result = 0;
   169     int i = 0;
   170     int mask = 0x00000004;
   170 
   171 
   171     if ([[gamemodArray objectAtIndex:i++] boolValue])
   172     // pack the gameflags in a single var and send it
   172         result |= 0x00000001;
   173     for (NSNumber *value in gamemodArray) {
   173     if ([[gamemodArray objectAtIndex:i++] boolValue])
   174         if ([value boolValue] == YES)
   174         result |= 0x00000010;
   175             result |= mask;
   175     if ([[gamemodArray objectAtIndex:i++] boolValue])
   176         mask <<= 1;
   176         result |= 0x00000004;
   177     }
   177     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   178         result |= 0x00000008;
       
   179     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   180         result |= 0x00000020;
       
   181     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   182         result |= 0x00000040;
       
   183     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   184         result |= 0x00000080;
       
   185     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   186         result |= 0x00000100;
       
   187     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   188         result |= 0x00000200;
       
   189     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   190         result |= 0x00000400;
       
   191     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   192         result |= 0x00000800;
       
   193     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   194         result |= 0x00002000;
       
   195     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   196         result |= 0x00004000;
       
   197     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   198         result |= 0x00008000;
       
   199     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   200         result |= 0x00010000;
       
   201     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   202         result |= 0x00020000;
       
   203     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   204         result |= 0x00080000;
       
   205     if ([[gamemodArray objectAtIndex:i++] boolValue])
       
   206         result |= 0x00100000;  
       
   207 
       
   208     DLog(@"Sent %d flags",i);
       
   209     NSString *flags = [[NSString alloc] initWithFormat:@"e$gmflags %d",result];
   178     NSString *flags = [[NSString alloc] initWithFormat:@"e$gmflags %d",result];
   210     [self sendToEngine:flags];
   179     [self sendToEngine:flags];
   211     [flags release];
   180     [flags release];
   212 
   181 
   213     i = 0;
       
   214     NSString *dmgMod = [[NSString alloc] initWithFormat:@"e$damagepct %d",[[basicArray objectAtIndex:i++] intValue]];
   182     NSString *dmgMod = [[NSString alloc] initWithFormat:@"e$damagepct %d",[[basicArray objectAtIndex:i++] intValue]];
   215     [self sendToEngine:dmgMod];
   183     [self sendToEngine:dmgMod];
   216     [dmgMod release];
   184     [dmgMod release];
   217 
   185 
   218     // support for endless games
   186     // support for endless games
   219     int tentativeTurntime = [[basicArray objectAtIndex:i++] intValue];
   187     NSInteger tentativeTurntime = [[basicArray objectAtIndex:i++] intValue];
   220     if (tentativeTurntime == 100)
   188     if (tentativeTurntime == 100)
   221         tentativeTurntime = 9999;
   189         tentativeTurntime = 9999;
   222     NSString *turnTime = [[NSString alloc] initWithFormat:@"e$turntime %d",tentativeTurntime * 1000];
   190     NSString *turnTime = [[NSString alloc] initWithFormat:@"e$turntime %d",tentativeTurntime * 1000];
   223     [self sendToEngine:turnTime];
   191     [self sendToEngine:turnTime];
   224     [turnTime release];
   192     [turnTime release];
   247 
   215 
   248     NSString *explosives = [[NSString alloc] initWithFormat:@"e$explosives %d",[[basicArray objectAtIndex:i++] intValue]];
   216     NSString *explosives = [[NSString alloc] initWithFormat:@"e$explosives %d",[[basicArray objectAtIndex:i++] intValue]];
   249     [self sendToEngine:explosives];
   217     [self sendToEngine:explosives];
   250     [explosives release];
   218     [explosives release];
   251 
   219 
   252     DLog(@"Sent %d modes",i);
   220     DLog(@"Sent %d flags and %d modes", [gamemodArray count], i);
   253     [schemeDictionary release];
   221     [schemeDictionary release];
   254     return result;
   222     return result;
   255 }
   223 }
   256 
   224 
   257 #pragma mark -
   225 #pragma mark -
   365                 [self sendToEngine:[self.gameConfig objectForKey:@"theme_command"]];
   333                 [self sendToEngine:[self.gameConfig objectForKey:@"theme_command"]];
   366 
   334 
   367                 // scheme (returns initial health)
   335                 // scheme (returns initial health)
   368                 NSInteger health = [self provideScheme:[self.gameConfig objectForKey:@"scheme"]];
   336                 NSInteger health = [self provideScheme:[self.gameConfig objectForKey:@"scheme"]];
   369 
   337 
       
   338                 // send an ammostore for each team
   370                 NSArray *teamsConfig = [self.gameConfig objectForKey:@"teams_list"];
   339                 NSArray *teamsConfig = [self.gameConfig objectForKey:@"teams_list"];
       
   340                 [self provideAmmoData:[self.gameConfig objectForKey:@"weapon"] forPlayingTeams:[teamsConfig count]];
       
   341 
       
   342                 // finally add hogs
   371                 for (NSDictionary *teamData in teamsConfig) {
   343                 for (NSDictionary *teamData in teamsConfig) {
   372                     [self provideTeamData:[teamData objectForKey:@"team"]
   344                     [self provideTeamData:[teamData objectForKey:@"team"]
   373                                   forHogs:[[teamData objectForKey:@"number"] intValue]
   345                                   forHogs:[[teamData objectForKey:@"number"] intValue]
   374                                withHealth:health
   346                                withHealth:health
   375                                   ofColor:[teamData objectForKey:@"color"]];
   347                                   ofColor:[teamData objectForKey:@"color"]];
   376                 }
   348                 }
   377 
       
   378                 [self provideAmmoData:[self.gameConfig objectForKey:@"weapon"] forPlayingTeams:[teamsConfig count]];
       
   379                 break;
   349                 break;
   380             case '?':
   350             case '?':
   381                 DLog(@"Ping? Pong!");
   351                 DLog(@"Ping? Pong!");
   382                 [self sendToEngine:@"!"];
   352                 [self sendToEngine:@"!"];
   383                 break;
   353                 break;