p_setup.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "Precompiled.h"
  21. #include "globaldata.h"
  22. #include <math.h>
  23. #include "z_zone.h"
  24. #include "m_swap.h"
  25. #include "m_bbox.h"
  26. #include "g_game.h"
  27. #include "i_system.h"
  28. #include "w_wad.h"
  29. #include "doomdef.h"
  30. #include "p_local.h"
  31. #include "s_sound.h"
  32. #include "doomstat.h"
  33. void P_SpawnMapThing (mapthing_t* mthing);
  34. //
  35. // MAP related Lookup tables.
  36. // Store VERTEXES, LINEDEFS, SIDEDEFS, etc.
  37. //
  38. // BLOCKMAP
  39. // Created from axis aligned bounding box
  40. // of the map, a rectangular array of
  41. // blocks of size ...
  42. // Used to speed up collision detection
  43. // by spatial subdivision in 2D.
  44. //
  45. // Blockmap size.
  46. // offsets in ::g->blockmap are from here
  47. // origin of block map
  48. // for thing chains
  49. // REJECT
  50. // For fast sight rejection.
  51. // Speeds up enemy AI by skipping detailed
  52. // LineOf Sight calculation.
  53. // Without special effect, this could be
  54. // used as a PVS lookup as well.
  55. //
  56. // Maintain single and multi player starting spots.
  57. //
  58. // P_LoadVertexes
  59. //
  60. void P_LoadVertexes (int lump)
  61. {
  62. byte* data;
  63. int i;
  64. mapvertex_t* ml;
  65. vertex_t* li;
  66. // Determine number of lumps:
  67. // total lump length / vertex record length.
  68. ::g->numvertexes = W_LumpLength (lump) / sizeof(mapvertex_t);
  69. // Allocate zone memory for buffer.
  70. // ::g->vertexes = (vertex_t*)Z_Malloc (::g->numvertexes*sizeof(vertex_t),PU_LEVEL,0);
  71. if (MallocForLump( lump, ::g->numvertexes*sizeof(vertex_t ), ::g->vertexes, PU_LEVEL_SHARED ))
  72. {
  73. // Load data into cache.
  74. data = (byte*)W_CacheLumpNum (lump,PU_CACHE_SHARED); // ALAN: LOADTIME
  75. ml = (mapvertex_t *)data;
  76. li = ::g->vertexes;
  77. // Copy and convert vertex coordinates,
  78. // internal representation as fixed.
  79. for (i=0 ; i < ::g->numvertexes ; i++, li++, ml++)
  80. {
  81. li->x = SHORT(ml->x)<<FRACBITS;
  82. li->y = SHORT(ml->y)<<FRACBITS;
  83. }
  84. // Free buffer memory.
  85. Z_Free(data);
  86. }
  87. }
  88. //
  89. // P_LoadSegs
  90. //
  91. void P_LoadSegs (int lump)
  92. {
  93. byte* data;
  94. int i;
  95. mapseg_t* ml;
  96. seg_t* li;
  97. line_t* ldef;
  98. int psetup_linedef;
  99. int side;
  100. ::g->numsegs = W_LumpLength (lump) / sizeof(mapseg_t);
  101. // ::g->segs = (seg_t*)Z_Malloc (::g->numsegs*sizeof(seg_t),PU_LEVEL,0);
  102. if (MallocForLump( lump, ::g->numsegs*sizeof(seg_t), ::g->segs, PU_LEVEL_SHARED ))
  103. {
  104. memset (::g->segs, 0, ::g->numsegs*sizeof(seg_t));
  105. data = (byte*)W_CacheLumpNum (lump,PU_CACHE_SHARED); // ALAN: LOADTIME
  106. ml = (mapseg_t *)data;
  107. li = ::g->segs;
  108. for (i=0 ; i < ::g->numsegs ; i++, li++, ml++)
  109. {
  110. li->v1 = &::g->vertexes[SHORT(ml->v1)];
  111. li->v2 = &::g->vertexes[SHORT(ml->v2)];
  112. li->angle = (SHORT(ml->angle))<<16;
  113. li->offset = (SHORT(ml->offset))<<16;
  114. psetup_linedef = SHORT(ml->linedef);
  115. ldef = &::g->lines[psetup_linedef];
  116. li->linedef = ldef;
  117. side = SHORT(ml->side);
  118. li->sidedef = &::g->sides[ldef->sidenum[side]];
  119. li->frontsector = ::g->sides[ldef->sidenum[side]].sector;
  120. if (ldef-> flags & ML_TWOSIDED)
  121. li->backsector = ::g->sides[ldef->sidenum[side^1]].sector;
  122. else
  123. li->backsector = 0;
  124. }
  125. Z_Free(data);
  126. }
  127. }
  128. //
  129. // P_LoadSubsectors
  130. //
  131. void P_LoadSubsectors (int lump)
  132. {
  133. byte* data;
  134. int i;
  135. mapsubsector_t* ms;
  136. subsector_t* ss;
  137. ::g->numsubsectors = W_LumpLength (lump) / sizeof(mapsubsector_t);
  138. if (MallocForLump( lump, ::g->numsubsectors*sizeof(subsector_t), ::g->subsectors, PU_LEVEL_SHARED ))
  139. {
  140. data = (byte*)W_CacheLumpNum (lump,PU_CACHE_SHARED); // ALAN: LOADTIME
  141. ms = (mapsubsector_t *)data;
  142. memset (::g->subsectors,0, ::g->numsubsectors*sizeof(subsector_t));
  143. ss = ::g->subsectors;
  144. for (i=0 ; i < ::g->numsubsectors ; i++, ss++, ms++)
  145. {
  146. ss->numlines = SHORT(ms->numsegs);
  147. ss->firstline = SHORT(ms->firstseg);
  148. }
  149. Z_Free(data);
  150. }
  151. }
  152. //
  153. // P_LoadSectors
  154. //
  155. void P_LoadSectors (int lump)
  156. {
  157. byte* data;
  158. int i;
  159. mapsector_t* ms;
  160. sector_t* ss;
  161. ::g->numsectors = W_LumpLength (lump) / sizeof(mapsector_t);
  162. ::g->sectors = (sector_t*)Z_Malloc( ::g->numsectors*sizeof(sector_t), PU_LEVEL, NULL );
  163. memset (::g->sectors, 0, ::g->numsectors*sizeof(sector_t));
  164. data = (byte*)W_CacheLumpNum (lump,PU_CACHE_SHARED); // ALAN: LOADTIME
  165. ms = (mapsector_t *)data;
  166. ss = ::g->sectors;
  167. for (i=0 ; i < ::g->numsectors ; i++, ss++, ms++)
  168. {
  169. ss->floorheight = SHORT(ms->floorheight)<<FRACBITS;
  170. ss->ceilingheight = SHORT(ms->ceilingheight)<<FRACBITS;
  171. ss->floorpic = R_FlatNumForName(ms->floorpic);
  172. ss->ceilingpic = R_FlatNumForName(ms->ceilingpic);
  173. ss->lightlevel = SHORT(ms->lightlevel);
  174. ss->special = SHORT(ms->special);
  175. ss->tag = SHORT(ms->tag);
  176. ss->thinglist = NULL;
  177. }
  178. Z_Free(data);
  179. /*
  180. if (MallocForLump( lump, ::g->numsectors*sizeof(sector_t), (void**)&::g->sectors, PU_LEVEL_SHARED ))
  181. {
  182. memset (::g->sectors, 0, ::g->numsectors*sizeof(sector_t));
  183. data = (byte*)W_CacheLumpNum (lump,PU_CACHE_SHARED); // ALAN: LOADTIME
  184. ms = (mapsector_t *)data;
  185. ss = ::g->sectors;
  186. for (i=0 ; i < ::g->numsectors ; i++, ss++, ms++)
  187. {
  188. ss->floorheight = SHORT(ms->floorheight)<<FRACBITS;
  189. ss->ceilingheight = SHORT(ms->ceilingheight)<<FRACBITS;
  190. ss->floorpic = R_FlatNumForName(ms->floorpic);
  191. ss->ceilingpic = R_FlatNumForName(ms->ceilingpic);
  192. ss->lightlevel = SHORT(ms->lightlevel);
  193. ss->special = SHORT(ms->special);
  194. ss->tag = SHORT(ms->tag);
  195. ss->thinglist = NULL;
  196. }
  197. DoomLib::Z_Free(data);
  198. }
  199. */
  200. }
  201. //
  202. // P_LoadNodes
  203. //
  204. void P_LoadNodes (int lump)
  205. {
  206. byte* data;
  207. int i;
  208. int j;
  209. int k;
  210. mapnode_t* mn;
  211. node_t* no;
  212. ::g->numnodes = W_LumpLength (lump) / sizeof(mapnode_t);
  213. if (MallocForLump( lump, ::g->numnodes*sizeof(node_t), ::g->nodes, PU_LEVEL_SHARED ))
  214. {
  215. data = (byte*)W_CacheLumpNum (lump,PU_CACHE_SHARED); // ALAN: LOADTIME
  216. mn = (mapnode_t *)data;
  217. no = ::g->nodes;
  218. for (i=0 ; i < ::g->numnodes ; i++, no++, mn++)
  219. {
  220. no->x = SHORT(mn->x)<<FRACBITS;
  221. no->y = SHORT(mn->y)<<FRACBITS;
  222. no->dx = SHORT(mn->dx)<<FRACBITS;
  223. no->dy = SHORT(mn->dy)<<FRACBITS;
  224. for (j=0 ; j<2 ; j++)
  225. {
  226. no->children[j] = SHORT(mn->children[j]);
  227. for (k=0 ; k<4 ; k++)
  228. no->bbox[j][k] = SHORT(mn->bbox[j][k])<<FRACBITS;
  229. }
  230. }
  231. Z_Free(data);
  232. }
  233. }
  234. //
  235. // P_LoadThings
  236. //
  237. void P_LoadThings (int lump)
  238. {
  239. byte* data;
  240. int i;
  241. mapthing_t* mt;
  242. int numthings;
  243. qboolean spawn;
  244. data = (byte*)W_CacheLumpNum (lump,PU_CACHE_SHARED); // ALAN: LOADTIME
  245. numthings = (W_LumpLength (lump) / sizeof(mapthing_t));
  246. mt = (mapthing_t *)data;
  247. for (i=0 ; i<numthings ; i++, mt++)
  248. {
  249. spawn = true;
  250. // Do not spawn cool, new monsters if !commercial
  251. if ( ::g->gamemode != commercial)
  252. {
  253. switch(mt->type)
  254. {
  255. case 68: // Arachnotron
  256. case 64: // Archvile
  257. case 88: // Boss Brain
  258. case 89: // Boss Shooter
  259. case 69: // Hell Knight
  260. case 67: // Mancubus
  261. case 71: // Pain Elemental
  262. case 65: // Former Human Commando
  263. case 66: // Revenant
  264. case 84: // Wolf SS
  265. spawn = false;
  266. break;
  267. }
  268. }
  269. if (spawn == false)
  270. break;
  271. // Do spawn all other stuff.
  272. mt->x = SHORT(mt->x);
  273. mt->y = SHORT(mt->y);
  274. mt->angle = SHORT(mt->angle);
  275. mt->type = SHORT(mt->type);
  276. mt->options = SHORT(mt->options);
  277. P_SpawnMapThing (mt);
  278. }
  279. Z_Free(data);
  280. }
  281. //
  282. // P_LoadLineDefs
  283. // Also counts secret ::g->lines for intermissions.
  284. //
  285. void P_LoadLineDefs (int lump)
  286. {
  287. byte* data;
  288. int i;
  289. maplinedef_t* mld;
  290. line_t* ld;
  291. vertex_t* v1;
  292. vertex_t* v2;
  293. ::g->numlines = W_LumpLength (lump) / sizeof(maplinedef_t);
  294. if (MallocForLump( lump, ::g->numlines*sizeof(line_t), ::g->lines, PU_LEVEL_SHARED ))
  295. {
  296. memset (::g->lines, 0, ::g->numlines*sizeof(line_t));
  297. data = (byte*)W_CacheLumpNum (lump,PU_CACHE_SHARED); // ALAN: LOADTIME
  298. mld = (maplinedef_t *)data;
  299. ld = ::g->lines;
  300. for (i=0 ; i < ::g->numlines ; i++, mld++, ld++)
  301. {
  302. ld->flags = SHORT(mld->flags);
  303. ld->special = SHORT(mld->special);
  304. ld->tag = SHORT(mld->tag);
  305. v1 = ld->v1 = &::g->vertexes[SHORT(mld->v1)];
  306. v2 = ld->v2 = &::g->vertexes[SHORT(mld->v2)];
  307. ld->dx = v2->x - v1->x;
  308. ld->dy = v2->y - v1->y;
  309. if (!ld->dx)
  310. ld->slopetype = ST_VERTICAL;
  311. else if (!ld->dy)
  312. ld->slopetype = ST_HORIZONTAL;
  313. else
  314. {
  315. if (FixedDiv (ld->dy , ld->dx) > 0)
  316. ld->slopetype = ST_POSITIVE;
  317. else
  318. ld->slopetype = ST_NEGATIVE;
  319. }
  320. if (v1->x < v2->x)
  321. {
  322. ld->bbox[BOXLEFT] = v1->x;
  323. ld->bbox[BOXRIGHT] = v2->x;
  324. }
  325. else
  326. {
  327. ld->bbox[BOXLEFT] = v2->x;
  328. ld->bbox[BOXRIGHT] = v1->x;
  329. }
  330. if (v1->y < v2->y)
  331. {
  332. ld->bbox[BOXBOTTOM] = v1->y;
  333. ld->bbox[BOXTOP] = v2->y;
  334. }
  335. else
  336. {
  337. ld->bbox[BOXBOTTOM] = v2->y;
  338. ld->bbox[BOXTOP] = v1->y;
  339. }
  340. ld->sidenum[0] = SHORT(mld->sidenum[0]);
  341. ld->sidenum[1] = SHORT(mld->sidenum[1]);
  342. if (ld->sidenum[0] != -1)
  343. ld->frontsector = ::g->sides[ld->sidenum[0]].sector;
  344. else
  345. ld->frontsector = 0;
  346. if (ld->sidenum[1] != -1)
  347. ld->backsector = ::g->sides[ld->sidenum[1]].sector;
  348. else
  349. ld->backsector = 0;
  350. }
  351. Z_Free(data);
  352. }
  353. }
  354. //
  355. // P_LoadSideDefs
  356. //
  357. void P_LoadSideDefs (int lump)
  358. {
  359. byte* data;
  360. int i;
  361. mapsidedef_t* msd;
  362. side_t* sd;
  363. ::g->numsides = W_LumpLength (lump) / sizeof(mapsidedef_t);
  364. if (MallocForLump( lump, ::g->numsides*sizeof(side_t), ::g->sides, PU_LEVEL_SHARED))
  365. {
  366. memset (::g->sides, 0, ::g->numsides*sizeof(side_t));
  367. data = (byte*)W_CacheLumpNum (lump,PU_CACHE_SHARED); // ALAN: LOADTIME
  368. msd = (mapsidedef_t *)data;
  369. sd = ::g->sides;
  370. for (i=0 ; i < ::g->numsides ; i++, msd++, sd++)
  371. {
  372. sd->textureoffset = SHORT(msd->textureoffset)<<FRACBITS;
  373. sd->rowoffset = SHORT(msd->rowoffset)<<FRACBITS;
  374. sd->toptexture = R_TextureNumForName(msd->toptexture);
  375. sd->bottomtexture = R_TextureNumForName(msd->bottomtexture);
  376. sd->midtexture = R_TextureNumForName(msd->midtexture);
  377. sd->sector = &::g->sectors[SHORT(msd->sector)];
  378. }
  379. Z_Free(data);
  380. }
  381. }
  382. //
  383. // P_LoadBlockMap
  384. //
  385. void P_LoadBlockMap (int lump)
  386. {
  387. int i;
  388. int count;
  389. bool firstTime = false;
  390. if (!lumpcache[lump]) { // SMF - solution for double endian conversion issue
  391. firstTime = true;
  392. }
  393. ::g->blockmaplump = (short*)W_CacheLumpNum (lump,PU_LEVEL_SHARED); // ALAN: This is initialized somewhere else as shared...
  394. ::g->blockmap = ::g->blockmaplump+4;
  395. count = W_LumpLength (lump)/2;
  396. if ( firstTime ) { // SMF
  397. for (i=0 ; i<count ; i++)
  398. ::g->blockmaplump[i] = SHORT(::g->blockmaplump[i]);
  399. }
  400. ::g->bmaporgx = ( ::g->blockmaplump[0] )<<FRACBITS;
  401. ::g->bmaporgy = ( ::g->blockmaplump[1] )<<FRACBITS;
  402. ::g->bmapwidth = ( ::g->blockmaplump[2] );
  403. ::g->bmapheight = ( ::g->blockmaplump[3] );
  404. // clear out mobj chains
  405. count = sizeof(*::g->blocklinks)* ::g->bmapwidth*::g->bmapheight;
  406. ::g->blocklinks = (mobj_t**)Z_Malloc (count,PU_LEVEL, 0);
  407. memset (::g->blocklinks, 0, count);
  408. }
  409. //
  410. // P_GroupLines
  411. // Builds sector line lists and subsector sector numbers.
  412. // Finds block bounding boxes for ::g->sectors.
  413. //
  414. void P_GroupLines (void)
  415. {
  416. line_t** linebuffer;
  417. int i;
  418. int j;
  419. int total;
  420. line_t* li;
  421. sector_t* sector;
  422. subsector_t* ss;
  423. seg_t* seg;
  424. fixed_t bbox[4];
  425. int block;
  426. // look up sector number for each subsector
  427. ss = ::g->subsectors;
  428. for (i=0 ; i < ::g->numsubsectors ; i++, ss++)
  429. {
  430. seg = &::g->segs[ss->firstline];
  431. ss->sector = seg->sidedef->sector;
  432. }
  433. // count number of ::g->lines in each sector
  434. li = ::g->lines;
  435. total = 0;
  436. for (i=0 ; i < ::g->numlines ; i++, li++)
  437. {
  438. total++;
  439. li->frontsector->linecount++;
  440. if (li->backsector && li->backsector != li->frontsector)
  441. {
  442. li->backsector->linecount++;
  443. total++;
  444. }
  445. }
  446. // build line tables for each sector
  447. linebuffer = (line_t**)Z_Malloc (total*4, PU_LEVEL, 0);
  448. sector = ::g->sectors;
  449. for (i=0 ; i < ::g->numsectors ; i++, sector++)
  450. {
  451. M_ClearBox (bbox);
  452. sector->lines = linebuffer;
  453. li = ::g->lines;
  454. for (j=0 ; j < ::g->numlines ; j++, li++)
  455. {
  456. if (li->frontsector == sector || li->backsector == sector)
  457. {
  458. *linebuffer++ = li;
  459. M_AddToBox (bbox, li->v1->x, li->v1->y);
  460. M_AddToBox (bbox, li->v2->x, li->v2->y);
  461. }
  462. }
  463. if (linebuffer - sector->lines != sector->linecount)
  464. I_Error ("P_GroupLines: miscounted");
  465. // set the degenmobj_t to the middle of the bounding box
  466. sector->soundorg.x = (bbox[BOXRIGHT]+bbox[BOXLEFT])/2;
  467. sector->soundorg.y = (bbox[BOXTOP]+bbox[BOXBOTTOM])/2;
  468. // adjust bounding box to map blocks
  469. block = (bbox[BOXTOP]-::g->bmaporgy+MAXRADIUS)>>MAPBLOCKSHIFT;
  470. block = block >= ::g->bmapheight ? ::g->bmapheight-1 : block;
  471. sector->blockbox[BOXTOP]=block;
  472. block = (bbox[BOXBOTTOM]-::g->bmaporgy-MAXRADIUS)>>MAPBLOCKSHIFT;
  473. block = block < 0 ? 0 : block;
  474. sector->blockbox[BOXBOTTOM]=block;
  475. block = (bbox[BOXRIGHT]-::g->bmaporgx+MAXRADIUS)>>MAPBLOCKSHIFT;
  476. block = block >= ::g->bmapwidth ? ::g->bmapwidth-1 : block;
  477. sector->blockbox[BOXRIGHT]=block;
  478. block = (bbox[BOXLEFT]-::g->bmaporgx-MAXRADIUS)>>MAPBLOCKSHIFT;
  479. block = block < 0 ? 0 : block;
  480. sector->blockbox[BOXLEFT]=block;
  481. }
  482. }
  483. //
  484. // P_SetupLevel
  485. //
  486. void
  487. P_SetupLevel
  488. ( int episode,
  489. int map,
  490. int playermask,
  491. skill_t skill)
  492. {
  493. int i;
  494. char lumpname[9];
  495. int lumpnum;
  496. ::g->totalkills = ::g->totalitems = ::g->totalsecret = ::g->wminfo.maxfrags = 0;
  497. ::g->wminfo.partime = 180;
  498. for (i=0 ; i<MAXPLAYERS ; i++)
  499. {
  500. ::g->players[i].killcount = ::g->players[i].secretcount
  501. = ::g->players[i].itemcount = 0;
  502. ::g->players[i].chainsawKills = 0;
  503. ::g->players[i].berserkKills = 0;
  504. }
  505. // Initial height of PointOfView
  506. // will be set by player think.
  507. ::g->players[::g->consoleplayer].viewz = 1;
  508. // Make sure all sounds are stopped before Z_FreeTags.
  509. S_Start ();
  510. Z_FreeTags( PU_LEVEL, PU_PURGELEVEL-1 );
  511. // UNUSED W_Profile ();
  512. P_InitThinkers ();
  513. // if working with a devlopment map, reload it
  514. // W_Reload ();
  515. // DHM - NERVE :: Update the cached asset pointers in case the wad files were reloaded
  516. {
  517. void ST_loadData(void);
  518. ST_loadData();
  519. void HU_Init(void);
  520. HU_Init();
  521. }
  522. // find map name
  523. if ( ::g->gamemode == commercial)
  524. {
  525. if (map<10)
  526. sprintf (lumpname,"map0%i", map);
  527. else
  528. sprintf (lumpname,"map%i", map);
  529. }
  530. else
  531. {
  532. lumpname[0] = 'E';
  533. lumpname[1] = '0' + episode;
  534. lumpname[2] = 'M';
  535. lumpname[3] = '0' + map;
  536. lumpname[4] = 0;
  537. }
  538. lumpnum = W_GetNumForName (lumpname);
  539. ::g->leveltime = 0;
  540. // note: most of this ordering is important
  541. P_LoadBlockMap (lumpnum+ML_BLOCKMAP);
  542. P_LoadVertexes (lumpnum+ML_VERTEXES);
  543. P_LoadSectors (lumpnum+ML_SECTORS);
  544. P_LoadSideDefs (lumpnum+ML_SIDEDEFS);
  545. P_LoadLineDefs (lumpnum+ML_LINEDEFS);
  546. P_LoadSubsectors (lumpnum+ML_SSECTORS);
  547. P_LoadNodes (lumpnum+ML_NODES);
  548. P_LoadSegs (lumpnum+ML_SEGS);
  549. ::g->rejectmatrix = (byte*)W_CacheLumpNum (lumpnum+ML_REJECT,PU_LEVEL);
  550. P_GroupLines ();
  551. ::g->bodyqueslot = 0;
  552. ::g->deathmatch_p = ::g->deathmatchstarts;
  553. P_LoadThings (lumpnum+ML_THINGS);
  554. // if ::g->deathmatch, randomly spawn the active ::g->players
  555. if (::g->deathmatch)
  556. {
  557. for (i=0 ; i<MAXPLAYERS ; i++)
  558. if (::g->playeringame[i])
  559. {
  560. // DHM - Nerve :: In deathmatch, reset every player at match start
  561. ::g->players[i].playerstate = PST_REBORN;
  562. ::g->players[i].mo = NULL;
  563. G_DeathMatchSpawnPlayer (i);
  564. }
  565. }
  566. // clear special respawning que
  567. ::g->iquehead = ::g->iquetail = 0;
  568. // set up world state
  569. P_SpawnSpecials ();
  570. // build subsector connect matrix
  571. // UNUSED P_ConnectSubsectors ();
  572. // preload graphics
  573. if (::g->precache)
  574. R_PrecacheLevel ();
  575. }
  576. //
  577. // P_Init
  578. //
  579. void P_Init (void)
  580. {
  581. P_InitSwitchList ();
  582. P_InitPicAnims ();
  583. R_InitSprites (sprnames);
  584. }