168{
169 if ([
self dockedStation] != [
UNIVERSE station])
171
172
173
174
175 NSMutableString *result = [NSMutableString string];
176 unsigned i;
177
178
179 for (i = 0; i < [passengers count]; i++)
180 {
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];
184
185 NSString* passenger_dest_name = [UNIVERSE getSystemName: dest];
186 int dest_eta = [passenger_info oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
187
188 if (system_id == dest)
189 {
190
191 if (dest_eta > 0)
192 {
193
194 long long fee = [passenger_info oo_longLongForKey:CONTRACT_KEY_FEE];
195 while ((
randf() < 0.75)&&(dest_eta > 3600))
196 {
197 fee *= 110;
198 fee /= 100;
199 dest_eta *= 0.5;
200 }
201 credits += 10 * fee;
202
203 [result appendFormatLine:DESC(@"passenger-delivered-okay-@-@-@"), passenger_name, OOIntCredits(fee), passenger_dest_name];
205 {
206 [self addRoleToPlayer:@"trader-courier+"];
207 }
208
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]];
212 }
213 else
214 {
215
216 long long fee = [passenger_info oo_longLongForKey:CONTRACT_KEY_FEE] / 2;
217 while (
randf() < 0.5)
218 fee /= 2;
219 credits += 10 * fee;
220
221 [result appendFormatLine:DESC(@"passenger-delivered-late-@-@-@"), passenger_name, OOIntCredits(fee), passenger_dest_name];
223 {
224 [self addRoleToPlayer:@"trader-courier+"];
225 }
226
227 [passengers removeObjectAtIndex:i--];
228 [self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"passenger",@"late",[NSNumber numberWithUnsignedInteger:10*fee],passenger_info,nil]];
229
230 }
231 }
232 else
233 {
234 if (dest_eta < 0)
235 {
236
237 [result appendFormatLine:DESC(@"passenger-failed-@"), passenger_name];
238
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]];
242 }
243 }
244 [passenger_info release];
245 }
246
247
248 for (i = 0; i < [parcels count]; i++)
249 {
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;
254
255 if (system_id == dest)
256 {
257
258 if (dest_eta > 0)
259 {
260
261 long long fee = [parcel_info oo_longLongForKey:CONTRACT_KEY_FEE];
262 while ((
randf() < 0.75)&&(dest_eta > 86400))
263 {
264
265 fee *= 110;
266 fee /= 100;
267 dest_eta *= 0.5;
268 }
269 credits += 10 * fee;
270
271 [result appendFormatLine:DESC(@"parcel-delivered-okay-@-@"), parcel_name, OOIntCredits(fee)];
272
273 [self increaseParcelReputation:RepForRisk([parcel_info oo_unsignedIntForKey:CONTRACT_KEY_RISK defaultValue:0])];
274
275 [parcels removeObjectAtIndex:i--];
277 {
278 [self addRoleToPlayer:@"trader-courier+"];
279 }
280 [self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"parcel",@"success",[NSNumber numberWithUnsignedInteger:10*fee],parcel_info,nil]];
281
282 }
283 else
284 {
285
286 long long fee = [parcel_info oo_longLongForKey:CONTRACT_KEY_FEE] / 2;
287 while (
randf() < 0.5)
288 fee /= 2;
289 credits += 10 * fee;
290
291 [result appendFormatLine:DESC(@"parcel-delivered-late-@-@"), parcel_name, OOIntCredits(fee)];
293 {
294 [self addRoleToPlayer:@"trader-courier+"];
295 }
296 [parcels removeObjectAtIndex:i--];
297 [self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"parcel",@"late",[NSNumber numberWithUnsignedInteger:10*fee],parcel_info,nil]];
298 }
299 }
300 else
301 {
302 if (dest_eta < 0)
303 {
304
305 [result appendFormatLine:DESC(@"parcel-failed-@"), parcel_name];
306
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]];
310 }
311 }
312 [parcel_info release];
313 }
314
315
316
317 for (i = 0; i < [contracts count]; i++)
318 {
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;
323
324 if (system_id == dest)
325 {
326
327
328 int fee = 10 * [contract_info oo_floatForKey:CONTRACT_KEY_FEE];
329
330 OOCommodityType contract_cargo_type = [contract_info oo_stringForKey:CARGO_KEY_TYPE];
331 int contract_amount = [contract_info oo_intForKey:CARGO_KEY_AMOUNT];
332
333 int quantity_on_hand = [shipCommodityData quantityForGood:contract_cargo_type];
334
335
336 if (dest_eta > 0)
337 {
338
339 if (quantity_on_hand >= contract_amount)
340 {
341
342
343
344 [shipCommodityData removeQuantity:contract_amount forGood:contract_cargo_type];
345
346
347
348
349
350
351 if ([shipCommodityData exportLegalityForGood:contract_cargo_type] > 0)
352 {
353 [self addRoleToPlayer:@"trader-smuggler"];
354 }
355 else
356 {
357 [self addRoleToPlayer:@"trader"];
358 }
359
360 credits += fee;
361 [result appendFormatLine:DESC(@"cargo-delivered-okay-@-@"), contract_cargo_desc, OOCredits(fee)];
362
363 [contracts removeObjectAtIndex:i--];
364
365
366 [self increaseContractReputation:10];
367 [self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"cargo",@"success",[NSNumber numberWithUnsignedInteger:fee],contract_info,nil]];
368
369 }
370 else
371 {
372
373
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;
376
377 if (percent_delivered >= acceptable_ratio)
378 {
379
380 [shipCommodityData setQuantity:0 forGood:contract_cargo_type];
381
382
383 int shortfall = 100 - percent_delivered;
384 int payment = percent_delivered * (fee) / 100.0;
385 credits += payment;
386
387 if ([shipCommodityData exportLegalityForGood:contract_cargo_type] > 0)
388 {
389 [self addRoleToPlayer:@"trader-smuggler"];
390 }
391 else
392 {
393 [self addRoleToPlayer:@"trader"];
394 }
395
396 [result appendFormatLine:DESC(@"cargo-delivered-short-@-@-d"), contract_cargo_desc, OOCredits(payment), shortfall];
397
398 [contracts removeObjectAtIndex:i--];
399
400 [self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"cargo",@"short",[NSNumber numberWithUnsignedInteger:payment],contract_info,nil]];
401
402 }
403 else
404 {
405 [result appendFormatLine:DESC(@"cargo-refused-short-%@"), contract_cargo_desc];
406
407 }
408 }
409 }
410 else
411 {
412
413 [result appendFormatLine:DESC(@"cargo-delivered-late-@"), contract_cargo_desc];
414
415 [contracts removeObjectAtIndex:i--];
416
417 [self decreaseContractReputation:10];
418 [self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"cargo",@"late",[NSNumber numberWithUnsignedInteger:0],contract_info,nil]];
419 }
420 }
421 else
422 {
423 if (dest_eta < 0)
424 {
425
426 [result appendFormatLine:DESC(@"cargo-failed-@"), contract_cargo_desc];
427
428 [contracts removeObjectAtIndex:i--];
429
430 [self decreaseContractReputation:10];
431 [self doScriptEvent:OOJSID("playerCompletedContract") withArguments:[NSArray arrayWithObjects:@"cargo",@"failed",[NSNumber numberWithUnsignedInteger:0],contract_info,nil]];
432 }
433 }
434 [contract_info release];
435 }
436
437
438 NSArray* names = [passenger_record allKeys];
439 for (i = 0; i < [names count]; i++)
440 {
441 double dest_eta = [passenger_record oo_doubleForKey:[names objectAtIndex:i]] - ship_clock;
442 if (dest_eta < 0)
443 {
444
445 BOOL on_board = NO;
446 unsigned j;
447 for (j = 0; j < [passengers count]; j++)
448 {
449 NSDictionary* passenger_info = [passengers oo_dictionaryAtIndex:j];
450 if ([[passenger_info objectForKey:
PASSENGER_KEY_NAME] isEqual:[names objectAtIndex:i]])
451 on_board = YES;
452 }
453 if (!on_board)
454 {
455 [passenger_record removeObjectForKey:[names objectAtIndex:i]];
456 }
457 }
458 }
459
460
461 NSArray* ids = [contract_record allKeys];
462 for (i = 0; i < [ids count]; i++)
463 {
464 double dest_eta = [(NSNumber*)[contract_record objectForKey:[ids objectAtIndex:i]] doubleValue] - ship_clock;
465 if (dest_eta < 0)
466 {
467 [contract_record removeObjectForKey:[ids objectAtIndex:i]];
468 }
469 }
470
471
472 ids = [parcel_record allKeys];
473 for (i = 0; i < [ids count]; i++)
474 {
475 double dest_eta = [(NSNumber*)[parcel_record objectForKey:[ids objectAtIndex:i]] doubleValue] - ship_clock;
476 if (dest_eta < 0)
477 {
478 [parcel_record removeObjectForKey:[ids objectAtIndex:i]];
479 }
480 }
481
482
483 if ([result length] == 0)
484 {
486 }
487 else
488 {
489
490 [result deleteCharacterAtIndex:[result length] - 1];
491 }
492
493 return result;
494}
#define CONTRACT_KEY_RISK
#define PASSENGER_KEY_NAME