foxygit / doom Log in
commit 38c31575d255e1b2ff71f9de2c4d16664e8fb1e9
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sun Apr 18 17:15:20 2010 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Apr 18 17:15:20 2010 +0000

    Add WAD merging command line options to Heretic.

    Subversion-branch: /branches/raven-branch
    Subversion-revision: 1903
---
 src/heretic/d_main.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 127 insertions(+)

diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c
index 52e4239f..5fa2d5f9 100644
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -46,6 +46,7 @@
 #include "m_controls.h"
 #include "p_local.h"
 #include "s_sound.h"
+#include "w_merge.h"
 #include "v_video.h"

 #define STARTUP_WINDOW_X 17
@@ -908,6 +909,132 @@ void D_DoomMain(void)

     D_AddFile(iwadfile);

+#ifdef FEATURE_WAD_MERGE
+
+    // Merged PWADs are loaded first, because they are supposed to be
+    // modified IWADs.
+
+    //!
+    // @arg <files>
+    // @category mod
+    //
+    // Simulates the behavior of deutex's -merge option, merging a PWAD
+    // into the main IWAD.  Multiple files may be specified.
+    //
+
+    p = M_CheckParm("-merge");
+
+    if (p > 0)
+    {
+        for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
+        {
+            char *filename;
+
+            filename = D_TryFindWADByName(myargv[p]);
+
+            printf(" merging %s\n", filename);
+            W_MergeFile(filename);
+        }
+    }
+
+    // NWT-style merging:
+
+    // NWT's -merge option:
+
+    //!
+    // @arg <files>
+    // @category mod
+    //
+    // Simulates the behavior of NWT's -merge option.  Multiple files
+    // may be specified.
+
+    p = M_CheckParm("-nwtmerge");
+
+    if (p > 0)
+    {
+        for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
+        {
+            char *filename;
+
+            filename = D_TryFindWADByName(myargv[p]);
+
+            printf(" performing NWT-style merge of %s\n", filename);
+            W_NWTDashMerge(filename);
+        }
+    }
+
+    // Add flats
+
+    //!
+    // @arg <files>
+    // @category mod
+    //
+    // Simulates the behavior of NWT's -af option, merging flats into
+    // the main IWAD directory.  Multiple files may be specified.
+    //
+
+    p = M_CheckParm("-af");
+
+    if (p > 0)
+    {
+        for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
+        {
+            char *filename;
+
+            filename = D_TryFindWADByName(myargv[p]);
+
+            printf(" merging flats from %s\n", filename);
+            W_NWTMergeFile(filename, W_NWT_MERGE_FLATS);
+        }
+    }
+
+    //!
+    // @arg <files>
+    // @category mod
+    //
+    // Simulates the behavior of NWT's -as option, merging sprites
+    // into the main IWAD directory.  Multiple files may be specified.
+    //
+
+    p = M_CheckParm("-as");
+
+    if (p > 0)
+    {
+        for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
+        {
+            char *filename;
+
+            filename = D_TryFindWADByName(myargv[p]);
+
+            printf(" merging sprites from %s\n", filename);
+            W_NWTMergeFile(filename, W_NWT_MERGE_SPRITES);
+        }
+    }
+
+    //!
+    // @arg <files>
+    // @category mod
+    //
+    // Equivalent to "-af <files> -as <files>".
+    //
+
+    p = M_CheckParm("-aa");
+
+    if (p > 0)
+    {
+        for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
+        {
+            char *filename;
+
+            filename = D_TryFindWADByName(myargv[p]);
+
+            printf(" merging sprites and flats from %s\n", filename);
+            W_NWTMergeFile(filename, W_NWT_MERGE_SPRITES | W_NWT_MERGE_FLATS);
+        }
+    }
+
+#endif
+
     // -FILE [filename] [filename] ...
     // Add files to the wad list.
     p = M_CheckParm("-file");