• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Fixed No Money for Selling Ship Upgrades

Hylie Pistof

Curmudgeon
QA Tester
Storm Modder
Pirate Legend
When stripping a ship before selling or berthing it I get no money for items sold and when I do sell it it gets a reduced price.
 
I don't understand your ship price story, I'm afraid.
Price is lower for a ship you sell if you sell the cargo first?
That makes sense, no? Selling a ship automatically sells the cargo still on board.
 
I did not mention cargo at all as I was talking about things like sails, and copper bottoms, and tall masts.
 
Oh, you meant upgrades. Sorry, your post said "items" which left me guessing.

Strange though; pretty sure there IS supposed to be some value for selling upgrades.
 
There used to be.
I made a separate issue from this so we won't forget to look at it.

Do you happen to have a save where you've got a ship with upgrades that sell for zero gold?

A quick look through the code doesn't show me anything obviously wrong, though I did mess around with that a few months back.

When you manually remove an upgrade, this code gets called:
Code:
int UnApplyTun (int _idx, string _improvement)
{
   [...]
   cost = GetCostTun(_idx, _improvement, PRICE_TYPE_SELL)/10;
   [...]
   if (cost > 0) { AddMoneytoCharacter(char, cost); }
   return 0;
}
So it is meant to take the "sale price", which takes into account your skills and abilities. And then you just get 10% of the value, which isn't much, but more than nothing.

When selling a ship, a similar piece of code is executed to give you the same amount of money back:
Code:
  //Levis take upgrades into account:
   string attributeName;
   int idx=0;
   for (int i = 0; i < SHIPUPGRADES_QUANTITY; i++) {
     idx++;
     attributeName = "pic" + idx;
     string upgrade = GetShipUpgradeID(i);
     if (cn >= 0 && CheckTun(cn, upgrade) == true) {
       price += makeint(GetCostTun(cn, upgrade, PRICE_TYPE_SELL)/10); //If an upgrade is applied, you get a percentage of the real price. This can be max of 10%
     }
   }

When berthing, it uses a different function (that for some reason is virtually identical to the normal function).
Apart from the time being zero, the only cost-related difference is this:
Code:
if (cost > 0) { AddMoneytoCharacter(char, cost); }
^ For normal selling of upgrade.

Code:
  if (cost > 0) {Characters[GetMainCharacterIndex()].Money = sti(Characters[GetMainCharacterIndex()].Money) + cost; }
^ For selling of upgrade when berthing.

So if I understand correctly:
- Selling upgrade manually: Get money OK
- Selling upgrade as part of whole ship sale: Don't get the money
- Selling upgrade as part of ship berthing: Don't get the money

Did I get that right?

If anything, I'd expect the NORMAL selling to not work right.
If I see that code correctly, the money might end up being added to a COMPANION CHARACTER instead of to the player, if you sell upgrades on a companion ship.
 
No that is not correct.

Sell upgrade manually = no money

sell ship with upgrades = more money

sell ship without upgrades = less money

I used to strip a ship of upgrades before berthing and get the money just because. It was supposed to work either way but I never trusted the game to work properly.

I have not berthed a ship in this game.

No, I cleaned out all the old saves last night.
 
Selling the upgrades and then the ship should give you the same money as selling the ship with upgrades.
So if you get less money for selling the ship without upgrades, that sounds right to me.

As for selling the upgrades manually, did you sell the upgrades on your own ship or a companion?
If a companion, could you check if the companion got the money?
Based on what I saw from the code, that does seem plausible.
 
@pedrwyth: I hope post #6 above makes sense to you.
If possible, it would be nice also to merge the 'UnApplyTun' and 'UnApplyTunBerth' functions.
It looks like the only difference is the length of time that passes, so it should be possible to get rid of some double coding there. :cheers
 
Mind that interface files are only loaded when they are used. And the unapplytun is in a interface file now I think. So you need to move it to another file if you want to use it outside the interface file too. Altough I'm not 100% sure, could be I moved it outside the interface file already in the past.
 
:aar Checked out the behaviour of this - currently:-

If you sell upgrades off your ship you get the money (sort of 10% of cost but a bit out in one of three upgrades I sold) which is roughly the reduction in sale price of ship with or without upgrades. Near enough not to worry too much but I will look to see if I can see how the variation arose.

