From 3727be9511973783d191633b53d3bffd5a50a46c Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Sat, 1 Jun 2024 14:46:45 -0400 Subject: [PATCH] fix: fixed a few oversights with follower message generation --- include/follower_helper.h | 2 +- src/event_object_movement.c | 12 +++++++----- src/random.c | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/follower_helper.h b/include/follower_helper.h index bfe19fb2d4..4d316ba1a3 100644 --- a/include/follower_helper.h +++ b/include/follower_helper.h @@ -65,7 +65,7 @@ struct FollowerMsgInfoExtended { #define MATCH_SPECIES(species) MATCH_U24(MSG_COND_SPECIES, species) #define MATCH_TYPES(type1, type2) MATCH_U8(MSG_COND_TYPE, type1, type2, 0) // Checks that follower has *neither* of the two types -#define MATCH_NOT_TYPES(type1, type2) MATCH_U8(MSG_COND_TYPE, type1, type2, TYPE_NONE) +#define MATCH_NOT_TYPES(type1, type2) MATCH_U8(MSG_COND_TYPE, type1, type2, TYPE_NONE | 1) #define MATCH_STATUS(status) MATCH_U24(MSG_COND_STATUS, status) #define MATCH_MAPSEC(mapsec) MATCH_U24(MSG_COND_MAPSEC, mapsec) #define MATCH_MAP_RAW(mapGroup, mapNum) MATCH_U8(MSG_COND_MAP, mapGroup, mapNum, 0) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index c16de175cc..436f048a5a 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -2114,12 +2114,12 @@ bool32 CheckMsgCondition(const struct MsgCondition *cond, struct Pokemon *mon, u case MSG_COND_TYPE: multi = (SpeciesHasType(species, cond->data.bytes[0]) || SpeciesHasType(species, cond->data.bytes[1])); - // if bytes[2] == TYPE_NONE, + // if bytes[2] nonzero, // invert; check that mon has *neither* type! - if (cond->data.bytes[2] == 0) - return multi; - else + if (cond->data.bytes[2] != 0) return !multi; + else + return multi; break; case MSG_COND_STATUS: return (cond->data.raw & mon->status); @@ -2190,9 +2190,11 @@ bool8 ScrFunc_getfolloweraction(struct ScriptContext *ctx) // Essentially a big [FOLLOWER_EMOTION_UPSET] = 15, [FOLLOWER_EMOTION_ANGRY] = 15, [FOLLOWER_EMOTION_PENSIVE] = 15, + [FOLLOWER_EMOTION_LOVE] = 0, [FOLLOWER_EMOTION_SURPRISE] = 10, [FOLLOWER_EMOTION_CURIOUS] = 10, [FOLLOWER_EMOTION_MUSIC] = 15, + [FOLLOWER_EMOTION_POISONED] = 0, }; u32 i, j; bool32 pickedCondition = FALSE; @@ -2220,7 +2222,7 @@ bool8 ScrFunc_getfolloweraction(struct ScriptContext *ctx) // Essentially a big if (GetCurrentWeather() == WEATHER_SUNNY_CLOUDS) condEmotes[condCount++] = (struct SpecialEmote) {.emotion=FOLLOWER_EMOTION_HAPPY, .index=31}; // Health & status-related - multi = mon->hp * 100 / mon->maxHP; + multi = SAFE_DIV(mon->hp * 100, mon->maxHP); if (multi < 20) { emotion_weight[FOLLOWER_EMOTION_SAD] = 30; condEmotes[condCount++] = (struct SpecialEmote) {.emotion=FOLLOWER_EMOTION_SAD, .index=4}; diff --git a/src/random.c b/src/random.c index 145da9bf63..c7f8212bdd 100644 --- a/src/random.c +++ b/src/random.c @@ -35,15 +35,15 @@ u16 Random2(void) // Returns a random index according to a list of weights u8 RandomWeightedIndex(u8 *weights, u8 length) { u32 i; - u16 random_value; + u16 randomValue; u16 weightSum = 0; for (i = 0; i < length; i++) weightSum += weights[i]; - random_value = Random() % weightSum; + randomValue = weightSum > 0 ? Random() % weightSum : 0; weightSum = 0; for (i = 0; i < length; i++) { weightSum += weights[i]; - if (random_value <= weightSum) + if (randomValue <= weightSum) return i; } }