Command: Use auxiliary data for league command strings
This commit is contained in:
@@ -222,6 +222,7 @@ add_files(
|
||||
language.h
|
||||
league_base.h
|
||||
league_cmd.cpp
|
||||
league_cmd.h
|
||||
league_gui.h
|
||||
league_gui.cpp
|
||||
league_type.h
|
||||
|
@@ -259,7 +259,7 @@ CommandProc CmdSetTimetableStart;
|
||||
|
||||
CommandProc CmdOpenCloseAirport;
|
||||
|
||||
CommandProc CmdCreateLeagueTable;
|
||||
CommandProcEx CmdCreateLeagueTable;
|
||||
CommandProcEx CmdCreateLeagueTableElement;
|
||||
CommandProc CmdUpdateLeagueTableElementData;
|
||||
CommandProcEx CmdUpdateLeagueTableElementScore;
|
||||
@@ -510,8 +510,8 @@ static const Command _command_proc_table[] = {
|
||||
|
||||
DEF_CMD(CmdOpenCloseAirport, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_OPEN_CLOSE_AIRPORT
|
||||
|
||||
DEF_CMD(CmdCreateLeagueTable, CMD_STR_SEP | CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_LEAGUE_TABLE
|
||||
DEF_CMD(CmdCreateLeagueTableElement, CMD_STR_SEP | CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_LEAGUE_TABLE_ELEMENT
|
||||
DEF_CMD(CmdCreateLeagueTable, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_LEAGUE_TABLE
|
||||
DEF_CMD(CmdCreateLeagueTableElement, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_LEAGUE_TABLE_ELEMENT
|
||||
DEF_CMD(CmdUpdateLeagueTableElementData, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_UPDATE_LEAGUE_TABLE_ELEMENT_DATA
|
||||
DEF_CMD(CmdUpdateLeagueTableElementScore, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_UPDATE_LEAGUE_TABLE_ELEMENT_SCORE
|
||||
DEF_CMD(CmdRemoveLeagueTableElement, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_LEAGUE_TABLE_ELEMENT
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "league_base.h"
|
||||
#include "league_cmd.h"
|
||||
#include "command_type.h"
|
||||
#include "command_func.h"
|
||||
#include "industry.h"
|
||||
@@ -175,28 +176,22 @@ CommandCost CmdRemoveLeagueTableElement(DoCommandFlag flags, LeagueTableElementI
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
CommandCost CmdCreateLeagueTable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
CommandCost CmdCreateLeagueTable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, uint64 p3, const char *text, const CommandAuxiliaryBase *aux_data)
|
||||
{
|
||||
std::string title, header, footer;
|
||||
text = StrConsumeToSeparator(title, text);
|
||||
if (text == nullptr) return CMD_ERROR;
|
||||
text = StrConsumeToSeparator(header, text);
|
||||
if (text == nullptr) return CMD_ERROR;
|
||||
text = StrConsumeToSeparator(footer, text);
|
||||
if (text != nullptr) return CMD_ERROR;
|
||||
CommandAuxData<LeagueTableCmdData> data;
|
||||
CommandCost ret = data.Load(aux_data);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
auto [res, id] = CmdCreateLeagueTable(flags, title, header, footer);
|
||||
auto [res, id] = CmdCreateLeagueTable(flags, data->title, data->header, data->footer);
|
||||
res.SetResultData(id);
|
||||
return res;
|
||||
}
|
||||
|
||||
CommandCost CmdCreateLeagueTableElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, uint64 p3, const char *text, const CommandAuxiliaryBase *aux_data)
|
||||
{
|
||||
std::string text_str, score;
|
||||
text = StrConsumeToSeparator(text_str, text);
|
||||
if (text == nullptr) return CMD_ERROR;
|
||||
text = StrConsumeToSeparator(score, text);
|
||||
if (text != nullptr) return CMD_ERROR;
|
||||
CommandAuxData<LeagueTableElementCmdData> data;
|
||||
CommandCost ret = data.Load(aux_data);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
LeagueTableID table = GB(p1, 0, 8);
|
||||
int64 rating = p3;
|
||||
@@ -204,21 +199,13 @@ CommandCost CmdCreateLeagueTableElement(TileIndex tile, DoCommandFlag flags, uin
|
||||
LinkType link_type = (LinkType)GB(p1, 16, 8);
|
||||
LinkTargetID link_target = (LinkTargetID)p2;
|
||||
|
||||
auto [res, id] = CmdCreateLeagueTableElement(flags, table, rating, company, text_str, score, link_type, link_target);
|
||||
auto [res, id] = CmdCreateLeagueTableElement(flags, table, rating, company, data->text_str, data->score, link_type, link_target);
|
||||
res.SetResultData(id);
|
||||
return res;
|
||||
}
|
||||
|
||||
CommandCost CmdUpdateLeagueTableElementData(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
std::string title, header, footer;
|
||||
text = StrConsumeToSeparator(title, text);
|
||||
if (text == nullptr) return CMD_ERROR;
|
||||
text = StrConsumeToSeparator(header, text);
|
||||
if (text == nullptr) return CMD_ERROR;
|
||||
text = StrConsumeToSeparator(footer, text);
|
||||
if (text != nullptr) return CMD_ERROR;
|
||||
|
||||
LeagueTableElementID element = GB(p1, 0, 16);
|
||||
CompanyID company = (CompanyID)GB(p1, 16, 8);
|
||||
LinkType link_type = (LinkType)GB(p1, 24, 8);
|
||||
|
54
src/league_cmd.h
Normal file
54
src/league_cmd.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 league_cmd.h Command definitions related to league tables. */
|
||||
|
||||
#ifndef LEAGUE_CMD_H
|
||||
#define LEAGUE_CMD_H
|
||||
|
||||
#include "command_aux.h"
|
||||
|
||||
struct LeagueTableCmdData : public CommandAuxiliarySerialisable<LeagueTableCmdData> {
|
||||
std::string title;
|
||||
std::string header;
|
||||
std::string footer;
|
||||
|
||||
virtual void Serialise(CommandSerialisationBuffer &buffer) const override
|
||||
{
|
||||
buffer.Send_string(this->title);
|
||||
buffer.Send_string(this->header);
|
||||
buffer.Send_string(this->footer);
|
||||
}
|
||||
|
||||
CommandCost Deserialise(CommandDeserialisationBuffer &buffer)
|
||||
{
|
||||
buffer.Recv_string(this->title, SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK);
|
||||
buffer.Recv_string(this->header, SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK);
|
||||
buffer.Recv_string(this->footer, SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK);
|
||||
return CommandCost();
|
||||
}
|
||||
};
|
||||
|
||||
struct LeagueTableElementCmdData : public CommandAuxiliarySerialisable<LeagueTableElementCmdData> {
|
||||
std::string text_str;
|
||||
std::string score;
|
||||
|
||||
virtual void Serialise(CommandSerialisationBuffer &buffer) const override
|
||||
{
|
||||
buffer.Send_string(this->text_str);
|
||||
buffer.Send_string(this->score);
|
||||
}
|
||||
|
||||
CommandCost Deserialise(CommandDeserialisationBuffer &buffer)
|
||||
{
|
||||
buffer.Recv_string(this->text_str, SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK);
|
||||
buffer.Recv_string(this->score, SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK);
|
||||
return CommandCost();
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* LEAGUE_CMD_H */
|
@@ -14,6 +14,7 @@
|
||||
#include "../script_instance.hpp"
|
||||
#include "script_error.hpp"
|
||||
#include "../../league_base.h"
|
||||
#include "../../league_cmd.h"
|
||||
#include "../../string_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
@@ -35,13 +36,12 @@
|
||||
const char *encoded_title = title->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(LEAGUE_TABLE_INVALID, encoded_title);
|
||||
|
||||
std::string cmd_text = encoded_title;
|
||||
cmd_text.push_back(0x1F);
|
||||
if (header != nullptr) cmd_text += header->GetEncodedText();
|
||||
cmd_text.push_back(0x1F);
|
||||
if (footer != nullptr) cmd_text += footer->GetEncodedText();
|
||||
LeagueTableCmdData data;
|
||||
data.title = encoded_title;
|
||||
data.header = header->GetEncodedText();
|
||||
data.footer = footer->GetEncodedText();
|
||||
|
||||
if (!ScriptObject::DoCommand(0, 0, 0, CMD_CREATE_LEAGUE_TABLE, cmd_text.c_str(), &ScriptInstance::DoCommandReturnLeagueTableID)) return LEAGUE_TABLE_INVALID;
|
||||
if (!ScriptObject::DoCommandEx(0, 0, 0, 0, CMD_CREATE_LEAGUE_TABLE, nullptr, &data, &ScriptInstance::DoCommandReturnLeagueTableID)) return LEAGUE_TABLE_INVALID;
|
||||
|
||||
/* In case of test-mode, we return LeagueTableID 0 */
|
||||
return (ScriptLeagueTable::LeagueTableID)0;
|
||||
@@ -76,10 +76,11 @@
|
||||
|
||||
EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, IsValidLink(Link((::LinkType)link_type, link_target)));
|
||||
|
||||
std::string cmd_text = std::move(encoded_text);
|
||||
cmd_text.push_back(0x1F);
|
||||
cmd_text += encoded_score;
|
||||
if (!ScriptObject::DoCommandEx(0, table | (c << 8) | (link_type << 16), link_target, rating, CMD_CREATE_LEAGUE_TABLE_ELEMENT, cmd_text.c_str(), 0, &ScriptInstance::DoCommandReturnLeagueTableElementID)) return LEAGUE_TABLE_ELEMENT_INVALID;
|
||||
LeagueTableElementCmdData data;
|
||||
data.text_str = std::move(encoded_text);
|
||||
data.score = encoded_score;
|
||||
|
||||
if (!ScriptObject::DoCommandEx(0, table | (c << 8) | (link_type << 16), link_target, rating, CMD_CREATE_LEAGUE_TABLE_ELEMENT, nullptr, &data, &ScriptInstance::DoCommandReturnLeagueTableElementID)) return LEAGUE_TABLE_ELEMENT_INVALID;
|
||||
|
||||
/* In case of test-mode, we return LeagueTableElementID 0 */
|
||||
return (ScriptLeagueTable::LeagueTableElementID)0;
|
||||
|
Reference in New Issue
Block a user