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

Adding locations without editing locations_init.c

Inez Dias

Privateer
Storm Modder
Pondering a quest I'm hoping to make (sometime) I was much annoyed by the fact that you have to edit so many files in order to add anything new. Though Nathan and Pieter have heroically kept track of all the changes made by different people, I think that for mere humans (such as me) it is quite impossible to set up a quest without messing everything up. I've been wondering about how to simplify that process.

As a start (based on an idea originally by Scheffnow, plus some code stolen from Nathan) I've written a function for locations_init so that it automatically loads all files in a "mods" subdirectory of locations/init and executes the initialization code in those files.
The following goes into locations_init.c:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->extern int InitModLocations();
object LocDirectory;

int LocationInitModLocations(int n)
{
    DeleteAttribute(&LocDirectory, "");
    
    LocDirectory.dir = "Program\\Locations\\init\\mods";
    LocDirectory.mask = "*.c";
    CreateEntity(&LocDirectory,"FINDFILESINTODIRECTORY");
    DeleteClass(&LocDirectory);
    aref arList;
    makearef(arList, LocDirectory.filelist);
    for(int i = 0; i < GetAttributesNum(arList); i++)
    {
  aref arCur = GetAttributeN(arList, i);
  string fname = GetAttributeValue(arCur);
  string fullname = "locations\\init\\mods\\"+fname;  
  if(LoadSegment(fullname))
  {
      ref pc = GetMainCharacter();
      pc.numlocations = n; //Hack because we can't pass parameters to extern functions
      n = InitModLocations();
      DeleteAttribute(pc, "numlocations");
      UnloadSegment(fullname);
  }
  else
  {
      Log_SetStringToLog("There's an error in the location init code in " + fname);
  }
    }
    return n;
}<!--c2--></div><!--ec2-->
Then, at the end of the function InitLocations
(before the line nLocationsNum = n;), add:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->n = LocationInitModLocations(n);<!--c2--></div><!--ec2-->

Thus new locations can easily be added by just dropping a file into that directory, without any further editing of locations_init.c.

I'd very much like to see this merged into the build or modpack, because it will much simplify the addition of new locations. It will not break any of the existing code, just adds some functionality that modders can use or not use as they wish.

If anyone does wish to use it, all you need to do is put the following function in your file:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->int InitModLocations()
{
    int n = GetMainCharacter().numlocations;

    //...    
    //increase n by 1 for each new location.

    return n;
}<!--c2--></div><!--ec2-->
Apart from the fact that it doesn't get n as a parameter (because extern functions with parameters don't work), the function is just like the ones in the stock game files in the Locations/init folder.

I'm however not sure how it all interacts with reinitializing - so I'd apprecitate any comments.

Sorry for posting so much code - couldn't get the attachment working - it kept saying I don't have permission <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/dunno.gif" style="vertical-align:middle" emoid=":shrug" border="0" alt="dunno.gif" />
 
Thanks a lot Inez! It will be added to the next modpack update. Actually: I already did, but I haven't made the update available yet. I haven't checked whether it works, but at least it doesn't crash the game. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
Just a little question: Is the "CheckDlgLoad.c" file from the PotC Euro-versions required for this mod? Because I don't think I added that file to the modpack yet. I do have it myself, but some other people might not have it.
 
<!--QuoteBegin-Pieter Boelen+Aug 14 2005, 03:07 PM--><div class='quotetop'>QUOTE(Pieter Boelen @ Aug 14 2005, 03:07 PM)</div><div class='quotemain'><!--QuoteEBegin-->It will be added to the next modpack update.<!--QuoteEnd--></div><!--QuoteEEnd-->
Thanks alot.
<!--QuoteBegin-Pieter Boelen+Aug 14 2005, 03:07 PM--><div class='quotetop'>QUOTE(Pieter Boelen @ Aug 14 2005, 03:07 PM)</div><div class='quotemain'><!--QuoteEBegin-->Just a little question: Is the "CheckDlgLoad.c" file from the PotC Euro-versions required for this mod? Because I don't think I added that file to the modpack yet. I do have it myself, but some other people might not have it.
<div align="right">[snapback]128176[/snapback]</div><!--QuoteEnd--></div><!--QuoteEEnd-->
Not, it's not needed for this.

