3547
|
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"
|
|
10 |
#import <mach/mach.h>
|
|
11 |
#import <mach/mach_host.h>
|
|
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];
|
|
27 |
NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:0],@"level",
|
|
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];
|
|
40 |
|
|
41 |
[theTeam writeToFile:teamFile atomically:YES];
|
|
42 |
[teamFile release];
|
|
43 |
[theTeam release];
|
|
44 |
}
|
|
45 |
|
|
46 |
void createWeaponNamed (NSString *nameWithoutExt) {
|
|
47 |
NSString *weaponsDirectory = WEAPONS_DIRECTORY();
|
|
48 |
|
|
49 |
if (![[NSFileManager defaultManager] fileExistsAtPath: weaponsDirectory]) {
|
|
50 |
[[NSFileManager defaultManager] createDirectoryAtPath:weaponsDirectory
|
|
51 |
withIntermediateDirectories:NO
|
|
52 |
attributes:nil
|
|
53 |
error:NULL];
|
|
54 |
}
|
|
55 |
|
|
56 |
NSDictionary *theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
|
3621
|
57 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version",
|
3598
|
58 |
@"9391929422199121032235111001201000000211110111",@"ammostore_initialqt",
|
|
59 |
@"0405040541600655546554464776576666666155510111",@"ammostore_probability",
|
3547
|
60 |
@"0000000000000205500000040007004000000000200000",@"ammostore_delay",
|
3598
|
61 |
@"1311110312111111123114111111111111111211111111",@"ammostore_crate", nil];
|
3547
|
62 |
|
|
63 |
NSString *weaponFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", weaponsDirectory, nameWithoutExt];
|
|
64 |
|
|
65 |
[theWeapon writeToFile:weaponFile atomically:YES];
|
|
66 |
[weaponFile release];
|
|
67 |
[theWeapon release];
|
|
68 |
}
|
|
69 |
|
|
70 |
void createSchemeNamed (NSString *nameWithoutExt) {
|
|
71 |
NSString *schemesDirectory = SCHEMES_DIRECTORY();
|
|
72 |
|
|
73 |
if (![[NSFileManager defaultManager] fileExistsAtPath: schemesDirectory]) {
|
|
74 |
[[NSFileManager defaultManager] createDirectoryAtPath:schemesDirectory
|
|
75 |
withIntermediateDirectories:NO
|
|
76 |
attributes:nil
|
|
77 |
error:NULL];
|
|
78 |
}
|
|
79 |
|
|
80 |
NSArray *theScheme = [[NSArray alloc] initWithObjects:
|
|
81 |
[NSNumber numberWithBool:NO], //fortmode
|
|
82 |
[NSNumber numberWithBool:NO], //divideteam
|
|
83 |
[NSNumber numberWithBool:NO], //solidland
|
|
84 |
[NSNumber numberWithBool:NO], //addborder
|
|
85 |
[NSNumber numberWithBool:NO], //lowgravity
|
|
86 |
[NSNumber numberWithBool:NO], //lasersight
|
|
87 |
[NSNumber numberWithBool:NO], //invulnerable
|
3573
|
88 |
[NSNumber numberWithBool:YES], //addmines
|
3547
|
89 |
[NSNumber numberWithBool:NO], //vampirism
|
|
90 |
[NSNumber numberWithBool:NO], //karma
|
|
91 |
[NSNumber numberWithBool:NO], //artillery
|
|
92 |
[NSNumber numberWithBool:YES], //randomorder
|
|
93 |
[NSNumber numberWithBool:NO], //king
|
|
94 |
[NSNumber numberWithBool:NO], //placehedgehogs
|
|
95 |
[NSNumber numberWithBool:NO], //clansharesammo
|
|
96 |
[NSNumber numberWithBool:NO], //disablegirders
|
|
97 |
[NSNumber numberWithBool:NO], //disablelandobjects
|
|
98 |
[NSNumber numberWithInt:100], //damagemodifier
|
|
99 |
[NSNumber numberWithInt:45], //turntime
|
|
100 |
[NSNumber numberWithInt:100], //initialhealth
|
|
101 |
[NSNumber numberWithInt:15], //suddendeathtimeout
|
|
102 |
[NSNumber numberWithInt:5], //cratedrops
|
|
103 |
[NSNumber numberWithInt:3], //minestime
|
|
104 |
[NSNumber numberWithInt:4], //mines
|
|
105 |
[NSNumber numberWithInt:0], //dudmines
|
|
106 |
[NSNumber numberWithInt:2], //explosives
|
|
107 |
nil];
|
|
108 |
|
|
109 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", schemesDirectory, nameWithoutExt];
|
|
110 |
|
|
111 |
[theScheme writeToFile:schemeFile atomically:YES];
|
|
112 |
[schemeFile release];
|
|
113 |
[theScheme release];
|
|
114 |
}
|
|
115 |
|
|
116 |
BOOL rotationManager (UIInterfaceOrientation interfaceOrientation) {
|
3551
|
117 |
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) ||
|
|
118 |
(interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
|
3547
|
119 |
}
|
|
120 |
|
|
121 |
NSInteger randomPort () {
|
|
122 |
srandom(time(NULL));
|
|
123 |
return (random() % 64511) + 1024;
|
|
124 |
}
|
|
125 |
|
|
126 |
void popError (const char *title, const char *message) {
|
|
127 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithUTF8String:title]
|
|
128 |
message:[NSString stringWithUTF8String:message]
|
|
129 |
delegate:nil
|
|
130 |
cancelButtonTitle:@"Ok"
|
|
131 |
otherButtonTitles:nil];
|
|
132 |
[alert show];
|
|
133 |
[alert release];
|
|
134 |
}
|
|
135 |
|
|
136 |
// by http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html
|
|
137 |
void print_free_memory () {
|
|
138 |
mach_port_t host_port;
|
|
139 |
mach_msg_type_number_t host_size;
|
|
140 |
vm_size_t pagesize;
|
|
141 |
|
|
142 |
host_port = mach_host_self();
|
|
143 |
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
|
|
144 |
host_page_size(host_port, &pagesize);
|
|
145 |
|
|
146 |
vm_statistics_data_t vm_stat;
|
|
147 |
|
|
148 |
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS)
|
|
149 |
DLog(@"Failed to fetch vm statistics");
|
|
150 |
|
|
151 |
/* Stats in bytes */
|
|
152 |
natural_t mem_used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pagesize;
|
|
153 |
natural_t mem_free = vm_stat.free_count * pagesize;
|
|
154 |
natural_t mem_total = mem_used + mem_free;
|
|
155 |
DLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
|
|
156 |
}
|