remove a useless field from weaponfile format
authorkoda
Thu, 07 Oct 2010 02:16:29 +0200
changeset 3930 8b00b4f93242
parent 3928 2560731c860d
child 3933 1a873262f5dd
remove a useless field from weaponfile format added some properties and memory checks use a notification instead of delegation for starting the game
project_files/HedgewarsMobile/Classes/CommodityFunctions.h
project_files/HedgewarsMobile/Classes/CommodityFunctions.m
project_files/HedgewarsMobile/Classes/GameConfigViewController.h
project_files/HedgewarsMobile/Classes/GameConfigViewController.m
project_files/HedgewarsMobile/Classes/GameSetup.m
project_files/HedgewarsMobile/Classes/MapConfigViewController.h
project_files/HedgewarsMobile/Classes/MapConfigViewController.m
project_files/HedgewarsMobile/Classes/PascalImports.h
project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.h	Thu Oct 07 02:03:01 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.h	Thu Oct 07 02:16:29 2010 +0200
@@ -58,7 +58,7 @@
 void playSound (NSString *snd);
 void popError (const char *title, const char *message);
 BOOL rotationManager (UIInterfaceOrientation interfaceOrientation);
-BOOL isPhone ();
+BOOL isApplePhone ();
 NSInteger randomPort ();
 NSString *modelType ();
 NSArray *getAvailableColors(void);
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Thu Oct 07 02:03:01 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Thu Oct 07 02:16:29 2010 +0200
@@ -74,7 +74,6 @@
     switch (type) {
         case 0: //default
             theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
-                         [NSNumber numberWithInt:HW_getNumberOfWeapons()],@"version",
                          @"939192942219912103223511100120100000021111010101",@"ammostore_initialqt",
                          @"040504054160065554655446477657666666615551010111",@"ammostore_probability",
                          @"000000000000020550000004000700400000000020000000",@"ammostore_delay",
@@ -82,7 +81,6 @@
             break;
         case 1: //crazy
             theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
-                         [NSNumber numberWithInt:HW_getNumberOfWeapons()],@"version",
                          @"999999999999999999299999999999999929999999990999",@"ammostore_initialqt",
                          @"111111011111111111111111111111111111111111110111",@"ammostore_probability",
                          @"000000000000000000000000000000000000000000000000",@"ammostore_delay",
@@ -90,7 +88,6 @@
             break;
         case 2: //pro mode
             theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
-                         [NSNumber numberWithInt:HW_getNumberOfWeapons()],@"version",
                          @"909000900000000000000900000000000000000000000000",@"ammostore_initialqt",
                          @"000000000000000000000000000000000000000000000000",@"ammostore_probability",
                          @"000000000000020550000004000700400000000020000000",@"ammostore_delay",
@@ -98,7 +95,6 @@
             break;
         case 3: //shoppa
             theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
-                         [NSNumber numberWithInt:HW_getNumberOfWeapons()],@"version",
                          @"000000990000000000000000000000000000000000000000",@"ammostore_initialqt",
                          @"444441004424440221011212122242200000000200040001",@"ammostore_probability",
                          @"000000000000000000000000000000000000000000000000",@"ammostore_delay",
@@ -106,7 +102,6 @@
             break;
         case 4: //basketball
             theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
-                         [NSNumber numberWithInt:HW_getNumberOfWeapons()],@"version",
                          @"939192942219912103223511100120100000021111010100",@"ammostore_initialqt",
                          @"000000000000000000000000000000000000000000000000",@"ammostore_probability",
                          @"000000000000000550000004000700400000000020000000",@"ammostore_delay",
@@ -114,7 +109,6 @@
             break;
         case 5: //minefield
             theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
-                         [NSNumber numberWithInt:HW_getNumberOfWeapons()],@"version",
                          @"000000990009000000030000000000000000000000000000",@"ammostore_initialqt",
                          @"000000000000000000000000000000000000000000000000",@"ammostore_probability",
                          @"000000000000020550000004000700400000000020000000",@"ammostore_delay",
@@ -231,7 +225,7 @@
     DLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
 }
 
