diff --git a/src/command.h b/src/command.h --- a/src/command.h +++ b/src/command.h @@ -195,9 +195,9 @@ struct Command { static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); } static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); } -static const CommandCost CMD_ERROR = CommandCost((StringID)INVALID_STRING_ID); +static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID); -#define return_cmd_error(errcode) do { return CommandCost((StringID)(errcode)); } while (0) +#define return_cmd_error(errcode) do { return CommandCost(errcode); } while (0) /* command.cpp */ typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2); diff --git a/src/openttd.cpp b/src/openttd.cpp --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -5,7 +5,6 @@ #include "stdafx.h" #define VARDEF #include "string.h" -#include "table/strings.h" #include "debug.h" #include "driver.h" #include "saveload.h" @@ -15,6 +14,7 @@ #include "helpers.hpp" #include "openttd.h" +#include "table/strings.h" #include "strings.h" #include "bridge_map.h" #include "functions.h" diff --git a/src/openttd.h b/src/openttd.h --- a/src/openttd.h +++ b/src/openttd.h @@ -51,7 +51,7 @@ struct PalSpriteID { typedef uint16 EngineID; typedef uint16 UnitID; typedef uint16 StringID; -#define INVALID_STRING_ID 0xFFFF +static const StringID INVALID_STRING_ID = 0xFFFF; typedef EngineID *EngineList; ///< engine list type placeholder acceptable for C code (see helpers.cpp) diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -1019,19 +1019,20 @@ static void WriteStringsH(const char *fi out = fopen("tmp.xxx", "w"); if (out == NULL) fatal("can't open tmp.xxx"); - fprintf(out, "enum StringIdEnum {"); + fprintf(out, "/* This file is automatically generated. Do not modify */\n\n"); + fprintf(out, "#ifndef TABLE_STRINGS_H\n"); + fprintf(out, "#define TABLE_STRINGS_H\n"); lastgrp = 0; for (i = 0; i != lengthof(_strings); i++) { if (_strings[i] != NULL) { - fprintf(out, next == i ? "\t%s,\n" : "\n\t%s = 0x%X,\n", _strings[i]->name, i); + if (next != i) fprintf(out, "\n"); + fprintf(out, "static const StringID %s = 0x%X;\n", _strings[i]->name, i); next = i + 1; } } - fprintf(out, "};\n"); - fprintf(out, "\nenum {\n" "\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n" @@ -1039,6 +1040,8 @@ static void WriteStringsH(const char *fi "};\n", (uint)_hash ); + fprintf(out, "\n#endif /* TABLE_STRINGS_H */\n"); + fclose(out); if (CompareFiles("tmp.xxx", filename)) { diff --git a/src/strings.cpp b/src/strings.cpp --- a/src/strings.cpp +++ b/src/strings.cpp @@ -696,7 +696,7 @@ static char* FormatString(char* buff, co * 8bit - cargo type * 16-bit - cargo count */ CargoID cargo = GetInt32(&argv); - StringID cargo_str = (cargo == CT_INVALID) ? (StringID)STR_8838_N_A : GetCargo(cargo)->quantifier; + StringID cargo_str = (cargo == CT_INVALID) ? STR_8838_N_A : GetCargo(cargo)->quantifier; buff = GetStringWithArgs(buff, cargo_str, argv++, last); break; } @@ -852,7 +852,7 @@ static char* FormatString(char* buff, co assert(g->IsValid()); args[0] = g->index; - buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : (StringID)STR_GROUP_NAME_FORMAT, args, last); + buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : STR_GROUP_NAME_FORMAT, args, last); break; }