• 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 Cannons are too large on some ships

Hylie Pistof

Curmudgeon
QA Tester
Storm Modder
Pirate Legend
So the little ships are still getting giant cannons. So be it.
 

Attachments

  • POTC 9-2-2017_2017_11_12_18_20_49_010.jpg
    POTC 9-2-2017_2017_11_12_18_20_49_010.jpg
    1.9 MB · Views: 381
  • POTC 9-2-2017_2017_11_12_18_20_57_259.jpg
    POTC 9-2-2017_2017_11_12_18_20_57_259.jpg
    1.9 MB · Views: 240
  • POTC 9-2-2017_2017_11_12_18_21_05_462.jpg
    POTC 9-2-2017_2017_11_12_18_21_05_462.jpg
    1.9 MB · Views: 344
That is definitely a bug. The carrack with 9lb cannons is reasonable - the normal maximum for that type is 6lb, but this one has the "Reinforced hull" upgrade which increases the maximum calibre by one. But the 24lb maximum on the brigantine and sloop of war is definitely wrong.

@Hylie Pistof: all the ships have the "Reinforced hull" upgrade. Did you remove and re-apply that, or did you just buy it once per ship? Also, are you playing in "Arcade" or "Realistic" mode? And have you altered the setting "USE_REAL_CANNONS" in "InternalSettings.h"?

Has anyone else seen stupidly large cannons on ships?
 
I have been using that Carrack since I got it. I do not remember about the Sloop of War but it could have been berthed and relaunched. The Brigantine was definitely berthed and relaunched and her cannon size went from 18 to 24 when relaunched. When a ship is berthed all upgrades are lost and it was fully upgraded before it was berthed.

I play in realistic mode with the Open Sea mod. The only thing I ever change in internalsettings.h are some settings at the top to get the Open Sea mod and turn off magic. I know nothing about "USE_REAL_CANNONS".

This is variable too. At one time I had 3 Sloop of War and each one had a different caliber of cannons.
 
I have been using that Carrack since I got it. I do not remember about the Sloop of War but it could have been berthed and relaunched. The Brigantine was definitely berthed and relaunched and her cannon size went from 18 to 24 when relaunched. When a ship is berthed all upgrades are lost and it was fully upgraded before it was berthed.
Ah-hah! That's the clue we needed. The problem is berthing, specifically laying up the ship as opposed to putting it on shore leave. Shore leave keeps the ship exactly as you left it, with an officer commanding it, and you get charged for crew expenses when you relaunch it. Laying up is supposed to remove all the upgrades, but although the list of upgrades is cleared, their effects aren't. So, you upgrade the ship with, among other things, "reinforced hull", which raises the maximum calibre one level. You berth it and pick the "laying up" option. When you relaunch it, the upgrade list is cleared but the ship's maximum calibre is still one calibre higher, and when you apply "reinforced hull" again, the maximum calibre goes up one more. So a sloop of war with normal maximum calibre 12 is upgraded to 18, keeps it after you've layed up and then relaunched the ship, then you apply "reinforced hull" again and its maximum calibre goes up to 24. That doesn't explain how a brigantine with normal maximum calibre 9 goes up to 24 unless you berthed and relaunched it several times, and if you're going to do that, why stop at 24?
pocket_battleship.jpg
Maximum calibre isn't the only thing increased by "reinforced hull". Unfortunately the crew of that bark is too small to fire more than one of its new monster cannons, which is a pity as the ship would otherwise have been a nasty surprise for any coastguard that tried to interfere with its smuggling run. xD

OK, down to business. The problem is with berthing, specifically with failing to properly strip out the effects of upgrades when the ship is layed up. Now I need to find the code responsible and see if I can fix this...
 
Some ships get cannons that are too big right from the start. That CastelF was only berthed one time, for instance. Personally I don't want the huge cannons as I feel the sweet spot is 12-18 pounders as the larger guns fire too slowly to be useful against smaller ships.
 
