P_SETUP.C 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. //**************************************************************************
  2. //**
  3. //** p_setup.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: p_setup.c,v $
  6. //** $Revision: 1.39 $
  7. //** $Date: 96/03/12 12:04:11 $
  8. //** $Author: bgokey $
  9. //**
  10. //**************************************************************************
  11. // HEADER FILES ------------------------------------------------------------
  12. #include <math.h>
  13. #include <stdlib.h>
  14. #include "h2def.h"
  15. #include "p_local.h"
  16. #include "soundst.h"
  17. // MACROS ------------------------------------------------------------------
  18. #define MAPINFO_SCRIPT_NAME "MAPINFO"
  19. #define MCMD_SKY1 1
  20. #define MCMD_SKY2 2
  21. #define MCMD_LIGHTNING 3
  22. #define MCMD_FADETABLE 4
  23. #define MCMD_DOUBLESKY 5
  24. #define MCMD_CLUSTER 6
  25. #define MCMD_WARPTRANS 7
  26. #define MCMD_NEXT 8
  27. #define MCMD_CDTRACK 9
  28. #define MCMD_CD_STARTTRACK 10
  29. #define MCMD_CD_END1TRACK 11
  30. #define MCMD_CD_END2TRACK 12
  31. #define MCMD_CD_END3TRACK 13
  32. #define MCMD_CD_INTERTRACK 14
  33. #define MCMD_CD_TITLETRACK 15
  34. #define UNKNOWN_MAP_NAME "DEVELOPMENT MAP"
  35. #define DEFAULT_SKY_NAME "SKY1"
  36. #define DEFAULT_SONG_LUMP "DEFSONG"
  37. #define DEFAULT_FADE_TABLE "COLORMAP"
  38. // TYPES -------------------------------------------------------------------
  39. typedef struct mapInfo_s mapInfo_t;
  40. struct mapInfo_s
  41. {
  42. short cluster;
  43. short warpTrans;
  44. short nextMap;
  45. short cdTrack;
  46. char name[32];
  47. short sky1Texture;
  48. short sky2Texture;
  49. fixed_t sky1ScrollDelta;
  50. fixed_t sky2ScrollDelta;
  51. boolean doubleSky;
  52. boolean lightning;
  53. int fadetable;
  54. char songLump[10];
  55. };
  56. // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
  57. void P_SpawnMapThing(mapthing_t *mthing);
  58. // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
  59. // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
  60. static int QualifyMap(int map);
  61. // EXTERNAL DATA DECLARATIONS ----------------------------------------------
  62. // PUBLIC DATA DEFINITIONS -------------------------------------------------
  63. int MapCount;
  64. mapthing_t deathmatchstarts[MAXDEATHMATCHSTARTS], *deathmatch_p;
  65. mapthing_t playerstarts[MAX_PLAYER_STARTS][MAXPLAYERS];
  66. int numvertexes;
  67. vertex_t *vertexes;
  68. int numsegs;
  69. seg_t *segs;
  70. int numsectors;
  71. sector_t *sectors;
  72. int numsubsectors;
  73. subsector_t *subsectors;
  74. int numnodes;
  75. node_t *nodes;
  76. int numlines;
  77. line_t *lines;
  78. int numsides;
  79. side_t *sides;
  80. short *blockmaplump; // offsets in blockmap are from here
  81. short *blockmap;
  82. int bmapwidth, bmapheight; // in mapblocks
  83. fixed_t bmaporgx, bmaporgy; // origin of block map
  84. mobj_t **blocklinks; // for thing chains
  85. byte *rejectmatrix; // for fast sight rejection
  86. // PRIVATE DATA DEFINITIONS ------------------------------------------------
  87. static mapInfo_t MapInfo[99];
  88. static char *MapCmdNames[] =
  89. {
  90. "SKY1",
  91. "SKY2",
  92. "DOUBLESKY",
  93. "LIGHTNING",
  94. "FADETABLE",
  95. "CLUSTER",
  96. "WARPTRANS",
  97. "NEXT",
  98. "CDTRACK",
  99. "CD_START_TRACK",
  100. "CD_END1_TRACK",
  101. "CD_END2_TRACK",
  102. "CD_END3_TRACK",
  103. "CD_INTERMISSION_TRACK",
  104. "CD_TITLE_TRACK",
  105. NULL
  106. };
  107. static int MapCmdIDs[] =
  108. {
  109. MCMD_SKY1,
  110. MCMD_SKY2,
  111. MCMD_DOUBLESKY,
  112. MCMD_LIGHTNING,
  113. MCMD_FADETABLE,
  114. MCMD_CLUSTER,
  115. MCMD_WARPTRANS,
  116. MCMD_NEXT,
  117. MCMD_CDTRACK,
  118. MCMD_CD_STARTTRACK,
  119. MCMD_CD_END1TRACK,
  120. MCMD_CD_END2TRACK,
  121. MCMD_CD_END3TRACK,
  122. MCMD_CD_INTERTRACK,
  123. MCMD_CD_TITLETRACK
  124. };
  125. static int cd_NonLevelTracks[6]; // Non-level specific song cd track numbers
  126. // CODE --------------------------------------------------------------------
  127. /*
  128. =================
  129. =
  130. = P_LoadVertexes
  131. =
  132. =================
  133. */
  134. void P_LoadVertexes (int lump)
  135. {
  136. byte *data;
  137. int i;
  138. mapvertex_t *ml;
  139. vertex_t *li;
  140. numvertexes = W_LumpLength (lump) / sizeof(mapvertex_t);
  141. vertexes = Z_Malloc (numvertexes*sizeof(vertex_t),PU_LEVEL,0);
  142. data = W_CacheLumpNum (lump,PU_STATIC);
  143. ml = (mapvertex_t *)data;
  144. li = vertexes;
  145. for (i=0 ; i<numvertexes ; i++, li++, ml++)
  146. {
  147. li->x = SHORT(ml->x)<<FRACBITS;
  148. li->y = SHORT(ml->y)<<FRACBITS;
  149. }
  150. Z_Free (data);
  151. }
  152. /*
  153. =================
  154. =
  155. = P_LoadSegs
  156. =
  157. =================
  158. */
  159. void P_LoadSegs (int lump)
  160. {
  161. byte *data;
  162. int i;
  163. mapseg_t *ml;
  164. seg_t *li;
  165. line_t *ldef;
  166. int linedef, side;
  167. numsegs = W_LumpLength (lump) / sizeof(mapseg_t);
  168. segs = Z_Malloc (numsegs*sizeof(seg_t),PU_LEVEL,0);
  169. memset (segs, 0, numsegs*sizeof(seg_t));
  170. data = W_CacheLumpNum (lump,PU_STATIC);
  171. ml = (mapseg_t *)data;
  172. li = segs;
  173. for (i=0 ; i<numsegs ; i++, li++, ml++)
  174. {
  175. li->v1 = &vertexes[SHORT(ml->v1)];
  176. li->v2 = &vertexes[SHORT(ml->v2)];
  177. li->angle = (SHORT(ml->angle))<<16;
  178. li->offset = (SHORT(ml->offset))<<16;
  179. linedef = SHORT(ml->linedef);
  180. ldef = &lines[linedef];
  181. li->linedef = ldef;
  182. side = SHORT(ml->side);
  183. li->sidedef = &sides[ldef->sidenum[side]];
  184. li->frontsector = sides[ldef->sidenum[side]].sector;
  185. if (ldef-> flags & ML_TWOSIDED)
  186. li->backsector = sides[ldef->sidenum[side^1]].sector;
  187. else
  188. li->backsector = 0;
  189. }
  190. Z_Free (data);
  191. }
  192. /*
  193. =================
  194. =
  195. = P_LoadSubsectors
  196. =
  197. =================
  198. */
  199. void P_LoadSubsectors (int lump)
  200. {
  201. byte *data;
  202. int i;
  203. mapsubsector_t *ms;
  204. subsector_t *ss;
  205. numsubsectors = W_LumpLength (lump) / sizeof(mapsubsector_t);
  206. subsectors = Z_Malloc (numsubsectors*sizeof(subsector_t),PU_LEVEL,0);
  207. data = W_CacheLumpNum (lump,PU_STATIC);
  208. ms = (mapsubsector_t *)data;
  209. memset (subsectors,0, numsubsectors*sizeof(subsector_t));
  210. ss = subsectors;
  211. for (i=0 ; i<numsubsectors ; i++, ss++, ms++)
  212. {
  213. ss->numlines = SHORT(ms->numsegs);
  214. ss->firstline = SHORT(ms->firstseg);
  215. }
  216. Z_Free (data);
  217. }
  218. /*
  219. =================
  220. =
  221. = P_LoadSectors
  222. =
  223. =================
  224. */
  225. void P_LoadSectors (int lump)
  226. {
  227. byte *data;
  228. int i;
  229. mapsector_t *ms;
  230. sector_t *ss;
  231. numsectors = W_LumpLength (lump) / sizeof(mapsector_t);
  232. sectors = Z_Malloc (numsectors*sizeof(sector_t),PU_LEVEL,0);
  233. memset (sectors, 0, numsectors*sizeof(sector_t));
  234. data = W_CacheLumpNum (lump,PU_STATIC);
  235. ms = (mapsector_t *)data;
  236. ss = sectors;
  237. // Make sure primary lumps are used for flat searching
  238. W_UsePrimary();
  239. for(i = 0; i < numsectors; i++, ss++, ms++)
  240. {
  241. ss->floorheight = SHORT(ms->floorheight)<<FRACBITS;
  242. ss->ceilingheight = SHORT(ms->ceilingheight)<<FRACBITS;
  243. ss->floorpic = R_FlatNumForName(ms->floorpic);
  244. ss->ceilingpic = R_FlatNumForName(ms->ceilingpic);
  245. ss->lightlevel = SHORT(ms->lightlevel);
  246. ss->special = SHORT(ms->special);
  247. ss->tag = SHORT(ms->tag);
  248. ss->thinglist = NULL;
  249. ss->seqType = SEQTYPE_STONE; // default seqType
  250. }
  251. if(DevMaps)
  252. {
  253. W_UseAuxiliary();
  254. }
  255. Z_Free(data);
  256. }
  257. /*
  258. =================
  259. =
  260. = P_LoadNodes
  261. =
  262. =================
  263. */
  264. void P_LoadNodes (int lump)
  265. {
  266. byte *data;
  267. int i,j,k;
  268. mapnode_t *mn;
  269. node_t *no;
  270. numnodes = W_LumpLength (lump) / sizeof(mapnode_t);
  271. nodes = Z_Malloc (numnodes*sizeof(node_t),PU_LEVEL,0);
  272. data = W_CacheLumpNum (lump,PU_STATIC);
  273. mn = (mapnode_t *)data;
  274. no = nodes;
  275. for (i=0 ; i<numnodes ; i++, no++, mn++)
  276. {
  277. no->x = SHORT(mn->x)<<FRACBITS;
  278. no->y = SHORT(mn->y)<<FRACBITS;
  279. no->dx = SHORT(mn->dx)<<FRACBITS;
  280. no->dy = SHORT(mn->dy)<<FRACBITS;
  281. for (j=0 ; j<2 ; j++)
  282. {
  283. no->children[j] = SHORT(mn->children[j]);
  284. for (k=0 ; k<4 ; k++)
  285. no->bbox[j][k] = SHORT(mn->bbox[j][k])<<FRACBITS;
  286. }
  287. }
  288. Z_Free (data);
  289. }
  290. //==========================================================================
  291. //
  292. // P_LoadThings
  293. //
  294. //==========================================================================
  295. void P_LoadThings(int lump)
  296. {
  297. byte *data;
  298. int i;
  299. mapthing_t *mt;
  300. int numthings;
  301. int playerCount;
  302. int deathSpotsCount;
  303. data = W_CacheLumpNum(lump, PU_STATIC);
  304. numthings = W_LumpLength(lump)/sizeof(mapthing_t);
  305. mt = (mapthing_t *)data;
  306. for(i = 0; i < numthings; i++, mt++)
  307. {
  308. mt->tid = SHORT(mt->tid);
  309. mt->x = SHORT(mt->x);
  310. mt->y = SHORT(mt->y);
  311. mt->height = SHORT(mt->height);
  312. mt->angle = SHORT(mt->angle);
  313. mt->type = SHORT(mt->type);
  314. mt->options = SHORT(mt->options);
  315. P_SpawnMapThing(mt);
  316. }
  317. P_CreateTIDList();
  318. P_InitCreatureCorpseQueue(false); // false = do NOT scan for corpses
  319. Z_Free(data);
  320. if(!deathmatch)
  321. { // Don't need to check deathmatch spots
  322. return;
  323. }
  324. playerCount = 0;
  325. for(i = 0; i < MAXPLAYERS; i++)
  326. {
  327. playerCount += playeringame[i];
  328. }
  329. deathSpotsCount = deathmatch_p-deathmatchstarts;
  330. if(deathSpotsCount < playerCount)
  331. {
  332. I_Error("P_LoadThings: Player count (%d) exceeds deathmatch "
  333. "spots (%d)", playerCount, deathSpotsCount);
  334. }
  335. }
  336. /*
  337. =================
  338. =
  339. = P_LoadLineDefs
  340. =
  341. =================
  342. */
  343. void P_LoadLineDefs(int lump)
  344. {
  345. byte *data;
  346. int i;
  347. maplinedef_t *mld;
  348. line_t *ld;
  349. vertex_t *v1, *v2;
  350. numlines = W_LumpLength(lump)/sizeof(maplinedef_t);
  351. lines = Z_Malloc(numlines*sizeof(line_t), PU_LEVEL, 0);
  352. memset(lines, 0, numlines*sizeof(line_t));
  353. data = W_CacheLumpNum(lump, PU_STATIC);
  354. mld = (maplinedef_t *)data;
  355. ld = lines;
  356. for(i = 0; i < numlines; i++, mld++, ld++)
  357. {
  358. ld->flags = SHORT(mld->flags);
  359. // Old line special info ...
  360. //ld->special = SHORT(mld->special);
  361. //ld->tag = SHORT(mld->tag);
  362. // New line special info ...
  363. ld->special = mld->special;
  364. ld->arg1 = mld->arg1;
  365. ld->arg2 = mld->arg2;
  366. ld->arg3 = mld->arg3;
  367. ld->arg4 = mld->arg4;
  368. ld->arg5 = mld->arg5;
  369. v1 = ld->v1 = &vertexes[SHORT(mld->v1)];
  370. v2 = ld->v2 = &vertexes[SHORT(mld->v2)];
  371. ld->dx = v2->x - v1->x;
  372. ld->dy = v2->y - v1->y;
  373. if (!ld->dx)
  374. ld->slopetype = ST_VERTICAL;
  375. else if (!ld->dy)
  376. ld->slopetype = ST_HORIZONTAL;
  377. else
  378. {
  379. if (FixedDiv (ld->dy , ld->dx) > 0)
  380. ld->slopetype = ST_POSITIVE;
  381. else
  382. ld->slopetype = ST_NEGATIVE;
  383. }
  384. if (v1->x < v2->x)
  385. {
  386. ld->bbox[BOXLEFT] = v1->x;
  387. ld->bbox[BOXRIGHT] = v2->x;
  388. }
  389. else
  390. {
  391. ld->bbox[BOXLEFT] = v2->x;
  392. ld->bbox[BOXRIGHT] = v1->x;
  393. }
  394. if (v1->y < v2->y)
  395. {
  396. ld->bbox[BOXBOTTOM] = v1->y;
  397. ld->bbox[BOXTOP] = v2->y;
  398. }
  399. else
  400. {
  401. ld->bbox[BOXBOTTOM] = v2->y;
  402. ld->bbox[BOXTOP] = v1->y;
  403. }
  404. ld->sidenum[0] = SHORT(mld->sidenum[0]);
  405. ld->sidenum[1] = SHORT(mld->sidenum[1]);
  406. if (ld->sidenum[0] != -1)
  407. ld->frontsector = sides[ld->sidenum[0]].sector;
  408. else
  409. ld->frontsector = 0;
  410. if (ld->sidenum[1] != -1)
  411. ld->backsector = sides[ld->sidenum[1]].sector;
  412. else
  413. ld->backsector = 0;
  414. }
  415. Z_Free (data);
  416. }
  417. /*
  418. =================
  419. =
  420. = P_LoadSideDefs
  421. =
  422. =================
  423. */
  424. void P_LoadSideDefs (int lump)
  425. {
  426. byte *data;
  427. int i;
  428. mapsidedef_t *msd;
  429. side_t *sd;
  430. numsides = W_LumpLength (lump) / sizeof(mapsidedef_t);
  431. sides = Z_Malloc (numsides*sizeof(side_t),PU_LEVEL,0);
  432. memset (sides, 0, numsides*sizeof(side_t));
  433. data = W_CacheLumpNum (lump,PU_STATIC);
  434. msd = (mapsidedef_t *)data;
  435. sd = sides;
  436. // Make sure primary lumps are used for texture searching
  437. W_UsePrimary();
  438. for(i = 0; i < numsides; i++, msd++, sd++)
  439. {
  440. sd->textureoffset = SHORT(msd->textureoffset)<<FRACBITS;
  441. sd->rowoffset = SHORT(msd->rowoffset)<<FRACBITS;
  442. sd->toptexture = R_TextureNumForName(msd->toptexture);
  443. sd->bottomtexture = R_TextureNumForName(msd->bottomtexture);
  444. sd->midtexture = R_TextureNumForName(msd->midtexture);
  445. sd->sector = &sectors[SHORT(msd->sector)];
  446. }
  447. if(DevMaps)
  448. {
  449. W_UseAuxiliary();
  450. }
  451. Z_Free(data);
  452. }
  453. /*
  454. =================
  455. =
  456. = P_LoadBlockMap
  457. =
  458. =================
  459. */
  460. void P_LoadBlockMap (int lump)
  461. {
  462. int i, count;
  463. blockmaplump = W_CacheLumpNum (lump,PU_LEVEL);
  464. blockmap = blockmaplump+4;
  465. count = W_LumpLength (lump)/2;
  466. for (i=0 ; i<count ; i++)
  467. blockmaplump[i] = SHORT(blockmaplump[i]);
  468. bmaporgx = blockmaplump[0]<<FRACBITS;
  469. bmaporgy = blockmaplump[1]<<FRACBITS;
  470. bmapwidth = blockmaplump[2];
  471. bmapheight = blockmaplump[3];
  472. // clear out mobj chains
  473. count = sizeof(*blocklinks)* bmapwidth*bmapheight;
  474. blocklinks = Z_Malloc (count,PU_LEVEL, 0);
  475. memset (blocklinks, 0, count);
  476. }
  477. /*
  478. =================
  479. =
  480. = P_GroupLines
  481. =
  482. = Builds sector line lists and subsector sector numbers
  483. = Finds block bounding boxes for sectors
  484. =================
  485. */
  486. void P_GroupLines (void)
  487. {
  488. line_t **linebuffer;
  489. int i, j, total;
  490. line_t *li;
  491. sector_t *sector;
  492. subsector_t *ss;
  493. seg_t *seg;
  494. fixed_t bbox[4];
  495. int block;
  496. // look up sector number for each subsector
  497. ss = subsectors;
  498. for (i=0 ; i<numsubsectors ; i++, ss++)
  499. {
  500. seg = &segs[ss->firstline];
  501. ss->sector = seg->sidedef->sector;
  502. }
  503. // count number of lines in each sector
  504. li = lines;
  505. total = 0;
  506. for (i=0 ; i<numlines ; i++, li++)
  507. {
  508. total++;
  509. li->frontsector->linecount++;
  510. if (li->backsector && li->backsector != li->frontsector)
  511. {
  512. li->backsector->linecount++;
  513. total++;
  514. }
  515. }
  516. // build line tables for each sector
  517. linebuffer = Z_Malloc (total*4, PU_LEVEL, 0);
  518. sector = sectors;
  519. for (i=0 ; i<numsectors ; i++, sector++)
  520. {
  521. M_ClearBox (bbox);
  522. sector->lines = linebuffer;
  523. li = lines;
  524. for (j=0 ; j<numlines ; j++, li++)
  525. {
  526. if (li->frontsector == sector || li->backsector == sector)
  527. {
  528. *linebuffer++ = li;
  529. M_AddToBox (bbox, li->v1->x, li->v1->y);
  530. M_AddToBox (bbox, li->v2->x, li->v2->y);
  531. }
  532. }
  533. if (linebuffer - sector->lines != sector->linecount)
  534. I_Error ("P_GroupLines: miscounted");
  535. // set the degenmobj_t to the middle of the bounding box
  536. sector->soundorg.x = (bbox[BOXRIGHT]+bbox[BOXLEFT])/2;
  537. sector->soundorg.y = (bbox[BOXTOP]+bbox[BOXBOTTOM])/2;
  538. // adjust bounding box to map blocks
  539. block = (bbox[BOXTOP]-bmaporgy+MAXRADIUS)>>MAPBLOCKSHIFT;
  540. block = block >= bmapheight ? bmapheight-1 : block;
  541. sector->blockbox[BOXTOP]=block;
  542. block = (bbox[BOXBOTTOM]-bmaporgy-MAXRADIUS)>>MAPBLOCKSHIFT;
  543. block = block < 0 ? 0 : block;
  544. sector->blockbox[BOXBOTTOM]=block;
  545. block = (bbox[BOXRIGHT]-bmaporgx+MAXRADIUS)>>MAPBLOCKSHIFT;
  546. block = block >= bmapwidth ? bmapwidth-1 : block;
  547. sector->blockbox[BOXRIGHT]=block;
  548. block = (bbox[BOXLEFT]-bmaporgx-MAXRADIUS)>>MAPBLOCKSHIFT;
  549. block = block < 0 ? 0 : block;
  550. sector->blockbox[BOXLEFT]=block;
  551. }
  552. }
  553. //=============================================================================
  554. /*
  555. =================
  556. =
  557. = P_SetupLevel
  558. =
  559. =================
  560. */
  561. #ifdef __WATCOMC__
  562. extern boolean i_CDMusic;
  563. #endif
  564. void P_SetupLevel(int episode, int map, int playermask, skill_t skill)
  565. {
  566. int i;
  567. int parm;
  568. char lumpname[9];
  569. char auxName[128];
  570. int lumpnum;
  571. mobj_t *mobj;
  572. for(i = 0; i < MAXPLAYERS; i++)
  573. {
  574. players[i].killcount = players[i].secretcount
  575. = players[i].itemcount = 0;
  576. }
  577. players[consoleplayer].viewz = 1; // will be set by player think
  578. #ifdef __WATCOMC__
  579. if(i_CDMusic == false)
  580. {
  581. S_StartSongName("chess", true); // Waiting-for-level-load song
  582. }
  583. #endif
  584. Z_FreeTags(PU_LEVEL, PU_PURGELEVEL-1);
  585. P_InitThinkers();
  586. leveltime = 0;
  587. if(DevMaps)
  588. {
  589. sprintf(auxName, "%sMAP%02d.WAD", DevMapsDir, map);
  590. W_OpenAuxiliary(auxName);
  591. }
  592. sprintf(lumpname, "MAP%02d", map);
  593. lumpnum = W_GetNumForName(lumpname);
  594. //
  595. // Begin processing map lumps
  596. // Note: most of this ordering is important
  597. //
  598. P_LoadBlockMap(lumpnum+ML_BLOCKMAP);
  599. P_LoadVertexes(lumpnum+ML_VERTEXES);
  600. P_LoadSectors(lumpnum+ML_SECTORS);
  601. P_LoadSideDefs(lumpnum+ML_SIDEDEFS);
  602. P_LoadLineDefs(lumpnum+ML_LINEDEFS);
  603. P_LoadSubsectors(lumpnum+ML_SSECTORS);
  604. P_LoadNodes(lumpnum+ML_NODES);
  605. P_LoadSegs(lumpnum+ML_SEGS);
  606. rejectmatrix = W_CacheLumpNum(lumpnum+ML_REJECT, PU_LEVEL);
  607. P_GroupLines();
  608. bodyqueslot = 0;
  609. po_NumPolyobjs = 0;
  610. deathmatch_p = deathmatchstarts;
  611. P_LoadThings(lumpnum+ML_THINGS);
  612. PO_Init(lumpnum+ML_THINGS); // Initialize the polyobjs
  613. P_LoadACScripts(lumpnum+ML_BEHAVIOR); // ACS object code
  614. //
  615. // End of map lump processing
  616. //
  617. if(DevMaps)
  618. {
  619. // Close the auxiliary file, but don't free its loaded lumps.
  620. // The next call to W_OpenAuxiliary() will do a full shutdown
  621. // of the current auxiliary WAD (free lumps and info lists).
  622. W_CloseAuxiliaryFile();
  623. W_UsePrimary();
  624. }
  625. // If deathmatch, randomly spawn the active players
  626. TimerGame = 0;
  627. if(deathmatch)
  628. {
  629. for (i=0 ; i<MAXPLAYERS ; i++)
  630. {
  631. if (playeringame[i])
  632. { // must give a player spot before deathmatchspawn
  633. mobj = P_SpawnMobj (playerstarts[0][i].x<<16,
  634. playerstarts[0][i].y<<16,0, MT_PLAYER_FIGHTER);
  635. players[i].mo = mobj;
  636. G_DeathMatchSpawnPlayer (i);
  637. P_RemoveMobj (mobj);
  638. }
  639. }
  640. parm = M_CheckParm("-timer");
  641. if(parm && parm < myargc-1)
  642. {
  643. TimerGame = atoi(myargv[parm+1])*35*60;
  644. }
  645. }
  646. // set up world state
  647. P_SpawnSpecials ();
  648. // build subsector connect matrix
  649. // P_ConnectSubsectors ();
  650. // Load colormap and set the fullbright flag
  651. i = P_GetMapFadeTable(gamemap);
  652. W_ReadLump(i, colormaps);
  653. if(i == W_GetNumForName("COLORMAP"))
  654. {
  655. LevelUseFullBright = true;
  656. }
  657. else
  658. { // Probably fog ... don't use fullbright sprites
  659. LevelUseFullBright = false;
  660. }
  661. // preload graphics
  662. if (precache)
  663. R_PrecacheLevel ();
  664. // Check if the level is a lightning level
  665. P_InitLightning();
  666. S_StopAllSound();
  667. SN_StopAllSequences();
  668. S_StartSong(gamemap, true);
  669. //printf ("free memory: 0x%x\n", Z_FreeMemory());
  670. }
  671. //==========================================================================
  672. //
  673. // InitMapInfo
  674. //
  675. //==========================================================================
  676. static void InitMapInfo(void)
  677. {
  678. int map;
  679. int mapMax;
  680. int mcmdValue;
  681. mapInfo_t *info;
  682. char songMulch[10];
  683. mapMax = 1;
  684. // Put defaults into MapInfo[0]
  685. info = MapInfo;
  686. info->cluster = 0;
  687. info->warpTrans = 0;
  688. info->nextMap = 1; // Always go to map 1 if not specified
  689. info->cdTrack = 1;
  690. info->sky1Texture = R_TextureNumForName(DEFAULT_SKY_NAME);
  691. info->sky2Texture = info->sky1Texture;
  692. info->sky1ScrollDelta = 0;
  693. info->sky2ScrollDelta = 0;
  694. info->doubleSky = false;
  695. info->lightning = false;
  696. info->fadetable = W_GetNumForName(DEFAULT_FADE_TABLE);
  697. strcpy(info->name, UNKNOWN_MAP_NAME);
  698. // strcpy(info->songLump, DEFAULT_SONG_LUMP);
  699. SC_Open(MAPINFO_SCRIPT_NAME);
  700. while(SC_GetString())
  701. {
  702. if(SC_Compare("MAP") == false)
  703. {
  704. SC_ScriptError(NULL);
  705. }
  706. SC_MustGetNumber();
  707. if(sc_Number < 1 || sc_Number > 99)
  708. { //
  709. SC_ScriptError(NULL);
  710. }
  711. map = sc_Number;
  712. info = &MapInfo[map];
  713. // Save song lump name
  714. strcpy(songMulch, info->songLump);
  715. // Copy defaults to current map definition
  716. memcpy(info, &MapInfo[0], sizeof(*info));
  717. // Restore song lump name
  718. strcpy(info->songLump, songMulch);
  719. // The warp translation defaults to the map number
  720. info->warpTrans = map;
  721. // Map name must follow the number
  722. SC_MustGetString();
  723. strcpy(info->name, sc_String);
  724. // Process optional tokens
  725. while(SC_GetString())
  726. {
  727. if(SC_Compare("MAP"))
  728. { // Start next map definition
  729. SC_UnGet();
  730. break;
  731. }
  732. mcmdValue = MapCmdIDs[SC_MustMatchString(MapCmdNames)];
  733. switch(mcmdValue)
  734. {
  735. case MCMD_CLUSTER:
  736. SC_MustGetNumber();
  737. info->cluster = sc_Number;
  738. break;
  739. case MCMD_WARPTRANS:
  740. SC_MustGetNumber();
  741. info->warpTrans = sc_Number;
  742. break;
  743. case MCMD_NEXT:
  744. SC_MustGetNumber();
  745. info->nextMap = sc_Number;
  746. break;
  747. case MCMD_CDTRACK:
  748. SC_MustGetNumber();
  749. info->cdTrack = sc_Number;
  750. break;
  751. case MCMD_SKY1:
  752. SC_MustGetString();
  753. info->sky1Texture = R_TextureNumForName(sc_String);
  754. SC_MustGetNumber();
  755. info->sky1ScrollDelta = sc_Number<<8;
  756. break;
  757. case MCMD_SKY2:
  758. SC_MustGetString();
  759. info->sky2Texture = R_TextureNumForName(sc_String);
  760. SC_MustGetNumber();
  761. info->sky2ScrollDelta = sc_Number<<8;
  762. break;
  763. case MCMD_DOUBLESKY:
  764. info->doubleSky = true;
  765. break;
  766. case MCMD_LIGHTNING:
  767. info->lightning = true;
  768. break;
  769. case MCMD_FADETABLE:
  770. SC_MustGetString();
  771. info->fadetable = W_GetNumForName(sc_String);
  772. break;
  773. case MCMD_CD_STARTTRACK:
  774. case MCMD_CD_END1TRACK:
  775. case MCMD_CD_END2TRACK:
  776. case MCMD_CD_END3TRACK:
  777. case MCMD_CD_INTERTRACK:
  778. case MCMD_CD_TITLETRACK:
  779. SC_MustGetNumber();
  780. cd_NonLevelTracks[mcmdValue-MCMD_CD_STARTTRACK] =
  781. sc_Number;
  782. break;
  783. }
  784. }
  785. mapMax = map > mapMax ? map : mapMax;
  786. }
  787. SC_Close();
  788. MapCount = mapMax;
  789. }
  790. //==========================================================================
  791. //
  792. // P_GetMapCluster
  793. //
  794. //==========================================================================
  795. int P_GetMapCluster(int map)
  796. {
  797. return MapInfo[QualifyMap(map)].cluster;
  798. }
  799. //==========================================================================
  800. //
  801. // P_GetMapCDTrack
  802. //
  803. //==========================================================================
  804. int P_GetMapCDTrack(int map)
  805. {
  806. return MapInfo[QualifyMap(map)].cdTrack;
  807. }
  808. //==========================================================================
  809. //
  810. // P_GetMapWarpTrans
  811. //
  812. //==========================================================================
  813. int P_GetMapWarpTrans(int map)
  814. {
  815. return MapInfo[QualifyMap(map)].warpTrans;
  816. }
  817. //==========================================================================
  818. //
  819. // P_GetMapNextMap
  820. //
  821. //==========================================================================
  822. int P_GetMapNextMap(int map)
  823. {
  824. return MapInfo[QualifyMap(map)].nextMap;
  825. }
  826. //==========================================================================
  827. //
  828. // P_TranslateMap
  829. //
  830. // Returns the actual map number given a warp map number.
  831. //
  832. //==========================================================================
  833. int P_TranslateMap(int map)
  834. {
  835. int i;
  836. for(i = 1; i < 99; i++) // Make this a macro
  837. {
  838. if(MapInfo[i].warpTrans == map)
  839. {
  840. return i;
  841. }
  842. }
  843. // Not found
  844. return -1;
  845. }
  846. //==========================================================================
  847. //
  848. // P_GetMapSky1Texture
  849. //
  850. //==========================================================================
  851. int P_GetMapSky1Texture(int map)
  852. {
  853. return MapInfo[QualifyMap(map)].sky1Texture;
  854. }
  855. //==========================================================================
  856. //
  857. // P_GetMapSky2Texture
  858. //
  859. //==========================================================================
  860. int P_GetMapSky2Texture(int map)
  861. {
  862. return MapInfo[QualifyMap(map)].sky2Texture;
  863. }
  864. //==========================================================================
  865. //
  866. // P_GetMapName
  867. //
  868. //==========================================================================
  869. char *P_GetMapName(int map)
  870. {
  871. return MapInfo[QualifyMap(map)].name;
  872. }
  873. //==========================================================================
  874. //
  875. // P_GetMapSky1ScrollDelta
  876. //
  877. //==========================================================================
  878. fixed_t P_GetMapSky1ScrollDelta(int map)
  879. {
  880. return MapInfo[QualifyMap(map)].sky1ScrollDelta;
  881. }
  882. //==========================================================================
  883. //
  884. // P_GetMapSky2ScrollDelta
  885. //
  886. //==========================================================================
  887. fixed_t P_GetMapSky2ScrollDelta(int map)
  888. {
  889. return MapInfo[QualifyMap(map)].sky2ScrollDelta;
  890. }
  891. //==========================================================================
  892. //
  893. // P_GetMapDoubleSky
  894. //
  895. //==========================================================================
  896. boolean P_GetMapDoubleSky(int map)
  897. {
  898. return MapInfo[QualifyMap(map)].doubleSky;
  899. }
  900. //==========================================================================
  901. //
  902. // P_GetMapLightning
  903. //
  904. //==========================================================================
  905. boolean P_GetMapLightning(int map)
  906. {
  907. return MapInfo[QualifyMap(map)].lightning;
  908. }
  909. //==========================================================================
  910. //
  911. // P_GetMapFadeTable
  912. //
  913. //==========================================================================
  914. boolean P_GetMapFadeTable(int map)
  915. {
  916. return MapInfo[QualifyMap(map)].fadetable;
  917. }
  918. //==========================================================================
  919. //
  920. // P_GetMapSongLump
  921. //
  922. //==========================================================================
  923. char *P_GetMapSongLump(int map)
  924. {
  925. if(!strcasecmp(MapInfo[QualifyMap(map)].songLump, DEFAULT_SONG_LUMP))
  926. {
  927. return NULL;
  928. }
  929. else
  930. {
  931. return MapInfo[QualifyMap(map)].songLump;
  932. }
  933. }
  934. //==========================================================================
  935. //
  936. // P_PutMapSongLump
  937. //
  938. //==========================================================================
  939. void P_PutMapSongLump(int map, char *lumpName)
  940. {
  941. if(map < 1 || map > MapCount)
  942. {
  943. return;
  944. }
  945. strcpy(MapInfo[map].songLump, lumpName);
  946. }
  947. //==========================================================================
  948. //
  949. // P_GetCDStartTrack
  950. //
  951. //==========================================================================
  952. int P_GetCDStartTrack(void)
  953. {
  954. return cd_NonLevelTracks[MCMD_CD_STARTTRACK-MCMD_CD_STARTTRACK];
  955. }
  956. //==========================================================================
  957. //
  958. // P_GetCDEnd1Track
  959. //
  960. //==========================================================================
  961. int P_GetCDEnd1Track(void)
  962. {
  963. return cd_NonLevelTracks[MCMD_CD_END1TRACK-MCMD_CD_STARTTRACK];
  964. }
  965. //==========================================================================
  966. //
  967. // P_GetCDEnd2Track
  968. //
  969. //==========================================================================
  970. int P_GetCDEnd2Track(void)
  971. {
  972. return cd_NonLevelTracks[MCMD_CD_END2TRACK-MCMD_CD_STARTTRACK];
  973. }
  974. //==========================================================================
  975. //
  976. // P_GetCDEnd3Track
  977. //
  978. //==========================================================================
  979. int P_GetCDEnd3Track(void)
  980. {
  981. return cd_NonLevelTracks[MCMD_CD_END3TRACK-MCMD_CD_STARTTRACK];
  982. }
  983. //==========================================================================
  984. //
  985. // P_GetCDIntermissionTrack
  986. //
  987. //==========================================================================
  988. int P_GetCDIntermissionTrack(void)
  989. {
  990. return cd_NonLevelTracks[MCMD_CD_INTERTRACK-MCMD_CD_STARTTRACK];
  991. }
  992. //==========================================================================
  993. //
  994. // P_GetCDTitleTrack
  995. //
  996. //==========================================================================
  997. int P_GetCDTitleTrack(void)
  998. {
  999. return cd_NonLevelTracks[MCMD_CD_TITLETRACK-MCMD_CD_STARTTRACK];
  1000. }
  1001. //==========================================================================
  1002. //
  1003. // QualifyMap
  1004. //
  1005. //==========================================================================
  1006. static int QualifyMap(int map)
  1007. {
  1008. return (map < 1 || map > MapCount) ? 0 : map;
  1009. }
  1010. //==========================================================================
  1011. //
  1012. // P_Init
  1013. //
  1014. //==========================================================================
  1015. void P_Init(void)
  1016. {
  1017. InitMapInfo();
  1018. P_InitSwitchList();
  1019. P_InitFTAnims(); // Init flat and texture animations
  1020. P_InitTerrainTypes();
  1021. P_InitLava();
  1022. R_InitSprites(sprnames);
  1023. }
  1024. // Special early initializer needed to start sound before R_Init()
  1025. void InitMapMusicInfo(void)
  1026. {
  1027. int i;
  1028. for (i=0; i<99; i++)
  1029. {
  1030. strcpy(MapInfo[i].songLump, DEFAULT_SONG_LUMP);
  1031. }
  1032. MapCount = 98;
  1033. }
  1034. /*
  1035. void My_Debug(void)
  1036. {
  1037. int i;
  1038. printf("My debug stuff ----------------------\n");
  1039. printf("gamemap=%d\n",gamemap);
  1040. for (i=0; i<10; i++)
  1041. {
  1042. printf("i=%d songlump=%s\n",i,MapInfo[i].songLump);
  1043. }
  1044. }
  1045. */