# HG changeset patch # User koda # Date 1289064090 -3600 # Node ID 51200479f9d8d09a7aa1155c6e618a5169726d24 # Parent eaff5615f9760c64f5940cfa67267798f7263750 update ios port with new health modes, increase sd turns, new game modes, fixed bugs that prevented the creation of AI controlled teams, revisited update modes diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Classes/CommodityFunctions.m --- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Sat Nov 06 18:21:30 2010 +0100 @@ -75,45 +75,45 @@ switch (type) { case 0: //default theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys: - @"9391929422199121032235111001201000000211110101010",@"ammostore_initialqt", - @"0405040541600655546554464776576666666155510101110",@"ammostore_probability", + @"9391929422199121032235111001201000000211110101011",@"ammostore_initialqt", + @"0405040541600655546554464776576666666155510101117",@"ammostore_probability", @"0000000000000205500000040007004000000000200000000",@"ammostore_delay", - @"1311110312111111123114111111111111111211111101110",@"ammostore_crate", nil]; + @"1311110312111111123114111111111111111211111101111",@"ammostore_crate", nil]; break; case 1: //crazy theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys: - @"9999999999999999992999999999999999299999999909990",@"ammostore_initialqt", - @"1111110111111111111111111111111111111111111101110",@"ammostore_probability", + @"9999999999999999992999999999999999299999999909999",@"ammostore_initialqt", + @"1111110111111111111111111111111111111111111101111",@"ammostore_probability", @"0000000000000000000000000000000000000000000000000",@"ammostore_delay", - @"1311110312111111123114111111111111111211110101110",@"ammostore_crate", nil]; + @"1311110312111111123114111111111111111211110101111",@"ammostore_crate", nil]; break; case 2: //pro mode theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys: @"9090009000000000000009000000000000000000000000000",@"ammostore_initialqt", @"0000000000000000000000000000000000000000000000000",@"ammostore_probability", @"0000000000000205500000040007004000000000200000000",@"ammostore_delay", - @"1111111111111111111111111111111111111111100101110",@"ammostore_crate", nil]; + @"1111111111111111111111111111111111111111100101111",@"ammostore_crate", nil]; break; case 3: //shoppa theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys: @"0000009900000000000000000000000000000000000000000",@"ammostore_initialqt", @"4444410044244402210112121222422000000002000400010",@"ammostore_probability", @"0000000000000000000000000000000000000000000000000",@"ammostore_delay", - @"1111111111111111111111111111111111111111101101110",@"ammostore_crate", nil]; + @"1111111111111111111111111111111111111111101101111",@"ammostore_crate", nil]; break; - case 4: //basketball + case 4: //clean slate theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys: - @"9391929422199121032235111001201000000211110101000",@"ammostore_initialqt", - @"0000000000000000000000000000000000000000000000000",@"ammostore_probability", - @"0000000000000005500000040007004000000000200000000",@"ammostore_delay", - @"1111111111111111111111111111111111111111111101110",@"ammostore_crate", nil]; + @"1010009000010000011000000000000000000000000000001",@"ammostore_initialqt", + @"0405040541600655546554464776576666666155510101117",@"ammostore_probability", + @"0000000000000205500000040007004000000000200000000",@"ammostore_delay", + @"1311110312111111123114111111111111111211111101111",@"ammostore_crate", nil]; break; case 5: //minefield theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys: @"0000009900090000000300000000000000000000000000000",@"ammostore_initialqt", @"0000000000000000000000000000000000000000000000000",@"ammostore_probability", @"0000000000000205500000040007004000000000200000000",@"ammostore_delay", - @"1111111111111111111111111111111111111111111101110",@"ammostore_crate", nil]; + @"1111111111111111111111111111111111111111111101111",@"ammostore_crate", nil]; break; default: NSLog(@"Nope"); @@ -143,8 +143,10 @@ [NSNumber numberWithInt:100], //initialhealth [NSNumber numberWithInt:15], //suddendeathtimeout [NSNumber numberWithInt:5], //cratedrops + [NSNumber numberWithInt:35], //healthprob + [NSNumber numberWithInt:25], //healthamount [NSNumber numberWithInt:3], //minestime - [NSNumber numberWithInt:4], //mines + [NSNumber numberWithInt:4], //minesnumber [NSNumber numberWithInt:0], //dudmines [NSNumber numberWithInt:2], //explosives nil]; diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Classes/GameSetup.m --- a/project_files/HedgewarsMobile/Classes/GameSetup.m Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Classes/GameSetup.m Sat Nov 06 18:21:30 2010 +0100 @@ -168,6 +168,7 @@ 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) { @@ -179,43 +180,62 @@ [self sendToEngine:flags]; [flags release]; - NSString *dmgMod = [[NSString alloc] initWithFormat:@"e$damagepct %d",[[basicArray objectAtIndex:i++] intValue]]; + NSString *dmgMod = [[NSString alloc] initWithFormat:@"e$damagepct %d",[[basicArray objectAtIndex:i] intValue]]; [self sendToEngine:dmgMod]; [dmgMod release]; + if (i < basicArraySize) i++; // support for endless games - NSInteger tentativeTurntime = [[basicArray objectAtIndex:i++] intValue]; + NSInteger tentativeTurntime = [[basicArray objectAtIndex:i] 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 + result = [[basicArray objectAtIndex:i] intValue]; // initial health + if (i < basicArraySize) i++; - NSString *sdTime = [[NSString alloc] initWithFormat:@"e$sd_turns %d",[[basicArray objectAtIndex:i++] intValue]]; + 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]]; + NSString *crateDrops = [[NSString alloc] initWithFormat:@"e$casefreq %d",[[basicArray objectAtIndex:i] intValue]]; [self sendToEngine:crateDrops]; [crateDrops release]; + if (i < basicArraySize) i++; - NSString *minesTime = [[NSString alloc] initWithFormat:@"e$minestime %d",[[basicArray objectAtIndex:i++] intValue] * 1000]; + 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++; - NSString *minesNumber = [[NSString alloc] initWithFormat:@"e$minesnum %d",[[basicArray objectAtIndex:i++] intValue]]; + 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]]; + 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]]; + 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]; @@ -225,7 +245,7 @@ #pragma mark - #pragma mark Thread/Network relevant code // select one of GameSetup method and execute it in a seprate thread --(void) startThread: (NSString *) selector { +-(void) startThread:(NSString *)selector { SEL usage = NSSelectorFromString(selector); [NSThread detachNewThreadSelector:usage toTarget:self withObject:nil]; } diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Classes/LevelViewController.m --- 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]; diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Classes/MainMenuViewController.m --- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Sat Nov 06 18:21:30 2010 +0100 @@ -55,18 +55,19 @@ [[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL]; // if the settings file is already present, we merge current preferences with the update - directoryToCheck = [NSString stringWithFormat:@"%@/Settings/settings.plist",resDir]; + fileToCheck = [NSString stringWithFormat:@"%@/Settings/settings.plist",resDir]; if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) { NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; - NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:directoryToCheck]; + NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:fileToCheck]; [update addEntriesFromDictionary:settings]; [settings release]; [update writeToFile:SETTINGS_FILE() atomically:YES]; [update release]; } else - [[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:SETTINGS_FILE() error:&err]; + [[NSFileManager defaultManager] copyItemAtPath:fileToCheck toPath:SETTINGS_FILE() error:&err]; - // if the teams are already present we merge the old teams if they still exist + // TODO: scrap this and always copy the bundled files; update exisising ones in some way + // if the teams are already present we merge the old teams, else we copy new teams directoryToCheck = [NSString stringWithFormat:@"%@/Settings/Teams",resDir]; if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()]) { for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryToCheck error:&err]) { @@ -79,43 +80,46 @@ [team release]; [update writeToFile:fileToCheck atomically:YES]; [update release]; - } + } else + [[NSFileManager defaultManager] copyItemAtPath:fileToUpdate toPath:fileToCheck error:&err]; } } else [[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:TEAMS_DIRECTORY() error:&err]; - // the same holds for schemes (but they're arrays) + // TODO: scrap this and always copy the bundled files; update exisising ones in some way + // the same holds for schemes (but they're dictionaries containing arrays) directoryToCheck = [NSString stringWithFormat:@"%@/Settings/Schemes",resDir]; if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()]) { for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryToCheck error:nil]) { fileToCheck = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),str]; fileToUpdate = [NSString stringWithFormat:@"%@/Settings/Schemes/%@",resDir,str]; if ([[NSFileManager defaultManager] fileExistsAtPath:fileToCheck]) { - NSArray *scheme = [[NSArray alloc] initWithContentsOfFile:fileToCheck]; - NSArray *update = [[NSArray alloc] initWithContentsOfFile:fileToUpdate]; - if ([update count] > [scheme count]) + NSDictionary *scheme = [[NSDictionary alloc] initWithContentsOfFile:fileToCheck]; + NSDictionary *update = [[NSDictionary alloc] initWithContentsOfFile:fileToUpdate]; + if ([[update objectForKey:@"basic"] count] > [[scheme objectForKey:@"basic"] count] || + [[update objectForKey:@"gamemod"] count] > [[scheme objectForKey:@"gamemod"] count]) [update writeToFile:fileToCheck atomically:YES]; [update release]; [scheme release]; - } + } else + [[NSFileManager defaultManager] copyItemAtPath:fileToUpdate toPath:fileToCheck error:&err]; } } else [[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:SCHEMES_DIRECTORY() error:&err]; - // we create weapons the first time only, they are autoupdated each time - if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO) { + // weapons are autoupdated at runtime but it's better to update then every new version + if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO) [[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY() withIntermediateDirectories:YES attributes:nil error:&err]; - createWeaponNamed(@"Default", 0); - createWeaponNamed(@"Crazy", 1); - createWeaponNamed(@"Pro mode", 2); - createWeaponNamed(@"Shoppa", 3); - createWeaponNamed(@"Basketball", 4); - createWeaponNamed(@"Minefield", 5); - } - + createWeaponNamed(@"Default", 0); + createWeaponNamed(@"Crazy", 1); + createWeaponNamed(@"Pro mode", 2); + createWeaponNamed(@"Shoppa", 3); + createWeaponNamed(@"Clean slate", 4); + createWeaponNamed(@"Minefield", 5); + if (err != nil) DLog(@"%@", err); else diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Resources/Settings/Schemes/Barrel Mayhem.plist --- a/project_files/HedgewarsMobile/Resources/Settings/Schemes/Barrel Mayhem.plist Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Resources/Settings/Schemes/Barrel Mayhem.plist Sat Nov 06 18:21:30 2010 +0100 @@ -9,6 +9,8 @@ 100 15 0 + 35 + 25 0 0 0 diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Resources/Settings/Schemes/Default.plist --- a/project_files/HedgewarsMobile/Resources/Settings/Schemes/Default.plist Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Resources/Settings/Schemes/Default.plist Sat Nov 06 18:21:30 2010 +0100 @@ -9,6 +9,8 @@ 100 15 5 + 35 + 25 3 4 0 diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Resources/Settings/Schemes/Minefield.plist --- a/project_files/HedgewarsMobile/Resources/Settings/Schemes/Minefield.plist Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Resources/Settings/Schemes/Minefield.plist Sat Nov 06 18:21:30 2010 +0100 @@ -9,6 +9,8 @@ 50 15 0 + 35 + 25 0 80 0 diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Resources/Settings/Schemes/Pro Mode.plist --- a/project_files/HedgewarsMobile/Resources/Settings/Schemes/Pro Mode.plist Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Resources/Settings/Schemes/Pro Mode.plist Sat Nov 06 18:21:30 2010 +0100 @@ -9,6 +9,8 @@ 100 15 0 + 35 + 25 3 0 0 diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Resources/Settings/Schemes/Shoppa.plist --- a/project_files/HedgewarsMobile/Resources/Settings/Schemes/Shoppa.plist Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Resources/Settings/Schemes/Shoppa.plist Sat Nov 06 18:21:30 2010 +0100 @@ -9,6 +9,8 @@ 100 50 1 + 0 + 35 3 0 0 diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Resources/Settings/Schemes/Timeless.plist --- a/project_files/HedgewarsMobile/Resources/Settings/Schemes/Timeless.plist Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Resources/Settings/Schemes/Timeless.plist Sat Nov 06 18:21:30 2010 +0100 @@ -9,6 +9,8 @@ 100 15 5 + 35 + 25 3 4 0 @@ -36,7 +38,7 @@ - + diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Resources/Settings/Schemes/Tunnel Hogs.plist --- a/project_files/HedgewarsMobile/Resources/Settings/Schemes/Tunnel Hogs.plist Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Resources/Settings/Schemes/Tunnel Hogs.plist Sat Nov 06 18:21:30 2010 +0100 @@ -9,6 +9,8 @@ 100 15 5 + 35 + 25 3 10 10 diff -r eaff5615f976 -r 51200479f9d8 project_files/HedgewarsMobile/Resources/Settings/iFrontend/basicFlags_en.plist --- a/project_files/HedgewarsMobile/Resources/Settings/iFrontend/basicFlags_en.plist Sat Nov 06 12:56:09 2010 -0400 +++ b/project_files/HedgewarsMobile/Resources/Settings/iFrontend/basicFlags_en.plist Sat Nov 06 18:21:30 2010 +0100 @@ -44,7 +44,7 @@ image SuddenDeath max - 50 + 999 min 0 title @@ -64,6 +64,30 @@ default + 35 + image + Health + max + 100 + min + 0 + title + Health Kit Probability + + + default + 25 + image + Health + max + 200 + min + 0 + title + Health Amount in Kit + + + default 3 image Time