home *** CD-ROM | disk | FTP | other *** search
/ Quake++ for Quake / Quake++.iso / quake / edquake / code / mapedit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-12  |  46.2 KB  |  1,603 lines

  1. /*EdQuake v0.50 source code
  2.   (c) Copyright 1996 Scott Mitting
  3.   email:smitting@netusa1.net
  4.   ----------------------------------
  5.   MAPEDIT.C  -  The heart of EdQuake
  6.         These functions do not work
  7.         they are under developement
  8.  
  9.   __variables:
  10.   __functions:
  11.   ----------------------------------
  12.   the entire source code is under renovation to make it easier
  13.   to understand.  happy coding.
  14. */
  15. #include <math.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <alloc.h>
  19. #include "svgacc.h"
  20. #include "grfx.h"
  21. #include "pak.h"
  22. #include "disk.h"
  23. #include "mapedit.h"
  24. #include "input.h"
  25. #include "ripper.h"
  26. #include "viewer.h"
  27. #include "wadmap.h"
  28. #include "bsp.h"
  29.  
  30. extern void setquakecolors();
  31. extern MouseCursor mymousecursor;
  32.  
  33. /*mapvertex_t mapvertex[2000];
  34.   mapline_t mapline[1000];
  35.   maproom_t maproom[300];*/
  36. mapvertex_t far *mapvertex;
  37.   mapline_t far *mapline;
  38.   maproom_t far *maproom;
  39.  
  40. int needsave = 0;
  41. int showgrid = 1;
  42.  
  43. int numvertex=0;
  44. int numlines=0;
  45. int numrooms=0;
  46.  
  47. int curvertex=1;
  48. int curline=1;
  49. int curroom=1;
  50.  
  51. int curmode = 0; //0=rooms 1=line 2=vertex
  52. long mapx=0, mapy=0;
  53. float zoom;
  54. //defaults
  55. char mapname[54] = "Untitled map";
  56.  
  57. void notdone()
  58. {
  59.    query("Not implemented");
  60. }
  61.  
  62. //this is DA-SHIT here!!!
  63. void savemap(char *filename)
  64. {
  65.  
  66.  
  67. }
  68.  
  69. void saveeqm(char *filename)
  70. {
  71.     FILE *f;
  72.     char magic[10];
  73.     int t;
  74.     int version; //0 = no things
  75.     f = fopen(filename, "wb");
  76.     if (!f) return;
  77.     fwrite("EdQuakeMap",10,1,f);
  78. //    if (magic != "EdQuakeMap") return;
  79.     fwrite(&version,2,1,f);
  80.     fwrite(mapname,52,1,f);
  81.     fwrite(&mapx,4,1,f);
  82.     fwrite(&mapy,4,1,f);
  83.     fwrite(&zoom,4,1,f);
  84.     fwrite(&numvertex,2,1,f);
  85.     for (t = 1; t <= numvertex; t++)
  86.       fwrite(&mapvertex[t],sizeof(mapvertex_t),1,f);
  87.     fwrite(&numlines,2,1,f);
  88.     for (t = 1; t <= numlines; t++)
  89.       fwrite(&mapline[t],sizeof(mapline_t),1,f);
  90.     fwrite(&numrooms,2,1,f);
  91.     for (t = 1; t <= numrooms; t++)
  92.       fwrite(&maproom[t],sizeof(maproom_t),1,f);
  93.     needsave = 0;
  94. }
  95.  
  96.  
  97. void loadeqm(char *filename)
  98. {
  99.     FILE *f;
  100.     char magic[10];
  101.     int t;
  102.     int version; //0 = no things
  103.     f = fopen(filename, "rb");
  104.     if (!f) return;
  105.     fread(magic,10,1,f);
  106. //    if (magic != "EdQuakeMap") return;
  107.     fread(&version,2,1,f);
  108.     fread(mapname,52,1,f);
  109.     fread(&mapx,4,1,f);
  110.     fread(&mapy,4,1,f);
  111.     fread(&zoom,4,1,f);
  112.     fread(&numvertex,2,1,f);
  113.     for (t = 1; t <= numvertex; t++)
  114.       fread(&mapvertex[t],sizeof(mapvertex_t),1,f);
  115.     fread(&numlines,2,1,f);
  116.     for (t = 1; t <= numlines; t++)
  117.       fread(&mapline[t],sizeof(mapline_t),1,f);
  118.     fread(&numrooms,2,1,f);
  119.     for (t = 1; t <= numrooms; t++)
  120.       fread(&maproom[t],sizeof(maproom_t),1,f);
  121.     needsave = 0;
  122. }
  123.  
  124.  
  125. void help()
  126. {
  127.    int mx,my,mbuts = 1;
  128.    while (mbuts) mousestatus(&mx,&my,&mbuts);
  129.    if (curmode == 0)
  130.    {
  131.      drwfillbox(SET,BLACK,0,120,640,600);
  132.      drwstring(SET,YELLOW,BLACK,"Help on Rooms:",10,130);
  133.      drwstring(SET,WHITE,BLACK,"Room - An entity made up of a set of walls where the main action takes",10,150);
  134.      drwstring(SET,WHITE,BLACK,"       place.  Can also split up a wall for detail, like using a cube",10,170);
  135.      drwstring(SET,WHITE,BLACK,"       for a railing on a bridge.",10,190);
  136.      drwstring(SET,YELLOW,BLACK,"Some Basic Usage:",10,210);
  137.      drwstring(SET,WHITE,BLACK,"Left Click and drag a box to create a new room at the default settings.",10,230);
  138.      drwstring(SET,WHITE,BLACK,"Settings are updated by clicking on the number that needs to be changed.",10,250);
  139.      drwstring(SET,WHITE,BLACK,"Rooms are selected by clicking on the arrows next to the room#",10,270);
  140.      drwstring(SET,WHITE,BLACK,"The delete button removels the floor and ceiling of the room and all of",10,290);
  141.      drwstring(SET,WHITE,BLACK,"   the walls that are not being used elsewhere in the level.",10,310);
  142.    }
  143.    if (curmode == 1)
  144.    {
  145.      drwfillbox(SET,BLACK,0,120,640,600);
  146.      drwstring(SET,YELLOW,BLACK,"Help on Walls:",10,130);
  147.      drwstring(SET,WHITE,BLACK,"Wall - A connection between 2 vertices with a texture and slant.",10,150);
  148.      drwstring(SET,WHITE,BLACK,"       The top and bottom values are optional for holes in walls.",10,170);
  149.      drwstring(SET,YELLOW,BLACK,"Some Basic Usage:",10,190);
  150.      drwstring(SET,WHITE,BLACK,"Click near a line or use the arrows near the wall#(less buggy) to",10,210);
  151.      drwstring(SET,WHITE,BLACK,"      select a wall.",10,230);
  152.      drwstring(SET,WHITE,BLACK,"Click on the data to change it.",10,250);
  153.    }
  154.    if (curmode == 2)
  155.    {
  156.      drwfillbox(SET,BLACK,0,120,640,600);
  157.      drwstring(SET,YELLOW,BLACK,"Help on Vertices:",10,130);
  158.      drwstring(SET,WHITE,BLACK,"Vertex - A 2d point by which all other map intities are attached to. ",10,150);
  159.      drwstring(SET,WHITE,BLACK,"         What's that you say?  It's not possible to make 3D levels in",10,170);
  160.      drwstring(SET,WHITE,BLACK,"         a 2d editor? :)",10,190);
  161.      drwstring(SET,YELLOW,BLACK,"Some Basic Usage:",10,210);
  162.      drwstring(SET,WHITE,BLACK,"Left Click and drag to move a vertex",10,230);
  163.      drwstring(SET,WHITE,BLACK,"Right Click selects a vertex",10,230);
  164.      drwstring(SET,WHITE,BLACK,"Delete removes a vertex and forces the walls attached to it to merge.",10,270);
  165.      drwstring(SET,WHITE,BLACK,"    You can't delete a vertex with more than 2 wall attached.",10,290);
  166.      drwstring(SET,WHITE,BLACK,"Click on the coord value if you want to specify an x or y value,",10,310);
  167.    }
  168.    mbuts = 0;
  169.    while (!mbuts) mousestatus(&mx, &my, &mbuts);
  170. }
  171.  
  172. void blankback()
  173. {
  174.    char buf[20];
  175.    int t;
  176.    drwfillbox(SET,BLACK,0,120,655,600);
  177. if (showgrid == 1)
  178. {
  179.    for (t = 0; t < 655; t+=8)
  180.      drwline(SET,BLUE,t,120,t,600);
  181.    for (t = 120; t < 600; t+=8)
  182.      drwline(SET,BLUE,0,t,655,t);
  183. }
  184.    sprintf(buf,"(%05i,",mapx);
  185.    drwstring(SET,WHITE,BLACK,buf,5,125);
  186.    sprintf(buf,"%05i)",mapy);
  187.    drwstring(SET,WHITE,BLACK,buf,60,125);
  188. }
  189.  
  190. void drawvertex()
  191. {
  192.    int t;
  193.    for (t = 1; t <= numvertex; t++)
  194.      if (t==curvertex)
  195.        drwbox(SET,RED, mapvertex[t].x-2+mapx,mapvertex[t].y-2+mapy,mapvertex[t].x+2+mapx,mapvertex[t].y+2+mapy);
  196.      else
  197.        drwbox(SET,YELLOW, mapvertex[t].x-2+mapx,mapvertex[t].y-2+mapy,mapvertex[t].x+2+mapx,mapvertex[t].y+2+mapy);
  198. }
  199.  
  200. void drawroom()
  201. {
  202.    int t;
  203.    for (t = 1; t <= maproom[curroom].numsides; t++)
  204.   drwline(SET,YELLOW,mapvertex[mapline[maproom[curroom].line[t]].v1].x+mapx,
  205.              mapvertex[mapline[maproom[curroom].line[t]].v1].y+mapy,
  206.              mapvertex[mapline[maproom[curroom].line[t]].v2].x+mapx,
  207.              mapvertex[mapline[maproom[curroom].line[t]].v2].y+mapy);
  208. }
  209.  
  210. void eraseroom()
  211. {
  212.    int t;
  213.    for (t = 1; t <= maproom[curroom].numsides; t++)
  214.   drwline(SET,WHITE,mapvertex[mapline[maproom[curroom].line[t]].v1].x+mapx,
  215.              mapvertex[mapline[maproom[curroom].line[t]].v1].y+mapy,
  216.              mapvertex[mapline[maproom[curroom].line[t]].v2].x+mapx,
  217.              mapvertex[mapline[maproom[curroom].line[t]].v2].y+mapy);
  218. }
  219.  
  220. void drawline()
  221. {
  222.   drwline(SET,RED,mapvertex[mapline[curline].v1].x+mapx,
  223.           mapvertex[mapline[curline].v1].y+mapy,
  224.           mapvertex[mapline[curline].v2].x+mapx,
  225.           mapvertex[mapline[curline].v2].y+mapy);
  226. }
  227.  
  228. void eraseline()
  229. {
  230.   if (mapline[curline].visible)
  231.   drwline(SET,WHITE,mapvertex[mapline[curline].v1].x+mapx,
  232.           mapvertex[mapline[curline].v1].y+mapy,
  233.           mapvertex[mapline[curline].v2].x+mapx,
  234.           mapvertex[mapline[curline].v2].y+mapy);
  235.   else
  236.   drwline(SET,BLUE,mapvertex[mapline[curline].v1].x+mapx,
  237.           mapvertex[mapline[curline].v1].y+mapy,
  238.           mapvertex[mapline[curline].v2].x+mapx,
  239.           mapvertex[mapline[curline].v2].y+mapy);
  240.  
  241. }
  242.  
  243. void roomtext()
  244. {
  245.    char buf[20];
  246.    mousehide();
  247.    drwfillbox(SET,BLACK,145,19,170,35);
  248.    impress(145,19,170,35);
  249.    sprintf(buf,"%3i",curroom);
  250.    drwstring(SET,WHITE,BLACK,buf,146,20);
  251.    drwfillbox(SET,BLACK,235,39,269,55);
  252.    impress(235,39,269,55);
  253.    drwfillbox(SET,BLACK,235,59,269,75);
  254.    impress(235,59,269,75);
  255.    drwfillbox(SET,BLACK,340,39,374,55);
  256.    impress(340,39,374,55);
  257.    drwfillbox(SET,BLACK,340,59,374,75);
  258.    impress(340,59,374,75);
  259.    drwfillbox(SET,BLACK,235,79,340,95);
  260.    impress(235,79,340,95);
  261.    drwfillbox(SET,BLACK,345,79,360,95);
  262.    impress(345,79,360,95);
  263.    if (maproom[curroom].fvis)
  264.    {
  265.       drwline(SET,WHITE,345,79,360,95);
  266.       drwline(SET,WHITE,345,95,360,79);
  267.    }
  268.    drwfillbox(SET,BLACK,235,99,340,115);
  269.    impress(235,99,340,115);
  270.    drwfillbox(SET,BLACK,345,99,360,115);
  271.    impress(345,99,360,115);
  272.    if (maproom[curroom].cvis)
  273.    {
  274.       drwline(SET,WHITE,345,99,360,115);
  275.       drwline(SET,WHITE,345,115,360,99);
  276.    }
  277.    sprintf(buf,"%4i",maproom[curroom].floor);
  278.    drwstring(SET,WHITE,BLACK,buf,236,40);
  279.    sprintf(buf,"%4i",maproom[curroom].ceiling);
  280.    drwstring(SET,WHITE,BLACK,buf,236,60);
  281.    sprintf(buf,"%4i",config.dfloor);
  282.    drwstring(SET,WHITE,BLACK,buf,341,40);
  283.    sprintf(buf,"%4i",config.dceil);
  284.    drwstring(SET,WHITE,BLACK,buf,341,60);
  285.    drwstring(SET,WHITE,BLACK,texture[maproom[curroom].ftext].name,236,80);
  286.    drwstring(SET,WHITE,BLACK,texture[maproom[curroom].ctext].name,236,100);
  287.    drawroom();
  288.    mouseshow();
  289. }
  290.  
  291. void drawback()
  292. {
  293.    int t;
  294.    mousehide();
  295.    setview(0,120,655,599);
  296.    blankback();
  297.    drawvertex();
  298.    for (t = 1; t <= numlines; t++)
  299.      if (t == curline)
  300.        drwline(SET,RED, mapvertex[mapline[t].v1].x+mapx,mapvertex[mapline[t].v1].y+mapy,mapvertex[mapline[t].v2].x+mapx,mapvertex[mapline[t].v2].y+mapy);
  301.      else
  302.      if (mapline[t].visible)
  303.        drwline(SET,WHITE, mapvertex[mapline[t].v1].x+mapx,mapvertex[mapline[t].v1].y+mapy,mapvertex[mapline[t].v2].x+mapx,mapvertex[mapline[t].v2].y+mapy);
  304.      else
  305.        drwline(SET,BLUE, mapvertex[mapline[t].v1].x+mapx,mapvertex[mapline[t].v1].y+mapy,mapvertex[mapline[t].v2].x+mapx,mapvertex[mapline[t].v2].y+mapy);
  306.    if (curmode == 0) drawroom();
  307.    mouseshow();
  308.    setview(0,0,799,599);
  309. }
  310.  
  311. void roominfo()
  312. {
  313.    char buf[20];
  314.    mousehide();
  315.    drwfillbox(SET,LTGRAY,105,18,594,117);
  316.    drwstring(SET,BLACK,LTGRAY,"room#",105,20);
  317.    drwfillbox(SET,BLACK,145,19,170,35);
  318.    impress(145,19,170,35);
  319.    sprintf(buf,"%3i",curroom);
  320.    drwstring(SET,WHITE,BLACK,buf,146,20);
  321.    scrollbutton(172,21,"");
  322.    scrollbutton(184,21,"");
  323.    drwstring(SET,BLACK,LTGRAY,"   floor height:",105,40);
  324.    drwfillbox(SET,BLACK,235,39,269,55);
  325.    impress(235,39,269,55);
  326.    drwstring(SET,BLACK,LTGRAY," ceiling height:",105,60);
  327.    drwfillbox(SET,BLACK,235,59,269,75);
  328.    impress(235,59,269,75);
  329.    drwstring(SET,BLACK,LTGRAY,"default:",275,40);
  330.    drwfillbox(SET,BLACK,340,39,374,55);
  331.    impress(340,39,374,55);
  332.    drwstring(SET,BLACK,LTGRAY,"default:",275,60);
  333.    drwfillbox(SET,BLACK,340,59,374,75);
  334.    impress(340,59,374,75);
  335.    drwstring(SET,BLACK,LTGRAY,"  floor texture:",105,80);
  336.    drwfillbox(SET,BLACK,235,79,340,95);
  337.    impress(235,79,340,95);
  338.    drwfillbox(SET,BLACK,345,79,360,95);
  339.    impress(345,79,360,95);
  340.    if (maproom[curroom].fvis)
  341.    {
  342.       drwline(SET,WHITE,345,79,360,95);
  343.       drwline(SET,WHITE,345,95,360,79);
  344.    }
  345.    drwstring(SET,BLACK,LTGRAY,"ceiling texture:",105,100);
  346.    drwfillbox(SET,BLACK,235,99,340,115);
  347.    impress(235,99,340,115);
  348.    drwfillbox(SET,BLACK,345,99,360,115);
  349.    impress(345,99,360,115);
  350.    if (maproom[curroom].fvis)
  351.    {
  352.       drwline(SET,WHITE,345,99,360,115);
  353.       drwline(SET,WHITE,345,115,360,99);
  354.    }
  355.    drwstring(SET,BLACK,LTGRAY,"visible",365,80);
  356.    drwstring(SET,BLACK,LTGRAY,"visible",365,100);
  357.    button(520,20,585,35," Delete");
  358.    button(520,40,585,55," Brush");
  359.    button(520,100,585,115,"  Help");
  360.  
  361.    sprintf(buf,"%4i",maproom[curroom].floor);
  362.    drwstring(SET,WHITE,BLACK,buf,236,40);
  363.    sprintf(buf,"%4i",maproom[curroom].ceiling);
  364.    drwstring(SET,WHITE,BLACK,buf,236,60);
  365.    sprintf(buf,"%4i",config.dfloor);
  366.    drwstring(SET,WHITE,BLACK,buf,341,40);
  367.    sprintf(buf,"%4i",config.dceil);
  368.    drwstring(SET,WHITE,BLACK,buf,341,60);
  369.    drwstring(SET,WHITE,BLACK,texture[maproom[curroom].ftext].name,236,80);
  370.    drwstring(SET,WHITE,BLACK,texture[maproom[curroom].ctext].name,236,100);
  371.    drawroom();
  372.    mouseshow();
  373. }
  374.  
  375. void wallinfo()
  376. {
  377.    char buf[20];
  378.    drwfillbox(SET,LTGRAY,105,18,594,117);
  379.    drwstring(SET,BLACK,LTGRAY,"wall#",105,20);
  380.    drwfillbox(SET,BLACK,145,19,170,35);
  381.    impress(145,19,170,35);
  382.    sprintf(buf,"%3i",curline);
  383.    drwstring(SET,WHITE,BLACK,buf,146,20);
  384.    scrollbutton(172,21,"");
  385.    scrollbutton(184,21,"");
  386.    drwstring(SET,BLACK,LTGRAY,"    hole bottom:",105,40);
  387.    drwfillbox(SET,BLACK,235,39,269,55);
  388.    impress(235,39,269,55);
  389.    drwstring(SET,BLACK,LTGRAY,"       hole top:",105,60);
  390.    drwfillbox(SET,BLACK,235,59,269,75);
  391.    impress(235,59,269,75);
  392.    drwstring(SET,BLACK,LTGRAY,"default:",275,40);
  393.    drwfillbox(SET,BLACK,340,39,374,55);
  394.    impress(340,39,374,55);
  395.    drwstring(SET,BLACK,LTGRAY,"default:",275,60);
  396.    drwfillbox(SET,BLACK,340,59,374,75);
  397.    impress(340,59,374,75);
  398.    drwstring(SET,BLACK,LTGRAY,"   wall texture:",105,100);
  399.    drwfillbox(SET,BLACK,235,99,340,115);
  400.    impress(235,99,340,115);
  401.    drwfillbox(SET,BLACK,345,99,360,115);
  402.    impress(345,99,360,115);
  403.    if (mapline[curline].visible)
  404.    {
  405.       drwline(SET,WHITE,345,99,360,115);
  406.       drwline(SET,WHITE,345,115,360,99);
  407.    }
  408.    drwstring(SET,BLACK,LTGRAY,"   hole enabled:",105,80);
  409.    drwfillbox(SET,BLACK,235,79,250,95);
  410.    impress(235,79,250,95);
  411.    if (mapline[curline].hole)
  412.    {
  413.       drwline(SET,WHITE,235,79,250,95);
  414.       drwline(SET,WHITE,235,95,250,79);
  415.    }
  416.    drwstring(SET,BLACK,LTGRAY,"visible",365,100);
  417.    button(520,20,585,35," Split");
  418.    button(520,100,585,115,"  Help");
  419.  
  420.    sprintf(buf,"%4i",mapline[curline].bottom);
  421.    drwstring(SET,WHITE,BLACK,buf,236,40);
  422.    sprintf(buf,"%4i",mapline[curline].top);
  423.    drwstring(SET,WHITE,BLACK,buf,236,60);
  424.    sprintf(buf,"%4i",config.dbottom);
  425.    drwstring(SET,WHITE,BLACK,buf,341,40);
  426.    sprintf(buf,"%4i",config.dtop);
  427.    drwstring(SET,WHITE,BLACK,buf,341,60);
  428.    drwstring(SET,WHITE,BLACK,texture[mapline[curline].texture].name,236,100);
  429.    drawline();
  430. }
  431.  
  432. void vertextext()//faster redraw
  433. {
  434.    char buf[20];
  435.    drwfillbox(SET,BLACK,165,19,190,35);
  436.    impress(165,19,190,35);
  437.    sprintf(buf,"%3i",curvertex);
  438.    drwstring(SET,WHITE,BLACK,buf,166,20);
  439.    drwfillbox(SET,BLACK,235,39,269,55);
  440.    impress(235,39,269,55);
  441.    drwfillbox(SET,BLACK,235,59,269,75);
  442.    impress(235,59,269,75);
  443.    sprintf(buf,"%4i",mapvertex[curvertex].x);
  444.    drwstring(SET,WHITE,BLACK,buf,236,40);
  445.    sprintf(buf,"%4i",mapvertex[curvertex].y);
  446.    drwstring(SET,WHITE,BLACK,buf,236,60);
  447. }
  448.  
  449.  
  450. void vertexinfo()
  451. {
  452.    char buf[20];
  453.    drwfillbox(SET,LTGRAY,105,18,594,117);
  454.    drwstring(SET,BLACK,LTGRAY,"vertex#",105,20);
  455.    drwfillbox(SET,BLACK,165,19,190,35);
  456.    impress(165,19,190,35);
  457.    sprintf(buf,"%3i",curvertex);
  458.    drwstring(SET,WHITE,BLACK,buf,166,20);
  459.    scrollbutton(192,21,"");
  460.    scrollbutton(204,21,"");
  461.    drwstring(SET,BLACK,LTGRAY,"       X coord:",105,40);
  462.    drwfillbox(SET,BLACK,235,39,269,55);
  463.    impress(235,39,269,55);
  464.    drwstring(SET,BLACK,LTGRAY,"       Y coord:",105,60);
  465.    drwfillbox(SET,BLACK,235,59,269,75);
  466.    impress(235,59,269,75);
  467.    button(520,20,585,35," Delete");
  468.    button(520,100,585,115,"  Help");
  469.  
  470.    sprintf(buf,"%4i",mapvertex[curvertex].x);
  471.    drwstring(SET,WHITE,BLACK,buf,236,40);
  472.    sprintf(buf,"%4i",mapvertex[curvertex].y);
  473.    drwstring(SET,WHITE,BLACK,buf,236,60);
  474. }
  475.  
  476. void objectinfo()
  477. {
  478.    drwfillbox(SET,LTGRAY,105,18,594,117);
  479.    drwstring(SET,BLACK,LTGRAY,"not implemented",105,20);
  480. }
  481.  
  482. void setcircles()
  483. {
  484.    int t;
  485.    mousehide();
  486.    for (t = 0; t < 4; t ++)
  487.      if (t == curmode) drwfillcircle(SET,BLACK,15,27+(t*20),2);
  488.           else drwfillcircle(SET,LTGRAY,15,27+(t*20),2);
  489.    mouseshow();
  490. }
  491.  
  492.  
  493. void setmapscreen()
  494. {
  495.    int k;
  496.    drwfillbox(SET,LTGRAY,0,0,800,600);
  497.    drawback();
  498.    impress(-1,119,655,601);//around map
  499.    impress(671,119,801,248);//around texture
  500.    impress(677,255,792,270);//around textbox
  501.    drwline(SET,WHITE,100,20,100,115);
  502.    drwline(SET,BLACK,101,20,101,115);
  503.    drwline(SET,WHITE,595,20,595,115);
  504.    drwline(SET,BLACK,596,20,596,115);
  505.    drwfillbox(SET,BLUE,0,0,800,15);
  506.    drwstring(SET,WHITE,BLUE,"EdQuake v0.49.00    (c) copyright 1996 CircleA Entertainment  ",25,1);
  507.    drwfillbox(SET,BLACK,678,256,791,269);
  508.    drwfillbox(SET,BLACK,672,120,800,247);
  509.    drwline(SET,WHITE,657,276,797,276);
  510.    drwline(SET,BLACK,657,275,797,275);
  511.    drwline(SET,WHITE,657,380,797,380);
  512.    drwline(SET,BLACK,657,379,797,379);
  513.    //draws buttons, but doesn't make them function
  514.    //(for redraws of screen)
  515.    button(680,390,700,410,"");
  516.    button(680,411,700,431,"");
  517.    button(659,400,679,420,"");
  518.    button(702,400,722,420,"");
  519.    drwstring(SET,BLACK,LTGRAY,"",686,393);
  520.    drwstring(SET,BLACK,LTGRAY,"",686,413);
  521.    k = 17; drwstring(SET,BLACK,LTGRAY,&k,665,404);
  522.    k = 16; drwstring(SET,BLACK,LTGRAY,&k,709,404);
  523.    scrollbutton(657,246,"");
  524.    scrollbutton(657,260,"");
  525.    button(670,280,785,295,"Console Editor");
  526.    button(670,300,785,315,"    Ripper");
  527.    button(670,320,785,335,"  Wave Editor");
  528.    button(670,340,785,355,"   LMP Viewer");
  529.    button(670,360,785,375,"     Quit");
  530.    button(670,460,785,475,"     About");
  531.    button(670,480,785,495,"  Clear Level ");
  532.    button(670,500,785,515,"  Load Level");
  533.    button(670,520,785,535,"  Save Level");
  534.    button(670,540,785,555,"  .MAP Import");
  535.    button(670,560,785,575,"  .MAP Export");
  536.    button(670,580,785,595,"   Process");
  537.    drwstring(SET,BLACK,LTGRAY,"Room",25,21);
  538.    drwcircle(SET,BLACK,15,27,4);
  539.    drwcircle(SET,WHITE,15,27,5);
  540.    drwstring(SET,BLACK,LTGRAY,"Wall",25,41);
  541.    drwcircle(SET,BLACK,15,47,4);
  542.    drwcircle(SET,WHITE,15,47,5);
  543.    drwstring(SET,BLACK,LTGRAY,"Vertex",25,61);
  544.    drwcircle(SET,BLACK,15,67,4);
  545.    drwcircle(SET,WHITE,15,67,5);
  546.    drwstring(SET,BLACK,LTGRAY,"Object",25,81);
  547.    drwcircle(SET,BLACK,15,87,4);
  548.    drwcircle(SET,WHITE,15,87,5);
  549.    drwfillcircle(SET,BLACK,15,27,2);
  550.    drwstring(SET,RED,LTGRAY,"Default Textures",650,18);
  551.    drwstring(SET,BLACK,LTGRAY,"   Wall:",605,35);
  552.    drwstring(SET,BLACK,LTGRAY,"  Floor:",605,55);
  553.    drwstring(SET,BLACK,LTGRAY,"Ceiling:",605,75);
  554.    drwfillbox(SET,BLACK,670,34,795,50);
  555.    impress(670,34,795,50);
  556.    drwstring(SET,WHITE,BLACK,texture[config.dwalltext].name,675,35);
  557.    drwfillbox(SET,BLACK,670,54,795,70);
  558.    impress(670,54,795,70);
  559.    drwstring(SET,WHITE,BLACK,texture[config.dfloortext].name,675,55);
  560.    drwfillbox(SET,BLACK,670,74,795,90);
  561.    impress(670,74,795,90);
  562.    drwstring(SET,WHITE,BLACK,texture[config.dceiltext].name,675,75);
  563.    drwfillbox(SET,BLACK,735,389,750,405);
  564.    impress(735,389,750,405);
  565.    if (showgrid == 1)
  566.    {
  567.       drwline(SET,WHITE,735,389,750,405);
  568.       drwline(SET,WHITE,735,405,750,389);
  569.    }
  570.    drwstring(SET,BLACK,LTGRAY,"grid",755,390);
  571.    if (curmode == 0) roominfo();
  572.    if (curmode == 1) wallinfo();
  573.    if (curmode == 2) vertexinfo();
  574.    if (curmode == 3) objectinfo();
  575.    setcircles();
  576.  
  577. }
  578.  
  579. long calcdist(long x0, long y0, long x1, long y1)
  580. { // I know, not a real distance, but works for our purposes and faster
  581.    return abs(x1-x0)+abs(y1-y0);
  582. }
  583.  
  584. void getvertex(long x, long y)
  585. {
  586.    long smalldist = 100000;
  587.    long cur;
  588.    int t;
  589.    for (t = 1; t <= numvertex; t++)
  590.    {
  591.       cur = calcdist(x-mapx,y-mapy,mapvertex[t].x,mapvertex[t].y);
  592.       if (cur < smalldist)
  593.       {
  594.      smalldist = cur;
  595.      curvertex = t;
  596.       }
  597.    }
  598. }
  599.  
  600. void getline(long x, long y)
  601. {//finds closest vertex and then determines closest line
  602.    long smalldist = 100000;
  603.    long cur;
  604.    long small;
  605.    int t;
  606.    for (t = 1; t <= numvertex; t++)
  607.    {
  608.       cur = calcdist(x-mapx,y-mapy,mapvertex[t].x,mapvertex[t].y);
  609.       if (cur < smalldist)
  610.       {
  611.      smalldist = cur;
  612.      small = t;
  613.       }
  614.    }
  615.    //check all lines for that vertex, find closest line
  616.    smalldist = 100000;
  617.    for (t = 1; t <= numlines; t++)
  618.    {
  619.       if (mapline[t].v1 == small)
  620.       {
  621.      cur = calcdist(x,y,mapvertex[mapline[t].v2].x,mapvertex[mapline[t].v2].y);
  622.      if (cur < smalldist)
  623.      {
  624.         smalldist = cur;
  625.         curline = t;
  626.      }
  627.       }
  628.       if (mapline[t].v2 == small)
  629.       {
  630.      cur = calcdist(x,y,mapvertex[mapline[t].v1].x,mapvertex[mapline[t].v1].y);
  631.      if (cur < smalldist)
  632.      {
  633.         smalldist = cur;
  634.         curline = t;
  635.      }
  636.       }
  637.    }
  638. }
  639.  
  640. void removevertex(int x)
  641. {
  642.    int t;
  643.    numvertex--;
  644.    for (t = x; t <= numvertex; t++)  //remove vertex
  645.       mapvertex[t] = mapvertex[t+1];
  646.    for (t = 1; t <= numlines; t++)   //remap line-vertex pointers
  647.    {
  648.       if (mapline[t].v1 > x) mapline[t].v1--;
  649.       if (mapline[t].v2 > x) mapline[t].v2--;
  650.    }
  651. }
  652.  
  653. //eliminated unneeded vertices
  654. void unchainedvertex()
  655. {
  656.    int t, t2, found;
  657.      for (t = 1; t <= numvertex; t++)
  658.      {
  659.        found = 0;
  660.        for (t2 = 1; t2 <= numlines; t2++)
  661.        {
  662.      if (mapline[t2].v1==t) {found = 1; t2 = numlines + 1;}
  663.      if (mapline[t2].v2==t) {found = 1; t2 = numlines + 1;}
  664.        }
  665.        if (!found) //remove vertex;
  666.        {
  667.      removevertex(t);
  668.      t--;
  669.        }
  670.      }
  671.   if (curvertex > numvertex) curvertex=numvertex;
  672.   vertexinfo();
  673. }
  674.  
  675. void cleanvertex()
  676. {
  677.    int t;
  678.    int merge = 0;
  679.    //check for vertices within 5
  680.    for (t = 1; t <= numvertex; t++)
  681.       if((abs(mapvertex[curvertex].x-mapvertex[t].x) < 5) && (abs(mapvertex[curvertex].y-mapvertex[t].y) < 5) && (t != curvertex)) merge = t;
  682.    if (merge == 0) return;
  683.    if (!query("Merge vertices?")) return;
  684.    for (t = 1; t <= numlines; t++)
  685.    {
  686.       if (mapline[t].v1 == curvertex) mapline[t].v1 = merge;
  687.       if (mapline[t].v2 == curvertex) mapline[t].v2 = merge;
  688.    }
  689.    unchainedvertex();
  690.    needsave = 1;
  691. }
  692.  
  693. void movevertex(int x, int y)
  694. {
  695.    int lineptr[100];  //limited to 100 lines per vertex;
  696.    int numptr = 0;
  697.    int mx, my, mbuts = 1;
  698.    int t;
  699.    getvertex(x, y);
  700.    mousehide();
  701.    mapvertex[curvertex].x -= mapx;
  702.    mapvertex[curvertex].y -= mapy;
  703.    while (mbuts)
  704.    {
  705.        mousestatus(&mx,&my,&mbuts);
  706.        drwbox(SET,BLACK, mapvertex[curvertex].x-2,mapvertex[curvertex].y-2,mapvertex[curvertex].x+2,mapvertex[curvertex].y+2);
  707.        mapvertex[curvertex].x = mx;
  708.        mapvertex[curvertex].y = my;
  709.        drwbox(SET,RED, mapvertex[curvertex].x-2,mapvertex[curvertex].y-2,mapvertex[curvertex].x+2,mapvertex[curvertex].y+2);
  710.    }
  711.        mapvertex[curvertex].x -= mapx;
  712.        mapvertex[curvertex].y -= mapy;
  713.    mbuts = 1;
  714.    while (mbuts) mousestatus(&mx,&my,&mbuts);
  715.    cleanvertex();
  716.    mouseshow();
  717.    needsave = 1;
  718. }
  719.  
  720. void screenshot()
  721. {
  722.    pcxmake(0,0,799,599,"screen.pcx");
  723. }
  724.  
  725. void splitline()
  726. {
  727.    int t, t2;
  728.    numvertex++;
  729.    mapvertex[numvertex].x = (mapvertex[mapline[curline].v1].x + mapvertex[mapline[curline].v2].x)/2;
  730.    mapvertex[numvertex].y = (mapvertex[mapline[curline].v1].y + mapvertex[mapline[curline].v2].y)/2;
  731.    numlines++;
  732.    mapline[numlines].v1 = numvertex;
  733.    mapline[numlines].v2 = mapline[curline].v2;
  734.    mapline[curline].v2 = numvertex;
  735.    mapline[numlines].visible = mapline[curline].visible;
  736.    mapline[numlines].texture = mapline[curline].texture;
  737.    mapline[numlines].top = mapline[curline].top;
  738.    mapline[numlines].bottom = mapline[curline].bottom;
  739.    mapline[numlines].hole = mapline[curline].hole;
  740.    for (t = 1; t <= numrooms; t++)
  741.       for (t2 = 1; t2 <= maproom[t].numsides; t2++)
  742.     if (maproom[t].line[t2] == curline)
  743.     {
  744.        maproom[t].numsides++;
  745.        maproom[t].line[maproom[t].numsides] = numlines;
  746.     }
  747.    needsave = 1;
  748. }
  749.  
  750. void newroom(int mx, int my)
  751. {
  752.    int mx2, my2, mbuts = 1;
  753.       drwline(SET,YELLOW,mx-5,my+5,mx+5,my-5);
  754.       drwline(SET,YELLOW,mx-5,my-5,mx+5,my+5);
  755.       while (mbuts)
  756.         mousestatus(&mx2,&my2,&mbuts);
  757.       if ((abs(mx2-mx) > 5) && (abs(my2-my) > 5))
  758.       {
  759.           mapvertex[numvertex+1].x=mx-mapx;
  760.           mapvertex[numvertex+1].y=my-mapy;
  761.           mapvertex[numvertex+2].x=mx2-mapx;
  762.           mapvertex[numvertex+2].y=my-mapy;
  763.           mapvertex[numvertex+3].x=mx2-mapx;
  764.           mapvertex[numvertex+3].y=my2-mapy;
  765.           mapvertex[numvertex+4].x=mx-mapx;
  766.           mapvertex[numvertex+4].y=my2-mapy;
  767.           mapline[numlines+1].v1 = numvertex+1;
  768.           mapline[numlines+1].v2 = numvertex+2;
  769.           mapline[numlines+1].visible = 1;
  770.           mapline[numlines+1].texture = config.dwalltext;
  771.           mapline[numlines+1].top = config.dtop;
  772.           mapline[numlines+1].bottom = config.dbottom;
  773.           mapline[numlines+1].hole = 0;
  774.           mapline[numlines+2].v1 = numvertex+2;
  775.           mapline[numlines+2].v2 = numvertex+3;
  776.           mapline[numlines+2].visible = 1;
  777.           mapline[numlines+2].texture = config.dwalltext;
  778.           mapline[numlines+2].top = config.dtop;
  779.           mapline[numlines+2].bottom = config.dbottom;
  780.           mapline[numlines+2].hole = 0;
  781.           mapline[numlines+3].v1 = numvertex+3;
  782.           mapline[numlines+3].v2 = numvertex+4;
  783.           mapline[numlines+3].visible = 1;
  784.           mapline[numlines+3].texture = config.dwalltext;
  785.           mapline[numlines+3].top = config.dtop;
  786.           mapline[numlines+3].bottom = config.dbottom;
  787.           mapline[numlines+3].hole = 0;
  788.           mapline[numlines+4].v1 = numvertex+4;
  789.           mapline[numlines+4].v2 = numvertex+1;
  790.           mapline[numlines+4].visible = 1;
  791.           mapline[numlines+4].texture = config.dwalltext;
  792.           mapline[numlines+4].top = config.dtop;
  793.           mapline[numlines+4].bottom = config.dbottom;
  794.           mapline[numlines+4].hole = 0;
  795.           maproom[numrooms+1].numsides = 4;
  796.           maproom[numrooms+1].line[1] = numlines+1;
  797.           maproom[numrooms+1].line[2] = numlines+2;
  798.           maproom[numrooms+1].line[3] = numlines+3;
  799.           maproom[numrooms+1].line[4] = numlines+4;
  800.           maproom[numrooms+1].ctext = config.dceiltext;
  801.           maproom[numrooms+1].ftext = config.dfloortext;
  802.           maproom[numrooms+1].ceiling = config.dceil;
  803.           maproom[numrooms+1].floor = config.dfloor;
  804.           maproom[numrooms+1].cvis = 1;
  805.           maproom[numrooms+1].fvis = 1;
  806.           numvertex+=4;
  807.           numlines+=4;
  808.           numrooms++;
  809.           curroom = numrooms;
  810.       }
  811.    needsave = 1;
  812. }
  813.  
  814. void mapedit(int e)
  815. {
  816.    button_t up, down, left, right;
  817.    button_t textureup, texturedown;
  818.    button_t gfx, ripperb, wave, quit;
  819.    button_t gotexture, golmp, goedit;
  820.    button_t editroom, editwall, editvert, editthings;
  821.    button_t walldefbut, floordefbut, ceildefbut;
  822.    button_t panel1, panel2;
  823.    button_t helpbut;
  824.    button_t vup, vdown, vxbut, vybut, vselect;
  825.    button_t rup, rdown, rselect;
  826.    button_t fhbut, chbut, fdbut, cdbut, ftbut, fvbut, ctbut, cvbut;
  827.    button_t gridbut, aboutbut, holebut;
  828.    button_t clearbut, loadbut, savebut, importbut, exportbut, processbut;
  829.    int curtexture = 1, k;
  830.    int mbuts, mx, my, mx2, my2;
  831.    char buf[20];
  832.    char *p;
  833.    mapvertex = farmalloc(8 * 1000);
  834.    mapline = farmalloc(24 * 1000);
  835.    maproom = farmalloc(56 * 100);
  836.  
  837.    loadeqm("test.eqm");
  838.    loadbsp(e);
  839.    gettexture();
  840.    setquakecolors();
  841.    res800();
  842.    mouseenter();
  843.    mousecursorset(&mymousecursor);
  844.    loadpcx(0,0,"quakepal.pcx");
  845.    mousehide();
  846.    //buttons
  847.    helpbut = button(520,100,585,115,"  Help");
  848.    up    = button(680,390,700,410,"");
  849.    down  = button(680,411,700,431,"");
  850.    left  = button(659,400,679,420,"");
  851.    right = button(702,400,722,420,"");
  852.    gridbut = clearbutton(735,389,750,405);
  853.    textureup = scrollbutton(657,246,"");
  854.    texturedown = scrollbutton(657,260,"");
  855.    gfx = button(670,280,785,295,"Console Editor");
  856.   ripperb = button(670,300,785,315,"    Ripper");
  857.      wave = button(670,320,785,335,"  Wave Editor");
  858.     golmp = button(670,340,785,355,"   LMP Viewer");
  859.      quit = button(670,360,785,375,"     Quit");
  860.  aboutbut = button(670,460,785,475,"     About");
  861.  clearbut = button(670,480,785,495,"  Clear Level ");
  862.   loadbut = button(670,500,785,515,"  Load Level");
  863.   savebut = button(670,520,785,535,"  Save Level");
  864. importbut = button(670,540,785,555,"  .MAP Import");
  865. exportbut = button(670,560,785,575,"  .MAP Export");
  866. processbut =button(670,580,785,595,"   Process");
  867.  
  868.    gotexture = clearbutton(672,120,800,247);
  869.    goedit = clearbutton(0,120,655,600);
  870.    editroom = clearbutton(0,21,100,40);
  871.    editwall = clearbutton(0,41,100,60);
  872.    editvert = clearbutton(0,61,100,80);
  873.    editthings = clearbutton(0,81,100,100);
  874.    walldefbut = clearbutton(670,34,795,50);
  875.    floordefbut = clearbutton(670,54,795,70);
  876.    ceildefbut = clearbutton(670,74,795,90);
  877.    panel1 = clearbutton(520,20,585,35);
  878.    panel2 = clearbutton(520,40,585,55);
  879.    //vertexbuttons
  880.      vup = scrollbutton(192,21,"");
  881.    vdown = scrollbutton(204,21,"");
  882.    vxbut = clearbutton(235,39,269,55);
  883.    vybut = clearbutton(235,59,269,75);
  884.    vselect = clearbutton(165,19,190,35);
  885.    //wall buttons
  886.    holebut = clearbutton(235,79,250,95);
  887.    //room buttons
  888.    rselect = clearbutton(145,19,170,35);
  889.    rup = scrollbutton(172,21,"");
  890.    rdown = scrollbutton(184,21,"");
  891.    fhbut = clearbutton(235,39,269,55);//floor height
  892.    chbut = clearbutton(235,59,269,75);//ceiling height
  893.    fdbut = clearbutton(340,39,374,55);//floor def
  894.    cdbut = clearbutton(340,59,374,75);//ceiling def
  895.    ftbut = clearbutton(235,79,340,95);//floor texture
  896.    fvbut = clearbutton(345,79,360,95);//floor vis
  897.    ctbut = clearbutton(235,99,340,115);//ceiling texture
  898.    cvbut = clearbutton(345,99,360,115);//ceiling vis
  899.  
  900.    //init texture
  901.    setmapscreen();
  902.    showtexture(curtexture);
  903.    drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  904.    mouseshow();
  905.    while (k != 27)
  906.    {
  907.      scrollbar(657,120,245,curtexture,numtex);
  908.      k = 0;
  909.         while (!kbhit() && !mbuts)
  910.         {
  911.            mousestatus(&mx,&my,&mbuts);
  912.            if (mbuts & 1)//scroll
  913.            {
  914.           if (hitbutton(mx,my,gridbut))
  915.           {
  916.              if (showgrid == 0) showgrid = 1; else showgrid = 0;
  917.              drawback();
  918.              while (mbuts)
  919.                 mousestatus(&mx,&my,&mbuts);
  920.              mbuts = 1;
  921.            mousehide();
  922.            drwfillbox(SET,BLACK,735,389,750,405);
  923.            impress(735,389,750,405);
  924.            if (showgrid == 1)
  925.            {
  926.               drwline(SET,WHITE,735,389,750,405);
  927.               drwline(SET,WHITE,735,405,750,389);
  928.            }
  929.            mouseshow();
  930.           }
  931.           if (hitbutton(mx,my,up))
  932.           {
  933.              mapy+=5;
  934.              drawback();
  935.           }
  936.           if (hitbutton(mx,my,down))
  937.           {
  938.              mapy-=5;
  939.              drawback();
  940.           }
  941.           if (hitbutton(mx,my,right))
  942.           {
  943.              mapx-=5;
  944.              drawback();
  945.           }
  946.           if (hitbutton(mx,my,left))
  947.           {
  948.              mapx+=5;
  949.              drawback();
  950.           }
  951.           if (hitbutton(mx,my,helpbut))
  952.           {
  953.              help();
  954.              drawback();
  955.           }
  956.           if (hitbutton(mx,my,editroom))
  957.           {
  958.              curmode = 0;
  959.              roominfo();
  960.              setcircles();
  961.              while (mbuts)
  962.                 mousestatus(&mx,&my,&mbuts);
  963.              mbuts = 1;
  964.           }
  965.           if (hitbutton(mx,my,editwall))
  966.           {
  967.              curmode = 1;
  968.              wallinfo();
  969.              setcircles();
  970.              while (mbuts)
  971.                 mousestatus(&mx,&my,&mbuts);
  972.              mbuts = 1;
  973.           }
  974.           if (hitbutton(mx,my,editvert))
  975.           {
  976.              curmode = 2;
  977.              vertexinfo();
  978.              setcircles();
  979.              while (mbuts)
  980.                 mousestatus(&mx,&my,&mbuts);
  981.              mbuts = 1;
  982.           }
  983.           if (hitbutton(mx,my,editthings))
  984.           {
  985.              curmode = 3;
  986.              objectinfo();
  987.              setcircles();
  988.              while (mbuts)
  989.                 mousestatus(&mx,&my,&mbuts);
  990.              mbuts = 1;
  991.           }
  992.           if (hitbutton(mx,my,texturedown))
  993.           {
  994.               if (curtexture++ >= numtex) curtexture = numtex - 1;
  995.               mousehide();
  996.               drwfillbox(SET,BLACK,678,256,791,269);
  997.               drwfillbox(SET,BLACK,672,120,800,247);
  998.               showtexture(curtexture);
  999.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1000.               mouseshow();
  1001.              while (mbuts)
  1002.                 mousestatus(&mx,&my,&mbuts);
  1003.              mbuts = 1;
  1004.           }
  1005.           if (hitbutton(mx,my,textureup))
  1006.           {
  1007.               if (curtexture-- < 1) curtexture = 1;
  1008.               mousehide();
  1009.               drwfillbox(SET,BLACK,678,256,791,269);
  1010.               drwfillbox(SET,BLACK,672,120,800,247);
  1011.               showtexture(curtexture);
  1012.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1013.               mouseshow();
  1014.              while (mbuts)
  1015.                 mousestatus(&mx,&my,&mbuts);
  1016.              mbuts = 1;
  1017.           }
  1018.           if (hitbutton(mx,my,quit)) k = 27;
  1019.           if (hitbutton(mx,my,ripperb))
  1020.           {
  1021.               while (ripper() != -1);
  1022.               mousehide();
  1023.               setmapscreen();
  1024.               showtexture(curtexture);
  1025.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1026.               mouseshow();
  1027.              while (mbuts)
  1028.                 mousestatus(&mx,&my,&mbuts);
  1029.              mbuts = 1;
  1030.           }
  1031.           if (hitbutton(mx,my,walldefbut))
  1032.           {
  1033.               config.dwalltext = curtexture;
  1034.               mousehide();
  1035.               drwfillbox(SET,BLACK,670,34,795,50);
  1036.               impress(670,34,795,50);
  1037.               drwstring(SET,WHITE,BLACK,texture[config.dwalltext].name,675,35);
  1038.               mouseshow();
  1039.           }
  1040.           if (hitbutton(mx,my,floordefbut))
  1041.           {
  1042.               config.dfloortext = curtexture;
  1043.               mousehide();
  1044.               drwfillbox(SET,BLACK,670,54,795,70);
  1045.               impress(670,54,795,70);
  1046.               drwstring(SET,WHITE,BLACK,texture[config.dfloortext].name,675,55);
  1047.               mouseshow();
  1048.           }
  1049.           if (hitbutton(mx,my,ceildefbut))
  1050.           {
  1051.               config.dceiltext = curtexture;
  1052.               mousehide();
  1053.               drwfillbox(SET,BLACK,670,74,795,90);
  1054.               impress(670,74,795,90);
  1055.               drwstring(SET,WHITE,BLACK,texture[config.dceiltext].name,675,75);
  1056.               mouseshow();
  1057.           }
  1058.           if (hitbutton(mx,my,gotexture))
  1059.           {
  1060.               selecttextures();
  1061.               mousehide();
  1062.               setmapscreen();
  1063.               showtexture(curtexture);
  1064.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1065.               mouseshow();
  1066.              while (mbuts)
  1067.                 mousestatus(&mx,&my,&mbuts);
  1068.              mbuts = 1;
  1069.           }
  1070.           if (hitbutton(mx,my,gfx))
  1071.           {
  1072. //              gfxwad();
  1073.               setmapscreen();
  1074.               mousehide();
  1075.               showtexture(curtexture);
  1076.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1077.               mouseshow();
  1078.              while (mbuts)
  1079.                 mousestatus(&mx,&my,&mbuts);
  1080.              mbuts = 1;
  1081.           }
  1082.           if (hitbutton(mx,my,golmp))
  1083.           {
  1084.               lmp();
  1085.               mousehide();
  1086.               setmapscreen();
  1087.               showtexture(curtexture);
  1088.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1089.               mouseshow();
  1090.              while (mbuts)
  1091.                 mousestatus(&mx,&my,&mbuts);
  1092.              mbuts = 1;
  1093.           }
  1094.           if (hitbutton(mx,my,aboutbut))
  1095.           {
  1096.               notdone();
  1097.               setmapscreen();
  1098.               showtexture(curtexture);
  1099.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1100.               mouseshow();
  1101.              while (mbuts)
  1102.                 mousestatus(&mx,&my,&mbuts);
  1103.              mbuts = 1;
  1104.           }
  1105.           if (hitbutton(mx,my,importbut))
  1106.           {
  1107.               notdone();
  1108.               setmapscreen();
  1109.               showtexture(curtexture);
  1110.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1111.               mouseshow();
  1112.              while (mbuts)
  1113.                 mousestatus(&mx,&my,&mbuts);
  1114.              mbuts = 1;
  1115.           }
  1116.           if (hitbutton(mx,my,exportbut))
  1117.           {
  1118.               notdone();
  1119.               setmapscreen();
  1120.               showtexture(curtexture);
  1121.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1122.               mouseshow();
  1123.              while (mbuts)
  1124.                 mousestatus(&mx,&my,&mbuts);
  1125.              mbuts = 1;
  1126.           }
  1127.           if (hitbutton(mx,my,clearbut))
  1128.           {
  1129.               if (needsave)
  1130.               {
  1131.               query("Save changes to level?");
  1132.               }
  1133.               numrooms = 0;
  1134.               curroom = 0;
  1135.               numlines = 0;
  1136.               curline = 1;
  1137.               numvertex = 1;
  1138.               curvertex = 1;
  1139.               setmapscreen();
  1140.               showtexture(curtexture);
  1141.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1142.               mouseshow();
  1143.              while (mbuts)
  1144.                 mousestatus(&mx,&my,&mbuts);
  1145.              mbuts = 1;
  1146.           }
  1147.           if (hitbutton(mx,my,processbut))
  1148.           {
  1149.               notdone();
  1150.               setmapscreen();
  1151.               showtexture(curtexture);
  1152.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1153.               mouseshow();
  1154.              while (mbuts)
  1155.                 mousestatus(&mx,&my,&mbuts);
  1156.              mbuts = 1;
  1157.           }
  1158.           if (hitbutton(mx,my,savebut))
  1159.           {
  1160.               p = wgetstringbox("Save File As", "Save as (.eqm):","");
  1161.               if (p) saveeqm(p);
  1162.               setmapscreen();
  1163.               showtexture(curtexture);
  1164.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1165.               mouseshow();
  1166.              while (mbuts)
  1167.                 mousestatus(&mx,&my,&mbuts);
  1168.              mbuts = 1;
  1169.           }
  1170.           if (hitbutton(mx,my,loadbut))
  1171.           {
  1172.               p = wgetstringbox("Load EQM File", "Load file (.eqm):","");
  1173.               if (p) loadeqm(p);
  1174.               setmapscreen();
  1175.               showtexture(curtexture);
  1176.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1177.               mouseshow();
  1178.              while (mbuts)
  1179.                 mousestatus(&mx,&my,&mbuts);
  1180.              mbuts = 1;
  1181.           }
  1182.           if (curmode == 0)
  1183.           {
  1184.              if (hitbutton(mx,my,goedit))
  1185.              {
  1186.                newroom(mx, my);
  1187.                drawback();
  1188.                roominfo();
  1189.              }
  1190.              if (hitbutton(mx,my,rselect))
  1191.              {
  1192.              eraseroom();
  1193.              curroom = wgetintbox("Select Room Number","Room Number",curroom);
  1194.              drawback();
  1195.              roomtext();
  1196.              while (mbuts)
  1197.                 mousestatus(&mx,&my,&mbuts);
  1198.              mbuts = 1;
  1199.              }
  1200.              if (hitbutton(mx,my,rup))
  1201.              {
  1202.              eraseroom();
  1203.              curroom++;
  1204.              if (curroom > numrooms) curroom = numrooms;
  1205.              roomtext();
  1206.              while (mbuts)
  1207.                 mousestatus(&mx,&my,&mbuts);
  1208.              mbuts = 1;
  1209.              }
  1210.              if (hitbutton(mx,my,rdown))
  1211.              {
  1212.              eraseroom();
  1213.              curroom--;
  1214.              if (curroom < 1) curroom = 1;
  1215.              roomtext();
  1216.              while (mbuts)
  1217.                 mousestatus(&mx,&my,&mbuts);
  1218.              mbuts = 1;
  1219.              }
  1220.              if (hitbutton(mx,my,fhbut))
  1221.              {
  1222.              maproom[curroom].floor = wgetintbox("Change Floor Height","Floor Height",maproom[curroom].floor);
  1223.              drawback();
  1224.              roomtext();
  1225.              while (mbuts)
  1226.                 mousestatus(&mx,&my,&mbuts);
  1227.              mbuts = 1;
  1228.              }
  1229.              if (hitbutton(mx,my,chbut))
  1230.              {
  1231.              maproom[curroom].ceiling = wgetintbox("Change Ceiling Height","Ceiling Height",maproom[curroom].ceiling);
  1232.              drawback();
  1233.              roomtext();
  1234.              while (mbuts)
  1235.                 mousestatus(&mx,&my,&mbuts);
  1236.              mbuts = 1;
  1237.              }
  1238.              if (hitbutton(mx,my,fdbut))
  1239.              {
  1240.              config.dfloor = wgetintbox("Change Floor Default","Floor Height",config.dfloor);
  1241.              drawback();
  1242.              roomtext();
  1243.              while (mbuts)
  1244.                 mousestatus(&mx,&my,&mbuts);
  1245.              mbuts = 1;
  1246.              }
  1247.              if (hitbutton(mx,my,cdbut))
  1248.              {
  1249.              config.dceil = wgetintbox("Change Ceiling Default","Ceiling Height",config.dceil);
  1250.              drawback();
  1251.              roomtext();
  1252.              while (mbuts)
  1253.                 mousestatus(&mx,&my,&mbuts);
  1254.              mbuts = 1;
  1255.              }
  1256.              if (hitbutton(mx,my,fvbut))
  1257.              {
  1258.              if (maproom[curroom].fvis == 0) maproom[curroom].fvis = 1;
  1259.                 else maproom[curroom].fvis = 0;
  1260.              roomtext();
  1261.              while (mbuts)
  1262.                 mousestatus(&mx,&my,&mbuts);
  1263.              mbuts = 1;
  1264.              }
  1265.              if (hitbutton(mx,my,cvbut))
  1266.              {
  1267.              if (maproom[curroom].cvis == 0) maproom[curroom].cvis = 1;
  1268.                 else maproom[curroom].cvis = 0;
  1269.              roomtext();
  1270.              while (mbuts)
  1271.                 mousestatus(&mx,&my,&mbuts);
  1272.              mbuts = 1;
  1273.              }
  1274.              if (hitbutton(mx,my,ctbut))
  1275.              {
  1276.              maproom[curroom].ctext = curtexture;
  1277.              roomtext();
  1278.              while (mbuts)
  1279.                 mousestatus(&mx,&my,&mbuts);
  1280.              mbuts = 1;
  1281.              }
  1282.              if (hitbutton(mx,my,ftbut))
  1283.              {
  1284.              maproom[curroom].ftext = curtexture;
  1285.              roomtext();
  1286.              while (mbuts)
  1287.                 mousestatus(&mx,&my,&mbuts);
  1288.              mbuts = 1;
  1289.              }
  1290.           }
  1291.           if (curmode == 1)
  1292.           {
  1293.              if (hitbutton(mx,my,panel1))
  1294.              {
  1295.              splitline();
  1296.              drawback();
  1297.              wallinfo();
  1298.              while (mbuts)
  1299.                 mousestatus(&mx,&my,&mbuts);
  1300.              mbuts = 1;
  1301.              }
  1302.              if (hitbutton(mx,my,goedit))
  1303.              {
  1304.              getline(mx,my);
  1305.              drawback();
  1306.              wallinfo();
  1307.              while (mbuts)
  1308.                 mousestatus(&mx,&my,&mbuts);
  1309.              mbuts = 1;
  1310.              }
  1311.              if (hitbutton(mx,my,rselect))
  1312.              {
  1313.              eraseline();
  1314.              curroom = wgetintbox("Select Wall Number","Wall Number",curline);
  1315.              drawback();
  1316.              wallinfo();
  1317.              while (mbuts)
  1318.                 mousestatus(&mx,&my,&mbuts);
  1319.              mbuts = 1;
  1320.              }
  1321.              if (hitbutton(mx,my,rup))
  1322.              {
  1323.              eraseline();
  1324.              curline++;
  1325.              if (curline > numlines) curline = numlines;
  1326.              wallinfo();
  1327.              while (mbuts)
  1328.                 mousestatus(&mx,&my,&mbuts);
  1329.              mbuts = 1;
  1330.              }
  1331.              if (hitbutton(mx,my,rdown))
  1332.              {
  1333.              eraseline();
  1334.              curline--;
  1335.              if (curline < 1) curline = 1;
  1336.              wallinfo();
  1337.              while (mbuts)
  1338.                 mousestatus(&mx,&my,&mbuts);
  1339.              mbuts = 1;
  1340.              }
  1341.              if (hitbutton(mx,my,chbut))
  1342.              {
  1343.              mapline[curline].top = wgetintbox("Change Hole Top Height","Hole Top Height",mapline[curline].top);
  1344.              drawback();
  1345.              wallinfo();
  1346.              while (mbuts)
  1347.                 mousestatus(&mx,&my,&mbuts);
  1348.              mbuts = 1;
  1349.              }
  1350.              if (hitbutton(mx,my,fhbut))
  1351.              {
  1352.              mapline[curline].bottom = wgetintbox("Change Hole Bottom Height","Hole Bottom Height",mapline[curline].bottom);
  1353.              drawback();
  1354.              wallinfo();
  1355.              while (mbuts)
  1356.                 mousestatus(&mx,&my,&mbuts);
  1357.              mbuts = 1;
  1358.              }
  1359.              if (hitbutton(mx,my,cdbut))
  1360.              {
  1361.              config.dtop = wgetintbox("Change Hole Top Default","Hole Top Height",config.dtop);
  1362.              drawback();
  1363.              wallinfo();
  1364.              while (mbuts)
  1365.                 mousestatus(&mx,&my,&mbuts);
  1366.              mbuts = 1;
  1367.              }
  1368.              if (hitbutton(mx,my,fdbut))
  1369.              {
  1370.              config.dbottom = wgetintbox("Change Hole Bottom Default","Hole Bottom Height",config.dbottom);
  1371.              drawback();
  1372.              wallinfo();
  1373.              while (mbuts)
  1374.                 mousestatus(&mx,&my,&mbuts);
  1375.              mbuts = 1;
  1376.              }
  1377.              if (hitbutton(mx,my,holebut))
  1378.              {
  1379.              if (mapline[curline].hole == 0) mapline[curline].hole = 1;
  1380.                 else mapline[curline].hole = 0;
  1381.              wallinfo();
  1382.              while (mbuts)
  1383.                 mousestatus(&mx,&my,&mbuts);
  1384.              mbuts = 1;
  1385.              }
  1386.              if (hitbutton(mx,my,ctbut))
  1387.              {
  1388.              mapline[curline].texture = curtexture;
  1389.              wallinfo();
  1390.              while (mbuts)
  1391.                 mousestatus(&mx,&my,&mbuts);
  1392.              mbuts = 1;
  1393.              }
  1394.              if (hitbutton(mx,my,cvbut))
  1395.              {
  1396.              if (mapline[curline].visible == 0) mapline[curline].visible = 1;
  1397.                else mapline[curline].visible = 0;
  1398.              wallinfo();
  1399.              while (mbuts)
  1400.                 mousestatus(&mx,&my,&mbuts);
  1401.              mbuts = 1;
  1402.              }
  1403.           }
  1404.           if (curmode == 2)
  1405.           {
  1406.              if (hitbutton(mx,my,goedit))
  1407.              {
  1408.              movevertex(mx, my);
  1409.              drawback();
  1410.                  vertexinfo();
  1411.              while (mbuts)
  1412.                 mousestatus(&mx,&my,&mbuts);
  1413.              mbuts = 1;
  1414.              }
  1415.              if (hitbutton(mx,my,vup))
  1416.              {
  1417.              curvertex++;
  1418.              if (curvertex > numvertex) curvertex = numvertex;
  1419.              drawvertex();
  1420.              vertextext();
  1421.              while (mbuts)
  1422.                 mousestatus(&mx,&my,&mbuts);
  1423.              mbuts = 1;
  1424.              }
  1425.              if (hitbutton(mx,my,vdown))
  1426.              {
  1427.              curvertex--;
  1428.              if (curvertex < 1) curvertex = 1;
  1429.              drawvertex();
  1430.                  vertextext();
  1431.              while (mbuts)
  1432.                 mousestatus(&mx,&my,&mbuts);
  1433.              mbuts = 1;
  1434.              }
  1435.              if (hitbutton(mx,my,vxbut))
  1436.              {
  1437.              mapvertex[curvertex].x = wgetintbox("Change Vertex X Coord","Vertex X Coord",mapvertex[curvertex].x);
  1438.              drawback();
  1439.                  vertexinfo();
  1440.              while (mbuts)
  1441.                 mousestatus(&mx,&my,&mbuts);
  1442.              mbuts = 1;
  1443.              }
  1444.              if (hitbutton(mx,my,vybut))
  1445.              {
  1446.              mapvertex[curvertex].y = wgetintbox("Change Vertex Y Coord","Vertex Y Coord",mapvertex[curvertex].y);
  1447.              drawback();
  1448.                  vertexinfo();
  1449.              while (mbuts)
  1450.                 mousestatus(&mx,&my,&mbuts);
  1451.              mbuts = 1;
  1452.              }
  1453.              if (hitbutton(mx,my,vselect))
  1454.              {
  1455.              curvertex = wgetintbox("Select Vertex","Vertex Number",curvertex);
  1456.              drawback();
  1457.                  vertexinfo();
  1458.              while (mbuts)
  1459.                 mousestatus(&mx,&my,&mbuts);
  1460.              mbuts = 1;
  1461.              }
  1462.           }
  1463.            }
  1464.            if (mbuts & 2)//scroll fast
  1465.            {
  1466.           if (hitbutton(mx,my,up))
  1467.           {
  1468.              mapy+=20;
  1469.              drawback();
  1470.           }
  1471.           if (hitbutton(mx,my,down))
  1472.           {
  1473.              mapy-=20;
  1474.              drawback();
  1475.           }
  1476.           if (hitbutton(mx,my,right))
  1477.           {
  1478.              mapx-=20;
  1479.              drawback();
  1480.           }
  1481.           if (hitbutton(mx,my,left))
  1482.           {
  1483.              mapx+=20;
  1484.              drawback();
  1485.           }
  1486.           if (hitbutton(mx,my,texturedown))
  1487.           {
  1488.               if (curtexture++ >= numtex) curtexture = numtex - 1;
  1489.               mousehide();
  1490.               drwfillbox(SET,BLACK,678,256,791,269);
  1491.               drwfillbox(SET,BLACK,672,120,800,247);
  1492.               showtexture(curtexture);
  1493.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1494.               mouseshow();
  1495.           }
  1496.           if (hitbutton(mx,my,textureup))
  1497.           {
  1498.               if (curtexture-- < 1) curtexture = 1;
  1499.               mousehide();
  1500.               drwfillbox(SET,BLACK,678,256,791,269);
  1501.               drwfillbox(SET,BLACK,672,120,800,247);
  1502.               showtexture(curtexture);
  1503.               drwstring(SET,WHITE,BLACK,texture[curtexture].name,678,256);
  1504.               mouseshow();
  1505.           }
  1506.           if (curmode==0)
  1507.           {
  1508.              if (hitbutton(mx,my,rup))
  1509.              {
  1510.              curroom++;
  1511.              if (curroom > numrooms) curroom = numrooms;
  1512.              eraseroom();
  1513.              roomtext();
  1514.              }
  1515.              if (hitbutton(mx,my,rdown))
  1516.              {
  1517.              curroom--;
  1518.              if (curroom < 1) curroom = 1;
  1519.              eraseroom();
  1520.              roomtext();
  1521.              }
  1522.           }
  1523.           if (curmode == 1) //move vertex
  1524.           {
  1525.              if (hitbutton(mx,my,rup))
  1526.              {
  1527.              eraseline();
  1528.              curline++;
  1529.              if (curline > numlines) curline = numlines;
  1530.              wallinfo();
  1531.              while (mbuts)
  1532.                 mousestatus(&mx,&my,&mbuts);
  1533.              mbuts = 1;
  1534.              }
  1535.              if (hitbutton(mx,my,rdown))
  1536.              {
  1537.              eraseline();
  1538.              curline--;
  1539.              if (curline < 1) curline = 1;
  1540.              wallinfo();
  1541.              while (mbuts)
  1542.                 mousestatus(&mx,&my,&mbuts);
  1543.              mbuts = 1;
  1544.              }
  1545.           }
  1546.           if (curmode == 2) //move vertex
  1547.           {
  1548.              if (hitbutton(mx,my,goedit))
  1549.              {
  1550.              getvertex(mx,my);
  1551.              drawback();
  1552.                  vertexinfo();
  1553.              while (mbuts)
  1554.                 mousestatus(&mx,&my,&mbuts);
  1555.              mbuts = 1;
  1556.              }
  1557.              if (hitbutton(mx,my,vup))
  1558.              {
  1559.              curvertex++;
  1560.              if (curvertex > numvertex) curvertex = numvertex;
  1561.              drawvertex();
  1562.              vertextext();
  1563.              }
  1564.              if (hitbutton(mx,my,vdown))
  1565.              {
  1566.              curvertex--;
  1567.              if (curvertex < 1) curvertex = 1;
  1568.              drawvertex();
  1569.                  vertextext();
  1570.              }
  1571.           }
  1572.            }
  1573.  
  1574.         }
  1575.         if (!mbuts) k = getkey();
  1576.         if (k == a_F1) screenshot();
  1577.         if (k == a_UP)
  1578.         {
  1579.          mapy+=5;
  1580.          drawback();
  1581.         }
  1582.         if (k == a_DOWN)
  1583.         {
  1584.          mapy-=5;
  1585.          drawback();
  1586.         }
  1587.         if (k == a_LEFT)
  1588.         {
  1589.          mapx+=5;
  1590.          drawback();
  1591.         }
  1592.         if (k == a_RIGHT)
  1593.         {
  1594.          mapx-=5;
  1595.          drawback();
  1596.         }
  1597.         mbuts = 0;
  1598.    }
  1599.    saveeqm("test.eqm");
  1600.   farfree(mapvertex);
  1601.   farfree(mapline);
  1602.   farfree(maproom);
  1603. }