If you sell a companion ship upgrade you get nothing and neither does the companion get an increase in personal finance (crew money is for the whole squadron but doesn't increase either). So as @Hylie Pistof reported this isn't working and your money goes into a black hole. :eek: I will try selling Pchar upgrades then swapping ships and doing the next in sequence which theoretically should behave correctly (not a solution just another check).

Berthing (for laying up) you get the 10%. However low cargo levels (just a few food and rum cargo) remuneration can be about 100 better than the store price but higher levels (I tried 200,000 worth of gold) are spot on - so again some minor variance to look for.:unsure

Finally when you remove the upgrades (by berthing at least - didn't notice on manual sale) they disappear from the little boxes in the ship interface but the ticks in the shipyard upgrades interface remain (and can include other upgrades too when I did two ships berthing more were shown ticked than had been installed on the second ship). I guess this is just a minor interface presentation hiccup and sailing behaviour would be without upgrades but don't really know how to test this. (Could it be a case of dumping the attributes??) I presume they have "gone" because you can't sell them again and only install appears. The interface does behave to let you re-install them OK too.

Now to start looking at the code....
 
@pedrwyth: I hope post #6 above makes sense to you.
If possible, it would be nice also to merge the 'UnApplyTun' and 'UnApplyTunBerth' functions.
It looks like the only difference is the length of time that passes, so it should be possible to get rid of some double coding there. :cheers
Indeed changing the cost line in the manual 'UnApplyTun' to that in UnApplyTunBerth did sort out the reported lack of remuneration for a companion ship manual sale of upgrades. So the two functions were even more alike. I have added a bool variable (berth) into the function call to allow time to be ignored when berthing so they can now use the same function call.:)

The minor price deviations from 10% were because copper plating takes into account a player cost factor where most of the other upgrades don't.

The ticking of the wrong upgrades is because when you first open the upgrades screen it is showing pchar ship upgrade ticks even if you have selected a different companion ship prior to opening the upgrade screen - it resets correctly if you move from one ship to another and as I said before does allow the correct re-installs anyway so a very minor interface display hiccup. Does it want a bug report for that (I don't really know where to start looking for the problem and I would think it's a quick fix if familiar with the interface functionality).

The one remaining problem (I hope) is that berthing does remove un-removeable upgrades - oops :eek:- So I have limited the call in stripUpgradesBerth to stop at six so you don't get money (or reduced performance) for the un-removeable ones. However I think the problem seems to be compounded since the berthing routines (kam_shipberthing) don't seem to store attributes for those upgrades (if I haven't misread the code) so they are lost anyway on relaunch (although my block at 5th upgrade means they will still be functional but unseen) EDIT No they won't it's a "new" ship without those attributes!END EDIT. So I think adding the attributes into what is stored (and retrieved) would resolve it - if I can sort out a way that doesn't crash if the attributes don't exist (I'm not sure if using the initialisation - setting them to "" and 0 which I see in KBroutines applied if not they are not there whilst berthing will do the trick to ensure no problems on relaunch).
 
Last edited:
You're don't an awesome job again, @pedrwyth! :cheers

I suppose when I merge your final files, I can have a quick look at those tick marks.
Or maybe @Levis would be able to find the solution very quickly too?

The reason for removing upgrades upon berthing may very well have been because they aren't stored properly.

If you want code that works even when attributes don't exist, use CheckAttribute and GetAttribute .
Hopefully that helps.

Anyway, thanks for looking into it. :cheers
 
Could you make a new bugreport for the things you mentioned? I could look into the interface problem next week probably
 
Could you make a new bugreport for the things you mentioned? I could look into the interface problem next week probably
Ok made a bug report for the minor graphical glitch.

Looked at the upgrade loss on berthing and it is slightly more complex since as well as the attributes the changed stats and increased cannon calibre etc needs storing. Probably not worth the effort and extra coding. I have put a note elsewhere for the future (I might follow it up if I get really bored).

So here are the two files for fixing the loss of payment for companion upgrade removal and merging the two separate functions (I have left the code for you to remove if you are happy with it).
 

Attachments

  • ship upgrade removal.7z
    29.2 KB · Views: 83
@pedrwyth: "not sure why it should only be 1/10th time to remove??"
^ I assume because maybe the original modder figured that removing goes faster than installing?
That is all I can think of anyway....
 
@pedrwyth: "not sure why it should only be 1/10th time to remove??"
^ I assume because maybe the original modder figured that removing goes faster than installing?
That is all I can think of anyway....

Yeh not a problem - but 1/10th of the time and 1/10th of the money looked a bit too neat of a correlation especially seeing them following on on the next line, plus thinking of sails and cannons I thought pretty much the same time on and off since they are replacements BUT if you factor in ordering them and getting them made it makes more sense. I suspect copper sheeting however may be pretty much the same on and off (plus making good) but it it doesn't really matter.
 
Back
Top