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

@@ -23,6 +23,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

@@ -180,6 +180,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_U64_TICK_COUNTER, XSCF_NULL, 1, 1, "u64_tick_counter", nullptr, nullptr, nullptr },
{ XSLFI_LINKGRAPH_TRAVEL_TIME, XSCF_NULL, 1, 1, "linkgraph_travel_time", nullptr, nullptr, nullptr },
{ XSLFI_LAST_LOADING_TICK, XSCF_NULL, 1, 1, "last_loading_tick", nullptr, nullptr, nullptr },
{ XSLFI_SCRIPT_LEAGUE_TABLES, XSCF_NULL, 1, 1, "script_league_tables", nullptr, nullptr, "LEAE,LEAT" },
{ XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker
};

View File

@@ -134,6 +134,7 @@ enum SlXvFeatureIndex {
XSLFI_U64_TICK_COUNTER, ///< See: SLV_U64_TICK_COUNTER
XSLFI_LINKGRAPH_TRAVEL_TIME, ///< See: SLV_LINKGRAPH_TRAVEL_TIME
XSLFI_LAST_LOADING_TICK, ///< See: SLV_LAST_LOADING_TICK
XSLFI_SCRIPT_LEAGUE_TABLES, ///< See: Scriptable league tables (PR #10001)
XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit
XSLFI_HEIGHT_8_BIT, ///< Map tile height is 8 bit instead of 4 bit, but savegame version may be before this became true in trunk

View File

@@ -0,0 +1,23 @@
/*
* 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"
struct GetLeagueChunkLoadInfo
{
static SaveLoadVersion GetVersion() { return SLV_MULTITRACK_LEVEL_CROSSINGS; }
};
static const ChunkHandler league_chunk_handlers[] = {
MakeUpstreamChunkHandler<'LEAE', GetLeagueChunkLoadInfo>(),
MakeUpstreamChunkHandler<'LEAT', GetLeagueChunkLoadInfo>(),
};
extern const ChunkHandlerTable _league_chunk_handlers(league_chunk_handlers);

View File

@@ -284,6 +284,7 @@ static const std::vector<ChunkHandler> &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;
@@ -326,6 +327,7 @@ static const std::vector<ChunkHandler> &ChunkHandlers()
_cargomonitor_chunk_handlers,
_goal_chunk_handlers,
_story_page_chunk_handlers,
_league_chunk_handlers,
_engine_chunk_handlers,
_town_chunk_handlers,
_sign_chunk_handlers,

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,