project_files/HedgewarsMobile/Classes/GameSetup.m
changeset 4211 7dcbd236ca59
parent 4210 caa9b08990eb
child 4244 bf46b4bdf27d
equal deleted inserted replaced
4210:caa9b08990eb 4211:7dcbd236ca59
   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 i = 0;
   169     int result = 0;
   169     int result = 0;
   170     int mask = 0x00000004;
   170     int mask = 0x00000004;
   171     int basicArraySize = [basicArray count] - 1;
       
   172 
   171 
   173     // pack the gameflags in a single var and send it
   172     // pack the gameflags in a single var and send it
   174     for (NSNumber *value in gamemodArray) {
   173     for (NSNumber *value in gamemodArray) {
   175         if ([value boolValue] == YES)
   174         if ([value boolValue] == YES)
   176             result |= mask;
   175             result |= mask;
   178     }
   177     }
   179     NSString *flags = [[NSString alloc] initWithFormat:@"e$gmflags %d",result];
   178     NSString *flags = [[NSString alloc] initWithFormat:@"e$gmflags %d",result];
   180     [self sendToEngine:flags];
   179     [self sendToEngine:flags];
   181     [flags release];
   180     [flags release];
   182 
   181 
   183     NSString *dmgMod = [[NSString alloc] initWithFormat:@"e$damagepct %d",[[basicArray objectAtIndex:i] intValue]];
   182     /* basic game flags */
   184     [self sendToEngine:dmgMod];
   183     NSString *path = [[NSString alloc] initWithFormat:@"%@/basicFlags_en.plist",IFRONTEND_DIRECTORY()];
   185     [dmgMod release];
   184     NSArray *mods = [[NSArray alloc] initWithContentsOfFile:path];
   186     if (i < basicArraySize) i++;
   185     [path release];
   187 
   186 
   188     // support for endless games
   187     // initial health
   189     NSInteger tentativeTurntime = [[basicArray objectAtIndex:i] intValue];
   188     result = [[basicArray objectAtIndex:0] intValue];
       
   189 
       
   190     // turn time
       
   191     NSInteger tentativeTurntime = [[basicArray objectAtIndex:1] intValue];
   190     if (tentativeTurntime >= 100)
   192     if (tentativeTurntime >= 100)
   191         tentativeTurntime = 9999;
   193         tentativeTurntime = 9999;
   192     NSString *turnTime = [[NSString alloc] initWithFormat:@"e$turntime %d",tentativeTurntime * 1000];
   194     NSString *turnTime = [[NSString alloc] initWithFormat:@"e$turntime %d",tentativeTurntime * 1000];
   193     [self sendToEngine:turnTime];
   195     [self sendToEngine:turnTime];
   194     [turnTime release];
   196     [turnTime release];
   195     if (i < basicArraySize) i++;
   197 
   196 
   198     for (i = 2; i < [basicArray count]; i++) {
   197     result = [[basicArray objectAtIndex:i] intValue]; // initial health
   199         NSDictionary *basicDict = [mods objectAtIndex:i];
   198     if (i < basicArraySize) i++;
   200         NSString *command = [basicDict objectForKey:@"command"];
   199 
   201         NSInteger value = [[basicArray objectAtIndex:i] intValue];
   200     NSString *sdTime = [[NSString alloc] initWithFormat:@"e$sd_turns %d",[[basicArray objectAtIndex:i] intValue]];
   202         if ([basicDict objectForKey:@"checkOverMax"] && value >= [[basicDict objectForKey:@"max"] intValue])
   201     [self sendToEngine:sdTime];
   203             value = 9999;
   202     [sdTime release];
   204         NSString *strToSend = [[NSString alloc] initWithFormat:@"%@ %d",command,value];
   203     if (i < basicArraySize) i++;
   205         [self sendToEngine:strToSend];
   204 
   206         [strToSend release];
   205     NSString *crateDrops = [[NSString alloc] initWithFormat:@"e$casefreq %d",[[basicArray objectAtIndex:i] intValue]];
   207     }
   206     [self sendToEngine:crateDrops];
   208     [mods release];
   207     [crateDrops release];
   209 
   208     if (i < basicArraySize) i++;
       
   209 
       
   210     NSString *healthProb = [[NSString alloc] initWithFormat:@"e$healthprob %d",[[basicArray objectAtIndex:i] intValue]];
       
   211     [self sendToEngine:healthProb];
       
   212     [healthProb release];
       
   213     if (i < basicArraySize) i++;
       
   214 
       
   215     NSString *healthAmount = [[NSString alloc] initWithFormat:@"e$hcaseamount %d",[[basicArray objectAtIndex:i] intValue]];
       
   216     [self sendToEngine:healthAmount];
       
   217     [healthAmount release];
       
   218     if (i < basicArraySize) i++;
       
   219 
       
   220     NSString *minesTime = [[NSString alloc] initWithFormat:@"e$minestime %d",[[basicArray objectAtIndex:i] intValue] * 1000];
       
   221     [self sendToEngine:minesTime];
       
   222     [minesTime release];
       
   223     if (i < basicArraySize) i++;
       
   224 
       
   225     NSString *minesNumber = [[NSString alloc] initWithFormat:@"e$minesnum %d",[[basicArray objectAtIndex:i] intValue]];
       
   226     [self sendToEngine:minesNumber];
       
   227     [minesNumber release];
       
   228     if (i < basicArraySize) i++;
       
   229 
       
   230     NSString *dudMines = [[NSString alloc] initWithFormat:@"e$minedudpct %d",[[basicArray objectAtIndex:i] intValue]];
       
   231     [self sendToEngine:dudMines];
       
   232     [dudMines release];
       
   233     if (i < basicArraySize) i++;
       
   234 
       
   235     NSString *explosives = [[NSString alloc] initWithFormat:@"e$explosives %d",[[basicArray objectAtIndex:i] intValue]];
       
   236     [self sendToEngine:explosives];
       
   237     [explosives release];
       
   238     if (i < basicArraySize) i++;
       
   239 
       
   240     DLog(@"Sent %d flags and %d modes", [gamemodArray count], i);
       
   241     [schemeDictionary release];
   210     [schemeDictionary release];
   242     return result;
   211     return result;
   243 }
   212 }
   244 
   213 
   245 #pragma mark -
   214 #pragma mark -