Update to 1.10.0-beta1

This commit is contained in:
dP
2019-10-31 22:24:28 +03:00
parent b84a475e14
commit 599ccf0c2b
1470 changed files with 354219 additions and 16795 deletions

View File

@@ -39,7 +39,7 @@
#include "sound_func.h"
#include "company_func.h"
#include "rev.h"
#ifdef WITH_FREETYPE
#if defined(WITH_FREETYPE) || defined(_WIN32)
#include "fontcache.h"
#endif
#include "textbuf_gui.h"
@@ -68,6 +68,10 @@
#include "void_map.h"
#include "station_base.h"
#if defined(WITH_FREETYPE) || defined(_WIN32)
#define HAS_TRUETYPE_FONT
#endif
#include "table/strings.h"
#include "table/settings.h"
@@ -84,7 +88,7 @@ static ErrorList _settings_error_list; ///< Errors while loading minimal setting
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList *list);
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
static bool IsSignedVarMemType(VarType vt);
@@ -96,7 +100,7 @@ static const char * const _list_group_names[] = {
"newgrf",
"servers",
"server_bind_addresses",
NULL
nullptr
};
/**
@@ -114,7 +118,7 @@ static size_t LookupOneOfMany(const char *many, const char *one, size_t onelen =
if (onelen == 0) onelen = strlen(one);
/* check if it's an integer */
if (*one >= '0' && *one <= '9') return strtoul(one, NULL, 0);
if (*one >= '0' && *one <= '9') return strtoul(one, nullptr, 0);
idx = 0;
for (;;) {
@@ -218,7 +222,7 @@ static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
int items[64];
int i, nitems;
if (str == NULL) {
if (str == nullptr) {
memset(items, 0, sizeof(items));
nitems = nelems;
} else {
@@ -348,7 +352,7 @@ static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32
*/
static const void *StringToVal(const SettingDescBase *desc, const char *orig_str)
{
const char *str = orig_str == NULL ? "" : orig_str;
const char *str = orig_str == nullptr ? "" : orig_str;
switch (desc->cmd) {
case SDT_NUMX: {
@@ -373,7 +377,7 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
size_t r = LookupOneOfMany(desc->many, str);
/* if the first attempt of conversion from string to the appropriate value fails,
* look if we have defined a converter from old value to new value. */
if (r == (size_t)-1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str);
if (r == (size_t)-1 && desc->proc_cnvt != nullptr) r = desc->proc_cnvt(str);
if (r != (size_t)-1) return (void*)r; // and here goes converted value
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
@@ -409,7 +413,7 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
default: break;
}
return NULL;
return nullptr;
}
/**
@@ -448,13 +452,30 @@ static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
case SLE_VAR_U16:
case SLE_VAR_I32: {
/* Override the minimum value. No value below sdb->min, except special value 0 */
if (!(sdb->flags & SGF_0ISDISABLED) || val != 0) val = Clamp(val, sdb->min, sdb->max);
if (!(sdb->flags & SGF_0ISDISABLED) || val != 0) {
if (!(sdb->flags & SGF_MULTISTRING)) {
/* Clamp value-type setting to its valid range */
val = Clamp(val, sdb->min, sdb->max);
} else if (val < sdb->min || val > (int32)sdb->max) {
/* Reset invalid discrete setting (where different values change gameplay) to its default value */
val = (int32)(size_t)sdb->def;
}
}
break;
}
case SLE_VAR_U32: {
/* Override the minimum value. No value below sdb->min, except special value 0 */
uint min = ((sdb->flags & SGF_0ISDISABLED) && (uint)val <= (uint)sdb->min) ? 0 : sdb->min;
WriteValue(ptr, SLE_VAR_U32, (int64)ClampU(val, min, sdb->max));
uint32 uval = (uint32)val;
if (!(sdb->flags & SGF_0ISDISABLED) || uval != 0) {
if (!(sdb->flags & SGF_MULTISTRING)) {
/* Clamp value-type setting to its valid range */
uval = ClampU(uval, sdb->min, sdb->max);
} else if (uval < (uint)sdb->min || uval > sdb->max) {
/* Reset invalid discrete setting to its default value */
uval = (uint32)(size_t)sdb->def;
}
}
WriteValue(ptr, SLE_VAR_U32, (int64)uval);
return;
}
case SLE_VAR_I64:
@@ -491,7 +512,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
/* For settings.xx.yy load the settings from [xx] yy = ? */
s = strchr(sdb->name, '.');
if (s != NULL) {
if (s != nullptr) {
group = ini->GetGroup(sdb->name, s - sdb->name);
s++;
} else {
@@ -500,19 +521,19 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
}
item = group->GetItem(s, false);
if (item == NULL && group != group_def) {
if (item == nullptr && group != group_def) {
/* For settings.xx.yy load the settings from [settingss] yy = ? in case the previous
* did not exist (e.g. loading old config files with a [settings] section */
item = group_def->GetItem(s, false);
}
if (item == NULL) {
if (item == nullptr) {
/* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
* did not exist (e.g. loading old config files with a [yapf] section */
const char *sc = strchr(s, '.');
if (sc != NULL) item = ini->GetGroup(s, sc - s)->GetItem(sc + 1, false);
if (sc != nullptr) item = ini->GetGroup(s, sc - s)->GetItem(sc + 1, false);
}
p = (item == NULL) ? sdb->def : StringToVal(sdb, item->value);
p = (item == nullptr) ? sdb->def : StringToVal(sdb, item->value);
ptr = GetVariableAddress(object, sld);
switch (sdb->cmd) {
@@ -527,16 +548,16 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
switch (GetVarMemType(sld->conv)) {
case SLE_VAR_STRB:
case SLE_VAR_STRBQ:
if (p != NULL) strecpy((char*)ptr, (const char*)p, (char*)ptr + sld->length - 1);
if (p != nullptr) strecpy((char*)ptr, (const char*)p, (char*)ptr + sld->length - 1);
break;
case SLE_VAR_STR:
case SLE_VAR_STRQ:
free(*(char**)ptr);
*(char**)ptr = p == NULL ? NULL : stredup((const char*)p);
*(char**)ptr = p == nullptr ? nullptr : stredup((const char*)p);
break;
case SLE_VAR_CHAR: if (p != NULL) *(char *)ptr = *(const char *)p; break;
case SLE_VAR_CHAR: if (p != nullptr) *(char *)ptr = *(const char *)p; break;
default: NOT_REACHED();
}
@@ -550,7 +571,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
/* Use default */
LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
} else if (sd->desc.proc_cnvt != NULL) {
} else if (sd->desc.proc_cnvt != nullptr) {
sd->desc.proc_cnvt((const char*)p);
}
break;
@@ -574,7 +595,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
*/
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
{
IniGroup *group_def = NULL, *group;
IniGroup *group_def = nullptr, *group;
IniItem *item;
char buf[512];
const char *s;
@@ -591,11 +612,11 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
/* XXX - wtf is this?? (group override?) */
s = strchr(sdb->name, '.');
if (s != NULL) {
if (s != nullptr) {
group = ini->GetGroup(sdb->name, s - sdb->name);
s++;
} else {
if (group_def == NULL) group_def = ini->GetGroup(grpname);
if (group_def == nullptr) group_def = ini->GetGroup(grpname);
s = sdb->name;
group = group_def;
}
@@ -603,7 +624,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
item = group->GetItem(s, true);
ptr = GetVariableAddress(object, sld);
if (item->value != NULL) {
if (item->value != nullptr) {
/* check if the value is the same as the old value */
const void *p = StringToVal(sdb, item->value);
@@ -616,7 +637,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
case SDT_MANYOFMANY:
switch (GetVarMemType(sld->conv)) {
case SLE_VAR_BL:
if (*(bool*)ptr == (p != NULL)) continue;
if (*(bool*)ptr == (p != nullptr)) continue;
break;
case SLE_VAR_I8:
@@ -667,7 +688,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
case SLE_VAR_STR: strecpy(buf, *(char**)ptr, lastof(buf)); break;
case SLE_VAR_STRQ:
if (*(char**)ptr == NULL) {
if (*(char**)ptr == nullptr) {
buf[0] = '\0';
} else {
seprintf(buf, lastof(buf), "\"%s\"", *(char**)ptr);
@@ -694,44 +715,44 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
/**
* Loads all items from a 'grpname' section into a list
* The list parameter can be a NULL pointer, in this case nothing will be
* The list parameter can be a nullptr pointer, in this case nothing will be
* saved and a callback function should be defined that will take over the
* list-handling and store the data itself somewhere.
* @param ini IniFile handle to the ini file with the source data
* @param grpname character string identifying the section-header of the ini file that will be parsed
* @param list new list with entries of the given section
*/
static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList *list)
static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &list)
{
IniGroup *group = ini->GetGroup(grpname);
if (group == NULL || list == NULL) return;
if (group == nullptr) return;
list->Clear();
list.clear();
for (const IniItem *item = group->item; item != NULL; item = item->next) {
if (item->name != NULL) *list->Append() = stredup(item->name);
for (const IniItem *item = group->item; item != nullptr; item = item->next) {
if (item->name != nullptr) list.emplace_back(item->name);
}
}
/**
* Saves all items from a list into the 'grpname' section
* The list parameter can be a NULL pointer, in this case a callback function
* The list parameter can be a nullptr pointer, in this case a callback function
* should be defined that will provide the source data to be saved.
* @param ini IniFile handle to the ini file where the destination data is saved
* @param grpname character string identifying the section-header of the ini file
* @param list pointer to an string(pointer) array that will be used as the
* source to be saved into the relevant ini section
*/
static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList *list)
static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
{
IniGroup *group = ini->GetGroup(grpname);
if (group == NULL || list == NULL) return;
if (group == nullptr) return;
group->Clear();
for (char **iter = list->Begin(); iter != list->End(); iter++) {
group->GetItem(*iter, true)->SetValue("");
for (const auto &iter : list) {
group->GetItem(iter.c_str(), true)->SetValue("");
}
}
@@ -788,7 +809,7 @@ SettingType SettingDesc::GetType() const
/** Reposition the main toolbar as the setting changed. */
static bool v_PositionMainToolbar(int32 p1)
{
if (_game_mode != GM_MENU) PositionMainToolbar(NULL);
if (_game_mode != GM_MENU) PositionMainToolbar(nullptr);
return true;
}
@@ -796,9 +817,9 @@ static bool v_PositionMainToolbar(int32 p1)
static bool v_PositionStatusbar(int32 p1)
{
if (_game_mode != GM_MENU) {
PositionStatusbar(NULL);
PositionNewsMessage(NULL);
PositionNetworkChatWindow(NULL);
PositionStatusbar(nullptr);
PositionNewsMessage(nullptr);
PositionNetworkChatWindow(nullptr);
}
return true;
}
@@ -1302,7 +1323,8 @@ static bool ChangeMaxHeightLevel(int32 p1)
static bool StationCatchmentChanged(int32 p1)
{
Station::RecomputeIndustriesNearForAll();
Station::RecomputeCatchmentForAll();
MarkWholeScreenDirty();
return true;
}
@@ -1322,9 +1344,6 @@ static bool InvalidateShipPathCache(int32 p1)
return true;
}
#ifdef ENABLE_NETWORK
static bool UpdateClientName(int32 p1)
{
NetworkUpdateClientName();
@@ -1356,9 +1375,6 @@ static bool UpdateClientConfigValues(int32 p1)
return true;
}
#endif /* ENABLE_NETWORK */
/* End - Callback Functions */
/**
@@ -1405,14 +1421,14 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
/* Clean any configured AI */
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME)->Change(NULL);
AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME)->Change(nullptr);
}
/* If no group exists, return */
if (group == NULL) return;
if (group == nullptr) return;
CompanyID c = COMPANY_FIRST;
for (item = group->item; c < MAX_COMPANIES && item != NULL; c++, item = item->next) {
for (item = group->item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
AIConfig *config = AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME);
config->Change(item->name);
@@ -1422,7 +1438,7 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
continue;
}
}
if (item->value != NULL) config->StringToSettings(item->value);
if (item->value != nullptr) config->StringToSettings(item->value);
}
}
@@ -1432,13 +1448,13 @@ static void GameLoadConfig(IniFile *ini, const char *grpname)
IniItem *item;
/* Clean any configured GameScript */
GameConfig::GetConfig(GameConfig::SSS_FORCE_NEWGAME)->Change(NULL);
GameConfig::GetConfig(GameConfig::SSS_FORCE_NEWGAME)->Change(nullptr);
/* If no group exists, return */
if (group == NULL) return;
if (group == nullptr) return;
item = group->item;
if (item == NULL) return;
if (item == nullptr) return;
GameConfig *config = GameConfig::GetConfig(AIConfig::SSS_FORCE_NEWGAME);
@@ -1449,7 +1465,7 @@ static void GameLoadConfig(IniFile *ini, const char *grpname)
return;
}
}
if (item->value != NULL) config->StringToSettings(item->value);
if (item->value != nullptr) config->StringToSettings(item->value);
}
/**
@@ -1496,13 +1512,13 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
{
IniGroup *group = ini->GetGroup(grpname);
IniItem *item;
GRFConfig *first = NULL;
GRFConfig *first = nullptr;
GRFConfig **curr = &first;
if (group == NULL) return NULL;
if (group == nullptr) return nullptr;
for (item = group->item; item != NULL; item = item->next) {
GRFConfig *c = NULL;
for (item = group->item; item != nullptr; item = item->next) {
GRFConfig *c = nullptr;
uint8 grfid_buf[4], md5sum[16];
char *filename = item->name;
@@ -1519,14 +1535,14 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
if (has_md5sum) {
const GRFConfig *s = FindGRFConfig(grfid, FGCM_EXACT, md5sum);
if (s != NULL) c = new GRFConfig(*s);
if (s != nullptr) c = new GRFConfig(*s);
}
if (c == NULL && !FioCheckFileExists(filename, NEWGRF_DIR)) {
if (c == nullptr && !FioCheckFileExists(filename, NEWGRF_DIR)) {
const GRFConfig *s = FindGRFConfig(grfid, FGCM_NEWEST_VALID);
if (s != NULL) c = new GRFConfig(*s);
if (s != nullptr) c = new GRFConfig(*s);
}
}
if (c == NULL) c = new GRFConfig(filename);
if (c == nullptr) c = new GRFConfig(filename);
/* Parse parameters */
if (!StrEmpty(item->value)) {
@@ -1561,7 +1577,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
/* Check for duplicate GRFID (will also check for duplicate filenames) */
bool duplicate = false;
for (const GRFConfig *gc = first; gc != NULL; gc = gc->next) {
for (const GRFConfig *gc = first; gc != nullptr; gc = gc->next) {
if (gc->ident.grfid == c->ident.grfid) {
SetDParamStr(0, c->filename);
SetDParamStr(1, gc->filename);
@@ -1590,7 +1606,7 @@ static void AISaveConfig(IniFile *ini, const char *grpname)
{
IniGroup *group = ini->GetGroup(grpname);
if (group == NULL) return;
if (group == nullptr) return;
group->Clear();
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
@@ -1614,7 +1630,7 @@ static void GameSaveConfig(IniFile *ini, const char *grpname)
{
IniGroup *group = ini->GetGroup(grpname);
if (group == NULL) return;
if (group == nullptr) return;
group->Clear();
GameConfig *config = GameConfig::GetConfig(AIConfig::SSS_FORCE_NEWGAME);
@@ -1660,7 +1676,7 @@ static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *li
IniGroup *group = ini->GetGroup(grpname);
const GRFConfig *c;
for (c = list; c != NULL; c = c->next) {
for (c = list; c != nullptr; c = c->next) {
/* Hex grfid (4 bytes in nibbles), "|", hex md5sum (16 bytes in nibbles), "|", file system path. */
char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
char params[512];
@@ -1677,9 +1693,9 @@ static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *li
static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool basic_settings = true, bool other_settings = true)
{
if (basic_settings) {
proc(ini, (const SettingDesc*)_misc_settings, "misc", NULL);
proc(ini, (const SettingDesc*)_misc_settings, "misc", nullptr);
#if defined(_WIN32) && !defined(DEDICATED)
proc(ini, (const SettingDesc*)_win32_settings, "win32", NULL);
proc(ini, (const SettingDesc*)_win32_settings, "win32", nullptr);
#endif /* _WIN32 */
}
@@ -1688,11 +1704,9 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP
proc(ini, _currency_settings,"currency", &_custom_currency);
proc(ini, _company_settings, "company", &_settings_client.company);
#ifdef ENABLE_NETWORK
proc_list(ini, "server_bind_addresses", &_network_bind_list);
proc_list(ini, "servers", &_network_host_list);
proc_list(ini, "bans", &_network_ban_list);
#endif /* ENABLE_NETWORK */
proc_list(ini, "server_bind_addresses", _network_bind_list);
proc_list(ini, "servers", _network_host_list);
proc_list(ini, "bans", _network_ban_list);
}
}
@@ -1727,10 +1741,10 @@ void LoadFromConfig(bool minimal)
ValidateSettings();
/* Display sheduled errors */
/* Display scheduled errors */
extern void ScheduleErrorMessage(ErrorList &datas);
ScheduleErrorMessage(_settings_error_list);
if (FindWindowById(WC_ERRMSG, 0) == NULL) ShowFirstError();
if (FindWindowById(WC_ERRMSG, 0) == nullptr) ShowFirstError();
}
delete ini;
@@ -1758,21 +1772,20 @@ void SaveToConfig()
/**
* Get the list of known NewGrf presets.
* @param[in,out] list Pointer to list for storing the preset names.
* @returns List of preset names.
*/
void GetGRFPresetList(GRFPresetList *list)
StringList GetGRFPresetList()
{
list->Clear();
StringList list;
IniFile *ini = IniLoadConfig();
IniGroup *group;
for (group = ini->group; group != NULL; group = group->next) {
std::unique_ptr<IniFile> ini(IniLoadConfig());
for (IniGroup *group = ini->group; group != nullptr; group = group->next) {
if (strncmp(group->name, "preset-", 7) == 0) {
*list->Append() = stredup(group->name + 7);
list.emplace_back(group->name + 7);
}
}
delete ini;
return list;
}
/**
@@ -1830,7 +1843,7 @@ void DeleteGRFPresetFromConfig(const char *config_name)
const SettingDesc *GetSettingDescription(uint index)
{
if (index >= lengthof(_settings)) return NULL;
if (index >= lengthof(_settings)) return nullptr;
return &_settings[index];
}
@@ -1849,7 +1862,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
{
const SettingDesc *sd = GetSettingDescription(p1);
if (sd == NULL) return CMD_ERROR;
if (sd == nullptr) return CMD_ERROR;
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR;
if (!sd->IsEditable(true)) return CMD_ERROR;
@@ -1865,7 +1878,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (oldval == newval) return CommandCost();
if (sd->desc.proc != NULL && !sd->desc.proc(newval)) {
if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
WriteValue(var, sd->save.conv, (int64)oldval);
return CommandCost();
}
@@ -1908,7 +1921,7 @@ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32
if (oldval == newval) return CommandCost();
if (sd->desc.proc != NULL && !sd->desc.proc(newval)) {
if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
WriteValue(var, sd->save.conv, (int64)oldval);
return CommandCost();
}
@@ -1941,7 +1954,7 @@ bool SetSettingValue(uint index, int32 value, bool force_newgame)
void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
Write_ValidateSetting(var2, sd, value);
}
if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
SetWindowClassesDirty(WC_GAME_OPTIONS);
@@ -1975,7 +1988,7 @@ void SetCompanySetting(uint index, int32 value)
} else {
void *var = GetVariableAddress(&_settings_client.company, &sd->save);
Write_ValidateSetting(var, sd, value);
if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
}
}
@@ -1992,7 +2005,6 @@ void SetDefaultCompanySettings(CompanyID cid)
}
}
#if defined(ENABLE_NETWORK)
/**
* Sync all company settings in a multiplayer game.
*/
@@ -2005,10 +2017,9 @@ void SyncCompanySettings()
const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save);
uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv);
uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv);
if (old_value != new_value) NetworkSendCommand(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, NULL, NULL, _local_company);
if (old_value != new_value) NetworkSendCommand(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, nullptr, nullptr, _local_company);
}
}
#endif /* ENABLE_NETWORK */
/**
* Get the index in the _company_settings array of a setting
@@ -2019,7 +2030,7 @@ uint GetCompanySettingIndex(const char *name)
{
uint i;
const SettingDesc *sd = GetSettingFromName(name, &i);
assert(sd != NULL && (sd->desc.flags & SGF_PER_COMPANY) != 0);
assert(sd != nullptr && (sd->desc.flags & SGF_PER_COMPANY) != 0);
return i;
}
@@ -2038,12 +2049,12 @@ bool SetSettingValue(uint index, const char *value, bool force_newgame)
if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) {
char **var = (char**)GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
free(*var);
*var = strcmp(value, "(null)") == 0 ? NULL : stredup(value);
*var = strcmp(value, "(null)") == 0 ? nullptr : stredup(value);
} else {
char *var = (char*)GetVariableAddress(NULL, &sd->save);
char *var = (char*)GetVariableAddress(nullptr, &sd->save);
strecpy(var, value, &var[sd->save.length - 1]);
}
if (sd->desc.proc != NULL) sd->desc.proc(0);
if (sd->desc.proc != nullptr) sd->desc.proc(0);
return true;
}
@@ -2053,7 +2064,7 @@ bool SetSettingValue(uint index, const char *value, bool force_newgame)
* @param name Name of the setting to return a setting description of
* @param i Pointer to an integer that will contain the index of the setting after the call, if it is successful.
* @return Pointer to the setting description of setting \a name if it can be found,
* \c NULL indicates failure to obtain the description
* \c nullptr indicates failure to obtain the description
*/
const SettingDesc *GetSettingFromName(const char *name, uint *i)
{
@@ -2069,7 +2080,7 @@ const SettingDesc *GetSettingFromName(const char *name, uint *i)
for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
const char *short_name = strchr(sd->desc.name, '.');
if (short_name != NULL) {
if (short_name != nullptr) {
short_name++;
if (strcmp(short_name, name) == 0) return sd;
}
@@ -2082,7 +2093,7 @@ const SettingDesc *GetSettingFromName(const char *name, uint *i)
if (strcmp(sd->desc.name, name) == 0) return sd;
}
return NULL;
return nullptr;
}
/* Those 2 functions need to be here, else we have to make some stuff non-static
@@ -2092,7 +2103,7 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
uint index;
const SettingDesc *sd = GetSettingFromName(name, &index);
if (sd == NULL) {
if (sd == nullptr) {
IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
return;
}
@@ -2125,7 +2136,7 @@ void IConsoleSetSetting(const char *name, int value)
{
uint index;
const SettingDesc *sd = GetSettingFromName(name, &index);
assert(sd != NULL);
assert(sd != nullptr);
SetSettingValue(index, value);
}
@@ -2141,7 +2152,7 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
const SettingDesc *sd = GetSettingFromName(name, &index);
const void *ptr;
if (sd == NULL) {
if (sd == nullptr) {
IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
return;
}
@@ -2165,7 +2176,7 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
/**
* List all settings and their value to the console
*
* @param prefilter If not \c NULL, only list settings with names that begin with \a prefilter prefix
* @param prefilter If not \c nullptr, only list settings with names that begin with \a prefilter prefix
*/
void IConsoleListSettings(const char *prefilter)
{
@@ -2173,7 +2184,7 @@ void IConsoleListSettings(const char *prefilter)
for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (prefilter != NULL && strstr(sd->desc.name, prefilter) == NULL) continue;
if (prefilter != nullptr && strstr(sd->desc.name, prefilter) == nullptr) continue;
char value[80];
const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
@@ -2193,7 +2204,7 @@ void IConsoleListSettings(const char *prefilter)
/**
* Save and load handler for settings
* @param osd SettingDesc struct containing all information
* @param object can be either NULL in which case we load global variables or
* @param object can be either nullptr in which case we load global variables or
* a pointer to a struct which is getting saved
*/
static void LoadSettings(const SettingDesc *osd, void *object)
@@ -2210,7 +2221,7 @@ static void LoadSettings(const SettingDesc *osd, void *object)
/**
* Save and load handler for settings
* @param sd SettingDesc struct containing all information
* @param object can be either NULL in which case we load global variables or
* @param object can be either nullptr in which case we load global variables or
* a pointer to a struct which is getting saved
*/
static void SaveSettings(const SettingDesc *sd, void *object)
@@ -2258,21 +2269,9 @@ static void Save_PATS()
SaveSettings(_settings, &_settings_game);
}
void CheckConfig()
{
/*
* Increase old default values for pf_maxdepth and pf_maxlength
* to support big networks.
*/
if (_settings_newgame.pf.opf.pf_maxdepth == 16 && _settings_newgame.pf.opf.pf_maxlength == 512) {
_settings_newgame.pf.opf.pf_maxdepth = 48;
_settings_newgame.pf.opf.pf_maxlength = 4096;
}
}
extern const ChunkHandler _setting_chunk_handlers[] = {
{ 'OPTS', NULL, Load_OPTS, NULL, NULL, CH_RIFF},
{ 'PATS', Save_PATS, Load_PATS, NULL, Check_PATS, CH_RIFF | CH_LAST},
{ 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_RIFF},
{ 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_RIFF | CH_LAST},
};
static bool IsSignedVarMemType(VarType vt)