Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sell option. #172

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Resources/Config/descriptions.plist
Original file line number Diff line number Diff line change
Expand Up @@ -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 ";
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Entities/PlayerEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 37 additions & 2 deletions src/Core/Entities/PlayerEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)];

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand Down
6 changes: 5 additions & 1 deletion src/Core/Entities/ShipEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/Core/GuiDisplayGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down