Move create league table element fields inside aux data struct

This commit is contained in:
Jonathan G Rennison 2024-08-30 17:40:58 +01:00
parent 7bbd88caa2
commit 64d312d028
3 changed files with 22 additions and 8 deletions

View File

@ -193,13 +193,7 @@ CommandCost CmdCreateLeagueTableElement(TileIndex tile, DoCommandFlag flags, uin
CommandCost ret = data.Load(aux_data);
if (ret.Failed()) return ret;
LeagueTableID table = GB(p1, 0, 8);
int64_t rating = p3;
CompanyID company = (CompanyID)GB(p1, 8, 8);
LinkType link_type = (LinkType)GB(p1, 16, 8);
LinkTargetID link_target = (LinkTargetID)p2;
auto [res, id] = CmdCreateLeagueTableElement(flags, table, rating, company, data->text_str, data->score, link_type, link_target);
auto [res, id] = CmdCreateLeagueTableElement(flags, data->table, data->rating, data->company, data->text_str, data->score, data->link_type, data->link_target);
res.SetResultData(id);
return res;
}

View File

@ -34,17 +34,32 @@ struct LeagueTableCmdData : public CommandAuxiliarySerialisable<LeagueTableCmdDa
};
struct LeagueTableElementCmdData : public CommandAuxiliarySerialisable<LeagueTableElementCmdData> {
LeagueTableID table;
int64_t rating;
CompanyID company;
LinkType link_type;
LinkTargetID link_target;
std::string text_str;
std::string score;
virtual void Serialise(CommandSerialisationBuffer &buffer) const override
{
buffer.Send_uint8(this->table);
buffer.Send_uint64(this->rating);
buffer.Send_uint8(this->company);
buffer.Send_uint8(this->link_type);
buffer.Send_uint32(this->link_target);
buffer.Send_string(this->text_str);
buffer.Send_string(this->score);
}
CommandCost Deserialise(CommandDeserialisationBuffer &buffer)
{
this->table = buffer.Recv_uint8();
this->rating = buffer.Recv_uint64();
this->company = (CompanyID)buffer.Recv_uint8();
this->link_type = (LinkType)buffer.Recv_uint8();
this->link_target = (LinkTargetID)buffer.Recv_uint32();
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();

View File

@ -76,10 +76,15 @@
EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, IsValidLink(Link((::LinkType)link_type, link_target)));
LeagueTableElementCmdData data;
data.table = table;
data.rating = rating;
data.company = c;
data.link_type = (::LinkType)link_type;
data.link_target = (::LinkTargetID)link_target;
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;
if (!ScriptObject::DoCommandEx(0, 0, 0, 0, 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;