diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 353d66fa9fa..cd035d42fd2 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -821,6 +821,8 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) { return CommandManiacSetGameOption(com); case Cmd::Maniac_CallCommand: return CommandManiacCallCommand(com); + case static_cast(2054): //Cmd::EasyRpg_GetTime + return CommandGetTime(com); default: return true; } @@ -4643,6 +4645,34 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const&) { return true; } +bool Game_Interpreter::CommandGetTime(lcf::rpg::EventCommand const& com) { + + std::string periodName = Utils::LowerCase(ToString(com.string)); + int32_t outputVariable = ValueOrVariable(com.parameters[0], com.parameters[1]); + + lcf::rpg::EventCommand outputCommand; + outputCommand.code = int(Cmd::ControlVars); + + std::time_t t = std::time(nullptr); + std::tm* tm = std::localtime(&t); + + int32_t dateOutput{}; + + if (periodName == "getyear") dateOutput = tm->tm_year + 1900; + if (periodName == "getmonth") dateOutput = tm->tm_mon + 1; + if (periodName == "getday") dateOutput = tm->tm_mday; + if (periodName == "gethour") dateOutput = tm->tm_hour; + if (periodName == "getminute") dateOutput = tm->tm_min; + if (periodName == "getsecond") dateOutput = tm->tm_sec; + if (periodName == "getweekday") dateOutput = tm->tm_wday +1; + if (periodName == "getyearday") dateOutput = tm->tm_yday +1; + + std::vector updateVarParams = { 0, outputVariable, 0, 0, 0, dateOutput }; + outputCommand.parameters = lcf::DBArray(updateVarParams.begin(), updateVarParams.end()); + + return ExecuteCommand(outputCommand); +} + Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() { return Game_Battle::IsBattleRunning() ? Game_Battle::GetInterpreter() diff --git a/src/game_interpreter.h b/src/game_interpreter.h index a436cbfaed1..085fda3e7c8 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -284,6 +284,7 @@ class Game_Interpreter bool CommandManiacChangePictureId(lcf::rpg::EventCommand const& com); bool CommandManiacSetGameOption(lcf::rpg::EventCommand const& com); bool CommandManiacCallCommand(lcf::rpg::EventCommand const& com); + bool CommandGetTime(lcf::rpg::EventCommand const& com); int DecodeInt(lcf::DBArray::const_iterator& it); const std::string DecodeString(lcf::DBArray::const_iterator& it);