-BOOL isPhone () {
+BOOL inline isApplePhone () {
     return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
 }
 
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.h	Thu Oct 07 02:03:01 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.h	Thu Oct 07 02:16:29 2010 +0200
@@ -20,13 +20,13 @@
 
 
 #import <UIKit/UIKit.h>
-#import "MapConfigViewController.h"
 
+@class HelpPageViewController;
+@class MapConfigViewController;
 @class TeamConfigViewController;
 @class SchemeWeaponConfigViewController;
-@class HelpPageViewController;
 
-@interface GameConfigViewController : UIViewController <MapConfigDelegate> {
+@interface GameConfigViewController : UIViewController {
     UIImage *hedgehogImage;
     UIView *imgContainer;
     HelpPageViewController *helpPage;
@@ -39,6 +39,9 @@
 @property (nonatomic,retain) UIImage *hedgehogImage;
 @property (nonatomic,retain) UIView *imgContainer;
 @property (nonatomic,retain) HelpPageViewController *helpPage;
+@property (nonatomic,retain) MapConfigViewController *mapConfigViewController;
+@property (nonatomic,retain) TeamConfigViewController *teamConfigViewController;
+@property (nonatomic,retain) SchemeWeaponConfigViewController *schemeWeaponConfigViewController;
 
 -(IBAction) buttonPressed:(id) sender;
 -(IBAction) segmentPressed:(id) sender;
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Thu Oct 07 02:03:01 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Thu Oct 07 02:16:29 2010 +0200
@@ -21,6 +21,7 @@
 
 #import "GameConfigViewController.h"
 #import "SDL_uikitappdelegate.h"
+#import "MapConfigViewController.h"
 #import "TeamConfigViewController.h"
 #import "SchemeWeaponConfigViewController.h"
 #import "HelpPageViewController.h"
@@ -29,15 +30,21 @@
 #import "PascalImports.h"
 
 @implementation GameConfigViewController
-@synthesize hedgehogImage, imgContainer, helpPage;
+@synthesize hedgehogImage, imgContainer, helpPage, mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController;
+
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return rotationManager(interfaceOrientation);
 }
 
--(IBAction) buttonPressed:(id) sender {    
+-(IBAction) buttonPressed:(id) sender {
     // works even if it's not actually a button
-    UIButton *theButton = (UIButton *)sender;
+    UIButton *theButton;
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+        theButton = [[(NSNotification *)sender userInfo] objectForKey:@"sender"];
+    else
+        theButton = (UIButton *)sender;
+
     switch (theButton.tag) {
         case 0:
             playSound(@"backSound");
@@ -180,7 +187,7 @@
 
 -(void) startGame:(UIButton *)button {
     button.enabled = YES;
-
+    
     if ([self isEverythingSet] == NO)
         return;
 
@@ -242,25 +249,30 @@
     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(buttonPressed:)
+                                                     name:@"buttonPressed"
+                                                   object:nil];
         srandom(time(NULL));
         self.hedgehogImage = nil;
         
         // load other controllers
-        if (mapConfigViewController == nil)
-            mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
-        mapConfigViewController.delegate = self;
-        mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
-        if (teamConfigViewController == nil)
-            teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
-        teamConfigViewController.view.frame = CGRectMake(348, 200, 328, 480);
-        [mapConfigViewController.view addSubview:teamConfigViewController.view];
-        if (schemeWeaponConfigViewController == nil)
-            schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
-        schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 600);
-        [mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view];
+        if (self.mapConfigViewController == nil)
+            self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
+        if (self.teamConfigViewController == nil)
+            self.teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
+        [self.mapConfigViewController.view addSubview:self.teamConfigViewController.view];
+        if (self.schemeWeaponConfigViewController == nil)
+            self.schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
+        [self.mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view];
+        self.mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
+        self.teamConfigViewController.view.frame = CGRectMake(348, 200, 328, 480);
+        self.schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 600);
+        
     } else {
         // this is the visible controller
-        mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
+        if (mapConfigViewController == nil)
+            mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
         // this must be loaded & added to auto set default scheme and ammo
         schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
         [self.view addSubview:schemeWeaponConfigViewController.view];
@@ -344,6 +356,8 @@
         teamConfigViewController = nil;
     if (schemeWeaponConfigViewController.view.superview == nil)
         schemeWeaponConfigViewController = nil;
+    if (helpPage.view.superview == nil)
+        helpPage = nil;
 
     // Release any cached data, images, etc that aren't in use.
     self.imgContainer = nil;
@@ -353,11 +367,13 @@
 }
 
 -(void) viewDidUnload {
+    [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:@"buttonPressed"];
     self.hedgehogImage = nil;
     self.imgContainer = nil;
-    mapConfigViewController = nil;
-    teamConfigViewController = nil;
-    schemeWeaponConfigViewController = nil;
+    self.mapConfigViewController = nil;
+    self.teamConfigViewController = nil;
+    self.schemeWeaponConfigViewController = nil;
+    self.helpPage = nil;
     MSG_DIDUNLOAD();
     [super viewDidUnload];
 }
@@ -368,6 +384,7 @@
     [mapConfigViewController release];
     [teamConfigViewController release];
     [schemeWeaponConfigViewController release];
+    [helpPage release];
     [super dealloc];
 }
 
--- a/project_files/HedgewarsMobile/Classes/GameSetup.m	Thu Oct 07 02:03:01 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameSetup.m	Thu Oct 07 02:16:29 2010 +0200
@@ -120,12 +120,12 @@
     NSString *weaponPath = [[NSString alloc] initWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),ammostoreName];
     NSDictionary *ammoData = [[NSDictionary alloc] initWithContentsOfFile:weaponPath];
     [weaponPath release];
-    NSString *update = @"";
 
     // if we're loading an older version of ammos fill the engine message with 0s
