From a54bc616780f6c2f862bd551726699842862f072 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 26 May 2019 15:46:30 +0300 Subject: [PATCH] - fixed conversation links with pages referenced by name https://forum.zdoom.org/viewtopic.php?t=64177 --- src/maploader/usdf.cpp | 129 +++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 63 deletions(-) diff --git a/src/maploader/usdf.cpp b/src/maploader/usdf.cpp index b2df9503c8..6d398ce337 100644 --- a/src/maploader/usdf.cpp +++ b/src/maploader/usdf.cpp @@ -482,11 +482,74 @@ class USDFParser : public UDMFParserBase return false; } Level->SetConversation(dlgid, type, startpos); - for(;startpos < Level->StrifeDialogues.Size(); startpos++) + + auto& dialogues = Level->StrifeDialogues; + const auto numnodes = dialogues.Size(); + + for (auto i = startpos; i < numnodes; i++) { - Level->StrifeDialogues[startpos]->SpeakerType = type; - Level->StrifeDialogues[startpos]->MenuClassName = clsid; + dialogues[i]->SpeakerType = type; + dialogues[i]->MenuClassName = clsid; } + + if (namespace_bits == Gz) // string page name linker + { + TMap nameToIndex; + + for (auto i = startpos; i < numnodes; i++) + { + FString key = dialogues[i]->ThisNodeName; + if (key.IsNotEmpty()) + { + key.ToLower(); + if (nameToIndex.CheckKey(key)) + Printf("Warning! Duplicate page name '%s'!\n", dialogues[i]->ThisNodeName.GetChars()); + else + { + nameToIndex[key] = i - startpos; + DPrintf(DMSG_NOTIFY, "GZSDF linker: Assigning pagename '%s' to node %i\n", key.GetChars(), i); + } + } + } + + if (nameToIndex.CountUsed()) + { + for (auto i = startpos; i < numnodes; i++) + { + FString itemLinkKey = dialogues[i]->ItemCheckNodeName; + if (itemLinkKey.IsNotEmpty()) + { + itemLinkKey.ToLower(); + if (nameToIndex.CheckKey(itemLinkKey)) + { + dialogues[i]->ItemCheckNode = nameToIndex[itemLinkKey] + 1; + DPrintf(DMSG_NOTIFY, "GZSDF linker: Item Link '%s' in node %i was index %i\n", itemLinkKey.GetChars(), i, nameToIndex[itemLinkKey]); + } + else + Printf("Warning! Reference to non-existent item-linked dialogue page name '%s' in page %i!\n", dialogues[i]->ItemCheckNodeName.GetChars(), i); + } + + FStrifeDialogueReply *NodeCheck = dialogues[i]->Children; + while (NodeCheck) + { + if (NodeCheck->NextNodeName.IsNotEmpty()) + { + FString key = NodeCheck->NextNodeName; + key.ToLower(); + if (nameToIndex.CheckKey(key)) + { + NodeCheck->NextNode = nameToIndex[key] + 1; + DPrintf(DMSG_NOTIFY, "GZSDF linker: Nextpage Link '%s' in node %i was index %i\n", key.GetChars(), i, nameToIndex[key]); + } + else + Printf("Warning! Reference to non-existent reply-linked dialogue page name '%s' in page %i!\n", NodeCheck->NextNodeName.GetChars(), i); + } + NodeCheck = NodeCheck->Next; + } + } + } + } + return true; } @@ -551,66 +614,6 @@ public: } } - if (namespace_bits == Gz) // string page name linker - { - int numnodes = Level->StrifeDialogues.Size(); - int usedstrings = false; - - TMap nameToIndex; - for (int i = 0; i < numnodes; i++) - { - FString key = Level->StrifeDialogues[i]->ThisNodeName; - if (key.IsNotEmpty()) - { - key.ToLower(); - if (nameToIndex.CheckKey(key)) - Printf("Warning! Duplicate page name '%s'!\n", Level->StrifeDialogues[i]->ThisNodeName.GetChars()); - else - { - nameToIndex[key] = i; - DPrintf(DMSG_NOTIFY, "GZSDF linker: Assigning pagename '%s' to node %i\n", key.GetChars(), i); - } - usedstrings = true; - } - } - if (usedstrings) - { - for (int i = 0; i < numnodes; i++) - { - FString itemLinkKey = Level->StrifeDialogues[i]->ItemCheckNodeName; - if (itemLinkKey.IsNotEmpty()) - { - itemLinkKey.ToLower(); - if (nameToIndex.CheckKey(itemLinkKey)) - { - Level->StrifeDialogues[i]->ItemCheckNode = nameToIndex[itemLinkKey] + 1; - DPrintf(DMSG_NOTIFY, "GZSDF linker: Item Link '%s' in node %i was index %i\n", itemLinkKey.GetChars(), i, nameToIndex[itemLinkKey]); - } - else - Printf("Warning! Reference to non-existent item-linked dialogue page name '%s' in page %i!\n", Level->StrifeDialogues[i]->ItemCheckNodeName.GetChars(), i); - } - - FStrifeDialogueReply *NodeCheck = Level->StrifeDialogues[i]->Children; - while (NodeCheck) - { - if (NodeCheck->NextNodeName.IsNotEmpty()) - { - FString key = NodeCheck->NextNodeName; - key.ToLower(); - if (nameToIndex.CheckKey(key)) - { - NodeCheck->NextNode = nameToIndex[key] + 1; - DPrintf(DMSG_NOTIFY, "GZSDF linker: Nextpage Link '%s' in node %i was index %i\n", key.GetChars(), i, nameToIndex[key]); - } - else - Printf("Warning! Reference to non-existent reply-linked dialogue page name '%s' in page %i!\n", NodeCheck->NextNodeName.GetChars(), i); - } - NodeCheck = NodeCheck->Next; - } - } - } - - } return true; } };