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

  1. /*
  2.    Doom Editor Utility, by Brendon Wyber and Raphaël Quinet.
  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.    EDIT.C - Editor routines.
  11.    */
  12.  
  13. /* the includes */
  14. #include "deu.h"
  15. #include "levels.h"
  16.  
  17. void DrawMapQuick();
  18.  
  19. extern Bool InfoShown;                /* should we display the info bar? */
  20. BCINT MoveSpeed;
  21.  
  22.  
  23. /*
  24.    the driving program
  25.    */
  26.  
  27. void EditLevel( BCINT episode, BCINT mission, Bool newlevel)
  28. {
  29.     MoveSpeed = DefaultLargeScroll;                /* movement speed */
  30.     ReadWTextureNames();
  31.     ReadFTextureNames();
  32.     InitGfx();
  33.     CheckMouseDriver();
  34.     if(mission != -1) {
  35.     if (episode < 1 || mission < 1)
  36.         SelectLevel( &episode, &mission);
  37.     }
  38.     if (episode > 0 && mission != 0) {
  39.     ClearMapScreen(0);
  40.     ReadLevelData( episode, mission);
  41.     if (newlevel) {
  42.         ForgetLevelData();
  43.         MapMinX = -4000;
  44.         MapMinY = -4000;
  45.         MapMaxX = 4000;
  46.         MapMaxY = 4000;
  47.     }
  48.     LogMessage( ": Editing E%dM%d...\n", episode, mission);
  49.     EditorLoop( episode, mission);
  50.     LogMessage( ": Finished editing E%dM%d...\n", episode, mission);
  51.     TermGfx();
  52.     if (!(Registered || Doom2))
  53.         printf( "Please register DOOM if you want to be able to save your changes.\n");
  54.     ForgetLevelData();
  55.     /* forget the level pointer */
  56.     Level = NULL;
  57.     }
  58.     else
  59.     TermGfx();
  60.     ForgetWTextureNames();
  61.     ForgetFTextureNames();
  62. }
  63.  
  64.  
  65.  
  66. /*
  67.    select a level
  68.    */
  69.  
  70. void SelectLevel( BCINT *episode, BCINT *mission)
  71. {
  72.     MDirPtr dir;
  73.     char *levels[32];
  74.     char name[8];
  75.     int n = 0;
  76.     
  77.     dir = MasterDir;
  78.     while (dir) {
  79.     if (dir->dir.size == 0)
  80.         if((Doom2 && !strncmp(dir->dir.name, "MAP", 3)) ||
  81.            (dir->dir.name[ 0] == 'E' &&
  82.         dir->dir.name[ 2] == 'M' &&
  83.         dir->dir.name[ 4] == '\0'))
  84.         levels[ n++] = dir->dir.name;
  85.     dir = dir->next;
  86.     }
  87.     if (*episode < 1)
  88.     *episode = 1;
  89.     
  90.     if(Doom2) {
  91.     sprintf(name, "MAP%02d", *episode);
  92.     }
  93.     else {
  94.     if(*mission < 1)
  95.         *mission = 1;
  96.     sprintf(name, "E%dM%d", *episode, *mission);
  97.     }
  98.     
  99.     InputNameFromList( -1, -1, "Select a Level to Edit:", n, levels, name);
  100.     FreeMemory( levels);
  101.     
  102.     if(name) {
  103.     if(Doom2) {
  104.         *episode = atoi(name + 3);
  105.         *mission = -1;
  106.     }
  107.     else {
  108.         *episode = name[1] - '0';
  109.         *mission = name[3] - '0';
  110.     }
  111.     }     
  112.     else {
  113.     *episode = 0;
  114.     *mission = 0;
  115.     }
  116. }
  117.  
  118.  
  119.  
  120. /*
  121.    get the name of the new WAD file
  122.    */
  123.  
  124. char *GetWadFileName( BCINT episode, BCINT mission)
  125. {
  126.     char *outfile = (char*)GetMemory( 80);
  127.     char *dotp;
  128.     WadPtr wad;
  129.     
  130.     /* get the file name */
  131.     if (! strcmp(Level->wadfile->filename, MainWad)) {
  132.     if(Doom2)
  133.         sprintf(outfile, "MAP%02d.WAD", episode);
  134.     else
  135.         sprintf( outfile, "E%dM%d.WAD", episode, mission);
  136.     }
  137.     else
  138.     strcpy( outfile, Level->wadfile->filename);
  139.     
  140.     do {
  141.     InputFileName( -1, -1, "Name of the new WAD file:", 79, outfile);
  142.     }
  143.     while (!strcmp(outfile, MainWad));
  144.     /* escape */
  145.     if (outfile[ 0] == '\0') {
  146.     FreeMemory( outfile);
  147.     return NULL;
  148.     }
  149.     /* if the WAD file already exists, rename it to "*.BAK" */
  150.     for (wad = WadFileList; wad; wad = wad->next)
  151.     if (!stricmp( outfile, wad->filename)) {
  152.         dotp = strrchr( wad->filename, '.');
  153.         if (dotp == NULL)
  154.         strcat( wad->filename, ".BAK");
  155.         else
  156.         strcpy( dotp, ".BAK");
  157.         /* need to close, then reopen: problems with SHARE.EXE */
  158.         fclose( wad->fileinfo);
  159.         if (rename( outfile, wad->filename) < 0) {
  160.         if (unlink( wad->filename) < 0)
  161.             ProgError( "could not delete file \"%s\"", wad->filename);
  162.         if (rename( outfile, wad->filename) < 0)
  163.             ProgError( "could not rename \"%s\" to \"%s\"", outfile, wad->filename);
  164.         }
  165.         wad->fileinfo = fopen( wad->filename, "rb");
  166.         if (wad->fileinfo == NULL)
  167.         ProgError( "could not reopen file \"%s\"", wad->filename);
  168.         break;
  169.     }
  170.     return outfile;
  171. }
  172.  
  173.  
  174.  
  175. /*
  176.    display the help screen
  177.    */
  178.  
  179. void DisplayHelp( BCINT objtype, BCINT grid) /* SWAP! */
  180. {
  181.     BCINT x0 = 137;
  182.     BCINT y0 = 35;
  183.     
  184.     if (UseMouse)
  185.     HideMousePointer();
  186.     /* put in the instructions */
  187.     DrawScreenBox3D( x0, y0, x0 + 364, y0 + 408);
  188.     SetColor( LIGHTCYAN);
  189.     DrawScreenText( x0 + 60, y0 + 20, "Doom Editor for Total Headcases");
  190.     DrawScreenText( 269 - strlen(GetEditModeName( objtype)) * 4, y0 + 32, "- %s Editor -", GetEditModeName( objtype));
  191.     SetColor( BLACK);
  192.     DrawScreenText( x0 + 10, y0 + 60, "Use the mouse or the cursor keys to move");
  193.     DrawScreenText( -1, -1, "around.  The map scrolls when the pointer");
  194.     DrawScreenText( -1, -1, "reaches the edge of the screen.");
  195.     DrawScreenText( -1, y0 + 100, "Other useful keys are:");
  196.     if (Registered)
  197.         DrawScreenText( -1, y0 + 115, "Q     - Quit or SaveAs - see deth.ini");
  198.     else {
  199.     SetColor( DARKGRAY);
  200.         DrawScreenText( -1, y0 + 115, "Q     - Quit without saving changes");
  201.     SetColor( BLACK);
  202.     }
  203.     DrawScreenText( -1, -1, "Esc   - Exit without saving changes");
  204.     DrawScreenText( -1, -1, "Tab   - Switch to the next editing mode");
  205.     DrawScreenText( -1, -1, "Space - Change the move/scroll speed");
  206.     DrawScreenText( -1, -1, "+/-   - Change the map scale (current: %d)", (BCINT) (1.0 / Scale + 0.5));
  207.     DrawScreenText( -1, -1, "G     - Change the grid scale (cur.: %d)", grid);
  208.     DrawScreenText( -1, -1, "H     - Hide the grid");
  209.     DrawScreenText( -1, -1, "K     - Kill the grid (set grid to 0)");
  210.     DrawScreenText( -1, -1, "N, >  - Jump to the next object.");
  211.     DrawScreenText( -1, -1, "P, <  - Jump to the previous object.");
  212.     DrawScreenText( -1, -1, "J, #  - Jump to a specific object (enter #)");
  213.     DrawScreenText( -1, -1, "M     - Mark/unmark current object (select)");
  214.     DrawScreenText( -1, -1, "D     - Toggle drag mode");
  215.     DrawScreenText( -1, -1, "C     - Clear all marks and redraw map");
  216.     DrawScreenText( -1, -1, "O     - Copy Objects");
  217.     DrawScreenText( -1, -1, ",     - Rotate Thing Clockwise");
  218.     DrawScreenText( -1, -1, ".     - Rotate Thing Anti-Clockwise");
  219.     DrawScreenText( -1, -1, "Ins   - Insert a new object");
  220.     DrawScreenText( -1, -1, "Del   - Delete the current object");
  221.     DrawScreenText( -1, -1, "Enter - Edit the current/selected object(s)");
  222.     DrawScreenText( -1, y0 + 320, "Mouse buttons:");
  223.     if (SwapButtons) {
  224.     DrawScreenText( -1, y0 + 330, "Left  - Edit the current/selected object(s)");
  225.     DrawScreenText( -1, -1, "Middle- Mark/unmark the current object.");
  226.     }
  227.     else {
  228.     DrawScreenText( -1, y0 + 330, "Left  - Mark/unmark the current object");
  229.     DrawScreenText( -1, -1, "Middle- Edit the current/selected object(s)");
  230.     }
  231.     DrawScreenText( -1, -1, "Right - Drag the current/selected object(s)");
  232.     SetColor( YELLOW);
  233.     DrawScreenText( -1, y0 + 390, "Press any key to return to the editor...");
  234.     bioskey( 0);
  235.     if (UseMouse)
  236.     ShowMousePointer();
  237. }
  238.  
  239.  
  240.  
  241. /*
  242.    the editor main loop
  243.    */
  244.  
  245. #define REDRAW_NONE            0
  246. #define REDRAW_QUICK        1
  247. #define REDRAW_ALL            2
  248.  
  249. void EditorLoop( BCINT episode, BCINT mission) /* SWAP! */
  250. {
  251.     BCINT  EditMode = OBJ_THINGS;
  252.     BCINT  CurObject = -1;
  253.     BCINT  OldObject = -1;
  254.     BCINT  RedrawMap = REDRAW_ALL;
  255.     BCINT  LastRedraw = REDRAW_NONE;
  256.     Bool   RedrawObj = FALSE;
  257.     Bool   DragObject = FALSE;
  258.     int    key, altkey;
  259.     BCINT  buttons; 
  260.     BCINT  oldbuttons = 0;
  261.     BCINT  GridScale = 0;
  262.     Bool   GridShown = TRUE;
  263.     SelPtr Selected = NULL;
  264.     char   keychar;
  265.     BCINT  SelBoxX = 0;
  266.     BCINT  SelBoxY = 0;
  267.     Bool   StretchSelBox = FALSE;
  268.     Bool   ShowRulers = FALSE;
  269.     BCINT  OldPointerX = 0;
  270.     BCINT  OldPointerY = 0;
  271.     
  272.     MadeChanges = FALSE;
  273.     MadeMapChanges = FALSE;
  274.     if (InitialScale < 1)
  275.     InitialScale = 1;
  276.     else if (InitialScale > 20)
  277.     InitialScale = 20;
  278.     Scale = (float) (1.0 / InitialScale);
  279.     CenterMapAroundCoords( (MapMinX + MapMaxX) / 2, (MapMinY + MapMaxY) / 2);
  280.     if (UseMouse) {
  281.     ResetMouseLimits();
  282.     SetMouseCoords( PointerX, PointerY);
  283.     ShowMousePointer();
  284.     oldbuttons = 0;
  285.     }
  286.     else
  287.     FakeCursor = TRUE;
  288.     
  289.     for (;;) {
  290.     key = 0;
  291.     altkey = 0;
  292.     
  293.     /* get mouse position and button status */
  294.     if (UseMouse) {
  295.         if (FakeCursor || ShowRulers) {
  296.         HideMousePointer();
  297.         DrawPointer( ShowRulers);
  298.         ShowMousePointer();
  299.         }
  300.         GetMouseCoords( &PointerX, &PointerY, &buttons);
  301.         if (FakeCursor || ShowRulers) {
  302.         HideMousePointer();
  303.         DrawPointer( ShowRulers);
  304.         ShowMousePointer();
  305.         }
  306.         if ( buttons == 1 && PointerY < 16) {
  307.         /* kluge for the menu bar */
  308.         altkey = 0x08;
  309.         if (PointerX < 12)
  310.             Beep();
  311.         else if (PointerX < 60)
  312.             key = 0x2100; /* 'F' */
  313.         else if (PointerX < 108)
  314.             key = 0x1200; /* 'E' */
  315.         else if (PointerX < 172)
  316.             key = 0x1f00; /* 'S' */
  317.         else if (PointerX < 228)
  318.             key = 0x3200; /* 'M' */
  319.         else if (PointerX < 276)
  320.             key = 0x1700; /* 'I' */
  321.         else if (PointerX < 348)
  322.             key = 0x1800; /* 'O' */
  323.         else if (PointerX < 406)
  324.             key = 0x2E00; /* 'C' */
  325.         else if (PointerX < ScrMaxX - 43)
  326.             Beep();
  327.         else
  328.             key = 0x2300; /* 'H' */
  329.         }
  330.         else {
  331.         if (buttons != oldbuttons) {
  332.             switch (buttons) {
  333.             case 1:
  334.             if (SwapButtons)
  335.                 key = 0x000D;
  336.             else
  337.                 key = 'M';      /* Press left button = Mark/Unmark ('M') */
  338.             break;
  339.             case 2:
  340.             if (! DragObject)
  341.                 key = 'D';      /* Press right button = Drag */
  342.             break;
  343.             case 3:
  344.             case 4:
  345.             if (SwapButtons)
  346.                 key = 'M';
  347.             else
  348.                 key = 0x000D;   /* Press middle button = Edit ('Enter') */
  349.             break;
  350.             default:
  351.             if (StretchSelBox) /* Release left button = End Selection Box */
  352.                 key = 'M';
  353.             if (DragObject)    /* Release right button = End Drag */
  354.                 key = 'D';
  355.             break;
  356.             }
  357.             altkey = bioskey( 2);
  358.         }
  359.         }
  360.         oldbuttons = buttons;
  361.     }
  362.     
  363.     /* drag object(s) */
  364.     if (DragObject) {
  365.         BCINT forgetit = FALSE;
  366.         
  367.         if (IsSelected( Selected, CurObject) == FALSE)
  368.         ForgetSelection( &Selected);
  369.         else if (Selected->objnum != CurObject) {
  370.         /* current object must be first in the list */
  371.         UnSelectObject( &Selected, CurObject);
  372.         SelectObject( &Selected, CurObject);
  373.         }
  374.         if (Selected == NULL && CurObject >= 0) {
  375.         SelectObject( &Selected, CurObject);
  376.         forgetit = TRUE;
  377.         }
  378.         if (Selected) {
  379.         if (MoveObjectsToCoords( EditMode, Selected, MAPX( PointerX), MAPY( PointerY), GridScale))
  380.             RedrawMap = REDRAW_ALL;
  381.         if (forgetit)
  382.             ForgetSelection( &Selected);
  383.         }
  384.         else {
  385.         Beep();
  386.         DragObject = FALSE;
  387.         }
  388.     }
  389.     else if (StretchSelBox) {
  390.         BCINT x = MAPX( PointerX);
  391.         BCINT y = MAPY( PointerY);
  392.         
  393.         /* draw selection box */
  394.         SetColor( CYAN);
  395.         setwritemode( XOR_PUT);
  396.         DrawMapLine( SelBoxX, SelBoxY, SelBoxX, y);
  397.         DrawMapLine( SelBoxX, y, x, y);
  398.         DrawMapLine( x, y, x, SelBoxY);
  399.         DrawMapLine( x, SelBoxY, SelBoxX, SelBoxY);
  400.         delay( 50);
  401.         DrawMapLine( SelBoxX, SelBoxY, SelBoxX, y);
  402.         DrawMapLine( SelBoxX, y, x, y);
  403.         DrawMapLine( x, y, x, SelBoxY);
  404.         DrawMapLine( x, SelBoxY, SelBoxX, SelBoxY);
  405.         setwritemode( COPY_PUT);
  406.     }
  407.     else if (!RedrawObj) {
  408.         /* check if there is something near the pointer */
  409.         OldObject = CurObject;
  410.         if ((bioskey( 2) & 0x03) == 0x00)  /* no shift keys */
  411.         CurObject = GetCurObject( EditMode, MAPX( PointerX - 4), MAPY( PointerY - 4), MAPX( PointerX + 4), MAPY( PointerY + 4));
  412.         if (CurObject < 0)
  413.         CurObject = OldObject;
  414.     }
  415.     
  416.     /* draw the map */
  417.     if((RedrawMap == REDRAW_NONE) &&
  418.        (LastRedraw == REDRAW_QUICK))
  419.         RedrawMap = REDRAW_ALL;
  420.     
  421.     if (RedrawMap == REDRAW_ALL) {
  422.         DrawMap( EditMode, GridScale, GridShown);
  423.         HighlightSelection( EditMode, Selected);
  424.     }
  425.     else if(RedrawMap == REDRAW_QUICK)
  426.         DrawMapQuick();
  427.     
  428.     /* highlight the current object and display the information box */
  429.     if (RedrawMap == REDRAW_ALL || CurObject != OldObject || RedrawObj) {
  430.         RedrawObj = FALSE;
  431.         if (!RedrawMap && OldObject >= 0)
  432.         HighlightObject( EditMode, OldObject, YELLOW); 
  433.         if (CurObject != OldObject) {
  434.         PlaySound( 50, 10);
  435.         OldObject = CurObject;
  436.         }
  437.         if (CurObject >= 0)
  438.         HighlightObject( EditMode, CurObject, YELLOW);
  439.         if (bioskey( 1)) /* speedup */
  440.         RedrawObj = TRUE;
  441.         else
  442.         DisplayObjectInfo( EditMode, CurObject);
  443.     }
  444.     if (RedrawMap && (FakeCursor || ShowRulers)) {
  445.         if (UseMouse)
  446.         HideMousePointer();
  447.         DrawPointer( ShowRulers);
  448.         if (UseMouse)
  449.         ShowMousePointer();
  450.     }
  451.     
  452.     /* display the current pointer coordinates */
  453.     if (RedrawMap == REDRAW_ALL || PointerX != OldPointerX || PointerY != OldPointerY) {
  454.         SetColor(DARKGRAY);
  455.         DrawScreenBox( ScrMaxX - 170, 5, ScrMaxX - 50, 12);
  456.         SetColor( BLUE);
  457.         DrawScreenText( ScrMaxX - 170, 5, "%d, %d", MAPX( PointerX), MAPY( PointerY));
  458.         OldPointerX = PointerX;
  459.         OldPointerY = PointerY;
  460.     }
  461.     
  462.     /* the map is up to date */
  463.     LastRedraw = RedrawMap;
  464.     RedrawMap = REDRAW_NONE;
  465.     
  466.     /* get user input */
  467.     if (bioskey( 1) || key) {
  468.         if (! key) {
  469.         key = bioskey( 0);
  470.         altkey = bioskey( 2);
  471.         }
  472.         
  473.         /* user wants to access the drop-down menus */
  474.         if (altkey & 0x08) {   /* if alt is pressed... */
  475.         if ((key & 0xFF00) == 0x2100)       /* Scan code for F */
  476.             key = PullDownMenu( 18, 17,
  477.                        "Save           F2", 0x3C00,    (BCINT) 'S', 1,
  478.                        ((Doom2 == TRUE) ?
  479.                        "Save As MAPxx  F3" :
  480.                        "Save As ExMx   F3"), 0x3D00,    (BCINT) 'A', 6,
  481.                        "Quit            Q", (BCINT) 'Q', (BCINT) 'Q', 1,
  482.                        NULL); 
  483.         else if ((key & 0xFF00) == 0x1200) {  /* Scan code for E */
  484.             
  485.             key = PullDownMenu( 66, 17,
  486.                        "Copy object(s)      O", (BCINT) 'O', (BCINT) 'C', 1,
  487.                        "Add object        Ins", 0x5200,    (BCINT) 'A', 1,
  488.                        "Delete object(s)  Del", 0x5300,    (BCINT) 'D', 1,
  489.                        ((EditMode == OBJ_VERTEXES) ?
  490.                     NULL :
  491.                     "Preferences        F5"), 0x3F00,   (BCINT) 'P', 1,
  492.                        NULL);
  493.         }
  494.         else if ((key & 0xFF00) == 0x1F00)  /* Scan code for S */
  495.             key = PullDownMenu( 114, 17,
  496.                        "Find/Change       F4", -1,        (BCINT) 'F', -1,
  497.                        "Repeat last find    ", -1,        (BCINT) 'R', -1,
  498.                        "Next object        N", (BCINT) 'N', (BCINT) 'N', 1,
  499.                        "Prev object        P", (BCINT) 'P', (BCINT) 'P', 1,
  500.                        "Jump to object...  J", (BCINT) 'J', (BCINT) 'J', 1,
  501.                        NULL);
  502.         else if ((key & 0xFF00) == 0x3200)  /* Scan code for M */
  503.             key = PullDownMenu( 178, 17,
  504.                        ((EditMode == OBJ_THINGS) ?
  505.                     "√ Things              T" :
  506.                     "  Things              T"), (BCINT) 'T', (BCINT) 'T', 3,
  507.                        ((EditMode == OBJ_LINEDEFS) ?
  508.                     "√ Linedefs+Sidedefs   L" :
  509.                     "  Linedefs+Sidedefs   L"), (BCINT) 'L', (BCINT) 'L', 3,
  510.                        ((EditMode == OBJ_VERTEXES) ?
  511.                     "√ Vertexes            V" :
  512.                     "  Vertexes            V"), (BCINT) 'V', (BCINT) 'V', 3,
  513.                        ((EditMode == OBJ_SECTORS) ?
  514.                     "√ Sectors             S" :
  515.                     "  Sectors             S"), (BCINT) 'S', (BCINT) 'S', 3,
  516.                        "  Next mode         Tab",  0x0009,    (BCINT) 'N', 3,
  517.                        "  Last mode   Shift+Tab",  0x0F00,    (BCINT) 'L', 3,
  518.                        NULL);
  519.         else if ((key & 0xFF00) == 0x1700) { /* Scan code for I */
  520.             key = 0;
  521.             /* code duplicated from 'F8' - I hate to do that */
  522.             if (Selected)
  523.             MiscOperations( 234, 17, EditMode, &Selected);
  524.             else {
  525.             if (CurObject >= 0)
  526.                 SelectObject( &Selected, CurObject);
  527.             MiscOperations( 234, 17, EditMode, &Selected);
  528.             if (CurObject >= 0)
  529.                 UnSelectObject( &Selected, CurObject);
  530.             }
  531.             CurObject = -1;
  532.             DragObject = FALSE;
  533.             StretchSelBox = FALSE;
  534.         }
  535.         else if ((key & 0xFF00) == 0x1800) { /* Scan code for O */
  536.             BCINT savednum, i;
  537.             
  538.             key = 0;
  539.             /* don't want to create the object behind the menu bar... */
  540.             if (PointerY < 20) {
  541.             PointerX = ScrCenterX;
  542.             PointerY = ScrCenterY;
  543.             }
  544.             /* code duplicated from 'F9' - I hate to do that */
  545.             savednum = NumLineDefs;
  546.             InsertStandardObject( 282, 17, MAPX( PointerX), MAPY( PointerY));
  547.             if (NumLineDefs > savednum) {
  548.             ForgetSelection( &Selected);
  549.             EditMode = OBJ_LINEDEFS;
  550.             for (i = savednum; i < NumLineDefs; i++)
  551.                 SelectObject( &Selected, i);
  552.             CurObject = NumLineDefs - 1;
  553.             OldObject = -1;
  554.             DragObject = FALSE;
  555.             StretchSelBox = FALSE;
  556.             }
  557.         }
  558.         else if ((key & 0xFF00) == 0x2E00) { /* Scan code for C */
  559.             key = 0;
  560.             CheckLevel( 354, 17);
  561.         }
  562.         else if ((key & 0xFF00) == 0x2300)  /* Scan code for H */
  563.             key = PullDownMenu( ScrMaxX, 17,
  564.                     "  Keyboard & mouse  F1",  0x3B00,    (BCINT) 'K', 3,
  565.                        (InfoShown ?
  566.                     "√ Info bar           I" :
  567.                     "  Info bar           I"), (BCINT) 'I', (BCINT) 'I', 3,
  568.                     "  About DETH...       ",  -1,    (BCINT) 'A', 3 ,
  569.                        NULL);
  570.         else {
  571.             Beep();
  572.             key = 0;
  573.         }
  574.         RedrawMap = REDRAW_ALL;
  575.         }
  576.         
  577.         /* User wants to do the impossible. */
  578.         if (key == -1) {
  579.         NotImplemented();
  580.         RedrawMap = REDRAW_ALL;
  581.         }
  582.         
  583.         /* simplify the checks later on */
  584.         if (isprint(key & 0x00ff)) 
  585.         keychar = toupper(key & 0x00ff);
  586.         else
  587.         keychar = '\0';
  588.         
  589.         
  590.         /* erase the (keyboard) pointer */
  591.         if (FakeCursor || ShowRulers) {
  592.         HideMousePointer();
  593.         DrawPointer( ShowRulers);
  594.         ShowMousePointer();
  595.         }
  596.         
  597.         /* user wants to exit            AJB   */
  598.         if (keychar == 'Q' && QisQuit == TRUE) {
  599.             if (!MadeChanges || Confirm(-1, -1, "You have unsaved changes.  Do you really want to quit?", NULL))
  600.             break;
  601.             RedrawMap = REDRAW_ALL;
  602.         } 
  603. /*        ForgetSelection( &Selected);        
  604.         if (CheckStartingPos()) {
  605.             if (Registered && MadeChanges) {
  606.             char *outfile;
  607.             
  608.             outfile = GetWadFileName( episode, mission);
  609.             if (outfile) {
  610.                 SaveLevelData( outfile);
  611.                 break;
  612.             }
  613.             }
  614.             else
  615.             break; 
  616.         } 
  617.         RedrawMap = REDRAW_ALL;
  618.         } */
  619.         else if ((key & 0x00FF) == 0x001B) { /* 'Esc' */
  620.         if (DragObject)
  621.             DragObject = FALSE;                          
  622.         else if (StretchSelBox)
  623.             StretchSelBox = FALSE;
  624.         else {
  625.             ForgetSelection( &Selected);
  626.             if (!MadeChanges || Confirm(-1, -1, "You have unsaved changes.  Do you really want to quit?", NULL))
  627.             break;
  628.             RedrawMap = REDRAW_ALL;
  629.         }
  630.         }
  631.         
  632.         /* user is lost */
  633.         else if ((key & 0xFF00) == 0x3B00) { /* 'F1' */
  634.         DisplayHelp( EditMode, GridScale);
  635.         RedrawMap = REDRAW_ALL;
  636.         }
  637.         
  638.         /* user wants to save the level data */
  639.         else if (((key & 0xFF00) == 0x3C00 || (keychar == 'Q')) && (Registered || Doom2)) { /* 'F2' */
  640.         char *outfile;
  641.         
  642.         if (CheckStartingPos()) {
  643.             outfile = GetWadFileName( episode, mission);
  644.             if (outfile)
  645.             SaveLevelData( outfile);
  646.         }
  647.         RedrawMap = REDRAW_ALL;
  648.         }
  649.         
  650.         /* user wants to save and change the episode and mission numbers */
  651.         else if ((key & 0xFF00) == 0x3D00 && (Registered || Doom2)) { /* 'F3' */
  652.         char *outfile;
  653.         BCINT e, m;
  654.         MDirPtr newLevel, oldl, newl;
  655.         char name[ 7];
  656.         
  657.         if (CheckStartingPos()) {
  658.             outfile = GetWadFileName( episode, mission);
  659.             if (outfile) {
  660.             e = episode;
  661.             m = mission;
  662.             SelectLevel( &e, &m);
  663.             if (e > 0 && m > 0 && (e != episode || m != mission)) {
  664.                 /* horrible but it works... */
  665.                 episode = e;
  666.                 mission = m;
  667.                 sprintf( name, "E%dM%d", episode, mission);
  668.                 newLevel = FindMasterDir( MasterDir, name);
  669.                 oldl = Level;
  670.                 newl = newLevel;
  671.                 for (m = 0; m < 11; m++) {
  672.                 newl->wadfile = oldl->wadfile;
  673.                 if (m > 0)
  674.                     newl->dir = oldl->dir;
  675.                 oldl = oldl->next;
  676.                 newl = newl->next;
  677.                 }
  678.                 Level = newLevel;
  679.             }
  680.             SaveLevelData( outfile);
  681.             }
  682.         }
  683.         RedrawMap = REDRAW_ALL;
  684.         }
  685.         
  686.         /* user wants to get the 'Preferences' menu */
  687.         else if ((key & 0xFF00) == 0x3F00) { /* 'F5' */
  688.         Preferences( -1, -1);
  689.         RedrawMap = REDRAW_ALL;
  690.         }
  691.         
  692.         /* user wants to get the menu of misc. ops */
  693.         else if ((key & 0xFF00) == 0x4200) { /* 'F8' */
  694.         if (Selected)
  695.             MiscOperations( -1, -1, EditMode, &Selected);
  696.         else {
  697.             if (CurObject >= 0)
  698.             SelectObject( &Selected, CurObject);
  699.             MiscOperations( -1, -1, EditMode, &Selected);
  700.             if (CurObject >= 0)
  701.             UnSelectObject( &Selected, CurObject);
  702.         }
  703.         CurObject = -1;
  704.         RedrawMap = REDRAW_ALL;
  705.         DragObject = FALSE;
  706.         StretchSelBox = FALSE;
  707.         }
  708.         
  709.         /* user wants to insert a standard shape */
  710.         else if ((key & 0xFF00) == 0x4300) { /* 'F9' */
  711.         BCINT savednum, i;
  712.         
  713.         savednum = NumLineDefs;
  714.         InsertStandardObject( -1, -1, MAPX( PointerX), MAPY( PointerY));
  715.         if (NumLineDefs > savednum) {
  716.             ForgetSelection( &Selected);
  717.             EditMode = OBJ_LINEDEFS;
  718.             for (i = savednum; i < NumLineDefs; i++)
  719.             SelectObject( &Selected, i);
  720.             CurObject = NumLineDefs - 1;
  721.             OldObject = -1;
  722.             DragObject = FALSE;
  723.             StretchSelBox = FALSE;
  724.         }
  725.         RedrawMap = REDRAW_ALL;
  726.         }
  727.         
  728.         /* user wants to check his level */
  729.         else if ((key & 0xFF00) == 0x4400) { /* 'F10' */
  730.         CheckLevel( -1, -1);
  731.         RedrawMap = REDRAW_ALL;
  732.         }
  733.         
  734.         /* user wants to display/hide the info box */
  735.         else if (keychar == 'I') {
  736.         InfoShown = !InfoShown;
  737.         RedrawMap = REDRAW_ALL;
  738.         }
  739.         
  740.         /* user wants to change the scale */
  741.         /*AJB*/
  742.         else if ((keychar == '+' || keychar == '=') && Scale < 16.0) { 
  743.         OrigX += (BCINT) ((PointerX - ScrCenterX) / Scale);
  744.         OrigY += (BCINT) ((ScrCenterY - PointerY) / Scale);
  745.         if (Scale < 1.0)
  746.             Scale = 1.0 / ((1.0 / Scale) - 1.0);
  747.         else
  748.             Scale = Scale * 2.0;
  749.         OrigX -= (BCINT) ((PointerX - ScrCenterX) / Scale);
  750.         OrigY -= (BCINT) ((ScrCenterY - PointerY) / Scale);
  751.         RedrawMap = REDRAW_ALL;
  752.         }
  753.         else if ((keychar == '-' || keychar == '_') && Scale > 0.05) {
  754.         OrigX += (BCINT) ((PointerX - ScrCenterX) / Scale);
  755.         OrigY += (BCINT) ((ScrCenterY - PointerY) / Scale);
  756.         if (Scale < 1.0)
  757.             Scale = 1.0 / ((1.0 / Scale) + 1.0);
  758.         else
  759.             Scale = Scale / 2.0;
  760.         OrigX -= (BCINT) ((PointerX - ScrCenterX) / Scale);
  761.         OrigY -= (BCINT) ((ScrCenterY - PointerY) / Scale);
  762.         RedrawMap = REDRAW_ALL;
  763.         }
  764.         
  765.         /* user wants to set the scale directly */
  766.         else if (keychar >= '0' && keychar <= '9') {
  767.         OrigX += (BCINT) ((PointerX - ScrCenterX) / Scale);
  768.         OrigY += (BCINT) ((ScrCenterY - PointerY) / Scale);
  769.         if (keychar == '0')
  770.             Scale = 0.1;
  771.         else
  772.             Scale = 1.0 / (keychar - '0');
  773.         OrigX -= (BCINT) ((PointerX - ScrCenterX) / Scale);
  774.         OrigY -= (BCINT) ((ScrCenterY - PointerY) / Scale);
  775.         RedrawMap = REDRAW_ALL;
  776.         }
  777.         
  778.         /* user wants to move */
  779.         else if ((key & 0xFF00) == 0x4800 && (PointerY - MoveSpeed) >= 0) {
  780.         if (UseMouse)
  781.             SetMouseCoords( PointerX, PointerY - MoveSpeed);
  782.         else
  783.             PointerY -= MoveSpeed;
  784.         }
  785.         else if ((key & 0xFF00) == 0x5000 && (PointerY + MoveSpeed) <= ScrMaxY) {
  786.         if (UseMouse)
  787.             SetMouseCoords( PointerX, PointerY + MoveSpeed);
  788.         else
  789.             PointerY += MoveSpeed;
  790.         }
  791.         else if ((key & 0xFF00) == 0x4B00 && (PointerX - MoveSpeed) >= 0) {
  792.         if (UseMouse)
  793.             SetMouseCoords( PointerX - MoveSpeed, PointerY);
  794.         else
  795.             PointerX -= MoveSpeed;
  796.         }
  797.         else if ((key & 0xFF00) == 0x4D00 && (PointerX + MoveSpeed) <= ScrMaxX) {
  798.         if (UseMouse)
  799.             SetMouseCoords( PointerX + MoveSpeed, PointerY);
  800.         else
  801.             PointerX += MoveSpeed;
  802.         }
  803.         
  804.         /* user wants so scroll the map */
  805.         else if ((key & 0xFF00) == 0x4900 && MAPY( ScrCenterY) < MapMaxY) {
  806.         OrigY += (BCINT) (ScrCenterY / Scale);
  807.         RedrawMap = REDRAW_ALL;
  808.         }
  809.         else if ((key & 0xFF00) == 0x5100 && MAPY( ScrCenterY) > MapMinY) {
  810.         OrigY -= (BCINT) (ScrCenterY / Scale);
  811.         RedrawMap = REDRAW_ALL;
  812.         }
  813.         else if ((key & 0xFF00) == 0x4700 && MAPX( ScrCenterX) > MapMinX) {
  814.         OrigX -= (BCINT) (ScrCenterX / Scale);
  815.         RedrawMap = REDRAW_ALL;
  816.         }
  817.         else if ((key & 0xFF00) == 0x4F00 && MAPX( ScrCenterX) < MapMaxX) {
  818.         OrigX += (BCINT) (ScrCenterX / Scale);
  819.         RedrawMap = REDRAW_ALL;
  820.         }
  821.         
  822.         /* user wants to change the movement speed */
  823.         else if (keychar == ' ')
  824.         MoveSpeed = MoveSpeed == 2 ? DefaultLargeScroll : 2;
  825.         
  826.         /* user wants to change the edit mode */
  827.         else if ((key & 0x00FF) == 0x0009 || (key & 0xFF00) == 0x0F00 || keychar == 'T' || keychar == 'V' || keychar == 'L' || keychar == 'S') {
  828.         BCINT   PrevMode = EditMode;
  829.         SelPtr NewSel;
  830.         
  831.         if ((key & 0x00FF) == 0x0009) { /* 'Tab' */
  832.             switch (EditMode) {
  833.             case OBJ_THINGS:
  834.             EditMode = OBJ_VERTEXES;
  835.             break;
  836.             case OBJ_VERTEXES:
  837.             EditMode = OBJ_LINEDEFS;
  838.             break;
  839.             case OBJ_LINEDEFS:
  840.             EditMode = OBJ_SECTORS;
  841.             break;
  842.             case OBJ_SECTORS:
  843.             EditMode = OBJ_THINGS;
  844.             break;
  845.             }
  846.         }
  847.         else if ((key & 0xFF00) == 0x0F00) { /* 'Shift-Tab' */
  848.             switch (EditMode) {
  849.             case OBJ_THINGS:
  850.             EditMode = OBJ_SECTORS;
  851.             break;
  852.             case OBJ_VERTEXES:
  853.             EditMode = OBJ_THINGS;
  854.             break;
  855.             case OBJ_LINEDEFS:
  856.             EditMode = OBJ_VERTEXES;
  857.             break;
  858.             case OBJ_SECTORS:
  859.             EditMode = OBJ_LINEDEFS;
  860.             break;
  861.             }
  862.         }
  863.         else {
  864.             if (keychar == 'T')
  865.             EditMode = OBJ_THINGS;
  866.             else if (keychar == 'V')
  867.             EditMode = OBJ_VERTEXES;
  868.             else if (keychar == 'L')
  869.             EditMode = OBJ_LINEDEFS;
  870.             else if (keychar == 'S')
  871.             EditMode = OBJ_SECTORS;
  872.             ForgetSelection( &Selected);
  873.         }
  874.         
  875.         /* special cases for the selection list... */
  876.         if (Selected) {
  877.             /* select all LineDefs bound to the selected Sectors */
  878.             if (PrevMode == OBJ_SECTORS && EditMode == OBJ_LINEDEFS) {
  879.             int l, sd;
  880.             
  881.             ObjectsNeeded( OBJ_LINEDEFS, OBJ_SIDEDEFS, 0);
  882.             NewSel = NULL;
  883.             for (l = 0; l < NumLineDefs; l++) {
  884.                 sd = LineDefs[ l].sidedef1;
  885.                 if (sd >= 0 && IsSelected( Selected, SideDefs[ sd].sector))
  886.                 SelectObject( &NewSel, l);
  887.                 else {
  888.                 sd = LineDefs[ l].sidedef2;
  889.                 if (sd >= 0 && IsSelected( Selected, SideDefs[ sd].sector))
  890.                     SelectObject( &NewSel, l);
  891.                 }
  892.             }
  893.             ForgetSelection( &Selected);
  894.             Selected = NewSel;
  895.             }
  896.             /* select all Vertices bound to the selected LineDefs */
  897.             else if (PrevMode == OBJ_LINEDEFS && EditMode == OBJ_VERTEXES) {
  898.             ObjectsNeeded( OBJ_LINEDEFS, 0);
  899.             NewSel = NULL;
  900.             while (Selected) {
  901.                 if (!IsSelected( NewSel, LineDefs[ Selected->objnum].start))
  902.                 SelectObject( &NewSel, LineDefs[ Selected->objnum].start);
  903.                 if (!IsSelected( NewSel, LineDefs[ Selected->objnum].end))
  904.                 SelectObject( &NewSel, LineDefs[ Selected->objnum].end);
  905.                 UnSelectObject( &Selected, Selected->objnum);
  906.             }
  907.             Selected = NewSel;
  908.             }
  909.             /* select all Sectors that have their LineDefs selected */
  910.             else if (PrevMode == OBJ_LINEDEFS && EditMode == OBJ_SECTORS) {
  911.             int l, sd;
  912.             
  913.             ObjectsNeeded( OBJ_LINEDEFS, OBJ_SIDEDEFS, 0);
  914.             NewSel = NULL;
  915.             /* select all Sectors... */
  916.             for (l = 0; l < NumSectors; l++)
  917.                 SelectObject( &NewSel, l);
  918.             /* ... then unselect those that should not be in the list */
  919.             for (l = 0; l < NumLineDefs; l++)
  920.                 if (!IsSelected( Selected, l)) {
  921.                 sd = LineDefs[ l].sidedef1;
  922.                 if (sd >= 0)
  923.                     UnSelectObject( &NewSel, SideDefs[ sd].sector);
  924.                 sd = LineDefs[ l].sidedef2;
  925.                 if (sd >= 0)
  926.                     UnSelectObject( &NewSel, SideDefs[ sd].sector);
  927.                 }
  928.             ForgetSelection( &Selected);
  929.             Selected = NewSel;
  930.             }
  931.             /* select all LineDefs that have both ends selected */
  932.             else if (PrevMode == OBJ_VERTEXES && EditMode == OBJ_LINEDEFS) {
  933.             int l;
  934.             
  935.             ObjectsNeeded( OBJ_LINEDEFS, 0);
  936.             NewSel = NULL;
  937.             for (l = 0; l < NumLineDefs; l++)
  938.                 if (IsSelected( Selected, LineDefs[ l].start) && IsSelected( Selected, LineDefs[ l].end))
  939.                 SelectObject( &NewSel, l);
  940.             ForgetSelection( &Selected);
  941.             Selected = NewSel;
  942.             }
  943.             /* unselect all */
  944.             else
  945.             ForgetSelection( &Selected);
  946.         }
  947.         if (GetMaxObjectNum( EditMode) >= 0 && Select0 == TRUE)
  948.             CurObject = 0;
  949.         else
  950.             CurObject = -1;
  951.         OldObject = -1;
  952.         DragObject = FALSE;
  953.         StretchSelBox = FALSE;
  954.         RedrawMap = REDRAW_ALL;
  955.         }
  956.         
  957.         /* user wants to change the grid scale */
  958.         else if (keychar == 'G') {
  959.         if ((altkey & 0x03) == 0x00) { /* no shift keys */
  960.             if (GridScale == 0)
  961.             GridScale = 512;
  962.             else if (GridScale > 4)
  963.             GridScale /= 2;
  964.             else
  965.             GridScale = 0;
  966.         }
  967.         else {
  968.             if (GridScale == 0)
  969.             GridScale = 4;
  970.             else if (GridScale < 512)
  971.             GridScale *= 2;
  972.             else
  973.             GridScale = 0;
  974.         }
  975.         RedrawMap = REDRAW_ALL;
  976.         }
  977.         else if (keychar == 'K') {
  978.             if ((altkey & 0x03) == 0x00)  /* no shift keys */
  979.                 GridScale = 0;
  980.         RedrawMap = REDRAW_ALL;
  981.         }
  982.         else if (keychar == 'H') {
  983.         if ((altkey & 0x03) != 0x00)  /* shift key pressed */
  984.             GridScale = 0;
  985.         else
  986.             GridShown = !GridShown;
  987.         RedrawMap = REDRAW_ALL;
  988.         }
  989.         
  990.         /* user wants to toggle the rulers */
  991.         else if (keychar == 'R')
  992.         ShowRulers = !ShowRulers;
  993.  
  994.  
  995.         /* user wants to toggle drag mode */
  996.         else if (keychar == 'D') {
  997.         StretchSelBox = FALSE;
  998.         if (DragObject) {
  999.             DragObject = FALSE;
  1000.             if (EditMode == OBJ_VERTEXES) {
  1001.             if (Selected == NULL && CurObject >= 0) {
  1002.                 SelectObject( &Selected, CurObject);
  1003.                 if (AutoMergeVertices( &Selected))
  1004.                 RedrawMap = REDRAW_ALL;
  1005.                 ForgetSelection( &Selected);
  1006.             }
  1007.             else
  1008.                 if (AutoMergeVertices( &Selected))
  1009.                 RedrawMap = REDRAW_ALL;
  1010.             }
  1011.             else if (EditMode == OBJ_LINEDEFS) {
  1012.             SelPtr NewSel, cur;
  1013.             
  1014.             ObjectsNeeded( OBJ_LINEDEFS, 0);
  1015.             NewSel = NULL;
  1016.             if (Selected == NULL && CurObject >= 0) {
  1017.                 SelectObject( &NewSel, LineDefs[ CurObject].start);
  1018.                 SelectObject( &NewSel, LineDefs[ CurObject].end);
  1019.             }
  1020.             else {
  1021.                 for (cur = Selected; cur; cur = cur->next) {
  1022.                 if (!IsSelected( NewSel, LineDefs[ cur->objnum].start))
  1023.                     SelectObject( &NewSel, LineDefs[ cur->objnum].start);
  1024.                 if (!IsSelected( NewSel, LineDefs[ cur->objnum].end))
  1025.                     SelectObject( &NewSel, LineDefs[ cur->objnum].end);
  1026.                 }
  1027.             }
  1028.             if (AutoMergeVertices( &NewSel))
  1029.                 RedrawMap = REDRAW_ALL;
  1030.             ForgetSelection( &NewSel);
  1031.             }
  1032.         }
  1033.         else {
  1034.             DragObject = TRUE;
  1035.             if (EditMode == OBJ_THINGS && CurObject >= 0)
  1036.             MoveObjectsToCoords( EditMode, NULL, Things[ CurObject].xpos, Things[ CurObject].ypos, 0);
  1037.             else if (EditMode == OBJ_VERTEXES && CurObject >= 0)
  1038.             MoveObjectsToCoords( EditMode, NULL, Vertexes[ CurObject].x, Vertexes[ CurObject].y, 0);
  1039.             else
  1040.             MoveObjectsToCoords( EditMode, NULL, MAPX( PointerX), MAPY( PointerY), GridScale);
  1041.         }
  1042.         }
  1043.         
  1044.         /* user wants to select the next or previous object */
  1045.         else if (keychar == 'N' || keychar == '>') {
  1046.         if (CurObject < GetMaxObjectNum( EditMode))
  1047.             CurObject++;
  1048.         else if (GetMaxObjectNum( EditMode) >= 0)
  1049.             CurObject = 0;
  1050.         else
  1051.             CurObject = -1;
  1052.         RedrawMap = REDRAW_ALL;
  1053.         }
  1054.         else if (keychar == 'P' || keychar == '<') {
  1055.         if (CurObject > 0)
  1056.             CurObject--;
  1057.         else
  1058.             CurObject = GetMaxObjectNum( EditMode);
  1059.         RedrawMap = REDRAW_ALL;
  1060.         }
  1061.         else if (keychar == 'J' || keychar == '#') {
  1062.         OldObject = InputObjectNumber( -1, -1, EditMode, CurObject);
  1063.         if (OldObject >= 0) {
  1064.             CurObject = OldObject;
  1065.             GoToObject( EditMode, CurObject);
  1066.         }
  1067.         else
  1068.             OldObject = CurObject;
  1069.         RedrawMap = REDRAW_ALL;
  1070.         }
  1071.         
  1072.         /* user wants to mark/unmark an object or a group of objects */
  1073.         else if (keychar == 'M') {
  1074.         if (StretchSelBox) {
  1075.             SelPtr oldsel;
  1076.             
  1077.             /* select all objects in the selection box */
  1078.             StretchSelBox = FALSE;
  1079.             RedrawMap = REDRAW_ALL;
  1080.             /* additive selection box or not? */
  1081.             if (AdditiveSelBox == FALSE)
  1082.             ForgetSelection( &Selected);
  1083.             else
  1084.             oldsel = Selected;
  1085.             Selected = SelectObjectsInBox( EditMode, SelBoxX, SelBoxY, MAPX( PointerX), MAPY( PointerY));
  1086.             if (AdditiveSelBox == TRUE)
  1087.             while (oldsel != NULL) {
  1088.                 if (! IsSelected( Selected, oldsel->objnum))
  1089.                 SelectObject( &Selected, oldsel->objnum);
  1090.                 UnSelectObject( &oldsel, oldsel->objnum);
  1091.             }
  1092.             if (Selected) {
  1093.             CurObject = Selected->objnum;
  1094.             PlaySound( 440, 10);
  1095.             }
  1096.             else
  1097.             CurObject = -1;
  1098.         }
  1099.         else if ((altkey & 0x03) == 0x00)  { /* no shift keys */
  1100.             if (CurObject >= 0) {
  1101.             /* mark or unmark one object */
  1102.             if (IsSelected( Selected, CurObject))
  1103.                 UnSelectObject( &Selected, CurObject);
  1104.             else
  1105.                 SelectObject( &Selected, CurObject);
  1106.             HighlightObject( EditMode, CurObject, GREEN);
  1107.             if (Selected)
  1108.                 PlaySound( 440, 10);
  1109.             DragObject = FALSE;
  1110.             }
  1111.             else
  1112.             Beep();
  1113.         }
  1114.         else {
  1115.             /* begin "stretch selection box" mode */
  1116.             SelBoxX = MAPX( PointerX);
  1117.             SelBoxY = MAPY( PointerY);
  1118.             StretchSelBox = TRUE;
  1119.             DragObject = FALSE;
  1120.         }
  1121.         }
  1122.         
  1123.         /* user wants to clear all marks and redraw the map */
  1124.         else if (keychar == 'C') {
  1125.         ForgetSelection( &Selected);
  1126.         RedrawMap = REDRAW_ALL;
  1127.         DragObject = FALSE;
  1128.         StretchSelBox = FALSE;
  1129.         }
  1130.         
  1131.         /* user wants to copy a group of objects */
  1132.         else if (keychar == 'O' && CurObject >= 0) {
  1133.         /* copy the object(s) */
  1134.         if (Selected == NULL)
  1135.             SelectObject( &Selected, CurObject);
  1136.         CopyObjects( EditMode, Selected);
  1137.         /* enter drag mode */
  1138.         DragObject = TRUE;
  1139.         CurObject = Selected->objnum;
  1140.         if (EditMode == OBJ_THINGS)
  1141.             MoveObjectsToCoords( EditMode, NULL, Things[ CurObject].xpos, Things[ CurObject].ypos, 0);
  1142.         else if (EditMode == OBJ_VERTEXES)
  1143.             MoveObjectsToCoords( EditMode, NULL, Vertexes[ CurObject].x, Vertexes[ CurObject].y, 0);
  1144.         else
  1145.             MoveObjectsToCoords( EditMode, NULL, MAPX( PointerX), MAPY( PointerY), GridScale);
  1146.         RedrawMap = REDRAW_ALL;
  1147.         StretchSelBox = FALSE;
  1148.         }
  1149.         
  1150.         /* user wants to rotate things */
  1151.         else if((keychar == ',') || (keychar == '.')) {
  1152.         if(EditMode == OBJ_THINGS) {
  1153.             BCINT temp, rot = (keychar == ',') ? 45 : 315;
  1154.             SelPtr cur;
  1155.             
  1156.             for(cur = Selected; cur; cur = cur->next) {
  1157.             if(cur->objnum != CurObject) {
  1158.                 temp = (Things[cur->objnum].angle + rot) % 360;
  1159.                 Things[cur->objnum].angle = temp;
  1160.             }
  1161.             }
  1162.             
  1163.             temp = (Things[CurObject].angle + rot) % 360;
  1164.             Things[CurObject].angle = temp;
  1165.             
  1166.             RedrawMap = REDRAW_ALL;
  1167.         }
  1168.         }
  1169.         
  1170.         
  1171.         /* user wants to edit the current object */
  1172.         else if ((key & 0x00FF) == 0x000D && CurObject >= 0) { /* 'Enter' */
  1173.         if (Selected)
  1174.             EditObjectsInfo( 0, 30, EditMode, Selected);
  1175.         else {
  1176.             SelectObject( &Selected, CurObject);
  1177.             EditObjectsInfo( 0, 30, EditMode, Selected);
  1178.             UnSelectObject( &Selected, CurObject);
  1179.         }
  1180.         RedrawMap = REDRAW_ALL;
  1181.         DragObject = FALSE;
  1182.         StretchSelBox = FALSE;
  1183.         }
  1184.         
  1185.         /* user wants to delete the current object */
  1186.         else if ((key & 0xFF00) == 0x5300 && CurObject >= 0) { /* 'Del' */
  1187.         if (EditMode == OBJ_THINGS || Expert || Confirm( -1, -1,
  1188.                                 (Selected ? "Do you really want to delete these objects?" : "Do you really want to delete this object?"),
  1189.                                 (Selected ? "This will also delete the objects bound to them." : "This will also delete the objects bound to it."))) {
  1190.             if (Selected)
  1191.             DeleteObjects( EditMode, &Selected);
  1192.             else
  1193.             DeleteObject( EditMode, CurObject);
  1194.             CurObject = -1;
  1195.         }
  1196.         DragObject = FALSE;
  1197.         StretchSelBox = FALSE;
  1198.         RedrawMap = REDRAW_ALL;
  1199.         }
  1200.         
  1201.         /* user wants to insert a new object */
  1202.         else if ((key & 0xFF00) == 0x5200) { /* 'Ins' */
  1203.         SelPtr cur;
  1204.         
  1205.         /* first special case: if several Vertices are selected, add new LineDefs */
  1206.         if (EditMode == OBJ_VERTEXES && Selected != NULL && Selected->next != NULL) {
  1207.             BCINT firstv;
  1208.             
  1209.             ObjectsNeeded( OBJ_LINEDEFS, 0);
  1210.             if (Selected->next->next != NULL)
  1211.             firstv = Selected->objnum;
  1212.             else
  1213.             firstv = -1;
  1214.             EditMode = OBJ_LINEDEFS;
  1215.             /* create LineDefs between the Vertices */
  1216.             for (cur = Selected; cur->next; cur = cur->next) {
  1217.             /* check if there is already a LineDef between the two Vertices */
  1218.             for (CurObject = 0; CurObject < NumLineDefs; CurObject++)
  1219.                 if ((LineDefs[ CurObject].start == cur->next->objnum && LineDefs[ CurObject].end == cur->objnum)
  1220.                 || (LineDefs[ CurObject].end == cur->next->objnum && LineDefs[ CurObject].start == cur->objnum))
  1221.                 break;
  1222.             if (CurObject < NumLineDefs)
  1223.                 cur->objnum = CurObject;
  1224.             else {
  1225.                 InsertObject( OBJ_LINEDEFS, -1, 0, 0);
  1226.                 CurObject = NumLineDefs - 1;
  1227.                 LineDefs[ CurObject].start = cur->next->objnum;
  1228.                 LineDefs[ CurObject].end = cur->objnum;
  1229.                 cur->objnum = CurObject;
  1230.             }
  1231.             }
  1232.             /* close the polygon if there are more than 2 Vertices */
  1233.             if (firstv >= 0 && (altkey & 0x03) != 0x00)  { /* shift key pressed */
  1234.             for (CurObject = 0; CurObject < NumLineDefs; CurObject++)
  1235.                 if ((LineDefs[ CurObject].start == firstv && LineDefs[ CurObject].end == cur->objnum)
  1236.                 || (LineDefs[ CurObject].end == firstv && LineDefs[ CurObject].start == cur->objnum))
  1237.                 break;
  1238.             if (CurObject < NumLineDefs)
  1239.                 cur->objnum = CurObject;
  1240.             else {
  1241.                 InsertObject( OBJ_LINEDEFS, -1, 0, 0);
  1242.                 CurObject = NumLineDefs - 1;
  1243.                 LineDefs[ CurObject].start = firstv;
  1244.                 LineDefs[ CurObject].end = cur->objnum;
  1245.                 cur->objnum = CurObject;
  1246.             }
  1247.             }
  1248.             else
  1249.             UnSelectObject( &Selected, cur->objnum);
  1250.         }
  1251.         /* second special case: if several LineDefs are selected, add new SideDefs and one Sector */
  1252.         else if (EditMode == OBJ_LINEDEFS && Selected != NULL) {
  1253.             ObjectsNeeded( OBJ_LINEDEFS, 0);
  1254.             for (cur = Selected; cur; cur = cur->next)
  1255.             if (LineDefs[ cur->objnum].sidedef1 >= 0 && LineDefs[ cur->objnum].sidedef2 >= 0) {
  1256.                 char msg[ 80];
  1257.                 
  1258.                 Beep();
  1259.                 sprintf( msg, "LineDef #%d already has two SideDefs", cur->objnum);
  1260.                 Notify( -1, -1, "Error: cannot add the new Sector", msg);
  1261.                 break;
  1262.             }
  1263.             if (cur == NULL) {
  1264.             EditMode = OBJ_SECTORS;
  1265.             InsertObject( OBJ_SECTORS, -1, 0, 0);
  1266.             CurObject = NumSectors - 1;
  1267.             for (cur = Selected; cur; cur = cur->next) {
  1268.                 InsertObject( OBJ_SIDEDEFS, -1, 0, 0);
  1269.                 SideDefs[ NumSideDefs - 1].sector = CurObject;
  1270.                 ObjectsNeeded( OBJ_LINEDEFS, OBJ_SIDEDEFS, 0);
  1271.                 if (LineDefs[ cur->objnum].sidedef1 >= 0) {
  1272.                 BCINT s;
  1273.                 
  1274.                 s = SideDefs[ LineDefs[ cur->objnum].sidedef1].sector;
  1275.                 if (s >= 0) {
  1276.                     Sectors[ CurObject].floorh = Sectors[ s].floorh;
  1277.                     Sectors[ CurObject].ceilh = Sectors[ s].ceilh;
  1278.                     strncpy( Sectors[ CurObject].floort, Sectors[ s].floort, 8);
  1279.                     strncpy( Sectors[ CurObject].ceilt, Sectors[ s].ceilt, 8);
  1280.                     Sectors[ CurObject].light = Sectors[ s].light;
  1281.                 }
  1282.                 LineDefs[ cur->objnum].sidedef2 = NumSideDefs - 1;
  1283.                 LineDefs[ cur->objnum].flags = 4;
  1284.                 strncpy( SideDefs[ NumSideDefs - 1].tex3, "-", 8);
  1285.                 strncpy( SideDefs[ LineDefs[ cur->objnum].sidedef1].tex3, "-", 8);
  1286.                 }
  1287.                 else
  1288.                 LineDefs[ cur->objnum].sidedef1 = NumSideDefs - 1;
  1289.             }
  1290.             ForgetSelection( &Selected);
  1291.             SelectObject( &Selected, CurObject);
  1292.             }
  1293.         }
  1294.         /* normal case: add a new object of the current type */
  1295.         else {
  1296.             ForgetSelection( &Selected);
  1297.             if (GridScale > 0)
  1298.             InsertObject( EditMode, CurObject, (BCINT) ((int)(MAPX( PointerX) + GridScale / 2)) & ((int)(~(GridScale - 1))), (BCINT) ((int)(MAPY( PointerY) + GridScale / 2)) & (int)(~(GridScale - 1)));
  1299.             else
  1300.             InsertObject( EditMode, CurObject, MAPX( PointerX), MAPY( PointerY));
  1301.             CurObject = GetMaxObjectNum( EditMode);
  1302.             if (EditMode == OBJ_LINEDEFS) {
  1303.             if (! Input2VertexNumbers( -1, -1, "Choose the two vertices for the new LineDef",
  1304.                           &(LineDefs[ CurObject].start), &(LineDefs[ CurObject].end))) {
  1305.                 DeleteObject( EditMode, CurObject);
  1306.                 CurObject = -1;
  1307.             }
  1308.             }
  1309.             else if (EditMode == OBJ_VERTEXES) {
  1310.             SelectObject( &Selected, CurObject);
  1311.             if (AutoMergeVertices( &Selected))
  1312.                 RedrawMap = REDRAW_ALL;
  1313.             ForgetSelection( &Selected);
  1314.             }
  1315.         }
  1316.         DragObject = FALSE;
  1317.         StretchSelBox = FALSE;
  1318.         RedrawMap = REDRAW_ALL;
  1319.         }
  1320.         
  1321.         /* user likes music */
  1322.         else if (key)
  1323.         Beep();
  1324.         
  1325.         /* redraw the (keyboard) pointer */
  1326.         if (FakeCursor || ShowRulers) {
  1327.         HideMousePointer();
  1328.         DrawPointer( ShowRulers);
  1329.         ShowMousePointer();
  1330.         }
  1331.     }
  1332.     
  1333.     /* check if Scroll Lock is off */
  1334.     if ((bioskey( 2) & 0x10) == 0x00) {
  1335.         /* move the map if the pointer is near the edge of the screen */
  1336.         if (PointerY <= (UseMouse ? 0 : 20)) {
  1337.         if (! UseMouse)
  1338.             PointerY += MoveSpeed;
  1339.         if (MAPY( ScrCenterY) < MapMaxY) {                                   
  1340.             OrigY += (BCINT) (MoveSpeed * 2.0 / Scale);
  1341.             RedrawMap = REDRAW_QUICK;
  1342.         }
  1343.         }
  1344.         if (PointerY >= ScrMaxY - (UseMouse ? 0 : 20)) {
  1345.         if (! UseMouse)
  1346.             PointerY -= MoveSpeed;
  1347.         if (MAPY( ScrCenterY) > MapMinY) {
  1348.             OrigY -= (BCINT) (MoveSpeed * 2.0 / Scale);
  1349.             RedrawMap = REDRAW_QUICK;
  1350.         }
  1351.         }
  1352.         if (PointerX <= (UseMouse ? 0 : 20)) {
  1353.         if (! UseMouse)   
  1354.             PointerX += MoveSpeed;
  1355.         if (MAPX( ScrCenterX) > MapMinX) {
  1356.             OrigX -= (BCINT) (MoveSpeed * 2.0 / Scale);
  1357.             RedrawMap = REDRAW_QUICK;
  1358.         }
  1359.         }
  1360.         if (PointerX >= ScrMaxX - (UseMouse ? 0 : 20)) {
  1361.         if (! UseMouse)
  1362.             PointerX -= MoveSpeed;
  1363.         if (MAPX( ScrCenterX) < MapMaxX) {
  1364.             OrigX += (BCINT) (MoveSpeed * 2.0 / Scale);
  1365.             RedrawMap = REDRAW_QUICK;
  1366.         }
  1367.         }
  1368.     }
  1369.     }
  1370. }
  1371.  
  1372.         
  1373. void DrawMapQuick()
  1374. {
  1375.     BCINT n;
  1376.     
  1377.     /*AJB*/
  1378.     if (InfoShown) {
  1379.         ClearMapScreen(13);
  1380.         setviewport(0, 0, ScrMaxX, ScrMaxY -13, TRUE);
  1381.         }
  1382.     else {
  1383.         ClearMapScreen(0);
  1384.         setviewport(0, 0, ScrMaxX, ScrMaxY, TRUE);
  1385.         }
  1386.     ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1387.     for (n = 0; n < NumLineDefs; n++) {
  1388.     SetColor(LIGHTGRAY);
  1389.     DrawMapLine( Vertexes[ LineDefs[ n].start].x, Vertexes[ LineDefs[ n].start].y,
  1390.             Vertexes[ LineDefs[ n].end].x, Vertexes[ LineDefs[ n].end].y);
  1391.     }
  1392.     
  1393.     /* draw in the things */
  1394.     SetColor(DARKGRAY);
  1395.         for (n = 0; n < NumThings; n++) {
  1396.             DrawMapLine( Things[ n].xpos - ( OBJSIZE * 2 ), Things[ n].ypos, Things[ n].xpos + ( OBJSIZE * 2 ), Things[ n].ypos);
  1397.             DrawMapLine( Things[ n].xpos, Things[ n].ypos - ( OBJSIZE * 2 ), Things[ n].xpos, Things[ n].ypos + ( OBJSIZE * 2 ));
  1398.         }
  1399.     setviewport(0, 0, ScrMaxX, ScrMaxY, TRUE);
  1400. }
  1401.  
  1402.  
  1403. /*
  1404.    draw the actual game map                            
  1405.    */
  1406.  
  1407. void DrawMap( BCINT editmode, BCINT grid, Bool drawgrid) /* SWAP! */
  1408. {
  1409.     BCINT  n, m;
  1410.     
  1411.     /* clear the screen */
  1412.     /*AJB*/
  1413.     if (InfoShown)
  1414.         ClearMapScreen(13);
  1415.     else
  1416.         ClearMapScreen(0);
  1417.     ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1418.     
  1419.     /* draw the grid */
  1420.     if (drawgrid == TRUE && grid > 0) {                       
  1421.     BCINT mapx0 = (BCINT)(((int)MAPX( 0)) & ((int)~(grid - 1)));
  1422.     BCINT mapx1 = (BCINT)(((int)(MAPX( ScrMaxX) + grid)) & ((int)~(grid - 1)));
  1423.     BCINT mapy0 = (BCINT)(((int)(MAPY( ScrMaxY) - grid)) & ((int)~(grid - 1)));
  1424.     BCINT mapy1 = (BCINT)(((int)MAPY( 0)) & ((int)~(grid - 1)));
  1425.     
  1426.     SetColor(DARKBLUE);
  1427.     for (n = mapx0; n <= mapx1; n += grid)
  1428.         DrawMapLine( n, mapy0, n, mapy1);
  1429.     for (n = mapy0; n <= mapy1; n += grid)
  1430.         DrawMapLine( mapx0, n, mapx1, n);
  1431.     }
  1432.     
  1433.     /* draw the linedefs to form the map */
  1434.     switch (editmode) {
  1435.     case OBJ_THINGS:
  1436.     ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1437.     /*AJB*/
  1438.     for (n = 0; n < NumLineDefs; n++) {
  1439.         if (LineDefs[ n].flags & 1)
  1440.             SetColor(LIGHTGRAY);
  1441.         else if (LineDefs[ n].flags & 2)
  1442.             SetColor(DARKGREEN);
  1443.         else if (LineDefs[ n].flags & 32)
  1444.             SetColor(DARKMAGENTA);
  1445.         else if (LineDefs[ n].flags & 64)
  1446.             SetColor(DARKRED);
  1447.         else if (LineDefs[ n].flags & 128)
  1448.             SetColor(ORANGE);
  1449.         else
  1450.             SetColor(DARKGRAY);
  1451.         DrawMapLine( Vertexes[ LineDefs[ n].start].x, Vertexes[ LineDefs[ n].start].y,
  1452.             Vertexes[ LineDefs[ n].end].x, Vertexes[ LineDefs[ n].end].y);
  1453.     }
  1454.     break;
  1455.     case OBJ_VERTEXES:
  1456.     ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1457.     SetColor(DARKGRAY);
  1458.     for (n = 0; n < NumLineDefs; n++)
  1459.         DrawMapVector( Vertexes[ LineDefs[ n].start].x, Vertexes[ LineDefs[ n].start].y,
  1460.               Vertexes[ LineDefs[ n].end].x, Vertexes[ LineDefs[ n].end].y);
  1461.     break;
  1462.     case OBJ_LINEDEFS:
  1463.     ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1464.     for (n = 0; n < NumLineDefs; n++) {
  1465.         if (LineDefs[ n].type > 0) {
  1466.         if (LineDefs[ n].tag > 0)
  1467.             SetColor( LIGHTMAGENTA);
  1468.         else
  1469.             SetColor( LIGHTGREEN);
  1470.         }
  1471.         /*AJB*/
  1472.         else if (LineDefs[ n].tag > 0)
  1473.             SetColor( LIGHTRED);
  1474.         else if (LineDefs[ n].flags & 1)
  1475.             SetColor(LIGHTGRAY);
  1476.         else if (LineDefs[ n].flags & 2)
  1477.             SetColor(DARKGREEN);
  1478.         else if (LineDefs[ n].flags & 32)
  1479.             SetColor(DARKMAGENTA);
  1480.         else if (LineDefs[ n].flags & 64)
  1481.             SetColor(DARKRED);
  1482.         else if (LineDefs[ n].flags & 128)
  1483.             SetColor(ORANGE);
  1484.         else
  1485.         SetColor(DARKGRAY);
  1486.         DrawMapLine( Vertexes[ LineDefs[ n].start].x, Vertexes[ LineDefs[ n].start].y,
  1487.             Vertexes[ LineDefs[ n].end].x, Vertexes[ LineDefs[ n].end].y);
  1488.     }
  1489.     break;
  1490.     case OBJ_SECTORS:
  1491.     ObjectsNeeded( OBJ_LINEDEFS, OBJ_SIDEDEFS, 0);
  1492.     for (n = 0; n < NumLineDefs; n++) {
  1493.         if ((m = LineDefs[ n].sidedef1) < 0 || (m = SideDefs[ m].sector) < 0)
  1494.         SetColor( LIGHTRED);
  1495.         else {
  1496.         /*AJB*/
  1497.         if (Sectors[ m].tag > 0)
  1498.             SetColor( LIGHTGREEN);
  1499.         else if (Sectors[ m].special > 0)
  1500.             SetColor( LIGHTCYAN);
  1501.         else if (LineDefs[ n].flags & 1)
  1502.             SetColor(LIGHTGRAY);
  1503.         else if (LineDefs[ n].flags & 2)
  1504.             SetColor(DARKGREEN);
  1505.         else if (LineDefs[ n].flags & 32)
  1506.             SetColor(DARKMAGENTA);
  1507.         else if (LineDefs[ n].flags & 64)
  1508.             SetColor(DARKRED);
  1509.         else if (LineDefs[ n].flags & 128)
  1510.             SetColor(ORANGE);
  1511.         else
  1512.             SetColor(DARKGRAY);
  1513.         if ((m = LineDefs[ n].sidedef2) >= 0) {
  1514.             if ((m = SideDefs[ m].sector) < 0)
  1515.             SetColor( LIGHTRED);
  1516.             else if (Sectors[ m].tag > 0)
  1517.             SetColor( LIGHTGREEN);
  1518.             else if (Sectors[ m].special > 0)
  1519.             SetColor( LIGHTCYAN);
  1520.         }
  1521.         }
  1522.         ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1523.         DrawMapLine( Vertexes[ LineDefs[ n].start].x, Vertexes[ LineDefs[ n].start].y,
  1524.             Vertexes[ LineDefs[ n].end].x, Vertexes[ LineDefs[ n].end].y);
  1525.     }
  1526.     break;
  1527.     }
  1528.     
  1529.     /* draw in the vertices */
  1530.     if (editmode == OBJ_VERTEXES) {
  1531.     SetColor( LIGHTGREEN);
  1532.     for (n = 0; n < NumVertexes; n++) {
  1533.         DrawMapLine( Vertexes[ n].x - ( OBJSIZE / 4 ), Vertexes[ n].y - ( OBJSIZE / 4 ), Vertexes[ n].x + ( OBJSIZE / 4 ), Vertexes[ n].y - ( OBJSIZE / 4 ));
  1534.         DrawMapLine( Vertexes[ n].x + ( OBJSIZE / 4 ), Vertexes[ n].y - ( OBJSIZE / 4 ), Vertexes[ n].x + ( OBJSIZE / 4 ), Vertexes[ n].y + ( OBJSIZE / 4 ));
  1535.         DrawMapLine( Vertexes[ n].x - ( OBJSIZE / 4 ), Vertexes[ n].y - ( OBJSIZE / 4 ), Vertexes[ n].x - ( OBJSIZE / 4 ), Vertexes[ n].y + ( OBJSIZE / 4 ));
  1536.         DrawMapLine( Vertexes[ n].x - ( OBJSIZE / 4 ), Vertexes[ n].y + ( OBJSIZE / 4 ), Vertexes[ n].x + ( OBJSIZE / 4 ), Vertexes[ n].y + ( OBJSIZE / 4 ));
  1537.     }
  1538.     }
  1539.     
  1540.     /* draw in the things */
  1541.     ObjectsNeeded( OBJ_THINGS, 0);
  1542.     if (editmode == OBJ_THINGS) {
  1543.         for (n = 0; n < NumThings; n++) {
  1544.             m = GetThingRadius(Things[n].type);
  1545.             SetColor( GetThingColour(Things[n].type));
  1546.             if (ThingAngle == FALSE) {
  1547.                 DrawMapLine( Things[n].xpos - m , Things[n].ypos, Things[n].xpos + m, Things[n].ypos);
  1548.                 DrawMapLine( Things[n].xpos, Things[n].ypos - m, Things[n].xpos, Things[n].ypos + m);
  1549.             }
  1550.             if (ThingAngle == TRUE) {
  1551.                 if (Things[n].angle == 0) 
  1552.                     DrawMapVector(Things[n].xpos - m, Things[n].ypos, Things[n].xpos + m, Things[n].ypos);
  1553.                 if (Things[n].angle == 180) 
  1554.                     DrawMapVector(Things[n].xpos + m, Things[n].ypos, Things[n].xpos - m, Things[n].ypos);
  1555.                 if (Things[n].angle == 90) 
  1556.                     DrawMapVector(Things[n].xpos, Things[n].ypos - m, Things[n].xpos, Things[n].ypos + m);
  1557.                 if (Things[n].angle == 270) 
  1558.                     DrawMapVector(Things[n].xpos, Things[n].ypos + m, Things[n].xpos, Things[n].ypos - m);
  1559.                 if (Things[n].angle == 45) 
  1560.                     DrawMapVector(Things[n].xpos - m / 1.4, Things[n].ypos - m / 1.4, Things[n].xpos + m / 1.4, Things[n].ypos + m / 1.4);
  1561.                 if (Things[n].angle == 315) 
  1562.                     DrawMapVector(Things[n].xpos - m / 1.4, Things[n].ypos + m / 1.4, Things[n].xpos + m / 1.4, Things[n].ypos - m / 1.4);
  1563.                 if (Things[n].angle == 225) 
  1564.                     DrawMapVector(Things[n].xpos + m / 1.4, Things[n].ypos + m / 1.4, Things[n].xpos - m / 1.4, Things[n].ypos - m / 1.4);
  1565.                 if (Things[n].angle == 135) 
  1566.                     DrawMapVector(Things[n].xpos + m / 1.4, Things[n].ypos - m / 1.4, Things[n].xpos - m / 1.4, Things[n].ypos + m / 1.4);
  1567.                 }
  1568.             DrawMapCircle( Things[ n].xpos, Things[ n].ypos, m);
  1569.         }
  1570.     }
  1571.     else {
  1572.     SetColor(DARKGRAY);
  1573.     for (n = 0; n < NumThings; n++) {
  1574.         DrawMapLine( Things[ n].xpos - ( OBJSIZE * 2 ), Things[ n].ypos, Things[ n].xpos + ( OBJSIZE * 2 ), Things[ n].ypos);
  1575.         DrawMapLine( Things[ n].xpos, Things[ n].ypos - ( OBJSIZE * 2 ), Things[ n].xpos, Things[ n].ypos + ( OBJSIZE * 2 ));
  1576.     }
  1577.     }
  1578.     
  1579.     /* draw in the title bar */
  1580.     DrawScreenBox3D( 0, 0, ScrMaxX, 16);
  1581.     SetColor( WHITE);
  1582.     DrawScreenText( 20,  4, "File  Edit  Search  Modes  Misc  Objects  Check");
  1583.     DrawScreenText( 20,  6, "_     _     _       _       _    _        _    ");
  1584.     DrawScreenText( ScrMaxX - 45, 4, "Help");
  1585.     DrawScreenText( ScrMaxX - 45, 6, "_   ");
  1586.     
  1587.     /* draw the bottom line, if needed */
  1588.     if (InfoShown) {
  1589.     DrawScreenBox3D( 0, ScrMaxY - 12, ScrMaxX, ScrMaxY);
  1590.     if (MadeMapChanges == TRUE)
  1591.         DrawScreenText( 5, ScrMaxY - 9, "Editing %s on %s #", GetEditModeName( editmode), Level->dir.name);
  1592.     else if (MadeChanges == TRUE)
  1593.         DrawScreenText( 5, ScrMaxY - 9, "Editing %s on %s *", GetEditModeName( editmode), Level->dir.name);
  1594.     else
  1595.         DrawScreenText( 5, ScrMaxY - 9, "Editing %s on %s", GetEditModeName( editmode), Level->dir.name);
  1596.     if (Scale < 1.0)
  1597.         DrawScreenText( ScrMaxX - 176, ScrMaxY - 9, "Scale: 1/%d  Grid: %d", (BCINT) (1.0 / Scale + 0.5), grid);
  1598.     else
  1599.         DrawScreenText( ScrMaxX - 176, ScrMaxY - 9, "Scale: %d/1  Grid: %d", (BCINT) Scale, grid);
  1600.     if (farcoreleft() < 50000L) {
  1601.         if (farcoreleft() < 20000L)
  1602.         SetColor( LIGHTRED);
  1603.         else
  1604.         SetColor( RED);
  1605.     }
  1606.     DrawScreenText( ScrCenterX - ((editmode == OBJ_LINEDEFS) ? 10 : 50), ScrMaxY - 9, "Free mem: %lu", farcoreleft());
  1607.     }
  1608. }
  1609.  
  1610.  
  1611.  
  1612. /*
  1613.    center the map around the given coords
  1614.    */
  1615.  
  1616. void CenterMapAroundCoords( BCINT xpos, BCINT ypos)
  1617. {
  1618.     OrigX = xpos;
  1619.     OrigY = ypos;
  1620.     PointerX = ScrCenterX;
  1621.     PointerY = ScrCenterY;
  1622. }
  1623.  
  1624.  
  1625.  
  1626. /*
  1627.    center the map around the object and zoom in if necessary
  1628.    */
  1629.  
  1630. void GoToObject( BCINT objtype, BCINT objnum) /* SWAP! */
  1631. {
  1632.     BCINT xpos, ypos;
  1633.     BCINT xpos2, ypos2;
  1634.     BCINT n;
  1635.     BCINT sd1, sd2;
  1636.     float oldscale;
  1637.     
  1638.     GetObjectCoords( objtype, objnum, &xpos, &ypos);
  1639.     CenterMapAroundCoords( xpos, ypos);
  1640.     oldscale = Scale;
  1641.     
  1642.     /* zoom in until the object can be selected */
  1643.     while (Scale < 4.0 && GetCurObject( objtype, MAPX( PointerX - 4), MAPY( PointerY - 4), MAPX( PointerX + 4), MAPY( PointerY + 4)) != objnum) {
  1644.     if (Scale < 1.0)
  1645.         Scale = 1.0 / ((1.0 / Scale) - 1.0);
  1646.     else
  1647.         Scale = Scale * 2.0;
  1648.     }
  1649.     /* Special case for Sectors: if several Sectors are one inside another, then     */
  1650.     /* zooming in on the center won't help.  So I choose a LineDef that borders the  */
  1651.     /* the Sector and move a few pixels towards the inside of the Sector.            */
  1652.     if (objtype == OBJ_SECTORS && GetCurObject( OBJ_SECTORS, OrigX, OrigY, OrigX, OrigY) != objnum) {
  1653.     /* restore the Scale */
  1654.     Scale = oldscale;
  1655.     for (n = 0; n < NumLineDefs; n++) {
  1656.         ObjectsNeeded( OBJ_LINEDEFS, 0);
  1657.         sd1 = LineDefs[ n].sidedef1;
  1658.         sd2 = LineDefs[ n].sidedef2;
  1659.         ObjectsNeeded( OBJ_SIDEDEFS, 0);
  1660.         if (sd1 >= 0 && SideDefs[ sd1].sector == objnum)
  1661.         break;
  1662.         if (sd2 >= 0 && SideDefs[ sd2].sector == objnum)
  1663.         break;
  1664.     }
  1665.     if (n < NumLineDefs) {
  1666.         GetObjectCoords( OBJ_LINEDEFS, n, &xpos2, &ypos2);
  1667.         n = ComputeDist( abs( xpos - xpos2), abs( ypos - ypos2)) / 7;
  1668.         if (n <= 1)
  1669.         n = 2;
  1670.         xpos = xpos2 + (xpos - xpos2) / n;
  1671.         ypos = ypos2 + (ypos - ypos2) / n;
  1672.         CenterMapAroundCoords( xpos, ypos);
  1673.         /* zoom in until the sector can be selected */
  1674.         while (Scale > 4.0 && GetCurObject( OBJ_SECTORS, OrigX, OrigY, OrigX, OrigY) != objnum) {
  1675.         if (Scale < 1.0)
  1676.             Scale = 1.0 / ((1.0 / Scale) - 1.0);
  1677.         else
  1678.             Scale = Scale / 2.0;
  1679.         }
  1680.     }
  1681.     }
  1682.     if (UseMouse)
  1683.     SetMouseCoords( PointerX, PointerY);
  1684. }
  1685.  
  1686.  
  1687.  
  1688. /* end of file */
  1689.