cocoaTouch/GameSetup.m
changeset 3170 1dbf4f8eaac0
parent 3165 3ec07a7d8456
child 3199 1a9938a27677
equal deleted inserted replaced
3169:c8c6ac44f51b 3170:1dbf4f8eaac0
    15 
    15 
    16 #define BUFFER_SIZE 256
    16 #define BUFFER_SIZE 256
    17 
    17 
    18 @implementation GameSetup
    18 @implementation GameSetup
    19 
    19 
    20 @synthesize systemSettings;
    20 @synthesize systemSettings, teams;
    21 
    21 
    22 -(id) init {
    22 -(id) init {
    23 	self = [super init];
    23 	if (self = [super init]) {
    24 	srandom(time(NULL));
    24     	srandom(time(NULL));
    25 	ipcPort = (random() % 64541) + 1025;
    25         ipcPort = (random() % 64541) + 1025;
    26 		
    26     
    27 	NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
    27         NSDictionary *hogA1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Snow Leopard",@"hogname",@"NoHat",@"hat",nil];
    28 	systemSettings = [[NSDictionary alloc] initWithContentsOfFile:filePath]; //should check it exists
    28         NSDictionary *hogA2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Leopard",@"hogname",@"NoHat",@"hat",nil];
    29 	return self;
    29         NSArray *hedgehogs1 = [[NSArray alloc] initWithObjects:hogA1,hogA2,nil];
       
    30         [hogA1 release];
       
    31         [hogA2 release];
       
    32         NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash",@"System Cats",@"teamname",
       
    33                                    @"star",@"grave",@"Earth",@"fort",@"Classic",@"voicepack",@"hedgewars",@"flag",hedgehogs1,@"hedgehogs",
       
    34                                    @"93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111",
       
    35                                    @"ammostore",nil];
       
    36         [hedgehogs1 release];
       
    37         
       
    38         NSDictionary *hogB1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Raichu",@"hogname",@"Bunny",@"hat",nil];
       
    39         NSDictionary *hogB2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Pikachu",@"hogname",@"Bunny",@"hat",nil];
       
    40         NSArray *hedgehogs2 = [[NSArray alloc] initWithObjects:hogB1,hogB2,nil];
       
    41         [hogB1 release];
       
    42         [hogB2 release];
       
    43         NSDictionary *secondTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4100897",@"color",@"0",@"hash",@"Poke-MAN",@"teamname",
       
    44                                     @"Badger",@"grave",@"UFO",@"fort",@"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs2,@"hedgehogs",
       
    45                                     @"93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111",
       
    46                                     @"ammostore",nil];
       
    47         [hedgehogs2 release];
       
    48         
       
    49         teams = [[NSArray alloc] initWithObjects: firstTeam, secondTeam, nil];
       
    50         [firstTeam release];
       
    51         [secondTeam release];
       
    52         
       
    53         NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
       
    54         systemSettings = [[NSDictionary alloc] initWithContentsOfFile:filePath]; //should check it exists
       
    55         return self;
       
    56     } else
       
    57         return nil;
    30 }
    58 }
    31 
    59 
    32 -(void) dealloc {
    60 -(void) dealloc {
       
    61     [teams release];
    33     [systemSettings release];
    62     [systemSettings release];
    34 	[super dealloc];
    63 	[super dealloc];
    35 }
    64 }
    36 
    65 
    37 #pragma mark -
    66 #pragma mark -
    44 -(int) sendToEngine: (NSString *)string {
    73 -(int) sendToEngine: (NSString *)string {
    45 	Uint8 length = [string length];
    74 	Uint8 length = [string length];
    46 	
    75 	
    47 	SDLNet_TCP_Send(csd, &length , 1);
    76 	SDLNet_TCP_Send(csd, &length , 1);
    48 	return SDLNet_TCP_Send(csd, [string UTF8String], length);
    77 	return SDLNet_TCP_Send(csd, [string UTF8String], length);
       
    78 }
       
    79 
       
    80 -(void) sendTeamData:(NSDictionary *)teamData {
       
    81     NSString *teamHashColorAndName = [[NSString alloc] initWithFormat:@"eaddteam %@ %@ %@", [teamData objectForKey:@"hash"], [teamData objectForKey:@"color"], [teamData objectForKey:@"teamname"]];
       
    82     [self sendToEngine: teamHashColorAndName];
       
    83     [teamHashColorAndName release];
       
    84     
       
    85     NSString *grave = [[NSString alloc] initWithFormat:@"egrave %@", [teamData objectForKey:@"grave"]];
       
    86     [self sendToEngine: grave];
       
    87     [grave release];
       
    88     
       
    89     NSString *fort = [[NSString alloc] initWithFormat:@"efort %@", [teamData objectForKey:@"fort"]];
       
    90     [self sendToEngine: fort];
       
    91     [fort release];
       
    92     
       
    93     NSString *voicepack = [[NSString alloc] initWithFormat:@"evoicepack %@", [teamData objectForKey:@"voicepack"]];
       
    94     [self sendToEngine: voicepack];
       
    95     [voicepack release];
       
    96     
       
    97     NSString *flag = [[NSString alloc] initWithFormat:@"eflag %@", [teamData objectForKey:@"flag"]];
       
    98     [self sendToEngine: flag];
       
    99     [flag release];
       
   100     
       
   101     NSArray *hogs = [teamData objectForKey:@"hedgehogs"];
       
   102     for (NSDictionary *hog in hogs) {
       
   103         NSString *hogLevelHealthAndName = [[NSString alloc] initWithFormat:@"eaddhh %@ %@ %@", [hog objectForKey:@"level"], [hog objectForKey:@"health"], [hog objectForKey:@"hogname"]];
       
   104         [self sendToEngine: hogLevelHealthAndName];
       
   105         [hogLevelHealthAndName release];
       
   106         
       
   107         NSString *hogHat = [[NSString alloc] initWithFormat:@"ehat %@", [hog objectForKey:@"hat"]];
       
   108         [self sendToEngine: hogHat];
       
   109         [hogHat release];
       
   110     }
       
   111     
       
   112     NSString *ammostore = [[NSString alloc] initWithFormat:@"eammstore %@", [teamData objectForKey:@"ammostore"]];
       
   113     [self sendToEngine: ammostore];
       
   114     [ammostore release];
    49 }
   115 }
    50 
   116 
    51 -(void) engineProtocol {
   117 -(void) engineProtocol {
    52 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   118 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    53 	IPaddress ip;
   119 	IPaddress ip;
   122 				[self sendToEngine:@"e$template_filter 1"];
   188 				[self sendToEngine:@"e$template_filter 1"];
   123 								
   189 								
   124 				// theme info
   190 				// theme info
   125 				[self sendToEngine:@"etheme Compost"];
   191 				[self sendToEngine:@"etheme Compost"];
   126 				
   192 				
   127 				// team 1 info
   193                 for (NSDictionary *teamData in teams) {
   128 				[self sendToEngine:@"eaddteam 0 4421353 System Cats"];
   194                     [self sendTeamData:teamData];
   129 				
   195                     NSLog(@"teamData sent");
   130 				// team 1 grave info
   196                 }
   131 				[self sendToEngine:@"egrave star"];
       
   132 				
       
   133 				// team 1 fort info
       
   134 				[self sendToEngine:@"efort Earth"];
       
   135 								
   197 								
   136 				// team 1 voicepack info
   198 			clientQuit = NO;
   137 				[self sendToEngine:@"evoicepack Classic"];
       
   138 				
       
   139 				// team 1 flag
       
   140 				[self sendToEngine:@"eflag hedgewars"];
       
   141 
       
   142 				// team 1 binds (skipped)			
       
   143 				// team 1 members info
       
   144 				[self sendToEngine:@"eaddhh 0 100 Snow Leopard"];
       
   145 				[self sendToEngine:@"ehat NoHat"];
       
   146 
       
   147 				// team 1 ammostore
       
   148 				[self sendToEngine:@"eammstore 93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111"];
       
   149 				
       
   150 				// team 2 info
       
   151 				[self sendToEngine:@"eaddteam 0 4100897 Poke-MAN"];
       
   152 				
       
   153 				// team 2 grave info
       
   154 				[self sendToEngine:@"egrave Badger"];
       
   155 				
       
   156 				// team 2 fort info
       
   157 				[self sendToEngine:@"efort UFO"];
       
   158 				
       
   159 				// team 2 voicepack info
       
   160 				[self sendToEngine:@"evoicepack Classic"];
       
   161 
       
   162 				// team 2 flag
       
   163 				[self sendToEngine:@"eflag hedgewars"];
       
   164 
       
   165 				// team 2 binds (skipped)
       
   166 				// team 2 members info
       
   167 				[self sendToEngine:@"eaddhh 0 100 Raichu"];
       
   168 				[self sendToEngine:@"ehat Bunny"];
       
   169 
       
   170 				// team 2 ammostore
       
   171 				[self sendToEngine:@"eammstore 93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111"];
       
   172 				
       
   173 				clientQuit = NO;
       
   174 			} else {
   199 			} else {
   175 				NSLog(@"engineProtocolThread - wrong message or client closed connection");
   200 				NSLog(@"engineProtocolThread - wrong message or client closed connection");
   176 				clientQuit = YES;
   201 				clientQuit = YES;
   177 			}
   202 			}
   178 			
   203