diff --git a/Resources/Config/descriptions.plist b/Resources/Config/descriptions.plist index d19cfdf49..686b64a5b 100644 --- a/Resources/Config/descriptions.plist +++ b/Resources/Config/descriptions.plist @@ -1656,9 +1656,12 @@ "equip-cash-value" = "Cash: [credits|dcr]."; "equip-no-equipment-available-for-purchase" = "No equipment available for purchase."; "equip-repair-@" = " Repair:%@"; + "equip-sell-@" = " Sell:%@"; + "upgradeinfo-@-price-is-for-refunding" = "%@ (Price will be refunded for the existing system)."; "upgradeinfo-@-price-is-for-repairing" = "%@ (Price is for repairing the existing system)."; "@-will-replace-other-energy" ="%@ (The installed energy recharge unit will be removed and sold for scrap)."; "upgradeinfo-@-weight-d-of-equipment" = "%@\nTakes up %dt of cargo space."; + "upgradeinfo-@-frees-weight-d-of-equipment" = "%@\nFrees up %dt of cargo space."; "forward-facing-string" = " Forward "; "aft-facing-string" = " Aft "; "port-facing-string" = " Port "; diff --git a/src/Core/Entities/PlayerEntity.h b/src/Core/Entities/PlayerEntity.h index 8d96c5e33..5dbbd8366 100644 --- a/src/Core/Entities/PlayerEntity.h +++ b/src/Core/Entities/PlayerEntity.h @@ -1033,6 +1033,9 @@ typedef enum - (OOSpeechSettings) isSpeechOn; +- (BOOL) isEquipmentSellOption:(NSString *)equipmentKey; +- (BOOL) canAddEquipmentSellOption:(NSString *)equipmentKey; + - (void) addEquipmentFromCollection:(id)equipment; // equipment may be an array, a set, a dictionary whose values are all YES, or a string. - (void) getFined; diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index dfb3acfd3..bb35d4481 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -8803,6 +8803,18 @@ - (void) setGuiToEquipShipScreen:(int)skipParam selectingFacingFor:(NSString *)e } + // is this item a sell option? + if ([self isEquipmentSellOption:eqKey]) + { + //desc = [NSString stringWithFormat:DESC(@"equip-sell-@"), desc]; //Uncomment to add "equip sell" string ("Sell: ") at the beginning to the entry. + if (installTime == 0) + { + installTime = 600 + price; + } + [gui setColor:[gui colorFromSetting:kGuiEquipmentSellColor defaultValue:[OOColor orangeColor]] forRow:row]; + + } + NSString *timeString = [UNIVERSE shortTimeDescription:installTime]; NSString *priceString = [NSString stringWithFormat:@" %@ ", OOCredits(price)]; @@ -8990,7 +9002,13 @@ - (void) showInformationForSelectedUpgradeWithFormatString:(NSString *)formatStr { if([eqKey hasSuffix:@"ENERGY_UNIT"] && ([self hasEquipmentItem:@"EQ_ENERGY_UNIT_DAMAGED"] || [self hasEquipmentItem:@"EQ_ENERGY_UNIT"] || [self hasEquipmentItem:@"EQ_NAVAL_ENERGY_UNIT_DAMAGED"])) desc = [NSString stringWithFormat:DESC(@"@-will-replace-other-energy"), desc]; - if (weight > 0) desc = [NSString stringWithFormat:DESC(@"upgradeinfo-@-weight-d-of-equipment"), desc, weight]; + + // In case the menu entry is for selling items: + if ([self isEquipmentSellOption:eqKey]) { + //desc = [NSString stringWithFormat:DESC(@"upgradeinfo-@-price-is-for-refunding"), desc]; //Uncomment to enable "price is for refunding" infotext at the end of the description text. + if (weight > 0) desc = [NSString stringWithFormat:DESC(@"upgradeinfo-@-frees-weight-d-of-equipment"), desc, weight]; + } + else if (weight > 0) desc = [NSString stringWithFormat:DESC(@"upgradeinfo-@-weight-d-of-equipment"), desc, weight]; } if (formatString) desc = [NSString stringWithFormat:formatString, desc]; [gui addLongText:desc startingAtRow:GUI_ROW_EQUIPMENT_DETAIL align:GUI_ALIGN_LEFT]; @@ -9713,7 +9731,7 @@ - (BOOL) tryBuyingItem:(NSString *)eqKey price *= priceFactor; // increased prices at some stations - if (price > credits) + if (price > credits && ![self isEquipmentSellOption:eqKey]) { return NO; } @@ -9913,6 +9931,10 @@ - (BOOL) tryBuyingItem:(NSString *)eqKey if ([self canAddEquipment:eqKey inContext:@"purchase"]) { + if ([self isEquipmentSellOption:eqKey]) { + credits += price; + return YES; + } credits -= price; [self addEquipmentItem:eqKey withValidation:NO inContext:@"purchase"]; // no need to validate twice. if (isRepair) @@ -10863,6 +10885,19 @@ - (BOOL) canAddEquipment:(NSString *)equipmentKey inContext:(NSString *)context return YES; } +- (BOOL) isEquipmentSellOption:(NSString *)equipmentKey +{ + return [equipmentKey hasSuffix:@"_SELL"]; +} + +- (BOOL) canAddEquipmentSellOption:(NSString *)equipmentKey +{ + if ([equipmentKey hasSuffix:@"_SELL"]) { + equipmentKey = [equipmentKey substringToIndex:[equipmentKey length] - [@"_SELL" length]]; + return [self hasEquipmentItem:equipmentKey]; + } + return false; +} - (BOOL) addEquipmentItem:(NSString *)equipmentKey inContext:(NSString *)context { diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index 25facaa44..9cb31fe2a 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -3403,7 +3403,6 @@ - (BOOL) equipmentValidToAdd:(NSString *)equipmentKey whileLoading:(BOOL)loading // while loading, we mainly need to catch changes when the installed oxps set has changed since saving. if ([eqType requiresEmptyPylon] && [self missileCount] >= [self missileCapacity] && !loading) return NO; if ([eqType requiresMountedPylon] && [self missileCount] == 0 && !loading) return NO; - if ([self availableCargoSpace] < [eqType requiredCargoSpace] && !validationForDamagedEquipment && !loading) return NO; if ([eqType requiresEquipment] != nil && ![self hasAllEquipment:[eqType requiresEquipment] includeWeapons:YES whileLoading:loading]) return NO; if ([eqType requiresAnyEquipment] != nil && ![self hasEquipmentItem:[eqType requiresAnyEquipment] includeWeapons:YES whileLoading:loading]) return NO; if ([eqType incompatibleEquipment] != nil && [self hasEquipmentItem:[eqType incompatibleEquipment] includeWeapons:YES whileLoading:loading]) return NO; @@ -3412,6 +3411,11 @@ - (BOOL) equipmentValidToAdd:(NSString *)equipmentKey whileLoading:(BOOL)loading if ([eqType requiresFreePassengerBerth] && [self passengerCount] >= [self passengerCapacity]) return NO; if ([eqType requiresFullFuel] && [self fuel] < [self fuelCapacity] && !loading) return NO; if ([eqType requiresNonFullFuel] && [self fuel] >= [self fuelCapacity] && !loading) return NO; + + // if the "equipment" is only a standin for a sell option, the weight isn't accually subtracted as it won't be added to the ship. + if (![equipmentKey hasSuffix:@"_SELL"]) { + if ([self availableCargoSpace] < [eqType requiredCargoSpace] && !validationForDamagedEquipment && !loading) return NO; + } if (!loading) { diff --git a/src/Core/GuiDisplayGen.h b/src/Core/GuiDisplayGen.h index abb4aa522..8d5181458 100644 --- a/src/Core/GuiDisplayGen.h +++ b/src/Core/GuiDisplayGen.h @@ -75,6 +75,7 @@ static NSString * const kGuiEquipmentUnavailableColor = @"equipment_unavailable_ static NSString * const kGuiEquipmentScrollColor = @"equipment_scroll_color"; static NSString * const kGuiEquipmentOptionColor = @"equipment_option_color"; static NSString * const kGuiEquipmentRepairColor = @"equipment_repair_color"; +static NSString * const kGuiEquipmentSellColor = @"equipment_sell_color"; static NSString * const kGuiEquipmentDescriptionColor = @"equipment_description_color"; static NSString * const kGuiEquipmentLaserColor = @"equipment_laser_color"; static NSString * const kGuiEquipmentLaserFittedColor = @"equipment_laser_fitted_color";