home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 26 / amigaformatcd26.iso / -screenplay- / otherstuff / adoom_src / am_map.c < prev    next >
C/C++ Source or Header  |  1998-03-09  |  33KB  |  1,459 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. //
  18. // $Log:$
  19. //
  20. // DESCRIPTION:  the automap code
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24. static const char rcsid[] = "$Id: am_map.c,v 1.4 1997/02/03 21:24:33 b1 Exp $";
  25.  
  26. #include <stdio.h>
  27.  
  28.  
  29. #include "z_zone.h"
  30. #include "doomdef.h"
  31. #include "st_stuff.h"
  32. #include "p_local.h"
  33. #include "w_wad.h"
  34.  
  35. #include "m_cheat.h"
  36. #include "i_system.h"
  37. #include "i_video.h"
  38.  
  39. // Needs access to LFB.
  40. #include "v_video.h"
  41.  
  42. // State.
  43. #include "doomstat.h"
  44. #include "r_state.h"
  45.  
  46. // Data.
  47. #include "dstrings.h"
  48.  
  49. #include "am_map.h"
  50.  
  51.  
  52. // For use if I do walls with outsides/insides
  53. #define REDS            (256-5*16)
  54. #define REDRANGE        16
  55. #define BLUES           (256-4*16+8)
  56. #define BLUERANGE       8
  57. #define GREENS          (7*16)
  58. #define GREENRANGE      16
  59. #define GRAYS           (6*16)
  60. #define GRAYSRANGE      16
  61. #define BROWNS          (4*16)
  62. #define BROWNRANGE      16
  63. #define YELLOWS         (256-32+7)
  64. #define YELLOWRANGE     1
  65. #define BLACK           0
  66. #define WHITE           (256-47)
  67.  
  68. // Automap colors
  69. #define BACKGROUND      BLACK
  70. #define YOURCOLORS      WHITE
  71. #define YOURRANGE       0
  72. #define WALLCOLORS      REDS
  73. #define WALLRANGE       REDRANGE
  74. #define TSWALLCOLORS    GRAYS
  75. #define TSWALLRANGE     GRAYSRANGE
  76. #define FDWALLCOLORS    BROWNS
  77. #define FDWALLRANGE     BROWNRANGE
  78. #define CDWALLCOLORS    YELLOWS
  79. #define CDWALLRANGE     YELLOWRANGE
  80. #define THINGCOLORS     GREENS
  81. #define THINGRANGE      GREENRANGE
  82. #define SECRETWALLCOLORS WALLCOLORS
  83. #define SECRETWALLRANGE WALLRANGE
  84. #define GRIDCOLORS      (GRAYS + GRAYSRANGE/2)
  85. #define GRIDRANGE       0
  86. #define XHAIRCOLORS     GRAYS
  87.  
  88. // drawing stuff
  89. #define FB              0
  90.  
  91. #define AM_PANDOWNKEY   KEY_DOWNARROW
  92. #define AM_PANUPKEY     KEY_UPARROW
  93. #define AM_PANRIGHTKEY  KEY_RIGHTARROW
  94. #define AM_PANLEFTKEY   KEY_LEFTARROW
  95. #define AM_ZOOMINKEY    '='
  96. #define AM_ZOOMOUTKEY   '-'
  97. #define AM_STARTKEY     KEY_TAB
  98. #define AM_ENDKEY       KEY_TAB
  99. #define AM_GOBIGKEY     '0'
  100. #define AM_FOLLOWKEY    'f'
  101. #define AM_GRIDKEY      'g'
  102. #define AM_MARKKEY      'm'
  103. #define AM_CLEARMARKKEY 'c'
  104.  
  105. #define AM_NUMMARKPOINTS 10
  106.  
  107. // scale on entry
  108. #define INITSCALEMTOF (.2*FRACUNIT)
  109. // how much the automap moves window per tic in frame-buffer coordinates
  110. // moves 140 pixels in 1 second
  111. #define F_PANINC        4
  112. // how much zoom-in per tic
  113. // goes to 2x in 1 second
  114. #define M_ZOOMIN        ((int) (1.02*FRACUNIT))
  115. // how much zoom-out per tic
  116. // pulls out to 0.5x in 1 second
  117. #define M_ZOOMOUT       ((int) (FRACUNIT/1.02))
  118.  
  119. // translates between frame-buffer and map distances
  120. #define FTOM(x) FixedMul(((x)<<16),scale_ftom)
  121. #define MTOF(x) (FixedMul((x),scale_mtof)>>16)
  122. // translates between frame-buffer and map coordinates
  123. #define CXMTOF(x)  (f_x + MTOF((x)-m_x))
  124. #define CYMTOF(y)  (f_y + (f_h - MTOF((y)-m_y)))
  125.  
  126. // the following is crap
  127. #define LINE_NEVERSEE ML_DONTDRAW
  128.  
  129. typedef struct
  130. {
  131.     int x, y;
  132. } fpoint_t;
  133.  
  134. typedef struct
  135. {
  136.     fpoint_t a, b;
  137. } fline_t;
  138.  
  139. typedef struct
  140. {
  141.     fixed_t             x,y;
  142. } mpoint_t;
  143.  
  144. typedef struct
  145. {
  146.     mpoint_t a, b;
  147. } mline_t;
  148.  
  149. typedef struct
  150. {
  151.     fixed_t slp, islp;
  152. } islope_t;
  153.  
  154.  
  155.  
  156. //
  157. // The vector graphics for the automap.
  158. //  A line drawing of the player pointing right,
  159. //   starting from the middle.
  160. //
  161. #define R ((8*PLAYERRADIUS)/7)
  162. mline_t player_arrow[] = {
  163.     { { -R+R/8, 0 }, { R, 0 } }, // -----
  164.     { { R, 0 }, { R-R/2, R/4 } },  // ----->
  165.     { { R, 0 }, { R-R/2, -R/4 } },
  166.     { { -R+R/8, 0 }, { -R-R/8, R/4 } }, // >---->
  167.     { { -R+R/8, 0 }, { -R-R/8, -R/4 } },
  168.     { { -R+3*R/8, 0 }, { -R+R/8, R/4 } }, // >>--->
  169.     { { -R+3*R/8, 0 }, { -R+R/8, -R/4 } }
  170. };
  171. #undef R
  172. #define NUMPLYRLINES (sizeof(player_arrow)/sizeof(mline_t))
  173.  
  174. #define R ((8*PLAYERRADIUS)/7)
  175. mline_t cheat_player_arrow[] = {
  176.     { { -R+R/8, 0 }, { R, 0 } }, // -----
  177.     { { R, 0 }, { R-R/2, R/6 } },  // ----->
  178.     { { R, 0 }, { R-R/2, -R/6 } },
  179.     { { -R+R/8, 0 }, { -R-R/8, R/6 } }, // >----->
  180.     { { -R+R/8, 0 }, { -R-R/8, -R/6 } },
  181.     { { -R+3*R/8, 0 }, { -R+R/8, R/6 } }, // >>----->
  182.     { { -R+3*R/8, 0 }, { -R+R/8, -R/6 } },
  183.     { { -R/2, 0 }, { -R/2, -R/6 } }, // >>-d--->
  184.     { { -R/2, -R/6 }, { -R/2+R/6, -R/6 } },
  185.     { { -R/2+R/6, -R/6 }, { -R/2+R/6, R/4 } },
  186.     { { -R/6, 0 }, { -R/6, -R/6 } }, // >>-dd-->
  187.     { { -R/6, -R/6 }, { 0, -R/6 } },
  188.     { { 0, -R/6 }, { 0, R/4 } },
  189.     { { R/6, R/4 }, { R/6, -R/7 } }, // >>-ddt->
  190.     { { R/6, -R/7 }, { R/6+R/32, -R/7-R/32 } },
  191.     { { R/6+R/32, -R/7-R/32 }, { R/6+R/10, -R/7 } }
  192. };
  193. #undef R
  194. #define NUMCHEATPLYRLINES (sizeof(cheat_player_arrow)/sizeof(mline_t))
  195.  
  196. #define R (FRACUNIT)
  197. mline_t triangle_guy[] = {
  198.     { { -.867*R, -.5*R }, { .867*R, -.5*R } },
  199.     { { .867*R, -.5*R } , { 0, R } },
  200.     { { 0, R }, { -.867*R, -.5*R } }
  201. };
  202. #undef R
  203. #define NUMTRIANGLEGUYLINES (sizeof(triangle_guy)/sizeof(mline_t))
  204.  
  205. #define R (FRACUNIT)
  206. mline_t thintriangle_guy[] = {
  207.     { { -.5*R, -.7*R }, { R, 0 } },
  208.     { { R, 0 }, { -.5*R, .7*R } },
  209.     { { -.5*R, .7*R }, { -.5*R, -.7*R } }
  210. };
  211. #undef R
  212. #define NUMTHINTRIANGLEGUYLINES (sizeof(thintriangle_guy)/sizeof(mline_t))
  213.  
  214.  
  215.  
  216.  
  217. static int      cheating = 0;
  218. static int      grid = 0;
  219.  
  220. static int      leveljuststarted = 1;   // kluge until AM_LevelInit() is called
  221.  
  222. boolean         automapactive = false;
  223.  
  224. static int      finit_width;
  225. static int      finit_height;
  226.  
  227. extern int      viewwidth; /* CDE'98 - Need this for maponhu */
  228. extern int      viewheight; /* CDE'98 - Need this for maponhu */
  229. extern int      viewwindowx; /* CDE'98 - Need this for maponhu */
  230. extern int      viewwindowy; /* CDE'98 - Need this for maponhu */
  231.  
  232. int      wx; /* CDE'98 - x offset from view */
  233. int      wy; /* CDE'98 - y offset from view */
  234.  
  235. // location of window on screen
  236. static int      f_x;
  237. static int      f_y;
  238.  
  239. // size of window on screen
  240. static int      f_w;
  241. static int      f_h;
  242.  
  243. static int      lightlev;               // used for funky strobing effect
  244. static byte*    fb;                     // pseudo-frame buffer
  245. static int      amclock;
  246.  
  247. static mpoint_t m_paninc; // how far the window pans each tic (map coords)
  248. static fixed_t  mtof_zoommul; // how far the window zooms in each tic (map coords)
  249. static fixed_t  ftom_zoommul; // how far the window zooms in each tic (fb coords)
  250.  
  251. static fixed_t  m_x, m_y;   // LL x,y where the window is on the map (map coords)
  252. static fixed_t  m_x2, m_y2; // UR x,y where the window is on the map (map coords)
  253.  
  254. //
  255. // width/height of window on map (map coords)
  256. //
  257. static fixed_t  m_w;
  258. static fixed_t  m_h;
  259.  
  260. // based on level size
  261. static fixed_t  min_x;
  262. static fixed_t  min_y; 
  263. static fixed_t  max_x;
  264. static fixed_t  max_y;
  265.  
  266. static fixed_t  max_w; // max_x-min_x,
  267. static fixed_t  max_h; // max_y-min_y
  268.  
  269. // based on player size
  270. static fixed_t  min_w;
  271. static fixed_t  min_h;
  272.  
  273.  
  274. static fixed_t  min_scale_mtof; // used to tell when to stop zooming out
  275. static fixed_t  max_scale_mtof; // used to tell when to stop zooming in
  276.  
  277. // old stuff for recovery later
  278. static fixed_t old_m_w, old_m_h;
  279. static fixed_t old_m_x, old_m_y;
  280.  
  281. // old location used by the Follower routine
  282. static mpoint_t f_oldloc;
  283.  
  284. // used by MTOF to scale from map-to-frame-buffer coords
  285. static fixed_t scale_mtof = INITSCALEMTOF;
  286. // used by FTOM to scale from frame-buffer-to-map coords (=1/scale_mtof)
  287. static fixed_t scale_ftom;
  288.  
  289. static player_t *plr; // the player represented by an arrow
  290.  
  291. static patch_t *marknums[10]; // numbers used for marking by the automap
  292. static mpoint_t markpoints[AM_NUMMARKPOINTS]; // where the points are
  293. static int markpointnum = 0; // next point to be assigned
  294.  
  295. static int followplayer = 1; // specifies whether to follow the player around
  296.  
  297. static unsigned char cheat_amap_seq[] = { 0xb2, 0x26, 0x26, 0x2e, 0xff };
  298. static cheatseq_t cheat_amap = { cheat_amap_seq, 0 };
  299.  
  300. static boolean stopped = true;
  301.  
  302. extern boolean viewactive;
  303. extern boolean rotatemap;
  304. extern boolean maponhu;
  305. //extern byte screens[][SCREENWIDTH*SCREENHEIGHT];
  306.  
  307.  
  308.  
  309. void resinit_am_map (void)
  310. {
  311.   finit_width = SCREENWIDTH;
  312.   finit_height = SCREENHEIGHT - 32;
  313. }
  314.  
  315.  
  316. //void
  317. //V_MarkRect
  318. //( int   x,
  319. //  int   y,
  320. //  int   width,
  321. //  int   height );
  322.  
  323. //
  324. // Rotation in 2D.
  325. // Used to rotate player arrow line character.
  326. //
  327. void
  328. AM_rotate
  329. ( fixed_t*      x,
  330.   fixed_t*      y,
  331.   angle_t       a )
  332. {
  333.     fixed_t tmpx;
  334.  
  335.     tmpx =
  336.         FixedMul(*x,finecosine[a>>ANGLETOFINESHIFT])
  337.         - FixedMul(*y,finesine[a>>ANGLETOFINESHIFT]);
  338.     
  339.     *y   =
  340.         FixedMul(*x,finesine[a>>ANGLETOFINESHIFT])
  341.         + FixedMul(*y,finecosine[a>>ANGLETOFINESHIFT]);
  342.  
  343.     *x = tmpx;
  344. }
  345.  
  346. // Calculates the slope and slope according to the x-axis of a line
  347. // segment in map coordinates (with the upright y-axis n' all) so
  348. // that it can be used with the brain-dead drawing stuff.
  349.  
  350. void
  351. AM_getIslope
  352. ( mline_t*      ml,
  353.   islope_t*     is )
  354. {
  355.     int dx, dy;
  356.  
  357.     dy = ml->a.y - ml->b.y;
  358.     dx = ml->b.x - ml->a.x;
  359.     if (!dy) is->islp = (dx<0?-MAXINT:MAXINT);
  360.     else is->islp = FixedDiv(dx, dy);
  361.     if (!dx) is->slp = (dy<0?-MAXINT:MAXINT);
  362.     else is->slp = FixedDiv(dy, dx);
  363.  
  364. }
  365.  
  366. //
  367. //
  368. //
  369. void AM_activateNewScale(void)
  370. {
  371.     m_x += m_w/2;
  372.     m_y += m_h/2;
  373.     m_w = FTOM(f_w);
  374.     m_h = FTOM(f_h);
  375.     m_x -= m_w/2;
  376.     m_y -= m_h/2;
  377.     m_x2 = m_x + m_w;
  378.     m_y2 = m_y + m_h;
  379. }
  380.  
  381. //
  382. //
  383. //
  384. void AM_saveScaleAndLoc(void)
  385. {
  386.     old_m_x = m_x;
  387.     old_m_y = m_y;
  388.     old_m_w = m_w;
  389.     old_m_h = m_h;
  390. }
  391.  
  392. //
  393. //
  394. //
  395. void AM_restoreScaleAndLoc(void)
  396. {
  397.  
  398.     m_w = old_m_w;
  399.     m_h = old_m_h;
  400.     if (!followplayer)
  401.     {
  402.         m_x = old_m_x;
  403.         m_y = old_m_y;
  404.     } else {
  405.         m_x = plr->mo->x - m_w/2;
  406.         m_y = plr->mo->y - m_h/2;
  407.     }
  408.     m_x2 = m_x + m_w;
  409.     m_y2 = m_y + m_h;
  410.  
  411.     // Change the scaling multipliers
  412.     scale_mtof = FixedDiv(f_w<<FRACBITS, m_w);
  413.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  414. }
  415.  
  416. //
  417. // adds a marker at the current location
  418. //
  419. void AM_addMark(void)
  420. {
  421.     markpoints[markpointnum].x = m_x + m_w/2;
  422.     markpoints[markpointnum].y = m_y + m_h/2;
  423.     markpointnum = (markpointnum + 1) % AM_NUMMARKPOINTS;
  424.  
  425. }
  426.  
  427. //
  428. // Determines bounding box of all vertices,
  429. // sets global variables controlling zoom range.
  430. //
  431. void AM_findMinMaxBoundaries(void)
  432. {
  433.     int i;
  434.     fixed_t a;
  435.     fixed_t b;
  436.  
  437.     min_x = min_y =  MAXINT;
  438.     max_x = max_y = -MAXINT;
  439.   
  440.     for (i=0;i<numvertexes;i++)
  441.     {
  442.         if (vertexes[i].x < min_x)
  443.             min_x = vertexes[i].x;
  444.         else if (vertexes[i].x > max_x)
  445.             max_x = vertexes[i].x;
  446.     
  447.         if (vertexes[i].y < min_y)
  448.             min_y = vertexes[i].y;
  449.         else if (vertexes[i].y > max_y)
  450.             max_y = vertexes[i].y;
  451.     }
  452.   
  453.     max_w = max_x - min_x;
  454.     max_h = max_y - min_y;
  455.  
  456.     min_w = 2*PLAYERRADIUS; // const? never changed?
  457.     min_h = 2*PLAYERRADIUS;
  458.  
  459.     a = FixedDiv(f_w<<FRACBITS, max_w);
  460.     b = FixedDiv(f_h<<FRACBITS, max_h);
  461.   
  462.     min_scale_mtof = a < b ? a : b;
  463.     max_scale_mtof = FixedDiv(f_h<<FRACBITS, 2*PLAYERRADIUS);
  464.  
  465. }
  466.  
  467.  
  468. //
  469. //
  470. //
  471. void AM_changeWindowLoc(void)
  472. {
  473.     if (m_paninc.x || m_paninc.y)
  474.     {
  475.         followplayer = 0;
  476.         f_oldloc.x = MAXINT;
  477.     }
  478.  
  479.     /* CDE'98 Rotate Map Patch - Rotate paninc or not ?? make your choice ... */
  480. /*
  481.     if(rotatemap)
  482.     {
  483.         fixed_t x,y;
  484.         x=m_paninc.x;
  485.         y=m_paninc.y;
  486.         AM_rotate(&x, &y, ANG90-plr->mo->angle);
  487.         m_x += x;
  488.         m_y += y;
  489.     } else {
  490. */
  491.         m_x += m_paninc.x;
  492.         m_y += m_paninc.y;
  493. /*
  494.     }
  495. */
  496.  
  497.     /* CDE'98  - checking for limit is disabled while in rotate mode */
  498.     /*           should not cause any problem */
  499.     if(!rotatemap)
  500.     {
  501.         if (m_x + m_w/2 > max_x)
  502.             m_x = max_x - m_w/2;
  503.         else if (m_x + m_w/2 < min_x)
  504.             m_x = min_x - m_w/2;
  505.   
  506.         if (m_y + m_h/2 > max_y)
  507.             m_y = max_y - m_h/2;
  508.         else if (m_y + m_h/2 < min_y)
  509.             m_y = min_y - m_h/2;
  510.     }
  511.  
  512.     m_x2 = m_x + m_w;
  513.     m_y2 = m_y + m_h;
  514. }
  515.  
  516.  
  517. //
  518. //
  519. //
  520. void AM_initVariables(void)
  521. {
  522.     int pnum;
  523.     static event_t st_notify = { ev_keyup, AM_MSGENTERED };
  524.  
  525.     automapactive = true;
  526.     fb = screens[0];
  527.  
  528.     f_oldloc.x = MAXINT;
  529.     amclock = 0;
  530.     lightlev = 0;
  531.  
  532.     m_paninc.x = m_paninc.y = 0;
  533.     ftom_zoommul = FRACUNIT;
  534.     mtof_zoommul = FRACUNIT;
  535.  
  536.     /* CDE'98 - Calculate view position and size */
  537.     if(maponhu)
  538.     {
  539.         wx = viewwindowx;
  540.         wy = viewwindowy;
  541.         f_w = viewwidth;
  542.         f_h = viewheight;
  543.     } else {
  544.         wx = 0;
  545.         wy = 0;
  546.         f_w = finit_width;
  547.         f_h = finit_height;
  548.     }
  549.  
  550.     m_w = FTOM(f_w);
  551.     m_h = FTOM(f_h);
  552.  
  553.     // find player to center on initially
  554.     if (!playeringame[pnum = consoleplayer])
  555.         for (pnum=0;pnum<MAXPLAYERS;pnum++)
  556.             if (playeringame[pnum])
  557.                 break;
  558.   
  559.     plr = &players[pnum];
  560.     m_x = plr->mo->x - m_w/2;
  561.     m_y = plr->mo->y - m_h/2;
  562.     AM_changeWindowLoc();
  563.  
  564.     // for saving & restoring
  565.     old_m_x = m_x;
  566.     old_m_y = m_y;
  567.     old_m_w = m_w;
  568.     old_m_h = m_h;
  569.  
  570.     // inform the status bar of the change
  571.     ST_Responder(&st_notify);
  572.  
  573. }
  574.  
  575. //
  576. // 
  577. //
  578. void AM_loadPics(void)
  579. {
  580.     int i;
  581.     char namebuf[9];
  582.   
  583.     for (i=0;i<10;i++)
  584.     {
  585.         sprintf(namebuf, "AMMNUM%d", i);
  586.         marknums[i] = W_CacheLumpName(namebuf, PU_STATIC);
  587.     }
  588.  
  589. }
  590.  
  591. void AM_unloadPics(void)
  592. {
  593.     int i;
  594.   
  595.     for (i=0;i<10;i++)
  596.         Z_ChangeTag(marknums[i], PU_CACHE);
  597.  
  598. }
  599.  
  600. void AM_clearMarks(void)
  601. {
  602.     int i;
  603.  
  604.     for (i=0;i<AM_NUMMARKPOINTS;i++)
  605.         markpoints[i].x = -1; // means empty
  606.     markpointnum = 0;
  607. }
  608.  
  609. //
  610. // should be called at the start of every level
  611. // right now, i figure it out myself
  612. //
  613. void AM_LevelInit(void)
  614. {
  615.     leveljuststarted = 0;
  616.  
  617.     f_x = f_y = 0;
  618.  
  619.     /* CDE'98 - Calculate view position and size */
  620.     if(maponhu)
  621.     {
  622.         wx = viewwindowx;
  623.         wy = viewwindowy;
  624.         f_w = viewwidth;
  625.         f_h = viewheight;
  626.     } else {
  627.         wx = 0;
  628.         wy = 0;
  629.         f_w = finit_width;
  630.         f_h = finit_height;
  631.     }
  632.  
  633.     AM_clearMarks();
  634.  
  635.     AM_findMinMaxBoundaries();
  636.     scale_mtof = FixedDiv(min_scale_mtof, (int) (0.7*FRACUNIT));
  637.     if (scale_mtof > max_scale_mtof)
  638.         scale_mtof = min_scale_mtof;
  639.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  640. }
  641.  
  642.  
  643.  
  644.  
  645. //
  646. //
  647. //
  648. void AM_Stop (void)
  649. {
  650.     static event_t st_notify = { 0, ev_keyup, AM_MSGEXITED };
  651.  
  652.     AM_unloadPics();
  653.     automapactive = false;
  654.     ST_Responder(&st_notify);
  655.     stopped = true;
  656. }
  657.  
  658. //
  659. //
  660. //
  661. void AM_Start (void)
  662. {
  663.     static int lastlevel = -1, lastepisode = -1;
  664.  
  665.     if (!stopped) AM_Stop();
  666.     stopped = false;
  667.     if (lastlevel != gamemap || lastepisode != gameepisode)
  668.     {
  669.         AM_LevelInit();
  670.         lastlevel = gamemap;
  671.         lastepisode = gameepisode;
  672.     }
  673.     AM_initVariables();
  674.     AM_loadPics();
  675. }
  676.  
  677. //
  678. // set the window scale to the maximum size
  679. //
  680. void AM_minOutWindowScale(void)
  681. {
  682.     scale_mtof = min_scale_mtof;
  683.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  684.     AM_activateNewScale();
  685. }
  686.  
  687. //
  688. // set the window scale to the minimum size
  689. //
  690. void AM_maxOutWindowScale(void)
  691. {
  692.     scale_mtof = max_scale_mtof;
  693.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  694.     AM_activateNewScale();
  695. }
  696.  
  697.  
  698. //
  699. // Handle events (user inputs) in automap mode
  700. //
  701. boolean
  702. AM_Responder
  703. ( event_t*      ev )
  704. {
  705.  
  706.     int rc;
  707.     static int cheatstate=0;
  708.     static int bigstate=0;
  709.     static char buffer[20];
  710.  
  711.     rc = false;
  712.  
  713.     if (!automapactive)
  714.     {
  715.         if (ev->type == ev_keydown && ev->data1 == AM_STARTKEY)
  716.         {
  717.             AM_Start ();
  718.             /* CDE'98 Map on Headup Patch */
  719.             if(!maponhu)
  720.                 viewactive = false;
  721.             rc = true;
  722.         }
  723.     }
  724.  
  725.     else if (ev->type == ev_keydown)
  726.     {
  727.  
  728.         rc = true;
  729.         switch(ev->data1)
  730.         {
  731.           case AM_PANRIGHTKEY: // pan right
  732.             if (!followplayer) m_paninc.x = FTOM(F_PANINC);
  733.             else rc = false;
  734.             break;
  735.           case AM_PANLEFTKEY: // pan left
  736.             if (!followplayer) m_paninc.x = -FTOM(F_PANINC);
  737.             else rc = false;
  738.             break;
  739.           case AM_PANUPKEY: // pan up
  740.             if (!followplayer) m_paninc.y = FTOM(F_PANINC);
  741.             else rc = false;
  742.             break;
  743.           case AM_PANDOWNKEY: // pan down
  744.             if (!followplayer) m_paninc.y = -FTOM(F_PANINC);
  745.             else rc = false;
  746.             break;
  747.           case AM_ZOOMOUTKEY: // zoom out
  748.             mtof_zoommul = M_ZOOMOUT;
  749.             ftom_zoommul = M_ZOOMIN;
  750.             break;
  751.           case AM_ZOOMINKEY: // zoom in
  752.             mtof_zoommul = M_ZOOMIN;
  753.             ftom_zoommul = M_ZOOMOUT;
  754.             break;
  755.           case AM_ENDKEY:
  756.             bigstate = 0;
  757.             viewactive = true;
  758.             AM_Stop ();
  759.             break;
  760.           case AM_GOBIGKEY:
  761.             bigstate = !bigstate;
  762.             if (bigstate)
  763.             {
  764.                 AM_saveScaleAndLoc();
  765.                 AM_minOutWindowScale();
  766.             }
  767.             else AM_restoreScaleAndLoc();
  768.             break;
  769.           case AM_FOLLOWKEY:
  770.             followplayer = !followplayer;
  771.             f_oldloc.x = MAXINT;
  772.             plr->message = followplayer ? AMSTR_FOLLOWON : AMSTR_FOLLOWOFF;
  773.             break;
  774.           case AM_GRIDKEY:
  775.             grid = !grid;
  776.             plr->message = grid ? AMSTR_GRIDON : AMSTR_GRIDOFF;
  777.             break;
  778.           case AM_MARKKEY:
  779.             sprintf(buffer, "%s %d", AMSTR_MARKEDSPOT, markpointnum);
  780.             plr->message = buffer;
  781.             AM_addMark();
  782.             break;
  783.           case AM_CLEARMARKKEY:
  784.             AM_clearMarks();
  785.             plr->message = AMSTR_MARKSCLEARED;
  786.             break;
  787.           default:
  788.             cheatstate=0;
  789.             rc = false;
  790.         }
  791.         if (!deathmatch && cht_CheckCheat(&cheat_amap, ev->data1))
  792.         {
  793.             rc = false;
  794.             cheating = (cheating+1) % 3;
  795.         }
  796.     }
  797.  
  798.     else if (ev->type == ev_keyup)
  799.     {
  800.         rc = false;
  801.         switch (ev->data1)
  802.         {
  803.           case AM_PANRIGHTKEY:
  804.             if (!followplayer) m_paninc.x = 0;
  805.             break;
  806.           case AM_PANLEFTKEY:
  807.             if (!followplayer) m_paninc.x = 0;
  808.             break;
  809.           case AM_PANUPKEY:
  810.             if (!followplayer) m_paninc.y = 0;
  811.             break;
  812.           case AM_PANDOWNKEY:
  813.             if (!followplayer) m_paninc.y = 0;
  814.             break;
  815.           case AM_ZOOMOUTKEY:
  816.           case AM_ZOOMINKEY:
  817.             mtof_zoommul = FRACUNIT;
  818.             ftom_zoommul = FRACUNIT;
  819.             break;
  820.         }
  821.     }
  822.  
  823.     return rc;
  824.  
  825. }
  826.  
  827.  
  828. //
  829. // Zooming
  830. //
  831. void AM_changeWindowScale(void)
  832. {
  833.  
  834.     // Change the scaling multipliers
  835.     scale_mtof = FixedMul(scale_mtof, mtof_zoommul);
  836.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  837.  
  838.     if (scale_mtof < min_scale_mtof)
  839.         AM_minOutWindowScale();
  840.     else if (scale_mtof > max_scale_mtof)
  841.         AM_maxOutWindowScale();
  842.     else
  843.         AM_activateNewScale();
  844. }
  845.  
  846.  
  847. //
  848. //
  849. //
  850. void AM_doFollowPlayer(void)
  851. {
  852.  
  853.     if (f_oldloc.x != plr->mo->x || f_oldloc.y != plr->mo->y)
  854.     {
  855.         m_x = FTOM(MTOF(plr->mo->x)) - m_w/2;
  856.         m_y = FTOM(MTOF(plr->mo->y)) - m_h/2;
  857.         m_x2 = m_x + m_w;
  858.         m_y2 = m_y + m_h;
  859.         f_oldloc.x = plr->mo->x;
  860.         f_oldloc.y = plr->mo->y;
  861.  
  862.         //  m_x = FTOM(MTOF(plr->mo->x - m_w/2));
  863.         //  m_y = FTOM(MTOF(plr->mo->y - m_h/2));
  864.         //  m_x = plr->mo->x - m_w/2;
  865.         //  m_y = plr->mo->y - m_h/2;
  866.  
  867.     }
  868.  
  869. }
  870.  
  871. //
  872. //
  873. //
  874. void AM_updateLightLev(void)
  875. {
  876.     static nexttic = 0;
  877.     //static int litelevels[] = { 0, 3, 5, 6, 6, 7, 7, 7 };
  878.     static int litelevels[] = { 0, 4, 7, 10, 12, 14, 15, 15 };
  879.     static int litelevelscnt = 0;
  880.    
  881.     // Change light level
  882.     if (amclock>nexttic)
  883.     {
  884.         lightlev = litelevels[litelevelscnt++];
  885.         if (litelevelscnt == sizeof(litelevels)/sizeof(int)) litelevelscnt = 0;
  886.         nexttic = amclock + 6 - (amclock % 6);
  887.     }
  888.  
  889. }
  890.  
  891.  
  892. //
  893. // Updates on Game Tick
  894. //
  895. void AM_Ticker (void)
  896. {
  897.  
  898.     if (!automapactive)
  899.         return;
  900.  
  901.     amclock++;
  902.  
  903.     if (followplayer)
  904.         AM_doFollowPlayer();
  905.  
  906.     // Change the zoom if necessary
  907.     if (ftom_zoommul != FRACUNIT)
  908.         AM_changeWindowScale();
  909.  
  910.     // Change x,y location
  911.     if (m_paninc.x || m_paninc.y)
  912.         AM_changeWindowLoc();
  913.  
  914.     // Update light level
  915.     // AM_updateLightLev();
  916.  
  917. }
  918.  
  919.  
  920. //
  921. // Clear automap frame buffer.
  922. //
  923. void AM_clearFB(int color)
  924. {
  925.     memset(fb, color, f_w*f_h);
  926. }
  927.  
  928.  
  929. //
  930. // Automap clipping of lines.
  931. //
  932. // Based on Cohen-Sutherland clipping algorithm but with a slightly
  933. // faster reject and precalculated slopes.  If the speed is needed,
  934. // use a hash algorithm to handle  the common cases.
  935. //
  936. boolean
  937. AM_clipMline
  938. ( mline_t*      ml,
  939.   fline_t*      fl )
  940. {
  941.     enum
  942.     {
  943.         LEFT    =1,
  944.         RIGHT   =2,
  945.         BOTTOM  =4,
  946.         TOP     =8
  947.     };
  948.     
  949.     register    outcode1 = 0;
  950.     register    outcode2 = 0;
  951.     register    outside;
  952.     
  953.     fpoint_t    tmp;
  954.     int         dx;
  955.     int         dy;
  956.  
  957.     
  958. #define DOOUTCODE(oc, mx, my) \
  959.     (oc) = 0; \
  960.     if ((my) < 0) (oc) |= TOP; \
  961.     else if ((my) >= f_h) (oc) |= BOTTOM; \
  962.     if ((mx) < 0) (oc) |= LEFT; \
  963.     else if ((mx) >= f_w) (oc) |= RIGHT;
  964.  
  965.     
  966.     // do trivial rejects and outcodes
  967.     if (ml->a.y > m_y2)
  968.         outcode1 = TOP;
  969.     else if (ml->a.y < m_y)
  970.         outcode1 = BOTTOM;
  971.  
  972.     if (ml->b.y > m_y2)
  973.         outcode2 = TOP;
  974.     else if (ml->b.y < m_y)
  975.         outcode2 = BOTTOM;
  976.     
  977.     if (outcode1 & outcode2)
  978.         return false; // trivially outside
  979.  
  980.     if (ml->a.x < m_x)
  981.         outcode1 |= LEFT;
  982.     else if (ml->a.x > m_x2)
  983.         outcode1 |= RIGHT;
  984.     
  985.     if (ml->b.x < m_x)
  986.         outcode2 |= LEFT;
  987.     else if (ml->b.x > m_x2)
  988.         outcode2 |= RIGHT;
  989.     
  990.     if (outcode1 & outcode2)
  991.         return false; // trivially outside
  992.  
  993.     // transform to frame-buffer coordinates.
  994.     fl->a.x = CXMTOF(ml->a.x);
  995.     fl->a.y = CYMTOF(ml->a.y);
  996.     fl->b.x = CXMTOF(ml->b.x);
  997.     fl->b.y = CYMTOF(ml->b.y);
  998.  
  999.     DOOUTCODE(outcode1, fl->a.x, fl->a.y);
  1000.     DOOUTCODE(outcode2, fl->b.x, fl->b.y);
  1001.  
  1002.     if (outcode1 & outcode2)
  1003.         return false;
  1004.  
  1005.     while (outcode1 | outcode2)
  1006.     {
  1007.         // may be partially inside box
  1008.         // find an outside point
  1009.         if (outcode1)
  1010.             outside = outcode1;
  1011.         else
  1012.             outside = outcode2;
  1013.         
  1014.         // clip to each side
  1015.         if (outside & TOP)
  1016.         {
  1017.             dy = fl->a.y - fl->b.y;
  1018.             dx = fl->b.x - fl->a.x;
  1019.             tmp.x = fl->a.x + (dx*(fl->a.y))/dy;
  1020.             tmp.y = 0;
  1021.         }
  1022.         else if (outside & BOTTOM)
  1023.         {
  1024.             dy = fl->a.y - fl->b.y;
  1025.             dx = fl->b.x - fl->a.x;
  1026.             tmp.x = fl->a.x + (dx*(fl->a.y-f_h))/dy;
  1027.             tmp.y = f_h-1;
  1028.         }
  1029.         else if (outside & RIGHT)
  1030.         {
  1031.             dy = fl->b.y - fl->a.y;
  1032.             dx = fl->b.x - fl->a.x;
  1033.             tmp.y = fl->a.y + (dy*(f_w-1 - fl->a.x))/dx;
  1034.             tmp.x = f_w-1;
  1035.         }
  1036.         else if (outside & LEFT)
  1037.         {
  1038.             dy = fl->b.y - fl->a.y;
  1039.             dx = fl->b.x - fl->a.x;
  1040.             tmp.y = fl->a.y + (dy*(-fl->a.x))/dx;
  1041.             tmp.x = 0;
  1042.         }
  1043.  
  1044.         if (outside == outcode1)
  1045.         {
  1046.             fl->a = tmp;
  1047.             DOOUTCODE(outcode1, fl->a.x, fl->a.y);
  1048.         }
  1049.         else
  1050.         {
  1051.             fl->b = tmp;
  1052.             DOOUTCODE(outcode2, fl->b.x, fl->b.y);
  1053.         }
  1054.         
  1055.         if (outcode1 & outcode2)
  1056.             return false; // trivially outside
  1057.     }
  1058.  
  1059.     return true;
  1060. }
  1061. #undef DOOUTCODE
  1062.  
  1063.  
  1064. //
  1065. // Classic Bresenham w/ whatever optimizations needed for speed
  1066. //
  1067. void
  1068. AM_drawFline
  1069. ( fline_t*      fl,
  1070.   int           color )
  1071. {
  1072.     register int x;
  1073.     register int y;
  1074.     register int dx;
  1075.     register int dy;
  1076.     register int sx;
  1077.     register int sy;
  1078.     register int ax;
  1079.     register int ay;
  1080.     register int d;
  1081. /*    
  1082.     static fuck = 0;
  1083.  
  1084.     // For debugging only
  1085.  
  1086.     if (      fl->a.x < 0 || fl->a.x >= f_w
  1087.            || fl->a.y < 0 || fl->a.y >= f_h
  1088.            || fl->b.x < 0 || fl->b.x >= f_w
  1089.            || fl->b.y < 0 || fl->b.y >= f_h)
  1090.     {
  1091.         fprintf(stderr, "fuck %d \r", fuck++);
  1092.         return;
  1093.     }
  1094. */
  1095.  
  1096. #define PUTDOT(xx,yy,cc) fb[(yy+wy)*finit_width+(xx+wx)]=(cc)
  1097.  
  1098.     dx = fl->b.x - fl->a.x;
  1099.     ax = 2 * (dx<0 ? -dx : dx);
  1100.     sx = dx<0 ? -1 : 1;
  1101.  
  1102.     dy = fl->b.y - fl->a.y;
  1103.     ay = 2 * (dy<0 ? -dy : dy);
  1104.     sy = dy<0 ? -1 : 1;
  1105.  
  1106.     x = fl->a.x;
  1107.     y = fl->a.y;
  1108.  
  1109.     if (ax > ay)
  1110.     {
  1111.         d = ay - ax/2;
  1112.         while (1)
  1113.         {
  1114.             PUTDOT(x,y,color);
  1115.             if (x == fl->b.x) return;
  1116.             if (d>=0)
  1117.             {
  1118.                 y += sy;
  1119.                 d -= ax;
  1120.             }
  1121.             x += sx;
  1122.             d += ay;
  1123.         }
  1124.     }
  1125.     else
  1126.     {
  1127.         d = ax - ay/2;
  1128.         while (1)
  1129.         {
  1130.             PUTDOT(x, y, color);
  1131.             if (y == fl->b.y) return;
  1132.             if (d >= 0)
  1133.             {
  1134.                 x += sx;
  1135.                 d -= ay;
  1136.             }
  1137.             y += sy;
  1138.             d += ax;
  1139.         }
  1140.     }
  1141. }
  1142.  
  1143.  
  1144.  
  1145. //
  1146. // Clip lines, draw visible part sof lines.
  1147. //
  1148. void
  1149. AM_drawMline
  1150. ( mline_t*      ml,
  1151.   int           color )
  1152. {
  1153.     static fline_t fl;
  1154.     mline_t     l;
  1155.  
  1156.     /* Rotate Map Patch - CDE 98' */
  1157.     if(rotatemap) {
  1158.         l.a.x = ml->a.x-plr->mo->x;
  1159.         l.a.y = ml->a.y-plr->mo->y;
  1160.         l.b.x = ml->b.x-plr->mo->x;
  1161.         l.b.y = ml->b.y-plr->mo->y;
  1162.  
  1163.         AM_rotate(&l.a.x, &l.a.y, ANG90-plr->mo->angle);
  1164.         AM_rotate(&l.b.x, &l.b.y, ANG90-plr->mo->angle);
  1165.  
  1166.         l.a.x += plr->mo->x;
  1167.         l.a.y += plr->mo->y;
  1168.         l.b.x += plr->mo->x;
  1169.         l.b.y += plr->mo->y;
  1170.  
  1171.         if (AM_clipMline(&l, &fl))
  1172.             AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
  1173.     } else {
  1174.         if (AM_clipMline(ml, &fl))
  1175.             AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
  1176.     }
  1177. }
  1178.  
  1179.  
  1180.  
  1181. //
  1182. // Draws flat (floor/ceiling tile) aligned grid lines.
  1183. //
  1184. void AM_drawGrid(int color)
  1185. {
  1186.     fixed_t x, y;
  1187.     fixed_t start, end;
  1188.     mline_t ml;
  1189.  
  1190.     // Figure out start of vertical gridlines
  1191.     start = m_x;
  1192.     if ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS))
  1193.         start += (MAPBLOCKUNITS<<FRACBITS)
  1194.             - ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS));
  1195.     end = m_x + m_w;
  1196.  
  1197.     // draw vertical gridlines
  1198.     ml.a.y = m_y;
  1199.     ml.b.y = m_y+m_h;
  1200.     for (x=start; x<end; x+=(MAPBLOCKUNITS<<FRACBITS))
  1201.     {
  1202.         ml.a.x = x;
  1203.         ml.b.x = x;
  1204.         AM_drawMline(&ml, color);
  1205.     }
  1206.  
  1207.     // Figure out start of horizontal gridlines
  1208.     start = m_y;
  1209.     if ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS))
  1210.         start += (MAPBLOCKUNITS<<FRACBITS)
  1211.             - ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS));
  1212.     end = m_y + m_h;
  1213.  
  1214.     // draw horizontal gridlines
  1215.     ml.a.x = m_x;
  1216.     ml.b.x = m_x + m_w;
  1217.     for (y=start; y<end; y+=(MAPBLOCKUNITS<<FRACBITS))
  1218.     {
  1219.         ml.a.y = y;
  1220.         ml.b.y = y;
  1221.         AM_drawMline(&ml, color);
  1222.     }
  1223.  
  1224. }
  1225.  
  1226. //
  1227. // Determines visible lines, draws them.
  1228. // This is LineDef based, not LineSeg based.
  1229. //
  1230. void AM_drawWalls(void)
  1231. {
  1232.     int i;
  1233.     static mline_t l;
  1234.  
  1235.     for (i=0;i<numlines;i++)
  1236.     {
  1237.         l.a.x = lines[i].v1->x;
  1238.         l.a.y = lines[i].v1->y;
  1239.         l.b.x = lines[i].v2->x;
  1240.         l.b.y = lines[i].v2->y;
  1241.         if (cheating || (lines[i].flags & ML_MAPPED))
  1242.         {
  1243.             if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
  1244.                 continue;
  1245.             if (!lines[i].backsector)
  1246.             {
  1247.                 AM_drawMline(&l, WALLCOLORS+lightlev);
  1248.             }
  1249.             else
  1250.             {
  1251.                 if (lines[i].special == 39)
  1252.                 { // teleporters
  1253.                     AM_drawMline(&l, WALLCOLORS+WALLRANGE/2);
  1254.                 }
  1255.                 else if (lines[i].flags & ML_SECRET) // secret door
  1256.                 {
  1257.                     if (cheating) AM_drawMline(&l, SECRETWALLCOLORS + lightlev);
  1258.                     else AM_drawMline(&l, WALLCOLORS+lightlev);
  1259.                 }
  1260.                 else if (lines[i].backsector->floorheight
  1261.                            != lines[i].frontsector->floorheight) {
  1262.                     AM_drawMline(&l, FDWALLCOLORS + lightlev); // floor level change
  1263.                 }
  1264.                 else if (lines[i].backsector->ceilingheight
  1265.                            != lines[i].frontsector->ceilingheight) {
  1266.                     AM_drawMline(&l, CDWALLCOLORS+lightlev); // ceiling level change
  1267.                 }
  1268.                 else if (cheating) {
  1269.                     AM_drawMline(&l, TSWALLCOLORS+lightlev);
  1270.                 }
  1271.             }
  1272.         }
  1273.         else if (plr->powers[pw_allmap])
  1274.         {
  1275.             if (!(lines[i].flags & LINE_NEVERSEE)) AM_drawMline(&l, GRAYS+3);
  1276.         }
  1277.     }
  1278. }
  1279.  
  1280. void
  1281. AM_drawLineCharacter
  1282. ( mline_t*      lineguy,
  1283.   int           lineguylines,
  1284.   fixed_t       scale,
  1285.   angle_t       angle,
  1286.   int           color,
  1287.   fixed_t       x,
  1288.   fixed_t       y )
  1289. {
  1290.     int         i;
  1291.     mline_t     l;
  1292.  
  1293.     for (i=0;i<lineguylines;i++)
  1294.     {
  1295.         l.a.x = lineguy[i].a.x;
  1296.         l.a.y = lineguy[i].a.y;
  1297.  
  1298.         if (scale)
  1299.         {
  1300.             l.a.x = FixedMul(scale, l.a.x);
  1301.             l.a.y = FixedMul(scale, l.a.y);
  1302.         }
  1303.  
  1304.         if (angle)
  1305.             AM_rotate(&l.a.x, &l.a.y, angle);
  1306.  
  1307.         l.a.x += x;
  1308.         l.a.y += y;
  1309.  
  1310.         l.b.x = lineguy[i].b.x;
  1311.         l.b.y = lineguy[i].b.y;
  1312.  
  1313.         if (scale)
  1314.         {
  1315.             l.b.x = FixedMul(scale, l.b.x);
  1316.             l.b.y = FixedMul(scale, l.b.y);
  1317.         }
  1318.  
  1319.         if (angle)
  1320.             AM_rotate(&l.b.x, &l.b.y, angle);
  1321.         
  1322.         l.b.x += x;
  1323.         l.b.y += y;
  1324.  
  1325.         AM_drawMline(&l, color);
  1326.     }
  1327. }
  1328.  
  1329. void AM_drawPlayers(void)
  1330. {
  1331.     int         i;
  1332.     player_t*   p;
  1333.     static int  their_colors[] = { GREENS, GRAYS, BROWNS, REDS };
  1334.     int         their_color = -1;
  1335.     int         color;
  1336.  
  1337.     if (!netgame)
  1338.     {
  1339.         if (cheating)
  1340.             AM_drawLineCharacter
  1341.                 (cheat_player_arrow, NUMCHEATPLYRLINES, 0,
  1342.                  plr->mo->angle, WHITE, plr->mo->x, plr->mo->y);
  1343.         else
  1344.             AM_drawLineCharacter
  1345.                 (player_arrow, NUMPLYRLINES, 0, plr->mo->angle,
  1346.                  WHITE, plr->mo->x, plr->mo->y);
  1347.         return;
  1348.     }
  1349.  
  1350.     for (i=0;i<MAXPLAYERS;i++)
  1351.     {
  1352.         their_color++;
  1353.         p = &players[i];
  1354.  
  1355.         if ( (deathmatch && !singledemo) && p != plr)
  1356.             continue;
  1357.  
  1358.         if (!playeringame[i])
  1359.             continue;
  1360.  
  1361.         if (p->powers[pw_invisibility])
  1362.             color = 246; // *close* to black
  1363.         else
  1364.             color = their_colors[their_color];
  1365.         
  1366.         AM_drawLineCharacter
  1367.             (player_arrow, NUMPLYRLINES, 0, p->mo->angle,
  1368.              color, p->mo->x, p->mo->y);
  1369.     }
  1370.  
  1371. }
  1372.  
  1373. void
  1374. AM_drawThings
  1375. ( int   colors,
  1376.   int   colorrange)
  1377. {
  1378.     int         i;
  1379.     mobj_t*     t;
  1380.  
  1381.     for (i=0;i<numsectors;i++)
  1382.     {
  1383.         t = sectors[i].thinglist;
  1384.         while (t)
  1385.         {
  1386.             AM_drawLineCharacter
  1387.                 (thintriangle_guy, NUMTHINTRIANGLEGUYLINES,
  1388.                  16<<FRACBITS, t->angle, colors+lightlev, t->x, t->y);
  1389.             t = t->snext;
  1390.         }
  1391.     }
  1392. }
  1393.  
  1394. void AM_drawMarks(void)
  1395. {
  1396.     int i, fx, fy, w, h;
  1397.     fixed_t x,y;
  1398.  
  1399.  
  1400.     for (i=0;i<AM_NUMMARKPOINTS;i++)
  1401.     {
  1402.         if (markpoints[i].x != -1)
  1403.         {
  1404.             //      w = SWAPSHORT(marknums[i]->width);
  1405.             //      h = SWAPSHORT(marknums[i]->height);
  1406.             w = 5; // because something's wrong with the wad, i guess
  1407.             h = 6; // because something's wrong with the wad, i guess
  1408.  
  1409.             /* CDE'98 Rotate Map Patch - Now rotate marks :) */
  1410.             if(rotatemap)
  1411.             {
  1412.                 x=markpoints[i].x-plr->mo->x;
  1413.                 y=markpoints[i].y-plr->mo->y;
  1414.                 AM_rotate(&x, &y, ANG90-plr->mo->angle);
  1415.                 x += plr->mo->x;
  1416.                 y += plr->mo->y;
  1417.                 fx = CXMTOF(x);
  1418.                 fy = CYMTOF(y);
  1419.             } else {
  1420.                 fx = CXMTOF(markpoints[i].x);
  1421.                 fy = CYMTOF(markpoints[i].y);
  1422.             }
  1423.  
  1424.             if (fx >= f_x  && fx <= f_w - w && fy >= f_y && fy <= f_h - h)
  1425.                 V_DrawPatch(fx+wx, fy+wy, FB, marknums[i]);
  1426.         }
  1427.     }
  1428. }
  1429.  
  1430. void AM_drawCrosshair(int color)
  1431. {
  1432.     /* CDE'98 - Crosshair on the view center whatever size/mode ! */
  1433.  
  1434.  
  1435.     fb[((viewwidth+2*viewwindowx)*(viewheight+2*viewwindowy+1))/2] = color; // single point for now
  1436. }
  1437.  
  1438. void AM_Drawer (void)
  1439. {
  1440.     if (!automapactive) return;
  1441.  
  1442.     /* Map On HeadUp Patch - CDE 98' */
  1443.     if(!maponhu)
  1444.         AM_clearFB(BACKGROUND);
  1445.  
  1446.     if (grid)
  1447.         AM_drawGrid(GRIDCOLORS);
  1448.     AM_drawWalls();
  1449.     AM_drawPlayers();
  1450.     if (cheating==2)
  1451.         AM_drawThings(THINGCOLORS, THINGRANGE);
  1452.     AM_drawCrosshair(XHAIRCOLORS);
  1453.  
  1454.     AM_drawMarks();
  1455.  
  1456.     I_MarkRect(f_x, f_y, f_w, f_h);
  1457.  
  1458. }
  1459.