mirror of https://github.com/OpenTTD/OpenTTD
Codechange: strongly type LeagueTableID and LeagueTableElementID
parent
6aada55e96
commit
6c8915fdbc
|
@ -17,10 +17,10 @@
|
|||
|
||||
bool IsValidLink(Link link);
|
||||
|
||||
typedef Pool<LeagueTableElement, LeagueTableElementID, 64, 64000> LeagueTableElementPool;
|
||||
using LeagueTableElementPool = Pool<LeagueTableElement, LeagueTableElementID, 64, LeagueTableElementID::End().base()>;
|
||||
extern LeagueTableElementPool _league_table_element_pool;
|
||||
|
||||
typedef Pool<LeagueTable, LeagueTableID, 4, 255> LeagueTablePool;
|
||||
using LeagueTablePool = Pool<LeagueTable, LeagueTableID, 4, LeagueTableID::End().base()>;
|
||||
extern LeagueTablePool _league_table_pool;
|
||||
|
||||
|
||||
|
|
|
@ -298,9 +298,8 @@ private:
|
|||
}
|
||||
|
||||
public:
|
||||
ScriptLeagueWindow(WindowDesc &desc, LeagueTableID table) : Window(desc)
|
||||
ScriptLeagueWindow(WindowDesc &desc, WindowNumber table) : Window(desc), table(table)
|
||||
{
|
||||
this->table = table;
|
||||
this->BuildTable();
|
||||
this->InitNested(table);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef LEAGUE_TYPE_H
|
||||
#define LEAGUE_TYPE_H
|
||||
|
||||
#include "core/pool_type.hpp"
|
||||
|
||||
/** Types of the possible link targets. */
|
||||
enum LinkType : uint8_t {
|
||||
LT_NONE = 0, ///< No link
|
||||
|
@ -29,12 +31,12 @@ struct Link {
|
|||
Link(): Link(LT_NONE, 0) {}
|
||||
};
|
||||
|
||||
typedef uint8_t LeagueTableID; ///< ID of a league table
|
||||
using LeagueTableID = PoolID<uint8_t, struct LeagueTableIDTag, 255, 0xFF>; ///< ID of a league table
|
||||
struct LeagueTable;
|
||||
static const LeagueTableID INVALID_LEAGUE_TABLE = 0xFF; ///< Invalid/unknown index of LeagueTable
|
||||
static constexpr LeagueTableID INVALID_LEAGUE_TABLE = LeagueTableID::Invalid(); ///< Invalid/unknown index of LeagueTable
|
||||
|
||||
typedef uint16_t LeagueTableElementID; ///< ID of a league table element
|
||||
using LeagueTableElementID = PoolID<uint16_t, struct LeagueTableElementIDTag, 64000, 0xFFFF>; ///< ID of a league table
|
||||
struct LeagueTableElement;
|
||||
static const LeagueTableElementID INVALID_LEAGUE_TABLE_ELEMENT = 0xFFFF; ///< Invalid/unknown index of LeagueTableElement
|
||||
static constexpr LeagueTableElementID INVALID_LEAGUE_TABLE_ELEMENT = LeagueTableElementID::Invalid(); ///< Invalid/unknown index of LeagueTableElement
|
||||
|
||||
#endif /* LEAGUE_TYPE_H */
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
if (!ScriptObject::Command<CMD_CREATE_LEAGUE_TABLE>::Do(&ScriptInstance::DoCommandReturnLeagueTableID, encoded_title, encoded_header, encoded_footer)) return LEAGUE_TABLE_INVALID;
|
||||
|
||||
/* In case of test-mode, we return LeagueTableID 0 */
|
||||
return static_cast<LeagueTableID>(0);
|
||||
return LeagueTableID::Begin();
|
||||
}
|
||||
|
||||
/* static */ bool ScriptLeagueTable::IsValidLeagueTableElement(LeagueTableElementID element_id)
|
||||
|
@ -74,7 +74,7 @@
|
|||
if (!ScriptObject::Command<CMD_CREATE_LEAGUE_TABLE_ELEMENT>::Do(&ScriptInstance::DoCommandReturnLeagueTableElementID, table, rating, c, encoded_text, encoded_score, (::LinkType)link_type, (::LinkTargetID)link_target)) return LEAGUE_TABLE_ELEMENT_INVALID;
|
||||
|
||||
/* In case of test-mode, we return LeagueTableElementID 0 */
|
||||
return static_cast<LeagueTableElementID>(0);
|
||||
return LeagueTableElementID::Begin();
|
||||
}
|
||||
|
||||
/* static */ bool ScriptLeagueTable::UpdateElementData(LeagueTableElementID element, ScriptCompany::CompanyID company, Text *text, LinkType link_type, SQInteger link_target)
|
||||
|
|
|
@ -663,7 +663,7 @@ static void AddDropDownLeagueTableOptions(DropDownList &list)
|
|||
{
|
||||
if (LeagueTable::GetNumItems() > 0) {
|
||||
for (LeagueTable *lt : LeagueTable::Iterate()) {
|
||||
list.push_back(MakeDropDownListStringItem(lt->title, lt->index));
|
||||
list.push_back(MakeDropDownListStringItem(lt->title, lt->index.base()));
|
||||
}
|
||||
} else {
|
||||
list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, LTMN_PERFORMANCE_LEAGUE));
|
||||
|
|
Loading…
Reference in New Issue