Oh, and one more thing: You need to have the "mods" subdirectory, or the game *will* crash. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
So could you please add that to the modpack (as an empty folder), too?
 
I already did. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
I also added an example.c to the folder, to explain things a bit:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->/*
Inez Dias -->
New locations can easily be added by just dropping a file into this directory, without any further editing of locations_init.c. Make sure the below code is in the file. And, of course, don't have it outcommented.
*/

/*
int InitModLocations()
{
    int n = GetMainCharacter().numlocations;

    // ...
    // increase n by 1 for each new location.

    return n;
}
*/<!--c2--></div><!--ec2-->
If you know what other text I could add to the example.c, please tell and I'll have that added instead.
 
Thanks a lot, you two <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/onya.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="onya.gif" />

That will make location modding easier <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/yes.gif" style="vertical-align:middle" emoid=":yes" border="0" alt="yes.gif" />
 
I am getting error reports with this new functionality as it is in the modpack:

RUNTIME ERROR - file: locations\locations_init.c; line: 188
Invalid function call
RUNTIME ERROR - file: locations\locations_init.c; line: 188
function 'LocationInitModLocations' stack error
RUNTIME ERROR - file: locations\locations_init.c; line: 188
Invalid function call
RUNTIME ERROR - file: locations\locations_init.c; line: 188
function 'LocationInitModLocations' stack error

Could you please look into this, Inez? I suppose it's got to do with me not merging it properly... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":?" border="0" alt="unsure.gif" />
 
Somebody PLEASE look into this bug. This code, as it is in the modpack now, is causing SERIOUS location-troubles. Falaise de Fleur is causing major trouble. But only if this code is in locations_init.c . So please, please look into it, because it's really troublesome. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/piratesing.gif" style="vertical-align:middle" emoid=":shock" border="0" alt="piratesing.gif" />
 
<!--QuoteBegin-Pieter Boelen+Aug 17 2005, 09:05 AM--><div class='quotetop'>QUOTE(Pieter Boelen @ Aug 17 2005, 09:05 AM)</div><div class='quotemain'><!--QuoteEBegin-->I am getting error reports with this new functionality as it is in the modpack:

...
RUNTIME ERROR - file: locations\locations_init.c; line: 188
Invalid function call
RUNTIME ERROR - file: locations\locations_init.c; line: 188
function 'LocationInitModLocations' stack error
.<div align="right">[snapback]128356[/snapback]</div><!--QuoteEnd--></div><!--QuoteEEnd-->
Me too!
 
<img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/w00t.gif" style="vertical-align:middle" emoid=":woot" border="0" alt="w00t.gif" /> Nice work, Inez! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/me.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="me.gif" />
 
I seem to have found the bug with the code. It is actually not Inez's fault, but mine, just like I expected. I added an example.c in the \mods subfolder, but commented out everything in the file. It seems like if the mod tries to load a file and the specific required code is not in there, it will cause major trouble. In the next modpack update, I will have the code uncommented again, so the mod actually finds the code it's looking for. With a bit of luck, that will work properly. I am at least not getting any error messages during the loading process.
Sorry for all the trouble I've been causing by doing this. I really hope it'll be fixed now. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/oops3.gif" style="vertical-align:middle" emoid=":eek:ops2" border="0" alt="oops3.gif" />
 
<img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/hi.gif" style="vertical-align:middle" emoid=":gday" border="0" alt="hi.gif" />
Will check this today!

Edit:
Added back Inez's code in locations_init.c, and corrected problem in mods/example.c .

Checked this at FdF, no problem, everything worked fine!
 
It's official then. Pieter has, once again, been causing major bugs. SHAME ON HIM!!!! Well... Ehm... Me, actually... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/oops3.gif" style="vertical-align:middle" emoid=":eek:ops2" border="0" alt="oops3.gif" />
Anyway: At least we now know to properly fix it. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
 
