• 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 Problem with gunner on deck

Oh Pieter, I worked really hard to get 3 cases of stringlogs depending on if only pchar, any officer or both
had refilled their ammo.
[...]
I have the same idea when you refill from the GPS yourself. I would prefer not to have it changed. If there's nothing wrong of course.
Indeed I saw that and that was quite nice. But the code just gets larger and larger, so I thought I'd suggest simplifying it a bit.

I think GetOfficersIndex 0 is the player, so all characters can be included in the same loop, for example.
That reduces a lot of double code (double code has been driving me completely nuts at my day job lately.... :oops: ).

Maybe you could use a string variable to store the characters that got resupplied?
Something like this, for example:
Code:
string SuppliedBy = "The Gunner";
if (AMMOMOD_ABLECAPTAIN) = "you";

string SuppliedChars = "";
if (Player is supplied) SuppliedChars = "you";
if (Officers are supplied) SuppliedChars = "your officers";
if (Player AND Officers are supplied) SuppliedChars = "you and your officers";

LogIt(TranslateString("", SuppliedBy + " supplied " + SuppliedChars + " with " + Ammunition!"));

It might also be worth putting some of this stuff into separate functions as I think the same section of code needs to be called from quests_common.c AND from the itemsbox.c interface.

Just to try and simplify it all? Just thought I'd suggest it for your consideration.
I'll leave it up to you what you want to do in the end. :shrug
 
Sounds very good Pieter.
The main reason for placing the code in quest_common was I needed a little delay.
(from start in LAi_deck). But of course it can be directed from itemsbox too.

If run from itemsbox it should be "You" as you're the one getting ammo out of the GPS.
So I say yes to everything. And thanks for your help. :onya
 
The event handlers you used before can give you a delay too.

But for now, it still runs through quests_common.c, which in turn calls the function:
Code:
    case "gunner_ammo":
       SupplyAmmo();
     break;

With the function itself looking like this:
Code:
void SupplyAmmo()
{
   if(ENABLE_AMMOMOD)
   {
     ref PChar = GetMainCharacter();
     ref NPChar;
     int i, iOfficer, cc;

     string weaponID;
     aref weapon;

     bool tmpAbleRefill = false;
     if (CharacterHasOfficerType(pchar, OFFIC_TYPE_CANNONEER))   { tmpAbleRefill = true; }
     if (AMMOMOD_ABLECAPTAIN)                   { tmpAbleRefill = true; }

     if (tmpAbleRefill)
     {
       //PLAYER AND OFFICERS
       for(i = 0; i < 4; i++)
       {
         iOfficer = GetOfficersIndex(PChar, i);
         if(iOfficer < 0) continue;
         NPChar = GetCharacter(iOfficer);

         weaponID = GetCharacterEquipByGroup(NPChar,GUN_ITEM_TYPE);
         if(weaponID != "")
         {
           Items_FindItem(weaponID, &weapon);
           if(CheckAttribute(weapon, "shottype"))
           {
             if(weapon.shottype == "pg2" || weapon.shottype == "pg" || weapon.shottype == "mb" || weapon.shottype == "pb" || weapon.shottype == "pb2")
             {
               DeleteAttribute(NPChar,"Items.gunpowder");
               DeleteAttribute(NPChar,"Items.pistolbullets");
               DeleteAttribute(NPChar,"Items.pistolgrapes");
               DeleteAttribute(NPChar,"Items.musketbullets");

               if(CheckCharacterItem(NPChar,"powderbarrel")) { TakeNItems(NPChar,"gunpowder", (4 * MAX_GUNPOWDER)); }
               else
               {
                 if(CheckCharacterItem(NPChar,"powderflask")) { TakeNItems(NPChar,"gunpowder", (2 * MAX_GUNPOWDER)); }
                 else { TakeNItems(NPChar,"gunpowder", MAX_GUNPOWDER); }
               }
               if(CheckCharacterItem(NPChar,"ammobag")) { cc = (4 * MAX_SHOTS); }
               else
               {
                 if(CheckCharacterItem(NPChar,"ammopouch")) { cc = (2 * MAX_SHOTS); }
                 else { cc = MAX_SHOTS; }
               }
               //LogIt("cc = " + cc);

               if(weapon.shottype == "pg2" || weapon.shottype == "pg")   { TakeNItems(NPChar,"pistolgrapes" , cc);  }
               if(weapon.shottype == "mb")                { TakeNItems(NPChar,"musketbullets", cc/2); }
               if(weapon.shottype == "pb2" || weapon.shottype == "pb")   { TakeNItems(NPChar,"pistolbullets", cc);  }
             }
           }
         }
       }
       LogIt(TranslateString("","Your shore party has been resupplied with Ammunition!"));
       PlaySound("INTERFACE\important_item.wav");
     }
   }
}
As you can see, the text is just a very simple "Your shore party has been resupplied with Ammunition!" in there.
As that is very general and doesn't mention who does it, technically it isn't wrong.
But it is also admittedly not as pretty as what you had in place.... :oops:
 
Oops, better add an override so that the itemsbox one DOES always supply you! :facepalm
Code:
void SupplyAmmo(bool bOverride)
{
   if(ENABLE_AMMOMOD)
   {
     ref PChar = GetMainCharacter();
     ref NPChar;
     int i, iOfficer, cc;

     string weaponID;
     aref weapon;

     bool tmpAbleRefill = false;
     if (bOverride)                         { tmpAbleRefill = true; }
     if (CharacterHasOfficerType(pchar, OFFIC_TYPE_CANNONEER))   { tmpAbleRefill = true; }
     if (AMMOMOD_ABLECAPTAIN)                   { tmpAbleRefill = true; }
 
My mistake; I wrote that function so it would ALWAYS do the same. Which didn't make any sense.
It should be better now.

Unfortunately I now find my time disappearing due to the suddenly even worse game performance, so I am quickly running out of time to do anything else. :modding
 
This should technically work as per the last EXE update.
Reminder @Jack Rackham to look at and tweak the code I rewrote so that you're actually happy with it.
I don't want to break your intentions, after all. :doff
 
Dunno where to ask this so........... I went to Nevis and got Artois Voisey and all went according to plan. He has a gun but no ammo and since I am carrying a Blunderbuss I could not give him any. So I changed him from a Navigator to a Gunner and sailed away. When I got to the next island I found that he still does not have ammo. Is this a bug or intentional?
 
Why can you not give him ammo because you have a blunderbuss?

Have you tried visiting the ammo locker in your Cargo hold?
 
I accidentally figured it out by hitting the wrong button and going on deck instead of going to sea, and we got ammo. Why were the unnecessary extra steps added?
 
Why were the unnecessary extra steps added?
What extra step? Is it required to go to your ship deck now? And it doesn't work if you go from port straight to 3D sailing mode?
The problem was that apparently it didn't always work when you did do that. :facepalm
 
I didn't know you could go direct from port to sailing mode. How? o_O
Otherwise Pieter I have no objections. Looks ok to me.
 
I have always gone from the dock to sea and gotten ammo from the gunner immediately. This is the first time that it does not work that way for me, but since I quit playing the latest games for many months, perhaps it has been changed and I do not know about it.

I go to the end of the dock and save, then hit enter and scroll to the water icon.
 
Aha. Guess we have to fix this then. It should of course work also without passing any shipdeck.
I can take a look tomorrow as I changed it.
 
I go to the end of the dock and save, then hit enter and scroll to the water icon.
Yep, I do that all the time as well. :yes

I have always gone from the dock to sea and gotten ammo from the gunner immediately. This is the first time that it does not work that way for me, but since I quit playing the latest games for many months, perhaps it has been changed and I do not know about it.
It was fairly recent. Past two weeks or so.

I didn't know you could go direct from port to sailing mode. How? o_O
Already answered by Hylie. :doff

Otherwise Pieter I have no objections. Looks ok to me.
The simplification is OK with you? Cheers! :cheers
 
Ok this is what I have done:
1 gunner or ablecaptain on => supply ammo also when going direct from land to sailing
2 the stringlog "Your shore party has been resupplied with Ammunition!" only appears if any in the shoreparty
really DID supply. Also prevents from repeated message going via deck (and supplying) then to sailing.
3 removed old code in LAi_deck. an old version from 2006! of this thing. It must have run double with the new one.
 
Back
Top