diff --git a/src/message.cc b/src/message.cc index 4491b29..dadfd8a 100644 --- a/src/message.cc +++ b/src/message.cc @@ -4,7 +4,9 @@ #include "game_config.h" #include "memory.h" #include "platform_compat.h" +#include "proto_types.h" #include "random.h" +#include "sfall_config.h" #include #include @@ -569,3 +571,46 @@ bool messageListFilterBadwords(MessageList* messageList) return true; } + +void messageListFilterGenderWords(MessageList* messageList, int gender) +{ + if (messageList == NULL) { + return; + } + + bool enabled = false; + configGetBool(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_GAME_DIALOG_GENDER_WORDS_KEY, &enabled); + if (!enabled) { + return; + } + + for (int index = 0; index < messageList->entries_num; index++) { + MessageListItem* item = &(messageList->entries[index]); + char* text = item->text; + char* sep; + + while ((sep = strchr(text, '^')) != NULL) { + *sep = '\0'; + char* start = strrchr(text, '<'); + char* end = strchr(sep + 1, '>'); + *sep = '^'; + + if (start != NULL && end != NULL) { + char* src; + size_t length; + if (gender == GENDER_FEMALE) { + src = sep + 1; + length = end - sep - 1; + } else { + src = start + 1; + length = sep - start - 1; + } + + strncpy(start, src, length); + strcpy(start + length, end + 1); + } else { + text = sep + 1; + } + } + } +} diff --git a/src/message.h b/src/message.h index a1fab3a..ff70d76 100644 --- a/src/message.h +++ b/src/message.h @@ -27,4 +27,6 @@ bool _message_make_path(char* dest, const char* path); char* getmsg(MessageList* msg, MessageListItem* entry, int num); bool messageListFilterBadwords(MessageList* messageList); +void messageListFilterGenderWords(MessageList* messageList, int gender); + #endif /* MESSAGE_H */ diff --git a/src/scripts.cc b/src/scripts.cc index fcbff25..dd31748 100644 --- a/src/scripts.cc +++ b/src/scripts.cc @@ -24,6 +24,7 @@ #include "proto.h" #include "proto_instance.h" #include "queue.h" +#include "stat.h" #include "tile.h" #include "window_manager.h" #include "window_manager_private.h" @@ -2661,6 +2662,10 @@ static int scriptsGetMessageList(int a1, MessageList** messageListPtr) debugPrint("\nError filtering script dialog message file!"); return -1; } + + // SFALL: Gender-specific words. + int gender = critterGetStat(gDude, STAT_GENDER); + messageListFilterGenderWords(messageList, gender); } *messageListPtr = messageList; diff --git a/src/sfall_config.h b/src/sfall_config.h index 0956e23..73c7845 100644 --- a/src/sfall_config.h +++ b/src/sfall_config.h @@ -55,6 +55,7 @@ #define SFALL_CONFIG_SCIENCE_REPAIR_TARGET_TYPE_KEY "ScienceOnCritters" #define SFALL_CONFIG_GAME_DIALOG_FIX_KEY "DialogueFix" #define SFALL_CONFIG_TWEAKS_FILE_KEY "TweaksFile" +#define SFALL_CONFIG_GAME_DIALOG_GENDER_WORDS_KEY "DialogGenderWords" #define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_MULTIPLIER 1 #define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_DIVISOR 3