<!--QuoteBegin-Pieter Boelen+Aug 24 2005, 07:51 PM--><div class='quotetop'>QUOTE(Pieter Boelen @ Aug 24 2005, 07:51 PM)</div><div class='quotemain'><!--QuoteEBegin-->It's official then. Pieter has, once again, been causing major bugs. SHAME ON HIM!!!! Well... Ehm... Me, actually... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/oops3.gif" style="vertical-align:middle" emoid=":eek:ops2" border="0" alt="oops3.gif" />
<div align="right">[snapback]128999[/snapback]</div><!--QuoteEnd--></div><!--QuoteEEnd-->
Only he who doeth nought maketh no mistakes <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/yes.gif" style="vertical-align:middle" emoid=":yes" border="0" alt="yes.gif" />
 
Ah... Well... I caused the trouble myself, so I deserved to go through it. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/whippa.gif" style="vertical-align:middle" emoid=":whipa" border="0" alt="whippa.gif" />
 
<!--QuoteBegin-Pieter Boelen+Aug 28 2005, 08:48 AM--><div class='quotetop'>QUOTE(Pieter Boelen @ Aug 28 2005, 08:48 AM)</div><div class='quotemain'><!--QuoteEBegin-->Ah... Well... I caused the trouble myself, so I deserved to go through it. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/whippa.gif" style="vertical-align:middle" emoid=":whipa" border="0" alt="whippa.gif" />
<div align="right">[snapback]129212[/snapback]</div><!--QuoteEnd--></div><!--QuoteEEnd-->
Yes, but did ye have to be tak'n me along for the ride, arrgggh! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/whippa.gif" style="vertical-align:middle" emoid=":whipa" border="0" alt="whippa.gif" />

Just kidding, we all have to be do'n our part to keep this here tub ... ahh ... boat afloat! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/smile2.gif" style="vertical-align:middle" emoid=":))" border="0" alt="smile2.gif" />
 
<!--QuoteBegin-Petros+Aug 28 2005, 09:51 PM--><div class='quotetop'>QUOTE(Petros @ Aug 28 2005, 09:51 PM)</div><div class='quotemain'><!--QuoteEBegin-->Yes, but did ye have to be tak'n me along for the ride, arrgggh! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/whippa.gif" style="vertical-align:middle" emoid=":whipa" border="0" alt="whippa.gif" />
<div align="right">[snapback]129228[/snapback]</div><!--QuoteEnd--></div><!--QuoteEEnd-->
SHAME ON ME!!!! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/boom.gif" style="vertical-align:middle" emoid=":boom" border="0" alt="boom.gif" />

Really: I'm sorry about that. Hope I won't be messing up <i>again</i> any time soon. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/oops3.gif" style="vertical-align:middle" emoid=":eek:ops2" border="0" alt="oops3.gif" />
 
<!--QuoteBegin-Pieter Boelen+Aug 29 2005, 05:41 AM--><div class='quotetop'>QUOTE(Pieter Boelen @ Aug 29 2005, 05:41 AM)</div><div class='quotemain'><!--QuoteEBegin--><!--QuoteBegin-Petros+Aug 28 2005, 09:51 PM--><div class='quotetop'>QUOTE(Petros @ Aug 28 2005, 09:51 PM)</div><div class='quotemain'><!--QuoteEBegin-->Yes, but did ye have to be tak'n me along for the ride, arrgggh! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/whippa.gif" style="vertical-align:middle" emoid=":whipa" border="0" alt="whippa.gif" />
<div align="right">[snapback]129228[/snapback]</div><!--QuoteEnd--></div><!--QuoteEEnd-->
SHAME ON ME!!!! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/boom.gif" style="vertical-align:middle" emoid=":boom" border="0" alt="boom.gif" />

Really: I'm sorry about that. Hope I won't be messing up <i>again</i> any time soon. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/oops3.gif" style="vertical-align:middle" emoid=":eek:ops2" border="0" alt="oops3.gif" />
<div align="right">[snapback]129262[/snapback]</div>
<!--QuoteEnd--></div><!--QuoteEEnd-->
Don't worry, I got over it!

While experiencing down time, I got the idea to start work on another ship. There is only one paint scheme for the Light Frigate so I started on it and finished it today. No new ship stats yet, just the paint job.
 
WOW! That's GREAT! I never did like the original Light Frigate skin too much. Your new one looks much better! Hope I'll be able to add it into the modpack soon. Together with any new skins you might have lying around. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
LOL. Looks like a Greek helmet thing on the back. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/razz.gif" style="vertical-align:middle" emoid=":razz" border="0" alt="razz.gif" />
 
Back
Top