• 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!

broken merchant

Hylie Pistof

Curmudgeon
QA Tester
Storm Modder
Pirate Legend
I just ran into a problem that I have not seen before. I loaded up on goods at Sao Jorge and sailed to Willemstad. Everything went normally until it came to trading with the merchant. Buying and selling items works, but anything having to do with the ships causes a ctd. When I try to sell cargo it crashes when I click on the ship icon. Asking for a trade mission gets a ctd. I have never seen a "sqrt" before, but that is what is causing the problem. Repeatedly going back to a previous save does not fix it. Any ideas?

addendum: This appears to be a ship related thing. I just went to the shipyard and all was well until it came to looking at the ships.

addy2: It appears to be a Willemstad thing. I sailed to Kralendijk and everything worked normally. Then went back to Willemstad and......ctd.
 
sqrt is "square root". It's trying to take the square root of a negative value for whatever strange reason.
 
Is there any way to trace this down and repair it? Otherwise Willemstad is as good as gone. Up to this point all islands have worked properly.
 
I got a scare when this happened at San Juan also. But when replayed, it worked ok.
 
Have you got any idea if this always happens or just sometimes? Have you seen any negative values in interfaces anywhere?

We could put a simple abs() in that line of code to ensure it never ends up negative.
That should solve the CTD, but could still potentially cause bizarre issues since it doesn't solve the reason for the negative value appearing.
That'd be harder to track down.
 
Every time I sail past Willemstad I stop and try it. Ctd every time so far.

I have 2 ships berthed at San Juan, which is why I got scared. Berthing and launching ships is expensive and a merchant is needed to stock the ship.

I have not seen anything odd. I had not been to Willemstad for a while, but knew its economy is really struggling. There was so little of everything that they could not even buy Care packages, where I was selling goods at a loss just to get them going again. I have since been to Tortuga and Turks, 2 islands I have not visited in a long time, and they are fine.

I just remembered that San Juan had just had a bad fire, and they didn't have much stock. Lots of money but no goods. :shrug

Two hours later: It happened again at St. Pierre. I went there on a trade mission and sold the cargo, repaired the ships, then spent so much time upgrading swords that I had to go buy more food and rum, then went back and finished upgrading swords. Then went looking for a trade mission. Instacrash! And it was "sqrt". :facepalm Now I get to do all of those swords again.............. :rumgone
 
Have you got any idea if this always happens or just sometimes? Have you seen any negative values in interfaces anywhere?

We could put a simple abs() in that line of code to ensure it never ends up negative.
That should solve the CTD, but could still potentially cause bizarre issues since it doesn't solve the reason for the negative value appearing.
That'd be harder to track down.

How does that "abs()" fit in exactly? The game is becoming unplayable now. It's ctding everywhere.
 
Seems the problem happens here:
Code:
float pow2(float num, float exp) // supports exponents of less than one via sqrt and a loop. Pure math, woohoo!
{
if(exp == 1.0) return num; // NK 05-03-30 add this check
if(exp > 1.0) return pow(num, exp);
int sqrtx = 0;
while(exp < 1.0)
{
exp *= 2;
sqrtx++;
}
num = pow(num, exp);
for(int i = 0; i < sqrtx; i++)
{
num = sqrt(num);
}
return num;
}
We could stick the abs in there as such:
Code:
float pow2(float num, float exp) // supports exponents of less than one via sqrt and a loop. Pure math, woohoo!
{
if(exp == 1.0) return num; // NK 05-03-30 add this check
if(exp > 1.0) return pow(num, exp);
int sqrtx = 0;
while(exp < 1.0)
{
exp *= 2;
sqrtx++;
}
num = pow(num, exp);
for(int i = 0; i < sqrtx; i++)
{
num = sqrt(abs(num)); // PB: No negative values
}
return num;
}
However, I have NO idea what kind of effects that is going to have. I have also no clue where that function is being called and why it's getting a negative value somehow. :modding
 
