author | koda |
Sat, 05 Jun 2010 14:07:58 +0000 | |
changeset 3495 | a6b4f351d400 |
parent 3490 | 016b3172b645 |
child 3513 | f589230fa21b |
permissions | -rw-r--r-- |
3325 | 1 |
// |
2 |
// CommodityFunctions.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 08/04/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "CommodityFunctions.h" |
|
3490 | 10 |
#import <mach/mach.h> |
11 |
#import <mach/mach_host.h> |
|
3325 | 12 |
|
13 |
void createTeamNamed (NSString *nameWithoutExt) { |
|
14 |
NSString *teamsDirectory = TEAMS_DIRECTORY(); |
|
15 |
||
16 |
if (![[NSFileManager defaultManager] fileExistsAtPath: teamsDirectory]) { |
|
17 |
[[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory |
|
18 |
withIntermediateDirectories:NO |
|
19 |
attributes:nil |
|
20 |
error:NULL]; |
|
21 |
} |
|
22 |
||
23 |
NSMutableArray *hedgehogs = [[NSMutableArray alloc] initWithCapacity: MAX_HOGS]; |
|
24 |
||
25 |
for (int i = 0; i < MAX_HOGS; i++) { |
|
26 |
NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i]; |
|
3479 | 27 |
NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:0],@"level", |
3325 | 28 |
hogName,@"hogname", @"NoHat",@"hat", nil]; |
29 |
[hogName release]; |
|
30 |
[hedgehogs addObject:hog]; |
|
31 |
[hog release]; |
|
32 |
} |
|
33 |
||
34 |
NSDictionary *theTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"0",@"hash", nameWithoutExt,@"teamname", |
|
35 |
@"Statue",@"grave", @"Plane",@"fort", @"Default",@"voicepack", |
|
36 |
@"hedgewars",@"flag", hedgehogs,@"hedgehogs", nil]; |
|
37 |
[hedgehogs release]; |
|
38 |
||
39 |
NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", teamsDirectory, nameWithoutExt]; |
|
3352 | 40 |
|
3325 | 41 |
[theTeam writeToFile:teamFile atomically:YES]; |
42 |
[teamFile release]; |
|
43 |
[theTeam release]; |
|
44 |
} |
|
3330 | 45 |
|
3479 | 46 |
void createSchemeNamed (NSString *nameWithoutExt) { |
47 |
NSString *schemesDirectory = SCHEMES_DIRECTORY(); |
|
48 |
||
49 |
if (![[NSFileManager defaultManager] fileExistsAtPath: schemesDirectory]) { |
|
50 |
[[NSFileManager defaultManager] createDirectoryAtPath:schemesDirectory |
|
51 |
withIntermediateDirectories:NO |
|
52 |
attributes:nil |
|
53 |
error:NULL]; |
|
54 |
} |
|
55 |
||
56 |
NSArray *theScheme = [[NSArray alloc] initWithObjects: |
|
57 |
[NSNumber numberWithBool:NO], //fortmode |
|
58 |
[NSNumber numberWithBool:NO], //divideteam |
|
59 |
[NSNumber numberWithBool:NO], //solidland |
|
60 |
[NSNumber numberWithBool:NO], //addborder |
|
61 |
[NSNumber numberWithBool:NO], //lowgravity |
|
62 |
[NSNumber numberWithBool:NO], //lasersight |
|
63 |
[NSNumber numberWithBool:NO], //invulnerable |
|
64 |
[NSNumber numberWithBool:NO], //addmines |
|
65 |
[NSNumber numberWithBool:NO], //vampirism |
|
66 |
[NSNumber numberWithBool:NO], //karma |
|
67 |
[NSNumber numberWithBool:NO], //artillery |
|
68 |
[NSNumber numberWithBool:YES], //randomorder |
|
69 |
[NSNumber numberWithBool:NO], //king |
|
70 |
[NSNumber numberWithBool:NO], //placehedgehogs |
|
71 |
[NSNumber numberWithBool:NO], //clansharesammo |
|
72 |
[NSNumber numberWithBool:NO], //disablegirders |
|
73 |
[NSNumber numberWithBool:NO], //disablelandobjects |
|
74 |
[NSNumber numberWithInt:100], //damagemodifier |
|
75 |
[NSNumber numberWithInt:45], //turntime |
|
76 |
[NSNumber numberWithInt:100], //initialhealth |
|
77 |
[NSNumber numberWithInt:15], //suddendeathtimeout |
|
78 |
[NSNumber numberWithInt:5], //cratedrops |
|
79 |
[NSNumber numberWithInt:3], //minestime |
|
80 |
[NSNumber numberWithInt:4], //mines |
|
81 |
[NSNumber numberWithInt:0], //dudmines |
|
82 |
[NSNumber numberWithInt:2], //explosives |
|
83 |
nil]; |
|
84 |
||
85 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", schemesDirectory, nameWithoutExt]; |
|
86 |
||
87 |
[theScheme writeToFile:schemeFile atomically:YES]; |
|
88 |
[schemeFile release]; |
|
89 |
[theScheme release]; |
|
90 |
} |
|
91 |
||
3335 | 92 |
BOOL rotationManager (UIInterfaceOrientation interfaceOrientation) { |
93 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
|
3405 | 94 |
return YES; |
3335 | 95 |
else |
96 |
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
|
97 |
||
98 |
} |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3352
diff
changeset
|
99 |
|
3373 | 100 |
NSInteger randomPort () { |
101 |
srandom(time(NULL)); |
|
102 |
return (random() % 64511) + 1024; |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3352
diff
changeset
|
103 |
} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3352
diff
changeset
|
104 |
|
3373 | 105 |
void popError (const char *title, const char *message) { |
106 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithUTF8String:title] |
|
107 |
message:[NSString stringWithUTF8String:message] |
|
108 |
delegate:nil |
|
109 |
cancelButtonTitle:@"Ok" |
|
110 |
otherButtonTitles:nil]; |
|
111 |
[alert show]; |
|
112 |
[alert release]; |
|
113 |
} |
|
3490 | 114 |
|
115 |
// by http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html |
|
116 |
void print_free_memory () { |
|
117 |
mach_port_t host_port; |
|
118 |
mach_msg_type_number_t host_size; |
|
119 |
vm_size_t pagesize; |
|
3373 | 120 |
|
3490 | 121 |
host_port = mach_host_self(); |
122 |
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t); |
|
123 |
host_page_size(host_port, &pagesize); |
|
124 |
||
125 |
vm_statistics_data_t vm_stat; |
|
126 |
||
127 |
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) |
|
128 |
DLog(@"Failed to fetch vm statistics"); |
|
129 |
||
130 |
/* Stats in bytes */ |
|
131 |
natural_t mem_used = (vm_stat.active_count + |
|
132 |
vm_stat.inactive_count + |
|
133 |
vm_stat.wire_count) * pagesize; |
|
134 |
natural_t mem_free = vm_stat.free_count * pagesize; |
|
135 |
natural_t mem_total = mem_used + mem_free; |
|
136 |
DLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total); |
|
137 |
} |