Skip to content

Commit 5e3a480

Browse files
committed
Set constant at the end of every iteration at config reading
Also added handler for when storage capacity is invalid or set below 1
1 parent a066bc3 commit 5e3a480

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/map/storage.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ static void storage_config_read_additional_fields(struct config_setting_t* t, st
10041004
* @param imported Whether the current config is imported from another file.
10051005
* @retval false in case of error.
10061006
*/
1007-
bool storage_config_read(const char* filename, bool imported)
1007+
bool storage_config_read(const char *filename, bool imported)
10081008
{
10091009
nullpo_retr(false, filename);
10101010

@@ -1054,24 +1054,29 @@ bool storage_config_read(const char* filename, bool imported)
10541054
continue;
10551055
}
10561056

1057-
if (libconfig->setting_lookup_string(t, "Constant", &constant) == CONFIG_FALSE) {
1058-
ShowError("storage_config_read: Constant field not found for storage configuration (Id: %d) in '%s'. Skipping...\n", s_conf.uid, filename);
1059-
continue;
1060-
} else {
1061-
script->set_constant(constant, s_conf.uid, false, false);
1062-
}
1063-
10641057
/* Capacity */
10651058
if (libconfig->setting_lookup_int(t, "Capacity", &s_conf.capacity) == CONFIG_FALSE) {
10661059
ShowError("storage_config_read: Capacity field not found for storage configuration (Id: %d) in '%s'. Skipping...\n", s_conf.uid, filename);
10671060
continue;
10681061
}
10691062

1063+
if (s_conf.capacity < 1) {
1064+
ShowWarning("storage_config_read: Invalid capacity for Storage #%d ('%s'). Skipping...\n", s_conf.uid, s_conf.name);
1065+
continue;
1066+
}
1067+
10701068
if (s_conf.capacity > MAX_STORAGE) {
10711069
ShowWarning("storage_config_read: Capacity for Storage #%d ('%s') is over MAX_STORAGE. Capping to %d.\n", s_conf.uid, s_conf.name, MAX_STORAGE);
10721070
s_conf.capacity = min(s_conf.capacity, MAX_STORAGE);
10731071
}
10741072

1073+
if (libconfig->setting_lookup_string(t, "Constant", &constant) == CONFIG_FALSE) {
1074+
ShowError("storage_config_read: Constant field not found for storage configuration (Id: %d) in '%s'. Skipping...\n", s_conf.uid, filename);
1075+
continue;
1076+
}
1077+
1078+
script->set_constant(constant, s_conf.uid, false, false);
1079+
10751080
/* Additional Fields */
10761081
storage->config_read_additional_fields(t, &s_conf, filename);
10771082

@@ -1089,7 +1094,7 @@ bool storage_config_read(const char* filename, bool imported)
10891094
const char* import = NULL;
10901095
if (libconfig->lookup_string(&stor_libconf, "import", &import) == CONFIG_TRUE) {
10911096
if (strcmp(import, filename) == 0 || strcmp(import, map->STORAGE_CONF_FILENAME) == 0) {
1092-
ShowWarning("battle_config_read: Loop detected! Skipping 'import'...\n");
1097+
ShowWarning("storage_config_read: Loop detected! Skipping 'import'...\n");
10931098
libconfig->destroy(&stor_libconf);
10941099
return false;
10951100
} else if (storage->config_read(import, true) == false) {

0 commit comments

Comments
 (0)