From 784aef89287856605cf42763b9d8322789546a00 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 13 Feb 2010 05:15:32 +0000 Subject: [PATCH] - Added checks for open and closed scripts sharing the same number to ensure that FBehavior::FindScript() will always return the closed version. See Hexen MAP30 and MAP33. SVN r2157 (trunk) --- src/p_acs.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index d79154609..c899c5844 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -1396,7 +1396,7 @@ void FBehavior::LoadScriptsDirectory () switch (Format) { case ACS_Old: - scripts.dw = (DWORD *)(Data + ((DWORD *)Data)[1]); + scripts.dw = (DWORD *)(Data + ((DWORD *)Data)[1]); // FIXME: Has this been byte-swapped before-hand? NumScripts = scripts.dw[0]; if (NumScripts != 0) { @@ -1473,6 +1473,25 @@ void FBehavior::LoadScriptsDirectory () if (NumScripts > 1) { qsort (Scripts, NumScripts, sizeof(ScriptPtr), SortScripts); + // Check for duplicates because ACC originally did not enforce + // script number uniqueness across different script types. We + // only need to do this for old format lumps, because the ACCs + // that produce new format lumps won't let you do this. + if (Format == ACS_Old) + { + for (i = 0; i < NumScripts - 1; ++i) + { + if (Scripts[i].Number == Scripts[i+1].Number) + { + Printf("Script %d appears more than once.\n", Scripts[i].Number); + // Make the closed version the first one. + if (Scripts[i+1].Type == SCRIPT_Closed) + { + swap(Scripts[i], Scripts[i+1]); + } + } + } + } } if (Format == ACS_Old) @@ -1589,6 +1608,15 @@ const ScriptPtr *FBehavior::FindScript (int script) const const ScriptPtr *ptr = BinarySearch ((ScriptPtr *)Scripts, NumScripts, &ScriptPtr::Number, (WORD)script); + // If the preceding script has the same number, return it instead. + // See the note by the script sorting above for why. + if (ptr > Scripts) + { + if (ptr[-1].Number == script) + { + ptr--; + } + } return ptr; }