MAP2D.CPP 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. #include <string.h>
  2. #include "engine.h"
  3. #include "map2d.h"
  4. #include "helix.h"
  5. #include "gameutil.h"
  6. #include "trig.h"
  7. #include "misc.h"
  8. #include "gfx.h"
  9. #include "view.h"
  10. #include "debug4g.h"
  11. #include "actor.h"
  12. #include "options.h"
  13. #include <memcheck.h>
  14. static scaleX, scaleY;
  15. static void ScaleLine(long x0, long y0, long x1, long y1, int nColor)
  16. {
  17. x0 = (gViewXCenter << 8) + mulscale16(x0, scaleX);
  18. y0 = (gViewYCenter << 8) + mulscale16(y0, scaleY);
  19. x1 = (gViewXCenter << 8) + mulscale16(x1, scaleX);
  20. y1 = (gViewYCenter << 8) + mulscale16(y1, scaleY);
  21. gfxDrawLine( x0, y0, x1, y1, nColor );
  22. }
  23. void DrawMap(int x, int y, int ang, int zoom)
  24. {
  25. int i, j;
  26. long x0, y0, x1, y1, x2, y2;
  27. int nSector1, nSector2;
  28. char nColor;
  29. gfxSetClip(gViewX0, gViewY0, gViewX1, gViewY1);
  30. scaleX = zoom * xdim * 3 / 4;
  31. scaleY = zoom * ydim;
  32. for (i = 0; i < numwalls; i++)
  33. {
  34. j = wall[i].nextwall;
  35. // only draw one side of walls
  36. if ( i < j )
  37. continue;
  38. if ( gFullMap || TestBitString(show2dwall, i) )
  39. {
  40. nColor = 0;
  41. if (j == -1)
  42. nColor = 0x8F; // red
  43. else
  44. {
  45. nSector1 = wall[j].nextsector;
  46. nSector2 = wall[i].nextsector;
  47. if (( sector[nSector1].ceilingz != sector[nSector2].ceilingz )
  48. && (!(sector[nSector1].ceilingstat & 1) && !(sector[nSector2].ceilingstat & 1)) )
  49. nColor = 0xF6; // yellow
  50. if ( sector[nSector1].floorz != sector[nSector2].floorz )
  51. nColor = 0x3B; // light brown
  52. }
  53. if (nColor == 0)
  54. continue;
  55. ScaleLine(wall[i].x - x, wall[i].y - y,
  56. wall[wall[i].point2].x - x, wall[wall[i].point2].y - y,
  57. nColor);
  58. }
  59. }
  60. if ( zoom >= 256 )
  61. {
  62. for (i = 0; i < numsectors; i++)
  63. {
  64. j = headspritesect[i];
  65. while (j != -1)
  66. {
  67. if ( gFullMap || TestBitString(show2dsprite, j) )
  68. {
  69. SPRITE *pSprite = &sprite[j];
  70. nColor = 43;
  71. if ((pSprite->cstat & kSpriteBlocking) > 0)
  72. nColor = 69;
  73. switch ( pSprite->cstat & kSpriteRMask )
  74. {
  75. case kSpriteFloor: // floor sprite
  76. break;
  77. case kSpriteWall: // wall sprite
  78. break;
  79. default:
  80. break;
  81. }
  82. x0 = mulscale16(pSprite->x - x, scaleX);
  83. y0 = mulscale16(pSprite->y - y, scaleY);
  84. //Draw sprite
  85. x0 = x1 = x2 =pSprite->clipdist << 2;
  86. y0 = y1 = y2 = 0;
  87. RotateVector(&x0, &y0, pSprite->ang);
  88. RotateVector(&x1, &y1, pSprite->ang + kAngle120);
  89. RotateVector(&x2, &y2, pSprite->ang - kAngle120);
  90. x0 += pSprite->x - x;
  91. y0 += pSprite->y - y;
  92. x1 += pSprite->x - x;
  93. y1 += pSprite->y - y;
  94. x2 += pSprite->x - x;
  95. y2 += pSprite->y - y;
  96. ScaleLine(x0, y0, x1, y1, nColor);
  97. ScaleLine(x1, y1, x2, y2, nColor);
  98. ScaleLine(x2, y2, x0, y0, nColor);
  99. }
  100. j = nextspritesect[j];
  101. }
  102. }
  103. }
  104. //Draw player
  105. x0 = 0x200;
  106. y0 = 0;
  107. x1 = -0x200;
  108. y1 = 0;
  109. RotateVector(&x0, &y0, ang);
  110. RotateVector(&x1, &y1, ang);
  111. ScaleLine(x0, y0, x1, y1, 0x18);
  112. x1 = 0x180;
  113. y1 = -0x80;
  114. RotateVector(&x1, &y1, ang);
  115. ScaleLine(x0, y0, x1, y1, 0x18);
  116. x1 = 0x180;
  117. y1 = 0x80;
  118. RotateVector(&x1, &y1, ang);
  119. ScaleLine(x0, y0, x1, y1, 0x18);
  120. x0 = -0x200;
  121. y0 = 0;
  122. RotateVector(&x0, &y0, ang);
  123. x1 = -0x280;
  124. y1 = -0x80;
  125. RotateVector(&x1, &y1, ang);
  126. ScaleLine(x0, y0, x1, y1, 0x18);
  127. x1 = -0x280;
  128. y1 = 0x80;
  129. RotateVector(&x1, &y1, ang);
  130. ScaleLine(x0, y0, x1, y1, 0x18);
  131. x0 = -0x180;
  132. y0 = 0;
  133. RotateVector(&x0, &y0, ang);
  134. x1 = -0x200;
  135. y1 = -0x80;
  136. RotateVector(&x1, &y1, ang);
  137. ScaleLine(x0, y0, x1, y1, 0x18);
  138. x1 = -0x200;
  139. y1 = 0x80;
  140. RotateVector(&x1, &y1, ang);
  141. ScaleLine(x0, y0, x1, y1, 0x18);
  142. x0 = -0x100;
  143. y0 = 0;
  144. RotateVector(&x0, &y0, ang);
  145. x1 = -0x180;
  146. y1 = -0x80;
  147. RotateVector(&x1, &y1, ang);
  148. ScaleLine(x0, y0, x1, y1, 0x18);
  149. x1 = -0x180;
  150. y1 = 0x80;
  151. RotateVector(&x1, &y1, ang);
  152. ScaleLine(x0, y0, x1, y1, 0x18);
  153. }
  154. #if 0
  155. int drawoverheadmap(long cposx, long cposy, long czoom, short cang)
  156. {
  157. long i, j, k, l, x1, y1, x2, y2, x3, y3, x4, y4, ox, oy, xoff, yoff;
  158. long xvect, yvect, dax, day, cosang, sinang, xspan, yspan;
  159. long xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum;
  160. short daang;
  161. char col;
  162. WALL *wal, *wal2;
  163. SPRITE *spr;
  164. xvect = mulscale(Sin(-cang), czoom, 16);
  165. yvect = mulscale(Cos(-cang), czoom, 16);
  166. //Draw red lines
  167. for(i=0;i<numsectors;i++)
  168. {
  169. startwall = sector[i].wallptr;
  170. endwall = sector[i].wallptr + sector[i].wallnum - 1;
  171. z1 = sector[i].ceilingz; z2 = sector[i].floorz;
  172. for(j=startwall,wal=&wall[startwall];j<=endwall;j++,wal++)
  173. {
  174. k = wal->nextwall; if (k < 0) continue;
  175. if ( !TestBitString(show2dwall, j) )
  176. continue;
  177. if ((k > j) && ShowBitString(show2dwall, k) )
  178. continue;
  179. if (sector[wal->nextsector].ceilingz == z1)
  180. if (sector[wal->nextsector].floorz == z2)
  181. if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) continue;
  182. col = 152;
  183. if (gViewMode == kView2DIcon)
  184. {
  185. if (sector[i].floorz != sector[i].ceilingz)
  186. if (sector[wal->nextsector].floorz != sector[wal->nextsector].ceilingz)
  187. if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0)
  188. if (sector[i].floorz == sector[wal->nextsector].floorz) continue;
  189. if (sector[i].floorpicnum != sector[wal->nextsector].floorpicnum) continue;
  190. if (sector[i].floorshade != sector[wal->nextsector].floorshade) continue;
  191. col = 12;
  192. }
  193. ox = wal->x-cposx; oy = wal->y-cposy;
  194. x1 = mulscale16(ox, xvect) - mulscale16(oy,yvect);
  195. y1 = mulscale16(oy, xvect) + mulscale16(ox,yvect);
  196. wal2 = &wall[wal->point2];
  197. ox = wal2->x-cposx; oy = wal2->y-cposy;
  198. x2 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  199. y2 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  200. drawline256(x1+(xdim<<11),y1+(ydim<<11),x2+(xdim<<11),y2+(ydim<<11),col);
  201. }
  202. }
  203. //Draw sprites
  204. k = gView->nSprite;
  205. for(i=0;i<numsectors;i++)
  206. for(j=headspritesect[i];j>=0;j=nextspritesect[j])
  207. if ( TestBitString(show2dsprite, j) )
  208. {
  209. spr = &sprite[j];
  210. col = 56;
  211. if ((spr->cstat&1) > 0) col = 248;
  212. if (j == k) col = 31;
  213. switch (spr->cstat&48)
  214. {
  215. case 0:
  216. ox = spr->x-cposx; oy = spr->y-cposy;
  217. x1 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  218. y1 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  219. if (gViewMode == kView2D)
  220. {
  221. ox = Cos(spr->ang) >> 23;
  222. oy = Sin(spr->ang) >> 23;
  223. x2 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  224. y2 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  225. if (j == gView->nSprite)
  226. {
  227. x1 = 0L;
  228. y1 = (64L<<12);
  229. x2 = 0L;
  230. y2 = -(czoom<<5);
  231. }
  232. drawline256(x1-x2+(xdim<<11),y1-y2+(ydim<<11),
  233. x1+x2+(xdim<<11),y1+y2+(ydim<<11),col);
  234. drawline256(x1-y2+(xdim<<11),y1+x2+(ydim<<11),
  235. x1+x2+(xdim<<11),y1+y2+(ydim<<11),col);
  236. drawline256(x1+y2+(xdim<<11),y1-x2+(ydim<<11),
  237. x1+x2+(xdim<<11),y1+y2+(ydim<<11),col);
  238. }
  239. else if (gViewMode == kView2DIcon)
  240. {
  241. if (((gotsector[i>>3]&(1<<(i&7))) > 0) && (czoom > 192))
  242. {
  243. daang = (short)((spr->ang-cang) & kAngleMask);
  244. if (j == gView->nSprite)
  245. { x1 = 0; y1 = (4096*64); daang = 0; }
  246. rotatesprite((x1<<4)+(xdim<<16),(y1<<4)+(ydim<<16),czoom*spr->yrepeat,daang,spr->picnum,spr->shade,spr->pal,
  247. spr->cstat & kSpriteTranslucent ? 1 : 0);
  248. }
  249. }
  250. break;
  251. case 16:
  252. x1 = spr->x; y1 = spr->y;
  253. tilenum = spr->picnum;
  254. xoff = picanm[tilenum].xcenter + spr->xoffset;
  255. if ((spr->cstat&4) > 0) xoff = -xoff;
  256. k = spr->ang; l = spr->xrepeat;
  257. dax = Sin(k) * l >> 16;
  258. day = Cos(k) * l >> 16;
  259. l = tilesizx[tilenum]; k = (l>>1)+xoff;
  260. x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l);
  261. y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l);
  262. ox = x1-cposx; oy = y1-cposy;
  263. x1 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  264. y1 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  265. ox = x2-cposx; oy = y2-cposy;
  266. x2 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  267. y2 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  268. drawline256(x1+(xdim<<11),y1+(ydim<<11),
  269. x2+(xdim<<11),y2+(ydim<<11),col);
  270. break;
  271. case 32:
  272. if (gViewMode == kView2D)
  273. {
  274. tilenum = spr->picnum;
  275. xoff = (long)(picanm[tilenum].xcenter + spr->xoffset);
  276. yoff = (long)(picanm[tilenum].ycenter + spr->yoffset);
  277. if ((spr->cstat&4) > 0) xoff = -xoff;
  278. if ((spr->cstat&8) > 0) yoff = -yoff;
  279. k = spr->ang;
  280. cosang = Cos(k) >> 16;
  281. sinang = Sin(k) >> 16;
  282. xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat;
  283. yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat;
  284. dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat;
  285. x1 = spr->x + mulscale16(sinang,dax) + mulscale16(cosang,day);
  286. y1 = spr->y + mulscale16(sinang,day) - mulscale16(cosang,dax);
  287. l = xspan*xrepeat;
  288. x2 = x1 - mulscale16(sinang,l);
  289. y2 = y1 + mulscale16(cosang,l);
  290. l = yspan*yrepeat;
  291. k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k;
  292. k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k;
  293. ox = x1-cposx; oy = y1-cposy;
  294. x1 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  295. y1 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  296. ox = x2-cposx; oy = y2-cposy;
  297. x2 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  298. y2 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  299. ox = x3-cposx; oy = y3-cposy;
  300. x3 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  301. y3 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  302. ox = x4-cposx; oy = y4-cposy;
  303. x4 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  304. y4 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  305. drawline256(x1+(xdim<<11),y1+(ydim<<11),
  306. x2+(xdim<<11),y2+(ydim<<11),col);
  307. drawline256(x2+(xdim<<11),y2+(ydim<<11),
  308. x3+(xdim<<11),y3+(ydim<<11),col);
  309. drawline256(x3+(xdim<<11),y3+(ydim<<11),
  310. x4+(xdim<<11),y4+(ydim<<11),col);
  311. drawline256(x4+(xdim<<11),y4+(ydim<<11),
  312. x1+(xdim<<11),y1+(ydim<<11),col);
  313. }
  314. break;
  315. }
  316. }
  317. //Draw white lines
  318. for(i=0;i<numsectors;i++)
  319. {
  320. startwall = sector[i].wallptr;
  321. endwall = sector[i].wallptr + sector[i].wallnum - 1;
  322. for(j=startwall,wal=&wall[startwall];j<=endwall;j++,wal++)
  323. {
  324. if (wal->nextwall >= 0) continue;
  325. if ( !TestBitString(show2dwall, j) ) continue;
  326. ox = wal->x-cposx; oy = wal->y-cposy;
  327. x1 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  328. y1 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  329. wal2 = &wall[wal->point2];
  330. ox = wal2->x-cposx; oy = wal2->y-cposy;
  331. x2 = mulscale16(ox,xvect) - mulscale16(oy,yvect);
  332. y2 = mulscale16(oy,xvect) + mulscale16(ox,yvect);
  333. drawline256(x1+(xdim<<11),y1+(ydim<<11),x2+(xdim<<11),y2+(ydim<<11),24);
  334. }
  335. }
  336. return 0;
  337. }
  338. #endif