00001
00002
00003
00004
00005
00006
00007
00008
00009 #import "ShortPacketWarningHandler.h"
00010 #import "LLNotificationCenter.h"
00011 #import "MessageConstants.h"
00012 #import "RCMmessage.h"
00013
00014
00015 @implementation ShortPacketWarningHandler
00016
00017
00018
00019 int arg3;
00020 int arg4;
00021 int karg3;
00022 int karg4;
00023 int karg5;
00024
00025 - (id) init {
00026 self = [super init];
00027 if (self != nil) {
00028 deamonMessages = [NSArray arrayWithObjects:
00029 @"Game is paused. CONTINUE to continue.",
00030 @"Game is no-longer paused!",
00031 @"Game is paused. Captains CONTINUE to continue.",
00032 @"Game will continue in 10 seconds",
00033 @"Teams chosen. Game will start in 1 minute.",
00034 @"----------- Game will start in 1 minute -------------",
00035 nil];
00036 [deamonMessages retain];
00037 warningMessages = [NSArray arrayWithObjects:
00038 @"Tractor beams haven't been invented yet.",
00039 @"Weapons's Officer: Cannot tractor while cloaked, sir!",
00040 @"Weapon's Officer: Vessel is out of range of our tractor beam.",
00041 @"You must have one kill to throw a coup",
00042 @"You must orbit your home planet to throw a coup",
00043 @"You already own a planet!!!",
00044 @"You must orbit your home planet to throw a coup",
00045 @"Too many armies on planet to throw a coup",
00046 @"Planet not yet ready for a coup",
00047 @"I cannot allow that. Pick another team",
00048 @"Please confirm change of teams. Select the new team again.",
00049 @"That is an illegal ship type. Try again.",
00050 @"That ship hasn't been designed yet. Try again.",
00051 @"Your new starbase is still under construction",
00052 @"Your team is not capable of defending such an expensive ship!",
00053 @"Your team's stuggling economy cannot support such an expenditure!",
00054 @"Your side already has a starbase!",
00055 @"Plasmas haven't been invented yet.",
00056 @"Weapon's Officer: Captain, this ship is not armed with plasma torpedoes!",
00057 @"Plasma torpedo launch tube has exceeded the maximum safe temperature!",
00058 @"Our fire control system limits us to 1 live torpedo at a time captain!",
00059 @"Our fire control system limits us to 1 live torpedo at a time captain!",
00060 @"We don't have enough fuel to fire a plasma torpedo!",
00061 @"We cannot fire while our vessel is undergoing repairs.",
00062 @"We are unable to fire while in cloak, captain!",
00063 @"Torpedo launch tubes have exceeded maximum safe temperature!",
00064 @"Our computers limit us to having 8 live torpedos at a time captain!",
00065 @"We don't have enough fuel to fire photon torpedos!",
00066 @"We cannot fire while our vessel is in repair mode.",
00067 @"We are unable to fire while in cloak, captain!",
00068 @"We only have forward mounted cannons.",
00069 @"Weapons Officer: This ship is not armed with phasers, captain!",
00070 @"Phasers have not recharged",
00071 @"Not enough fuel for phaser",
00072 @"Can't fire while repairing",
00073 @"Weapons overheated",
00074 @"Cannot fire while cloaked",
00075 @"Phaser missed!!!",
00076 @"You destroyed the plasma torpedo!",
00077 @"Must be orbiting to bomb",
00078 @"Can't bomb your own armies. Have you been reading Catch-22 again?",
00079 @"Must declare war first (no Pearl Harbor syndrome allowed here).",
00080 @"Bomb out of T-mode? Please verify your order to bomb.",
00081 @"Hoser!",
00082 @"Must be orbiting or docked to beam up.",
00083 @"Those aren't our men.",
00084 @"Comm Officer: We're not authorized to beam foriegn troops on board!",
00085 @"Must be orbiting or docked to beam down.",
00086 @"Comm Officer: Starbase refuses permission to beam our troops over.",
00087 @"Pausing ten seconds to re-program battle computers.",
00088 @"You must orbit your HOME planet to apply for command reassignment!",
00089 @"You must orbit your home planet to apply for command reassignment!",
00090 @"Can only refit to starbase on your home planet.",
00091 @"You must dock YOUR starbase to apply for command reassignment!",
00092 @"Must orbit home planet or dock your starbase to apply for command reassignment!",
00093 @"Central Command refuses to accept a ship in this condition!",
00094 @"You must beam your armies down before moving to your new ship",
00095 @"That ship hasn't been designed yet.",
00096 @"Your side already has a starbase!",
00097 @"Your team is not capable of defending such an expensive ship",
00098 @"Your new starbase is still under construction",
00099 @"Your team's stuggling economy cannot support such an expenditure!",
00100 @"You are being transported to your new vessel .... @",
00101 @"Engineering: Energize. [ SFX: chimes ]",
00102 @"Wait, you forgot your toothbrush!",
00103 @"Nothing like turning in a used ship for a new one.",
00104 @"First officer: Oh no, not you again... we're doomed!",
00105 @"First officer: Uh, I'd better run diagnostics on the escape pods.",
00106 @"Shipyard controller: This time, *please* be more careful, okay?",
00107 @"Weapons officer: Not again! This is absurd...",
00108 @"Weapons officer: ... the whole ship's computer is down?",
00109 @"Weapons officer: Just to twiddle a few bits of the ship's memory?",
00110 @"Weapons officer: Bah! [ bangs fist on inoperative console ]",
00111 @"First Officer: Easy, big guy... it's just one of those mysterious",
00112 @"First Officer: laws of the universe, like 'tires on the ether'.",
00113 @"First Officer: laws of the universe, like 'Klingon bitmaps are ugly'.",
00114 @"First Officer: laws of the universe, like 'all admirals have scummed'.",
00115 @"First Officer: laws of the universe, like 'Mucus Pig exists'.",
00116 @"First Officer: laws of the universe, like 'guests advance 5x faster'.",
00117 @"Helmsman: Captain, the maximum safe speed for docking or orbiting is warp 2!",
00118 @"Central Command regulations prohibits you from orbiting foreign planets",
00119 @"Helmsman: Sensors read no valid targets in range to dock or orbit sir!",
00120 @"No more room on board for armies",
00121 @"You notice everyone on the bridge is staring at you.",
00122 @"Can't send in practice robot with other players in the game.",
00123 @"Self Destruct has been canceled",
00124 @"Be quiet",
00125 @"You are censured. Message was not sent.",
00126 @"You are ignoring that player. Message was not sent.",
00127 @"That player is censured. Message was not sent.",
00128 @"Self destruct initiated",
00129 @"Scanners haven't been invented yet",
00130 @"WARNING: BROKEN mode is enabled",
00131 @"Server can't do that UDP mode",
00132 @"Server will send with TCP only",
00133 @"Server will send with simple UDP",
00134 @"Request for fat UDP DENIED (set to simple)",
00135 @"Request for double UDP DENIED (set to simple)",
00136 @"Update request DENIED (chill out!)",
00137 @"Player lock lost while player dead.",
00138 @"Can only lock on own team.",
00139 @"You can only warp to your own team's planets!",
00140 @"Planet lock lost on change of ownership.",
00141 @" Weapons officer: Finally! systems are back online!",
00142 nil ];
00143 [warningMessages retain];
00144 notificationCenter = [LLNotificationCenter defaultCenter];
00145 serverSentStrings = [[NSMutableArray alloc] init];
00146 }
00147 return self;
00148 }
00149
00150 - (id) initWithUniverse:(Universe*)myUniverse {
00151 self = [self init];
00152 if (self != nil) {
00153 universe = myUniverse;
00154 }
00155 return self;
00156 }
00157
00158 - (NSString *) handleSWarning: (char*)buffer {
00159 int which_message = buffer & 0xFF;
00160 int arg1 = buffer & 0xFF;
00161 int arg2 = buffer & 0xFF;
00162 int temp = 0;
00163
00164 RCMmessage *rcm;
00165 NSString *message;
00166 Player *player;
00167 Planet *planet;
00168
00169 switch (which_message) {
00170 case SPW_TEXTE:
00171 temp = (arg1 | arg2 << 8);
00172 if (temp >= 0 && temp < [warningMessages count]) {
00173 message = [warningMessages objectAtIndex:temp];
00174 [notificationCenter postNotificationName:@"SPW_TEXTE" object:self userInfo:message];
00175
00176
00177 if (temp == 90) {
00178 [notificationCenter postNotificationName:@"SPW_SELF_DESTRUCT_INITIATED"];
00179 }
00180
00181 }
00182 break;
00183 case SPW_PHASER_HIT_TEXT :
00184 player = [universe playerWithId: (arg1 & 0x3F)];
00185
00186 if((arg1 & 0x40) != 0) {
00187 arg2 |= 0x100;
00188 }
00189 if((arg1 & 0x80) != 0) {
00190 arg2 |= 0x200;
00191 }
00192
00193 message = [NSString stringWithFormat: @"Phaser burst hit %@ for %d points.", [player longName], arg2];
00194 [notificationCenter postNotificationName:@"SPW_PHASER_HIT_TEXT" object:self userInfo:message];
00195
00196
00197 break;
00198 case SPW_BOMB_INEFFECTIVE :
00199 message = [NSString stringWithFormat: @"Weapons Officer: Bombing is ineffective for %d armies.", arg1];
00200 [notificationCenter postNotificationName:@"SPW_BOMB_INEFFECTIVE" object:self userInfo:message];
00201 break;
00202 case SPW_BOMB_TEXT :
00203 planet = [universe planetWithId: arg1];
00204 message = [NSString stringWithFormat: @"Bombing %d. Sensors read %d armies left.", [planet name], arg2];
00205 [notificationCenter postNotificationName:@"SPW_BOMB_TEXT" object:self userInfo:message];
00206 break;
00207 case SPW_BEAMUP_TEXT :
00208 planet = [universe planetWithId: arg1];
00209 message = [NSString stringWithFormat: @"%@: Too few armies to beam up.", [planet name]];
00210 [notificationCenter postNotificationName:@"SPW_BEAMUP_TEXT" object:self userInfo:message];
00211 break;
00212 case SPW_BEAMUP2_TEXT :
00213 message = [NSString stringWithFormat: @"Beaming up. (%d/%d)", arg1, arg2];
00214 [notificationCenter postNotificationName:@"SPW_BEAMUP2_TEXT" object:self userInfo:message];
00215 break;
00216 case SPW_BEAMUPSTARBASE_TEXT :
00217 player = [universe playerWithId: arg1];
00218 message = [NSString stringWithFormat: @"Starbase %d: Too few armies to beam up.", [player longName]];
00219 [notificationCenter postNotificationName:@"SPW_BEAMUPSTARBASE_TEXT" object:self userInfo:message];
00220 break;
00221 case SPW_BEAMDOWNSTARBASE_TEXT :
00222 player = [universe playerWithId: arg1];
00223 message = [NSString stringWithFormat: @"No more armies to beam down to Starbase %@", [player longName]];
00224 [notificationCenter postNotificationName:@"SPW_BEAMDOWNSTARBASE_TEXT" object:self userInfo:message];
00225 break;
00226 case SPW_BEAMDOWNPLANET_TEXT :
00227 planet = [universe planetWithId: arg1];
00228 message = [NSString stringWithFormat: @"No more armies to beam down to %@.", [planet name]];
00229 [notificationCenter postNotificationName:@"SPW_BEAMDOWNPLANET_TEXT" object:self userInfo:message];
00230 break;
00231 case SPW_SBREPORT :
00232 player = [universe playerWithId: arg1];
00233 message = [NSString stringWithFormat: @"Transporter Room: Starbase %@ reports all troop bunkers are full!", [player longName]];
00234 [notificationCenter postNotificationName:@"SPW_SBREPORT" object:self userInfo:message];
00235 break;
00236 case SPW_ONEARG_TEXT :
00237 switch(arg1) {
00238 case 0 :
00239 message = [NSString stringWithFormat: @"Engineering: Energizing transporters in %d seconds", arg2];
00240 break;
00241 case 1 :
00242 message = [NSString stringWithFormat: @"Stand By ... Self Destruct in %d seconds", arg2];
00243 break;
00244 case 2 :
00245 message = [NSString stringWithFormat: @"Helmsman: Docking manuever completed Captain. All moorings secured at port %d", arg2];
00246 break;
00247 case 3 :
00248 message = [NSString stringWithFormat: @"Not constructed yet. %d minutes required for completion", arg2];
00249 break;
00250 default :
00251 message = nil;
00252 }
00253 [notificationCenter postNotificationName:@"SPW_ONEARG_TEXT" object:self userInfo:message];
00254 break;
00255 case SPW_ARGUMENTS :
00256 arg3 = arg1;
00257 arg4 = arg2;
00258 break;
00259 case SPW_BEAM_D_PLANET_TEXT :
00260 planet = [universe planetWithId: arg1];
00261 message = [NSString stringWithFormat: @"Beaming down. (%d/%d) %@ has %d armies left.", arg3, arg4, [planet name], arg2];
00262 [notificationCenter postNotificationName:@"SPW_BEAM_D_PLANET_TEXT" object:self userInfo:message];
00263 break;
00264 case SPW_BEAM_U_TEXT :
00265 player = [universe playerWithId: arg1];
00266 message = [NSString stringWithFormat: @"Transfering ground units. (%d/%d) Starbase %@ has %d armies left.", arg3, arg4, [player longName], arg2];
00267 [notificationCenter postNotificationName:@"SPW_BEAM_U_TEXT" object:self userInfo:message];
00268 break;
00269 case SPW_LOCKPLANET_TEXT :
00270 planet = [universe planetWithId: arg1];
00271 message = [NSString stringWithFormat: @"Locking onto ", [planet name]];
00272 [notificationCenter postNotificationName:@"SPW_LOCKPLANET_TEXT" object:self userInfo:message];
00273 break;
00274 case SPW_LOCKPLAYER_TEXT :
00275 player = [universe playerWithId: arg1];
00276 message = [NSString stringWithFormat: @"Locking onto ", [player longName]];
00277 [notificationCenter postNotificationName:@"SPW_LOCKPLAYER_TEXT" object:self userInfo:message];
00278 break;
00279 case SPW_SBRANK_TEXT :
00280 message = [NSString stringWithFormat: @"You need a rank of %@ or higher to command a starbase!", [[universe rankWithId: arg1] name] ];
00281 [notificationCenter postNotificationName:@"SPW_SBRANK_TEXT" object:self userInfo:message];
00282 break;
00283 case SPW_SBDOCKREFUSE_TEXT :
00284 player = [universe playerWithId: arg1];
00285 message = [NSString stringWithFormat: @"Starbase %@ refusing us docking permission captain.", [player longName]];
00286 [notificationCenter postNotificationName:@"SPW_SBDOCKREFUSE_TEXT" object:self userInfo:message];
00287 break;
00288 case SPW_SBDOCKDENIED_TEXT :
00289 player = [universe playerWithId: arg1];
00290 message = [NSString stringWithFormat: @"Starbase %@ Permission to dock denied, all ports currently occupied.", [player longName]];
00291 [notificationCenter postNotificationName:@"SPW_SBDOCKDENIED_TEXT" object:self userInfo:message];
00292 break;
00293 case SPW_SBLOCKSTRANGER :
00294 player = [universe playerWithId: arg1];
00295 message = [NSString stringWithFormat: @"Locking onto ", [player longName]];
00296 [notificationCenter postNotificationName:@"SPW_SBLOCKSTRANGER" object:self userInfo:message];
00297 break;
00298 case SPW_SBLOCKMYTEAM :
00299 player = [universe playerWithId: arg1];
00300 if ([player flags] & PLAYER_DOCK) {
00301 message = [NSString stringWithFormat: @"Locking onto %@ (docking is enabled)", [player longName]];
00302 } else {
00303 message = [NSString stringWithFormat: @"Locking onto %@ (docking is disabled)", [player longName]];
00304 }
00305 [notificationCenter postNotificationName:@"SPW_SBLOCKMYTEAM" object:self userInfo:message];
00306 break;
00307 case SPW_DMKILL:
00308 case SPW_INLDMKILL:
00309 {
00310 int damage = (karg3 | (karg4 & 127) << 8);
00311 int armies = ((arg1 >> 6) | (arg2 & 192) >> 4);
00312 if((karg4 & 128) != 0) {
00313 armies |= 16;
00314 }
00315
00316 rcm = [[RCMmessage alloc] init];
00317 [rcm setFlags: ALL | VALID | KILL];
00318 [rcm setTo: 0];
00319 [rcm setType:1];
00320 [rcm setSender: [universe playerWithId:arg1 & 0x3F]];
00321 [rcm setTargetPlayer: [universe playerWithId:arg2 & 0x3F]];
00322 [rcm setArmies:armies];
00323 [rcm setShields: damage % 100];
00324 [rcm setDamage: damage /100];
00325 [rcm setTargetPlanet: nil];
00326 [rcm setWeaponTemp:karg5];
00327 [notificationCenter postNotificationName:@"SPW_RCM_DMKILL" object:self userInfo:rcm];
00328 message = nil;
00329 }
00330 break;
00331 case SPW_KILLARGS :
00332 karg3 = arg1;
00333 karg4 = arg2;
00334 break;
00335 case SPW_KILLARGS2 :
00336 karg5 = arg1;
00337
00338
00339 if(karg5 < 0 || karg5 >= 7) {
00340 karg5 = 6;
00341 }
00342 break;
00343 case SPW_DMKILLP :
00344 case SPW_INLDMKILLP :
00345 player = [universe playerWithId: arg1];
00346 planet = [universe planetWithId: arg2];
00347
00348 rcm = [[RCMmessage alloc] init];
00349 [rcm setFlags: ALL | VALID | KILL];
00350 [rcm setTo: 0];
00351 [rcm setType:2];
00352 [rcm setSender: player];
00353 [rcm setTargetPlayer: player];
00354 [rcm setArmies:0];
00355 [rcm setDamage: 0];
00356 [rcm setShields: 0];
00357 [rcm setTargetPlanet:planet];
00358 [rcm setWeaponTemp:karg5];
00359 [notificationCenter postNotificationName:@"SPW_RCM_DMKILLP" object:self userInfo:rcm];
00360 message = nil;
00361 break;
00362 case SPW_DMBOMB :
00363 player = [universe playerWithId: arg1];
00364 planet = [universe planetWithId: arg2];
00365
00366 rcm = [[RCMmessage alloc] init];
00367 [rcm setFlags: TEAM | VALID | BOMB];
00368 [rcm setTo: [[planet owner] bitMask]];
00369 [rcm setType:3];
00370 [rcm setSender: player];
00371 [rcm setTargetPlayer: player];
00372 [rcm setArmies:0];
00373 [rcm setDamage: arg3];
00374 [rcm setShields: 0];
00375 [rcm setTargetPlanet:planet];
00376 [rcm setWeaponTemp:karg5];
00377 [notificationCenter postNotificationName:@"SPW_RCM_DMBOMB" object:self userInfo:rcm];
00378 message = nil;
00379 break;
00380 case SPW_DMDEST :
00381 planet = [universe planetWithId: arg1];
00382 player = [universe playerWithId: arg2];
00383
00384 rcm = [[RCMmessage alloc] init];
00385 [rcm setFlags: TEAM | VALID | DEST];
00386 [rcm setTo: [[planet owner] bitMask]];
00387 [rcm setType:4];
00388 [rcm setSender: player];
00389 [rcm setTargetPlayer: player];
00390 [rcm setArmies:0];
00391 [rcm setDamage: 0];
00392 [rcm setShields: 0];
00393 [rcm setTargetPlanet:planet];
00394 [rcm setWeaponTemp:karg5];
00395 [notificationCenter postNotificationName:@"SPW_RCM_DMDEST" object:self userInfo:rcm];
00396 message = nil;
00397 break;
00398 case SPW_DMTAKE :
00399 planet = [universe planetWithId: arg1];
00400 player = [universe playerWithId: arg2];
00401
00402 rcm = [[RCMmessage alloc] init];
00403 [rcm setFlags: TEAM | VALID | TAKE];
00404 [rcm setTo: [[planet owner] bitMask]];
00405 [rcm setType:5];
00406 [rcm setSender: player];
00407 [rcm setTargetPlayer: player];
00408 [rcm setArmies:0];
00409 [rcm setDamage: 0];
00410 [rcm setShields: 0];
00411 [rcm setTargetPlanet:planet];
00412 [rcm setWeaponTemp:karg5];
00413 [notificationCenter postNotificationName:@"SPW_RCM_DMTAKE" object:self userInfo:rcm];
00414 message = nil;
00415 break;
00416 case SPW_DGHOSTKILL :
00417 {
00418 int damage = karg3 | ((karg4 & 0xFF) << 8);
00419 player = [universe playerWithId: arg1];
00420
00421 rcm = [[RCMmessage alloc] init];
00422 [rcm setFlags: TEAM | VALID];
00423 [rcm setTo: [[planet owner] bitMask]];
00424 [rcm setType:6];
00425 [rcm setSender: player];
00426 [rcm setTargetPlayer: player];
00427 [rcm setArmies:0];
00428 [rcm setDamage: damage / 100];
00429 [rcm setShields: damage % 100];
00430 [rcm setTargetPlanet: nil];
00431 [rcm setWeaponTemp:karg5];
00432 [notificationCenter postNotificationName:@"SPW_RCM_DMGHOSTKILL" object:self userInfo:rcm];
00433 message = nil;
00434 break;
00435 }
00436 case SPW_INLDRESUME :
00437 message = [NSString stringWithFormat: @" Game will resume in %d seconds",arg1];
00438
00439
00440 [notificationCenter postNotificationName:@"SPW_INLDRESUME" object:self userInfo:message];
00441 break;
00442 case SPW_INLDTEXTE :
00443 if(arg1 < [deamonMessages count]) {
00444 message = [deamonMessages objectAtIndex: arg1];
00445
00446
00447 [notificationCenter postNotificationName:@"SPW_INLDTEXTE" object:self userInfo:message];
00448 }
00449 break;
00450 case SPW_STEXTE :
00451
00452 if([serverSentStrings objectAtIndex: arg1] != nil) {
00453 message = [serverSentStrings objectAtIndex: arg1];
00454 [notificationCenter postNotificationName:@"SPW_STEXTE" object:self userInfo:message];
00455 }
00456 break;
00457 case SPW_SHORT_WARNING :
00458 message = [NSString stringWithCString:(buffer + 4) length:(arg2 -5)];
00459 [notificationCenter postNotificationName:@"SPW_SHORT_WARNING" object:self userInfo:message];
00460 break;
00461 case SPW_STEXTE_STRING :
00462 message = [NSString stringWithCString:(buffer + 4) length:(arg2 -5)];
00463
00464 [serverSentStrings insertObject: message atIndex:(buffer & 0xFF)];
00465 [notificationCenter postNotificationName:@"SPW_STEXTE_STRING" object:self userInfo:message];
00466 break;
00467 default :
00468 message = @"Unknown short message!";
00469 [notificationCenter postNotificationName:@"SPW_UNKNOWN" object:self userInfo:message];
00470 break;
00471 }
00472
00473
00474
00475 [notificationCenter postNotificationName:@"SPW_MESSAGE" object:self userInfo:message];
00476
00477 return message;
00478 }
00479
00480 @end