4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file script_goal.hpp Everything to manipulate the current running goal. */
12 #ifndef SCRIPT_GOAL_HPP
13 #define SCRIPT_GOAL_HPP
15 #include "script_company.hpp"
16 #include "../../goal_type.h"
19 * Class that handles some goal related functions.
21 * Goals are saved and loaded. Upon bankruptcy or company takeover, all company
22 * specific goals are removed for that company. You can also remove individual
23 * goals using #Remove.
27 class ScriptGoal
: public ScriptObject
{
33 /* Note: these values represent part of the in-game GoalID enum */
34 GOAL_INVALID
= ::INVALID_GOALTYPE
, ///< An invalid goal id.
38 * Goal types that can be given to a goal.
41 /* Note: these values represent part of the in-game GoalType enum */
42 GT_NONE
= ::GT_NONE
, ///< Destination is not linked.
43 GT_TILE
= ::GT_TILE
, ///< Destination is a tile.
44 GT_INDUSTRY
= ::GT_INDUSTRY
, ///< Destination is an industry.
45 GT_TOWN
= ::GT_TOWN
, ///< Destination is a town.
46 GT_COMPANY
= ::GT_COMPANY
, ///< Destination is a company.
47 GT_STORY_PAGE
= ::GT_STORY_PAGE
///< Destination is a story page.
51 * Types of queries we could do to the user.
52 * Basically the title of the question window.
55 QT_QUESTION
, ///< Asking a simple question; title: Question.
56 QT_INFORMATION
, ///< Showing an informational message; title: Information.
57 QT_WARNING
, ///< Showing a warning; title: Warning.
58 QT_ERROR
, ///< Showing an error; title: Error.
62 * Types of buttons that can be in the question window.
65 /* Note: these values represent part of the string list starting with STR_GOAL_QUESTION_BUTTON_CANCEL */
66 BUTTON_CANCEL
= (1 << 0), ///< Cancel button.
67 BUTTON_OK
= (1 << 1), ///< OK button.
68 BUTTON_NO
= (1 << 2), ///< No button.
69 BUTTON_YES
= (1 << 3), ///< Yes button.
70 BUTTON_DECLINE
= (1 << 4), ///< Decline button.
71 BUTTON_ACCEPT
= (1 << 5), ///< Accept button.
72 BUTTON_IGNORE
= (1 << 6), ///< Ignore button.
73 BUTTON_RETRY
= (1 << 7), ///< Retry button.
74 BUTTON_PREVIOUS
= (1 << 8), ///< Previous button.
75 BUTTON_NEXT
= (1 << 9), ///< Next button.
76 BUTTON_STOP
= (1 << 10), ///< Stop button.
77 BUTTON_START
= (1 << 11), ///< Start button.
78 BUTTON_GO
= (1 << 12), ///< Go button.
79 BUTTON_CONTINUE
= (1 << 13), ///< Continue button.
80 BUTTON_RESTART
= (1 << 14), ///< Restart button.
81 BUTTON_POSTPONE
= (1 << 15), ///< Postpone button.
82 BUTTON_SURRENDER
= (1 << 16), ///< Surrender button.
83 BUTTON_CLOSE
= (1 << 17), ///< Close button.
87 * Check whether this is a valid goalID.
88 * @param goal_id The GoalID to check.
89 * @return True if and only if this goal is valid.
91 static bool IsValidGoal(GoalID goal_id
);
95 * @param company The company to create the goal for, or ScriptCompany::COMPANY_INVALID for all.
96 * @param goal The goal to add to the GUI (can be either a raw string, or a ScriptText object).
97 * @param type The type of the goal.
98 * @param destination The destination of the \a type type.
99 * @return The new GoalID, or GOAL_INVALID if it failed.
100 * @pre No ScriptCompanyMode may be in scope.
101 * @pre goal != NULL && len(goal) != 0.
102 * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
103 * @pre if type is GT_STORY_PAGE, the company of the goal and the company of the story page need to match:
104 * \li Global goals can only reference global story pages.
105 * \li Company specific goals can reference global story pages and story pages of the same company.
107 static GoalID
New(ScriptCompany::CompanyID company
, Text
*goal
, GoalType type
, uint32 destination
);
110 * Remove a goal from the list.
111 * @param goal_id The goal to remove.
112 * @return True if the action succeeded.
113 * @pre No ScriptCompanyMode may be in scope.
114 * @pre IsValidGoal(goal_id).
116 static bool Remove(GoalID goal_id
);
119 * Update goal text of a goal.
120 * @param goal_id The goal to update.
121 * @param goal The new goal text (can be either a raw string, or a ScriptText object).
122 * @return True if the action succeeded.
123 * @pre No ScriptCompanyMode may be in scope.
124 * @pre goal != NULL && len(goal) != 0.
125 * @pre IsValidGoal(goal_id).
127 static bool SetText(GoalID goal_id
, Text
*goal
);
130 * Update the progress text of a goal. The progress text is a text that
131 * is shown adjacent to the goal but in a separate column. Try to keep
132 * the progress string short.
133 * @param goal_id The goal to update.
134 * @param progress The new progress text for the goal (can be either a raw string,
135 * or a ScriptText object). To clear the progress string you can pass NULL or an
137 * @return True if the action succeeded.
138 * @pre No ScriptCompanyMode may be in scope.
139 * @pre IsValidGoal(goal_id).
141 static bool SetProgress(GoalID goal_id
, Text
*progress
);
144 * Update completed status of goal
145 * @param goal_id The goal to update.
146 * @param complete The new goal completed status.
147 * @return True if the action succeeded.
148 * @pre No ScriptCompanyMode may be in scope.
149 * @pre IsValidGoal(goal_id).
151 static bool SetCompleted(GoalID goal_id
, bool complete
);
154 * Checks if a given goal have been marked as completed.
155 * @param goal_id The goal to check complete status.
156 * @return True if the goal is completed, otherwise false.
157 * @pre No ScriptCompanyMode may be in scope.
158 * @pre IsValidGoal(goal_id).
160 static bool IsCompleted(GoalID goal_id
);
164 * @param uniqueid Your unique id to distinguish results of multiple questions in the returning event.
165 * @param company The company to ask the question, or ScriptCompany::COMPANY_INVALID for all.
166 * @param question The question to ask (can be either a raw string, or a ScriptText object).
167 * @param type The type of question that is being asked.
168 * @param buttons Any combinations (at least 1, up to 3) of buttons defined in QuestionButton. Like BUTTON_YES + BUTTON_NO.
169 * @return True if the action succeeded.
170 * @pre No ScriptCompanyMode may be in scope.
171 * @pre question != NULL && len(question) != 0.
172 * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
173 * @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3.
174 * @note Replies to the question are given by you via the event ScriptEvent_GoalQuestionAnswer.
175 * @note There is no guarantee you ever get a reply on your question.
177 static bool Question(uint16 uniqueid
, ScriptCompany::CompanyID company
, Text
*question
, QuestionType type
, int buttons
);
180 * Close the question on all clients.
181 * @param uniqueid The uniqueid of the question you want to close.
182 * @return True if the action succeeded.
183 * @pre No ScriptCompanyMode may be in scope.
184 * @note If you send a question to a single company, and get a reply for them,
185 * the question is already closed on all clients. Only use this function if
186 * you want to timeout a question, or if you send the question to all
187 * companies, but you are only interested in the reply of the first.
189 static bool CloseQuestion(uint16 uniqueid
);
192 #endif /* SCRIPT_GOAL_HPP */