home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the DOOM Programming Gurus / Tricks_of_the_Doom_Programming_Gurus.iso / bonus / editors / deth / source / deu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-03  |  16.2 KB  |  511 lines

  1. /*
  2.    Doom Editor for Total Headcases, by Simon Oke and Antony Burden.
  3.    
  4.    You are allowed to use any parts of this code in another program, as
  5.    long as you give credits to the authors in the documentation and in
  6.    the program itself.  Read the file README.1ST for more information.
  7.    
  8.    This program comes with absolutely no warranty.
  9.    
  10.    DEU.H - Main game defines.
  11.    */
  12.  
  13. /* the includes */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <stdarg.h>
  18. #include <ctype.h>
  19.  
  20.  
  21. #if defined(__TURBOC__)
  22.  
  23. #include <graphics.h>
  24. #include <alloc.h>
  25. #include <dos.h>
  26. #include <bios.h>
  27. #define DEU_VERSION    "5.2"    /* the version number */
  28. typedef int            BCINT;
  29. typedef unsigned int   UBCINT;
  30.  
  31. #elif defined(__GNUC__)
  32.  
  33. #include "deu-go32.h"
  34. #define DEU_VERSION     "5.2 - DJGPP/GO32 version"
  35. typedef short int            BCINT;
  36. typedef unsigned short int   UBCINT;
  37.  
  38. #define DETH_VERSION    "2.1 - The Configurable Release"
  39.  
  40. #endif
  41.  
  42. /* define some new colors */
  43. #define DARKBLUE    16
  44. #define DARKGREEN    17
  45. #define DARKRED        18
  46. #define DARKMAGENTA    19
  47. #define GRAY        20
  48. #define DARKERGRAY    21
  49. #define    ORANGE        22
  50.  
  51. typedef unsigned char BYTE;
  52.  
  53. /* now safe to include this, as it uses BCINTs */
  54. #include "wstructs.h"
  55.  
  56.  
  57. /*
  58.    the directory structure is the structure used by DOOM to order the
  59.    data in it's WAD files
  60.    */
  61.  
  62. typedef struct Directory huge *DirPtr;
  63. struct Directory
  64. {
  65.     long start;            /* offset to start of data */
  66.     long size;            /* byte size of data */
  67.     char name[ 8];        /* name of data block */
  68. };
  69.  
  70.  
  71.  
  72. /*
  73.    The wad file pointer structure is used for holding the information
  74.    on the wad files in a linked list.
  75.    
  76.    The first wad file is the main wad file. The rest are patches.
  77.    */
  78.  
  79. typedef struct WadFileInfo huge *WadPtr;
  80. struct WadFileInfo
  81. {
  82.     WadPtr next;        /* next file in linked list */
  83.     char *filename;        /* name of the wad file */
  84.     FILE *fileinfo;        /* C file stream information */
  85.     char type[ 4];        /* type of wad file (IWAD or PWAD) */
  86.     long dirsize;        /* directory size of WAD */
  87.     long dirstart;        /* offset to start of directory */
  88.     DirPtr directory;        /* array of directory information */
  89. };
  90.  
  91.  
  92.  
  93. /*
  94.    the master directory structure is used to build a complete directory
  95.    of all the data blocks from all the various wad files
  96.    */
  97.  
  98. typedef struct MasterDirectory huge *MDirPtr;
  99. struct MasterDirectory
  100. {
  101.     MDirPtr next;        /* next in list */
  102.     WadPtr wadfile;        /* file of origin */
  103.     struct Directory dir;    /* directory data */
  104. };
  105.  
  106.  
  107.  
  108. /*
  109.    the selection list is used when more than one object is selected
  110.    */
  111.  
  112. typedef struct SelectionList *SelPtr;
  113. struct SelectionList
  114. {
  115.     SelPtr next;        /* next in list */
  116.     BCINT objnum;        /* object number */
  117. };
  118.  
  119.  
  120. /*
  121.    syntactic sugar
  122.    */
  123. typedef BCINT Bool;             /* Boolean data: true or false */
  124.  
  125.  
  126. /*
  127.    description of the command line arguments and config file keywords
  128.    */
  129.  
  130. typedef struct
  131. {
  132.     char *short_name;        /* abbreviated command line argument */
  133.     char *long_name;        /* command line arg. or keyword */
  134.     enum                        /* type of this option */
  135.         {
  136.         OPT_BOOLEAN,                     /* boolean (toggle) */
  137.         OPT_INTEGER,                     /* integer number */
  138.         OPT_STRING,                      /* character string */
  139.         OPT_STRINGACC,                   /* character string, but store in a list */
  140.         OPT_STRINGLIST,                  /* list of character strings */
  141.         OPT_END                          /* end of the options description */
  142.         } opt_type;                    
  143.     char *msg_if_true;        /* message printed if option is true */
  144.     char *msg_if_false;        /* message printed if option is false */
  145.     void *data_ptr;             /* pointer to the data */
  146. } OptDesc;
  147.  
  148.  
  149. /* generic string list type  -- used for holding level names,
  150.    ftexture sections, texture sections */
  151. typedef struct _SList {
  152.     char *string;
  153.     struct _SList *next;
  154. } *SList;
  155.  
  156. /* sector type type (!) (actually a list type) */
  157. typedef struct _sector_type {
  158.     char *shortname, *longname;
  159.     BCINT type;
  160.     struct _sector_type *next;
  161. } sector_type;
  162.  
  163. typedef struct _sector_class {
  164.     char *name;
  165.     sector_type *types;
  166.     struct _sector_class *next;
  167. } sector_class;
  168.  
  169. /* type for a list of linedef types */
  170. typedef struct _ld_type {
  171.     char *shortname, *longname;
  172.     BCINT type;
  173.     struct _ld_type *next;
  174. } ld_type;
  175.  
  176. /* type for the list of linedef type classes (phew!) */
  177. typedef struct _ld_class {
  178.     char *name;
  179.     ld_type *types;
  180.     struct _ld_class *next;
  181. } ld_class;
  182.  
  183. /* as above, but for a thing */
  184. typedef struct _thing_type {
  185.     BCINT    type, col2, col1, radius;
  186.     char     *name;
  187.     struct _thing_type *next;
  188. } thing_type;
  189.  
  190. /* and a list of thing classes */
  191. typedef struct _thing_class {
  192.     char *name;
  193.     thing_type *types;
  194.     struct _thing_class *next;
  195. } thing_class;
  196.  
  197.  
  198. /*
  199.    the macros and constants
  200.    */
  201.  
  202. /* name of the configuration file */
  203. #define DEU_CONFIG_FILE        "DETH.INI"
  204.  
  205. /* name of the log file (debug mode) */
  206. #define DEU_LOG_FILE        "DETH.LOG"
  207.  
  208. /* convert screen coordinates to map coordinates */
  209. #define MAPX(x)            (OrigX + (BCINT) (((x) - ScrCenterX) / Scale))
  210. #define MAPY(y)            (OrigY + (BCINT) ((ScrCenterY - (y)) / Scale))
  211.  
  212. /* convert map coordinates to screen coordinates */
  213. #define SCREENX(x)        (ScrCenterX + (BCINT) (((x) - OrigX) * Scale))
  214. #define SCREENY(y)        (ScrCenterY + (BCINT) ((OrigY - (y)) * Scale))
  215.  
  216. /* object types */
  217. #define OBJ_THINGS        1
  218. #define OBJ_LINEDEFS        2
  219. #define OBJ_SIDEDEFS        3
  220. #define OBJ_VERTEXES        4
  221. #define OBJ_SEGS        5
  222. #define OBJ_SSECTORS        6
  223. #define OBJ_NODES        7
  224. #define OBJ_SECTORS        8
  225. #define OBJ_REJECT        9
  226. #define OBJ_BLOCKMAP        10
  227.  
  228. /* boolean constants */
  229. #ifndef TRUE
  230. #define TRUE            1
  231. #define FALSE            0
  232. #endif
  233.  
  234. /* half the size of an object (Thing or Vertex) in map coords */
  235. #define OBJSIZE            7
  236.  
  237.  
  238. /* the interfile global variables */
  239.  
  240. /* from deu.c */
  241. extern Bool CirrusCursor;          /* use hardware cursor on Cirrus Logic VGA cards */
  242. extern Bool Select0;               /* select object 0 by default when switching modes */
  243. extern Bool Debug;        /* are we debugging? */
  244. extern Bool SwapButtons;    /* swap right and middle mouse buttons */
  245. extern Bool Quiet;        /* don't play a sound when an object is selected */
  246. extern Bool Quieter;        /* don't play any sound, even when an error occurs */
  247. extern Bool Expert;        /* don't ask for confirmation for some operations */
  248. extern Bool QisQuit;        
  249. extern BCINT InitialScale;    /* initial zoom factor for map */
  250. extern BCINT VideoMode;          /* default video mode for VESA cards */
  251. extern char *BGIDriver;        /* default extended BGI driver */
  252. extern Bool FakeCursor;    /* use a "fake" mouse cursor */
  253. extern Bool Colour2;        /* use the alternate set for things colors */
  254. extern Bool AdditiveSelBox;    /* additive selection box or select in box only? */
  255. extern BCINT SplitFactor;       /* factor used by the nodes builder */
  256. extern char *MainWad;        /* name of the main wad file */
  257. extern FILE *logfile;        /* filepointer to the error log */
  258. extern Bool square_circles;
  259. extern Bool ThingAngle;        /* draw things with arrow */
  260. extern Bool Doom2;        /* Is this Doom 2 ?? */
  261. extern char *RegTest;
  262. extern Bool Registered;        /* registered or shareware WAD file? */
  263.  
  264. /* from wads.c */
  265. extern WadPtr  WadFileList;    /* list of wad files */
  266. extern MDirPtr MasterDir;    /* the master directory */
  267. extern SList LevelNames;
  268.  
  269. /* from edit.c */
  270. extern Bool InfoShown;          /* is the bottom line displayed? */
  271.  
  272. /* from gfx.c */
  273. extern BCINT GfxMode;        /* current graphics mode, or 0 for text */
  274. extern float Scale;        /* scale to draw map 20 to 1 */
  275. extern BCINT OrigX;        /* the X origin */
  276. extern BCINT OrigY;        /* the Y origin */
  277. extern BCINT PointerX;        /* X position of pointer */
  278. extern BCINT PointerY;        /* Y position of pointer */
  279. extern BCINT ScrMaxX;        /* maximum X screen coord */
  280. extern BCINT ScrMaxY;        /* maximum Y screen coord */
  281. extern BCINT ScrCenterX;    /* X coord of screen center */
  282. extern BCINT ScrCenterY;    /* Y coord of screen center */
  283.  
  284. /* from mouse.c */
  285. extern Bool UseMouse;        /* is there a mouse driver? */
  286.  
  287. /* from things2.c */
  288. extern thing_class *Thing_classes;
  289.  
  290. /* from names.c */
  291. extern ld_class *Linedef_classes;
  292. extern sector_class *Sector_classes;
  293.  
  294. /* from levels.c */
  295. extern SList Ftexture_sections;
  296. extern SList Texture_sections;
  297.  
  298. /*
  299.    the function prototypes
  300.    */
  301.  
  302. /* from deu.c */
  303. int main( int, char *[]);
  304. void ParseCommandLineOptions( int, char *[]);
  305. void ParseConfigFileOptions( char *);
  306. void Usage( FILE *);
  307. void Credits( FILE *);
  308. void FunnyMessage( FILE *);
  309. void Beep( void);
  310. void PlaySound( BCINT , BCINT );
  311. void ProgError( char *, ...);
  312. void LogMessage( char *, ...);
  313. void MainLoop( void);
  314.  
  315. /* from memory.c */
  316. void *GetMemory( size_t);
  317. void *ResizeMemory( void *, size_t);
  318. void FreeMemory( void *);
  319. void huge *GetFarMemory( unsigned long size);
  320. void huge *ResizeFarMemory( void huge *old, unsigned long size);
  321. void FreeFarMemory( void huge *);
  322.  
  323. /* from wads.c */
  324. void OpenMainWad( char *);
  325. void OpenPatchWad( char *);
  326. void CloseWadFiles( void);
  327. void CloseUnusedWadFiles( void);
  328. WadPtr BasicWadOpen( char *);
  329. void BasicWadRead( WadPtr, void huge *, long);
  330. void BasicWadSeek( WadPtr, long);
  331. MDirPtr FindMasterDir( MDirPtr, char *);
  332. void ListMasterDirectory( FILE *);
  333. void ListFileDirectory( FILE *, WadPtr);
  334. void BuildNewMainWad( char *, Bool);
  335. void WriteBytes( FILE *, void huge *, long);
  336. void CopyBytes( FILE *, FILE *, long);
  337. BCINT  Exists( char *);
  338. void DumpDirectoryEntry( FILE *, char *);
  339. void SaveDirectoryEntry( FILE *, char *);
  340. void SaveEntryToRawFile( FILE *, char *);
  341. void SaveEntryFromRawFile( FILE *, FILE *, char *);
  342.  
  343. /* from levels.c */
  344. void ReadLevelData( BCINT , BCINT ); /* SWAP! */
  345. void ForgetLevelData( void); /* SWAP! */
  346. void SaveLevelData( char *); /* SWAP! */
  347. void ReadWTextureNames( void);
  348. void ForgetFTextureNames( void);
  349. void ReadFTextureNames( void);
  350. void ReadFTextureNamesIn( char *);
  351. void ForgetWTextureNames( void);
  352.  
  353. /* from edit.c */
  354. void EditLevel( BCINT , BCINT , Bool);
  355. void SelectLevel( BCINT  *, BCINT  *);
  356. void EditorLoop( BCINT , BCINT ); /* SWAP! */
  357. void DrawMap( BCINT , BCINT, Bool ); /* SWAP! */
  358. void CenterMapAroundCoords( BCINT , BCINT );
  359. void GoToObject( BCINT , BCINT ); /* SWAP! */
  360.  
  361. /* from gfx.c */
  362. void InitGfx( void);
  363. Bool SwitchToVGA256( void);
  364. Bool SwitchToVGA16( void);
  365. void TermGfx( void);
  366. void ClearScreen( void);
  367. void ClearMapScreen(BCINT);
  368. void SetColor( BCINT );
  369. void DrawMapLine( BCINT , BCINT , BCINT , BCINT );
  370. void DrawMapCircle( BCINT , BCINT , BCINT );
  371. void DrawMapVector( BCINT , BCINT , BCINT , BCINT );
  372. void DrawMapArrow( BCINT , BCINT , UBCINT);
  373. void DrawScreenLine( BCINT , BCINT , BCINT , BCINT );
  374. void DrawScreenBox( BCINT , BCINT , BCINT , BCINT );
  375. void DrawScreenBox3D( BCINT , BCINT , BCINT , BCINT );
  376. void DrawScreenBoxHollow( BCINT , BCINT , BCINT , BCINT );
  377. void DrawScreenMeter( BCINT , BCINT , BCINT , BCINT , float);
  378. void DrawScreenText( BCINT , BCINT , char *, ...);
  379. void DrawPointer( Bool);
  380. void SetDoomPalette( BCINT );
  381. BCINT TranslateToGameColor( BCINT );
  382. UBCINT ComputeAngle( BCINT , BCINT );
  383. UBCINT ComputeDist( BCINT , BCINT );
  384. void InsertPolygonVertices( BCINT , BCINT , BCINT , BCINT );
  385. void RotateAndScaleCoords( BCINT  *, BCINT  *, double, double);
  386.  
  387. /* from things2.c */
  388. BCINT  GetThingColour( BCINT );
  389. char *GetThingName( BCINT );
  390. BCINT  GetThingRadius( BCINT );
  391. char *GetAngleName( BCINT );
  392. char *GetWhenName( BCINT );
  393.  
  394. /* from names.c */
  395. char *GetObjectTypeName( BCINT );
  396. char *GetEditModeName( BCINT );
  397. char *GetLineDefTypeName( BCINT );
  398. char *GetLineDefTypeLongName( BCINT );
  399. char *GetLineDefFlagsName( BCINT );
  400. char *GetLineDefFlagsLongName( BCINT );
  401. char *GetSectorTypeName( BCINT );
  402. char *GetSectorTypeLongName( BCINT );
  403. Bool LinedefIsDoom2Only(BCINT);
  404. void index_ld_types();
  405.  
  406. /* from mouse.c */
  407. void CheckMouseDriver( void);
  408. void ShowMousePointer( void);
  409. void HideMousePointer( void);
  410. void GetMouseCoords( BCINT  *, BCINT  *, BCINT  *);
  411. void SetMouseCoords( BCINT , BCINT );
  412. void SetMouseLimits( BCINT , BCINT , BCINT , BCINT );
  413. void ResetMouseLimits( void);
  414.  
  415. /* from menus.c */
  416. BCINT DisplayMenuArray( BCINT , BCINT , char *, BCINT , BCINT  *, char *[ 30], BCINT  [30]);
  417. BCINT DisplayMenu( BCINT , BCINT , char *, ...);
  418. BCINT PullDownMenu( BCINT , BCINT , ...);
  419. BCINT InputInteger( BCINT , BCINT , BCINT  *, BCINT , BCINT );
  420. BCINT InputIntegerValue( BCINT , BCINT , BCINT , BCINT , BCINT );
  421. void InputNameFromListWithFunc( BCINT , BCINT , char *, BCINT , char **, BCINT , char *, BCINT , BCINT , void (*hookfunc)(BCINT , BCINT , BCINT , BCINT , char *));
  422.  
  423. void InputNameFromList( BCINT , BCINT , char *, BCINT , char **, char *);
  424. void InputFileName( BCINT , BCINT , char *, BCINT , char *);
  425. Bool Confirm( BCINT , BCINT , char *, char *);
  426. void Notify( BCINT , BCINT , char *, char *);
  427. void DisplayMessage( BCINT , BCINT , char *, ...);
  428. void NotImplemented( void);
  429.  
  430. /* from objects.c */
  431. BCINT GetMaxObjectNum(BCINT );
  432. void HighlightSelection( BCINT , SelPtr); /* SWAP! */
  433. Bool IsSelected( SelPtr, BCINT );
  434. void SelectObject( SelPtr *, BCINT );
  435. void UnSelectObject( SelPtr *, BCINT );
  436. void ForgetSelection( SelPtr *);
  437. BCINT GetMaxObjectNum( BCINT);
  438. BCINT GetCurObject( BCINT , BCINT , BCINT , BCINT , BCINT ); /* SWAP! */
  439. SelPtr SelectObjectsInBox( BCINT , BCINT , BCINT , BCINT , BCINT ); /* SWAP! */
  440. void HighlightObject( BCINT , BCINT , BCINT ); /* SWAP! */
  441. void DeleteObject( BCINT , BCINT ); /* SWAP! */
  442. void DeleteObjects( BCINT , SelPtr *); /* SWAP! */
  443. void InsertObject( BCINT , BCINT , BCINT , BCINT ); /* SWAP! */
  444. BCINT GetOppositeSector( BCINT, Bool); /* SWAP ! */
  445. Bool IsLineDefInside( BCINT , BCINT , BCINT , BCINT , BCINT ); /* SWAP - needs Vertexes & LineDefs */
  446. void CopyObjects( BCINT , SelPtr); /* SWAP! */
  447. Bool MoveObjectsToCoords( BCINT , SelPtr, BCINT , BCINT , BCINT ); /* SWAP! */
  448. void GetObjectCoords( BCINT , BCINT , BCINT  *, BCINT  *); /* SWAP! */
  449. void RotateAndScaleObjects( BCINT , SelPtr, double, double); /* SWAP! */
  450. BCINT FindFreeTag(void); /* SWAP! */
  451. void FlipLineDefs( SelPtr, Bool); /* SWAP! */
  452. void DeleteVerticesJoinLineDefs( SelPtr ); /* SWAP! */
  453. void MergeVertices( SelPtr *); /* SWAP! */
  454. Bool AutoMergeVertices( SelPtr *); /* SWAP! */
  455. void SplitLineDefs( SelPtr); /* SWAP! */
  456. void SplitSector( BCINT , BCINT ); /* SWAP! */
  457. void SplitLineDefsAndSector( BCINT , BCINT ); /* SWAP! */
  458. void MergeSectors( SelPtr *); /* SWAP! */
  459. void DeleteLineDefsJoinSectors( SelPtr *); /* SWAP! */
  460. void MakeDoorFromSector( BCINT ); /* SWAP! */
  461. void MakeLiftFromSector( BCINT ); /* SWAP! */
  462. void AlignTexturesY( SelPtr *, Bool, Bool); /* SWAP! */
  463. void AlignTexturesX( SelPtr *, Bool, Bool); /* SWAP! */
  464. void DistributeSectorFloors( SelPtr); /* SWAP! */
  465. BCINT CommonVertex(BCINT, BCINT);
  466. SelPtr rev_list(SelPtr);    /* return a new list, which is the reverse
  467.                                of the original */
  468. void delete_list(SelPtr);    /* use this to delete it afterwards */
  469. void DistributeSectorCeilings( SelPtr); /* SWAP! */
  470. void DistributeLightLevels( SelPtr); /* SWAP! */
  471.  
  472.  
  473. /* from editobj.c */
  474. void DisplayObjectInfo( BCINT , BCINT ); /* SWAP! */
  475. BCINT InputObjectNumber( BCINT , BCINT , BCINT , BCINT );
  476. BCINT InputObjectXRef( BCINT , BCINT , BCINT , Bool, BCINT );
  477. Bool Input2VertexNumbers( BCINT, BCINT, char *, BCINT *, BCINT *);
  478. void EditObjectsInfo( BCINT , BCINT , BCINT , SelPtr);
  479. void CheckLevel( BCINT , BCINT ); /* SWAP! */
  480. Bool CheckStartingPos( void); /* SWAP! */
  481. void InsertStandardObject( BCINT , BCINT , BCINT , BCINT ); /* SWAP! */
  482. void MiscOperations( BCINT , BCINT , BCINT , SelPtr *); /* SWAP! */
  483. void Preferences( BCINT , BCINT );
  484.  
  485. /* from nodes.c */
  486. void ShowProgress( BCINT );
  487.  
  488. /* from textures.c */
  489. void ChooseFloorTexture( BCINT , BCINT , char *, BCINT , char **, char *);
  490. void ChooseWallTexture( BCINT , BCINT , char *, BCINT , char **, char *);
  491. void ChooseSprite( BCINT , BCINT , char *, char *);
  492. void GetWallTextureSize( BCINT *, BCINT *, char *);
  493. void *GetResource(char *);
  494. void ForgetResource(char *);
  495. Texture *FindTexture(char *);
  496. Texture *FindTextureIn(char *, void *);
  497. void ForgetAllResources(void);
  498.  
  499. /* from readcfg.c */
  500. void readcfg(char *);
  501.  
  502. /* from swapmem.c */
  503.  
  504. #if defined(__TURBOC__)
  505. void InitSwap( void);
  506. void FreeSomeMemory( void);
  507. void ObjectsNeeded( BCINT , ...);
  508. #endif
  509.  
  510. /* end of file */
  511.