summaryrefslogtreecommitdiff
path: root/src/goal.cpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2012-01-03 16:36:24 +0000
committertruebrain <truebrain@openttd.org>2012-01-03 16:36:24 +0000
commit34d90da509a27c4abe35c11d7f034b1e386cd968 (patch)
tree552a11c264ee5b26ad849818f50f45bf9927735c /src/goal.cpp
parent18ac3f2bd89aa11fefa64bdada287a72937ab8d5 (diff)
downloadopenttd-34d90da509a27c4abe35c11d7f034b1e386cd968.tar.xz
(svn r23731) -Add: add GSGoal::Question(), to ask a question to a(ll) company(ies). It can contain random text, and at most 3 buttons from a collection of 17
Diffstat (limited to 'src/goal.cpp')
-rw-r--r--src/goal.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/goal.cpp b/src/goal.cpp
index 91ba6d288..5a3433573 100644
--- a/src/goal.cpp
+++ b/src/goal.cpp
@@ -26,6 +26,8 @@
#include "command_func.h"
#include "company_base.h"
#include "string_func.h"
+#include "gui.h"
+#include "network/network.h"
#include "table/strings.h"
@@ -118,3 +120,65 @@ CommandCost CmdRemoveGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
return CommandCost();
}
+
+
+/**
+ * Ask a goal related question
+ * @param tile unused.
+ * @param flags type of operation
+ * @param p1 various bitstuffed elements
+ * - p1 = (bit 0 - 15) - Unique ID to use for this question.
+ * - p1 = (bit 16 - 23) - Company for which this question is.
+ * @param p2 Buttons of the question.
+ * @param text Text of the question.
+ * @return the cost of this operation or an error
+ */
+CommandCost CmdGoalQuestion(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
+{
+ uint16 uniqueid = (GoalType)GB(p1, 0, 16);
+ CompanyID company = (CompanyID)GB(p1, 16, 8);
+
+ if (_current_company != OWNER_DEITY) return CMD_ERROR;
+ if (StrEmpty(text)) return CMD_ERROR;
+ if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
+ if (CountBits(p2) < 1 || CountBits(p2) > 3) return CMD_ERROR;
+
+ if (flags & DC_EXEC) {
+ if (company == _local_company || (company == INVALID_COMPANY && Company::IsValidID(_local_company))) ShowGoalQuestion(uniqueid, p2, text);
+ }
+
+ return CommandCost();
+}
+
+/**
+ * Reply to a goal question.
+ * @param tile unused.
+ * @param flags type of operation
+ * @param p1 Unique ID to use for this question.
+ * @param p2 Button the company pressed
+ * @param text Text of the question.
+ * @return the cost of this operation or an error
+ */
+CommandCost CmdGoalQuestionAnswer(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
+{
+ if (p1 > UINT16_MAX) return CMD_ERROR;
+ if (p2 >= 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) DeleteWindowById(WC_GOAL_QUESTION, p1);
+ return CommandCost();
+ }
+
+ if (_networking && _local_company == _current_company) {
+ /* Somebody in the same company answered the question. Close the window */
+ if (flags & DC_EXEC) DeleteWindowById(WC_GOAL_QUESTION, p1);
+ if (!_network_server) return CommandCost();
+ }
+
+ if (flags & DC_EXEC) {
+ Game::NewEvent(new ScriptEventGoalQuestionAnswer(p1, (ScriptCompany::CompanyID)(byte)_current_company, (ScriptGoal::QuestionButton)(1 << p2)));
+ }
+
+ return CommandCost();
+}