ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
authorkoda
Mon, 26 Mar 2012 03:24:50 +0200
changeset 6822 206db098f8c5
parent 6821 d4f75843cf5d
child 6823 e54a68b9b844
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
hedgewars/uMobile.pas
project_files/HedgewarsMobile/Classes/CreationChamber.m
project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.h
project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.h
project_files/HedgewarsMobile/Classes/HWUtils.h
project_files/HedgewarsMobile/Classes/HWUtils.m
project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.h
project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m
project_files/HedgewarsMobile/Classes/HoldTableViewCell.m
project_files/HedgewarsMobile/Classes/MainMenuViewController.m
project_files/HedgewarsMobile/Classes/MapConfigViewController.m
project_files/HedgewarsMobile/Classes/MapPreviewButtonView.h
project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m
project_files/HedgewarsMobile/Classes/ObjcExports.h
project_files/HedgewarsMobile/Classes/ObjcExports.m
project_files/HedgewarsMobile/Classes/OverlayViewController.h
project_files/HedgewarsMobile/Classes/OverlayViewController.m
project_files/HedgewarsMobile/Classes/SavedGamesViewController.h
project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m
project_files/HedgewarsMobile/Classes/ServerProtocolNetwork.h
project_files/HedgewarsMobile/Classes/ServerProtocolNetwork.m
project_files/HedgewarsMobile/Classes/SingleSchemeViewController.h
project_files/HedgewarsMobile/Classes/SingleTeamViewController.h
project_files/HedgewarsMobile/Classes/SingleWeaponViewController.h
project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m
project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m
project_files/HedgewarsMobile/Hedgewars_Prefix.pch
--- a/hedgewars/uMobile.pas	Sun Mar 25 21:17:01 2012 +0200
+++ b/hedgewars/uMobile.pas	Mon Mar 26 03:24:50 2012 +0200
@@ -54,9 +54,8 @@
         exit(true);
     end
     else exit(false);
-{$ELSE}
+{$ENDIF}
     exit(false);
-{$ENDIF}
 end;
 
 // this function should make the device vibrate in some way
--- a/project_files/HedgewarsMobile/Classes/CreationChamber.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/CreationChamber.m	Mon Mar 26 03:24:50 2012 +0200
@@ -20,8 +20,6 @@
 
 
 #import "CreationChamber.h"
-#import "hwconsts.h"
-
 
 @implementation CreationChamber
 
--- a/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.h	Mon Mar 26 03:24:50 2012 +0200
@@ -20,8 +20,6 @@
 
 
 #import <Foundation/Foundation.h>
-#import "SDL_net.h"
-
 
 @interface EngineProtocolNetwork : NSObject {
     NSMutableArray *statsArray;
@@ -37,10 +35,7 @@
 
 
 -(id)   init;
-
 -(void) spawnThread:(NSString *)onSaveFile withOptions:(NSDictionary *)dictionary;
-+(NSInteger) activeEnginePort;
-
 -(void) engineProtocol:(id) object;
 
 -(int)  sendToEngine:(NSString *)string;
--- a/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m	Mon Mar 26 03:24:50 2012 +0200
@@ -20,13 +20,10 @@
 
 
 #import "EngineProtocolNetwork.h"
-#import "OverlayViewController.h"
 
 
 #define BUFFER_SIZE 255     // like in original frontend
 
-static NSInteger activeEnginePort;
-
 @implementation EngineProtocolNetwork
 @synthesize statsArray, stream, csd, enginePort;
 
@@ -37,7 +34,6 @@
         self.stream = nil;
         self.enginePort = [HWUtils randomPort];
     }
-    activeEnginePort = self.enginePort;
     return self;
 }
 
@@ -59,10 +55,6 @@
                            withObject:dictionary];
 }
 
-+(NSInteger) activeEnginePort {
-    return activeEnginePort;
-}
-
 #pragma mark -
 #pragma mark Provider functions
 // unpacks team data from the selected team.plist to a sequence of engine commands
@@ -402,6 +394,7 @@
     [self.stream release];
 
     // Close the client socket