Thank you, I will try it soonest.

I want to keep this game going because with my rank I can get the large ships I'm working on easily. Starting a new game would waste time, plus I have ships berthed all over the place waiting to get worked on.

edit: So far, so good. The game would stall in the stores and shipyards every time a ship was selected for trade or repairs before. That is gone and POTC is moving very fast compared to before.
 
keep an eye out for the possibility that the lag might be gone because it's now skipping something we don't want to be skipped.
 
float pow2 -- introduced in Build 11 update 2

From Neew Horizons Tutorials & History.pdf

04-09-06 upd2
KAM - add general and worldmap pages to reconfigure controls
NK - fixed PRS3 bug in iface\ship.c
NK - Added new stuff to PRS3. Now you can do random stat mods without using nation multipliers (do not set refShip.unique but do set refShip.NoNatStatMod = true). Plus, nation from ship will override passed nation for SetRandomStatsToShip (though you can change a #define to make this an frnd() chance...)
NK - I had the wrong rev of KAM_Shipberthing_ship.c Fixed now
NK - fixed set dialog defaults (i.e. default address form) so it checks sex instead of ID.
NK - added float pow2(float num, float exp); this allows for <1.0 exponents (but slowly, because it's non-native and uses multiple sqrt()s in a for loop)
NK - added GetCharacterReputation(ref chr); use this rather than a direct sti(chr.reputation) because it supports chr.reputation == "none" (as many default chars have that set).
NK - tweaked GetFame() if nation passed is PIRATE, to check all ranks and crew share ratio.


float pow2 -- appears to be used in :-

initItems.c
AIship.c
LAi_fightparams.c
items_utilite.c
Towntable,c
StoreUtilite.c

:shrug
 
i guess it's designed to use values between 1 and 0, but was never designed to stop at 0 when counting down. the coder just assumed noone would reach the point where it could go below 0.
 
All I know is that in sailing, fighting on land and at sea, and trading with merchants and shipwrights the game is running smooth and fast. :keith


I got a scare at the Philipsburg shipyard when it hung for 15 seconds or so, and it ctd'ed during a boarding battle once. I don't know if the boarding ctd is related or not.


Edit: I finally made it to Willemstad where this started, but I was too late. The economy had collapsed and the merchant had no money. After buying what I could I decided to sell him some linen. Normally when a merchant doesn't have the money to buy all of a commodity, he buys what he can and leaves the rest. Not this time! He bought it all and went over 13,000 Piasters in the hole! :8q I had to go to the shipyard and upgrade a ship to get them out of hock. The game was lagging badly at every transaction until then too. So this fix isn't perfect, but it is far better than the alternative. :nerbz
 
A possible exploit is a small price to pay for getting the merchants back.

There is one other thing though. I went back to Willemstad again and there were no goods for sale at all. Zero amounts, except for the linen I had earlier sold him. It was still there untouched and it could be neither be bought or sold. He had some money so I sold him some sugar and the "buy" and "sell" buttons stayed grayed out. I hope he starts working again.
 
Willemstad is still in trouble. The street mechants have money and seem to be recovering, but the main store is destitute. No cash at all the last three visits. There are a few items for sail now, so maybe he will recover too. He did not go into negative numbers when buying from this time also.
 
Willemstad is coming back! :shoot:

Every time I stopped there the merchant had 0 money. Then I stopped there with a fleet of badly shot up ships and spent some serious money at the shipyard. The English can be tough opponents.
thpirateshipff.gif



Then the next two times i have stopped there the merchant has money and now he even has trade goods. :j2

So Pieter, your change has made a big difference and can only be a bad thing for that one colony, and only until it recovers. :2up
 
Sounds like we'd better keep it; at least it's not CRASHING, even though it doesn't quite behave sensibly either.
 
The only merchant that has acted oddly is the one at Willemstad, and he is now acting normally and has stopped buying things when he runs out of money.
 
Back
Top