From 0840a749686df3e9c3a7b9f2f853be04ab5ab015 Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 7 Nov 2011 19:30:35 +0000 Subject: [PATCH] * Manifest screen fixes: - removed unnecessary extra blank lines. - when all possible types of cargo are in the hold, show alien items quantity on the manifest screen! - If more passengers/contracts/missions than can be displayed, show '...' rather than overflowing into the HUD area. * fix: no passengers / contracts from hacked strict mode savegames. * fixed a contract_record memleak. - whitespaces code cleanup. git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4641 127b21dd-08f5-0310-b4b7-95ae10353056 --- src/Core/Entities/PlayerEntity.m | 103 +++++++++-------- src/Core/Entities/PlayerEntityContracts.m | 134 +++++++++++++--------- 2 files changed, 138 insertions(+), 99 deletions(-) diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index c8ca2ff9..93e36af0 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -817,7 +817,7 @@ static GLfloat sBaseMass = 0.0; eqScripts = [[NSMutableArray alloc] init]; [self addEquipmentFromCollection:equipment]; primedEquipment = [self getEqScriptIndexForKey:[dict oo_stringForKey:@"primed_equipment"]]; // if key not found primedEquipment is set to primed-none - + if ([self hasEquipmentItem:@"EQ_ADVANCED_COMPASS"]) compassMode = COMPASS_MODE_PLANET; else compassMode = COMPASS_MODE_BASIC; compassTarget = nil; @@ -833,35 +833,48 @@ static GLfloat sBaseMass = 0.0; [reputation release]; reputation = [[dict oo_dictionaryForKey:@"reputation"] mutableCopy]; if (reputation == nil) reputation = [[NSMutableDictionary alloc] init]; - - // passengers - max_passengers = [dict oo_intForKey:@"max_passengers"]; + + // passengers and contracts [passengers release]; - passengers = [[dict oo_arrayForKey:@"passengers"] mutableCopy]; - if (passengers == nil) passengers = [[NSMutableArray alloc] init]; [passenger_record release]; - passenger_record = [[dict oo_dictionaryForKey:@"passenger_record"] mutableCopy]; + [contracts release]; + [contract_record release]; + + // Don't load passengers & contracts in strict mode savegames! + if ([UNIVERSE strict]) + { + max_passengers = 0; + passengers = nil; + passenger_record = nil; + contracts = nil; + contract_record = nil; + } + else + { + max_passengers = [dict oo_intForKey:@"max_passengers" defaultValue:0]; + passengers = [[dict oo_arrayForKey:@"passengers"] mutableCopy]; + passenger_record = [[dict oo_dictionaryForKey:@"passenger_record"] mutableCopy]; + contracts = [[dict oo_arrayForKey:@"contracts"] mutableCopy]; + contract_record = [[dict oo_dictionaryForKey:@"contract_record"] mutableCopy]; + } + + if (passengers == nil) passengers = [[NSMutableArray alloc] init]; if (passenger_record == nil) passenger_record = [[NSMutableDictionary alloc] init]; + if (contracts == nil) contracts = [[NSMutableArray alloc] init]; + if (contract_record == nil) contract_record = [[NSMutableDictionary alloc] init]; //specialCargo [specialCargo release]; specialCargo = [[dict oo_stringForKey:@"special_cargo"] copy]; - - // contracts - [contracts release]; - contracts = [[dict oo_arrayForKey:@"contracts"] mutableCopy]; - if (contracts == nil) contracts = [[NSMutableArray alloc] init]; - contract_record = [[dict oo_dictionaryForKey:@"contract_record"] mutableCopy]; - if (contract_record == nil) contract_record = [[NSMutableDictionary alloc] init]; // mission destinations missionDestinations = [[dict oo_arrayForKey:@"missionDestinations"] mutableCopy]; if (missionDestinations == nil) missionDestinations = [[NSMutableArray alloc] init]; - + // shipyard shipyard_record = [[dict oo_dictionaryForKey:@"shipyard_record"] mutableCopy]; if (shipyard_record == nil) shipyard_record = [[NSMutableDictionary alloc] init]; - + // Normalize cargo capacity unsigned original_hold_size = [UNIVERSE maxCargoForShip:[self shipDataKey]]; max_cargo = [dict oo_unsignedIntForKey:@"max_cargo" defaultValue:max_cargo]; @@ -895,7 +908,7 @@ static GLfloat sBaseMass = 0.0; ship_clock = [dict oo_doubleForKey:@"ship_clock" defaultValue:PLAYER_SHIP_CLOCK_START]; fps_check_time = ship_clock; - + // mission_variables [mission_variables release]; mission_variables = [[dict oo_dictionaryForKey:@"mission_variables"] mutableCopy]; @@ -995,7 +1008,7 @@ static GLfloat sBaseMass = 0.0; // restore subentities status [self deserializeShipSubEntitiesFrom:[dict oo_stringForKey:@"subentities_status"]]; - + // wormholes NSArray * whArray; whArray = [dict objectForKey:@"wormholes"]; @@ -1020,7 +1033,7 @@ static GLfloat sBaseMass = 0.0; // custom view no. if (_customViews != nil) _customViewIndex = [dict oo_unsignedIntForKey:@"custom_view_index"] % [_customViews count]; - + // trumble information [self setUpTrumbles]; [self setTrumbleValueFrom:[dict objectForKey:@"trumbles"]]; // if it doesn't exist we'll check user-defaults @@ -1078,7 +1091,7 @@ static GLfloat sBaseMass = 0.0; target_memory_index = 0; dockingReport = [[NSMutableString alloc] init]; - + [self initControls]; } @@ -1116,7 +1129,7 @@ static GLfloat sBaseMass = 0.0; // reset HUD & default commlog behaviour [UNIVERSE setAutoCommLog:YES]; [UNIVERSE setPermanentCommLog:NO]; - + [self switchHudTo:@"hud.plist"]; scanner_zoom_rate = 0.0f; @@ -1545,7 +1558,7 @@ static GLfloat sBaseMass = 0.0; [OOScriptTimer updateTimers]; UPDATE_STAGE(@"checkScriptsIfAppropriate"); [self checkScriptsIfAppropriate]; - + // deal with collisions UPDATE_STAGE(@"manageCollisions"); [self manageCollisions]; @@ -1668,7 +1681,7 @@ static bool minShieldLevelPercentageInitialised = false; shot_time = starboard_shot_time; break; } - + // cloaking device if ([self hasCloakingDevice] && cloaking_device_active) { @@ -1678,7 +1691,7 @@ static bool minShieldLevelPercentageInitialised = false; if (energy < CLOAKING_DEVICE_MIN_ENERGY) [self deactivateCloakingDevice]; } - + // military_jammer if ([self hasMilitaryJammer]) { @@ -1701,7 +1714,7 @@ static bool minShieldLevelPercentageInitialised = false; if (ecm_in_operation) { UPDATE_STAGE(@"updating ECM"); - + if (energy > 0.0) energy -= (float)(ECM_ENERGY_DRAIN_FACTOR * delta_t); // drain energy because of the ECM else @@ -1714,7 +1727,7 @@ static bool minShieldLevelPercentageInitialised = false; ecm_in_operation = NO; } } - + // Energy Banks and Shields // TODO: Remove case statement once we pick the best solution. switch(EnergyDistribution) @@ -1730,13 +1743,13 @@ static bool minShieldLevelPercentageInitialised = false; if (energy > maxEnergy) energy = maxEnergy; } - + // Recharge shields from energy banks float rechargeFwd = (float)([self shieldRechargeRate] * delta_t); float rechargeAft = rechargeFwd; float fwdMax = [self maxForwardShieldLevel]; float aftMax = [self maxAftShieldLevel]; - + if (forward_shield < fwdMax) { if (forward_shield + rechargeFwd > fwdMax) rechargeFwd = fwdMax - forward_shield; @@ -1761,18 +1774,18 @@ static bool minShieldLevelPercentageInitialised = false; */ { UPDATE_STAGE(@"updating energy and shield charges"); - + // 1. (Over)charge energy banks (will get normalised later) double energy_multiplier = 1.0 + 0.1 * [self installedEnergyUnitType]; // 1.8x recharge with normal energy unit, 2.6x with naval! energy += energy_recharge_rate * energy_multiplier * delta_t; - + // 2. Calculate shield recharge rates float fwdMax = [self maxForwardShieldLevel]; float aftMax = [self maxAftShieldLevel]; float shieldRecharge = [self shieldRechargeRate] * delta_t; float rechargeFwd = MIN(shieldRecharge, fwdMax - forward_shield); float rechargeAft = MIN(shieldRecharge, aftMax - aft_shield); - + // Note: we've simplified this a little, so if either shield is below // the critical threshold, we allocate all energy. Ideally we // would only allocate the full recharge to the critical shield, @@ -1784,7 +1797,7 @@ static bool minShieldLevelPercentageInitialised = false; float minEnergyBankLevel = [[UNIVERSE planetInfo] oo_floatForKey:@"shield_charge_energybank_threshold" defaultValue:0.25]; energyForShields = MAX(0.0, energy -0.1 - (maxEnergy * minEnergyBankLevel)); // NB: The - 0.1 ensures the energy value does not 'bounce' across the critical energy message and causes spurious energy-low warnings } - + if( forward_shield < aft_shield ) { rechargeFwd = MIN(rechargeFwd, energyForShields); @@ -1795,12 +1808,12 @@ static bool minShieldLevelPercentageInitialised = false; rechargeAft = MIN(rechargeAft, energyForShields); rechargeFwd = MIN(rechargeFwd, energyForShields - rechargeAft); } - + // 3. Recharge shields, drain banks, and clamp values forward_shield += rechargeFwd; aft_shield += rechargeAft; energy -= rechargeFwd + rechargeAft; - + forward_shield = OOClamp_0_max_f(forward_shield, fwdMax); aft_shield = OOClamp_0_max_f(aft_shield, aftMax); energy = OOClamp_0_max_f(energy, maxEnergy); @@ -1818,10 +1831,10 @@ static bool minShieldLevelPercentageInitialised = false; UPDATE_STAGE(@"updating energy and shield charges"); double energy_multiplier = 1.0 + 0.1 * [self installedEnergyUnitType]; // 1.8x recharge with normal energy unit, 2.6x with naval! float energyGenerated = energy_recharge_rate * energy_multiplier * delta_t; - + // 1. (Over)charge energy banks (will get normalised later) energy += energyGenerated; - + // 2. Calculate how much energy can be used for the shields #if defined(NDEBUG) // TODO - cache this value somewhere, or is it cheap enough to perform this lookup? @@ -1845,7 +1858,7 @@ static bool minShieldLevelPercentageInitialised = false; float recharge = [self shieldRechargeRate] * delta_t; float rechargeFwd = MIN(recharge, fwdMax - forward_shield); float rechargeAft = MIN(recharge, aftMax - aft_shield); - + if( (rechargeFwd == rechargeAft) || ((rechargeFwd > energyForShields) && (rechargeAft > energyForShields)) ) { @@ -1860,13 +1873,13 @@ static bool minShieldLevelPercentageInitialised = false; { rechargeFwd = MIN(rechargeFwd, energyForShields - rechargeAft); } - + forward_shield += rechargeFwd; aft_shield += rechargeAft; - + energy -= rechargeFwd; energy -= rechargeAft; - + forward_shield = OOClamp_0_max_f(forward_shield, fwdMax); aft_shield = OOClamp_0_max_f(aft_shield, aftMax); } @@ -1874,7 +1887,7 @@ static bool minShieldLevelPercentageInitialised = false; } break; } - + if (sun) { UPDATE_STAGE(@"updating sun effects"); @@ -1924,7 +1937,7 @@ static bool minShieldLevelPercentageInitialised = false; if (ship_temperature > SHIP_MIN_CABIN_TEMP) ship_temperature += (float)((external_temp - heatThreshold - ship_temperature) * SHIP_COOLING_FACTOR * deltaInsulation); } - + if (ship_temperature > SHIP_MAX_CABIN_TEMP) [self takeHeatDamage: delta_t * ship_temperature]; } @@ -1996,12 +2009,12 @@ static bool minShieldLevelPercentageInitialised = false; flightSpeed += (float)(speed_delta * delta_t * HYPERSPEED_FACTOR); if (flightSpeed > maxFlightSpeed * HYPERSPEED_FACTOR) flightSpeed = (float)(maxFlightSpeed * HYPERSPEED_FACTOR); - + // check for mass lock hyperspeed_locked = [self massLocked]; // check for mass lock & external temperature? //hyperspeed_locked = flightSpeed * air_friction > 40.0f+(ship_temperature - external_temp ) * SHIP_COOLING_FACTOR || [self massLocked]; - + if (hyperspeed_locked) { [self playJumpMassLocked]; @@ -2092,7 +2105,7 @@ static bool minShieldLevelPercentageInitialised = false; [UNIVERSE addMessage:DESC(@"target-lost") forCount:3.0]; [self removeTarget:primeTarget]; } - + // update subentities UPDATE_STAGE(@"updating subentities"); totalBoundingBox = boundingBox; // reset totalBoundingBox diff --git a/src/Core/Entities/PlayerEntityContracts.m b/src/Core/Entities/PlayerEntityContracts.m index 17f8fb95..a1f26441 100644 --- a/src/Core/Entities/PlayerEntityContracts.m +++ b/src/Core/Entities/PlayerEntityContracts.m @@ -1016,9 +1016,15 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh // GUI stuff { - unsigned i = 0; + NSArray* cargoManifest = [self cargoList]; + NSArray* missionsManifest = [self missionsList]; + NSArray* passengerManifest = [self passengerList]; + NSArray* contractManifest = [self contractList]; - unsigned n_manifest_rows = 8; + unsigned i = 0; + unsigned max_rows = 20; + unsigned manifest_count = [cargoManifest count]; + unsigned n_cargo_rows = (manifest_count + 1)/2; OOGUIRow cargo_row = 2; OOGUIRow passenger_row = 2; OOGUIRow contracts_row = 2; @@ -1029,11 +1035,6 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh tab_stops[1] = 256; [gui setTabStops:tab_stops]; - NSArray* cargoManifest = [self cargoList]; - NSArray* passengerManifest = [self passengerList]; - NSArray* contractManifest = [self contractList]; - NSArray* missionsManifest = [self missionsList]; - unsigned rating = 0; unsigned kills[8] = { 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0200, 0x0A00, 0x1900 }; while ((rating < 8)&&(kills[rating] <= ship_kills)) @@ -1041,85 +1042,110 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh rating ++; } + // Cargo Manifest current_cargo = [self cargoQuantityOnBoard]; [gui clearAndKeepBackground:!guiChanged]; [gui setTitle:DESC(@"manifest-title")]; [gui setText:[NSString stringWithFormat:DESC(@"manifest-cargo-d-d"), current_cargo, max_cargo] forRow:cargo_row - 1]; - [gui setText:DESC(@"manifest-none") forRow:cargo_row]; [gui setColor:[OOColor yellowColor] forRow:cargo_row - 1]; - [gui setColor:[OOColor greenColor] forRow:cargo_row]; - if ([cargoManifest count] > 0) + if (manifest_count > 0) { - for (i = 0; i < n_manifest_rows; i++) + for (i = 0; i < n_cargo_rows; i++) { NSMutableArray* row_info = [NSMutableArray arrayWithCapacity:2]; - if (i < [cargoManifest count]) + if (i < manifest_count) [row_info addObject:[cargoManifest objectAtIndex:i]]; else [row_info addObject:@""]; - if (i + n_manifest_rows < [cargoManifest count]) - [row_info addObject:[cargoManifest objectAtIndex:i + n_manifest_rows]]; + if (i + n_cargo_rows < manifest_count) + [row_info addObject:[cargoManifest objectAtIndex:i + n_cargo_rows]]; else [row_info addObject:@""]; [gui setArray:(NSArray *)row_info forRow:cargo_row + i]; [gui setColor:[OOColor greenColor] forRow:cargo_row + i]; } } - - if ([cargoManifest count] < n_manifest_rows) - passenger_row = cargo_row + [cargoManifest count] + 2; else - passenger_row = cargo_row + n_manifest_rows + 2; - - [gui setText:[NSString stringWithFormat:DESC(@"manifest-passengers-d-d"), [passengerManifest count], max_passengers] forRow:passenger_row - 1]; - [gui setText:DESC(@"manifest-none") forRow:passenger_row]; - [gui setColor:[OOColor yellowColor] forRow:passenger_row - 1]; - [gui setColor:[OOColor greenColor] forRow:passenger_row]; - - if ([passengerManifest count] > 0) { - for (i = 0; i < [passengerManifest count]; i++) - { - [gui setText:(NSString*)[passengerManifest objectAtIndex:i] forRow:passenger_row + i]; - [gui setColor:[OOColor greenColor] forRow:passenger_row + i]; - } - } - - contracts_row = passenger_row + [passengerManifest count] + 2; - - [gui setText:DESC(@"manifest-contracts") forRow:contracts_row - 1]; - [gui setText:DESC(@"manifest-none") forRow:contracts_row]; - [gui setColor:[OOColor yellowColor] forRow:contracts_row - 1]; - [gui setColor:[OOColor greenColor] forRow:contracts_row]; - - if ([contractManifest count] > 0) - { - for (i = 0; i < [contractManifest count]; i++) - { - [gui setText:(NSString*)[contractManifest objectAtIndex:i] forRow:contracts_row + i]; - [gui setColor:[OOColor greenColor] forRow:contracts_row + i]; - } + [gui setText:DESC(@"manifest-none") forRow:cargo_row]; + [gui setColor:[OOColor greenColor] forRow:cargo_row]; + n_cargo_rows=1; } - if ([missionsManifest count] > 0) + passenger_row = cargo_row + n_cargo_rows + 1; + + // Passengers Manifest + manifest_count = [passengerManifest count]; + + if (passenger_row <= max_rows) + { + [gui setText:[NSString stringWithFormat:DESC(@"manifest-passengers-d-d"), manifest_count, max_passengers] forRow:passenger_row - 1]; + [gui setColor:[OOColor yellowColor] forRow:passenger_row - 1]; + if (manifest_count > 0) + { + for (i = 0; i < manifest_count && (passenger_row + i < max_rows); i++) + { + [gui setText:(NSString*)[passengerManifest objectAtIndex:i] forRow:passenger_row + i]; + [gui setColor:[OOColor greenColor] forRow:passenger_row + i]; + } + } + else + { + [gui setText:DESC(@"manifest-none") forRow:passenger_row]; + [gui setColor:[OOColor greenColor] forRow:passenger_row]; + manifest_count = 1; + } + } + contracts_row = passenger_row + manifest_count + 1; + + // Contracts Manifest + manifest_count = [contractManifest count]; + if (contracts_row <= max_rows) { - missions_row = contracts_row + [contractManifest count] + 2; + [gui setText:DESC(@"manifest-contracts") forRow:contracts_row - 1]; + [gui setColor:[OOColor yellowColor] forRow:contracts_row - 1]; + if (manifest_count > 0) + { + for (i = 0; i < manifest_count && (contracts_row + i < max_rows); i++) + { + [gui setText:(NSString*)[contractManifest objectAtIndex:i] forRow:contracts_row + i]; + [gui setColor:[OOColor greenColor] forRow:contracts_row + i]; + } + } + else + { + [gui setText:DESC(@"manifest-none") forRow:contracts_row]; + [gui setColor:[OOColor greenColor] forRow:contracts_row]; + manifest_count = 1; + } + } + missions_row = contracts_row + manifest_count + 1; + + // Missions Manifest + manifest_count = [missionsManifest count]; + + if (missions_row <= max_rows && manifest_count > 0) + { [gui setText:DESC(@"manifest-missions") forRow:missions_row - 1]; [gui setColor:[OOColor yellowColor] forRow:missions_row - 1]; - if ([missionsManifest count] > 0) + for (i = 0; i < manifest_count && (missions_row + i < max_rows); i++) { - for (i = 0; i < [missionsManifest count]; i++) - { - [gui setText:(NSString*)[missionsManifest objectAtIndex:i] forRow:missions_row + i]; - [gui setColor:[OOColor greenColor] forRow:missions_row + i]; - } + [gui setText:(NSString*)[missionsManifest objectAtIndex:i] forRow:missions_row + i]; + [gui setColor:[OOColor greenColor] forRow:missions_row + i]; } } + + if (missions_row + manifest_count >= max_rows ) + { + [gui setText:@" . . ." forRow:max_rows]; + [gui setColor:[OOColor greenColor] forRow:max_rows]; + } + [gui setShowTextCursor:NO]; } /* ends */