cocoaTouch/otherSrc/CommodityFunctions.m
author nemo
Mon, 17 May 2010 15:50:48 +0000
changeset 3474 c6d308f5a431
parent 3405 8fdb08497bf1
child 3479 972ae3ec178a
permissions -rw-r--r--
Skip collision on X for barrels that aren't knocked over
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     1
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     2
//  CommodityFunctions.m
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     3
//  HedgewarsMobile
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     4
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     5
//  Created by Vittorio on 08/04/10.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     7
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     8
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     9
#import "CommodityFunctions.h"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    10
#import "SDL_uikitappdelegate.h"
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    11
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    12
void createTeamNamed (NSString *nameWithoutExt) {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    13
    NSString *teamsDirectory = TEAMS_DIRECTORY();
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    14
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    15
    if (![[NSFileManager defaultManager] fileExistsAtPath: teamsDirectory]) {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    16
        [[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    17
                                  withIntermediateDirectories:NO 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    18
                                                   attributes:nil 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    19
                                                        error:NULL];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    20
    }
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    21
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    22
    NSMutableArray *hedgehogs = [[NSMutableArray alloc] initWithCapacity: MAX_HOGS];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    23
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    24
    for (int i = 0; i < MAX_HOGS; i++) {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    25
        NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents: 3335
diff changeset
    26
	NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health", [NSNumber numberWithInt:0],@"level",
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    27
                             hogName,@"hogname", @"NoHat",@"hat", nil];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    28
        [hogName release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    29
        [hedgehogs addObject:hog];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    30
        [hog release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    31
    }
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    32
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    33
    NSDictionary *theTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"0",@"hash", nameWithoutExt,@"teamname",
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    34
                             @"Statue",@"grave", @"Plane",@"fort", @"Default",@"voicepack",
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    35
                             @"hedgewars",@"flag", hedgehogs,@"hedgehogs", nil];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    36
    [hedgehogs release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    37
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    38
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", teamsDirectory, nameWithoutExt];
3352
ac5d14a35482 complete previews on the team settings
koda
parents: 3340
diff changeset
    39
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    40
    [theTeam writeToFile:teamFile atomically:YES];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    41
    [teamFile release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    42
    [theTeam release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    43
}
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    44
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    45
BOOL rotationManager (UIInterfaceOrientation interfaceOrientation) {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    46
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
3405
8fdb08497bf1 js' patch that restores Vsync on snow leopard
koda
parents: 3385
diff changeset
    47
        return YES;
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    48
    else
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    49
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    50
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    51
}
3365
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3352
diff changeset
    52
3373
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    53
NSInteger randomPort () {
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    54
    srandom(time(NULL));
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    55
    return (random() % 64511) + 1024;
3365
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3352
diff changeset
    56
}
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3352
diff changeset
    57
3373
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    58
void popError (const char *title, const char *message) {
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    59
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithUTF8String:title]
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    60
                                                    message:[NSString stringWithUTF8String:message]
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    61
                                                   delegate:nil
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    62
                                          cancelButtonTitle:@"Ok"
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    63
                                          otherButtonTitles:nil];
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    64
    [alert show];
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    65
    [alert release];
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    66
}
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    67
    
3365
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3352
diff changeset
    68
3373
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3365
diff changeset
    69