Skip to content

Commit

Permalink
Time fix attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
brightrim committed Jun 15, 2024
1 parent 69fd828 commit 3334eba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ class World : public WorldScriptInterface {
* Method for returning the current illarion time
*
*@param timeType <"year"|"month"|"day"|"hour"|"minute"|"second">
*@return an int which is the current illarion time from the type
*@return a long which is the current illarion time from the type
*/
auto getTime(const std::string &timeType) const -> int override;
auto getTime(const std::string &timeType) const -> long override;

void allowLogin(bool allow) { _is_login_allowed = allow; }
auto isLoginAllowed() const -> bool { return _is_login_allowed; }
Expand Down
2 changes: 1 addition & 1 deletion src/WorldIMPLTalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void World::sendIGTime(Player *cp) const {
ServerCommandPointer cmd = std::make_shared<UpdateTimeTC>(
static_cast<unsigned char>(getTime("hour")), static_cast<unsigned char>(getTime("minute")),
static_cast<unsigned char>(getTime("day")), static_cast<unsigned char>(getTime("month")),
static_cast<short int>(getTime("year")));
static_cast<long>(getTime("year")));
cp->Connection->addCommand(cmd);
}

Expand Down
18 changes: 9 additions & 9 deletions src/WorldIMPLTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,17 +597,17 @@ void World::Load() {

void World::import() { maps.importFromEditor(); }

auto World::getTime(const std::string &timeType) const -> int {
auto World::getTime(const std::string &timeType) const -> long {
// return unix timestamp if requsted and quit function
if (timeType == "unix") {
return (int)time(nullptr);
return (long)time(nullptr);
}

// get current time and timezone data to get additional informations for time conversation
time_t curr_unixtime = time(nullptr);
struct tm *timestamp = localtime(&curr_unixtime);

auto illaTime = (int)curr_unixtime;
auto illaTime = (long)curr_unixtime;
static constexpr auto secondsInHour = 60 * 60;

// in case its currently dst, correct the timestamp so the illarion time changes the timestamp as well
Expand All @@ -618,25 +618,25 @@ auto World::getTime(const std::string &timeType) const -> int {
illaTime = (illaTime - illarionBirthTime) * illarionTimeFactor;

if (timeType == "illarion") {
return (int)illaTime;
return (long)illaTime;
}

// Calculating year
static constexpr auto secondsInYear = 60 * 60 * 24 * 365;
auto year = (int)(illaTime / secondsInYear);
auto year = (long)(illaTime / secondsInYear);
illaTime -= year * secondsInYear;

// Calculating day
static constexpr auto secondsInDay = 60 * 60 * 24;
auto day = (int)(illaTime / secondsInDay);
auto day = (long)(illaTime / secondsInDay);
illaTime -= day * secondsInDay;
++day;

// Calculating month
static constexpr auto daysInIllarionMonth = 24;
static constexpr auto daysInLastIllarionMonth = 5;
static constexpr auto monthsInIllarionYear = 16;
auto month = (int)(day / daysInIllarionMonth);
auto month = (long)(day / daysInIllarionMonth);
day -= month * daysInIllarionMonth;

// checking for range borders and fixing the date
Expand Down Expand Up @@ -668,12 +668,12 @@ auto World::getTime(const std::string &timeType) const -> int {

// Calculate the time of day
// Calculating hour
const auto hour = (int)(illaTime / secondsInHour);
const auto hour = (long)(illaTime / secondsInHour);
illaTime -= hour * secondsInHour;

// Calculating minute
static constexpr auto secondsInMinute = 60;
const auto minute = (int)(illaTime / secondsInMinute);
const auto minute = (long)(illaTime / secondsInMinute);

// Calculating seconds
illaTime -= minute * secondsInMinute;
Expand Down
2 changes: 1 addition & 1 deletion src/WorldScriptInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class WorldScriptInterface {
// Other

virtual void broadcast(const std::string &german, const std::string &english) const = 0;
[[nodiscard]] virtual auto getTime(const std::string &timeType) const -> int = 0;
[[nodiscard]] virtual auto getTime(const std::string &timeType) const -> long = 0;
virtual void gfx(unsigned short int gfxid, const position &pos) const = 0;
virtual void makeSound(unsigned short int soundid, const position &pos) const = 0;
virtual void sendMonitoringMessage(const std::string &msg, unsigned char id = 0) const = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/test_binding_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MockWorld : public World {
MOCK_METHOD(void, removePersistenceAt, (const position &), (override));
MOCK_METHOD(bool, isPersistentAt, (const position &), (const override));
MOCK_METHOD(void, broadcast, (const std::string &, const std::string &), (const override));
MOCK_METHOD(int, getTime, (const std::string &), (const override));
MOCK_METHOD(long, getTime, (const std::string &), (const override));
MOCK_METHOD(void, gfx, (unsigned short int, const position &), (const override));
MOCK_METHOD(void, makeSound, (unsigned short int, const position &), (const override));
MOCK_METHOD(void, sendMonitoringMessage, (const std::string &, unsigned char), (const override));
Expand Down

0 comments on commit 3334eba

Please sign in to comment.