66 BOOL added_entry = NO;
69 OOGovernmentID government = [[[UNIVERSE currentSystemData] objectForKey:KEY_GOVERNMENT] intValue];
70 if ([
UNIVERSE inInterstellarSpace]) government = 1;
74 for (i = 0; i < [
cargo count]; i++)
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"),
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"),
156 if ((i < [rescuees
count] - 1) && added_entry)
157 [
result appendString:@"\n"];
169 if ([
self dockedStation] != [
UNIVERSE station])
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];
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];
237 [
result appendFormatLine:DESC(@"passenger-failed-@"), passenger_name];
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)];
275 [
parcels removeObjectAtIndex:i--];
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)];
296 [
parcels removeObjectAtIndex:i--];
305 [
result appendFormatLine:DESC(@"parcel-failed-@"), parcel_name];
308 [
parcels removeObjectAtIndex: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];
331 int contract_amount = [
contract_info oo_intForKey:CARGO_KEY_AMOUNT];
339 if (quantity_on_hand >= contract_amount)
351 if ([shipCommodityData exportLegalityForGood:contract_cargo_type] > 0)
361 [
result appendFormatLine:DESC(@"cargo-delivered-okay-@-@"), contract_cargo_desc, OOCredits(fee)];
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)
383 int shortfall = 100 - percent_delivered;
384 int payment = percent_delivered * (fee) / 100.0;
387 if ([shipCommodityData exportLegalityForGood:contract_cargo_type] > 0)
396 [
result appendFormatLine:DESC(@"cargo-delivered-short-@-@-d"), contract_cargo_desc, OOCredits(payment), shortfall];
405 [
result appendFormatLine:DESC(@"cargo-refused-short-%@"), contract_cargo_desc];
413 [
result appendFormatLine:DESC(@"cargo-delivered-late-@"), contract_cargo_desc];
426 [
result appendFormatLine:DESC(@"cargo-failed-@"), contract_cargo_desc];
439 for (i = 0; i < [
names count]; i++)
449 NSDictionary* passenger_info = [
passengers oo_dictionaryAtIndex:j];
450 if ([[passenger_info objectForKey:
PASSENGER_KEY_NAME] isEqual:[names objectAtIndex:i]])
462 for (i = 0; i < [
ids count]; i++)
473 for (i = 0; i < [
ids count]; i++)
483 if ([result length] == 0)
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;
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,
1026 if (contractCargoUnits ==
UNITS_KILOGRAMS) cargoSpaceRequired /= 1000;
1027 if (contractCargoUnits ==
UNITS_GRAMS) cargoSpaceRequired /= 1000000;
1029 if (cargoSpaceRequired > [
self availableCargoSpace])
return NO;
1035 if ([shipCommodityData exportLegalityForGood:type] > 0)
1135 gui_screen = GUI_SCREEN_MANIFEST;
1136 BOOL guiChanged = (oldScreen != gui_screen);
1144 NSInteger current, max;
1150 NSArray* cargoManifest = [
self cargoList];
1154 NSUInteger max_rows = 20;
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]])
1182 NSInteger page_offset = 0;
1183 BOOL multi_page = NO;
1185 NSUInteger total_rows = cargoRowCount + mmRows + 5;
1186 if (total_rows > max_rows)
1190 if (page_offset < 0 || (NSUInteger)page_offset >= total_rows)
1211 current = current_cargo;
1213 NSString *cargoString =
OOExpandKey(
@"oolite-manifest-cargo", current, max);
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++)
1228 if (i + cargoRowCount < manifestCount)
1245 missionsRow = cargoRow + cargoRowCount + 1;
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;
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)
1307 r_start = nextPageRow;
1311 if (total_rows > max_rows + page_offset)
1339 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO];
1373 gui_screen = GUI_SCREEN_REPORT;
1374 BOOL guiChanged = (oldScreen != gui_screen);
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)];
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"];
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];
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];
1545 for (i = 0; i < (shipCount - skip) && (
int)i < rowCount; i++)
1547 NSDictionary* ship_info = [
shipyard oo_dictionaryAtIndex:i + skip];
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),
1557 if (i < shipCount - skip)
1565 [
gui setSelectableRange:NSMakeRange( GUI_ROW_SHIPYARD_START, i + startRow - GUI_ROW_SHIPYARD_START)];
1572 [
gui setText:DESC(@"shipyard-no-ships-available-for-purchase")
forRow:GUI_ROW_NO_SHIPS
align:GUI_ALIGN_CENTER];
1586 [UNIVERSE enterGUIViewModeWithMouseInteraction:YES];
1602 if (sel_row <= 0)
return;
1605 while ([row_info
count] < 4)
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];
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)];
1731 if (selectedRow <= 0)
return NO;
1735 if ([key hasPrefix:
@"More:"])
1737 NSInteger fromShip = [[
key componentsSeparatedByString:@":"] oo_integerAtIndex:1];
1738 if (fromShip < 0) fromShip = 0;
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];
1752 while ([row_info
count] < 4)
1756 [
row_info replaceObjectAtIndex:2 withObject:@""];
1757 [
row_info replaceObjectAtIndex:3 withObject:@""];
1765 [UNIVERSE removeDemoShips];
1770 NSDictionary *shipInfo = [currentShipyard oo_dictionaryForKey:key];
1774 if (credits + tradeIn < price * 10)
1781 [
NSNumber numberWithUnsignedLongLong:price],
1782 [
NSNumber numberWithUnsignedLongLong:(tradeIn / 10)], nil]];
1785 NSString *good =
nil;
1786 foreach (good, [shipCommodityData goods])
1795 credits -= 10 * price - tradeIn;
1797 NSDictionary *shipDict = [
shipInfo oo_dictionaryForKey:SHIPYARD_KEY_SHIP];
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"])
1826 if (![
self setCommanderDataFromDictionary:cmdr_dict])
return NO;
1832 ship_clock_adjust += 3600.0;
1835 ship_trade_in_factor = 100;
1837 if ([
UNIVERSE autoSave]) [UNIVERSE setAutoSaveNow:YES];