• 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 SetCurrentTime - integers or floats?

Grey Roger

Sea Dog
Staff member
Administrator
Storm Modder
I'm not sure if this is a bug, so feel free to move this report somewhere more appropriate.

In "PROGRAM\calendar.c", 'SetCurrentTime' is defined thus:
Code:
void SetCurrentTime(int hour, int minutes)
So if I want to set the time to 11:00 plus a random number of minutes, this should do it, right?
Code:
cc = rand(59);
SetCurrentTime(11, cc);
Wrong. That sets the time to 11:00, consistently. On the other hand:
Code:
cc = rand(99);
SetCurrentTime(11.0 + cc/100.0, 0);
does the job. You'd think that would either generate an error (giving a floating point value to an integer argument) or consistently return 11:00 ('minutes' set to 0), but in fact this is the code which generates random times for me.

Is there another definition of 'SetCurrentTime' somewhere which uses a floating point for 'hour' and disregards 'minute'? Otherwise, why does giving it a floating point 'hour' work and why does giving it an integer 'minute' not work?
 
Code:
void SetCurrentTime(int hour, int minutes)
{
    Environment.date.hour = hour;
    Environment.date.min = minutes;
    Environment.time = hour + makeint(makefloat(minutes) / 60.0); // KK
    worldMap.date.hour = hour;
    worldMap.date.min = minutes;
}

uhm ... yeah it seems something goes wrong there :p.
the makeint should go away and there should be a check to see minutes is not larger then 60 (thats probably why the makeint was there).
 
something like this?
Code:
void SetCurrentTime(int hour, int minutes)
{
    minutes = iclamp(0,59,minutes);
    hour = iclamp(0,23,hour);
    Environment.date.hour = hour;
    Environment.date.min = minutes;
    Environment.time = hour + (makefloat(minutes) / 60.0); // KK
    worldMap.date.hour = hour;
    worldMap.date.min = minutes;
}

could you test it @Grey Roger
 
Yes, that seems to work. It apparently accepts both the old floating point "hour" and the proper integer "hour" plus "minutes".

I copied a new version of "calendar.c" with that code into place, re-ran my storyline savegame leading to the point where it's supposed to set the random time, and it did. Except I'd forgotten to change my storyline code, so it still had the old 'SetCurrentTime(11.0 + cc/100.0, 0);' line.

After quitting the game, changing the code to 'SetCurrentTime(11, cc);' (where cc is now set as rand(59)) and re-running the savegame again, it also set the random time. This is good - it means any existing code which uses a floating point "hour" to set minutes will still work, while anyone who sees how 'SetCurrentTime' is supposed to work and gives it proper "hours" and "minutes" values will also get their correct time.

It may mean anyone who sets both a floating point "hour" and a non-zero "minutes" may get silly results, but then anyone who is that determined to break things while writing game code can do it a lot more thoroughly in other ways, and probably will. xD Anyone else will presumably pick one method or the other and stick with it.
 
It may mean anyone who sets both a floating point "hour" and a non-zero "minutes" may get silly results, but then anyone who is that determined to break things while writing game code can do it a lot more thoroughly in other ways, and probably will. xD
:rofl :rofl :rofl
 
Back
Top