64 BOOL added_entry = NO;
67 OOGovernmentID government = [[[UNIVERSE currentSystemData] objectForKey:KEY_GOVERNMENT] intValue];
73 for (i = 0; i < [
cargo count]; i++) {
79 [
rescuees addObjectsFromArray:podCrew];
81 [
cargo removeObjectAtIndex:i];
87 for (i = 0; i < [
rescuees count]; i++) {
90 if ([rescuee script]) {
92 }
else if ([rescuee legacyScript]) {
97 }
else if ([rescuee insuranceCredits] && [rescuee legalStatus]) {
98 float reward = (5.0 + government) * [rescuee legalStatus];
100 if (government > (
Ranrot() & 7) || reward >= insurance) {
102 [
result appendFormat:DESC(@"capture-reward-for-@@-@-credits-@-alt"),
104 OOStringFromDeciCredits(insurance, YES, NO)];
108 [
result appendFormat:DESC(@"rescue-reward-for-@@-@-credits-@-alt"),
110 OOStringFromDeciCredits(reward, YES, NO)];
111 reward = insurance - reward;
116 }
else if ([rescuee insuranceCredits]) {
118 [
result appendFormat:DESC(@"rescue-reward-for-@@-@-credits"),
124 }
else if ([rescuee legalStatus]) {
126 float reward = (5.0 + government) * [rescuee legalStatus];
127 [
result appendFormat:DESC(@"capture-reward-for-@@-@-credits"),
137 if ((i < [rescuees
count] - 1) && added_entry)
138 [
result appendString:@"\n"];
149 if ([
self dockedStation] != [
UNIVERSE station])
160 NSDictionary* passenger_info = [[
passengers oo_dictionaryAtIndex:i] retain];
161 NSString* passenger_name = [
passenger_info oo_stringForKey:PASSENGER_KEY_NAME];
162 int dest = [
passenger_info oo_intForKey:CONTRACT_KEY_DESTINATION];
164 NSString* passenger_dest_name = [UNIVERSE getSystemName:dest];
165 int dest_eta = [
passenger_info oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
167 if (system_id == dest) {
171 long long fee = [
passenger_info oo_longLongForKey:CONTRACT_KEY_FEE];
172 while ((
randf() < 0.75) && (dest_eta > 3600))
180 [
result appendFormatLine:DESC(@"passenger-delivered-okay-@-@-@"), passenger_name, OOIntCredits(fee), passenger_dest_name];
181 if ([passenger_info oo_unsignedIntForKey:
CONTRACT_KEY_RISK defaultValue:0] > 0) {
190 long long fee = [
passenger_info oo_longLongForKey:CONTRACT_KEY_FEE] / 2;
191 while (
randf() < 0.5)
195 [
result appendFormatLine:DESC(@"passenger-delivered-late-@-@-@"), passenger_name, OOIntCredits(fee), passenger_dest_name];
196 if ([passenger_info oo_unsignedIntForKey:
CONTRACT_KEY_RISK defaultValue:0] > 0) {
206 [
result appendFormatLine:DESC(@"passenger-failed-@"), passenger_name];
217 for (i = 0; i < [
parcels count]; i++) {
218 NSDictionary* parcel_info = [[
parcels oo_dictionaryAtIndex:i] retain];
219 NSString* parcel_name = [
parcel_info oo_stringForKey:PASSENGER_KEY_NAME];
220 int dest = [
parcel_info oo_intForKey:CONTRACT_KEY_DESTINATION];
221 int dest_eta = [
parcel_info oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
223 if (system_id == dest) {
227 long long fee = [
parcel_info oo_longLongForKey:CONTRACT_KEY_FEE];
228 while ((
randf() < 0.75) && (dest_eta > 86400))
237 [
result appendFormatLine:DESC(@"parcel-delivered-okay-@-@"), parcel_name, OOIntCredits(fee)];
241 [
parcels removeObjectAtIndex:i--];
249 long long fee = [
parcel_info oo_longLongForKey:CONTRACT_KEY_FEE] / 2;
250 while (
randf() < 0.5)
254 [
result appendFormatLine:DESC(@"parcel-delivered-late-@-@"), parcel_name, OOIntCredits(fee)];
258 [
parcels removeObjectAtIndex:i--];
264 [
result appendFormatLine:DESC(@"parcel-failed-@"), parcel_name];
267 [
parcels removeObjectAtIndex:i--];
275 for (i = 0; i < [
contracts count]; i++) {
276 NSDictionary* contract_info = [[
contracts oo_dictionaryAtIndex:i] retain];
277 NSString* contract_cargo_desc = [
contract_info oo_stringForKey:CARGO_KEY_DESCRIPTION];
278 int dest = [
contract_info oo_intForKey:CONTRACT_KEY_DESTINATION];
279 int dest_eta = [
contract_info oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
281 if (system_id == dest) {
284 int fee = 10 * [
contract_info oo_floatForKey:CONTRACT_KEY_FEE];
287 int contract_amount = [
contract_info oo_intForKey:CARGO_KEY_AMOUNT];
294 if (quantity_on_hand >= contract_amount) {
305 if ([shipCommodityData exportLegalityForGood:contract_cargo_type] > 0) {
312 [
result appendFormatLine:DESC(@"cargo-delivered-okay-@-@"), contract_cargo_desc, OOCredits(fee)];
323 float percent_delivered = 100.0 * (float)quantity_on_hand / (
float)contract_amount;
324 float acceptable_ratio = 100.0 - 10.0 * system_id / 256.0;
326 if (percent_delivered >= acceptable_ratio) {
331 int shortfall = 100 - percent_delivered;
332 int payment = percent_delivered * (fee) / 100.0;
335 if ([shipCommodityData exportLegalityForGood:contract_cargo_type] > 0) {
341 [
result appendFormatLine:DESC(@"cargo-delivered-short-@-@-d"), contract_cargo_desc, OOCredits(payment), shortfall];
348 [
result appendFormatLine:DESC(@"cargo-refused-short-%@"), contract_cargo_desc];
354 [
result appendFormatLine:DESC(@"cargo-delivered-late-@"), contract_cargo_desc];
364 [
result appendFormatLine:DESC(@"cargo-failed-@"), contract_cargo_desc];
377 for (i = 0; i < [
names count]; i++) {
384 NSDictionary* passenger_info = [
passengers oo_dictionaryAtIndex:j];
385 if ([[passenger_info objectForKey:
PASSENGER_KEY_NAME] isEqual:[names objectAtIndex:i]])
396 for (i = 0; i < [
ids count]; i++) {
405 for (i = 0; i < [
ids count]; i++) {
412 if ([result length] == 0) {
746- (BOOL)addPassenger:(NSString*)Name start:(
unsigned)start destination:(
unsigned)Destination eta:(
double)eta fee:(
double)fee advance:(
double)advance risk:(
unsigned)risk
748 NSDictionary* passenger_info = [
NSDictionary dictionaryWithObjectsAndKeys:
749 Name, PASSENGER_KEY_NAME,
750 [
NSNumber numberWithInt:start], CONTRACT_KEY_START,
751 [
NSNumber numberWithInt:Destination], CONTRACT_KEY_DESTINATION,
752 [
NSNumber numberWithDouble:[PLAYER clockTime]], CONTRACT_KEY_DEPARTURE_TIME,
753 [
NSNumber numberWithDouble:eta], CONTRACT_KEY_ARRIVAL_TIME,
754 [
NSNumber numberWithDouble:fee], CONTRACT_KEY_FEE,
755 [
NSNumber numberWithDouble:advance], CONTRACT_KEY_PREMIUM,
756 [
NSNumber numberWithUnsignedInt:risk], CONTRACT_KEY_RISK,
761 if ([passengers
count] >= max_passengers || [passenger_record objectForKey:Name] !=
nil)
849- (BOOL)awardContract:(
unsigned)qty commodity:(
OOCommodityType)type start:(
unsigned)start
850 destination:(
unsigned)Destination
853 premium:(
double)premium
856 unsigned sr1 =
Ranrot() & 0x111111;
857 int sr2 =
Ranrot() & 0x111111;
859 NSString* cargo_ID = [
NSString stringWithFormat:@"%06x-%06x", sr1, sr2];
861 if (![[
UNIVERSE commodities] goodDefined:type])
867 while ([contract_record objectForKey:cargo_ID] !=
nil) {
869 cargo_ID = [
NSString stringWithFormat:@"%06x-%06x", sr1, sr2];
872 NSDictionary* cargo_info = [
NSDictionary dictionaryWithObjectsAndKeys:
873 cargo_ID, CARGO_KEY_ID,
874 type, CARGO_KEY_TYPE,
875 [
NSNumber numberWithInt:qty], CARGO_KEY_AMOUNT,
876 [UNIVERSE describeCommodity:type
878 CARGO_KEY_DESCRIPTION,
879 [
NSNumber numberWithInt:start], CONTRACT_KEY_START,
880 [
NSNumber numberWithInt:Destination], CONTRACT_KEY_DESTINATION,
881 [
NSNumber numberWithDouble:[PLAYER clockTime]], CONTRACT_KEY_DEPARTURE_TIME,
882 [
NSNumber numberWithDouble:eta], CONTRACT_KEY_ARRIVAL_TIME,
883 [
NSNumber numberWithDouble:fee], CONTRACT_KEY_FEE,
884 [
NSNumber numberWithDouble:premium], CONTRACT_KEY_PREMIUM,
893 cargoSpaceRequired /= 1000;
895 cargoSpaceRequired /= 1000000;
897 if (cargoSpaceRequired > [
self availableCargoSpace])
904 if ([shipCommodityData exportLegalityForGood:type] > 0) {
991 gui_screen = GUI_SCREEN_MANIFEST;
992 BOOL guiChanged = (oldScreen != gui_screen);
999 NSInteger current, max;
1005 NSArray* cargoManifest = [
self cargoList];
1009 NSUInteger max_rows = 20;
1011 NSUInteger cargoRowCount = (manifestCount + 1) / 2;
1017 if ([[
self hud] isHidden] || [[
self hud] allowBigGui]) {
1022 NSUInteger mmRows = 0;
1024 foreach (mmEntry, missionsManifest) {
1025 if ([mmEntry isKindOfClass:[NSString
class]]) {
1027 }
else if ([mmEntry isKindOfClass:[NSArray
class]]) {
1032 NSInteger page_offset = 0;
1033 BOOL multi_page = NO;
1035 NSUInteger total_rows = cargoRowCount + mmRows + 5;
1036 if (total_rows > max_rows) {
1039 if (page_offset < 0 || (NSUInteger)page_offset >= total_rows) {
1058 current = current_cargo;
1060 NSString* cargoString =
OOExpandKey(
@"oolite-manifest-cargo", current, max);
1062 max = max_passengers;
1063 NSString* cabinString =
OOExpandKey(
@"oolite-manifest-cabins", current, max);
1064 NSArray* manifestHeader = [
NSArray arrayWithObjects:cargoString, cabinString, nil];
1068 if (manifestCount > 0) {
1069 for (i = 0; i < cargoRowCount; i++) {
1073 if (i + cargoRowCount < manifestCount) {
1085 missionsRow = cargoRow + cargoRowCount + 1;
1090 if (manifestCount > 0) {
1091 if ([[missionsManifest objectAtIndex:0] isKindOfClass:[NSString
class]]) {
1099 NSUInteger mmRow = 0;
1100 for (i = 0; i < manifestCount; i++) {
1101 NSString* mmItem =
nil;
1103 if ([mmEntry isKindOfClass:[NSString
class]]) {
1104 mmItem = [
NSString stringWithFormat:@"\t%@", (NSString*)mmEntry];
1107 }
else if ([mmEntry isKindOfClass:[NSArray
class]]) {
1108 BOOL isHeading = YES;
1109 foreach (mmItem, mmEntry) {
1113 mmItem = [
NSString stringWithFormat:@"\t%@", (NSString*)mmItem];
1126 if (page_offset > 0) {
1131 r_start = nextPageRow;
1135 if (total_rows > max_rows + page_offset) {
1158 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO];
1188 gui_screen = GUI_SCREEN_REPORT;
1189 BOOL guiChanged = (oldScreen != gui_screen);
1198 [
gui setTitle:OOExpandKey(@"arrival-report-title")];
1200 for (i = 1; i <= 18; i++) {
1206 while (([dockingReport length] > 0) && (text_row < 18)) {
1207 if ([dockingReport rangeOfString:
@"\n"].location != NSNotFound) {
1208 while (([dockingReport rangeOfString:
@"\n"].location != NSNotFound) && (text_row < 18)) {
1209 NSUInteger line_break = [
dockingReport rangeOfString:@"\n"].location;
1210 NSString* line = [
dockingReport substringToIndex:line_break];
1211 [
dockingReport deleteCharactersInRange:NSMakeRange(0, line_break + 1)];
1236 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO];
1241 NSDictionary* bgDescriptor = [UNIVERSE screenTextureDescriptorForKey:@"report"];
1242 if (bgDescriptor ==
nil)
1243 bgDescriptor = [UNIVERSE screenTextureDescriptorForKey:@"status_docked"];
1244 if (bgDescriptor ==
nil)
1245 bgDescriptor = [UNIVERSE screenTextureDescriptorForKey:@"status"];
1261- (void)setGuiToShipyardScreen:(NSUInteger)skip
1266 gui_screen = GUI_SCREEN_SHIPYARD;
1267 BOOL guiChanged = (oldScreen != gui_screen);
1275 if (station !=
nil) {
1278 station = [UNIVERSE station];
1279 stationTechLevel = NSNotFound;
1281 if ([station localShipyard] ==
nil) {
1287 [currentShipyard release];
1290 for (i = 0; i < [
shipyard count]; i++) {
1291 [currentShipyard setObject:[
shipyard objectAtIndex:i]
1292 forKey:[[
shipyard oo_dictionaryAtIndex:i] oo_stringForKey:SHIPYARD_KEY_ID]];
1295 NSUInteger shipCount = [
shipyard count];
1298 if (skip >= shipCount)
1299 skip = shipCount - 1;
1306 NSString* system = [UNIVERSE getSystemName:system_id];
1307 [
gui setTitle:OOExpandKey(@"shipyard-title", system)];
1311 tab_stops[1] = -258;
1320 NSInteger previous = 0;
1332 if (skip + rowCount < shipCount)
1336 if (shipCount > 0) {
1338 [
gui setArray:[
NSArray arrayWithObjects:DESC(@"shipyard-shiptype"), DESC(@"shipyard-price-label"),
1339 DESC(@"shipyard-cargo-label"), DESC(@"shipyard-speed-label"), nil]
1340 forRow:GUI_ROW_SHIPYARD_LABELS];
1347 for (i = 0; i < (shipCount - skip) && (
int)i < rowCount; i++) {
1348 NSDictionary* ship_info = [
shipyard oo_dictionaryAtIndex:i + skip];
1352 [
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]]],
1353 OOIntCredits(ship_price),
1358 if (i < shipCount - skip) {
1365 [
gui setSelectableRange:NSMakeRange(GUI_ROW_SHIPYARD_START, i + startRow - GUI_ROW_SHIPYARD_START)];
1371 [
gui setText:DESC(@"shipyard-no-ships-available-for-purchase")
forRow:GUI_ROW_NO_SHIPS
align:GUI_ALIGN_CENTER];
1385 [UNIVERSE enterGUIViewModeWithMouseInteraction:YES];
1403 while ([row_info
count] < 4) {
1409 NSDictionary* info = [currentShipyard oo_dictionaryForKey:key];
1412 [
row_info replaceObjectAtIndex:2 withObject:@""];
1413 [
row_info replaceObjectAtIndex:3 withObject:@""];
1418 [UNIVERSE removeDemoShips];
1422 NSString* salesPitch = [
info oo_stringForKey:KEY_SHORT_DESCRIPTION];
1423 NSDictionary* shipDict = [
info oo_dictionaryForKey:SHIPYARD_KEY_SHIP];
1425 int cargoRating = [
shipDict oo_intForKey:@"max_cargo"];
1427 cargo_extra = [
shipDict oo_intForKey:@"extra_cargo" defaultValue:15];
1428 float speedRating = 0.001 * [
shipDict oo_intForKey:@"max_flight_speed"];
1430 NSArray* shipExtras = [
info oo_arrayForKey:KEY_EQUIPMENT_EXTRAS];
1432 if ([[shipExtras oo_stringAtIndex:i] isEqualToString:
@"EQ_CARGO_BAY"]) {
1433 cargoRating += cargo_extra;
1434 }
else if ([[shipExtras oo_stringAtIndex:i] isEqualToString:
@"EQ_PASSENGER_BERTH"]) {
1439 [
row_info replaceObjectAtIndex:2 withObject:OOExpandKey(@"shipyard-cargo-value", cargoRating)];
1440 [
row_info replaceObjectAtIndex:3 withObject:OOExpandKey(@"shipyard-speed-value", speedRating)];
1515 if (selectedRow <= 0)
1520 if ([key hasPrefix:
@"More:"]) {
1521 NSInteger fromShip = [[
key componentsSeparatedByString:@":"] oo_integerAtIndex:1];
1526 if ([[
UNIVERSE gui] selectedRow] < 0) {
1527 [[UNIVERSE gui] setSelectedRow:GUI_ROW_SHIPYARD_START];
1529 if (fromShip == 0) {
1530 [[UNIVERSE gui] setSelectedRow:GUI_ROW_SHIPYARD_START + MAX_ROWS_SHIPS_FOR_SALE - 1];
1535 while ([row_info
count] < 4) {
1538 [
row_info replaceObjectAtIndex:2 withObject:@""];
1539 [
row_info replaceObjectAtIndex:3 withObject:@""];
1546 [UNIVERSE removeDemoShips];
1551 NSDictionary* shipInfo = [currentShipyard oo_dictionaryForKey:key];
1555 if (credits + tradeIn < price * 10)
1562 [
NSNumber numberWithUnsignedLongLong:price],
1563 [
NSNumber numberWithUnsignedLongLong:(tradeIn / 10)], nil]];
1566 NSString* good =
nil;
1567 foreach (good, [shipCommodityData goods]) {
1575 credits -= 10 * price - tradeIn;
1577 NSDictionary* shipDict = [
shipInfo oo_dictionaryForKey:SHIPYARD_KEY_SHIP];
1583 NSArray* extras = [
shipInfo oo_arrayForKey:KEY_EQUIPMENT_EXTRAS];
1584 for (NSUInteger i = 0; i < [
extras count]; i++) {
1585 NSString* eq_key = [
extras oo_stringAtIndex:i];
1586 if ([eq_key isEqualToString:
@"EQ_PASSENGER_BERTH"]) {
1602 if (![
self setCommanderDataFromDictionary:cmdr_dict])
1609 ship_clock_adjust += 3600.0;
1612 ship_trade_in_factor = 100;
1615 [UNIVERSE setAutoSaveNow:YES];