Codechange: Use std:: features for NewGRF town names (#10631)
This removes manual memory (de-)allocation and list counting.
This commit is contained in:
@@ -17,29 +17,31 @@
|
||||
#include "strings_type.h"
|
||||
|
||||
struct NamePart {
|
||||
byte prob; ///< The relative probability of the following name to appear in the bottom 7 bits.
|
||||
union {
|
||||
char *text; ///< If probability bit 7 is clear
|
||||
byte id; ///< If probability bit 7 is set
|
||||
} data;
|
||||
std::string text; ///< If probability bit 7 is clear
|
||||
byte id; ///< If probability bit 7 is set
|
||||
byte prob; ///< The relative probability of the following name to appear in the bottom 7 bits.
|
||||
};
|
||||
|
||||
struct NamePartList {
|
||||
byte partcount;
|
||||
byte bitstart;
|
||||
byte bitcount;
|
||||
uint16 maxprob;
|
||||
NamePart *parts;
|
||||
byte bitstart; ///< Start of random seed bits to use.
|
||||
byte bitcount; ///< Number of bits of random seed to use.
|
||||
uint16 maxprob; ///< Total probability of all parts.
|
||||
std::vector<NamePart> parts; ///< List of parts to choose from.
|
||||
};
|
||||
|
||||
struct TownNameStyle {
|
||||
StringID name; ///< String ID of this town name style.
|
||||
byte id; ///< Index within partlist for this town name style.
|
||||
|
||||
TownNameStyle(StringID name, byte id) : name(name), id(id) { }
|
||||
};
|
||||
|
||||
struct GRFTownName {
|
||||
uint32 grfid;
|
||||
byte nb_gen;
|
||||
byte id[128];
|
||||
StringID name[128];
|
||||
byte nbparts[128];
|
||||
NamePartList *partlist[128];
|
||||
GRFTownName *next;
|
||||
static const uint MAX_LISTS = 128; ///< Maximum number of town name lists that can be defined per GRF.
|
||||
|
||||
uint32 grfid; ///< GRF ID of NewGRF.
|
||||
std::vector<TownNameStyle> styles; ///< Style names defined by the Town Name NewGRF.
|
||||
std::vector<NamePartList> partlists[MAX_LISTS]; ///< Lists of town name parts.
|
||||
};
|
||||
|
||||
GRFTownName *AddGRFTownName(uint32 grfid);
|
||||
@@ -47,9 +49,9 @@ GRFTownName *GetGRFTownName(uint32 grfid);
|
||||
void DelGRFTownName(uint32 grfid);
|
||||
void CleanUpGRFTownNames();
|
||||
char *GRFTownNameGenerate(char *buf, uint32 grfid, uint16 gen, uint32 seed, const char *last);
|
||||
uint32 GetGRFTownNameId(int gen);
|
||||
uint16 GetGRFTownNameType(int gen);
|
||||
StringID GetGRFTownNameName(uint gen);
|
||||
uint32 GetGRFTownNameId(uint16 gen);
|
||||
uint16 GetGRFTownNameType(uint16 gen);
|
||||
StringID GetGRFTownNameName(uint16 gen);
|
||||
|
||||
const std::vector<StringID>& GetGRFTownNameList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user