Feature: [GS] Scriptable league tables (#10001)

(cherry picked from commit 5e14a20b3b)
This commit is contained in:
dP
2022-11-26 21:03:03 +04:00
committed by Jonathan G Rennison
parent 1260e51d84
commit c91033ac5e
28 changed files with 1352 additions and 232 deletions

View File

@@ -18,6 +18,7 @@ add_files(
group_sl.cpp
industry_sl.cpp
labelmaps_sl.cpp
league_sl.cpp
linkgraph_sl.cpp
map_sl.cpp
misc_sl.cpp

View File

@@ -0,0 +1,93 @@
/*
* 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_sl.cpp Code handling saving and loading of league tables */
#include "../../stdafx.h"
#include "saveload.h"
#include "../../league_base.h"
#include "../../safeguards.h"
namespace upstream_sl {
static const SaveLoad _league_table_elements_desc[] = {
SLE_VAR(LeagueTableElement, table, SLE_UINT8),
SLE_VAR(LeagueTableElement, rating, SLE_UINT64),
SLE_VAR(LeagueTableElement, company, SLE_UINT8),
SLE_SSTR(LeagueTableElement, text, SLE_STR | SLF_ALLOW_CONTROL),
SLE_SSTR(LeagueTableElement, score, SLE_STR | SLF_ALLOW_CONTROL),
SLE_VAR(LeagueTableElement, link.type, SLE_UINT8),
SLE_VAR(LeagueTableElement, link.target, SLE_UINT32),
};
struct LEAEChunkHandler : ChunkHandler {
LEAEChunkHandler() : ChunkHandler('LEAE', CH_TABLE) {}
void Save() const override
{
SlTableHeader(_league_table_elements_desc);
for (LeagueTableElement *lte : LeagueTableElement::Iterate()) {
SlSetArrayIndex(lte->index);
SlObject(lte, _league_table_elements_desc);
}
}
void Load() const override
{
const std::vector<SaveLoad> slt = SlTableHeader(_league_table_elements_desc);
int index;
while ((index = SlIterateArray()) != -1) {
LeagueTableElement *lte = new (index) LeagueTableElement();
SlObject(lte, slt);
}
}
};
static const SaveLoad _league_tables_desc[] = {
SLE_SSTR(LeagueTable, title, SLE_STR | SLF_ALLOW_CONTROL),
};
struct LEATChunkHandler : ChunkHandler {
LEATChunkHandler() : ChunkHandler('LEAT', CH_TABLE) {}
void Save() const override
{
SlTableHeader(_league_tables_desc);
for (LeagueTable *lt : LeagueTable::Iterate()) {
SlSetArrayIndex(lt->index);
SlObject(lt, _league_tables_desc);
}
}
void Load() const override
{
const std::vector<SaveLoad> slt = SlTableHeader(_league_tables_desc);
int index;
while ((index = SlIterateArray()) != -1) {
LeagueTable *lt = new (index) LeagueTable();
SlObject(lt, slt);
}
}
};
static const LEAEChunkHandler LEAE;
static const LEATChunkHandler LEAT;
static const ChunkHandlerRef league_chunk_handlers[] = {
LEAE,
LEAT,
};
extern const ChunkHandlerTable _league_chunk_handlers(league_chunk_handlers);
}

View File

@@ -101,6 +101,7 @@ static const std::vector<ChunkHandlerRef> &ChunkHandlers()
extern const ChunkHandlerTable _cargomonitor_chunk_handlers;
extern const ChunkHandlerTable _goal_chunk_handlers;
extern const ChunkHandlerTable _story_page_chunk_handlers;
extern const ChunkHandlerTable _league_chunk_handlers;
extern const ChunkHandlerTable _ai_chunk_handlers;
extern const ChunkHandlerTable _game_chunk_handlers;
extern const ChunkHandlerTable _animated_tile_chunk_handlers;
@@ -132,6 +133,7 @@ static const std::vector<ChunkHandlerRef> &ChunkHandlers()
_cargomonitor_chunk_handlers,
_goal_chunk_handlers,
_story_page_chunk_handlers,
_league_chunk_handlers,
_engine_chunk_handlers,
_town_chunk_handlers,
_sign_chunk_handlers,