From 31869501eebf575a7897b0270e14f96fb229a46d Mon Sep 17 00:00:00 2001 From: Rubidium Date: Tue, 31 Jan 2023 16:59:58 +0100 Subject: [PATCH] Fix: make script goals work with the whole range of ClientIDs --- src/goal.cpp | 4 +++- src/goal_cmd.h | 2 +- src/script/api/script_goal.cpp | 2 -- src/script/api/script_goal.hpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/goal.cpp b/src/goal.cpp index 447763866b..208678678d 100644 --- a/src/goal.cpp +++ b/src/goal.cpp @@ -224,9 +224,11 @@ CommandCost CmdSetGoalCompleted(DoCommandFlag flags, GoalID goal, bool completed * @param text Text of the question. * @return the cost of this operation or an error */ -CommandCost CmdGoalQuestion(DoCommandFlag flags, uint16 uniqueid, uint16 target, bool is_client, uint32 button_mask, GoalQuestionType type, const std::string &text) +CommandCost CmdGoalQuestion(DoCommandFlag flags, uint16 uniqueid, uint32 target, bool is_client, uint32 button_mask, GoalQuestionType type, const std::string &text) { + static_assert(sizeof(uint32) >= sizeof(CompanyID)); CompanyID company = (CompanyID)target; + static_assert(sizeof(uint32) >= sizeof(ClientID)); ClientID client = (ClientID)target; static_assert(GOAL_QUESTION_BUTTON_COUNT < 29); diff --git a/src/goal_cmd.h b/src/goal_cmd.h index e57d9b185c..3f5eac7d8c 100644 --- a/src/goal_cmd.h +++ b/src/goal_cmd.h @@ -18,7 +18,7 @@ CommandCost CmdRemoveGoal(DoCommandFlag flags, GoalID goal); CommandCost CmdSetGoalText(DoCommandFlag flags, GoalID goal, const std::string &text); CommandCost CmdSetGoalProgress(DoCommandFlag flags, GoalID goal, const std::string &text); CommandCost CmdSetGoalCompleted(DoCommandFlag flags, GoalID goal, bool completed); -CommandCost CmdGoalQuestion(DoCommandFlag flags, uint16 uniqueid, uint16 target, bool is_client, uint32 button_mask, GoalQuestionType type, const std::string &text); +CommandCost CmdGoalQuestion(DoCommandFlag flags, uint16 uniqueid, uint32 target, bool is_client, uint32 button_mask, GoalQuestionType type, const std::string &text); CommandCost CmdGoalQuestionAnswer(DoCommandFlag flags, uint16 uniqueid, uint8 button); DEF_CMD_TRAIT(CMD_CREATE_GOAL, CmdCreateGoal, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT) diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp index 70f040dd45..d908f4e720 100644 --- a/src/script/api/script_goal.cpp +++ b/src/script/api/script_goal.cpp @@ -137,8 +137,6 @@ { EnforcePrecondition(false, ScriptGame::IsMultiplayer()); EnforcePrecondition(false, ScriptClient::ResolveClientID(client) != ScriptClient::CLIENT_INVALID); - /* Can only send 16 bits of client_id before proper fix is implemented */ - EnforcePrecondition(false, client < (1 << 16)); return DoQuestion(uniqueid, client, true, question, type, buttons); } diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp index dda8498fe4..69f8c38f66 100644 --- a/src/script/api/script_goal.hpp +++ b/src/script/api/script_goal.hpp @@ -170,7 +170,7 @@ public: * @pre question != null && len(question) != 0. * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID. * @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3. - * @note Replies to the question are given by you via the event ScriptEvent_GoalQuestionAnswer. + * @note Replies to the question are given by you via the event ScriptEventGoalQuestionAnswer. * @note There is no guarantee you ever get a reply on your question. */ static bool Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons); @@ -188,7 +188,7 @@ public: * @pre question != null && len(question) != 0. * @pre ResolveClientID(client) != CLIENT_INVALID. * @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3. - * @note Replies to the question are given by you via the event ScriptEvent_GoalQuestionAnswer. + * @note Replies to the question are given by you via the event ScriptEventGoalQuestionAnswer. * @note There is no guarantee you ever get a reply on your question. */ static bool QuestionClient(uint16 uniqueid, ScriptClient::ClientID client, Text *question, QuestionType type, int buttons);