-    int diff = HW_getNumberOfWeapons() - [[ammoData objectForKey:@"version"] intValue];
-    if (diff != 0)
-        update = [NSString stringWithCharacters:(const unichar*)"0000000000000000000000000000000000" length:diff];
+    int diff = HW_getNumberOfWeapons() - [[ammoData objectForKey:@"ammostore_initialqt"] length];
+    NSString *update = @"";
+    while ([update length] < diff)
+        update = [update stringByAppendingString:@"0"];
 
     NSString *ammloadt = [[NSString alloc] initWithFormat:@"eammloadt %@%@", [ammoData objectForKey:@"ammostore_initialqt"], update];
     [self sendToEngine: ammloadt];
@@ -143,7 +143,7 @@
     [self sendToEngine: ammreinf];
     [ammreinf release];
 
-    // sent twice so it applies to both teams
+    // send this for each team so it applies the same ammostore to all teams
     NSString *ammstore = [[NSString alloc] initWithString:@"eammstore"];
     for (int i = 0; i < numberOfTeams; i++)
         [self sendToEngine: ammstore];
@@ -410,9 +410,10 @@
             case 'q':
                 // game ended, can remove the savefile
                 [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil];
-                // so update the relative viewcontroler
+                // so update the relative viewcontroler and the overlay
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"removedSave" object:nil];
-                // and disable the overlay
+                // and remove + disable the overlay
+                [[NSNotificationCenter defaultCenter] postNotificationName:@"remove overlay" object:nil];
                 setGameRunning(NO);
                 break;
             default:
--- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.h	Thu Oct 07 02:03:01 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.h	Thu Oct 07 02:16:29 2010 +0200
@@ -22,16 +22,7 @@
 #import <UIKit/UIKit.h>
 #import "MapPreviewButtonView.h"
 
-@protocol MapConfigDelegate <NSObject>
-
--(void) buttonPressed:(id) sender;
-
-@end
-
-
 @interface MapConfigViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, MapPreviewViewDelegate> {
-    id<MapConfigDelegate> delegate;
-    
     NSInteger oldValue;  //slider
     NSInteger oldPage;   //segmented control
     BOOL busy;
@@ -59,7 +50,6 @@
     NSArray *dataSourceArray;
 }
 
-@property (nonatomic,retain) id<MapConfigDelegate> delegate;
 
 @property (nonatomic,assign) NSInteger maxHogs;
 @property (nonatomic,assign) BOOL busy;
--- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Thu Oct 07 02:03:01 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Thu Oct 07 02:16:29 2010 +0200
@@ -29,7 +29,7 @@
 
 @implementation MapConfigViewController
 @synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand, staticMapCommand,
-            missionCommand, tableView, maxLabel, sizeLabel, segmentedControl, slider, lastIndexPath, dataSourceArray, busy, delegate;
+            missionCommand, tableView, maxLabel, sizeLabel, segmentedControl, slider, lastIndexPath, dataSourceArray, busy;
 
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
@@ -366,10 +366,9 @@
 }
 
 #pragma mark -
-#pragma mark delegate functions for iPad
+#pragma mark calls the parent's function that checks the parameters and starts the game
 -(IBAction) buttonPressed:(id) sender {
-    if (self.delegate != nil && [delegate respondsToSelector:@selector(buttonPressed:)])
-        [self.delegate buttonPressed:(UIButton *)sender];
+    [[NSNotificationCenter defaultCenter] postNotificationName:@"buttonPressed" object:nil userInfo:[NSDictionary dictionaryWithObject:sender forKey:@"sender"]];
 }
 
 -(void) loadDataSourceArray {
@@ -443,8 +442,6 @@
 }
 
 -(void) viewDidUnload {
-    self.delegate = nil;
-    
     self.previewButton = nil;
     self.seedCommand = nil;
     self.templateFilterCommand = nil;
@@ -477,8 +474,6 @@
 }
 
 -(void) dealloc {
-    self.delegate = nil;
-    
     [seedCommand release];
     [templateFilterCommand release];
     [mapGenCommand release];
--- a/project_files/HedgewarsMobile/Classes/PascalImports.h	Thu Oct 07 02:03:01 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h	Thu Oct 07 02:16:29 2010 +0200
@@ -82,7 +82,8 @@
     void HW_setPianoSound(int snd);
     
     void HW_setWeapon(int whichone);
-    unsigned char *HW_getDelays(void);
+    unsigned char *HW_getAmmoDelays(void);
+    unsigned char *HW_getAmmoCounts(void);
     int  HW_getTurnsForCurrentTeam(void);
     int  HW_getNumberOfWeapons(void);
     char *HW_getWeaponNameByIndex(int whichone);
--- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m	Thu Oct 07 02:03:01 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m	Thu Oct 07 02:16:29 2010 +0200
@@ -103,7 +103,6 @@
     NSString *cratenessStr = [NSString stringWithUTF8String:crateness];
     
     NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys:
-                            [NSNumber numberWithInt:HW_getNumberOfWeapons()],@"version",
                             quantityStr,@"ammostore_initialqt",
                             probabilityStr,@"ammostore_probability",
                             delayStr,@"ammostore_delay",