(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

This commit is contained in:
truebrain
2012-01-03 16:36:24 +00:00
parent e40e1325d6
commit 59de5e9570
20 changed files with 427 additions and 10 deletions

View File

@@ -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();
}