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

Included in Build Storing and restoring things

Grey Roger

Sea Dog
Staff member
Administrator
Storm Modder
Have a look at this:
Code:
bool TempRemoveItems(ref _refCharacter)
{
   if( CheckAttribute(_refCharacter,"TmpItemHolder") ) return false;
   if( !CheckAttribute(_refCharacter,"items") ) return false;

   aref dstRef; makearef(dstRef, _refCharacter.TmpItemHolder);
   aref srcRef; makearef(srcRef, _refCharacter.items);

   CopyAttributes(dstRef,srcRef);
   DeleteAttribute(_refCharacter,"items");
   return true;
}

bool RestoreTempRemovedItems(ref _refCharacter)
{
   if( !CheckAttribute(_refCharacter,"TmpItemHolder") ) return false;

   aref dstRef; makearef(dstRef, _refCharacter.items);
   aref srcRef; makearef(srcRef, _refCharacter.TmpItemHolder);

   DeleteAttribute(_refCharacter,"items");
   CopyAttributes(dstRef,srcRef);
   DeleteAttribute(_refCharacter,"TmpItemHolder");
   return true;
}
That's my attempt to remove all the player's equipment, then put it back again later, e.g. if it's taken from you while you're in prison and then returned later when you leave. (At present your weapons are unequipped and then you're prevented from re-equipping, then you just have to not look at the "Inventory" screen and pretend that all your stuff isn't still there.)

'TempRemoveItems' works perfectly, as confirmed by a 'DumpAttributes'. But 'RestoreTempRemovedItems' crashes the game, leaving nothing suspicious in "compile.log" or "system.log" and no "error.log" at all. A mass of 'trace' statements (literally one after almost every command) shows that it crashes while trying to 'CopyAtttibutes'. That's probably because "dstRef" is defined as pointing to "_refCharacter.items", which has just been deleted so "dstRef" is no longer pointing at anything. I moved the 'DeleteAttributes' up to before both the 'aref' declarations and the function worked.

Now look at this in "quests.c":
Code:
bool ShipTempRemove(ref _refCharacter)
{
   if( CheckAttribute(_refCharacter,"TmpShipHolder") ) return false;
   if( !CheckAttribute(_refCharacter,"Ship") ) return false;

   aref dstRef; makearef(dstRef, _refCharacter.TmpShipHolder);
   aref srcRef; makearef(srcRef, _refCharacter.Ship);

   CopyAttributes(dstRef,srcRef);
   return true;
}

// Âîññòàíîâèòü äàííûå î íàøåì ñòàðîì êîðàáëå èç ïàìÿòè
//------------------------------------------------------
bool RestoreTempRemovedShip(ref _refCharacter)
{
   if( !CheckAttribute(_refCharacter,"TmpShipHolder") ) return false;

   aref dstRef; makearef(dstRef, _refCharacter.Ship);
   aref srcRef; makearef(srcRef, _refCharacter.TmpShipHolder);

   DeleteAttribute(_refCharacter,"Ship");
   CopyAttributes(dstRef,srcRef);
   DeleteAttribute(_refCharacter,"TmpShipHolder");
   return true;
}
It's no coincidence that these are almost identical to my functions. I didn't know about 'CopyAttributes' but guessed that something of the sort must be at the heart of 'ExchangeCharacterShip', which I did know, so I went looking for the definition of 'ExchangeCharacterShip' to see how it worked and found the above two functions, which do exactly what I want except they do it to ships instead of items. So I simply copied them and replaced "Ship" with "items".

Those two functions aren't used anywhere, despite being in "quests.c" ever since the stock game, and as 'RestoreTempRemovedShip' is near identical to my original 'RestoreTempRemovedItems' then it will probably crash the game for the same reason. And my guess is that's why, when you lose your ship in the standard storyline after falling overboard in a storm, you do so by an 'ExchangeCharacterShip' with a dummy character created specifically for that purpose. Moving the 'DeleteAttribute(_refCharacter,"Ship")' up to before the two 'aref' lines would probably make this function work as well.
 
Good find, @Grey Roger! :onya

I'd suggest you include your proposed change in your next upload.
It might as well be correct, right? :cheeky
 
The ship store/restore functions aren't used anywhere so this would be an alteration to a core game file which isn't strictly a fix, so it's the sort of thing I don't put into the "fixes only" collection. The item store/restore functions will, initially at least, go into my storyline "quests_reaction.c" file as local declarations - they're needed for the bit I'm writing at the moment and will be available after the next "Ardent" upload. I'd suggest the functions go into the next experimental release, then other modders can play around with them. In particular, if the item store/restore functions do prove reliable, I'll use them for the prison section of "Hornblower".
 
The ship store/restore functions aren't used anywhere so this would be an alteration to a core game file which isn't strictly a fix, so it's the sort of thing I don't put into the "fixes only" collection.
Since they aren't used, changing them in the "fixes only" archive will have no consequences whatsoever.
Until somebody ever decides to use them, in which case your change will probably be a great help since it would actually work. :cheeky

The item store/restore functions will, initially at least, go into my storyline "quests_reaction.c" file as local declarations
If you really want to have them only in your storyline, I'd suggest using the optional SL_utils.c instead as that is meant for storyline-specific function declarations.
But since those functions aren't used anywhere else, adding them to the main code will also have no consequences.
Until somebody wants to use those functions too, in which case they'll already exists in a generally accessible spot.

So I can see no harm in adding both in the general game code.
 
Very well, both the updated ship store/restore functions and the new item store/restore functions are going into "quests.c" in the fixes collection, and the same "quests.c" will also go into the next "Ardent" upload because the storyline now requires the item functions.

Meanwhile, definitely not for the fixes collection and probably not for any other official update, is this version of "PROGRAM\Storyline\standard\quests_reaction.c". At the points where you take over Rabel Yverneau's frigate and where you hand it over in Port Royale, I've replaced the 'ExchangeCharacterShip' lines involving dummy character "Ship Storage" with 'ShipTempRemove(PChar)' and 'RestoreTempRemovedShip(PChar)'. I'm playing through "Tales of a Sea Hawk" as a test of the fixes collection and have just got to that point in the story, providing an opportunity to test the ship store/restore functions, and they seem to have worked. The only snag is that if you have one or more companion ships, they stay with you and are liable to be sunk by the Speightstown fort, but that happens with the old 'ExchangeCharacterShip' system as well. You'll just have to make sure you've sold or berthed any companion ships before you go to Speightstown, as you always have needed to do!
 

Attachments

  • quests_reaction.c
    344.4 KB · Views: 135
So you tested your modified stock game code and it DOES actually seem to work?
Nicely done, mate!!! :woot
 
Yes, I had a savegame when I had two prize ships which I hadn't sold, so I put the modified "quests_reaction.c" into place, loaded it, and played up to the point at which I arrive at Jamaica, teleport to the townhall and get my original ship back. One of the prize ships was sunk by Speightstown fort, the other survived. More importantly it also survived both the 'ShipTempRemove(PChar)' before I took over Rabel Yverneau's ship, and the 'RestoreTempRemovedShip(PChar)' which gave me back my own ship.
 
Sounds like you fixed a bug with the stock game code then. :onya
 
Back
Top