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

Time advancement

Bullgod

Landlubber
Hi everybody,
I hope this is a proper place to post my question. I'm asking about CoAS script in particular.
I'm no coder and my understanding of whatever is in game script files is kind of vague, so I can't figure it out by myself without learning the programming language (it's C, right?). I wasn't able to find anything on what I'm looking for anywhere, so I don't know if it was tried before.
Anyway, my question is:
Is it possible to add a bit of code somewhere to advance time by some amount (random number of minutes or rather hours) whether player travels to another inland map? I really think travelling from one end of Jamaica (for example) to the other should take more time than a minute. I think it would also have significant impact on gameplay if traveling through island would be more time consuming.
I'm actually asking if anyone knows where such code could be inserted and how should it look like (if it's possible at all).

Actually the same thing refers to "teleporting" on sea map, but that's less important, as I can simply not use that feature (or use it only in case of ships or places close by, not beaches on the opposite side of island).
 
Should be possible. That was done as a very old mod in PotC as well.

This is how it works in PotC. File is PROGRAM\Locations\locations_loader.c:
Code:
bool LoadLocation(ref loc)
{
   traceif("LoadLocation(ref loc) " + loc.id);
   PostEvent(EVENT_LOCATION_LOAD,0);

   int i;
   bool res;
   ref mainCharacter = GetMainCharacter(); // KK

   for (i = 0; i < MAX_SHIPS_IN_LOCATION; i++) { iShips[i] = -1; } // KK

   //Time update==========================================================================
   // NK 04-09-21 with time now added on the fly this is unnecessary. However, with TIMEUPDATE_BLOCK_LAND we still need something.
   /*if(locTmpTime > 300)
   {
     AddTimeToCurrent(4, 0);
   }else{
     if(locTmpTime > 100)
     {
       AddTimeToCurrent(0, 30);
     }else{
       AddTimeToCurrent(0, 5);
     }
   }*/
   if(TIMEUPDATE_BLOCK_LAND)
   {
     AddTimeToCurrent(0, (locTmpTime * TIMESCALAR_LAND)/60.0);
     // WM wdmgrid section 04-10-24 -->
     // done in calendar.c now:
   }
   // NK <--
Needs the following defines:
Code:
#define TIMESCALAR_LAND         10       // INT - same but for land
#define TIMEUPDATE_BLOCK_LAND     1       // BOOL - whether time updates per minute or on location change (i.e. in blocks)
Will probably be very similar in CoAS.
 
Thank you very much for such quick answer! :)
Unfortunately it didn't work. Maybe I've pasted it wrong... dunno. Screen just go blank at loading.

But... I've figured it out thanks to you, because I knew where to look now.

Here's how that part of code looks like in unmodified file:
Code:
bool LoadLocation(ref loc)
{
   //trace("LoadLocation(ref loc) " + loc.id);
   PostEvent(EVENT_LOCATION_LOAD,0);

   int i;
   bool res;
   
   //Time update==========================================================================
   locTmpTime += 5;
   CalcLocalTime(3);
}
What those two commands do I have no idea.
I looked through this and other files (like dialog script that advances time when talking to slef) to find commands that might help do the trick, and I've constructed this:
Code:
bool LoadLocation(ref loc)
{
   //trace("LoadLocation(ref loc) " + loc.id);
   PostEvent(EVENT_LOCATION_LOAD,0);

   int i;
   bool res;
  //Time update==========================================================================
   locTmpTime += 5;
   CalcLocalTime(3);
   {
     if(CheckAttribute(loc, "type"))
     {   
       res = false;
       switch(loc.type)
       {
         case "jungle":
         res=true;
         break;
         case "seashore":
         res=true;
         break;
       }
       if(res)
       {
         int iAddTime;
         iAddTime= 2       
         WaitDate("",0,0,0,iAddTime,0);
         RefreshWeather();
         RefreshLandTime();   
       }
   }
}
Which makes time advance 2 hours on every loading of jungle and seashore location (well, that includes boat landing, but that's something to fine tune later).
Unfortunately I don't know how to exclude Town Jungle Exit from that list, as it is of the "jungle" type and therefore leaving town is quite time consuming (but nevermind that).
Apart from that it works and seems to be working good.

I have but one more question.
Could you help me a little more by telling me how to randomize iAddTime number?
The script I took this from advanced time to specific hour.
 
As I said, the code I posted is from PotC, not CoAS. They're very similar, but not identical.
The parts marked with NK are mod-added and might work as clues. :shrug

For randomize, just use rand(2) which will return 0,1 or 2. Or rand(2)+1 to return 1-3 instead.
 
Thank you very much again, Pieter.

Sorry for asking such basic things, but C tutorials found online somehow only got me confused.

I also managed somehow to brake things in the meantime, but I should be able to make it work now... eventually :)
 
Back
Top