project_files/HedgewarsMobile/Classes/GameSetup.m
changeset 4760 224c31b3ce7d
parent 4757 7ca9ebb6895d
child 4769 42adc7c11980
equal deleted inserted replaced
4757:7ca9ebb6895d 4760:224c31b3ce7d
    26 #import "OverlayViewController.h"
    26 #import "OverlayViewController.h"
    27 
    27 
    28 #define BUFFER_SIZE 255     // like in original frontend
    28 #define BUFFER_SIZE 255     // like in original frontend
    29 
    29 
    30 @implementation GameSetup
    30 @implementation GameSetup
    31 @synthesize systemSettings, gameConfig, statsDictionary, savePath, menuStyle;
    31 @synthesize systemSettings, gameConfig, statsArray, savePath, menuStyle;
    32 
    32 
    33 -(id) initWithDictionary:(NSDictionary *)gameDictionary {
    33 -(id) initWithDictionary:(NSDictionary *)gameDictionary {
    34     if (self = [super init]) {
    34     if (self = [super init]) {
    35         ipcPort = randomPort();
    35         ipcPort = randomPort();
    36 
    36 
    56             self.savePath = [SAVES_DIRECTORY() stringByAppendingFormat:@"%@.hws", newDateString];
    56             self.savePath = [SAVES_DIRECTORY() stringByAppendingFormat:@"%@.hws", newDateString];
    57             [outputFormatter release];
    57             [outputFormatter release];
    58         } else
    58         } else
    59             self.savePath = path;
    59             self.savePath = path;
    60 
    60 
    61         self.statsDictionary = nil;
    61         self.statsArray = nil;
    62     }
    62     }
    63     return self;
    63     return self;
    64 }
    64 }
    65 
    65 
    66 -(void) dealloc {
    66 -(void) dealloc {
    67     [statsDictionary release];
    67     [statsArray release];
    68     [gameConfig release];
    68     [gameConfig release];
    69     [systemSettings release];
    69     [systemSettings release];
    70     [savePath release];
    70     [savePath release];
    71     [super dealloc];
    71     [super dealloc];
    72 }
    72 }
   347                     DLog(@"ERROR - wrong protocol number: %d (expecting %d)", netProto, eProto);
   347                     DLog(@"ERROR - wrong protocol number: %d (expecting %d)", netProto, eProto);
   348                     clientQuit = YES;
   348                     clientQuit = YES;
   349                 }
   349                 }
   350                 break;
   350                 break;
   351             case 'i':
   351             case 'i':
       
   352                 if (self.statsArray == nil)
       
   353                     self.statsArray = [[NSMutableArray alloc] initWithCapacity:statMaxCapacity];
   352                 switch (buffer[1]) {
   354                 switch (buffer[1]) {
   353                     case 'r':
   355                     case 'r':           // winning team
   354                         if (self.statsDictionary == nil)
   356                         [self.statsArray insertObject:[NSString stringWithUTF8String:&buffer[2]] atIndex:0];
   355                             self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity];
   357                         break;
   356                         [self.statsDictionary setObject:[NSString stringWithUTF8String:&buffer[2]] forKey:@"winning_team"];
   358                     case 'D':           // best shot
   357                         break;
   359                         [self.statsArray addObject:[NSString stringWithFormat:@"Best shot by %s", &buffer[2]]];
   358                     case 'D':
   360                         break;
   359                         if (self.statsDictionary == nil)
   361                     case 'k':           // best hedgehog
   360                             self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity];
   362                         [self.statsArray addObject:[NSString stringWithFormat:@"Best hedgehog: %s", &buffer[2]]];
   361                         [self.statsDictionary setObject:[NSString stringWithFormat:@"Best shot: %s", &buffer[2]] forKey:@"best_shot"];
   363                         break;
   362                         break;
   364                     case 'K':           // number of hogs killed
   363                     case 'k':
   365                         [self.statsArray addObject:[NSString stringWithFormat:@"%s hogs killed", &buffer[2]]];
   364                         if (self.statsDictionary == nil)
   366                         break;
   365                             self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity];
   367                     case 'H':           //something about team health
   366                         [self.statsDictionary setObject:[NSString stringWithFormat:@"Best hedgehog: %s", &buffer[2]] forKey:@"best_hog"];
   368                         break;
   367                         break;
   369                     case 'T':           // local team stats
   368                     case 'K':
   370                         break;
   369                         if (self.statsDictionary == nil)
   371                     case 'P':           // player postion
   370                             self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity];
   372                         break;
   371                         [self.statsDictionary setObject:[NSString stringWithFormat:@"%s hogs killed", &buffer[2]] forKey:@"kills"];
   373                     case 's':           // self damage
   372                         break;
   374                         [self.statsArray addObject:[NSString stringWithFormat:@"%s hit himself", &buffer[2]]];
   373                     case 'H':
   375                         break;
   374                         //something about team health
   376                     case 'S':           // friendly fire
   375                         break;
   377                         [self.statsArray addObject:[NSString stringWithFormat:@"%s hit his friends", &buffer[2]]];
   376                     case 'T':
   378                         break;
   377                         // local team stats
   379                     case 'B':           // turn skipped
   378                         break;
   380                         [self.statsArray addObject:[NSString stringWithFormat:@"%s skipped most turns", &buffer[2]]];
   379                     case 'P':
       
   380                         // player postion
       
   381                         break;
       
   382                     case 's':
       
   383                         if (self.statsDictionary == nil)
       
   384                             self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity];
       
   385                         [self.statsDictionary setObject:[NSString stringWithFormat:@"%s hit himself", &buffer[2]] forKey:@"self_dmg"];
       
   386                         break;
       
   387                     case 'S':
       
   388                         if (self.statsDictionary == nil)
       
   389                             self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity];
       
   390                         [self.statsDictionary setObject:[NSString stringWithFormat:@"%s hit his friends", &buffer[2]] forKey:@"friendly_fire"];
       
   391                         break;
       
   392                     case 'B':
       
   393                         if (self.statsDictionary == nil)
       
   394                             self.statsDictionary = [[NSMutableDictionary alloc] initWithCapacity:statMaxCapacity];
       
   395                         [self.statsDictionary setObject:[NSString stringWithFormat:@"%s skipped most turns", &buffer[2]] forKey:@"turn_skips"];
       
   396                         break;
   381                         break;
   397                     default:
   382                     default:
   398                         DLog(@"Unhandled stat message, see statsPage.cpp");
   383                         DLog(@"Unhandled stat message, see statsPage.cpp");
   399                         break;
   384                         break;
   400                 }
   385                 }