2011-12-19 21:03:17 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file script_goal.hpp Everything to manipulate the current running goal. */
|
|
|
|
|
|
|
|
#ifndef SCRIPT_GOAL_HPP
|
|
|
|
#define SCRIPT_GOAL_HPP
|
|
|
|
|
2018-04-28 15:37:59 +00:00
|
|
|
#include "script_client.hpp"
|
2011-12-19 21:03:17 +00:00
|
|
|
#include "script_company.hpp"
|
|
|
|
#include "../../goal_type.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class that handles some goal related functions.
|
2013-02-10 19:49:04 +00:00
|
|
|
*
|
|
|
|
* Goals are saved and loaded. Upon bankruptcy or company takeover, all company
|
|
|
|
* specific goals are removed for that company. You can also remove individual
|
|
|
|
* goals using #Remove.
|
|
|
|
*
|
2011-12-19 21:03:17 +00:00
|
|
|
* @api game
|
|
|
|
*/
|
|
|
|
class ScriptGoal : public ScriptObject {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* The goal IDs.
|
|
|
|
*/
|
2024-01-07 16:41:53 +00:00
|
|
|
enum GoalID : uint16_t {
|
2011-12-19 21:03:17 +00:00
|
|
|
/* Note: these values represent part of the in-game GoalID enum */
|
2023-02-01 22:35:51 +00:00
|
|
|
GOAL_INVALID = ::INVALID_GOAL, ///< An invalid goal id.
|
2011-12-19 21:03:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Goal types that can be given to a goal.
|
|
|
|
*/
|
2020-06-27 12:59:15 +00:00
|
|
|
enum GoalType : byte {
|
2011-12-19 21:03:17 +00:00
|
|
|
/* Note: these values represent part of the in-game GoalType enum */
|
|
|
|
GT_NONE = ::GT_NONE, ///< Destination is not linked.
|
|
|
|
GT_TILE = ::GT_TILE, ///< Destination is a tile.
|
|
|
|
GT_INDUSTRY = ::GT_INDUSTRY, ///< Destination is an industry.
|
|
|
|
GT_TOWN = ::GT_TOWN, ///< Destination is a town.
|
|
|
|
GT_COMPANY = ::GT_COMPANY, ///< Destination is a company.
|
2013-11-16 17:41:57 +00:00
|
|
|
GT_STORY_PAGE = ::GT_STORY_PAGE ///< Destination is a story page.
|
2011-12-19 21:03:17 +00:00
|
|
|
};
|
|
|
|
|
2012-01-21 12:03:55 +00:00
|
|
|
/**
|
|
|
|
* Types of queries we could do to the user.
|
|
|
|
* Basically the title of the question window.
|
|
|
|
*/
|
|
|
|
enum QuestionType {
|
|
|
|
QT_QUESTION, ///< Asking a simple question; title: Question.
|
|
|
|
QT_INFORMATION, ///< Showing an informational message; title: Information.
|
|
|
|
QT_WARNING, ///< Showing a warning; title: Warning.
|
|
|
|
QT_ERROR, ///< Showing an error; title: Error.
|
|
|
|
};
|
|
|
|
|
2013-07-13 06:38:54 +00:00
|
|
|
/**
|
|
|
|
* Types of buttons that can be in the question window.
|
|
|
|
*/
|
2012-01-03 16:36:24 +00:00
|
|
|
enum QuestionButton {
|
|
|
|
/* Note: these values represent part of the string list starting with STR_GOAL_QUESTION_BUTTON_CANCEL */
|
|
|
|
BUTTON_CANCEL = (1 << 0), ///< Cancel button.
|
|
|
|
BUTTON_OK = (1 << 1), ///< OK button.
|
|
|
|
BUTTON_NO = (1 << 2), ///< No button.
|
|
|
|
BUTTON_YES = (1 << 3), ///< Yes button.
|
|
|
|
BUTTON_DECLINE = (1 << 4), ///< Decline button.
|
|
|
|
BUTTON_ACCEPT = (1 << 5), ///< Accept button.
|
|
|
|
BUTTON_IGNORE = (1 << 6), ///< Ignore button.
|
|
|
|
BUTTON_RETRY = (1 << 7), ///< Retry button.
|
|
|
|
BUTTON_PREVIOUS = (1 << 8), ///< Previous button.
|
|
|
|
BUTTON_NEXT = (1 << 9), ///< Next button.
|
|
|
|
BUTTON_STOP = (1 << 10), ///< Stop button.
|
|
|
|
BUTTON_START = (1 << 11), ///< Start button.
|
|
|
|
BUTTON_GO = (1 << 12), ///< Go button.
|
|
|
|
BUTTON_CONTINUE = (1 << 13), ///< Continue button.
|
|
|
|
BUTTON_RESTART = (1 << 14), ///< Restart button.
|
|
|
|
BUTTON_POSTPONE = (1 << 15), ///< Postpone button.
|
|
|
|
BUTTON_SURRENDER = (1 << 16), ///< Surrender button.
|
|
|
|
BUTTON_CLOSE = (1 << 17), ///< Close button.
|
|
|
|
};
|
|
|
|
|
2011-12-19 21:03:17 +00:00
|
|
|
/**
|
|
|
|
* Check whether this is a valid goalID.
|
|
|
|
* @param goal_id The GoalID to check.
|
|
|
|
* @return True if and only if this goal is valid.
|
|
|
|
*/
|
|
|
|
static bool IsValidGoal(GoalID goal_id);
|
|
|
|
|
2023-06-08 17:00:31 +00:00
|
|
|
/**
|
|
|
|
* Check whether this is a valid goal destination.
|
|
|
|
* @param company The relevant company if a story page is the destination.
|
|
|
|
* @param type The type of the goal.
|
|
|
|
* @param destination The destination of the \a type type.
|
|
|
|
* @return True if and only if this goal destination is valid.
|
|
|
|
*/
|
|
|
|
static bool IsValidGoalDestination(ScriptCompany::CompanyID company, GoalType type, SQInteger destination);
|
|
|
|
|
2011-12-19 21:03:17 +00:00
|
|
|
/**
|
|
|
|
* Create a new goal.
|
|
|
|
* @param company The company to create the goal for, or ScriptCompany::COMPANY_INVALID for all.
|
2011-12-19 21:06:06 +00:00
|
|
|
* @param goal The goal to add to the GUI (can be either a raw string, or a ScriptText object).
|
2011-12-19 21:03:17 +00:00
|
|
|
* @param type The type of the goal.
|
2012-07-10 18:37:54 +00:00
|
|
|
* @param destination The destination of the \a type type.
|
2011-12-19 21:03:17 +00:00
|
|
|
* @return The new GoalID, or GOAL_INVALID if it failed.
|
2023-03-02 18:44:13 +00:00
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
2023-01-25 22:44:58 +00:00
|
|
|
* @pre goal != null && len(goal) != 0.
|
2011-12-19 21:03:17 +00:00
|
|
|
* @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
|
2013-11-16 17:41:57 +00:00
|
|
|
* @pre if type is GT_STORY_PAGE, the company of the goal and the company of the story page need to match:
|
|
|
|
* \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.
|
2011-12-19 21:03:17 +00:00
|
|
|
*/
|
2023-02-11 18:02:23 +00:00
|
|
|
static GoalID New(ScriptCompany::CompanyID company, Text *goal, GoalType type, SQInteger destination);
|
2011-12-19 21:03:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a goal from the list.
|
|
|
|
* @param goal_id The goal to remove.
|
|
|
|
* @return True if the action succeeded.
|
2023-03-02 18:44:13 +00:00
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
2011-12-19 21:03:17 +00:00
|
|
|
* @pre IsValidGoal(goal_id).
|
|
|
|
*/
|
|
|
|
static bool Remove(GoalID goal_id);
|
2012-01-03 16:36:24 +00:00
|
|
|
|
2023-06-08 17:00:31 +00:00
|
|
|
/**
|
|
|
|
* Update goal destination of a goal.
|
|
|
|
* @param goal_id The goal to update.
|
|
|
|
* @param type The type of the goal.
|
|
|
|
* @param destination The destination of the \a type type.
|
|
|
|
* @return True if the action succeeded.
|
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
|
|
|
* @pre IsValidGoal(goal_id).
|
|
|
|
* @pre IsValidGoalDestination(g->company, type, destination).
|
|
|
|
*/
|
|
|
|
static bool SetDestination(GoalID goal_id, GoalType type, SQInteger destination);
|
|
|
|
|
2013-05-26 19:54:43 +00:00
|
|
|
/**
|
|
|
|
* Update goal text of a goal.
|
|
|
|
* @param goal_id The goal to update.
|
|
|
|
* @param goal The new goal text (can be either a raw string, or a ScriptText object).
|
|
|
|
* @return True if the action succeeded.
|
2023-03-02 18:44:13 +00:00
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
2023-01-25 22:44:58 +00:00
|
|
|
* @pre goal != null && len(goal) != 0.
|
2013-05-26 19:54:43 +00:00
|
|
|
* @pre IsValidGoal(goal_id).
|
|
|
|
*/
|
|
|
|
static bool SetText(GoalID goal_id, Text *goal);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the progress text of a goal. The progress text is a text that
|
|
|
|
* is shown adjacent to the goal but in a separate column. Try to keep
|
|
|
|
* the progress string short.
|
|
|
|
* @param goal_id The goal to update.
|
|
|
|
* @param progress The new progress text for the goal (can be either a raw string,
|
2023-01-25 22:44:58 +00:00
|
|
|
* or a ScriptText object). To clear the progress string you can pass null or an
|
2013-05-26 19:54:43 +00:00
|
|
|
* empty string.
|
|
|
|
* @return True if the action succeeded.
|
2023-03-02 18:44:13 +00:00
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
2013-05-26 19:54:43 +00:00
|
|
|
* @pre IsValidGoal(goal_id).
|
|
|
|
*/
|
|
|
|
static bool SetProgress(GoalID goal_id, Text *progress);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update completed status of goal
|
|
|
|
* @param goal_id The goal to update.
|
|
|
|
* @param complete The new goal completed status.
|
|
|
|
* @return True if the action succeeded.
|
2023-03-02 18:44:13 +00:00
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
2013-05-26 19:54:43 +00:00
|
|
|
* @pre IsValidGoal(goal_id).
|
|
|
|
*/
|
|
|
|
static bool SetCompleted(GoalID goal_id, bool complete);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a given goal have been marked as completed.
|
|
|
|
* @param goal_id The goal to check complete status.
|
|
|
|
* @return True if the goal is completed, otherwise false.
|
2023-03-02 18:44:13 +00:00
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
2013-05-26 19:54:43 +00:00
|
|
|
* @pre IsValidGoal(goal_id).
|
|
|
|
*/
|
|
|
|
static bool IsCompleted(GoalID goal_id);
|
|
|
|
|
2012-01-03 16:36:24 +00:00
|
|
|
/**
|
2018-04-28 15:37:59 +00:00
|
|
|
* Ask a question of all players in a company.
|
2012-01-03 16:36:24 +00:00
|
|
|
* @param uniqueid Your unique id to distinguish results of multiple questions in the returning event.
|
|
|
|
* @param company The company to ask the question, or ScriptCompany::COMPANY_INVALID for all.
|
|
|
|
* @param question The question to ask (can be either a raw string, or a ScriptText object).
|
2012-01-21 12:03:55 +00:00
|
|
|
* @param type The type of question that is being asked.
|
2012-01-03 16:36:24 +00:00
|
|
|
* @param buttons Any combinations (at least 1, up to 3) of buttons defined in QuestionButton. Like BUTTON_YES + BUTTON_NO.
|
|
|
|
* @return True if the action succeeded.
|
2023-03-02 18:44:13 +00:00
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
2023-01-25 22:44:58 +00:00
|
|
|
* @pre question != null && len(question) != 0.
|
2012-01-03 16:36:24 +00:00
|
|
|
* @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
|
|
|
|
* @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3.
|
2024-01-07 16:41:53 +00:00
|
|
|
* @pre uniqueid >= 0 && uniqueid <= MAX(uint16_t)
|
2023-01-31 15:59:58 +00:00
|
|
|
* @note Replies to the question are given by you via the event ScriptEventGoalQuestionAnswer.
|
2012-01-03 16:36:24 +00:00
|
|
|
* @note There is no guarantee you ever get a reply on your question.
|
|
|
|
*/
|
2023-02-11 18:02:23 +00:00
|
|
|
static bool Question(SQInteger uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, SQInteger buttons);
|
2012-01-03 16:36:24 +00:00
|
|
|
|
2018-04-28 15:37:59 +00:00
|
|
|
/**
|
|
|
|
* Ask client a question.
|
|
|
|
* @param uniqueid Your unique id to distinguish results of multiple questions in the returning event.
|
|
|
|
* @param client The client to ask the question.
|
|
|
|
* @param question The question to ask (can be either a raw string, or a ScriptText object).
|
|
|
|
* @param type The type of question that is being asked.
|
|
|
|
* @param buttons Any combinations (at least 1, up to 3) of buttons defined in QuestionButton. Like BUTTON_YES + BUTTON_NO.
|
|
|
|
* @return True if the action succeeded.
|
2023-03-02 18:44:13 +00:00
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
2018-04-28 15:37:59 +00:00
|
|
|
* @pre ScriptGame::IsMultiplayer()
|
2023-01-25 22:44:58 +00:00
|
|
|
* @pre question != null && len(question) != 0.
|
2018-04-28 15:37:59 +00:00
|
|
|
* @pre ResolveClientID(client) != CLIENT_INVALID.
|
|
|
|
* @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3.
|
2024-01-07 16:41:53 +00:00
|
|
|
* @pre uniqueid >= 0 && uniqueid <= MAX(uint16_t)
|
2023-01-31 15:59:58 +00:00
|
|
|
* @note Replies to the question are given by you via the event ScriptEventGoalQuestionAnswer.
|
2018-04-28 15:37:59 +00:00
|
|
|
* @note There is no guarantee you ever get a reply on your question.
|
|
|
|
*/
|
2023-02-11 18:02:23 +00:00
|
|
|
static bool QuestionClient(SQInteger uniqueid, ScriptClient::ClientID client, Text *question, QuestionType type, SQInteger buttons);
|
2018-04-28 15:37:59 +00:00
|
|
|
|
2012-01-03 16:36:24 +00:00
|
|
|
/**
|
|
|
|
* Close the question on all clients.
|
|
|
|
* @param uniqueid The uniqueid of the question you want to close.
|
|
|
|
* @return True if the action succeeded.
|
2023-03-02 18:44:13 +00:00
|
|
|
* @pre ScriptCompanyMode::IsDeity().
|
2024-01-07 16:41:53 +00:00
|
|
|
* @pre uniqueid >= 0 && uniqueid <= MAX(uint16_t)
|
2012-01-03 16:36:24 +00:00
|
|
|
* @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.
|
|
|
|
*/
|
2023-02-11 18:02:23 +00:00
|
|
|
static bool CloseQuestion(SQInteger uniqueid);
|
2018-04-28 15:37:59 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Does common checks and asks the question.
|
|
|
|
*/
|
2024-01-07 16:41:53 +00:00
|
|
|
static bool DoQuestion(SQInteger uniqueid, uint32_t target, bool is_client, Text *question, QuestionType type, SQInteger buttons);
|
2011-12-19 21:03:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SCRIPT_GOAL_HPP */
|