From 66acabe5c6439ea19592cc5ce00ca92f830a536c Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Mon, 29 Aug 2022 00:38:23 -0400 Subject: [PATCH] Refactored follower messages. --- include/follower_helper.h | 64 ++++++++++++++++++++++-- src/event_object_movement.c | 2 +- src/follower_helper.c | 98 ++++++++++++++++++++++++------------- 3 files changed, 125 insertions(+), 39 deletions(-) diff --git a/include/follower_helper.h b/include/follower_helper.h index 54b4d4d164..115242fdb9 100644 --- a/include/follower_helper.h +++ b/include/follower_helper.h @@ -16,9 +16,14 @@ enum { FOLLOWER_EMOTION_LENGTH, }; +// This struct is optimized for size +// Each "section" can be used to combine multiple conditions, +// i.e, species and map +// Just set the flags accordingly and use the right union member struct __attribute__((packed)) FollowerMsgInfoExtended { const u8 *text; const u8 *script; + union __attribute__((packed)) { u16 species:10; struct __attribute__((packed)) { @@ -55,7 +60,8 @@ struct __attribute__((packed)) FollowerMsgInfoExtended { } wt; u16 wtFlags:2; // 1 = weather matching, 2 = song, 3 = time u16 weight:3; - u16 textSpread:1; // if set, `text` is an array of texts instead + // if set, `text` is treated as an array of up to 4 texts instead + u16 textSpread:1; union __attribute__((packed)) { struct __attribute__((packed)) { @@ -63,9 +69,61 @@ struct __attribute__((packed)) FollowerMsgInfoExtended { u16 distance:6; } mb; } near; - u16 nearFlags:2; // 1 = mb within '+' shape distance away + u16 nearFlags:2; // 1 = mb within '+'-shaped distance away }; -extern const struct FollowerMsgInfoExtended gFollowerConditionalMessages[]; +enum { + ST_FLAGS_SPECIES = 1, + ST_FLAGS_TYPE, + ST_FLAGS_STATUS, +}; + +enum { + MM_FLAGS_MAPSEC = 1, + MM_FLAGS_MAP, + MM_FLAGS_MB, // (m)etatile (b)ehavior +}; + +enum { + WT_FLAGS_WEATHER = 1, + WT_FLAGS_MUSIC, + WT_FLAGS_TIME, +}; + +#define NEAR_FLAGS_MB 1 + +enum { + COND_MSG_CELEBI, + COND_MSG_FIRE, + COND_MSG_EVER_GRANDE, + COND_MSG_ROUTE_112, + COND_MSG_DAY_CARE, + COND_MSG_MART, + COND_MSG_VICTORY_ROAD, + COND_MSG_BIKE_SHOP, + COND_MSG_MACHINES, + COND_MSG_SAILING, + COND_MSG_PUDDLE, + COND_MSG_SAND, + COND_MSG_GRASS, + COND_MSG_FOOTPRINTS, + COND_MSG_ELEVATOR, + COND_MSG_ICE_ROOM, + COND_MSG_ROUTE_117, + COND_MSG_DRAGON_GROWL, + COND_MSG_FEAR, + COND_MSG_FIRE_RAIN, + COND_MSG_FROZEN, + COND_MSG_SEASIDE, + COND_MSG_WATERFALL, + COND_MSG_RAIN, + COND_MSG_REFLECTION, + COND_MSG_LEAVES, + COND_MSG_ICE, + COND_MSG_BURN, + COND_MSG_COUNT, +}; + +extern const struct FollowerMsgInfoExtended gFollowerConditionalMessages[COND_MSG_COUNT]; #endif //GUARD_FOLLOWER_HELPER_H diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 9822d2ba2b..60e0b035da 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -2083,7 +2083,7 @@ bool8 ScrFunc_getfolloweraction(struct ScriptContext *ctx) // Essentially a big } // Match scripted conditional messages // With 50% chance, try to match scripted conditional messages - for (i = (Random() & 1) ? 28 : 0, j = 1; i < 28; i++) { + for (i = (Random() & 1) ? COND_MSG_COUNT : 0, j = 1; i < COND_MSG_COUNT; i++) { const struct FollowerMsgInfoExtended *info = &gFollowerConditionalMessages[i]; if (info->stFlags == 1 && species != info->st.species) continue; diff --git a/src/follower_helper.c b/src/follower_helper.c index b477f1d1e9..328bd8aab0 100644 --- a/src/follower_helper.c +++ b/src/follower_helper.c @@ -66,204 +66,232 @@ static const u8 sCondMsg41[] = _("{STR_VAR_1} is touching the ice."); static const u8* const sIceTexts[] = {sCondMsg26, sCondMsg40, sCondMsg41, NULL}; static const u8 sCondMsg42[] = _("{STR_VAR_1}'s burn looks painful!"); -// Note that the size of this array must also be correct in event_object_movement -const struct FollowerMsgInfoExtended gFollowerConditionalMessages[28] = { +// See the struct definition in follower_helper.h for more info +const struct FollowerMsgInfoExtended gFollowerConditionalMessages[COND_MSG_COUNT] = { + [COND_MSG_CELEBI] = { .text = (u8*)sCelebiTexts, .textSpread = 1, .script = EventScript_FollowerDance, .st = {.species = SPECIES_CELEBI}, - .stFlags = 1, // MATCH_SPECIES + .stFlags = ST_FLAGS_SPECIES, .emotion = FOLLOWER_EMOTION_NEUTRAL, }, + [COND_MSG_FIRE] = { .text = (u8*)sFireTexts, .st = {.types = {.type1 = TYPE_FIRE, .type2 = TYPE_FIRE}}, - .stFlags = 2, // MATCH_TYPES + .stFlags = ST_FLAGS_TYPE, .emotion = FOLLOWER_EMOTION_NEUTRAL, .textSpread = 1, }, + [COND_MSG_EVER_GRANDE] = { .text = sCondMsg06, .script = EventScript_FollowerFaceUp, .mm = {.map = {.mapNum = MAP_NUM(EVER_GRANDE_CITY), .mapGroup = MAP_GROUP(EVER_GRANDE_CITY)}}, - .mmFlags = 2, // MATCH_MAP + .mmFlags = MM_FLAGS_MAP, .emotion = FOLLOWER_EMOTION_HAPPY, }, + [COND_MSG_ROUTE_112] = { .text = sCondMsg07, .mm = {.map = {.mapNum = MAP_NUM(ROUTE112), .mapGroup = MAP_GROUP(ROUTE112)}}, - .mmFlags = 2, // MATCH_MAP + .mmFlags = MM_FLAGS_MAP, .emotion = FOLLOWER_EMOTION_HAPPY, }, + [COND_MSG_DAY_CARE] = { .text = sCondMsg08, .script = EventScript_FollowerNostalgia, .mm = {.map = {.mapNum = MAP_NUM(ROUTE117_POKEMON_DAY_CARE), .mapGroup = MAP_GROUP(ROUTE117_POKEMON_DAY_CARE)}}, - .mmFlags = 2, // MATCH_MAP + .mmFlags = MM_FLAGS_MAP, .emotion = FOLLOWER_EMOTION_NEUTRAL, }, + [COND_MSG_MART] = { .text = (u8*)sShopTexts, .textSpread = 1, .script = EventScript_FollowerLookAround, .wt = {.song = MUS_POKE_MART}, - .wtFlags = 2, // MATCH_SONG + .wtFlags = WT_FLAGS_MUSIC, .emotion = FOLLOWER_EMOTION_NEUTRAL, }, + [COND_MSG_VICTORY_ROAD] = { .text = sCondMsg11, .wt = {.song = MUS_VICTORY_ROAD}, - .wtFlags = 2, // MATCH_SONG + .wtFlags = WT_FLAGS_MUSIC, .emotion = FOLLOWER_EMOTION_PENSIVE, }, + [COND_MSG_BIKE_SHOP] = { .text = sCondMsg12, .mm = {.map = {.mapNum = MAP_NUM(MAUVILLE_CITY_BIKE_SHOP), .mapGroup = MAP_GROUP(MAUVILLE_CITY_BIKE_SHOP)}}, - .mmFlags = 2, // MATCH_MAP + .mmFlags = MM_FLAGS_MAP, .emotion = FOLLOWER_EMOTION_PENSIVE, }, + [COND_MSG_MACHINES] = { .text = (u8*)sMachineTexts, .mm = {.map = {.mapNum = MAP_NUM(NEW_MAUVILLE_INSIDE), .mapGroup = MAP_GROUP(NEW_MAUVILLE_INSIDE)}}, - .mmFlags = 2, // MAP + .mmFlags = MM_FLAGS_MAP, .emotion = FOLLOWER_EMOTION_MUSIC, .textSpread = 1, }, + [COND_MSG_SAILING] = { .text = (u8*)sBoatTexts, .script = EventScript_FollowerLookAround, .wt = {.song = MUS_SAILING}, - .wtFlags = 2, // MATCH_SONG + .wtFlags = WT_FLAGS_MUSIC, .emotion = FOLLOWER_EMOTION_MUSIC, .textSpread = 1, }, + [COND_MSG_PUDDLE] = { .text = sCondMsg18, .script = EventScript_FollowerHopping, .mm = {.mb = {.behavior1 = MB_SHALLOW_WATER, .behavior2 = MB_PUDDLE}}, - .mmFlags = 3, // MB + .mmFlags = MM_FLAGS_MB, .emotion = FOLLOWER_EMOTION_MUSIC, }, + [COND_MSG_SAND] = { .text = sCondMsg19, .mm = {.mb = {.behavior1 = MB_SAND, .behavior2 = MB_DEEP_SAND}}, - .mmFlags = 3, // MB + .mmFlags = MM_FLAGS_MB, .emotion = FOLLOWER_EMOTION_MUSIC, }, + [COND_MSG_GRASS] = { .text = sCondMsg20, .mm = {.mb = {.behavior1 = MB_TALL_GRASS, .behavior2 = MB_LONG_GRASS}}, - .mmFlags = 3, // MB + .mmFlags = MM_FLAGS_MB, .emotion = FOLLOWER_EMOTION_MUSIC, }, + [COND_MSG_FOOTPRINTS] = { .text = sCondMsg21, .mm = {.mb = {.behavior1 = MB_SAND, .behavior2 = MB_FOOTPRINTS}}, - .mmFlags = 3, // MB + .mmFlags = MM_FLAGS_MB, .emotion = FOLLOWER_EMOTION_MUSIC, }, + [COND_MSG_ELEVATOR] = { .text = (u8*)sElevatorTexts, .textSpread = 1, .mm = {.map = {.mapNum = MAP_NUM(LILYCOVE_CITY_DEPARTMENT_STORE_ELEVATOR), .mapGroup = MAP_GROUP(LILYCOVE_CITY_DEPARTMENT_STORE_ELEVATOR)}}, - .mmFlags = 2, // MAP + .mmFlags = MM_FLAGS_MAP, .emotion = FOLLOWER_EMOTION_SURPRISE, }, + [COND_MSG_ICE_ROOM] = { .text = (u8*)sColdTexts, .textSpread = 1, .mm = {.map = {.mapNum = MAP_NUM(SHOAL_CAVE_LOW_TIDE_ICE_ROOM), .mapGroup = MAP_GROUP(SHOAL_CAVE_LOW_TIDE_ICE_ROOM)}}, - .mmFlags = 2, // MAP + .mmFlags = MM_FLAGS_MAP, .emotion = FOLLOWER_EMOTION_SURPRISE, }, + [COND_MSG_ROUTE_117] = { .text = sCondMsg27, .mm = {.map = {.mapNum = MAP_NUM(ROUTE117), .mapGroup = MAP_GROUP(ROUTE117)}}, - .mmFlags = 2, // MAP + .mmFlags = MM_FLAGS_MAP, .emotion = FOLLOWER_EMOTION_SURPRISE, }, + [COND_MSG_DRAGON_GROWL] = { .text = sCondMsg28, .st = {.types = {.type1 = TYPE_DRAGON, .type2 = TYPE_DRAGON}}, - .stFlags = 2, // MATCH_TYPES + .stFlags = ST_FLAGS_TYPE, .mm = {.mapSec = {.mapSec = MAPSEC_SKY_PILLAR}}, - .mmFlags = 1, // MAP_SEC + .mmFlags = MM_FLAGS_MAPSEC, .emotion = FOLLOWER_EMOTION_UPSET, }, + [COND_MSG_FEAR] = { .text = (u8*)sFearTexts, .textSpread = 1, .st = {.types = {.type1 = TYPE_GHOST, .type2 = TYPE_NOT_TYPE1}}, - .stFlags = 2, // TYPE + .stFlags = ST_FLAGS_TYPE, .mm = {.mapSec = {.mapSec = MAPSEC_MT_PYRE}}, - .mmFlags = 1, // MAP_SEC + .mmFlags = MM_FLAGS_MAPSEC, .wt = {.song = MUS_MT_PYRE}, - .wtFlags = 2, // SONG + .wtFlags = WT_FLAGS_MUSIC, .emotion = FOLLOWER_EMOTION_UPSET, }, + [COND_MSG_FIRE_RAIN] = { .text = sCondMsg31, .st = {.types = {.type1 = TYPE_FIRE, .type2 = TYPE_FIRE}}, - .stFlags = 2, // TYPE + .stFlags = ST_FLAGS_TYPE, .wt = {.weather = {.weather1 = WEATHER_RAIN, .weather2 = WEATHER_RAIN_THUNDERSTORM}}, - .wtFlags = 1, // WEATHER + .wtFlags = WT_FLAGS_WEATHER, .emotion = FOLLOWER_EMOTION_UPSET, }, + [COND_MSG_FROZEN] = { .text = sCondMsg32, .st = {.status = STATUS1_FREEZE}, - .stFlags = 3, // STATUS + .stFlags = ST_FLAGS_STATUS, .emotion = FOLLOWER_EMOTION_UPSET, }, + [COND_MSG_SEASIDE] = { .text = (u8*)sSeaTexts, .textSpread = 1, .script = EventScript_FollowerFaceResult, .near = {.mb = {.behavior = MB_OCEAN_WATER, .distance = 5}}, - .nearFlags = 1, // mb + .nearFlags = NEAR_FLAGS_MB, .emotion = FOLLOWER_EMOTION_MUSIC, }, + [COND_MSG_WATERFALL] = { .text = sCondMsg36, .script = EventScript_FollowerFaceResult, .near = {.mb = {.behavior = MB_WATERFALL, .distance = 5}}, - .nearFlags = 1, // mb + .nearFlags = NEAR_FLAGS_MB, .emotion = FOLLOWER_EMOTION_MUSIC, }, + [COND_MSG_RAIN] = { .text = sCondMsg37, .st = {.types = {.type1 = TYPE_FIRE, .type2 = TYPE_NOT_TYPE1}}, - .stFlags = 2, // TYPE + .stFlags = ST_FLAGS_TYPE, .wt = {.weather = {.weather1 = WEATHER_RAIN, .weather2 = WEATHER_RAIN_THUNDERSTORM}}, - .wtFlags = 1, // WEATHER + .wtFlags = WT_FLAGS_WEATHER, .emotion = FOLLOWER_EMOTION_MUSIC, }, + [COND_MSG_REFLECTION] = { .text = sCondMsg38, .script = EventScript_FollowerFaceResult, .near = {.mb = {.behavior = MB_POND_WATER, .distance = 1}}, - .nearFlags = 1, // mb + .nearFlags = NEAR_FLAGS_MB, .emotion = FOLLOWER_EMOTION_PENSIVE, }, + [COND_MSG_LEAVES] = { .text = sCondMsg39, .mm = {.mapSec = {.mapSec = MAPSEC_PETALBURG_WOODS}}, - .mmFlags = 1, // MAP_SEC + .mmFlags = MM_FLAGS_MAPSEC, .emotion = FOLLOWER_EMOTION_PENSIVE, }, + [COND_MSG_ICE] = { .text = (u8*)sIceTexts, .textSpread = 1, .script = EventScript_FollowerFaceResult, .near = {.mb = {.behavior = MB_ICE, .distance = 1}}, - .nearFlags = 1, // mb + .nearFlags = NEAR_FLAGS_MB, .emotion = FOLLOWER_EMOTION_PENSIVE, }, + [COND_MSG_BURN] = { .text = sCondMsg42, .st = {.status STATUS1_BURN}, - .stFlags 3, // STATUS + .stFlags = ST_FLAGS_STATUS, .emotion = FOLLOWER_EMOTION_SAD, }, };