home *** CD-ROM | disk | FTP | other *** search
/ D!Zone (Collector's Edition) / D_ZONE_CD.ISO / helps / dmijum / jumble.c < prev    next >
C/C++ Source or Header  |  1994-12-06  |  26KB  |  675 lines

  1. /*
  2.  *    JUMBLE.C
  3.  *
  4.  *    Version 1.0.0
  5.  *
  6.  *    Abstract:
  7.  *     This program creates a file, JUMBLE.WAD, that contains the 27 maps
  8.  *     from DOOM in a random order. The things (characters, items, etc.) in each
  9.  *     map are shuffled and start out facing in a random direction.  Each map
  10.  *     has a song randomly assigned to it.  The Boss levels are special
  11.  *     exceptions: they remain in the same place (map 8), but they get new,
  12.  *     wacky music never before heard in a map. Take note: JUMBLE.WAD is over
  13.  *     3 megs in size. E3M8 is handled specially, and it is twisted!
  14.  *
  15.  *     After creating JUMBLE.WAD, run DOOM with this form:
  16.  *      DOOM -file JUMBLE.WAD { other parameters }
  17.  *
  18.  *    History:
  19.  *     1.0.0    (April 3, 1994)
  20.  *
  21.  *  Author:
  22.  *     Michael McMahon
  23.  *
  24.  ****************************************************************************
  25.  * Jumble Function Directory
  26.  *---------------------------------------------------------------------------
  27.  *Index: Name                     : Description
  28.  *---------------------------------------------------------------------------
  29.  * #1  : WadfileCopyAndJumbleMap : Can be used instead of 'WadfileCopyMap'.
  30.  ****************************************************************************
  31.  *
  32.  *  WADLIB SOFTWARE LICENSE AGREEMENT
  33.  *
  34.  *    1. GRANT OF LICENSE. Michael McMahon and his affiliations (collectively
  35.  *       the "AUTHOR") grant you (either an individual or an entity) the
  36.  *       non-exclusive, royalty-free right to use this library source code,
  37.  *       documentation, and sample code (collectively, the "SOFTWARE") for
  38.  *       any lawful purpose subject to the terms of this license.  By using the
  39.  *       SOFTWARE you are agreeing to be bound to all the terms of this license.
  40.  *
  41.  *    2. COPYRIGHT.  The SOFTWARE is Copyright (c) 1994, Michael McMahon,
  42.  *       PO Box 14807, San Luis Nabisco, CA 93406-4807 USA. All Rights Reserved
  43.  *       Worldwide.  You may not use, modify, or distribute the SOFTWARE except
  44.  *       as otherwise provided herein.
  45.  *
  46.  *    3. DECLARATION OF PUBLIC DOMAIN DISTRIBUTION AND USE. The distribution
  47.  *       and use of the SOFTWARE is hereby designated PUBLIC DOMAIN by the
  48.  *       the AUTHOR.    You may not sell, rent, or lease this SOFTWARE.  The
  49.  *       SOFTWARE may be reproduced verbatim in part or in full by any
  50.  *       reproduction means for any lawful purpose, and may also be subject to
  51.  *       the following agreement.
  52.  *
  53.  *    4. AGREEMENT FOR USE OF SOFTWARE. The AUTHOR grants you a non-exclusive,
  54.  *       royalty-free right to incorporate the SOFTWARE into any production for
  55.  *       any legal purpose as long as you agree
  56.  *        (a) to indemnify, hold harmless, and defend the AUTHOR from and against
  57.  *            any claims or lawsuits, including attorneys' fees, that arise or
  58.  *            result from the use or distribution of your software production; and
  59.  *        (b) no matter how much the SOFTWARE is modified, the AUTHOR owns the
  60.  *            copyright and this original, unmodified copyright notice remains
  61.  *            intact in the source code; and,
  62.  *        (c) the AUTHOR is not held responsible for fixing bugs or making
  63.  *            enhancements or changes to the SOFTWARE for any reason; and,
  64.  *        (d) the SOFTWARE is not redistributed if it is modified in any way; and,
  65.  *      (e) otherwise comply with the terms of this agreement; and,
  66.  *        (f) the AUTHOR is forgiven for making so many demands.
  67.  *
  68.  *     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE
  69.  *     AUTHOR FURTHER DISCLAIMS ALL IMPLIED WARRANTIES, INCLUDING WITHOUT
  70.  *     LIMITATION ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR OF FITNESS
  71.  *     FOR A PARTICULAR PURPOSE.    THE ENTIRE RISK ARISING OUT OF THE USE
  72.  *     OR PERFORMANCE OF THE SOFTWARE REMAINS WITH YOU.
  73.  *
  74.  *     The author can be reached at:
  75.  *      Michael McMahon
  76.  *      P.O. Box 14807
  77.  *      San Luis Nabisco, CA 93406-4807 USA
  78.  *      Internet: mmcmahon@oboe.calpoly.edu
  79.  *      [Bug reports, suggestions, success stories, etc. are welcome; tech
  80.  *       support, and other unnecessary two-way mail, is not]
  81.  */
  82.  
  83. #include <assert.h>
  84. #include <stdio.h>
  85. #include <stdlib.h>
  86. #include <malloc.h>
  87. #include <mem.h>
  88. #include <time.h>
  89. #include "general.h"
  90. #include "wadfile.h"
  91. #include "dm_mapdf.h"
  92.  
  93. /* Program-specific definitions */
  94. #define PROG_FILENAME "JUMBLE"
  95. #define PROG_AUTHOR   "Michael McMahon"
  96.  
  97. /* Values to be returned to the operating system */
  98. #define EXIT_ERROR -1
  99. #define EXIT_OK    0
  100.  
  101. /* System bounds */
  102. #define MAX_ENTRIES 500
  103. #define FILE_NAME_SIZE 200
  104.  
  105. /* Target filename */
  106. #define JUMBLE_NAME "JUMBLE.WAD"
  107.  
  108. /* Jumble structure */
  109. typedef struct {
  110.     int episode;
  111.     int map;
  112.     int touched;
  113.     char musicName[SIZEOF_WAD_DIR_ENTRY];
  114. } JumbledMapRec;
  115.  
  116. /* Funny BOSS level music */
  117. char * bossEpisodeMusic[DOOM_LASTEPISODE]={"D_VICTOR","D_INTRO\0","D_BUNNY\0"};
  118.  
  119. /* Maximum allowable THINGS per map */
  120. #define MAX_THINGS 1000
  121.  
  122. /* Record used to shuffle THINGS */
  123. struct {
  124.     int newLocation;
  125.     int touched;
  126. } jumbledThings[MAX_THINGS];
  127.  
  128. /* Symbol used to determine what maps still need to be defined */
  129. #define JUMBLEREC_UNTOUCHED 0
  130. #define JUMBLEREC_TOUCHED    1
  131.  
  132. /* Thing types */
  133. #define TYPE_PLAYER1START        1
  134. #define TYPE_PLAYER2START        2
  135. #define TYPE_PLAYER3START        3
  136. #define TYPE_PLAYER4START        4
  137. #define TYPE_BLUEKEY            5
  138. #define TYPE_YELLOWKEY            6
  139. #define TYPE_SPIDERDEMON        7
  140. #define TYPE_DEATHMATCHPOS        11
  141. #define TYPE_REDKEY             13
  142. #define TYPE_TELEPORTER         14
  143. #define TYPE_CYBERLORD            16
  144. #define TYPE_CELL_CASE            17
  145. #define TYPE_REDSKULL            38
  146. #define TYPE_YELLOWSKULL        39
  147. #define TYPE_BLUESKULL            40
  148. #define TYPE_INVULNERABILITY    2022
  149. #define TYPE_CELL_CHARGE        2047
  150. #define TYPE_BARON                3003
  151. #define TYPE_HUMAN                3004
  152. #define TYPE_CACODEMON            3005
  153.  
  154. /* Constants used in randomizing angle THINGS initially face */
  155. #define NUM_FACES       8
  156. #define TOTAL_DEGREES    360
  157.  
  158. /*------------------------- Internal routines ---------------------------*/
  159.  
  160. /**[ Internal 1 of 2 ]****************************************************
  161.  *                                                                       *
  162.  *      wadMalloc                                                          *
  163.  *                                                                         *
  164.  * Desc:                                                                 *
  165.  *       This is the memory allocation routine for this example program.     *
  166.  *       The memory management routines are stored outside WADFILE.C so     *
  167.  *       it would be compatible with any memory manager.    This example     *
  168.  *       uses ANSI C's malloc.                                             *
  169.  *                                                                         *
  170.  * Def:                                                                  *
  171.  *       static void * wadMalloc(unsigned long size);                      *
  172.  *                                                                       *
  173.  * Parm:                                                                 *
  174.  *       size    Number of bytes to allocate.                              *
  175.  *                                                                         *
  176.  * Retn:                                                                 *
  177.  *       Pointer to allocated memory, or NULL if not enough memory.         *
  178.  *                                                                         *
  179.  * Notes:                                                                *
  180.  *     Use a pointer to this routine as the first parameter in the       *
  181.  *     'WadfileInitialize' call.                                         *
  182.  *                                                                         *
  183.  *************************************************************************/
  184.  
  185. static void * wadMalloc (unsigned long size)
  186. {
  187.   /* Note: If size is > 64k, some implementations of malloc might not work */
  188.     return malloc(size);
  189. }
  190.  
  191. /**[ Internal 2 of 2 ]****************************************************
  192.  *                                                                       *
  193.  *      wadFree                                                             *
  194.  *                                                                       *
  195.  * Desc:                                                                 *
  196.  *       This is the memory deallocation routine for this example program. *
  197.  *       The memory management routines are stored outside WADFILE.C so     *
  198.  *       it would be compatible with any memory manager.    This example     *
  199.  *       uses ANSI C's free.                                               *
  200.  *                                                                       *
  201.  * Def: