mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Changed "add_extra_msg_file" script function (#249)
* added auto ID assignment for the message file.
This commit is contained in:
@@ -244,7 +244,7 @@
|
|||||||
#define ADD_PERK_MODE_REMOVE (4) // remove from the list of selectable perks
|
#define ADD_PERK_MODE_REMOVE (4) // remove from the list of selectable perks
|
||||||
|
|
||||||
// sfall_funcX macros
|
// 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 add_iface_tag sfall_func0("add_iface_tag")
|
||||||
#define art_cache_clear sfall_func0("art_cache_clear")
|
#define art_cache_clear sfall_func0("art_cache_clear")
|
||||||
#define attack_is_aimed sfall_func0("attack_is_aimed")
|
#define attack_is_aimed sfall_func0("attack_is_aimed")
|
||||||
|
|||||||
@@ -609,10 +609,13 @@ optional arguments:
|
|||||||
> int sfall_func2("has_fake_trait_npc", object npc, string nameTrait)
|
> 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)
|
- 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)
|
> int sfall_func1("add_extra_msg_file", string fileName)
|
||||||
- loads the custom message file and assigns it with the specified ID number
|
> 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
|
- 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 -------
|
------ MORE INFO -------
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ const fo::MessageList* gameMsgFiles[] = {
|
|||||||
ExtraGameMessageListsMap gExtraGameMsgLists;
|
ExtraGameMessageListsMap gExtraGameMsgLists;
|
||||||
static std::vector<std::string> msgFileList;
|
static std::vector<std::string> msgFileList;
|
||||||
|
|
||||||
|
static long msgNumCounter = 0x3000;
|
||||||
|
|
||||||
fo::MessageNode *GetMsgNode(fo::MessageList *msgList, int msgRef) {
|
fo::MessageNode *GetMsgNode(fo::MessageList *msgList, int msgRef) {
|
||||||
if (msgList != nullptr && msgList->numMsgs > 0) {
|
if (msgList != nullptr && msgList->numMsgs > 0) {
|
||||||
fo::MessageNode *msgNode = msgList->nodes;
|
fo::MessageNode *msgNode = msgList->nodes;
|
||||||
@@ -115,16 +117,22 @@ static void ReadExtraGameMsgFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long Message::AddExtraMsgFile(const char* msgName, long msgNumber) {
|
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\\");
|
std::string path("game\\");
|
||||||
path += msgName;
|
path += msgName;
|
||||||
fo::MessageList* list = new fo::MessageList();
|
fo::MessageList* list = new fo::MessageList();
|
||||||
if (fo::func::message_load(list, path.c_str())) {
|
if (fo::func::message_load(list, path.c_str())) {
|
||||||
|
if (msgNumber == 0) msgNumber = msgNumCounter++;
|
||||||
gExtraGameMsgLists.emplace(msgNumber, list);
|
gExtraGameMsgLists.emplace(msgNumber, list);
|
||||||
} else {
|
} else {
|
||||||
delete list;
|
delete list;
|
||||||
|
msgNumber = -2;
|
||||||
}
|
}
|
||||||
return 0;
|
return msgNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ClearScriptAddedExtraGameMsg() { // C++11
|
static void ClearScriptAddedExtraGameMsg() { // C++11
|
||||||
@@ -136,6 +144,7 @@ static void ClearScriptAddedExtraGameMsg() { // C++11
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
msgNumCounter = 0x3000;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ClearReadExtraGameMsgFiles() {
|
static void ClearReadExtraGameMsgFiles() {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ static MetaruleTableType metaruleTable;
|
|||||||
- arg1, arg2, ... - argument types for automatic validation
|
- arg1, arg2, ... - argument types for automatic validation
|
||||||
*/
|
*/
|
||||||
static const SfallMetarule metarules[] = {
|
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},
|
{"add_iface_tag", sf_add_iface_tag, 0, 0},
|
||||||
{"art_cache_clear", sf_art_cache_flush, 0, 0},
|
{"art_cache_clear", sf_art_cache_flush, 0, 0},
|
||||||
{"attack_is_aimed", sf_attack_is_aimed, 0, 0},
|
{"attack_is_aimed", sf_attack_is_aimed, 0, 0},
|
||||||
|
|||||||
@@ -298,8 +298,17 @@ void sf_message_str_game(OpcodeContext& ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sf_add_extra_msg_file(OpcodeContext& ctx) {
|
void sf_add_extra_msg_file(OpcodeContext& ctx) {
|
||||||
long result = Message::AddExtraMsgFile(ctx.arg(0).strValue(), ctx.arg(1).rawValue());
|
long result = Message::AddExtraMsgFile(ctx.arg(0).strValue(), (ctx.numArgs() == 2) ? ctx.arg(1).rawValue() : 0);
|
||||||
if (result == -1) ctx.printOpcodeError("%s() - cannot add message file with the specified number.", ctx.getMetaruleName());
|
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);
|
ctx.setReturn(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user