From d9735f603c311a78062c9ebf4a10e1da204a5c75 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sat, 15 Feb 2020 00:47:42 +0100 Subject: Add default values and limits to pet DB fields --- db/pre-re/pet_db.conf | 24 ++++++++++++------------ db/re/pet_db.conf | 24 ++++++++++++------------ src/map/pet.c | 52 ++++++++++++++++++++++++++++++--------------------- 3 files changed, 55 insertions(+), 45 deletions(-) diff --git a/db/pre-re/pet_db.conf b/db/pre-re/pet_db.conf index d80434f46..ea8059154 100644 --- a/db/pre-re/pet_db.conf +++ b/db/pre-re/pet_db.conf @@ -39,22 +39,22 @@ pet_db:( // ================ Optional fields =============================== TamingItem: Taming Item (string, defaults to 0) AccessoryItem: Equipment Id (string, defaults to 0) - FoodItem: Food Id (string, defaults to 0) - FoodEffectiveness: hunger points (int, defaults to 0) - HungerDelay: hunger time (int, defaults to 0) + FoodItem: Food Id (string, defaults to "Pet_Food" (ID=537)) + FoodEffectiveness: hunger points (int, defaults to 80) + HungerDelay: hunger time (int, defaults to 60) Intimacy: { - Initial: start intimacy (int, defaults to 0) - FeedIncrement: feeding intimacy (int, defaults to 0) - OverFeedDecrement: overfeeding intimacy (int, defaults to 0) - OwnerDeathDecrement: owner die intimacy (int, defaults to 0) + Initial: start intimacy (int, defaults to 250) + FeedIncrement: feeding intimacy (int, defaults to 10) + OverFeedDecrement: overfeeding intimacy (int, defaults to 100) + OwnerDeathDecrement: owner die intimacy (int, defaults to 20) } - CaptureRate: capture rate (int, defaults to 0) - Speed: speed (int, defaults to 0) + CaptureRate: capture rate (int, defaults to 1000) + Speed: speed (int, defaults to 150) SpecialPerformance: true/false (boolean, defaults to false) TalkWithEmotes: convert talk (boolean, defaults to false) - AttackRate: attack rate (int, defaults to 0) - DefendRate: Defence attack (int, defaults to 0) - ChangeTargetRate: change target (int, defaults to 0) + AttackRate: attack rate (int, defaults to 300) + DefendRate: Defence attack (int, defaults to 300) + ChangeTargetRate: change target (int, defaults to 800) Evolve: { EggID: { (string, Evolved Pet EggID) Name: Amount (items required to perform evolution) diff --git a/db/re/pet_db.conf b/db/re/pet_db.conf index 3a1ceb5e0..34bb535db 100644 --- a/db/re/pet_db.conf +++ b/db/re/pet_db.conf @@ -39,22 +39,22 @@ pet_db:( // ================ Optional fields =============================== TamingItem: Taming Item (string, defaults to 0) AccessoryItem: Equipment Id (string, defaults to 0) - FoodItem: Food Id (string, defaults to 0) - FoodEffectiveness: hunger points (int, defaults to 0) - HungerDelay: hunger time (int, defaults to 0) + FoodItem: Food Id (string, defaults to "Pet_Food" (ID=537)) + FoodEffectiveness: hunger points (int, defaults to 80) + HungerDelay: hunger time (int, defaults to 60) Intimacy: { - Initial: start intimacy (int, defaults to 0) - FeedIncrement: feeding intimacy (int, defaults to 0) - OverFeedDecrement: overfeeding intimacy (int, defaults to 0) - OwnerDeathDecrement: owner die intimacy (int, defaults to 0) + Initial: start intimacy (int, defaults to 250) + FeedIncrement: feeding intimacy (int, defaults to 10) + OverFeedDecrement: overfeeding intimacy (int, defaults to 100) + OwnerDeathDecrement: owner die intimacy (int, defaults to 20) } - CaptureRate: capture rate (int, defaults to 0) - Speed: speed (int, defaults to 0) + CaptureRate: capture rate (int, defaults to 1000) + Speed: speed (int, defaults to 150) SpecialPerformance: true/false (boolean, defaults to false) TalkWithEmotes: convert talk (boolean, defaults to false) - AttackRate: attack rate (int, defaults to 0) - DefendRate: Defence attack (int, defaults to 0) - ChangeTargetRate: change target (int, defaults to 0) + AttackRate: attack rate (int, defaults to 300) + DefendRate: Defence attack (int, defaults to 300) + ChangeTargetRate: change target (int, defaults to 800) Evolve: { EggID: { (string, Evolved Pet EggID) Name: Amount (items required to perform evolution) diff --git a/src/map/pet.c b/src/map/pet.c index ba873dd4b..90cab5626 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -1393,33 +1393,43 @@ static int pet_read_db_sub(struct config_setting_t *it, int n, const char *sourc } } + pet->db[n].FoodID = 537; + if (libconfig->setting_lookup_string(it, "FoodItem", &str)) { if (!(data = itemdb->name2id(str))) { - ShowWarning("pet_read_db_sub: Invalid item '%s' in pet %d of \"%s\", defaulting to 0.\n", str, pet->db[n].class_, source); + ShowWarning("pet_read_db_sub: Invalid FoodItem '%s' in pet %d of \"%s\", defaulting to Pet_Food (ID=537).\n", str, pet->db[n].class_, source); } else { pet->db[n].FoodID = data->nameid; } } - if (libconfig->setting_lookup_int(it, "FoodEffectiveness", &i32)) - pet->db[n].fullness = i32; + int ret = libconfig->setting_lookup_int(it, "FoodEffectiveness", &i32); + pet->db[n].fullness = (ret == CONFIG_FALSE) ? 80 : cap_value(i32, 1, PET_HUNGER_STUFFED); + + ret = libconfig->setting_lookup_int(it, "HungerDelay", &i32); + pet->db[n].hungry_delay = (ret == CONFIG_FALSE) ? 60000 : cap_value(1000 * i32, 0, INT_MAX); - if (libconfig->setting_lookup_int(it, "HungerDelay", &i32)) - pet->db[n].hungry_delay = i32 * 1000; + /** + * Preventively set default intimacy values here, just in case that 'Intimacy' block is not defined, + * or pet_read_db_sub_intimacy() fails execution. + * + **/ + pet->db[n].intimate = PET_INTIMACY_NEUTRAL; + pet->db[n].r_hungry = 10; + pet->db[n].r_full = 100; + pet->db[n].die = 20; if ((t = libconfig->setting_get_member(it, "Intimacy"))) { if (config_setting_is_group(t)) { pet->read_db_sub_intimacy(n, t); } } - if (pet->db[n].r_hungry <= 0) - pet->db[n].r_hungry = 1; - if (libconfig->setting_lookup_int(it, "CaptureRate", &i32)) - pet->db[n].capture = i32; + ret = libconfig->setting_lookup_int(it, "CaptureRate", &i32); + pet->db[n].capture = (ret == CONFIG_FALSE) ? 1000 : cap_value(i32, 1, 10000); - if (libconfig->setting_lookup_int(it, "Speed", &i32)) - pet->db[n].speed = i32; + ret = libconfig->setting_lookup_int(it, "Speed", &i32); + pet->db[n].speed = (ret == CONFIG_FALSE) ? DEFAULT_WALK_SPEED : cap_value(i32, MIN_WALK_SPEED, MAX_WALK_SPEED); if ((t = libconfig->setting_get_member(it, "SpecialPerformance")) && (i32 = libconfig->setting_get_bool(t))) pet->db[n].s_perfor = (char)i32; @@ -1427,14 +1437,14 @@ static int pet_read_db_sub(struct config_setting_t *it, int n, const char *sourc if ((t = libconfig->setting_get_member(it, "TalkWithEmotes")) && (i32 = libconfig->setting_get_bool(t))) pet->db[n].talk_convert_class = i32; - if (libconfig->setting_lookup_int(it, "AttackRate", &i32)) - pet->db[n].attack_rate = i32; + ret = libconfig->setting_lookup_int(it, "AttackRate", &i32); + pet->db[n].attack_rate = (ret == CONFIG_FALSE) ? 300 : cap_value(i32, 0, 10000); - if (libconfig->setting_lookup_int(it, "DefendRate", &i32)) - pet->db[n].defence_attack_rate = i32; + ret = libconfig->setting_lookup_int(it, "DefendRate", &i32); + pet->db[n].defence_attack_rate = (ret == CONFIG_FALSE) ? 300 : cap_value(i32, 0, 10000); - if (libconfig->setting_lookup_int(it, "ChangeTargetRate", &i32)) - pet->db[n].change_target_rate = i32; + ret = libconfig->setting_lookup_int(it, "ChangeTargetRate", &i32); + pet->db[n].change_target_rate = (ret == CONFIG_FALSE) ? 800 : cap_value(i32, 0, 10000); // Pet Evolution if ((t = libconfig->setting_get_member(it, "Evolve")) && config_setting_is_group(t)) { @@ -1536,16 +1546,16 @@ static bool pet_read_db_sub_intimacy(int idx, struct config_setting_t *t) Assert_ret(idx >= 0 && idx < MAX_PET_DB); if (libconfig->setting_lookup_int(t, "Initial", &i32)) - pet->db[idx].intimate = i32; + pet->db[idx].intimate = cap_value(i32, PET_INTIMACY_AWKWARD, PET_INTIMACY_MAX); if (libconfig->setting_lookup_int(t, "FeedIncrement", &i32)) - pet->db[idx].r_hungry = i32; + pet->db[idx].r_hungry = cap_value(i32, PET_INTIMACY_AWKWARD, PET_INTIMACY_MAX); if (libconfig->setting_lookup_int(t, "OverFeedDecrement", &i32)) - pet->db[idx].r_full = i32; + pet->db[idx].r_full = cap_value(i32, PET_INTIMACY_NONE, PET_INTIMACY_MAX); if (libconfig->setting_lookup_int(t, "OwnerDeathDecrement", &i32)) - pet->db[idx].die = i32; + pet->db[idx].die = cap_value(i32, PET_INTIMACY_NONE, PET_INTIMACY_MAX); return true; } -- cgit v1.2.3-70-g09d2