There's nothing forcing you to install the biggest guns allowed. ;) Personally, I regard the increase in maximum gun size as unrealistic anyway - no matter how tough you make the hull, if you fit the ship with heavier guns than it was originally designed to carry, it may end up overweight or top heavy, therefore likely to be unstable and capsize in the first storm. So after I've fitted "reinforced hull", I don't upgrade the ship's cannons beyond the normal maximum.

Meanwhile, trying to hunt down the bugs, I put some 'trace' statements into "KB_routines.c" and "kam_shipberthing_ship.c". This was the result, in "compile.log":
Code:
SHIP BERTHING: stripping upgrades
SHIP BERTHING: ship being stripped belongs to 'Fred Bob
KB_ROUTINES: unapplytunhullhp: current HP = 1245
KB_ROUTINES: unapplytunhullhp: new HP = 1132
KB_ROUTINES: unapplytunupcaliber: current calibre = 1
KB_ROUTINES: unapplytunupcaliber: new calibre = 4
So it thinks it's about to restore HP and calibre back to normal. But the reduction in calibre doesn't stick. One cycle later:
Code:
SHIP BERTHING: stripping upgrades
SHIP BERTHING: ship being stripped belongs to 'Fred Bob
KB_ROUTINES: unapplytunhullhp: current HP = 1137
KB_ROUTINES: unapplytunhullhp: new HP = 1132
KB_ROUTINES: unapplytunupcaliber: current calibre = 2
KB_ROUTINES: unapplytunupcaliber: new calibre = 6
First time round, it upgraded the ship's normal maximum 4lb to 6lb, then failed to reduce it. Second time round, it upgraded the maximum from 6lb to 9lb, and failed to reduce it. The HP reset does seem to stick, though. That implies a problem specific to 'unapplytunupcaliber'.

In 'applytunupcaliber', this is where the ship gets the upgrade:
Code:
_char.ship.stats.maxcaliber = Cannon_Calibers[cal+inc];
And in 'unapplytunupcaliber', this is where the ship doesn't get downgraded:if(cal != -1) { cal=cal - inc; _char.ship.maxcaliber= Cannon_Calibers[cal]; }[/code]Next time I get to play this, I'm going to see what happens if "_char.ship.maxcaliber" is replaced by "_char.ship.stats.maxcaliber"...

Meanwhile, another error has been shown up during these experiments.
Code:
RUNTIME ERROR - file: islands\islands.c; line: 17
invalid index -1 [size:24]
RUNTIME ERROR - file: islands\islands.c; line: 17
function 'GetIslandByIndex' stack error
RUNTIME ERROR - file: interface\shipyard.c; line: 5140
Using reference variable without initializing
RUNTIME ERROR - file: interface\shipyard.c; line: 5140
Using reference variable without initializing
RUNTIME ERROR - file: interface\shipyard.c; line: 5140
null ap
RUNTIME ERROR - file: interface\shipyard.c; line: 5140
null ap
RUNTIME ERROR - file: interface\shipyard.c; line: 5142
uninitialized aref
Lines 5140-5142 in "shipyard.c" are this:
Code:
    aref islRef; makearef(islRef,CurIsland.Trade.Contraband);
   int n;
   for(i=0;i<GetAttributesNum(islRef);i++)
It's part of function 'CheckForContraband'. So this is probably for @Levis to sort out. Note that this is from a game in progress with my smuggling character; he's done a smuggling run to Port Royale (more than one, in fact), but currently has nothing which is contraband there. But for this experiment, I'd loaded up a savegame and then went to the shipyard. So at the time when this error log was generated, the only things I'd done were to buy a ship, then upgrade, berth and relaunch it a couple of times.
 

Attachments

  • error.log
    1.7 KB · Views: 193
@Grey Roger that error was also reported by someone else already. Once I have time I will look into it. I would appreciate if you uploaded the savegame where this happened to a seperate topic so I can replicate the bug.
 
No. That is a different problem, and if confirmed by anyone else, will need to be dealt with separately. At the moment I'm trying to hammer the next update archive into shape and don't have time to look into this.
 
@Grey Roger that error was also reported by someone else already. Once I have time I will look into it. I would appreciate if you uploaded the savegame where this happened to a seperate topic so I can replicate the bug.
There's no point in uploading the savegame because my installation currently has changes from @DeathDaisy and @Jack Rackham which both require a new game. The savegame is incompatible with any installation that does not also have both changes.

