diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-11-20 22:30:56 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-12-16 22:28:32 +0100 |
commit | e6e69d528921ab731c4c38ee708ff31b7055fd27 (patch) | |
tree | 25e19470a3b2179c7c9c9b76cdc4dc7e2906dbf4 /src/goal.cpp | |
parent | 1a42a8a5d50e917a3b7158feadc70205cf912cba (diff) | |
download | openttd-e6e69d528921ab731c4c38ee708ff31b7055fd27.tar.xz |
Codechange: Un-bitstuff goal and story page commands.
Diffstat (limited to 'src/goal.cpp')
-rw-r--r-- | src/goal.cpp | 115 |
1 files changed, 46 insertions, 69 deletions
diff --git a/src/goal.cpp b/src/goal.cpp index a60853829..99322ec2c 100644 --- a/src/goal.cpp +++ b/src/goal.cpp @@ -36,49 +36,44 @@ INSTANTIATE_POOL_METHODS(Goal) /** * Create a new goal. * @param flags type of operation - * @param tile unused. - * @param p1 various bitstuffed elements - * - p1 = (bit 0 - 7) - GoalType of destination. - * - p1 = (bit 8 - 15) - Company for which this goal is. - * @param p2 GoalTypeID of destination. + * @param company Company for which this goal is. + * @param type GoalType of destination. + * @param dest GoalTypeID of destination. * @param text Text of the goal. * @return the cost of this operation or an error */ -CommandCost CmdCreateGoal(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdCreateGoal(DoCommandFlag flags, CompanyID company, GoalType type, GoalTypeID dest, const std::string &text) { if (!Goal::CanAllocateItem()) return CMD_ERROR; - GoalType type = (GoalType)GB(p1, 0, 8); - CompanyID company = (CompanyID)GB(p1, 8, 8); - if (_current_company != OWNER_DEITY) return CMD_ERROR; if (text.empty()) return CMD_ERROR; if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR; switch (type) { case GT_NONE: - if (p2 != 0) return CMD_ERROR; + if (dest != 0) return CMD_ERROR; break; case GT_TILE: - if (!IsValidTile(p2)) return CMD_ERROR; + if (!IsValidTile(dest)) return CMD_ERROR; break; case GT_INDUSTRY: - if (!Industry::IsValidID(p2)) return CMD_ERROR; + if (!Industry::IsValidID(dest)) return CMD_ERROR; break; case GT_TOWN: - if (!Town::IsValidID(p2)) return CMD_ERROR; + if (!Town::IsValidID(dest)) return CMD_ERROR; break; case GT_COMPANY: - if (!Company::IsValidID(p2)) return CMD_ERROR; + if (!Company::IsValidID(dest)) return CMD_ERROR; break; case GT_STORY_PAGE: { - if (!StoryPage::IsValidID(p2)) return CMD_ERROR; - CompanyID story_company = StoryPage::Get(p2)->company; + if (!StoryPage::IsValidID(dest)) return CMD_ERROR; + CompanyID story_company = StoryPage::Get(dest)->company; if (company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != company) return CMD_ERROR; break; } @@ -89,7 +84,7 @@ CommandCost CmdCreateGoal(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 if (flags & DC_EXEC) { Goal *g = new Goal(); g->type = type; - g->dst = p2; + g->dst = dest; g->company = company; g->text = stredup(text.c_str()); g->progress = nullptr; @@ -111,19 +106,16 @@ CommandCost CmdCreateGoal(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 /** * Remove a goal. * @param flags type of operation - * @param tile unused. - * @param p1 GoalID to remove. - * @param p2 unused. - * @param text unused. + * @param goal GoalID to remove. * @return the cost of this operation or an error */ -CommandCost CmdRemoveGoal(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdRemoveGoal(DoCommandFlag flags, GoalID goal) { if (_current_company != OWNER_DEITY) return CMD_ERROR; - if (!Goal::IsValidID(p1)) return CMD_ERROR; + if (!Goal::IsValidID(goal)) return CMD_ERROR; if (flags & DC_EXEC) { - Goal *g = Goal::Get(p1); + Goal *g = Goal::Get(goal); CompanyID c = g->company; delete g; @@ -141,20 +133,18 @@ CommandCost CmdRemoveGoal(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 /** * Update goal text of a goal. * @param flags type of operation - * @param tile unused. - * @param p1 GoalID to update. - * @param p2 unused + * @param goal GoalID to update. * @param text Text of the goal. * @return the cost of this operation or an error */ -CommandCost CmdSetGoalText(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdSetGoalText(DoCommandFlag flags, GoalID goal, const std::string &text) { if (_current_company != OWNER_DEITY) return CMD_ERROR; - if (!Goal::IsValidID(p1)) return CMD_ERROR; + if (!Goal::IsValidID(goal)) return CMD_ERROR; if (text.empty()) return CMD_ERROR; if (flags & DC_EXEC) { - Goal *g = Goal::Get(p1); + Goal *g = Goal::Get(goal); free(g->text); g->text = stredup(text.c_str()); @@ -171,19 +161,17 @@ CommandCost CmdSetGoalText(DoCommandFlag flags, TileIndex tile, uint32 p1, uint3 /** * Update progress text of a goal. * @param flags type of operation - * @param tile unused. - * @param p1 GoalID to update. - * @param p2 unused + * @param goal GoalID to update. * @param text Progress text of the goal. * @return the cost of this operation or an error */ -CommandCost CmdSetGoalProgress(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdSetGoalProgress(DoCommandFlag flags, GoalID goal, const std::string &text) { if (_current_company != OWNER_DEITY) return CMD_ERROR; - if (!Goal::IsValidID(p1)) return CMD_ERROR; + if (!Goal::IsValidID(goal)) return CMD_ERROR; if (flags & DC_EXEC) { - Goal *g = Goal::Get(p1); + Goal *g = Goal::Get(goal); free(g->progress); if (text.empty()) { g->progress = nullptr; @@ -204,20 +192,18 @@ CommandCost CmdSetGoalProgress(DoCommandFlag flags, TileIndex tile, uint32 p1, u /** * Update completed state of a goal. * @param flags type of operation - * @param tile unused. - * @param p1 GoalID to update. - * @param p2 completed state. If goal is completed, set to 1, otherwise 0. - * @param text unused + * @param goal GoalID to update. + * @param completed completed state of goal. * @return the cost of this operation or an error */ -CommandCost CmdSetGoalCompleted(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdSetGoalCompleted(DoCommandFlag flags, GoalID goal, bool completed) { if (_current_company != OWNER_DEITY) return CMD_ERROR; - if (!Goal::IsValidID(p1)) return CMD_ERROR; + if (!Goal::IsValidID(goal)) return CMD_ERROR; if (flags & DC_EXEC) { - Goal *g = Goal::Get(p1); - g->completed = p2 == 1; + Goal *g = Goal::Get(goal); + g->completed = completed; if (g->company == INVALID_COMPANY) { InvalidateWindowClassesData(WC_GOALS_LIST); @@ -232,27 +218,21 @@ CommandCost CmdSetGoalCompleted(DoCommandFlag flags, TileIndex tile, uint32 p1, /** * Ask a goal related question * @param flags type of operation - * @param tile unused. - * @param p1 various bitstuffed elements - * - p1 = (bit 0 - 15) - Unique ID to use for this question. - * - p1 = (bit 16 - 31) - Company or client for which this question is. - * @param p2 various bitstuffed elements - * - p2 = (bit 0 - 17) - Buttons of the question. - * - p2 = (bit 29 - 30) - Question type. - * - p2 = (bit 31) - Question target: 0 - company, 1 - client. + * @param uniqueid Unique ID to use for this question. + * @param target Company or client for which this question is. + * @param is_client Question target: false - company, true - client. + * @param button_mask Buttons of the question. + * @param type Question type. * @param text Text of the question. * @return the cost of this operation or an error */ -CommandCost CmdGoalQuestion(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdGoalQuestion(DoCommandFlag flags, uint16 uniqueid, uint16 target, bool is_client, uint32 button_mask, GoalQuestionType type, const std::string &text) { - uint16 uniqueid = (uint16)GB(p1, 0, 16); - CompanyID company = (CompanyID)GB(p1, 16, 8); - ClientID client = (ClientID)GB(p1, 16, 16); + CompanyID company = (CompanyID)target; + ClientID client = (ClientID)target; static_assert(GOAL_QUESTION_BUTTON_COUNT < 29); - uint32 button_mask = GB(p2, 0, GOAL_QUESTION_BUTTON_COUNT); - byte type = GB(p2, 29, 2); - bool is_client = HasBit(p2, 31); + button_mask &= (1U << GOAL_QUESTION_BUTTON_COUNT) - 1; if (_current_company != OWNER_DEITY) return CMD_ERROR; if (text.empty()) return CMD_ERROR; @@ -284,31 +264,28 @@ CommandCost CmdGoalQuestion(DoCommandFlag flags, TileIndex tile, uint32 p1, uint /** * Reply to a goal question. * @param flags type of operation - * @param tile unused. - * @param p1 Unique ID to use for this question. - * @param p2 Button the company pressed - * @param text Text of the question. + * @param uniqueid Unique ID to use for this question. + * @param button Button the company pressed * @return the cost of this operation or an error */ -CommandCost CmdGoalQuestionAnswer(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) +CommandCost CmdGoalQuestionAnswer(DoCommandFlag flags, uint16 uniqueid, uint8 button) { - if (p1 > UINT16_MAX) return CMD_ERROR; - if (p2 >= GOAL_QUESTION_BUTTON_COUNT) return CMD_ERROR; + if (button >= GOAL_QUESTION_BUTTON_COUNT) return CMD_ERROR; if (_current_company == OWNER_DEITY) { /* It has been requested to close this specific question on all clients */ - if (flags & DC_EXEC) CloseWindowById(WC_GOAL_QUESTION, p1); + if (flags & DC_EXEC) CloseWindowById(WC_GOAL_QUESTION, uniqueid); return CommandCost(); } if (_networking && _local_company == _current_company) { /* Somebody in the same company answered the question. Close the window */ - if (flags & DC_EXEC) CloseWindowById(WC_GOAL_QUESTION, p1); + if (flags & DC_EXEC) CloseWindowById(WC_GOAL_QUESTION, uniqueid); if (!_network_server) return CommandCost(); } if (flags & DC_EXEC) { - Game::NewEvent(new ScriptEventGoalQuestionAnswer(p1, (ScriptCompany::CompanyID)(byte)_current_company, (ScriptGoal::QuestionButton)(1 << p2))); + Game::NewEvent(new ScriptEventGoalQuestionAnswer(uniqueid, (ScriptCompany::CompanyID)(byte)_current_company, (ScriptGoal::QuestionButton)(1 << button))); } return CommandCost(); |