wolf_level.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  1. /*
  2. Copyright (C) 2004-2005 Michael Liebscher
  3. Copyright (C) 2000-2002 by DarkOne the Hacker
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * wolf_level.c: Wolfenstein3-D Level management.
  18. *
  19. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  20. * Date: 2004
  21. *
  22. * Acknowledgement:
  23. * Portion of this code was derived from NewWolf, and was originally
  24. * written by DarkOne the Hacker.
  25. *
  26. * Acknowledgement:
  27. * Portion of this code was derived from Wolfenstein 3-D, and was originally
  28. * written by Id Software, Inc.
  29. *
  30. */
  31. #include "../wolfiphone.h"
  32. statinfo_t static_wl6[]=
  33. {
  34. {false, -1}, // puddle spr1v
  35. { true, -1}, // Green Barrel "
  36. { true, -1}, // Table/chairs "
  37. { true, -1}, // Floor lamp "
  38. {false, -1}, // Chandelier "
  39. { true, -1}, // Hanged man "
  40. {false, pow_alpo}, // Bad food "
  41. { true, -1}, // Red pillar "
  42. { true, -1}, // Tree spr2v
  43. {false, -1}, // Skeleton flat "
  44. { true, -1}, // Sink " (SOD:gibs)
  45. { true, -1}, // Potted plant "
  46. { true, -1}, // Urn "
  47. { true, -1}, // Bare table "
  48. {false, -1}, // Ceiling light "
  49. {false, -1}, // Kitchen stuff "
  50. { true, -1}, // suit of armor spr3v
  51. { true, -1}, // Hanging cage "
  52. { true, -1}, // SkeletoninCage "
  53. {false, -1}, // Skeleton relax "
  54. {false, pow_key1}, // Key 1 "
  55. {false, pow_key2}, // Key 2 "
  56. { true, -1}, // stuff (SOD:gibs)
  57. {false, -1}, // stuff
  58. {false, pow_food}, // Good food spr4v
  59. {false, pow_firstaid}, // First aid "
  60. {false, pow_clip}, // Clip "
  61. {false, pow_machinegun},// Machine gun "
  62. {false, pow_chaingun}, // Gatling gun "
  63. {false, pow_cross}, // Cross "
  64. {false, pow_chalice}, // Chalice "
  65. {false, pow_bible}, // Bible "
  66. {false, pow_crown}, // crown spr5v
  67. {false, pow_fullheal}, // one up "
  68. {false, pow_gibs}, // gibs "
  69. { true, -1}, // barrel "
  70. { true, -1}, // well "
  71. { true, -1}, // Empty well "
  72. {false, pow_gibs}, // Gibs 2 "
  73. { true, -1}, // flag "
  74. { true, -1}, // Call Apogee spr7v
  75. {false, -1}, // junk "
  76. {false, -1}, // junk "
  77. {false, -1}, // junk "
  78. {false, -1}, // pots "
  79. { true, -1}, // stove " (SOD:gibs)
  80. { true, -1}, // spears " (SOD:gibs)
  81. {false, -1}, // vines "
  82. };
  83. statinfo_t static_sod[] =
  84. {
  85. {false, -1}, // puddle spr1v
  86. { true, -1}, // Green Barrel "
  87. { true, -1}, // Table/chairs "
  88. { true, -1}, // Floor lamp "
  89. {false, -1}, // Chandelier "
  90. { true, -1}, // Hanged man "
  91. {false, pow_alpo}, // Bad food "
  92. { true, -1}, // Red pillar "
  93. { true, -1}, // Tree spr2v
  94. {false, -1}, // Skeleton flat "
  95. { true, -1}, // Sink " (SOD:gibs)
  96. { true, -1}, // Potted plant "
  97. { true, -1}, // Urn "
  98. { true, -1}, // Bare table "
  99. {false, -1}, // Ceiling light "
  100. { true, -1}, // Gibs!
  101. { true, -1}, // suit of armor spr3v
  102. { true, -1}, // Hanging cage "
  103. { true, -1}, // SkeletoninCage "
  104. {false, -1}, // Skeleton relax "
  105. {false, pow_key1}, // Key 1 "
  106. {false, pow_key2}, // Key 2 "
  107. { true, -1}, // stuff (SOD:gibs)
  108. {false, -1}, // stuff
  109. {false, pow_food}, // Good food spr4v
  110. {false, pow_firstaid}, // First aid "
  111. {false, pow_clip}, // Clip "
  112. {false, pow_machinegun},// Machine gun "
  113. {false, pow_chaingun}, // Gatling gun "
  114. {false, pow_cross}, // Cross "
  115. {false, pow_chalice}, // Chalice "
  116. {false, pow_bible}, // Bible "
  117. {false, pow_crown}, // crown spr5v
  118. {false, pow_fullheal}, // one up "
  119. {false, pow_gibs}, // gibs "
  120. { true, -1}, // barrel "
  121. { true, -1}, // well "
  122. { true, -1}, // Empty well "
  123. {false, pow_gibs}, // Gibs 2 "
  124. { true, -1}, // flag "
  125. {false, -1}, // Red light
  126. {false, -1}, // junk "
  127. {false, -1}, // junk "
  128. {false, -1}, // junk "
  129. { true, -1}, // Gibs!
  130. { true, -1}, // stove " (SOD:gibs)
  131. { true, -1}, // spears " (SOD:gibs)
  132. {false, -1}, // vines "
  133. { true, -1}, // marble pillar
  134. {false, pow_25clip}, // bonus 25 clip
  135. { true, -1}, // truck
  136. {false, pow_spear}, // SPEAR OF DESTINY!
  137. };
  138. statinfo_t *statinfo = static_wl6;
  139. int num_statics = sizeof( static_wl6 ) / sizeof( static_wl6[ 0 ] );
  140. texture_t *wallTextures[1000];
  141. texture_t *spriteTextures[1000];
  142. PRIVATE W16 cachedGuard = 0;
  143. PRIVATE W16 cachedOfficer = 0;
  144. PRIVATE W16 cachedSS = 0;
  145. PRIVATE W16 cachedDog = 0;
  146. PRIVATE W16 cachedMutant = 0;
  147. PRIVATE int progress_bar = 0;
  148. LevelData_t levelData;
  149. void CacheTextures( W16 start, W16 end )
  150. {
  151. W16 i;
  152. static char texname[ 64 ];
  153. for( i = start ; i <= end ; ++i )
  154. {
  155. if ( !spriteTextures[i] ) {
  156. my_snprintf( texname, sizeof( texname ), "%s/%.3d.tga", spritelocation, i );
  157. spriteTextures[i] = TM_FindTexture( texname, TT_Sprite );
  158. }
  159. }
  160. }
  161. /*
  162. -----------------------------------------------------------------------------
  163. Function: Level_ScanInfoPlane -Spawn all actors and mark down special places.
  164. Parameters:
  165. Returns:
  166. Notes:
  167. -----------------------------------------------------------------------------
  168. */
  169. PUBLIC void Level_ScanInfoPlane( LevelData_t *lvl )
  170. {
  171. int x, y;
  172. W16 tile;
  173. cachedGuard = 0;
  174. cachedOfficer = 0;
  175. cachedSS = 0;
  176. cachedDog = 0;
  177. cachedMutant = 0;
  178. progress_bar = 0;
  179. for( y = 0 ; y < 64; ++y )
  180. {
  181. for( x = 0 ; x < 64 ; ++x )
  182. {
  183. tile = lvl->Plane2[ (63 - y) * 64 + x ];
  184. if( ! tile )
  185. {
  186. continue;
  187. }
  188. switch( tile )
  189. {
  190. //
  191. // guard
  192. //
  193. case 180:
  194. case 181:
  195. case 182:
  196. case 183:
  197. if( skill->value < gd_hard )
  198. break;
  199. tile -= 36;
  200. case 144:
  201. case 145:
  202. case 146:
  203. case 147:
  204. if( skill->value < gd_medium )
  205. break;
  206. tile -= 36;
  207. case 108:
  208. case 109:
  209. case 110:
  210. case 111:
  211. if( ! cachedGuard )
  212. {
  213. CacheTextures( SPR_GRD_S_1, SPR_GRD_SHOOT3 );
  214. cachedGuard = 1;
  215. }
  216. SpawnStand( en_guard, x, y, tile - 108, lvl );
  217. break;
  218. case 184:
  219. case 185:
  220. case 186:
  221. case 187:
  222. if( skill->value < gd_hard )
  223. break;
  224. tile -= 36;
  225. case 148:
  226. case 149:
  227. case 150:
  228. case 151:
  229. if( skill->value < gd_medium )
  230. break;
  231. tile -= 36;
  232. case 112:
  233. case 113:
  234. case 114:
  235. case 115:
  236. if( ! cachedGuard )
  237. {
  238. CacheTextures( SPR_GRD_S_1, SPR_GRD_SHOOT3 );
  239. cachedGuard = 1;
  240. }
  241. SpawnPatrol( en_guard, x, y,tile - 112 );
  242. break;
  243. case 124:
  244. SpawnDeadGuard( en_guard, x, y );
  245. break;
  246. //
  247. // officer
  248. //
  249. case 188:
  250. case 189:
  251. case 190:
  252. case 191:
  253. if( skill->value < gd_hard )
  254. break;
  255. tile -= 36;
  256. case 152:
  257. case 153:
  258. case 154:
  259. case 155:
  260. if( skill->value < gd_medium )
  261. break;
  262. tile -= 36;
  263. case 116:
  264. case 117:
  265. case 118:
  266. case 119:
  267. if( ! cachedOfficer )
  268. {
  269. CacheTextures( SPR_OFC_S_1, SPR_OFC_SHOOT3 );
  270. cachedOfficer = 1;
  271. }
  272. SpawnStand( en_officer, x, y, tile - 116, lvl );
  273. break;
  274. case 192:
  275. case 193:
  276. case 194:
  277. case 195:
  278. if( skill->value < gd_hard )
  279. break;
  280. tile -= 36;
  281. case 156:
  282. case 157:
  283. case 158:
  284. case 159:
  285. if( skill->value < gd_medium )
  286. break;
  287. tile -= 36;
  288. case 120:
  289. case 121:
  290. case 122:
  291. case 123:
  292. if( ! cachedOfficer )
  293. {
  294. CacheTextures( SPR_OFC_S_1, SPR_OFC_SHOOT3 );
  295. cachedOfficer = 1;
  296. }
  297. SpawnPatrol( en_officer, x, y, tile - 120 );
  298. break;
  299. //
  300. // SS
  301. //
  302. case 198:
  303. case 199:
  304. case 200:
  305. case 201:
  306. if( skill->value < gd_hard )
  307. break;
  308. tile -= 36;
  309. case 162:
  310. case 163:
  311. case 164:
  312. case 165:
  313. if( skill->value < gd_medium )
  314. break;
  315. tile -= 36;
  316. case 126:
  317. case 127:
  318. case 128:
  319. case 129:
  320. if( ! cachedSS )
  321. {
  322. CacheTextures( SPR_SS_S_1, SPR_SS_SHOOT3 );
  323. cachedSS = 1;
  324. }
  325. SpawnStand( en_ss, x, y, tile - 126, lvl );
  326. break;
  327. case 202:
  328. case 203:
  329. case 204:
  330. case 205:
  331. if( skill->value < gd_hard )
  332. break;
  333. tile -= 36;
  334. case 166:
  335. case 167:
  336. case 168:
  337. case 169:
  338. if( skill->value < gd_medium )
  339. break;
  340. tile -= 36;
  341. case 130:
  342. case 131:
  343. case 132:
  344. case 133:
  345. if( ! cachedSS )
  346. {
  347. CacheTextures( SPR_SS_S_1, SPR_SS_SHOOT3 );
  348. cachedSS = 1;
  349. }
  350. SpawnPatrol( en_ss, x, y, tile - 130 );
  351. break;
  352. //
  353. // dogs
  354. //
  355. case 206:
  356. case 207:
  357. case 208:
  358. case 209:
  359. if( skill->value < gd_hard )
  360. break;
  361. tile -= 36;
  362. case 170:
  363. case 171:
  364. case 172:
  365. case 173:
  366. if( skill->value < gd_medium )
  367. break;
  368. tile -= 36;
  369. case 134:
  370. case 135:
  371. case 136:
  372. case 137:
  373. if( ! cachedDog )
  374. {
  375. CacheTextures( SPR_DOG_W1_1, SPR_DOG_JUMP3 );
  376. cachedDog = 1;
  377. }
  378. SpawnStand( en_dog, x, y, tile - 134, lvl );
  379. break;
  380. case 210:
  381. case 211:
  382. case 212:
  383. case 213:
  384. if( skill->value < gd_hard )
  385. break;
  386. tile -= 36;
  387. case 174:
  388. case 175:
  389. case 176:
  390. case 177:
  391. if( skill->value < gd_medium )
  392. break;
  393. tile -= 36;
  394. case 138:
  395. case 139:
  396. case 140:
  397. case 141:
  398. if( ! cachedDog )
  399. {
  400. CacheTextures( SPR_DOG_W1_1, SPR_DOG_JUMP3 );
  401. cachedDog = 1;
  402. }
  403. SpawnPatrol( en_dog, x, y, tile - 138 );
  404. break;
  405. // bosses
  406. case 214:
  407. CacheTextures( SPR_BOSS_W1, SPR_BOSS_DIE3 );
  408. SpawnBoss( en_boss, x, y );
  409. break;
  410. case 197:
  411. CacheTextures( SPR_GRETEL_W1, SPR_GRETEL_DIE3 );
  412. SpawnBoss( en_gretel, x, y );
  413. break;
  414. case 215:
  415. CacheTextures( SPR_GIFT_W1, SPR_GIFT_DEAD );
  416. SpawnBoss( en_gift, x, y );
  417. break;
  418. case 179:
  419. CacheTextures( SPR_FAT_W1, SPR_FAT_DEAD );
  420. SpawnBoss( en_fat, x, y );
  421. break;
  422. case 196:
  423. CacheTextures( SPR_SCHABB_W1, SPR_HYPO4 );
  424. SpawnBoss( en_schabbs, x, y );
  425. break;
  426. case 160:
  427. CacheTextures( SPR_FAKE_W1, SPR_FAKE_DEAD );
  428. SpawnBoss( en_fake, x, y );
  429. break;
  430. case 178:
  431. CacheTextures( SPR_MECHA_W1, SPR_HITLER_DIE7 );
  432. SpawnBoss( en_mecha, x, y );
  433. break;
  434. //
  435. // Spear
  436. //
  437. case 106:
  438. CacheTextures( SPR_SPECTRE_W1, SPR_SPECTRE_F4 );
  439. SpawnBoss( en_spectre, x, y );
  440. break;
  441. case 107:
  442. CacheTextures( SPR_ANGEL_W1, SPR_ANGEL_DEAD );
  443. SpawnBoss( en_angel, x, y );
  444. break;
  445. case 125:
  446. CacheTextures( SPR_TRANS_W1, SPR_TRANS_DIE3 );
  447. SpawnBoss( en_trans, x, y );
  448. break;
  449. case 142:
  450. CacheTextures( SPR_UBER_W1, SPR_UBER_DEAD );
  451. SpawnBoss( en_uber, x, y );
  452. break;
  453. case 143:
  454. CacheTextures( SPR_WILL_W1, SPR_WILL_DEAD );
  455. SpawnBoss( en_will, x, y );
  456. break;
  457. case 161:
  458. CacheTextures( SPR_DEATH_W1, SPR_DEATH_DEAD );
  459. SpawnBoss( en_death, x, y );
  460. break;
  461. //
  462. // mutants
  463. //
  464. case 252:
  465. case 253:
  466. case 254:
  467. case 255:
  468. if( skill->value < gd_hard )
  469. break;
  470. tile -= 18;
  471. case 234:
  472. case 235:
  473. case 236:
  474. case 237:
  475. if( skill->value < gd_medium )
  476. break;
  477. tile -= 18;
  478. case 216:
  479. case 217:
  480. case 218:
  481. case 219:
  482. if( ! cachedMutant )
  483. {
  484. CacheTextures( SPR_MUT_S_1, SPR_MUT_SHOOT4 );
  485. cachedMutant = 1;
  486. }
  487. SpawnStand( en_mutant, x, y, tile - 216, lvl );
  488. break;
  489. case 256:
  490. case 257:
  491. case 258:
  492. case 259:
  493. if (skill->value<gd_hard)
  494. break;
  495. tile -= 18;
  496. case 238:
  497. case 239:
  498. case 240:
  499. case 241:
  500. if( skill->value < gd_medium )
  501. break;
  502. tile -= 18;
  503. case 220:
  504. case 221:
  505. case 222:
  506. case 223:
  507. if( ! cachedMutant )
  508. {
  509. CacheTextures( SPR_MUT_S_1, SPR_MUT_SHOOT4 );
  510. cachedMutant = 1;
  511. }
  512. SpawnPatrol( en_mutant, x, y, tile - 220 );
  513. break;
  514. //
  515. // ghosts
  516. //
  517. case 224:
  518. CacheTextures( SPR_BLINKY_W1, SPR_BLINKY_W2 );
  519. SpawnGhosts( en_blinky, x, y );
  520. break;
  521. case 225:
  522. CacheTextures( SPR_PINKY_W1, SPR_PINKY_W2 );
  523. SpawnGhosts( en_clyde, x, y );
  524. break;
  525. case 226:
  526. CacheTextures( SPR_CLYDE_W1, SPR_CLYDE_W2 );
  527. SpawnGhosts( en_pinky, x, y );
  528. break;
  529. case 227:
  530. CacheTextures( SPR_INKY_W1, SPR_INKY_W2 );
  531. SpawnGhosts( en_inky, x, y );
  532. break;
  533. }
  534. }
  535. }
  536. }
  537. /*
  538. -----------------------------------------------------------------------------
  539. Function:
  540. Parameters:
  541. Returns:
  542. Notes:
  543. -----------------------------------------------------------------------------
  544. */
  545. PRIVATE void Lvl_SpawnStatic( LevelData_t *lvl, int type, int x, int y )
  546. {
  547. int spr_id;
  548. if( statinfo[ type ].powerup == -1 )
  549. {
  550. if( statinfo[ type ].block ) // blocking static
  551. {
  552. lvl->tilemap[ x ][ y ] |= BLOCK_TILE;
  553. }
  554. else // dressing static
  555. {
  556. lvl->tilemap[ x ][ y ] |= DRESS_TILE;
  557. }
  558. spr_id = Sprite_GetNewSprite();
  559. if( spr_id == -1 )
  560. {
  561. return;
  562. }
  563. Sprite_SetPos( spr_id, TILE2POS( x ), TILE2POS( y ), 0 );
  564. Sprite_SetTex( spr_id, 0, SPR_STAT_0 + type );
  565. }
  566. else
  567. {
  568. Powerup_Spawn( x, y, statinfo[ type ].powerup );
  569. if( statinfo[ type ].powerup == pow_cross ||
  570. statinfo[ type ].powerup == pow_chalice ||
  571. statinfo[ type ].powerup == pow_bible ||
  572. statinfo[ type ].powerup == pow_crown ||
  573. statinfo[ type ].powerup == pow_fullheal )
  574. {
  575. levelstate.total_treasure++; // FIXME: move this to Powerup_Spawn Function!
  576. }
  577. }
  578. }
  579. /*
  580. -----------------------------------------------------------------------------
  581. Function:
  582. Parameters:
  583. Returns:
  584. Notes:
  585. -----------------------------------------------------------------------------
  586. */
  587. PRIVATE void Lvl_SpawnObj( LevelData_t *lvl, int type, int x, int y )
  588. {
  589. if( type >= 23 && type < 23 + num_statics )
  590. {// static object
  591. Lvl_SpawnStatic( lvl, type - 23, x, y);
  592. return;
  593. }
  594. switch( type )
  595. {
  596. case 0x13: // start N
  597. lvl->pSpawn.origin[ 0 ] = TILE2POS( x );
  598. lvl->pSpawn.origin[ 1 ] = TILE2POS( y );
  599. lvl->pSpawn.angle = ANG_90;
  600. break;
  601. case 0x14: // start E
  602. lvl->pSpawn.origin[ 0 ] = TILE2POS( x );
  603. lvl->pSpawn.origin[ 1 ] = TILE2POS( y );
  604. lvl->pSpawn.angle = ANG_0;
  605. break;
  606. case 0x15: // start S
  607. lvl->pSpawn.origin[ 0 ] = TILE2POS( x );
  608. lvl->pSpawn.origin[ 1 ] = TILE2POS( y );
  609. lvl->pSpawn.angle = ANG_270;
  610. break;
  611. case 0x16: // start W
  612. lvl->pSpawn.origin[ 0 ] = TILE2POS( x );
  613. lvl->pSpawn.origin[ 1 ] = TILE2POS( y );
  614. lvl->pSpawn.angle = ANG_180;
  615. break;
  616. case 0x5a: // turn E
  617. lvl->tilemap[ x ][ y ] |= TILE_IS_E_TURN;//FIXME!
  618. break;
  619. case 0x5b: // turn NE
  620. lvl->tilemap[ x ][ y ] |= TILE_IS_NE_TURN;//FIXME!
  621. break;
  622. case 0x5c: // turn N
  623. lvl->tilemap[ x ][ y ] |= TILE_IS_N_TURN;//FIXME!
  624. break;
  625. case 0x5d: // turn NW
  626. lvl->tilemap[ x ][ y ] |= TILE_IS_NW_TURN;//FIXME!
  627. break;
  628. case 0x5e: // turn W
  629. lvl->tilemap[ x ][ y ] |= TILE_IS_W_TURN;//FIXME!
  630. break;
  631. case 0x5f: // turn SW
  632. lvl->tilemap[ x ][ y ] |= TILE_IS_SW_TURN;//FIXME!
  633. break;
  634. case 0x60: // turn S
  635. lvl->tilemap[ x ][ y ] |= TILE_IS_S_TURN;//FIXME!
  636. break;
  637. case 0x61: // turn SE
  638. lvl->tilemap[ x ][ y ] |= TILE_IS_SE_TURN;//FIXME!
  639. break;
  640. case 0x62: // pushwall modifier
  641. lvl->tilemap[ x ][ y ] |= SECRET_TILE;
  642. levelstate.total_secrets++;
  643. break;
  644. case 0x63: // Victory trigger
  645. lvl->tilemap[ x ][ y ] |= EXIT_TILE;
  646. break;
  647. // spawn guards
  648. } // end of switch( type )
  649. }
  650. /*
  651. -----------------------------------------------------------------------------
  652. Function:
  653. Parameters:
  654. length -[in] The length of the EXPANDED data.
  655. Returns:
  656. Notes:
  657. -----------------------------------------------------------------------------
  658. */
  659. PRIVATE void Lvl_CarmackExpand( W16 *source, W16 *dest, W16 length )
  660. {
  661. #define NEARTAG 0xA7
  662. #define FARTAG 0xA8
  663. W32 chhigh, offset;
  664. W16 *copyptr, *outptr;
  665. W8 *inptr;
  666. W16 ch, count;
  667. length /= 2;
  668. inptr = (W8 *)source;
  669. outptr = dest;
  670. while( length )
  671. {
  672. ch = *(W16 *)inptr;
  673. inptr += 2;
  674. chhigh = ch >> 8;
  675. if( chhigh == NEARTAG )
  676. {
  677. count = ch & 0xff;
  678. if( ! count )
  679. { // have to insert a word containing the tag byte
  680. ch |= *inptr++;
  681. *outptr++ = (W16)ch;
  682. length--;
  683. }
  684. else
  685. {
  686. offset = *inptr++;
  687. copyptr = outptr - offset;
  688. length -= count;
  689. while( count-- )
  690. {
  691. *outptr++ = *copyptr++;
  692. }
  693. }
  694. }
  695. else if( chhigh == FARTAG )
  696. {
  697. count = ch & 0xff;
  698. if( ! count )
  699. { // have to insert a word containing the tag byte
  700. ch |= *inptr++;
  701. *outptr++ = ch;
  702. length--;
  703. }
  704. else
  705. {
  706. offset = *(W16 *)inptr;
  707. inptr += 2;
  708. copyptr = dest + offset;
  709. length -= count;
  710. while( count-- )
  711. {
  712. *outptr++ = *copyptr++;
  713. }
  714. }
  715. }
  716. else
  717. {
  718. *outptr++ = ch;
  719. length--;
  720. }
  721. }
  722. }
  723. /*
  724. -----------------------------------------------------------------------------
  725. Function:
  726. Parameters:
  727. length -[in] Is EXPANDED length
  728. Returns:
  729. Notes:
  730. -----------------------------------------------------------------------------
  731. */
  732. PRIVATE void Lvl_RLEWexpand( W16 *source, W16 *dest,
  733. long length, unsigned rlewtag )
  734. {
  735. unsigned value,count,i;
  736. W16 *end;
  737. //
  738. // expand it
  739. //
  740. end = dest + (length >> 1);
  741. do
  742. {
  743. value = *source++;
  744. if( value != rlewtag )
  745. {
  746. //
  747. // uncompressed
  748. //
  749. *dest++ = value;
  750. }
  751. else
  752. {
  753. //
  754. // compressed string
  755. //
  756. count = *source++;
  757. value = *source++;
  758. for( i = 1 ; i <= count ; ++i )
  759. {
  760. *dest++ = value;
  761. }
  762. }
  763. } while( dest < end );
  764. }
  765. #define MAPHEADER_SIZE 49
  766. #define MAP_SIGNATURE 0x21444921
  767. /*
  768. -----------------------------------------------------------------------------
  769. Function:
  770. Parameters:
  771. Returns:
  772. Notes:
  773. -----------------------------------------------------------------------------
  774. */
  775. PUBLIC LevelData_t *Level_LoadMap( const char *levelname )
  776. {
  777. W16 rle;
  778. W32 offset[ 3 ];
  779. W16 length[ 3 ];
  780. W16 w, h;
  781. W32 signature;
  782. W16 *buffer, expanded;
  783. W8 *data;
  784. W32 ceiling, floor;
  785. LevelData_t *newMap;
  786. filehandle_t *fhandle;
  787. W16 mapNameLength;
  788. char *mapName;
  789. W16 musicNameLength;
  790. char *musicName;
  791. SW32 filesize;
  792. int x, y0, y, layer1, layer2, layer3;
  793. if( g_version->value == SPEAROFDESTINY && currentMap.episode >= 6 && currentMap.episode < 9)//added the episode check... gsh)
  794. {
  795. statinfo = static_sod;
  796. num_statics = sizeof( static_sod ) / sizeof( static_sod[ 0 ] );
  797. }
  798. else
  799. {
  800. statinfo = static_wl6;
  801. num_statics = sizeof( static_wl6 ) / sizeof( static_wl6[ 0 ] );
  802. }
  803. newMap = &levelData;
  804. memset( newMap, 0, sizeof( LevelData_t ) );
  805. fhandle = FS_OpenFile( levelname, 0 );
  806. if( ! fhandle )
  807. {
  808. char errBuffer[1024];
  809. sprintf( errBuffer, "levelname: %s, could not be found", levelname);
  810. iphoneMessageBox("map filename", errBuffer);
  811. Com_Printf( "Could not load map (%s)\n", levelname );
  812. return NULL;
  813. }
  814. filesize = FS_GetFileSize( fhandle );
  815. if( filesize < MAPHEADER_SIZE )
  816. {
  817. iphoneMessageBox("map header size", "header size of the map is wrong");
  818. Com_Printf("Map file size is smaller than mapheader size\n");
  819. return NULL;
  820. }
  821. //
  822. // Process map header
  823. //
  824. FS_ReadFile( &signature, 1, 4, fhandle );
  825. if( signature != MAP_SIGNATURE )
  826. {
  827. iphoneMessageBox("map signature", "signature of the map file is invalid");
  828. Com_Printf("File signature does not match MAP_SIGNATURE\n");
  829. return NULL;
  830. }
  831. FS_ReadFile( &rle, 2, 1, fhandle );
  832. FS_ReadFile( &w, 2, 1, fhandle );
  833. FS_ReadFile( &h, 2, 1, fhandle );
  834. FS_ReadFile( &ceiling, 4, 1, fhandle );
  835. FS_ReadFile( &floor, 4, 1, fhandle );
  836. FS_ReadFile( &length, 2, 3, fhandle );
  837. FS_ReadFile( &offset, 4, 3, fhandle );
  838. FS_ReadFile( &mapNameLength, 1, 2, fhandle );
  839. FS_ReadFile( &musicNameLength, 1, 2, fhandle );
  840. FS_ReadFile( &levelstate.fpartime, sizeof( float ), 1, fhandle );
  841. FS_ReadFile( levelstate.spartime, sizeof( W8 ), 5, fhandle );
  842. levelstate.spartime[ 5 ] = '\0';
  843. if( filesize < (MAPHEADER_SIZE + mapNameLength + musicNameLength +
  844. length[ 0 ] + length[ 1 ] + length[ 2 ]) )
  845. {
  846. iphoneMessageBox("map filesize", "filesize is less than MAPHEADER_SIZE + mapNameLength + musicNameLength + etc");
  847. Com_Printf("filesize is less than MAPHEADER_SIZE + mapNameLength + musicNameLength + etc\n");
  848. return NULL;
  849. }
  850. mapName = Z_Malloc( mapNameLength + 1 );
  851. musicName = Z_Malloc( musicNameLength + 1 );
  852. FS_ReadFile( mapName, 1, mapNameLength, fhandle );
  853. mapName[ mapNameLength ] = '\0';
  854. FS_ReadFile( musicName, 1, musicNameLength, fhandle );
  855. musicName[ musicNameLength ] = '\0';
  856. if( filesize < (MAPHEADER_SIZE + mapNameLength + musicNameLength) )
  857. {
  858. iphoneMessageBox("map filesize", "filesize is less than MAPHEADER_SIZE + mapNameLength + musicNameLength");
  859. Com_Printf("filesize is less than MAPHEADER_SIZE + mapNameLength + musicNameLength\n");
  860. return NULL;
  861. }
  862. //
  863. // Plane1 -Walls
  864. //
  865. data = MM_MALLOC( length[ 0 ] );
  866. FS_FileSeek( fhandle, offset[ 0 ], SEEK_SET );
  867. FS_ReadFile( data, 1, length[ 0 ], fhandle );
  868. expanded = *((unsigned short *)data);
  869. buffer = MM_MALLOC( expanded );
  870. Lvl_CarmackExpand( (unsigned short *)data+1, buffer, expanded );
  871. Lvl_RLEWexpand( buffer+1, newMap->Plane1, 64*64*2, rle );
  872. MM_FREE( buffer );
  873. MM_FREE( data );
  874. //
  875. // Plane2 -Objects
  876. //
  877. data = MM_MALLOC( length[ 1 ] );
  878. FS_FileSeek( fhandle, offset[ 1 ], SEEK_SET );
  879. FS_ReadFile( data, 1, length[ 1 ], fhandle );
  880. expanded = *((PW16)data);
  881. buffer = MM_MALLOC( expanded );
  882. Lvl_CarmackExpand( (PW16)data+1, buffer, expanded );
  883. Lvl_RLEWexpand( buffer+1, newMap->Plane2, 64*64*2, rle );
  884. MM_FREE( buffer );
  885. MM_FREE( data );
  886. //
  887. // Plane3 -Other
  888. //
  889. data = MM_MALLOC( length[ 2 ] );
  890. FS_FileSeek( fhandle, offset[ 2 ], SEEK_SET );
  891. FS_ReadFile( data, 1, length[ 2 ], fhandle );
  892. expanded = *((PW16)data);
  893. buffer = MM_MALLOC( expanded );
  894. Lvl_CarmackExpand( (PW16)data+1, buffer, expanded );
  895. Lvl_RLEWexpand( buffer+1, newMap->Plane3, 64*64*2, rle );
  896. MM_FREE( buffer );
  897. MM_FREE( data );
  898. FS_CloseFile( fhandle );
  899. // HUGE HACK to take out the pushwall maze that occasionally
  900. // gets players stuck in level E4M2 without actually touching
  901. // a map editor...
  902. if ( !strcmp( levelname, "maps/w31.map" ) ) {
  903. for ( x = 22 ; x <= 32 ; x++ ) {
  904. for ( y0 = 30 ; y0 <= 32 ; y0++ ) {
  905. newMap->Plane1[ y0 * 64 + x ] = newMap->Plane1[ 30*64+21 ];
  906. newMap->Plane2[ y0 * 64 + x ] = newMap->Plane2[ 30*64+21 ];
  907. newMap->Plane3[ y0 * 64 + x ] = newMap->Plane3[ 30*64+21 ];
  908. }
  909. }
  910. }
  911. for( y0 = 0 ; y0 < 64 ; ++y0 )
  912. for( x = 0 ; x < 64 ; ++x )
  913. {
  914. y = 63 - y0;
  915. layer1 = newMap->Plane1[ y0 * 64 + x ];
  916. layer2 = newMap->Plane2[ y0 * 64 + x ];
  917. layer3 = newMap->Plane3[ y0 * 64 + x ];
  918. // if server, process obj layer!
  919. if( layer2 )
  920. {
  921. Lvl_SpawnObj( newMap, layer2, x, y );
  922. }
  923. // Map data layer
  924. if( layer1 == 0 )
  925. {
  926. newMap->areas[ x ][ y ] = -3; // unknown area
  927. }
  928. else if( layer1 < 0x6a ) // solid map object
  929. {
  930. if( (layer1 >= 0x5A && layer1 <= 0x5F) ||
  931. layer1 == 0x64 || layer1 == 0x65 ) // door
  932. {
  933. newMap->tilemap[ x ][ y ] |= DOOR_TILE;
  934. Door_SpawnDoor( &newMap->Doors, x, y, layer1 );
  935. newMap->areas[ x ][ y ] = -2; // door area
  936. }
  937. else
  938. {
  939. newMap->tilemap[ x ][ y ] |= WALL_TILE;
  940. newMap->wall_tex_x[ x ][ y ] = (layer1-1) * 2 + 1;
  941. newMap->wall_tex_y[ x ][ y ] = (layer1-1) * 2;
  942. newMap->areas[ x ][ y ] = -1; // wall area
  943. if( layer1 == 0x15 ) // elevator
  944. {
  945. newMap->tilemap[ x ][ y ] |= ELEVATOR_TILE;
  946. }
  947. }
  948. }
  949. else if( layer1 == 0x6a ) // Ambush floor tile
  950. {
  951. newMap->tilemap[ x ][ y ] |= AMBUSH_TILE;
  952. newMap->areas[ x ][ y ] = -3; // unknown area
  953. }
  954. else if( layer1 >= FIRSTAREA &&
  955. layer1 < (FIRSTAREA + NUMAREAS) ) // area
  956. {
  957. if( layer1 == FIRSTAREA ) // secret level
  958. {
  959. newMap->tilemap[ x ][ y ] |= SECRETLEVEL_TILE;
  960. }
  961. newMap->areas[ x ][ y ] = layer1 - FIRSTAREA;// spawn area
  962. }
  963. else
  964. {
  965. newMap->areas[ x ][ y ] = -3; // unknown area
  966. }
  967. // End of the map data layer
  968. }
  969. // JDC: try to replace all the unknown areas with an adjacent area, to
  970. // avoid the silent attack / no damage problem when you get an ambush
  971. // guard stuck on their original tile
  972. for ( x = 1 ; x < 63 ; x++ ) {
  973. for ( y = 1 ; y < 63 ; y++ ) {
  974. if ( newMap->areas[x][y] != -3 ) {
  975. continue;
  976. }
  977. if ( newMap->areas[x-1][y] >= 0 ) {
  978. newMap->areas[x][y] = newMap->areas[x-1][y];
  979. } else if ( newMap->areas[x+1][y] >= 0 ) {
  980. newMap->areas[x][y] = newMap->areas[x+1][y];
  981. } else if ( newMap->areas[x][y-1] >= 0 ) {
  982. newMap->areas[x][y] = newMap->areas[x][y-1];
  983. } else if ( newMap->areas[x+1][y+1] >= 0 ) {
  984. newMap->areas[x][y] = newMap->areas[x][y+1];
  985. }
  986. }
  987. }
  988. Door_SetAreas( &newMap->Doors, newMap->areas );
  989. my_strlcpy( levelstate.level_name, mapName, sizeof( levelstate.level_name ) );
  990. strcpy( newMap->mapName, mapName );
  991. strcpy( newMap->musicName, musicName );
  992. newMap->ceilingColour[ 0 ] = (W8)((ceiling >> 16) & 0xFF);
  993. newMap->ceilingColour[ 1 ] = (W8)((ceiling >> 8) & 0xFF);
  994. newMap->ceilingColour[ 2 ] = (W8)((ceiling ) & 0xFF);
  995. newMap->floorColour[ 0 ] = (W8)((floor >> 16) & 0xFF);
  996. newMap->floorColour[ 1 ] = (W8)((floor >> 8) & 0xFF);
  997. newMap->floorColour[ 2 ] = (W8)((floor ) & 0xFF);
  998. return newMap;
  999. }
  1000. /*
  1001. -----------------------------------------------------------------------------
  1002. Function: Level_VerifyMap
  1003. Parameters: level file name
  1004. Returns: 0 if invalid map, 1 otherwise
  1005. Notes:
  1006. -----------------------------------------------------------------------------
  1007. */
  1008. PUBLIC int Level_VerifyMap( const char *levelname )
  1009. {
  1010. W16 rle;
  1011. W32 offset[ 3 ];
  1012. W16 length[ 3 ];
  1013. W16 w, h;
  1014. W32 signature;
  1015. W32 ceiling, floor;
  1016. filehandle_t *fhandle;
  1017. W16 mapNameLength;
  1018. char *mapName = NULL;
  1019. W16 musicNameLength;
  1020. char *musicName = NULL;
  1021. SW32 filesize;
  1022. int value = 1;
  1023. fhandle = FS_OpenFile( levelname, FA_FILE_IPHONE_DOC_DIR );
  1024. if( ! fhandle )
  1025. {
  1026. value = 0;
  1027. goto cleanup;
  1028. }
  1029. filesize = FS_GetFileSize( fhandle );
  1030. if( filesize < MAPHEADER_SIZE )
  1031. {
  1032. value = 0;
  1033. goto cleanup;
  1034. }
  1035. FS_ReadFile( &signature, 1, 4, fhandle );
  1036. if( signature != MAP_SIGNATURE )
  1037. {
  1038. value = 0;
  1039. goto cleanup;
  1040. }
  1041. FS_ReadFile( &rle, 2, 1, fhandle );
  1042. FS_ReadFile( &w, 2, 1, fhandle );
  1043. FS_ReadFile( &h, 2, 1, fhandle );
  1044. FS_ReadFile( &ceiling, 4, 1, fhandle );
  1045. FS_ReadFile( &floor, 4, 1, fhandle );
  1046. FS_ReadFile( &length, 2, 3, fhandle );
  1047. FS_ReadFile( &offset, 4, 3, fhandle );
  1048. FS_ReadFile( &mapNameLength, 1, 2, fhandle );
  1049. FS_ReadFile( &musicNameLength, 1, 2, fhandle );
  1050. FS_ReadFile( &levelstate.fpartime, sizeof( float ), 1, fhandle );
  1051. FS_ReadFile( levelstate.spartime, sizeof( W8 ), 5, fhandle );
  1052. levelstate.spartime[ 5 ] = '\0';
  1053. if( filesize < (MAPHEADER_SIZE + mapNameLength + musicNameLength +
  1054. length[ 0 ] + length[ 1 ] + length[ 2 ]) )
  1055. {
  1056. value = 0;
  1057. goto cleanup;
  1058. }
  1059. mapName = Z_Malloc( mapNameLength + 1 );
  1060. musicName = Z_Malloc( musicNameLength + 1 );
  1061. FS_ReadFile( mapName, 1, mapNameLength, fhandle );
  1062. mapName[ mapNameLength ] = '\0';
  1063. FS_ReadFile( musicName, 1, musicNameLength, fhandle );
  1064. musicName[ musicNameLength ] = '\0';
  1065. if( filesize < (MAPHEADER_SIZE + mapNameLength + musicNameLength) )
  1066. {
  1067. value = 0;
  1068. goto cleanup;
  1069. }
  1070. cleanup:
  1071. FS_CloseFile(fhandle);
  1072. if (mapName) {
  1073. Z_Free(mapName);
  1074. }
  1075. if (musicName) {
  1076. Z_Free(musicName);
  1077. }
  1078. return value;
  1079. }
  1080. /*
  1081. -----------------------------------------------------------------------------
  1082. Function:
  1083. Parameters:
  1084. Returns:
  1085. Notes:
  1086. -----------------------------------------------------------------------------
  1087. */
  1088. PUBLIC void Level_PrecacheTextures_Sound( LevelData_t *lvl )
  1089. {
  1090. int x, y;
  1091. char texname[ 32 ];
  1092. for( x = 0 ; x < 64 ; ++x )
  1093. for( y = 0 ; y < 64 ; ++y )
  1094. {
  1095. if( lvl->tilemap[ x ][ y ] & WALL_TILE )
  1096. {
  1097. LoadWallTexture( lvl->wall_tex_x[ x ][ y ] );
  1098. LoadWallTexture( lvl->wall_tex_y[ x ][ y ] );
  1099. }
  1100. if( lvl->tilemap[ x ][ y ] & POWERUP_TILE )
  1101. {
  1102. int tex = lvl->tilemap[ x ][ y ] & POWERUP_TILE;
  1103. my_snprintf( texname, sizeof( texname ), "%s/%.3d.tga", spritelocation, tex );
  1104. spriteTextures[tex] = TM_FindTexture( texname, TT_Wall );
  1105. }
  1106. }
  1107. // Doors
  1108. for( x = TEX_DOOR; x < TEX_DLOCK+2 ; ++x )
  1109. {
  1110. LoadWallTexture( x );
  1111. }
  1112. // Items
  1113. CacheTextures( 26, 36 );
  1114. // Weapon frames
  1115. CacheTextures( SPR_KNIFEREADY, SPR_CHAINATK4 );
  1116. // in case the last wall load was a dim copy
  1117. pfglColor3f( 1, 1, 1 );
  1118. }
  1119. /*
  1120. -----------------------------------------------------------------------------
  1121. Function:
  1122. Parameters:
  1123. Returns: true if a straight line between 2 points is unobstructed,
  1124. otherwise false.
  1125. Notes:
  1126. -----------------------------------------------------------------------------
  1127. */
  1128. PUBLIC _boolean Level_CheckLine( SW32 x1, SW32 y1, SW32 x2, SW32 y2, LevelData_t *lvl )
  1129. {
  1130. SW32 xt1, yt1, xt2, yt2; /* tile positions */
  1131. SW32 x, y; /* current point in !tiles! */
  1132. SW32 xdist, ydist;
  1133. SW32 xstep, ystep; /* Step value for each whole xy */
  1134. SW32 deltafrac; /* current point in !1/256 of tile! */
  1135. SW32 Frac; /* Fractional xy stepper */
  1136. SW32 partial; /* how much to move in our direction to border */
  1137. SW32 intercept; /* Temp for door code */
  1138. #define FRACBITS 8 /* Number of bits of fraction */
  1139. // get start & end tiles
  1140. xt1 = x1 >> TILESHIFT;
  1141. yt1 = y1 >> TILESHIFT;
  1142. xt2 = x2 >> TILESHIFT;
  1143. yt2 = y2 >> TILESHIFT;
  1144. xdist = ABS( xt2 - xt1 ); // X distance in tiles
  1145. ydist = ABS( yt2 - yt1 ); // Y distance in tiles
  1146. // 1/256 tile precision (TILESHIFT is 16)
  1147. x1 >>= FRACBITS; y1 >>= FRACBITS;
  1148. x2 >>= FRACBITS; y2 >>= FRACBITS;
  1149. if( xdist ) // always positive check only for 0
  1150. {
  1151. if( xt2 > xt1 )
  1152. {
  1153. partial = 256 - (x1 & 0xff);
  1154. xstep = 1;
  1155. }
  1156. else
  1157. {
  1158. partial = x1 & 0xff;
  1159. xstep = -1;
  1160. }
  1161. deltafrac = ABS( x2 - x1 );
  1162. ystep = ((y2 - y1) << FRACBITS) / deltafrac;
  1163. Frac = y1 + ((ystep * partial) >> FRACBITS);
  1164. x = xt1 + xstep;
  1165. xt2 += xstep;
  1166. do
  1167. {
  1168. y = Frac >> FRACBITS;
  1169. Frac += ystep;
  1170. assert( x >= 0 && x < 64 && y >= 0 && y < 64 );
  1171. if( lvl->tilemap[ x ][ y ] & WALL_TILE )
  1172. {
  1173. return false; // Wall is in path quitting!
  1174. }
  1175. if( lvl->tilemap[ x ][ y ] & DOOR_TILE )
  1176. {// door, see if the door is open enough
  1177. if( lvl->Doors.DoorMap[ x ][ y ].action != dr_open )
  1178. {
  1179. if( lvl->Doors.DoorMap[ x ][ y ].action == dr_closed )
  1180. {
  1181. return false;
  1182. }
  1183. // checking vertical doors in action: ->_I_
  1184. intercept = ((Frac - ystep / 2) & 0xFF) >> 4; // 1/64 of tile
  1185. if( intercept < (63 - lvl->Doors.DoorMap[ x ][ y ].ticcount) )
  1186. {
  1187. return false;
  1188. }
  1189. }
  1190. }
  1191. x += xstep;
  1192. } while( x != xt2 );
  1193. }
  1194. if( ydist ) // always positive check only for 0
  1195. {
  1196. if( yt2 > yt1 )
  1197. {
  1198. partial = 256 - (y1 & 0xff);
  1199. ystep = 1;
  1200. }
  1201. else
  1202. {
  1203. partial = y1 & 0xff;
  1204. ystep = -1;
  1205. }
  1206. deltafrac = ABS( y2 - y1 );
  1207. xstep = ((x2 - x1) << FRACBITS) / deltafrac;
  1208. Frac = x1 + ((xstep * partial) >> FRACBITS);
  1209. y = yt1 + ystep;
  1210. yt2 += ystep;
  1211. do
  1212. {
  1213. x = Frac >> FRACBITS;
  1214. Frac += xstep;
  1215. assert( x >= 0 && x < 64 && y >= 0 && y < 64 );
  1216. if( lvl->tilemap[ x ][ y ] & WALL_TILE )
  1217. {
  1218. return false; // Wall is in path quitting!
  1219. }
  1220. if( lvl->tilemap[ x ][ y ] & DOOR_TILE )
  1221. {// door, see if the door is open enough
  1222. if( lvl->Doors.DoorMap[ x ][ y ].action != dr_open )
  1223. {
  1224. if( lvl->Doors.DoorMap[ x ][ y ].action == dr_closed )
  1225. {
  1226. return false;
  1227. }
  1228. // checking vertical doors in action: ->_I_
  1229. intercept = ((Frac - xstep / 2) & 0xFF) >> 4; // 1/64 of tile
  1230. if( intercept < lvl->Doors.DoorMap[ x ][ y ].ticcount )
  1231. {
  1232. return false;
  1233. }
  1234. }
  1235. }
  1236. y += ystep;
  1237. } while( y != yt2 );
  1238. }
  1239. return true;
  1240. }