From 1daf444b3ef59eeecca2b62c6395442e68a74209 Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Sat, 14 Oct 2023 16:01:40 -0300 Subject: [PATCH 1/2] New Command: 2054 - GetTime Gets current date information and attach it to a variable. Usage: ```js @raw 2054, "Type_of_Date", targetVar_IsVar, targerVat ``` ```js // "set year to variable 1:" @raw 2054, "getYear", 0, 1 // "set month to variable 2:" @raw 2054, "getMonth", 0, 2 // "set day to variable 3:" @raw 2054, "getDay", 0, 3 // "set hour to variable 4:" @raw 2054, "getHour", 0, 4 // "set minute to variable 5:" @raw 2054, "getMinute", 0, 5 // "set second to variable 6:" @raw 2054, "getSecond", 0, 6 // "set day of week to variable 7:" @raw 2054, "getWeekDay", 0, 7 // "set days in year to variable 8:" @raw 2054, "getYearDay", 0, 8 ``` --- src/game_interpreter.cpp | 28 ++++++++++++++++++++++++++++ src/game_interpreter.h | 1 + 2 files changed, 29 insertions(+) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 353d66fa9f..91a081d3d1 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,32 @@ 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]); + + 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; + if (periodName == "gettimestamp") dateOutput = t; + + Main_Data::game_variables->Set(outputVariable, dateOutput); + Game_Map::SetNeedRefresh(true); + + return true; +} + 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 a436cbfaed..085fda3e7c 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); From f860effceb164d05742316f49c89c870721ef819 Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Wed, 8 Nov 2023 19:26:07 -0300 Subject: [PATCH 2/2] Move command to ControlVariables --- src/game_interpreter.cpp | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 91a081d3d1..cf159ac242 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -821,8 +821,6 @@ 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; } @@ -1074,6 +1072,33 @@ bool Game_Interpreter::CommandControlSwitches(lcf::rpg::EventCommand const& com) } bool Game_Interpreter::CommandControlVariables(lcf::rpg::EventCommand const& com) { // code 10220 + + if (!com.string.empty()){ + std::string periodName = Utils::LowerCase(ToString(com.string)); + int32_t outputVariable = ValueOrVariable(com.parameters[0], com.parameters[1]); + + 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; + if (periodName == "getdaylightsavings") dateOutput = tm->tm_isdst + 1; + if (periodName == "gettimestamp") dateOutput = t; + + Main_Data::game_variables->Set(outputVariable, dateOutput); + Game_Map::SetNeedRefresh(true); + + return true; + } + int value = 0; int operand = com.parameters[4]; @@ -4645,32 +4670,6 @@ 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]); - - 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; - if (periodName == "gettimestamp") dateOutput = t; - - Main_Data::game_variables->Set(outputVariable, dateOutput); - Game_Map::SetNeedRefresh(true); - - return true; -} - Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() { return Game_Battle::IsBattleRunning() ? Game_Battle::GetInterpreter()