+    [HWUtils freePort:self.enginePort];
     SDLNet_TCP_Close(csd);
     SDLNet_Quit();
 
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Mon Mar 26 03:24:50 2012 +0200
@@ -21,10 +21,7 @@
 
 #import "GameInterfaceBridge.h"
 #import "EngineProtocolNetwork.h"
-#import "OverlayViewController.h"
 #import "StatsPageViewController.h"
-#import "AudioManagerController.h"
-#import "ObjcExports.h"
 
 static UIViewController *callingController;
 
@@ -85,9 +82,6 @@
     [UIView commitAnimations];
     [self.blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
 
-    // the overlay is not needed any more and can be removed
-    [[OverlayViewController mainOverlay] removeOverlay];
-
     // engine thread *should* be done by now
     NSArray *stats = [[NSArray alloc] initWithArray:self.proto.statsArray copyItems:YES];
     if ([HWUtils gameStatus] == gsEnded && stats != nil) {
--- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.h	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import <UIKit/UIKit.h>
-#import "EditableCellView.h"
 
 @interface GeneralSettingsViewController : UITableViewController <EditableCellViewDelegate> {
 
--- a/project_files/HedgewarsMobile/Classes/HWUtils.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/HWUtils.h	Mon Mar 26 03:24:50 2012 +0200
@@ -40,6 +40,7 @@
 +(void) releaseCache;
 
 +(NSInteger) randomPort;
++(void) freePort:(NSInteger) port;
 +(BOOL) isNetworkReachable;
 +(UIView *)mainSDLViewInstance;
 
--- a/project_files/HedgewarsMobile/Classes/HWUtils.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/HWUtils.m	Mon Mar 26 03:24:50 2012 +0200
@@ -24,12 +24,11 @@
 #import <sys/sysctl.h>
 #import <netinet/in.h>
 #import <SystemConfiguration/SCNetworkReachability.h>
-#import "hwconsts.h"
-#import "EngineProtocolNetwork.h"
 #import "SDL_uikitwindow.h"
 
 static NSString *cachedModel = nil;
 static NSArray *cachedColors = nil;
+static NSMutableArray *activePorts = nil;
 
 static TGameType gameType = gtNone;
 static TGameStatus gameStatus = gsNone;
@@ -98,18 +97,31 @@
 +(void) releaseCache {
     [cachedModel release], cachedModel = nil;
     [cachedColors release], cachedColors = nil;
+    // don't release activePorts here
 }
 
 #pragma mark -
 #pragma mark Helper Functions without cache
 +(NSInteger) randomPort {
-    srandom(time(NULL));
-    NSInteger res = (random() % 64511) + 1024;
-    // recall self until you get a free port
-    if (res == NETGAME_DEFAULT_PORT || res == [EngineProtocolNetwork activeEnginePort])
-        return [self randomPort];
-    else
-        return res;
+    // set a new feed only at initialization time and forbid connecting to the server port
+    if (activePorts == nil) {
+        srandom(time(NULL));
+        activePorts = [[NSMutableArray arrayWithObject:[NSNumber numberWithInt:NETGAME_DEFAULT_PORT]] retain];
+    }
+
+    // pick a random number from the free ports list
+    NSInteger res = 0;
+    do {
+        res = (random() % 64511) + 1024;
+    } while ([activePorts containsObject:[NSNumber numberWithInt:res]]);
+
+    // add this number to the forbdding list
+    [activePorts addObject:[NSNumber numberWithInt:res]];
+    return res;
+}
+
++(void) freePort:(NSInteger) port {
+    [activePorts removeObject:[NSNumber numberWithInt:port]];
 }
 
 +(BOOL) isNetworkReachable {
--- a/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.h	Mon Mar 26 03:24:50 2012 +0200
@@ -25,7 +25,7 @@
 @class MainMenuViewController;
 
 @interface HedgewarsAppDelegate : SDLUIKitDelegate {
-    MainMenuViewController *mainViewController;
+    MainMenuViewController *mainViewController;     // required to dismiss the SettingsBaseViewController
     UIWindow *uiwindow;
 }
 
--- a/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m	Mon Mar 26 03:24:50 2012 +0200
@@ -21,12 +21,10 @@
 
 #import "HedgewarsAppDelegate.h"
 #import "MainMenuViewController.h"
-#import "ObjcExports.h"
-#include <unistd.h>
-
 
 @implementation SDLUIKitDelegate (customDelegate)
 
+// hijack the the SDL_UIKitAppDelegate to use the UIApplicationDelegate we implement here
 +(NSString *)getAppDelegateClassName {
     return @"HedgewarsAppDelegate";
 }
@@ -57,13 +55,13 @@
     [[UIApplication sharedApplication] setStatusBarHidden:YES];
 
     self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+    self.uiwindow.backgroundColor = [UIColor blackColor];
 
     NSString *controllerName = (IS_IPAD() ? @"MainMenuViewController-iPad" : @"MainMenuViewController-iPhone");
     self.mainViewController = [[MainMenuViewController alloc] initWithNibName:controllerName bundle:nil];
-
     [self.uiwindow addSubview:self.mainViewController.view];
     [self.mainViewController release];
-    self.uiwindow.backgroundColor = [UIColor blackColor];
+
     [self.uiwindow makeKeyAndVisible];
 }
 
@@ -78,10 +76,10 @@
     // don't clean mainMenuViewController here!!!
 }
 
-// true multitasking with sdl works only on 4.2 and above; we close the game to avoid a black screen at return
+// true multitasking with SDL works only on 4.2 and above; we close the game to avoid a black screen at return
 -(void) applicationWillResignActive:(UIApplication *)application {
     if ([HWUtils isGameLaunched] && [[[UIDevice currentDevice] systemVersion] floatValue] < 4.2f)
-         HW_terminate(NO);
+        HW_terminate(NO);
 
     [super applicationWillResignActive:application];
 }
--- a/project_files/HedgewarsMobile/Classes/HoldTableViewCell.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/HoldTableViewCell.m	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import "HoldTableViewCell.h"
-#import "CGPointUtils.h"
 
 @implementation HoldTableViewCell
 @synthesize delegate;
--- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import "MainMenuViewController.h"
-#import "CreationChamber.h"
 #import "GameConfigViewController.h"
 #import "SettingsContainerViewController.h"
 #import "AboutViewController.h"
--- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Mon Mar 26 03:24:50 2012 +0200
@@ -22,7 +22,6 @@
 #import "MapConfigViewController.h"
 #import <QuartzCore/QuartzCore.h>
 #import "SchemeWeaponConfigViewController.h"
-#import "GameConfigViewController.h"
 
 #define scIndex         self.segmentedControl.selectedSegmentIndex
 #define isRandomness()  (segmentedControl.selectedSegmentIndex == 0 || segmentedControl.selectedSegmentIndex == 2)
--- a/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.h	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import <UIKit/UIKit.h>
-#import "SDL_net.h"
 
 @protocol MapPreviewViewDelegate <NSObject>
 
--- a/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m	Mon Mar 26 03:24:50 2012 +0200
@@ -20,8 +20,6 @@
 
 
 #import "MapPreviewButtonView.h"
-#import "MapConfigViewController.h"
-#import "UIImageExtra.h"
 #import <pthread.h>
 #import <QuartzCore/QuartzCore.h>
 
@@ -116,6 +114,7 @@
         }
     }
 
