project_files/HedgewarsMobile/Classes/GameSetup.m
changeset 4208 dd54999c2822
parent 4151 08b95ec1bfdf
child 4210 caa9b08990eb
equal deleted inserted replaced
4207:31e77dcf18fe 4208:dd54999c2822
   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];
   190     if (tentativeTurntime >= 100)
   189 
   191         tentativeTurntime = 9999;
   190     for (i = 1; i < [basicArray count]; i++) {
   192     NSString *turnTime = [[NSString alloc] initWithFormat:@"e$turntime %d",tentativeTurntime * 1000];
   191         NSDictionary *basicDict = [mods objectAtIndex:i];
   193     [self sendToEngine:turnTime];
   192         NSString *command = [basicDict objectForKey:@"command"];
   194     [turnTime release];
   193         NSInteger value = [[basicArray objectAtIndex:i] intValue];
   195     if (i < basicArraySize) i++;
   194         if ([basicDict objectForKey:@"checkOverMax"] && value >= [[basicDict objectForKey:@"max"] intValue])
   196 
   195             value = 9999;
   197     result = [[basicArray objectAtIndex:i] intValue]; // initial health
   196         NSString *strToSend = [[NSString alloc] initWithFormat:@"%@ %d",command,value];
   198     if (i < basicArraySize) i++;
   197         [self sendToEngine:strToSend];
   199 
   198         [strToSend release];
   200     NSString *sdTime = [[NSString alloc] initWithFormat:@"e$sd_turns %d",[[basicArray objectAtIndex:i] intValue]];
   199     }
   201     [self sendToEngine:sdTime];
   200     [mods release];
   202     [sdTime release];
   201 
   203     if (i < basicArraySize) i++;
       
   204 
       
   205     NSString *crateDrops = [[NSString alloc] initWithFormat:@"e$casefreq %d",[[basicArray objectAtIndex:i] intValue]];
       
   206     [self sendToEngine:crateDrops];
       
   207     [crateDrops release];
       
   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];
   202     [schemeDictionary release];
   242     return result;
   203     return result;
   243 }
   204 }
   244 
   205 
   245 #pragma mark -
   206 #pragma mark -