project_files/HedgewarsMobile/Classes/GameSetup.m
changeset 4211 7dcbd236ca59
parent 4210 caa9b08990eb
child 4244 bf46b4bdf27d
--- a/project_files/HedgewarsMobile/Classes/GameSetup.m	Sun Nov 07 18:35:21 2010 -0500
+++ b/project_files/HedgewarsMobile/Classes/GameSetup.m	Mon Nov 08 23:46:34 2010 +0100
@@ -168,7 +168,6 @@
     int i = 0;
     int result = 0;
     int mask = 0x00000004;
-    int basicArraySize = [basicArray count] - 1;
 
     // pack the gameflags in a single var and send it
     for (NSNumber *value in gamemodArray) {
@@ -180,64 +179,34 @@
     [self sendToEngine:flags];
     [flags release];
 
-    NSString *dmgMod = [[NSString alloc] initWithFormat:@"e$damagepct %d",[[basicArray objectAtIndex:i] intValue]];
-    [self sendToEngine:dmgMod];
-    [dmgMod release];
-    if (i < basicArraySize) i++;
+    /* basic game flags */
+    NSString *path = [[NSString alloc] initWithFormat:@"%@/basicFlags_en.plist",IFRONTEND_DIRECTORY()];
+    NSArray *mods = [[NSArray alloc] initWithContentsOfFile:path];
+    [path release];
 
-    // support for endless games
-    NSInteger tentativeTurntime = [[basicArray objectAtIndex:i] intValue];
+    // initial health
+    result = [[basicArray objectAtIndex:0] intValue];
+
+    // turn time
+    NSInteger tentativeTurntime = [[basicArray objectAtIndex:1] intValue];
     if (tentativeTurntime >= 100)
         tentativeTurntime = 9999;
     NSString *turnTime = [[NSString alloc] initWithFormat:@"e$turntime %d",tentativeTurntime * 1000];
     [self sendToEngine:turnTime];
     [turnTime release];
-    if (i < basicArraySize) i++;
-
-    result = [[basicArray objectAtIndex:i] intValue]; // initial health
-    if (i < basicArraySize) i++;
-
-    NSString *sdTime = [[NSString alloc] initWithFormat:@"e$sd_turns %d",[[basicArray objectAtIndex:i] intValue]];
-    [self sendToEngine:sdTime];
-    [sdTime release];
-    if (i < basicArraySize) i++;
-
-    NSString *crateDrops = [[NSString alloc] initWithFormat:@"e$casefreq %d",[[basicArray objectAtIndex:i] intValue]];
-    [self sendToEngine:crateDrops];
-    [crateDrops release];
-    if (i < basicArraySize) i++;
-
-    NSString *healthProb = [[NSString alloc] initWithFormat:@"e$healthprob %d",[[basicArray objectAtIndex:i] intValue]];
-    [self sendToEngine:healthProb];
-    [healthProb release];
-    if (i < basicArraySize) i++;
 
-    NSString *healthAmount = [[NSString alloc] initWithFormat:@"e$hcaseamount %d",[[basicArray objectAtIndex:i] intValue]];
-    [self sendToEngine:healthAmount];
-    [healthAmount release];
-    if (i < basicArraySize) i++;
-
-    NSString *minesTime = [[NSString alloc] initWithFormat:@"e$minestime %d",[[basicArray objectAtIndex:i] intValue] * 1000];
-    [self sendToEngine:minesTime];
-    [minesTime release];
-    if (i < basicArraySize) i++;
+    for (i = 2; i < [basicArray count]; i++) {
+        NSDictionary *basicDict = [mods objectAtIndex:i];
+        NSString *command = [basicDict objectForKey:@"command"];
+        NSInteger value = [[basicArray objectAtIndex:i] intValue];
+        if ([basicDict objectForKey:@"checkOverMax"] && value >= [[basicDict objectForKey:@"max"] intValue])
+            value = 9999;
+        NSString *strToSend = [[NSString alloc] initWithFormat:@"%@ %d",command,value];
+        [self sendToEngine:strToSend];
+        [strToSend release];
+    }
+    [mods release];
 
-    NSString *minesNumber = [[NSString alloc] initWithFormat:@"e$minesnum %d",[[basicArray objectAtIndex:i] intValue]];
-    [self sendToEngine:minesNumber];
-    [minesNumber release];
-    if (i < basicArraySize) i++;
-
-    NSString *dudMines = [[NSString alloc] initWithFormat:@"e$minedudpct %d",[[basicArray objectAtIndex:i] intValue]];
-    [self sendToEngine:dudMines];
-    [dudMines release];
-    if (i < basicArraySize) i++;
-
-    NSString *explosives = [[NSString alloc] initWithFormat:@"e$explosives %d",[[basicArray objectAtIndex:i] intValue]];
-    [self sendToEngine:explosives];
-    [explosives release];
-    if (i < basicArraySize) i++;
-
-    DLog(@"Sent %d flags and %d modes", [gamemodArray count], i);
     [schemeDictionary release];
     return result;
 }