1
0
Fork 0

Codechange: Use SQInteger for generic numbers in script_goal

pull/10532/head
glx22 2023-02-11 19:02:23 +01:00 committed by Loïc Guilloux
parent e784915b27
commit 6ca8499e6a
2 changed files with 16 additions and 11 deletions

View File

@ -28,7 +28,7 @@
return ::Goal::IsValidID(goal_id);
}
/* static */ ScriptGoal::GoalID ScriptGoal::New(ScriptCompany::CompanyID company, Text *goal, GoalType type, uint32 destination)
/* static */ ScriptGoal::GoalID ScriptGoal::New(ScriptCompany::CompanyID company, Text *goal, GoalType type, SQInteger destination)
{
CCountedPtr<Text> counter(goal);
@ -104,7 +104,7 @@
return g != nullptr && g->completed;
}
/* static */ bool ScriptGoal::DoQuestion(uint16 uniqueid, uint32 target, bool is_client, Text *question, QuestionType type, uint32 buttons)
/* static */ bool ScriptGoal::DoQuestion(SQInteger uniqueid, uint32 target, bool is_client, Text *question, QuestionType type, SQInteger buttons)
{
CCountedPtr<Text> counter(question);
@ -114,13 +114,14 @@
EnforcePreconditionEncodedText(false, text);
uint min_buttons = (type == QT_QUESTION ? 1 : 0);
EnforcePrecondition(false, CountBits(buttons) >= min_buttons && CountBits(buttons) <= 3);
EnforcePrecondition(false, buttons < (1 << ::GOAL_QUESTION_BUTTON_COUNT));
EnforcePrecondition(false, buttons >= 0 && buttons < (1 << ::GOAL_QUESTION_BUTTON_COUNT));
EnforcePrecondition(false, (int)type < ::GQT_END);
EnforcePrecondition(false, uniqueid >= 0 && uniqueid <= UINT16_MAX);
return ScriptObject::Command<CMD_GOAL_QUESTION>::Do(uniqueid, target, is_client, buttons, (::GoalQuestionType)type, text);
}
/* static */ bool ScriptGoal::Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons)
/* static */ bool ScriptGoal::Question(SQInteger uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, SQInteger buttons)
{
EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
uint8 c = company;
@ -129,16 +130,17 @@
return DoQuestion(uniqueid, c, false, question, type, buttons);
}
/* static */ bool ScriptGoal::QuestionClient(uint16 uniqueid, ScriptClient::ClientID client, Text *question, QuestionType type, int buttons)
/* static */ bool ScriptGoal::QuestionClient(SQInteger uniqueid, ScriptClient::ClientID client, Text *question, QuestionType type, SQInteger buttons)
{
EnforcePrecondition(false, ScriptGame::IsMultiplayer());
EnforcePrecondition(false, ScriptClient::ResolveClientID(client) != ScriptClient::CLIENT_INVALID);
return DoQuestion(uniqueid, client, true, question, type, buttons);
}
/* static */ bool ScriptGoal::CloseQuestion(uint16 uniqueid)
/* static */ bool ScriptGoal::CloseQuestion(SQInteger uniqueid)
{
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(false, uniqueid >= 0 && uniqueid <= UINT16_MAX);
return ScriptObject::Command<CMD_GOAL_QUESTION_ANSWER>::Do(uniqueid, 0);
}

View File

@ -103,7 +103,7 @@ public:
* \li Global goals can only reference global story pages.
* \li Company specific goals can reference global story pages and story pages of the same company.
*/
static GoalID New(ScriptCompany::CompanyID company, Text *goal, GoalType type, uint32 destination);
static GoalID New(ScriptCompany::CompanyID company, Text *goal, GoalType type, SQInteger destination);
/**
* Remove a goal from the list.
@ -170,10 +170,11 @@ public:
* @pre question != null && len(question) != 0.
* @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
* @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3.
* @pre uniqueid >= 0 && uniqueid <= MAX(uint16)
* @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);
static bool Question(SQInteger uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, SQInteger buttons);
/**
* Ask client a question.
@ -188,28 +189,30 @@ public:
* @pre question != null && len(question) != 0.
* @pre ResolveClientID(client) != CLIENT_INVALID.
* @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3.
* @pre uniqueid >= 0 && uniqueid <= MAX(uint16)
* @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);
static bool QuestionClient(SQInteger uniqueid, ScriptClient::ClientID client, Text *question, QuestionType type, SQInteger buttons);
/**
* Close the question on all clients.
* @param uniqueid The uniqueid of the question you want to close.
* @return True if the action succeeded.
* @pre No ScriptCompanyMode may be in scope.
* @pre uniqueid >= 0 && uniqueid <= MAX(uint16)
* @note If you send a question to a single company, and get a reply for them,
* the question is already closed on all clients. Only use this function if
* you want to timeout a question, or if you send the question to all
* companies, but you are only interested in the reply of the first.
*/
static bool CloseQuestion(uint16 uniqueid);
static bool CloseQuestion(SQInteger uniqueid);
protected:
/**
* Does common checks and asks the question.
*/
static bool DoQuestion(uint16 uniqueid, uint32 target, bool is_client, Text *question, QuestionType type, uint32 buttons);
static bool DoQuestion(SQInteger uniqueid, uint32 target, bool is_client, Text *question, QuestionType type, SQInteger buttons);
};
#endif /* SCRIPT_GOAL_HPP */