Changed "add_extra_msg_file" script function (#249)

* added auto ID assignment for the message file.
This commit is contained in:
NovaRain
2019-07-16 12:45:22 +08:00
parent 2bfb886ece
commit 16fbc0f93f
5 changed files with 30 additions and 9 deletions
+1 -1
View File
@@ -244,7 +244,7 @@
#define ADD_PERK_MODE_REMOVE (4) // remove from the list of selectable perks
// sfall_funcX macros
#define add_extra_msg_file(name, number) sfall_func2("add_extra_msg_file", name, number)
#define add_extra_msg_file(name) sfall_func1("add_extra_msg_file", name)
#define add_iface_tag sfall_func0("add_iface_tag")
#define art_cache_clear sfall_func0("art_cache_clear")
#define attack_is_aimed sfall_func0("attack_is_aimed")
+6 -3
View File
@@ -609,10 +609,13 @@ optional arguments:
> int sfall_func2("has_fake_trait_npc", object npc, string nameTrait)
- these functions are similar to has_fake_*/set_fake_*/set_selectable_perk functions, but apply to the specified party member NPC (including dude_obj)
> void sfall_func2("add_extra_msg_file", string fileName, int fileNumber)
- loads the custom message file and assigns it with the specified ID number
> int sfall_func1("add_extra_msg_file", string fileName)
> int sfall_func2("add_extra_msg_file", string fileName, int fileNumber)
- loads the custom message file, and returns the file ID number assigned to it in range from 0x3000 to 0x3FFF for the message_str_game function to get messages from the file
- fileName: the name of the custom message file (including the .msg extension) in "text\<language>\game\" directory
- fileNumber: the file ID number for the message_str_game function to get messages from the file. The available range is from 0x3000 to 0x3FFF
optional argument:
- fileNumber: the file ID number for the message_str_game function. The available range is from 0x2000 to 0x2FFF (see ExtraGameMsgFileList setting in ddraw.ini)
use fileNumber only if you want to add a message file without editing ddraw.ini or existing scripts to support the old way
------------------------
------ MORE INFO -------
+11 -2
View File
@@ -56,6 +56,8 @@ const fo::MessageList* gameMsgFiles[] = {
ExtraGameMessageListsMap gExtraGameMsgLists;
static std::vector<std::string> msgFileList;
static long msgNumCounter = 0x3000;
fo::MessageNode *GetMsgNode(fo::MessageList *msgList, int msgRef) {
if (msgList != nullptr && msgList->numMsgs > 0) {
fo::MessageNode *msgNode = msgList->nodes;
@@ -115,16 +117,22 @@ static void ReadExtraGameMsgFiles() {
}
long Message::AddExtraMsgFile(const char* msgName, long msgNumber) {
if (msgNumber < 0x3000 || msgNumber > 0x3FFF || gExtraGameMsgLists.count(msgNumber)) return -1;
if (msgNumber) {
if (msgNumber < 0x2000 || msgNumber > 0x2FFF) return -1;
if (gExtraGameMsgLists.count(msgNumber)) return 0; // file has already been added
} else if (msgNumCounter > 0x3FFF) return -3;
std::string path("game\\");
path += msgName;
fo::MessageList* list = new fo::MessageList();
if (fo::func::message_load(list, path.c_str())) {
if (msgNumber == 0) msgNumber = msgNumCounter++;
gExtraGameMsgLists.emplace(msgNumber, list);
} else {
delete list;
msgNumber = -2;
}
return 0;
return msgNumber;
}
static void ClearScriptAddedExtraGameMsg() { // C++11
@@ -136,6 +144,7 @@ static void ClearScriptAddedExtraGameMsg() { // C++11
++it;
}
}
msgNumCounter = 0x3000;
}
static void ClearReadExtraGameMsgFiles() {
@@ -59,7 +59,7 @@ static MetaruleTableType metaruleTable;
- arg1, arg2, ... - argument types for automatic validation
*/
static const SfallMetarule metarules[] = {
{"add_extra_msg_file", sf_add_extra_msg_file, 2, 2, {ARG_STRING, ARG_INT}},
{"add_extra_msg_file", sf_add_extra_msg_file, 1, 2, {ARG_STRING, ARG_INT}},
{"add_iface_tag", sf_add_iface_tag, 0, 0},
{"art_cache_clear", sf_art_cache_flush, 0, 0},
{"attack_is_aimed", sf_attack_is_aimed, 0, 0},
+11 -2
View File
@@ -298,8 +298,17 @@ void sf_message_str_game(OpcodeContext& ctx) {
}
void sf_add_extra_msg_file(OpcodeContext& ctx) {
long result = Message::AddExtraMsgFile(ctx.arg(0).strValue(), ctx.arg(1).rawValue());
if (result == -1) ctx.printOpcodeError("%s() - cannot add message file with the specified number.", ctx.getMetaruleName());
long result = Message::AddExtraMsgFile(ctx.arg(0).strValue(), (ctx.numArgs() == 2) ? ctx.arg(1).rawValue() : 0);
switch (result) {
case -1 :
ctx.printOpcodeError("%s() - cannot add message file with the specified number.", ctx.getMetaruleName());
break;
case -2 :
ctx.printOpcodeError("%s() - error loading message file.", ctx.getMetaruleName());
break;
case -3 :
ctx.printOpcodeError("%s() - the limit of adding message files has been exceeded.", ctx.getMetaruleName());
}
ctx.setReturn(result);
}