43#import "MyOpenGLView.h"
53@interface PlayerEntity (ContractsPrivate)
56- (NSArray*) contractsListFromArray:(NSArray *) contracts_array forCargo:(BOOL) forCargo forParcels:(BOOL)forParcels;
61@implementation PlayerEntity (Contracts)
63- (NSString *) processEscapePods
66 BOOL added_entry = NO;
67 NSMutableString *result = [NSMutableString string];
68 NSMutableArray *rescuees = [NSMutableArray array];
69 OOGovernmentID government = [[[UNIVERSE currentSystemData] objectForKey:KEY_GOVERNMENT] intValue];
70 if ([
UNIVERSE inInterstellarSpace]) government = 1;
74 for (i = 0; i < [cargo count]; i++)
76 ShipEntity *cargoItem = [cargo objectAtIndex:i];
77 NSArray *podCrew = [cargoItem
crew];
82 [rescuees addObjectsFromArray:podCrew];
84 [cargo removeObjectAtIndex:i];
90 for (i = 0; i < [rescuees count]; i++)
98 else if ([rescuee legacyScript])
105 else if ([rescuee insuranceCredits] && [rescuee legalStatus])
107 float reward = (5.0 + government) * [rescuee legalStatus];
109 if (government > (
Ranrot() & 7) || reward >= insurance)
112 [result appendFormat:DESC(@"capture-reward-for-@@-@-credits-@-alt"),
114 OOStringFromDeciCredits(insurance, YES, NO)];
120 [result appendFormat:DESC(@"rescue-reward-for-@@-@-credits-@-alt"),
121 [rescuee
name], [rescuee
shortDescription], OOStringFromDeciCredits(insurance - reward, YES, NO),
122 OOStringFromDeciCredits(reward, YES, NO)];
123 reward = insurance - reward;
129 else if ([rescuee insuranceCredits])
132 [result appendFormat:DESC(@"rescue-reward-for-@@-@-credits"),
139 else if ([rescuee legalStatus])
142 float reward = (5.0 + government) * [rescuee legalStatus];
143 [result appendFormat:DESC(@"capture-reward-for-@@-@-credits"),
152 [shipCommodityData addQuantity:1 forGood:@"slaves"];
156 if ((i < [rescuees
count] - 1) && added_entry)
157 [result appendString:@"\n"];
167- (NSString *) checkPassengerContracts
169 if ([
self dockedStation] != [
UNIVERSE station])
175 NSMutableString *result = [NSMutableString string];
179 for (i = 0; i < [passengers count]; i++)
181 NSDictionary* passenger_info = [[passengers oo_dictionaryAtIndex:i] retain];
182 NSString* passenger_name = [passenger_info oo_stringForKey:PASSENGER_KEY_NAME];
183 int dest = [passenger_info oo_intForKey:CONTRACT_KEY_DESTINATION];
185 NSString* passenger_dest_name = [UNIVERSE getSystemName: dest];
186 int dest_eta = [passenger_info oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
188 if (system_id == dest)
194 long long fee = [passenger_info oo_longLongForKey:CONTRACT_KEY_FEE];
195 while ((
randf() < 0.75)&&(dest_eta > 3600))
203 [result appendFormatLine:DESC(@"passenger-delivered-okay-@-@-@"), passenger_name, OOIntCredits(fee), passenger_dest_name];
206 [
self addRoleToPlayer:@"trader-courier+"];
209 [
self increasePassengerReputation:RepForRisk([passenger_info oo_unsignedIntForKey:CONTRACT_KEY_RISK defaultValue:0])];
210 [passengers removeObjectAtIndex:i--];
211 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"passenger",@"success",[NSNumber numberWithUnsignedInteger:(10*fee)],passenger_info,nil]];
216 long long fee = [passenger_info oo_longLongForKey:CONTRACT_KEY_FEE] / 2;
217 while (
randf() < 0.5)
221 [result appendFormatLine:DESC(@"passenger-delivered-late-@-@-@"), passenger_name, OOIntCredits(fee), passenger_dest_name];
224 [
self addRoleToPlayer:@"trader-courier+"];
227 [passengers removeObjectAtIndex:i--];
228 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"passenger",@"late",[NSNumber numberWithUnsignedInteger:10*fee],passenger_info,nil]];
237 [result appendFormatLine:DESC(@"passenger-failed-@"), passenger_name];
239 [
self decreasePassengerReputation:RepForRisk([passenger_info oo_unsignedIntForKey:CONTRACT_KEY_RISK defaultValue:0])];
240 [passengers removeObjectAtIndex:i--];
241 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"passenger",@"failed",[NSNumber numberWithUnsignedInteger:0],passenger_info,nil]];
244 [passenger_info release];
248 for (i = 0; i < [parcels count]; i++)
250 NSDictionary* parcel_info = [[parcels oo_dictionaryAtIndex:i] retain];
251 NSString* parcel_name = [parcel_info oo_stringForKey:PASSENGER_KEY_NAME];
252 int dest = [parcel_info oo_intForKey:CONTRACT_KEY_DESTINATION];
253 int dest_eta = [parcel_info oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
255 if (system_id == dest)
261 long long fee = [parcel_info oo_longLongForKey:CONTRACT_KEY_FEE];
262 while ((
randf() < 0.75)&&(dest_eta > 86400))
271 [result appendFormatLine:DESC(@"parcel-delivered-okay-@-@"), parcel_name, OOIntCredits(fee)];
273 [
self increaseParcelReputation:RepForRisk([parcel_info oo_unsignedIntForKey:CONTRACT_KEY_RISK defaultValue:0])];
275 [parcels removeObjectAtIndex:i--];
278 [
self addRoleToPlayer:@"trader-courier+"];
280 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"parcel",@"success",[NSNumber numberWithUnsignedInteger:10*fee],parcel_info,nil]];
286 long long fee = [parcel_info oo_longLongForKey:CONTRACT_KEY_FEE] / 2;
287 while (
randf() < 0.5)
291 [result appendFormatLine:DESC(@"parcel-delivered-late-@-@"), parcel_name, OOIntCredits(fee)];
294 [
self addRoleToPlayer:@"trader-courier+"];
296 [parcels removeObjectAtIndex:i--];
297 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"parcel",@"late",[NSNumber numberWithUnsignedInteger:10*fee],parcel_info,nil]];
305 [result appendFormatLine:DESC(@"parcel-failed-@"), parcel_name];
307 [
self decreaseParcelReputation:RepForRisk([parcel_info oo_unsignedIntForKey:CONTRACT_KEY_RISK defaultValue:0])];
308 [parcels removeObjectAtIndex:i--];
309 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"parcel",@"failed",[NSNumber numberWithUnsignedInteger:0],parcel_info,nil]];
312 [parcel_info release];
317 for (i = 0; i < [contracts count]; i++)
319 NSDictionary* contract_info = [[contracts oo_dictionaryAtIndex:i] retain];
320 NSString* contract_cargo_desc = [contract_info oo_stringForKey:CARGO_KEY_DESCRIPTION];
321 int dest = [contract_info oo_intForKey:CONTRACT_KEY_DESTINATION];
322 int dest_eta = [contract_info oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
324 if (system_id == dest)
328 int fee = 10 * [contract_info oo_floatForKey:CONTRACT_KEY_FEE];
330 OOCommodityType contract_cargo_type = [contract_info oo_stringForKey:CARGO_KEY_TYPE];
331 int contract_amount = [contract_info oo_intForKey:CARGO_KEY_AMOUNT];
333 int quantity_on_hand = [shipCommodityData quantityForGood:contract_cargo_type];
339 if (quantity_on_hand >= contract_amount)
344 [shipCommodityData removeQuantity:contract_amount forGood:contract_cargo_type];
351 if ([shipCommodityData exportLegalityForGood:contract_cargo_type] > 0)
353 [
self addRoleToPlayer:@"trader-smuggler"];
357 [
self addRoleToPlayer:@"trader"];
361 [result appendFormatLine:DESC(@"cargo-delivered-okay-@-@"), contract_cargo_desc, OOCredits(fee)];
363 [contracts removeObjectAtIndex:i--];
366 [
self increaseContractReputation:10];
367 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"cargo",@"success",[NSNumber numberWithUnsignedInteger:fee],contract_info,nil]];
374 float percent_delivered = 100.0 * (float)quantity_on_hand/(
float)contract_amount;
375 float acceptable_ratio = 100.0 - 10.0 * system_id / 256.0;
377 if (percent_delivered >= acceptable_ratio)
380 [shipCommodityData setQuantity:0 forGood:contract_cargo_type];
383 int shortfall = 100 - percent_delivered;
384 int payment = percent_delivered * (fee) / 100.0;
387 if ([shipCommodityData exportLegalityForGood:contract_cargo_type] > 0)
389 [
self addRoleToPlayer:@"trader-smuggler"];
393 [
self addRoleToPlayer:@"trader"];
396 [result appendFormatLine:DESC(@"cargo-delivered-short-@-@-d"), contract_cargo_desc, OOCredits(payment), shortfall];
398 [contracts removeObjectAtIndex:i--];
400 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"cargo",@"short",[NSNumber numberWithUnsignedInteger:payment],contract_info,nil]];
405 [result appendFormatLine:DESC(@"cargo-refused-short-%@"), contract_cargo_desc];
413 [result appendFormatLine:DESC(@"cargo-delivered-late-@"), contract_cargo_desc];
415 [contracts removeObjectAtIndex:i--];
417 [
self decreaseContractReputation:10];
418 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"cargo",@"late",[NSNumber numberWithUnsignedInteger:0],contract_info,nil]];
426 [result appendFormatLine:DESC(@"cargo-failed-@"), contract_cargo_desc];
428 [contracts removeObjectAtIndex:i--];
430 [
self decreaseContractReputation:10];
431 [
self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"cargo",@"failed",[NSNumber numberWithUnsignedInteger:0],contract_info,nil]];
434 [contract_info release];
438 NSArray* names = [passenger_record allKeys];
439 for (i = 0; i < [names count]; i++)
441 double dest_eta = [passenger_record oo_doubleForKey:[names objectAtIndex:i]] - ship_clock;
447 for (j = 0; j < [passengers count]; j++)
449 NSDictionary* passenger_info = [passengers oo_dictionaryAtIndex:j];
450 if ([[passenger_info objectForKey:
PASSENGER_KEY_NAME] isEqual:[names objectAtIndex:i]])
455 [passenger_record removeObjectForKey:[names objectAtIndex:i]];
461 NSArray* ids = [contract_record allKeys];
462 for (i = 0; i < [ids count]; i++)
464 double dest_eta = [(NSNumber*)[contract_record objectForKey:[ids objectAtIndex:i]] doubleValue] - ship_clock;
467 [contract_record removeObjectForKey:[ids objectAtIndex:i]];
472 ids = [parcel_record allKeys];
473 for (i = 0; i < [ids count]; i++)
475 double dest_eta = [(NSNumber*)[parcel_record objectForKey:[ids objectAtIndex:i]] doubleValue] - ship_clock;
478 [parcel_record removeObjectForKey:[ids objectAtIndex:i]];
483 if ([result length] == 0)
490 [result deleteCharacterAtIndex:[result length] - 1];
500 for (
unsigned i = 0; i < [contracts count]; i++)
502 NSDictionary* contract_info = [contracts oo_dictionaryAtIndex:i];
503 OOCommodityType contract_cargo_type = [contract_info oo_stringForKey:CARGO_KEY_TYPE];
504 if ([good isEqualToString:contract_cargo_type])
506 total += [contract_info oo_unsignedIntegerForKey:CARGO_KEY_AMOUNT];
513- (void) addMessageToReport:(NSString*) report
515 if ([report length] != 0)
517 if ([dockingReport length] == 0)
518 [dockingReport appendString:report];
520 [dockingReport appendFormat:@"\n\n%@", report];
525- (NSDictionary*) reputation
531- (
int) passengerReputation
533 int good = [reputation oo_intForKey:PASSAGE_GOOD_KEY];
534 int bad = [reputation oo_intForKey:PASSAGE_BAD_KEY];
535 int unknown = [reputation oo_intForKey:PASSAGE_UNKNOWN_KEY];
542 return (good + unknown - 3 * bad) / 2;
546- (void) increasePassengerReputation:(
unsigned)amount
548 int good = [reputation oo_intForKey:PASSAGE_GOOD_KEY];
549 int bad = [reputation oo_intForKey:PASSAGE_BAD_KEY];
550 int unknown = [reputation oo_intForKey:PASSAGE_UNKNOWN_KEY];
552 for (
unsigned i=0;i<amount;i++)
570 [reputation oo_setInteger:good forKey:PASSAGE_GOOD_KEY];
571 [reputation oo_setInteger:bad forKey:PASSAGE_BAD_KEY];
572 [reputation oo_setInteger:unknown forKey:PASSAGE_UNKNOWN_KEY];
576- (void) decreasePassengerReputation:(
unsigned)amount
578 int good = [reputation oo_intForKey:PASSAGE_GOOD_KEY];
579 int bad = [reputation oo_intForKey:PASSAGE_BAD_KEY];
580 int unknown = [reputation oo_intForKey:PASSAGE_UNKNOWN_KEY];
582for (
unsigned i=0;i<amount;i++)
600 [reputation oo_setInteger:good forKey:PASSAGE_GOOD_KEY];
601 [reputation oo_setInteger:bad forKey:PASSAGE_BAD_KEY];
602 [reputation oo_setInteger:unknown forKey:PASSAGE_UNKNOWN_KEY];
606- (
int) parcelReputation
608 int good = [reputation oo_intForKey:PARCEL_GOOD_KEY];
609 int bad = [reputation oo_intForKey:PARCEL_BAD_KEY];
610 int unknown = [reputation oo_intForKey:PARCEL_UNKNOWN_KEY];
617 return (good + unknown - 3 * bad) / 2;
621- (void) increaseParcelReputation:(
unsigned)amount
623 int good = [reputation oo_intForKey:PARCEL_GOOD_KEY];
624 int bad = [reputation oo_intForKey:PARCEL_BAD_KEY];
625 int unknown = [reputation oo_intForKey:PARCEL_UNKNOWN_KEY];
627 for (
unsigned i=0;i<amount;i++)
645 [reputation oo_setInteger:good forKey:PARCEL_GOOD_KEY];
646 [reputation oo_setInteger:bad forKey:PARCEL_BAD_KEY];
647 [reputation oo_setInteger:unknown forKey:PARCEL_UNKNOWN_KEY];
651- (void) decreaseParcelReputation:(
unsigned)amount
653 int good = [reputation oo_intForKey:PARCEL_GOOD_KEY];
654 int bad = [reputation oo_intForKey:PARCEL_BAD_KEY];
655 int unknown = [reputation oo_intForKey:PARCEL_UNKNOWN_KEY];
657 for (
unsigned i=0;i<amount;i++)
675 [reputation oo_setInteger:good forKey:PARCEL_GOOD_KEY];
676 [reputation oo_setInteger:bad forKey:PARCEL_BAD_KEY];
677 [reputation oo_setInteger:unknown forKey:PARCEL_UNKNOWN_KEY];
681- (
int) contractReputation
683 int good = [reputation oo_intForKey:CONTRACTS_GOOD_KEY];
684 int bad = [reputation oo_intForKey:CONTRACTS_BAD_KEY];
685 int unknown = [reputation oo_intForKey:CONTRACTS_UNKNOWN_KEY];
692 return (good + unknown - 3 * bad) / 2;
696- (void) increaseContractReputation:(
unsigned)amount
698 int good = [reputation oo_intForKey:CONTRACTS_GOOD_KEY];
699 int bad = [reputation oo_intForKey:CONTRACTS_BAD_KEY];
700 int unknown = [reputation oo_intForKey:CONTRACTS_UNKNOWN_KEY];
702 for (
unsigned i=0;i<amount;i++)
720 [reputation oo_setInteger:good forKey:CONTRACTS_GOOD_KEY];
721 [reputation oo_setInteger:bad forKey:CONTRACTS_BAD_KEY];
722 [reputation oo_setInteger:unknown forKey:CONTRACTS_UNKNOWN_KEY];
726- (void) decreaseContractReputation:(
unsigned)amount
728 int good = [reputation oo_intForKey:CONTRACTS_GOOD_KEY];
729 int bad = [reputation oo_intForKey:CONTRACTS_BAD_KEY];
730 int unknown = [reputation oo_intForKey:CONTRACTS_UNKNOWN_KEY];
732 for (
unsigned i=0;i<amount;i++)
750 [reputation oo_setInteger:good forKey:CONTRACTS_GOOD_KEY];
751 [reputation oo_setInteger:bad forKey:CONTRACTS_BAD_KEY];
752 [reputation oo_setInteger:unknown forKey:CONTRACTS_UNKNOWN_KEY];
756- (void) erodeReputation
758 int c_good = [reputation oo_intForKey:CONTRACTS_GOOD_KEY];
759 int c_bad = [reputation oo_intForKey:CONTRACTS_BAD_KEY];
760 int c_unknown = [reputation oo_intForKey:CONTRACTS_UNKNOWN_KEY];
761 int p_good = [reputation oo_intForKey:PASSAGE_GOOD_KEY];
762 int p_bad = [reputation oo_intForKey:PASSAGE_BAD_KEY];
763 int p_unknown = [reputation oo_intForKey:PASSAGE_UNKNOWN_KEY];
764 int pl_good = [reputation oo_intForKey:PARCEL_GOOD_KEY];
765 int pl_bad = [reputation oo_intForKey:PARCEL_BAD_KEY];
766 int pl_unknown = [reputation oo_intForKey:PARCEL_UNKNOWN_KEY];
804 [reputation setObject:[NSNumber numberWithInt:c_good] forKey:CONTRACTS_GOOD_KEY];
805 [reputation setObject:[NSNumber numberWithInt:c_bad] forKey:CONTRACTS_BAD_KEY];
806 [reputation setObject:[NSNumber numberWithInt:c_unknown] forKey:CONTRACTS_UNKNOWN_KEY];
807 [reputation setObject:[NSNumber numberWithInt:p_good] forKey:PASSAGE_GOOD_KEY];
808 [reputation setObject:[NSNumber numberWithInt:p_bad] forKey:PASSAGE_BAD_KEY];
809 [reputation setObject:[NSNumber numberWithInt:p_unknown] forKey:PASSAGE_UNKNOWN_KEY];
810 [reputation setObject:[NSNumber numberWithInt:pl_good] forKey:PARCEL_GOOD_KEY];
811 [reputation setObject:[NSNumber numberWithInt:pl_bad] forKey:PARCEL_BAD_KEY];
812 [reputation setObject:[NSNumber numberWithInt:pl_unknown] forKey:PARCEL_UNKNOWN_KEY];
818- (void) normaliseReputation
820 int c_good = [reputation oo_intForKey:CONTRACTS_GOOD_KEY];
821 int c_bad = [reputation oo_intForKey:CONTRACTS_BAD_KEY];
822 int c_unknown = [reputation oo_intForKey:CONTRACTS_UNKNOWN_KEY];
823 int p_good = [reputation oo_intForKey:PASSAGE_GOOD_KEY];
824 int p_bad = [reputation oo_intForKey:PASSAGE_BAD_KEY];
825 int p_unknown = [reputation oo_intForKey:PASSAGE_UNKNOWN_KEY];
826 int pl_good = [reputation oo_intForKey:PARCEL_GOOD_KEY];
827 int pl_bad = [reputation oo_intForKey:PARCEL_BAD_KEY];
828 int pl_unknown = [reputation oo_intForKey:PARCEL_UNKNOWN_KEY];
830 int c = c_good + c_bad + c_unknown;
842 int p = p_good + p_bad + p_unknown;
854 int pl = pl_good + pl_bad + pl_unknown;
866 [reputation setObject:[NSNumber numberWithInt:c_good] forKey:CONTRACTS_GOOD_KEY];
867 [reputation setObject:[NSNumber numberWithInt:c_bad] forKey:CONTRACTS_BAD_KEY];
868 [reputation setObject:[NSNumber numberWithInt:c_unknown] forKey:CONTRACTS_UNKNOWN_KEY];
869 [reputation setObject:[NSNumber numberWithInt:p_good] forKey:PASSAGE_GOOD_KEY];
870 [reputation setObject:[NSNumber numberWithInt:p_bad] forKey:PASSAGE_BAD_KEY];
871 [reputation setObject:[NSNumber numberWithInt:p_unknown] forKey:PASSAGE_UNKNOWN_KEY];
872 [reputation setObject:[NSNumber numberWithInt:pl_good] forKey:PARCEL_GOOD_KEY];
873 [reputation setObject:[NSNumber numberWithInt:pl_bad] forKey:PARCEL_BAD_KEY];
874 [reputation setObject:[NSNumber numberWithInt:pl_unknown] forKey:PARCEL_UNKNOWN_KEY];
879- (BOOL) addPassenger:(NSString*)Name start:(
unsigned)start destination:(
unsigned)Destination eta:(
double)eta fee:(
double)fee advance:(
double)advance risk:(
unsigned)risk
881 NSDictionary* passenger_info = [NSDictionary dictionaryWithObjectsAndKeys:
882 Name, PASSENGER_KEY_NAME,
883 [NSNumber numberWithInt:start], CONTRACT_KEY_START,
884 [NSNumber numberWithInt:Destination], CONTRACT_KEY_DESTINATION,
885 [NSNumber numberWithDouble:[PLAYER clockTime]], CONTRACT_KEY_DEPARTURE_TIME,
886 [NSNumber numberWithDouble:eta], CONTRACT_KEY_ARRIVAL_TIME,
887 [NSNumber numberWithDouble:fee], CONTRACT_KEY_FEE,
888 [NSNumber numberWithDouble:advance], CONTRACT_KEY_PREMIUM,
889 [NSNumber numberWithUnsignedInt:risk], CONTRACT_KEY_RISK,
894 if ([passengers
count] >= max_passengers || [passenger_record objectForKey:Name] !=
nil)
return NO;
898 [
self addRoleToPlayer:@"trader-courier+"];
901 [passengers addObject:passenger_info];
902 [passenger_record setObject:[NSNumber numberWithDouble:eta] forKey:Name];
904 [
self doScriptEvent:OOJSID("playerEnteredContract") withArguments:[NSArray arrayWithObjects:@"passenger",passenger_info,nil]];
910- (BOOL) removePassenger:(NSString*)Name
913 if ([passengers
count] == 0)
return NO;
917 for (i = 0; i < [passengers count]; i++)
919 NSString *this_name = [[passengers oo_dictionaryAtIndex:i] oo_stringForKey:PASSENGER_KEY_NAME];
921 if ([Name isEqualToString:this_name])
923 [passengers removeObjectAtIndex:i];
924 [passenger_record removeObjectForKey:Name];
933- (BOOL) addParcel:(NSString*)Name start:(
unsigned)start destination:(
unsigned)Destination eta:(
double)eta fee:(
double)fee premium:(
double)premium risk:(
unsigned)risk
935 NSDictionary* parcel_info = [NSDictionary dictionaryWithObjectsAndKeys:
936 Name, PASSENGER_KEY_NAME,
937 [NSNumber numberWithInt:start], CONTRACT_KEY_START,
938 [NSNumber numberWithInt:Destination], CONTRACT_KEY_DESTINATION,
939 [NSNumber numberWithDouble:[PLAYER clockTime]], CONTRACT_KEY_DEPARTURE_TIME,
940 [NSNumber numberWithDouble:eta], CONTRACT_KEY_ARRIVAL_TIME,
941 [NSNumber numberWithDouble:fee], CONTRACT_KEY_FEE,
942 [NSNumber numberWithDouble:premium], CONTRACT_KEY_PREMIUM,
943 [NSNumber numberWithUnsignedInt:risk], CONTRACT_KEY_RISK,
954 [
self addRoleToPlayer:@"trader-courier+"];
957 [parcels addObject:parcel_info];
958 [parcel_record setObject:[NSNumber numberWithDouble:eta] forKey:Name];
960 [
self doScriptEvent:OOJSID("playerEnteredContract") withArguments:[NSArray arrayWithObjects:@"parcel",parcel_info,nil]];
966- (BOOL) removeParcel:(NSString*)Name
969 if ([parcels
count] == 0)
return NO;
973 for (i = 0; i < [parcels count]; i++)
975 NSString *this_name = [[parcels oo_dictionaryAtIndex:i] oo_stringForKey:PASSENGER_KEY_NAME];
977 if ([Name isEqualToString:this_name])
979 [parcels removeObjectAtIndex:i];
980 [parcel_record removeObjectForKey:Name];
989- (BOOL) awardContract:(
unsigned)qty commodity:(
OOCommodityType)type start:(
unsigned)start
990 destination:(
unsigned)Destination eta:(
double)eta fee:(
double)fee premium:(
double)premium
993 unsigned sr1 =
Ranrot()&0x111111;
994 int sr2 =
Ranrot()&0x111111;
996 NSString *cargo_ID =[NSString stringWithFormat:@"%06x-%06x", sr1, sr2];
998 if (![[
UNIVERSE commodities] goodDefined:type])
return NO;
999 if (qty < 1)
return NO;
1002 while ([contract_record objectForKey:cargo_ID] !=
nil)
1005 cargo_ID =[NSString stringWithFormat:@"%06x-%06x", sr1, sr2];
1008 NSDictionary* cargo_info = [NSDictionary dictionaryWithObjectsAndKeys:
1009 cargo_ID, CARGO_KEY_ID,
1010 type, CARGO_KEY_TYPE,
1011 [NSNumber numberWithInt:qty], CARGO_KEY_AMOUNT,
1012 [UNIVERSE describeCommodity:type amount:qty], CARGO_KEY_DESCRIPTION,
1013 [NSNumber numberWithInt:start], CONTRACT_KEY_START,
1014 [NSNumber numberWithInt:Destination], CONTRACT_KEY_DESTINATION,
1015 [NSNumber numberWithDouble:[PLAYER clockTime]], CONTRACT_KEY_DEPARTURE_TIME,
1016 [NSNumber numberWithDouble:eta], CONTRACT_KEY_ARRIVAL_TIME,
1017 [NSNumber numberWithDouble:fee], CONTRACT_KEY_FEE,
1018 [NSNumber numberWithDouble:premium], CONTRACT_KEY_PREMIUM,
1024 OOMassUnit contractCargoUnits = [shipCommodityData massUnitForGood:type];
1026 if (contractCargoUnits ==
UNITS_KILOGRAMS) cargoSpaceRequired /= 1000;
1027 if (contractCargoUnits ==
UNITS_GRAMS) cargoSpaceRequired /= 1000000;
1029 if (cargoSpaceRequired > [
self availableCargoSpace])
return NO;
1031 [shipCommodityData addQuantity:qty forGood:type];
1033 current_cargo = [
self cargoQuantityOnBoard];
1035 if ([shipCommodityData exportLegalityForGood:type] > 0)
1037 [
self addRoleToPlayer:@"trader-smuggler"];
1038 [roleWeightFlags setObject:[NSNumber numberWithInt:1] forKey:@"bought-illegal"];
1042 [
self addRoleToPlayer:@"trader"];
1043 [roleWeightFlags setObject:[NSNumber numberWithInt:1] forKey:@"bought-legal"];
1046 [contracts addObject:cargo_info];
1047 [contract_record setObject:[NSNumber numberWithDouble:eta] forKey:cargo_ID];
1049 [
self doScriptEvent:OOJSID("playerEnteredContract") withArguments:[NSArray arrayWithObjects:@"cargo",cargo_info,nil]];
1055- (BOOL) removeContract:(
OOCommodityType)type destination:(
unsigned)dest
1057 if ([contracts
count] == 0 || dest > 255)
return NO;
1059 if (![[
UNIVERSE commodities] goodDefined:type])
return NO;
1063 for (i = 0; i < [contracts count]; i++)
1065 NSDictionary *contractInfo = [contracts oo_dictionaryAtIndex:i];
1066 unsigned cargoDest = [contractInfo oo_intForKey:CONTRACT_KEY_DESTINATION];
1067 OOCommodityType cargoType = [contractInfo oo_stringForKey:CARGO_KEY_TYPE];
1069 if ([cargoType isEqualToString:type] && cargoDest == dest)
1071 [contract_record removeObjectForKey:[contractInfo oo_stringForKey:CARGO_KEY_ID]];
1072 [contracts removeObjectAtIndex:i];
1083- (NSArray*) passengerList
1085 return [
self contractsListFromArray:passengers forCargo:NO forParcels:NO];
1089- (NSArray*) parcelList
1091 return [
self contractsListFromArray:parcels forCargo:NO forParcels:YES];
1095- (NSArray*) contractList
1097 return [
self contractsListFromArray:contracts forCargo:YES forParcels:NO];
1101- (NSArray*) contractsListFromArray:(NSArray *) contracts_array forCargo:(BOOL) forCargo forParcels:(BOOL)forParcels
1104 NSMutableArray *result = [NSMutableArray arrayWithCapacity:5];
1105 NSString *formatString = (forCargo||forParcels) ?
@"oolite-manifest-item-delivery" :
@"oolite-manifest-person-travelling";
1107 for (i = 0; i < [contracts_array count]; i++)
1109 NSDictionary* contract_info = (NSDictionary *)[contracts_array objectAtIndex:i];
1110 NSString* label = [contract_info oo_stringForKey:forCargo ? CARGO_KEY_DESCRIPTION : PASSENGER_KEY_NAME];
1112 NSString* destination = [UNIVERSE getSystemName: [contract_info oo_intForKey:CONTRACT_KEY_DESTINATION]];
1113 int dest_eta = [contract_info oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
1114 NSString *deadline = [UNIVERSE shortTimeDescription:dest_eta];
1119 [result addObject:OOExpandKey(formatString, label, destination, deadline, feeDesc)];
1128#define SET_MANIFEST_ROW(obj,color,row) ([self setManifestScreenRow:obj inColor:color forRow:row ofRows:max_rows andOffset:page_offset inMultipage:multi_page])
1130- (void) setGuiToManifestScreen
1135 gui_screen = GUI_SCREEN_MANIFEST;
1136 BOOL guiChanged = (oldScreen != gui_screen);
1144 NSInteger current, max;
1150 NSArray* cargoManifest = [
self cargoList];
1151 NSArray* missionsManifest = [
self missionsList];
1154 NSUInteger max_rows = 20;
1155 NSUInteger manifestCount = [cargoManifest count];
1156 NSUInteger cargoRowCount = (manifestCount + 1)/2;
1162 if ([[
self hud] isHidden] || [[
self hud] allowBigGui])
1168 NSUInteger mmRows = 0;
1170 foreach (mmEntry, missionsManifest)
1172 if ([mmEntry isKindOfClass:[NSString
class]])
1176 else if ([mmEntry isKindOfClass:[NSArray
class]])
1178 mmRows += [(NSArray *)mmEntry count];
1182 NSInteger page_offset = 0;
1183 BOOL multi_page = NO;
1185 NSUInteger total_rows = cargoRowCount + mmRows + 5;
1186 if (total_rows > max_rows)
1189 page_offset = ([gui
statusPage]-1) * max_rows;
1190 if (page_offset < 0 || (NSUInteger)page_offset >= total_rows)
1206 current_cargo = [
self cargoQuantityOnBoard];
1209 [gui
setTitle:DESC(@"manifest-title")];
1211 current = current_cargo;
1212 max = [
self maxAvailableCargoSpace];
1213 NSString *cargoString =
OOExpandKey(
@"oolite-manifest-cargo", current, max);
1214 current = [[
self passengerList] count];
1215 max = max_passengers;
1216 NSString *cabinString =
OOExpandKey(
@"oolite-manifest-cabins", current, max);
1217 NSArray *manifestHeader = [NSArray arrayWithObjects:cargoString,cabinString,nil];
1221 if (manifestCount > 0)
1223 for (i = 0; i < cargoRowCount; i++)
1225 NSMutableArray* row_info = [NSMutableArray arrayWithCapacity:3];
1227 [row_info addObject:[cargoManifest objectAtIndex:i]];
1228 if (i + cargoRowCount < manifestCount)
1230 [row_info addObject:[cargoManifest objectAtIndex:i + cargoRowCount]];
1234 [row_info addObject:@""];
1245 missionsRow = cargoRow + cargoRowCount + 1;
1248 manifestCount = [missionsManifest count];
1250 if (manifestCount > 0)
1252 if ([[missionsManifest objectAtIndex:0] isKindOfClass:[NSString
class]])
1263 NSUInteger mmRow = 0;
1264 for (i = 0; i < manifestCount; i++)
1266 NSString *mmItem =
nil;
1267 mmEntry = [missionsManifest objectAtIndex:i];
1268 if ([mmEntry isKindOfClass:[NSString
class]])
1270 mmItem = [NSString stringWithFormat:@"\t%@",(NSString *)mmEntry];
1274 else if ([mmEntry isKindOfClass:[NSArray
class]])
1276 BOOL isHeading = YES;
1277 foreach (mmItem, mmEntry)
1281 SET_MANIFEST_ROW( ((NSString *)mmItem) , entryColor , missionsRow + mmRow);
1285 mmItem = [NSString stringWithFormat:@"\t%@",(NSString *)mmItem];
1286 SET_MANIFEST_ROW( ((NSString *)mmItem) , subheadColor , missionsRow + mmRow);
1299 if (page_offset > 0)
1302 [gui
setKey:GUI_KEY_OK
forRow:MANIFEST_SCREEN_ROW_BACK];
1307 r_start = nextPageRow;
1309 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-back"), @" <-- ",nil]
forRow:MANIFEST_SCREEN_ROW_BACK];
1311 if (total_rows > max_rows + page_offset)
1321 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-more"), @" --> ",nil]
forRow:nextPageRow];
1334 [lastTextKey release];
1338 [
self setShowDemoShips:NO];
1339 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO];
1345 [
self noteGUIDidChangeFrom:oldScreen to:gui_screen];
1350- (void) setManifestScreenRow:(
id)object inColor:(
OOColor*)color forRow:(
OOGUIRow)row ofRows:(
OOGUIRow)max_rows andOffset:(
OOGUIRow)offset inMultipage:(BOOL)multi
1353 if (disp_row < 1 || disp_row > max_rows)
return;
1354 if (multi) disp_row++;
1356 if ([
object isKindOfClass:[NSString
class]])
1360 else if ([
object isKindOfClass:[NSArray
class]])
1368- (void) setGuiToDockingReportScreen
1373 gui_screen = GUI_SCREEN_REPORT;
1374 BOOL guiChanged = (oldScreen != gui_screen);
1378 [dockingReport setString:[dockingReport stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
1383 [gui
setTitle:OOExpandKey(@"arrival-report-title")];
1385 for (i=1;i<=18;i++) {
1391 while (([dockingReport length] > 0)&&(text_row < 18))
1393 if ([dockingReport rangeOfString:
@"\n"].location != NSNotFound)
1395 while (([dockingReport rangeOfString:
@"\n"].location != NSNotFound)&&(text_row < 18))
1397 NSUInteger line_break = [dockingReport rangeOfString:@"\n"].location;
1398 NSString* line = [dockingReport substringToIndex:line_break];
1399 [dockingReport deleteCharactersInRange: NSMakeRange( 0, line_break + 1)];
1402 [dockingReport setString:[dockingReport stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
1407 [dockingReport setString:@""];
1411 [gui
setText:[NSString stringWithFormat:DESC_PLURAL(@"contracts-cash-@-load-d-of-d-passengers-d-of-d-berths", max_passengers), OOCredits(credits), current_cargo, [
self maxAvailableCargoSpace], [passengers count], max_passengers]
forRow: GUI_ROW_MARKET_CASH];
1422 [lastTextKey release];
1426 [
self setShowDemoShips:NO];
1427 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO];
1433 NSDictionary *bgDescriptor = [UNIVERSE screenTextureDescriptorForKey:@"report"];
1434 if (bgDescriptor ==
nil) bgDescriptor = [UNIVERSE screenTextureDescriptorForKey:@"status_docked"];
1435 if (bgDescriptor ==
nil) bgDescriptor = [UNIVERSE screenTextureDescriptorForKey:@"status"];
1437 [
self noteGUIDidChangeFrom:oldScreen to:gui_screen];
1448 NSDictionary *shipInfo = [currentShipyard oo_dictionaryForKey:key];
1449 return [shipInfo oo_unsignedLongLongForKey:SHIPYARD_KEY_PRICE];
1453- (void) setGuiToShipyardScreen:(NSUInteger)skip
1458 gui_screen = GUI_SCREEN_SHIPYARD;
1459 BOOL guiChanged = (oldScreen != gui_screen);
1473 station = [UNIVERSE station];
1474 stationTechLevel = NSNotFound;
1476 if ([station localShipyard] ==
nil)
1483 [currentShipyard release];
1484 currentShipyard = [[NSMutableDictionary alloc] initWithCapacity:[shipyard count]];
1486 for (i = 0; i < [shipyard count]; i++)
1488 [currentShipyard setObject:[shipyard objectAtIndex:i]
1489 forKey:[[shipyard oo_dictionaryAtIndex:i] oo_stringForKey:SHIPYARD_KEY_ID]];
1492 NSUInteger shipCount = [shipyard count];
1495 if (skip >= shipCount) skip = shipCount - 1;
1496 if (skip < 2) skip = 0;
1501 NSString *system = [UNIVERSE getSystemName:system_id];
1502 [gui
setTitle:OOExpandKey(@"shipyard-title", system)];
1506 tab_stops[1] = -258;
1515 NSInteger previous = 0;
1529 if (skip + rowCount < shipCount)
1536 [gui
setArray:[NSArray arrayWithObjects:DESC(@"shipyard-shiptype"), DESC(@"shipyard-price-label"),
1537 DESC(@"shipyard-cargo-label"), DESC(@"shipyard-speed-label"), nil]
forRow:GUI_ROW_SHIPYARD_LABELS];
1542 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-back"), @" <-- ", nil]
forRow:GUI_ROW_SHIPYARD_START];
1543 [gui
setKey:[NSString stringWithFormat:@"More:%ld", previous]
forRow:GUI_ROW_SHIPYARD_START];
1545 for (i = 0; i < (shipCount - skip) && (
int)i < rowCount; i++)
1547 NSDictionary* ship_info = [shipyard oo_dictionaryAtIndex:i + skip];
1548 OOCreditsQuantity ship_price = [ship_info oo_unsignedLongLongForKey:SHIPYARD_KEY_PRICE];
1550 [gui
setArray:[NSArray arrayWithObjects:
1551 [NSString stringWithFormat:@" %@ ",[[ship_info oo_dictionaryForKey:SHIPYARD_KEY_SHIP] oo_stringForKey:@"display_name" defaultValue:[[ship_info oo_dictionaryForKey:SHIPYARD_KEY_SHIP] oo_stringForKey:KEY_NAME]]],
1552 OOIntCredits(ship_price),
1555 [gui
setKey:(NSString*)[ship_info objectForKey:SHIPYARD_KEY_ID]
forRow:startRow + i];
1557 if (i < shipCount - skip)
1560 [gui
setArray:[NSArray arrayWithObjects:DESC(@"gui-more"), @" --> ", nil]
forRow:startRow + i];
1561 [gui
setKey:[NSString stringWithFormat:@"More:%ld", rowCount + skip]
forRow:startRow + i];
1565 [gui
setSelectableRange:NSMakeRange( GUI_ROW_SHIPYARD_START, i + startRow - GUI_ROW_SHIPYARD_START)];
1567 if(shipCount == 1) [gui setFirstSelectableRow];
1568 [
self showShipyardInfoForSelection];
1572 [gui
setText:DESC(@"shipyard-no-ships-available-for-purchase")
forRow:GUI_ROW_NO_SHIPS
align:GUI_ALIGN_CENTER];
1578 [
self showTradeInInformationFooter];
1585 [
self setShowDemoShips:(shipCount > 0)];
1586 [UNIVERSE enterGUIViewModeWithMouseInteraction:YES];
1596- (void) showShipyardInfoForSelection
1602 if (sel_row <= 0)
return;
1604 NSMutableArray *row_info = [NSMutableArray arrayWithArray:(NSArray*)[gui
objectForRow:GUI_ROW_SHIPYARD_LABELS]];
1605 while ([row_info
count] < 4)
1607 [row_info addObject:@""];
1610 NSString *key = [gui
keyForRow:sel_row];
1612 NSDictionary *info = [currentShipyard oo_dictionaryForKey:key];
1615 [row_info replaceObjectAtIndex:2 withObject:@""];
1616 [row_info replaceObjectAtIndex:3 withObject:@""];
1622 [UNIVERSE removeDemoShips];
1627 NSString *salesPitch = [info oo_stringForKey:KEY_SHORT_DESCRIPTION];
1628 NSDictionary *shipDict = [info oo_dictionaryForKey:SHIPYARD_KEY_SHIP];
1630 int cargoRating = [shipDict oo_intForKey:@"max_cargo"];
1632 cargo_extra = [shipDict oo_intForKey:@"extra_cargo" defaultValue:15];
1633 float speedRating = 0.001 * [shipDict oo_intForKey:@"max_flight_speed"];
1635 NSArray *shipExtras = [info oo_arrayForKey:KEY_EQUIPMENT_EXTRAS];
1636 for (i = 0; i < [shipExtras count]; i++)
1638 if ([[shipExtras oo_stringAtIndex:i] isEqualToString:
@"EQ_CARGO_BAY"])
1640 cargoRating += cargo_extra;
1642 else if ([[shipExtras oo_stringAtIndex:i] isEqualToString:
@"EQ_PASSENGER_BERTH"])
1648 [row_info replaceObjectAtIndex:2 withObject:OOExpandKey(@"shipyard-cargo-value", cargoRating)];
1649 [row_info replaceObjectAtIndex:3 withObject:OOExpandKey(@"shipyard-speed-value", speedRating)];
1652 [
self showTradeInInformationFooter];
1661 [
self showShipyardModel:[info oo_stringForKey:SHIPYARD_KEY_SHIPDATA_KEY]
1663 personality:[info oo_unsignedShortForKey:SHIPYARD_KEY_PERSONALITY]];
1672 [gui
setArray:[NSArray arrayWithArray:row_info]
forRow:GUI_ROW_SHIPYARD_LABELS];
1676- (void) showTradeInInformationFooter
1681 NSString *shipType = [
self displayName];
1685 [gui
setText:OOExpandKey(@"shipyard-trade-in-value", shipType, tradeIn)
forRow: GUI_ROW_MARKET_CASH - 1];
1686 [gui
setText:OOExpandKey(@"shipyard-total-available-with-trade-in", shipType, total, credits, tradeIn)
forRow: GUI_ROW_MARKET_CASH];
1690- (void) showShipyardModel:(NSString *)shipKey shipData:(NSDictionary *)shipData personality:(uint16_t)personality
1692 if (shipKey ==
nil || [
self dockedStation] ==
nil)
return;
1693 [
self showShipModelWithKey:shipKey shipData:shipData personality:personality factorX:1.2 factorY:0.8 factorZ:6.4 inContext:@"shipyard"];
1697- (NSInteger) missingSubEntitiesAdjustment
1700 NSUInteger percent = 5 * ([
self maxShipSubEntities] - [[[
self shipSubEntityEnumerator] allObjects]
count]);
1701 return (percent > 35 ? 35 : percent);
1719 unsigned long long value = [UNIVERSE tradeInValueForCommanderDictionary:[
self commanderDataDictionary]];
1720 value -= value * 0.006 * [
self missingSubEntitiesAdjustment];
1721 value =
cunningFee(((value * 75 * ship_trade_in_factor) + 5000) / 10000, 0.005);
1726- (BOOL) buySelectedShip
1731 if (selectedRow <= 0)
return NO;
1733 NSString *key = [gui
keyForRow:selectedRow];
1735 if ([key hasPrefix:
@"More:"])
1737 NSInteger fromShip = [[key componentsSeparatedByString:@":"] oo_integerAtIndex:1];
1738 if (fromShip < 0) fromShip = 0;
1740 [
self setGuiToShipyardScreen:fromShip];
1741 if ([[
UNIVERSE gui] selectedRow] < 0)
1743 [[UNIVERSE gui] setSelectedRow:GUI_ROW_SHIPYARD_START];
1747 [[UNIVERSE gui] setSelectedRow:GUI_ROW_SHIPYARD_START + MAX_ROWS_SHIPS_FOR_SALE - 1];
1751 NSMutableArray *row_info = [NSMutableArray arrayWithArray:(NSArray*)[gui
objectForRow:GUI_ROW_SHIPYARD_LABELS]];
1752 while ([row_info
count] < 4)
1754 [row_info addObject:@""];
1756 [row_info replaceObjectAtIndex:2 withObject:@""];
1757 [row_info replaceObjectAtIndex:3 withObject:@""];
1764 [gui
setArray:[NSArray arrayWithArray:row_info]
forRow:GUI_ROW_SHIPYARD_LABELS];
1765 [UNIVERSE removeDemoShips];
1770 NSDictionary *shipInfo = [currentShipyard oo_dictionaryForKey:key];
1771 OOCreditsQuantity price = [shipInfo oo_unsignedLongLongForKey:SHIPYARD_KEY_PRICE];
1774 if (credits + tradeIn < price * 10)
1778 [
self doScriptEvent:OOJSID("playerWillBuyNewShip")
1779 withArguments:[NSArray arrayWithObjects:[shipInfo oo_stringForKey:SHIPYARD_KEY_SHIPDATA_KEY],
1780 [[[
self dockedStation] localShipyard] objectAtIndex:selectedRow - GUI_ROW_SHIPYARD_START],
1781 [NSNumber numberWithUnsignedLongLong:price],
1782 [NSNumber numberWithUnsignedLongLong:(tradeIn / 10)], nil]];
1785 NSString *good =
nil;
1786 foreach (good, [shipCommodityData goods])
1788 [
self trySellingCommodity:good all:YES];
1795 credits -= 10 * price - tradeIn;
1797 NSDictionary *shipDict = [shipInfo oo_dictionaryForKey:SHIPYARD_KEY_SHIP];
1798 [
self newShipCommonSetup:[shipInfo oo_stringForKey:SHIPYARD_KEY_SHIPDATA_KEY] yardInfo:shipInfo baseInfo:shipDict];
1803 NSArray *extras = [shipInfo oo_arrayForKey:KEY_EQUIPMENT_EXTRAS];
1804 for (NSUInteger i = 0; i < [extras count]; i++)
1806 NSString *eq_key = [extras oo_stringAtIndex:i];
1807 if ([eq_key isEqualToString:
@"EQ_PASSENGER_BERTH"])
1814 [
self addEquipmentItem:eq_key withValidation:YES inContext:@"newShip"];
1819 [shipyard_record setObject:[
self shipDataKey] forKey:[shipInfo objectForKey:SHIPYARD_KEY_ID]];
1822 [[[
self dockedStation] localShipyard] removeObjectAtIndex:selectedRow - GUI_ROW_SHIPYARD_START];
1825 NSDictionary* cmdr_dict = [
self commanderDataDictionary];
1826 if (![
self setCommanderDataFromDictionary:cmdr_dict])
return NO;
1828 [
self setStatus:STATUS_DOCKED];
1829 [
self setEntityPersonalityInt:[shipInfo oo_unsignedShortForKey:SHIPYARD_KEY_PERSONALITY]];
1832 ship_clock_adjust += 3600.0;
1835 ship_trade_in_factor = 100;
1842- (BOOL) replaceShipWithNamedShip:(NSString *)shipKey
1849 if (ship_info ==
nil || ship_base_dict ==
nil) {
1854 [
self doScriptEvent:OOJSID("playerWillReplaceShip") withArgument:shipKey];
1856 [
self newShipCommonSetup:shipKey yardInfo:ship_info baseInfo:ship_base_dict];
1859 NSDictionary* cmdr_dict = [
self commanderDataDictionary];
1860 if (![
self setCommanderDataFromDictionary:cmdr_dict])
return NO;
1863 NSArray* extras = [NSMutableArray arrayWithArray:[[ship_info oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_arrayForKey:KEY_EQUIPMENT_EXTRAS]];
1864 for (
unsigned i = 0; i < [extras count]; i++)
1866 NSString* eq_key = [extras oo_stringAtIndex:i];
1867 if ([eq_key isEqualToString:
@"EQ_PASSENGER_BERTH"])
1874 [
self addEquipmentItem:eq_key withValidation:YES inContext:@"newShip"];
1878 [
self setEntityPersonalityInt:[ship_info oo_unsignedShortForKey:SHIPYARD_KEY_PERSONALITY]];
1883- (void) newShipCommonSetup:(NSString *)shipKey yardInfo:(NSDictionary *)ship_info baseInfo:(NSDictionary *)ship_base_dict
1886 [shipCommodityData removeAllGoods];
1890 [passengers removeAllObjects];
1891 [passenger_record removeAllObjects];
1897 [
self clearSubEntities];
1899 [
self setShipDataKey:shipKey];
1901 NSDictionary *shipDict = ship_base_dict;
1905 [
self setFuel:[
self fuelCapacity]];
1908 int base_facings = [shipDict oo_unsignedIntForKey:KEY_WEAPON_FACINGS defaultValue:15];
1909 int available_facings = [ship_info oo_unsignedIntForKey:KEY_WEAPON_FACINGS defaultValue:base_facings];
1936 max_cargo = [UNIVERSE maxCargoForShip:[
self shipDataKey]];
1939 [
self tidyMissilePylons];
1942 missiles = [shipDict oo_unsignedIntForKey:@"missiles"];
1951 NSMutableSet *portable_equipment = [NSMutableSet set];
1952 NSEnumerator *eqEnum =
nil;
1953 NSString *eq_desc =
nil;
1956 for (eqEnum = [
self equipmentEnumerator]; (eq_desc = [eqEnum nextObject]);)
1959 if ([item isPortableBetweenShips]) [portable_equipment addObject:eq_desc];
1963 [
self removeAllEquipment];
1966 for (eqEnum = [portable_equipment objectEnumerator]; (eq_desc = [eqEnum nextObject]); )
1968 [
self addEquipmentItem:eq_desc withValidation:NO inContext:@"portable"];
1973 [
self setUpSubEntities];
1976 [
self setShipClassName:[shipDict oo_stringForKey:@"name"]];
1977 [
self setShipUniqueName:@""];
1981 if (ship_kills >= 6400)
1983 [
self clearRolesFromPlayer:0.1];
1985 else if (ship_kills >= 2560)
1987 [
self clearRolesFromPlayer:0.25];
1991 [
self clearRolesFromPlayer:0.5];
OOGUITabStop OOGUITabSettings[GUI_MAX_COLUMNS]
#define OOExpandKey(key,...)
OOINLINE NSString * OOIntCredits(OOCreditsQuantity integerCredits)
NSString * OOCommodityType
uint64_t OOCreditsQuantity
@ WEAPON_FACING_STARBOARD
#define MAX_ROWS_SHIPS_FOR_SALE
#define GUI_ROW_SHIPYARD_START
#define CONTRACT_KEY_RISK
#define PASSENGER_KEY_NAME
#define GUI_ROW_SHIPYARD_INFO_START
#define SET_MANIFEST_ROW(obj, color, row)
static unsigned RepForRisk(unsigned risk)
static NSMutableDictionary * currentShipyard
#define MANIFEST_SCREEN_ROW_BACK
#define MANIFEST_SCREEN_ROW_NEXT
OOWeaponType OOWeaponTypeFromEquipmentIdentifierSloppy(NSString *string) PURE_FUNC
#define PASSENGER_BERTH_SPACE
OOCreditsQuantity tradeInValue()
BOOL setBackgroundTextureKey:(NSString *key)
OOColor * colorFromSetting:defaultValue:(NSString *setting,[defaultValue] OOColor *def)
BOOL setSelectedRow:(OOGUIRow row)
OOGUIRow addLongText:startingAtRow:align:(NSString *str,[startingAtRow] OOGUIRow row,[align] OOGUIAlignment alignment)
BOOL setForegroundTextureKey:(NSString *key)
void setStatusPage:(NSInteger pageNum)
void setText:forRow:(NSString *str,[forRow] OOGUIRow row)
void setText:forRow:align:(NSString *str,[forRow] OOGUIRow row,[align] OOGUIAlignment alignment)
void clearAndKeepBackground:(BOOL keepBackground)
void overrideTabs:from:length:(OOGUITabSettings stops,[from] NSString *setting,[length] NSUInteger len)
void setSelectableRange:(NSRange range)
void setColor:forRow:(OOColor *color,[forRow] OOGUIRow row)
id objectForRow:(OOGUIRow row)
void setTitle:(NSString *str)
void setTabStops:(OOGUITabSettings stops)
NSString * keyForRow:(OOGUIRow row)
void setShowTextCursor:(BOOL yesno)
BOOL setBackgroundTextureDescriptor:(NSDictionary *descriptor)
void setArray:forRow:(NSArray *arr,[forRow] OOGUIRow row)
void setKey:forRow:(NSString *str,[forRow] OOGUIRow row)
OOCreditsQuantity insuranceCredits()
void doScriptEvent:(jsid message)
NSDictionary * infoForScripting()
NSString * shortDescription()
OOColor * darkGrayColor()
OOEquipmentType * equipmentTypeWithIdentifier:(NSString *identifier)
NSDictionary * shipyardInfoForKey:(NSString *key)
OOShipRegistry * sharedRegistry()
NSDictionary * shipInfoForKey:(NSString *key)
void calculateCurrentCargo()
void runUnsanitizedScriptActions:allowingAIMethods:withContextName:forTarget:(NSArray *unsanitizedActions,[allowingAIMethods] BOOL allowAIMethods,[withContextName] NSString *contextName,[forTarget] ShipEntity *target)
void doScriptEvent:withArguments:(jsid message,[withArguments] NSArray *arguments)
void setCrew:(NSArray *crewArray)
NSMutableArray * localShipyard
void generateShipyard:(OOTechLevelID stationTechLevel)
OOTechLevelID equivalentTechLevel
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
double cunningFee(double value, double precision)