Merge branch 'master' into jgrpp
# Conflicts: # projects/openttd_vs140.vcxproj.filters # projects/openttd_vs141.vcxproj.filters # projects/openttd_vs142.vcxproj.filters # src/base_consist.h # src/company_base.h # src/newgrf_config.cpp # src/newgrf_config.h # src/openttd.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/saveload/station_sl.cpp # src/settings.cpp # src/signs_base.h # src/string.cpp # src/string_func.h # src/table/misc_settings.ini # src/table/settings.h.preamble # src/town_cmd.cpp # src/vehicle.cpp # src/vehicle_cmd.cpp # src/video/cocoa/cocoa_v.mm # src/video/null_v.cpp
This commit is contained in:
108
src/settings.cpp
108
src/settings.cpp
@@ -422,6 +422,7 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
|
||||
return desc->def;
|
||||
}
|
||||
|
||||
case SDT_STDSTRING:
|
||||
case SDT_STRING: return orig_str;
|
||||
case SDT_INTLIST: return str;
|
||||
default: break;
|
||||
@@ -527,45 +528,42 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
{
|
||||
IniGroup *group;
|
||||
IniGroup *group_def = ini->GetGroup(grpname);
|
||||
IniItem *item;
|
||||
const void *p;
|
||||
void *ptr;
|
||||
const char *s;
|
||||
|
||||
for (; sd->save.cmd != SL_END; sd++) {
|
||||
const SettingDescBase *sdb = &sd->desc;
|
||||
const SaveLoad *sld = &sd->save;
|
||||
|
||||
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to, sld->ext_feature_test)) continue;
|
||||
IniItem *item;
|
||||
if (sdb->flags & SGF_NO_NEWGAME) {
|
||||
item = nullptr;
|
||||
} else {
|
||||
/* For settings.xx.yy load the settings from [xx] yy = ? */
|
||||
s = strchr(sdb->name, '.');
|
||||
if (s != nullptr) {
|
||||
group = ini->GetGroup(sdb->name, s - sdb->name);
|
||||
s++;
|
||||
std::string s{ sdb->name };
|
||||
auto sc = s.find('.');
|
||||
if (sc != std::string::npos) {
|
||||
group = ini->GetGroup(s.substr(0, sc));
|
||||
s = s.substr(sc + 1);
|
||||
} else {
|
||||
s = sdb->name;
|
||||
group = group_def;
|
||||
}
|
||||
|
||||
item = group->GetItem(s, false);
|
||||
if (item == nullptr && group != group_def) {
|
||||
/* For settings.xx.yy load the settings from [settingss] yy = ? in case the previous
|
||||
/* For settings.xx.yy load the settings from [settings] 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 == 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 != nullptr) item = ini->GetGroup(s, sc - s)->GetItem(sc + 1, false);
|
||||
sc = s.find('.');
|
||||
if (sc != std::string::npos) item = ini->GetGroup(s.substr(0, sc))->GetItem(s.substr(sc + 1), false);
|
||||
}
|
||||
}
|
||||
|
||||
p = (item == nullptr) ? sdb->def : StringToVal(sdb, item->value);
|
||||
ptr = GetVariableAddress(object, sld);
|
||||
const void *p = (item == nullptr) ? sdb->def : StringToVal(sdb, item->value.has_value() ? item->value->c_str() : nullptr);
|
||||
void *ptr = GetVariableAddress(object, sld);
|
||||
|
||||
switch (sdb->cmd) {
|
||||
case SDT_BOOLX: // All four are various types of (integer) numbers
|
||||
@@ -594,6 +592,22 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
}
|
||||
break;
|
||||
|
||||
case SDT_STDSTRING:
|
||||
switch (GetVarMemType(sld->conv)) {
|
||||
case SLE_VAR_STR:
|
||||
case SLE_VAR_STRQ:
|
||||
if (p != nullptr) {
|
||||
reinterpret_cast<std::string *>(ptr)->assign((const char *)p);
|
||||
} else {
|
||||
reinterpret_cast<std::string *>(ptr)->clear();
|
||||
}
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SDT_INTLIST: {
|
||||
if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) {
|
||||
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
|
||||
@@ -629,7 +643,6 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
IniGroup *group_def = nullptr, *group;
|
||||
IniItem *item;
|
||||
char buf[512];
|
||||
const char *s;
|
||||
void *ptr;
|
||||
|
||||
for (; sd->save.cmd != SL_END; sd++) {
|
||||
@@ -643,22 +656,22 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
if (sdb->flags & SGF_NO_NEWGAME) continue;
|
||||
|
||||
/* XXX - wtf is this?? (group override?) */
|
||||
s = strchr(sdb->name, '.');
|
||||
if (s != nullptr) {
|
||||
group = ini->GetGroup(sdb->name, s - sdb->name);
|
||||
s++;
|
||||
std::string s{ sdb->name };
|
||||
auto sc = s.find('.');
|
||||
if (sc != std::string::npos) {
|
||||
group = ini->GetGroup(s.substr(0, sc));
|
||||
s = s.substr(sc + 1);
|
||||
} else {
|
||||
if (group_def == nullptr) group_def = ini->GetGroup(grpname);
|
||||
s = sdb->name;
|
||||
group = group_def;
|
||||
}
|
||||
|
||||
item = group->GetItem(s, true);
|
||||
ptr = GetVariableAddress(object, sld);
|
||||
|
||||
if (item->value != nullptr) {
|
||||
if (item->value.has_value()) {
|
||||
/* check if the value is the same as the old value */
|
||||
const void *p = StringToVal(sdb, item->value);
|
||||
const void *p = StringToVal(sdb, item->value->c_str());
|
||||
|
||||
/* The main type of a variable/setting is in bytes 8-15
|
||||
* The subtype (what kind of numbers do we have there) is in 0-7 */
|
||||
@@ -732,6 +745,22 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
}
|
||||
break;
|
||||
|
||||
case SDT_STDSTRING:
|
||||
switch (GetVarMemType(sld->conv)) {
|
||||
case SLE_VAR_STR: strecpy(buf, reinterpret_cast<std::string *>(ptr)->c_str(), lastof(buf)); break;
|
||||
|
||||
case SLE_VAR_STRQ:
|
||||
if (reinterpret_cast<std::string *>(ptr)->empty()) {
|
||||
buf[0] = '\0';
|
||||
} else {
|
||||
seprintf(buf, lastof(buf), "\"%s\"", reinterpret_cast<std::string *>(ptr)->c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
|
||||
case SDT_INTLIST:
|
||||
MakeIntList(buf, lastof(buf), ptr, sld->length, sld->conv);
|
||||
break;
|
||||
@@ -740,8 +769,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
}
|
||||
|
||||
/* The value is different, that means we have to write it to the ini */
|
||||
free(item->value);
|
||||
item->value = stredup(buf);
|
||||
item->value.emplace(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -763,7 +791,7 @@ static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &li
|
||||
list.clear();
|
||||
|
||||
for (const IniItem *item = group->item; item != nullptr; item = item->next) {
|
||||
if (item->name != nullptr) list.emplace_back(item->name);
|
||||
if (!item->name.empty()) list.push_back(item->name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1610,14 +1638,14 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
|
||||
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);
|
||||
config->Change(item->name.c_str());
|
||||
if (!config->HasScript()) {
|
||||
if (strcmp(item->name, "none") != 0) {
|
||||
DEBUG(script, 0, "The AI by the name '%s' was no longer found, and removed from the list.", item->name);
|
||||
if (item->name != "none") {
|
||||
DEBUG(script, 0, "The AI by the name '%s' was no longer found, and removed from the list.", item->name.c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (item->value != nullptr) config->StringToSettings(item->value);
|
||||
if (item->value.has_value()) config->StringToSettings(item->value->c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1637,14 +1665,14 @@ static void GameLoadConfig(IniFile *ini, const char *grpname)
|
||||
|
||||
GameConfig *config = GameConfig::GetConfig(AIConfig::SSS_FORCE_NEWGAME);
|
||||
|
||||
config->Change(item->name);
|
||||
config->Change(item->name.c_str());
|
||||
if (!config->HasScript()) {
|
||||
if (strcmp(item->name, "none") != 0) {
|
||||
DEBUG(script, 0, "The GameScript by the name '%s' was no longer found, and removed from the list.", item->name);
|
||||
if (item->name != "none") {
|
||||
DEBUG(script, 0, "The GameScript by the name '%s' was no longer found, and removed from the list.", item->name.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (item->value != nullptr) config->StringToSettings(item->value);
|
||||
if (item->value.has_value()) config->StringToSettings(item->value->c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1668,7 +1696,7 @@ static int DecodeHexNibble(char c)
|
||||
* @param dest_size Number of bytes in \a dest.
|
||||
* @return Whether reading was successful.
|
||||
*/
|
||||
static bool DecodeHexText(char *pos, uint8 *dest, size_t dest_size)
|
||||
static bool DecodeHexText(const char *pos, uint8 *dest, size_t dest_size)
|
||||
{
|
||||
while (dest_size > 0) {
|
||||
int hi = DecodeHexNibble(pos[0]);
|
||||
@@ -1700,7 +1728,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
|
||||
GRFConfig *c = nullptr;
|
||||
|
||||
uint8 grfid_buf[4], md5sum[16];
|
||||
char *filename = item->name;
|
||||
const char *filename = item->name.c_str();
|
||||
bool has_grfid = false;
|
||||
bool has_md5sum = false;
|
||||
|
||||
@@ -1724,8 +1752,8 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
|
||||
if (c == nullptr) c = new GRFConfig(filename);
|
||||
|
||||
/* Parse parameters */
|
||||
if (!StrEmpty(item->value)) {
|
||||
int count = ParseIntList(item->value, c->param, lengthof(c->param));
|
||||
if (item->value.has_value() && !item->value->empty()) {
|
||||
int count = ParseIntList(item->value->c_str(), c->param, lengthof(c->param));
|
||||
if (count < 0) {
|
||||
SetDParamStr(0, filename);
|
||||
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
|
||||
@@ -1748,7 +1776,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
|
||||
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
|
||||
}
|
||||
|
||||
SetDParamStr(0, StrEmpty(filename) ? item->name : filename);
|
||||
SetDParamStr(0, StrEmpty(filename) ? item->name.c_str() : filename);
|
||||
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_GRF, WL_CRITICAL);
|
||||
delete c;
|
||||
continue;
|
||||
@@ -1959,8 +1987,8 @@ StringList GetGRFPresetList()
|
||||
|
||||
std::unique_ptr<IniFile> ini(IniLoadConfig());
|
||||
for (IniGroup *group = ini->group; group != nullptr; group = group->next) {
|
||||
if (strncmp(group->name, "preset-", 7) == 0) {
|
||||
list.emplace_back(group->name + 7);
|
||||
if (group->name.compare(0, 7, "preset-") == 0) {
|
||||
list.push_back(group->name.substr(7));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user