Endless-Sky-Pirate-Campaign / endless-sky

Space exploration, trading, and combat game.
http://endless-sky.github.io/
GNU General Public License v3.0
2 stars 1 forks source link

feature : varying outfit prices at outfitters #11

Closed Hurleveur closed 2 years ago

Hurleveur commented 2 years ago

Feature: This PR implements the feature request detailed and discussed in the discord.

Feature Details

All outfits can now have varying prices and sell types, with the highest price taking priority and hidden > import > default when there are conflicts. mapOutfitterPanel now has varying colors depending on the prices, same for shipyardpanel and there is a legend ! The prices for ship vary depending on where they are landed (when not on a planet it is based on default outfit price), to buy/sell them, the right % of depreciation is also displayed, even for things you have not bought.

UI Screenshots

tradepricecolors This is an example with prices going from 1000 to 20000 with the laser rifle. note : I've changed the legend to be even more representative, now the second number shown in the legend is right between the first and the third.

Usage Examples

outfitter "Planet Name"
  "Laser Rifle"
  "Gun" 200
  hidden
    "Drugs"
    "Stuff" 500
  import
    "liquor" 200
    "stolen part"

Import and hidden mean you can only sell them, except that you won't see the hidden things except if you yourself have some. The new prices will override the base ones, and if multiple prices are specified for one place the highest one will be taken normally, except if one of the two is hidden/import that take priority respectively over import and base/base. Now to get to the real nice stuff : mapOutfitterPanel, import will have a little (import) after the price and same for hidden except you won't see it if you don't have at least one of that outfit stored at that planet.

Note : you can also not have the outfits under categories like this, but I would like everything to follow this principle in the sales.txt and such files so there is no repetition. The other way is meant to add a few outfits of different categories like this : "outfitname" 500 "import" but you have to specify the price if you want to give a special sell type.

By default hidden items will not show on the mapOutfitterPanel, however if you want them to, you just need to store one of that hidden outfit on the planet where you want to see it, you will then see it's price for that particular place where it is hidden and stored, from anywhere, on the map.

Testing Done

I tested everything I could think off, loading different sales, putting different types, prices of outfits. The thing that needs to be tested more is what takes priority over what in the txt, to check if it corresponds to what was asked.

Performance Impact

Pretty much not any but I'll develop a bit : I used a map for the extension of the outfits; OutfitSale, like the std::set of Sale it uses pointers to Outfits but here it links them to Sold that contains the special prices, and selling conditions. Now all outfits are contained within OutfitSale instead of Sale, but outfitsale can be converted into Sale. It is not a template, however but that can be changed easily if needed later. I used enums and another map in Sold to have the best performance when comparing them, which happens quite a lot when they get combined into a big OutfitSale containing all available outfits. I did all I could think off to change as little code as possible whilst having the best performance possible. This means that theoretically, nothing changes for performances except when in shipyards because the prices need to be calculated according to local outfit prices, but I am pretty sure it could not have been done a more optimised way. (same for the map, it has to be calculated for each system)

NOTE : once this PR makes it into main game, create a pr to high dpi to add the new image (that is just one part of the planet and orbits image)

quyykk commented 2 years ago

Also please add any new files to the CodeBlocks project :)