+    [HWUtils freePort:port];
     SDLNet_TCP_Close(sd);
     SDLNet_Quit();
     return map;
--- a/project_files/HedgewarsMobile/Classes/ObjcExports.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/ObjcExports.h	Mon Mar 26 03:24:50 2012 +0200
@@ -19,16 +19,6 @@
  */
 
 
-@interface ObjcExports : NSObject {
-
-}
-
-+(void) setGrenadeTime:(NSInteger) value;
-+(NSInteger) grenadeTime;
-
-@end
-
-
 void clearView(void);
 BOOL isApplePhone(void);
 
--- a/project_files/HedgewarsMobile/Classes/ObjcExports.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/ObjcExports.m	Mon Mar 26 03:24:50 2012 +0200
@@ -22,25 +22,9 @@
 #import "ObjcExports.h"
 #import "OverlayViewController.h"
 
-
-// cache the grenade time
-static NSInteger grenadeTime;
 // the reference to the newMenu instance
 static OverlayViewController *overlay_instance;
 
-@implementation ObjcExports
-
-+(void) setGrenadeTime:(NSInteger) value {
-    grenadeTime = value;
-}
-
-+(NSInteger) grenadeTime {
-    return grenadeTime;
-}
-
-@end
-
-
 #pragma mark -
 #pragma mark functions called by pascal code
 BOOL inline isApplePhone() {
@@ -51,9 +35,7 @@
     // this is the first ojbc function called by engine, so we have to initialize some variables here
     overlay_instance = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
     // in order to get rotation events we have to insert the view inside the first view of the second window
-    //TODO: when multihead make sure that overlay is displayed in the touch-enabled window
     [[HWUtils mainSDLViewInstance] addSubview:overlay_instance.view];
-    grenadeTime = 2;
 
     if ([HWUtils gameType] == gtSave) {
         [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
@@ -102,20 +84,7 @@
 }
 
 void clearView() {
-    // don't use any engine calls here as this function is called every time the ammomenu is opened
-    [UIView beginAnimations:@"remove button" context:NULL];
-    [UIView setAnimationDuration:ANIMATION_DURATION];
-    overlay_instance.confirmButton.alpha = 0;
-    overlay_instance.grenadeTimeSegment.alpha = 0;
-    [UIView commitAnimations];
-
-    if (overlay_instance.confirmButton)
-        [overlay_instance.confirmButton performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
-    if (overlay_instance.grenadeTimeSegment) {
-        [overlay_instance.grenadeTimeSegment performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
-        overlay_instance.grenadeTimeSegment.tag = 0;
-    }
-    grenadeTime = 2;
+    [overlay_instance clearOverlay];
 }
 
 // dummy function to prevent linkage fail
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h	Mon Mar 26 03:24:50 2012 +0200
@@ -45,6 +45,7 @@
     UIActivityIndicatorView *loadingIndicator;
     UIButton *confirmButton;
     UISegmentedControl *grenadeTimeSegment;
+    NSInteger cachedGrenadeTime;
 }
 
 @property (nonatomic,retain) id popoverController;
@@ -53,8 +54,7 @@
 @property (nonatomic,retain) UIActivityIndicatorView *loadingIndicator;
 @property (nonatomic,retain) UIButton *confirmButton;
 @property (nonatomic,retain) UISegmentedControl *grenadeTimeSegment;
-
-+(OverlayViewController *)mainOverlay;
+@property (assign) NSInteger cachedGrenadeTime;
 
 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@@ -66,9 +66,10 @@
 
 -(void) showPopover;
 -(void) dismissPopover;
+
 -(void) dimOverlay;
 -(void) activateOverlay;
--(void) removeOverlay;
+-(void) clearOverlay;
 
 #define ANIMATION_DURATION 0.25
 #define CONFIRMATION_TAG 5959
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Mon Mar 26 03:24:50 2012 +0200
@@ -23,7 +23,6 @@
 #import "InGameMenuViewController.h"
 #import "HelpPageViewController.h"
 #import "CGPointUtils.h"
-#import "ObjcExports.h"
 
 
 #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
@@ -32,10 +31,8 @@
 #define doNotDim()          [dimTimer setFireDate:HIDING_TIME_NEVER]
 
 
-static OverlayViewController *mainOverlay;
-
 @implementation OverlayViewController
-@synthesize popoverController, popupMenu, helpPage, loadingIndicator, confirmButton, grenadeTimeSegment;
+@synthesize popoverController, popupMenu, helpPage, loadingIndicator, confirmButton, grenadeTimeSegment, cachedGrenadeTime;
 
 #pragma mark -
 #pragma mark rotation
@@ -51,15 +48,10 @@
         isAttacking = NO;
         isPopoverVisible = NO;
         loadingIndicator = nil;
-        mainOverlay = self;
     }
     return self;
 }
 
-+(OverlayViewController *)mainOverlay {
-    return mainOverlay;
-}
-
 -(void) viewDidLoad {
     // fill all the screen available as sdlview disables autoresizing
     self.view.frame = [[UIScreen mainScreen] safeBounds];
@@ -96,7 +88,6 @@
 
     // only objects initialized in viewDidLoad should be here
     dimTimer = nil;
-    mainOverlay = nil;
     self.helpPage = nil;
     [self dismissPopover];
     self.popoverController = nil;
@@ -153,12 +144,17 @@
     doNotDim();
 }
 
--(void) removeOverlay {
-    [self.popupMenu performSelectorOnMainThread:@selector(dismiss) withObject:nil waitUntilDone:YES];
-    [self.popoverController performSelectorOnMainThread:@selector(dismissPopoverAnimated:) withObject:nil waitUntilDone:YES];
-    [self.view performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:YES];
-    [self performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:YES];
-    mainOverlay = nil;
+-(void) clearOverlay {
+    [UIView beginAnimations:@"remove button" context:NULL];
+    [UIView setAnimationDuration:ANIMATION_DURATION];
+    self.confirmButton.alpha = 0;
+    self.grenadeTimeSegment.alpha = 0;
+    [UIView commitAnimations];
+
+    if (self.confirmButton)
+        [self.confirmButton performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
+    if (self.grenadeTimeSegment)
+        [self.grenadeTimeSegment performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
 }
 
 #pragma mark -
@@ -237,12 +233,12 @@
         case 10:
             [AudioManagerController playClickSound];
             HW_pause();
-            clearView();
+            [self clearOverlay];
             [self showPopover];
             break;
         case 11:
             [AudioManagerController playClickSound];
-            clearView();
+            [self clearOverlay];
             HW_ammoMenu();
             break;
         default:
@@ -256,16 +252,17 @@
 }
 
 -(void) sendHWClick {
+    [self clearOverlay];
     HW_click();
-    clearView();
     doDim();
 }
 
 -(void) setGrenadeTime:(id) sender {
     UISegmentedControl *theSegment = (UISegmentedControl *)sender;
-    if ([ObjcExports grenadeTime] != theSegment.selectedSegmentIndex) {
-        HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1);
-        [ObjcExports setGrenadeTime:theSegment.selectedSegmentIndex];
+    NSInteger timeIndex = theSegment.selectedSegmentIndex;
+    if (self.cachedGrenadeTime != timeIndex) {
+        HW_setGrenadeTime(timeIndex + 1);
+        self.cachedGrenadeTime = timeIndex;
     }
 }
 
@@ -424,14 +421,13 @@
                     doNotDim();
                 } else
                     if (HW_isWeaponTimerable()) {
-                        if (self.grenadeTimeSegment.tag != 0) {
+                        if (self.grenadeTimeSegment.superview != nil) {
                             [UIView beginAnimations:@"removing segmented control" context:NULL];
                             [UIView setAnimationDuration:ANIMATION_DURATION];
                             self.grenadeTimeSegment.alpha = 0;
                             [UIView commitAnimations];
 
                             [self.grenadeTimeSegment performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
-                            self.grenadeTimeSegment.tag = 0;
                         } else {
                             if (self.grenadeTimeSegment == nil) {
                                 NSArray *items = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil];
@@ -441,18 +437,20 @@
                                 self.grenadeTimeSegment = grenadeSegment;
                                 [grenadeSegment release];
                             }
-                            self.grenadeTimeSegment.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50);
-                            self.grenadeTimeSegment.selectedSegmentIndex = [ObjcExports grenadeTime];
+                            self.grenadeTimeSegment.frame = CGRectMake(screen.size.width / 2 - 125, screen.size.height, 250, 50);
+                            self.grenadeTimeSegment.selectedSegmentIndex = self.cachedGrenadeTime;
                             self.grenadeTimeSegment.alpha = 1;
+                            self.grenadeTimeSegment.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
+                                                                       UIViewAutoresizingFlexibleRightMargin |
+                                                                       UIViewAutoresizingFlexibleTopMargin;
                             [self.view addSubview:self.grenadeTimeSegment];
 
                             [UIView beginAnimations:@"inserting segmented control" context:NULL];
                             [UIView setAnimationDuration:ANIMATION_DURATION];
                             [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
-                            self.grenadeTimeSegment.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width - 100, 250, 50);
+                            self.grenadeTimeSegment.frame = CGRectMake(screen.size.width / 2 - 125, screen.size.height - 100, 250, 50);
                             [UIView commitAnimations];
 
-                            self.grenadeTimeSegment.tag++;
                             [self activateOverlay];
                             doNotDim();
                         }
--- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.h	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import <UIKit/UIKit.h>
-#import "EditableCellView.h"
 
 
 @interface SavedGamesViewController : UIViewController <UITableViewDelegate, UITableViewDataSource,
--- a/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import "SchemeSettingsViewController.h"
-#import "CreationChamber.h"
 #import "SingleSchemeViewController.h"
 
 @implementation SchemeSettingsViewController
--- a/project_files/HedgewarsMobile/Classes/ServerProtocolNetwork.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/ServerProtocolNetwork.h	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import <Foundation/Foundation.h>
-#import "SDL_net.h"
 //#import "EngineProtocolNetwork.h"
 
 @interface ServerProtocolNetwork : NSObject {
--- a/project_files/HedgewarsMobile/Classes/ServerProtocolNetwork.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/ServerProtocolNetwork.m	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import "ServerProtocolNetwork.h"
-#import "hwconsts.h"
 
 #define BUFFER_SIZE 256
 
--- a/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.h	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import <UIKit/UIKit.h>
-#import "EditableCellView.h"
 
 @interface SingleSchemeViewController : UITableViewController <EditableCellViewDelegate> {
     NSString *schemeName;
--- a/project_files/HedgewarsMobile/Classes/SingleTeamViewController.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/SingleTeamViewController.h	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import <UIKit/UIKit.h>
-#import "EditableCellView.h"
 
 @class HogHatViewController;
 @class GravesViewController;
--- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.h	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.h	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import <UIKit/UIKit.h>
-#import "EditableCellView.h"
 #import "WeaponCellView.h"
 
 @interface SingleWeaponViewController : UITableViewController <EditableCellViewDelegate, WeaponButtonControllerDelegate> {
--- a/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import "TeamSettingsViewController.h"
-#import "CreationChamber.h"
 #import "SingleTeamViewController.h"
 
 @implementation TeamSettingsViewController
--- a/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m	Mon Mar 26 03:24:50 2012 +0200
@@ -20,7 +20,6 @@
 
 
 #import "WeaponSettingsViewController.h"
-#import "CreationChamber.h"
 #import "SingleWeaponViewController.h"
 
 @implementation WeaponSettingsViewController
--- a/project_files/HedgewarsMobile/Hedgewars_Prefix.pch	Sun Mar 25 21:17:01 2012 +0200
+++ b/project_files/HedgewarsMobile/Hedgewars_Prefix.pch	Mon Mar 26 03:24:50 2012 +0200
@@ -23,12 +23,16 @@
 #import <Foundation/Foundation.h>
 #import <CoreGraphics/CoreGraphics.h>
 #import <UIKit/UIKit.h>
-#import "PascalImports.h"
-#import "UIImageExtra.h"
-#import "DefinesAndMacros.h"
 #import "HedgewarsAppDelegate.h"
 #import "AudioManagerController.h"
+#import "ExtraCategories.h"
+#import "UIImageExtra.h"
+#import "PascalImports.h"
+#import "DefinesAndMacros.h"
+#import "EditableCellView.h"
+#import "CreationChamber.h"
 #import "HWUtils.h"
-#import "ExtraCategories.h"
+#import "hwconsts.h"
+#import "SDL_net.h"
 #endif