You can check it easily enough, though. Edit "InternalSettings.h" to enable cheatmode. Start a FreePlay game, give yourself plenty of money, then go into the tavern and recruit an officer - anybody will do, whether a random officer at a table or your choice of specific officer from the tavern keeper. Then go to the shipyard and buy any ship for the officer. Give it the "Reinforced hull" upgrade. Berth it, choose laying up as the berthing method. Relaunch it. That should trigger the error - if not, it may be that you need to do a smuggling run first.
 
Meanwhile, back to the "Cannons are too large" bug: fixed! At least, that part of it to do with berthing ships. Replacing "_char.ship.maxcaliber" with "_char.ship.stats.maxcaliber" in this line:
Code:
if(cal != -1) { cal=cal - inc; _char.ship.stats.maxcaliber= Cannon_Calibers[cal]; }
did the trick. Evidence in "compile.log", before I removed the trace commands for the final version:
Code:
SHIP BERTHING: stripping upgrades
SHIP BERTHING: ship being stripped belongs to 'Sympken Bertotten'
KB_ROUTINES: unapplytunhullhp: current HP = 1690
KB_ROUTINES: unapplytunhullhp: new HP = 1610
KB_ROUTINES: unapplytunupcaliber: current calibre = 2
KB_ROUTINES: unapplytunupcaliber: new calibre = 6
IT dropped low quality weapon (blade46) in favor of higher quality (blade46+1)
SMUGGLING smuggler visited Redmond
Force_GetShipType: Maxclass = 7, Minclass = 8, Per = Golden Age of Piracy, Nat = Britain, Type = trade, Loop = 0, Ship ID = Ketch
SMUGGLING total amount of smuggled goods: Redmond is 1116
SHIP BERTHING: stripping upgrades
SHIP BERTHING: ship being stripped belongs to 'Sympken Bertotten'
KB_ROUTINES: unapplytunhullhp: current HP = 1707
KB_ROUTINES: unapplytunhullhp: new HP = 1610
KB_ROUTINES: unapplytunupcaliber: current calibre = 2
KB_ROUTINES: unapplytunupcaliber: new calibre = 6
There is still a minor problem in that, if you buy a ship with "Reinforced hull", it already has its maximum calibre raised by one, and that's the value which is stored when the ship is berthed. So a ship which is supposed to have 4lb cannons instead has a permanent maximum of 6lb, which is what happened here. Laying it up, relaunching it, and buying "Reinforced hull" again raises its maximum to 9lb - but then laying it up again and relaunching it puts it back to 6lb. At least you can't keep upgrading, berthing and relaunching the ship repeatedly to get 32lb guns on a lugger any more.

There was a problem with HP after all. Adding the "Reinforced hull" upgrade raises the ship's maximum HP and also raises the ship's current HP by the same amount. The code to remove the upgrade didn't reduce the ship's current HP, so the relaunched ship had HP of over 100%. I've added this to "unapplytunhullhp":
Code:
    if (CheckAttribute(_char, "ship.hp"))
   {
       int shipHP = sti(_char.ship.hp);
       int tuneHP = sti(_char.ship.tune.(_improvement).hp);
       if(shipHP - tuneHP > 0) _char.ship.hp = shipHP - tuneHP; //Levis added check to make sure we dont go under 0
   }
It's copied from the section of "applytunhullhp" which adds to the current HP, changing a "+" to a "-". I'm not sure why the check for HP going below 0 is needed for adding HP, but it's certainly worth putting into the HP reduction in case the ship was badly damaged when you berthed it, in which case removing the HP added by "Reinforced hull" could very well sink it. The result is that laying up and relaunching a ship doesn't leave it with excess HP any more.

Fixed "KB_routines.c" attached.
 

Attachments

  • KB_routines.c
    21.8 KB · Views: 178
Cool. To me the bigger cannons was new, but the stronger hull has always been there. I just go looking for a storm to knock it down below 100% ans it's all good.
 
Back
Top