project_files/HedgewarsMobile/Classes/LevelViewController.m
changeset 4149 51200479f9d8
parent 3971 5c82ee165ed5
child 4284 57a501a69e5f
--- a/project_files/HedgewarsMobile/Classes/LevelViewController.m	Sat Nov 06 12:56:09 2010 -0400
+++ b/project_files/HedgewarsMobile/Classes/LevelViewController.m	Sat Nov 06 18:21:30 2010 +0100
@@ -95,14 +95,15 @@
         if (cell == nil) {
             cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease];
             UISwitch *theSwitch = [[UISwitch alloc] init];
-            if (numberOfSections == 1)
-                theSwitch.on = NO;
-            else
-                theSwitch.on = YES;
             [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
             cell.accessoryView = theSwitch;
             [theSwitch release];
         }
+        UISwitch *theSwitch = (UISwitch *)cell.accessoryView;
+        if (numberOfSections == 1)
+            theSwitch.on = NO;
+        else
+            theSwitch.on = YES;
         cell.textLabel.text = NSLocalizedString(@"Hogs controlled by AI",@"");
     } else {
         cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
@@ -137,7 +138,7 @@
     if (theSwitch.on) {
         numberOfSections = 2;
         [self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade];
-        level = random() % [levelArray count];
+        level = 1 + (random() % ([levelArray count] - 1));
     } else {
         numberOfSections = 1;
         [self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade];
@@ -146,7 +147,7 @@
 
     DLog(@"New level is %d",level);
     for (NSMutableDictionary *hog in hogs)
-        [hog setObject:[NSNumber numberWithInt:0] forKey:@"level"];
+        [hog setObject:[NSNumber numberWithInt:level] forKey:@"level"];
 
     [self.tableView reloadData];
     [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];