P_MOBJ.C 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442
  1. //**************************************************************************
  2. //**
  3. //** p_mobj.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: p_mobj.c,v $
  6. //** $Revision: 1.133 $
  7. //** $Date: 96/01/12 12:31:43 $
  8. //** $Author: bgokey $
  9. //**
  10. //**************************************************************************
  11. // HEADER FILES ------------------------------------------------------------
  12. #include "h2def.h"
  13. #include "p_local.h"
  14. #include "sounds.h"
  15. #include "soundst.h"
  16. // MACROS ------------------------------------------------------------------
  17. #define MAX_TID_COUNT 200
  18. // TYPES -------------------------------------------------------------------
  19. // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
  20. void G_PlayerReborn(int player);
  21. void P_MarkAsLeaving(mobj_t *corpse);
  22. // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
  23. void P_SpawnMapThing(mapthing_t *mthing);
  24. // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
  25. static void PlayerLandedOnThing(mobj_t *mo, mobj_t *onmobj);
  26. // EXTERNAL DATA DECLARATIONS ----------------------------------------------
  27. extern mobj_t LavaInflictor;
  28. // PUBLIC DATA DEFINITIONS -------------------------------------------------
  29. mobjtype_t PuffType;
  30. mobj_t *MissileMobj;
  31. fixed_t FloatBobOffsets[64] =
  32. {
  33. 0, 51389, 102283, 152192,
  34. 200636, 247147, 291278, 332604,
  35. 370727, 405280, 435929, 462380,
  36. 484378, 501712, 514213, 521763,
  37. 524287, 521763, 514213, 501712,
  38. 484378, 462380, 435929, 405280,
  39. 370727, 332604, 291278, 247147,
  40. 200636, 152192, 102283, 51389,
  41. -1, -51390, -102284, -152193,
  42. -200637, -247148, -291279, -332605,
  43. -370728, -405281, -435930, -462381,
  44. -484380, -501713, -514215, -521764,
  45. -524288, -521764, -514214, -501713,
  46. -484379, -462381, -435930, -405280,
  47. -370728, -332605, -291279, -247148,
  48. -200637, -152193, -102284, -51389
  49. };
  50. // PRIVATE DATA DEFINITIONS ------------------------------------------------
  51. static int TIDList[MAX_TID_COUNT+1]; // +1 for termination marker
  52. static mobj_t *TIDMobj[MAX_TID_COUNT];
  53. // CODE --------------------------------------------------------------------
  54. //==========================================================================
  55. //
  56. // P_SetMobjState
  57. //
  58. // Returns true if the mobj is still present.
  59. //
  60. //==========================================================================
  61. boolean P_SetMobjState(mobj_t *mobj, statenum_t state)
  62. {
  63. state_t *st;
  64. if(state == S_NULL)
  65. { // Remove mobj
  66. mobj->state = S_NULL;
  67. P_RemoveMobj(mobj);
  68. return(false);
  69. }
  70. st = &states[state];
  71. mobj->state = st;
  72. mobj->tics = st->tics;
  73. mobj->sprite = st->sprite;
  74. mobj->frame = st->frame;
  75. if(st->action)
  76. { // Call action function
  77. st->action(mobj);
  78. }
  79. return(true);
  80. }
  81. //==========================================================================
  82. //
  83. // P_SetMobjStateNF
  84. //
  85. // Same as P_SetMobjState, but does not call the state function.
  86. //
  87. //==========================================================================
  88. boolean P_SetMobjStateNF(mobj_t *mobj, statenum_t state)
  89. {
  90. state_t *st;
  91. if(state == S_NULL)
  92. { // Remove mobj
  93. mobj->state = S_NULL;
  94. P_RemoveMobj(mobj);
  95. return(false);
  96. }
  97. st = &states[state];
  98. mobj->state = st;
  99. mobj->tics = st->tics;
  100. mobj->sprite = st->sprite;
  101. mobj->frame = st->frame;
  102. return(true);
  103. }
  104. //----------------------------------------------------------------------------
  105. //
  106. // PROC P_ExplodeMissile
  107. //
  108. //----------------------------------------------------------------------------
  109. void P_ExplodeMissile(mobj_t *mo)
  110. {
  111. mo->momx = mo->momy = mo->momz = 0;
  112. P_SetMobjState(mo, mobjinfo[mo->type].deathstate);
  113. //mo->tics -= P_Random()&3;
  114. mo->flags &= ~MF_MISSILE;
  115. switch(mo->type)
  116. {
  117. case MT_SORCBALL1:
  118. case MT_SORCBALL2:
  119. case MT_SORCBALL3:
  120. S_StartSound(NULL, SFX_SORCERER_BIGBALLEXPLODE);
  121. break;
  122. case MT_SORCFX1:
  123. S_StartSound(NULL, SFX_SORCERER_HEADSCREAM);
  124. break;
  125. default:
  126. if(mo->info->deathsound)
  127. {
  128. S_StartSound(mo, mo->info->deathsound);
  129. }
  130. break;
  131. }
  132. }
  133. //----------------------------------------------------------------------------
  134. //
  135. // PROC P_FloorBounceMissile
  136. //
  137. //----------------------------------------------------------------------------
  138. void P_FloorBounceMissile(mobj_t *mo)
  139. {
  140. if(P_HitFloor(mo) >= FLOOR_LIQUID)
  141. {
  142. switch(mo->type)
  143. {
  144. case MT_SORCFX1:
  145. case MT_SORCBALL1:
  146. case MT_SORCBALL2:
  147. case MT_SORCBALL3:
  148. break;
  149. default:
  150. P_RemoveMobj(mo);
  151. return;
  152. }
  153. }
  154. switch(mo->type)
  155. {
  156. case MT_SORCFX1:
  157. mo->momz = -mo->momz; // no energy absorbed
  158. break;
  159. case MT_SGSHARD1:
  160. case MT_SGSHARD2:
  161. case MT_SGSHARD3:
  162. case MT_SGSHARD4:
  163. case MT_SGSHARD5:
  164. case MT_SGSHARD6:
  165. case MT_SGSHARD7:
  166. case MT_SGSHARD8:
  167. case MT_SGSHARD9:
  168. case MT_SGSHARD0:
  169. mo->momz = FixedMul(mo->momz, -0.3*FRACUNIT);
  170. if(abs(mo->momz) < (FRACUNIT/2))
  171. {
  172. P_SetMobjState(mo, S_NULL);
  173. return;
  174. }
  175. break;
  176. default:
  177. mo->momz = FixedMul(mo->momz, -0.7*FRACUNIT);
  178. break;
  179. }
  180. mo->momx = 2*mo->momx/3;
  181. mo->momy = 2*mo->momy/3;
  182. if(mo->info->seesound)
  183. {
  184. switch(mo->type)
  185. {
  186. case MT_SORCBALL1:
  187. case MT_SORCBALL2:
  188. case MT_SORCBALL3:
  189. if (!mo->args[0]) S_StartSound(mo, mo->info->seesound);
  190. break;
  191. default:
  192. S_StartSound(mo, mo->info->seesound);
  193. break;
  194. }
  195. S_StartSound(mo, mo->info->seesound);
  196. }
  197. // P_SetMobjState(mo, mobjinfo[mo->type].deathstate);
  198. }
  199. //----------------------------------------------------------------------------
  200. //
  201. // PROC P_ThrustMobj
  202. //
  203. //----------------------------------------------------------------------------
  204. void P_ThrustMobj(mobj_t *mo, angle_t angle, fixed_t move)
  205. {
  206. angle >>= ANGLETOFINESHIFT;
  207. mo->momx += FixedMul(move, finecosine[angle]);
  208. mo->momy += FixedMul(move, finesine[angle]);
  209. }
  210. //----------------------------------------------------------------------------
  211. //
  212. // FUNC P_FaceMobj
  213. //
  214. // Returns 1 if 'source' needs to turn clockwise, or 0 if 'source' needs
  215. // to turn counter clockwise. 'delta' is set to the amount 'source'
  216. // needs to turn.
  217. //
  218. //----------------------------------------------------------------------------
  219. int P_FaceMobj(mobj_t *source, mobj_t *target, angle_t *delta)
  220. {
  221. angle_t diff;
  222. angle_t angle1;
  223. angle_t angle2;
  224. angle1 = source->angle;
  225. angle2 = R_PointToAngle2(source->x, source->y, target->x, target->y);
  226. if(angle2 > angle1)
  227. {
  228. diff = angle2-angle1;
  229. if(diff > ANGLE_180)
  230. {
  231. *delta = ANGLE_MAX-diff;
  232. return(0);
  233. }
  234. else
  235. {
  236. *delta = diff;
  237. return(1);
  238. }
  239. }
  240. else
  241. {
  242. diff = angle1-angle2;
  243. if(diff > ANGLE_180)
  244. {
  245. *delta = ANGLE_MAX-diff;
  246. return(1);
  247. }
  248. else
  249. {
  250. *delta = diff;
  251. return(0);
  252. }
  253. }
  254. }
  255. //----------------------------------------------------------------------------
  256. //
  257. //
  258. // The missile special1 field must be mobj_t *target. Returns true if
  259. // target was tracked, false if not.
  260. //
  261. //----------------------------------------------------------------------------
  262. boolean P_SeekerMissile(mobj_t *actor, angle_t thresh, angle_t turnMax)
  263. {
  264. int dir;
  265. int dist;
  266. angle_t delta;
  267. angle_t angle;
  268. mobj_t *target;
  269. target = (mobj_t *)actor->special1;
  270. if(target == NULL)
  271. {
  272. return(false);
  273. }
  274. if(!(target->flags&MF_SHOOTABLE))
  275. { // Target died
  276. actor->special1 = 0;
  277. return(false);
  278. }
  279. dir = P_FaceMobj(actor, target, &delta);
  280. if(delta > thresh)
  281. {
  282. delta >>= 1;
  283. if(delta > turnMax)
  284. {
  285. delta = turnMax;
  286. }
  287. }
  288. if(dir)
  289. { // Turn clockwise
  290. actor->angle += delta;
  291. }
  292. else
  293. { // Turn counter clockwise
  294. actor->angle -= delta;
  295. }
  296. angle = actor->angle>>ANGLETOFINESHIFT;
  297. actor->momx = FixedMul(actor->info->speed, finecosine[angle]);
  298. actor->momy = FixedMul(actor->info->speed, finesine[angle]);
  299. if(actor->z+actor->height < target->z
  300. || target->z+target->height < actor->z)
  301. { // Need to seek vertically
  302. dist = P_AproxDistance(target->x-actor->x, target->y-actor->y);
  303. dist = dist/actor->info->speed;
  304. if(dist < 1)
  305. {
  306. dist = 1;
  307. }
  308. actor->momz = (target->z+(target->height>>1)
  309. -(actor->z+(actor->height>>1)))/dist;
  310. }
  311. return(true);
  312. }
  313. //----------------------------------------------------------------------------
  314. //
  315. // PROC P_XYMovement
  316. //
  317. //----------------------------------------------------------------------------
  318. #define STOPSPEED 0x1000
  319. #define FRICTION_NORMAL 0xe800
  320. #define FRICTION_LOW 0xf900
  321. #define FRICTION_FLY 0xeb00
  322. void P_XYMovement(mobj_t *mo)
  323. {
  324. fixed_t ptryx, ptryy;
  325. player_t *player;
  326. fixed_t xmove, ymove;
  327. int special;
  328. angle_t angle;
  329. static int windTab[3] = {2048*5, 2048*10, 2048*25};
  330. if(!mo->momx && !mo->momy)
  331. {
  332. if(mo->flags&MF_SKULLFLY)
  333. { // A flying mobj slammed into something
  334. mo->flags &= ~MF_SKULLFLY;
  335. mo->momx = mo->momy = mo->momz = 0;
  336. P_SetMobjState(mo, mo->info->seestate);
  337. }
  338. return;
  339. }
  340. special = mo->subsector->sector->special;
  341. if(mo->flags2&MF2_WINDTHRUST)
  342. {
  343. switch(special)
  344. {
  345. case 40: case 41: case 42: // Wind_East
  346. P_ThrustMobj(mo, 0, windTab[special-40]);
  347. break;
  348. case 43: case 44: case 45: // Wind_North
  349. P_ThrustMobj(mo, ANG90, windTab[special-43]);
  350. break;
  351. case 46: case 47: case 48: // Wind_South
  352. P_ThrustMobj(mo, ANG270, windTab[special-46]);
  353. break;
  354. case 49: case 50: case 51: // Wind_West
  355. P_ThrustMobj(mo, ANG180, windTab[special-49]);
  356. break;
  357. }
  358. }
  359. player = mo->player;
  360. if(mo->momx > MAXMOVE)
  361. {
  362. mo->momx = MAXMOVE;
  363. }
  364. else if(mo->momx < -MAXMOVE)
  365. {
  366. mo->momx = -MAXMOVE;
  367. }
  368. if(mo->momy > MAXMOVE)
  369. {
  370. mo->momy = MAXMOVE;
  371. }
  372. else if(mo->momy < -MAXMOVE)
  373. {
  374. mo->momy = -MAXMOVE;
  375. }
  376. xmove = mo->momx;
  377. ymove = mo->momy;
  378. do
  379. {
  380. if(xmove > MAXMOVE/2 || ymove > MAXMOVE/2)
  381. {
  382. ptryx = mo->x+xmove/2;
  383. ptryy = mo->y+ymove/2;
  384. xmove >>= 1;
  385. ymove >>= 1;
  386. }
  387. else
  388. {
  389. ptryx = mo->x + xmove;
  390. ptryy = mo->y + ymove;
  391. xmove = ymove = 0;
  392. }
  393. if(!P_TryMove(mo, ptryx, ptryy))
  394. { // Blocked move
  395. if(mo->flags2&MF2_SLIDE)
  396. { // Try to slide along it
  397. if(BlockingMobj == NULL)
  398. { // Slide against wall
  399. P_SlideMove(mo);
  400. }
  401. else
  402. { // Slide against mobj
  403. //if(P_TryMove(mo, mo->x, mo->y+mo->momy))
  404. if(P_TryMove(mo, mo->x, ptryy))
  405. {
  406. mo->momx = 0;
  407. }
  408. //else if(P_TryMove(mo, mo->x+mo->momx, mo->y))
  409. else if(P_TryMove(mo, ptryx, mo->y))
  410. {
  411. mo->momy = 0;
  412. }
  413. else
  414. {
  415. mo->momx = mo->momy = 0;
  416. }
  417. }
  418. }
  419. else if(mo->flags&MF_MISSILE)
  420. {
  421. if(mo->flags2&MF2_FLOORBOUNCE)
  422. {
  423. if(BlockingMobj)
  424. {
  425. if ((BlockingMobj->flags2&MF2_REFLECTIVE) ||
  426. ((!BlockingMobj->player) &&
  427. (!(BlockingMobj->flags&MF_COUNTKILL))))
  428. {
  429. fixed_t speed;
  430. angle = R_PointToAngle2(BlockingMobj->x,
  431. BlockingMobj->y, mo->x, mo->y)
  432. +ANGLE_1*((P_Random()%16)-8);
  433. speed = P_AproxDistance(mo->momx, mo->momy);
  434. speed = FixedMul(speed, 0.75*FRACUNIT);
  435. mo->angle = angle;
  436. angle >>= ANGLETOFINESHIFT;
  437. mo->momx = FixedMul(speed, finecosine[angle]);
  438. mo->momy = FixedMul(speed, finesine[angle]);
  439. if(mo->info->seesound)
  440. {
  441. S_StartSound(mo, mo->info->seesound);
  442. }
  443. return;
  444. }
  445. else
  446. { // Struck a player/creature
  447. P_ExplodeMissile(mo);
  448. }
  449. }
  450. else
  451. { // Struck a wall
  452. P_BounceWall(mo);
  453. switch(mo->type)
  454. {
  455. case MT_SORCBALL1:
  456. case MT_SORCBALL2:
  457. case MT_SORCBALL3:
  458. case MT_SORCFX1:
  459. break;
  460. default:
  461. if(mo->info->seesound)
  462. {
  463. S_StartSound(mo, mo->info->seesound);
  464. }
  465. break;
  466. }
  467. return;
  468. }
  469. }
  470. if(BlockingMobj &&
  471. (BlockingMobj->flags2 & MF2_REFLECTIVE))
  472. {
  473. angle = R_PointToAngle2(BlockingMobj->x,
  474. BlockingMobj->y,
  475. mo->x, mo->y);
  476. // Change angle for delflection/reflection
  477. switch(BlockingMobj->type)
  478. {
  479. case MT_CENTAUR:
  480. case MT_CENTAURLEADER:
  481. if ( abs(angle-BlockingMobj->angle)>>24 > 45)
  482. goto explode;
  483. if (mo->type == MT_HOLY_FX)
  484. goto explode;
  485. // Drop through to sorcerer full reflection
  486. case MT_SORCBOSS:
  487. // Deflection
  488. if (P_Random()<128)
  489. angle += ANGLE_45;
  490. else
  491. angle -= ANGLE_45;
  492. break;
  493. default:
  494. // Reflection
  495. angle += ANGLE_1 * ((P_Random()%16)-8);
  496. break;
  497. }
  498. // Reflect the missile along angle
  499. mo->angle = angle;
  500. angle >>= ANGLETOFINESHIFT;
  501. mo->momx = FixedMul(mo->info->speed>>1, finecosine[angle]);
  502. mo->momy = FixedMul(mo->info->speed>>1, finesine[angle]);
  503. // mo->momz = -mo->momz;
  504. if (mo->flags2 & MF2_SEEKERMISSILE)
  505. {
  506. mo->special1 = (int)(mo->target);
  507. }
  508. mo->target = BlockingMobj;
  509. return;
  510. }
  511. explode:
  512. // Explode a missile
  513. if(ceilingline && ceilingline->backsector
  514. && ceilingline->backsector->ceilingpic == skyflatnum)
  515. { // Hack to prevent missiles exploding against the sky
  516. if(mo->type == MT_BLOODYSKULL)
  517. {
  518. mo->momx = mo->momy = 0;
  519. mo->momz = -FRACUNIT;
  520. }
  521. else if(mo->type == MT_HOLY_FX)
  522. {
  523. P_ExplodeMissile(mo);
  524. }
  525. else
  526. {
  527. P_RemoveMobj(mo);
  528. }
  529. return;
  530. }
  531. P_ExplodeMissile(mo);
  532. }
  533. //else if(mo->info->crashstate)
  534. //{
  535. // mo->momx = mo->momy = 0;
  536. // P_SetMobjState(mo, mo->info->crashstate);
  537. // return;
  538. //}
  539. else
  540. {
  541. mo->momx = mo->momy = 0;
  542. }
  543. }
  544. } while(xmove || ymove);
  545. // Friction
  546. if(player && player->cheats&CF_NOMOMENTUM)
  547. { // Debug option for no sliding at all
  548. mo->momx = mo->momy = 0;
  549. return;
  550. }
  551. if(mo->flags&(MF_MISSILE|MF_SKULLFLY))
  552. { // No friction for missiles
  553. return;
  554. }
  555. if(mo->z > mo->floorz && !(mo->flags2&MF2_FLY) && !(mo->flags2&MF2_ONMOBJ))
  556. { // No friction when falling
  557. if (mo->type != MT_BLASTEFFECT)
  558. return;
  559. }
  560. if(mo->flags&MF_CORPSE)
  561. { // Don't stop sliding if halfway off a step with some momentum
  562. if(mo->momx > FRACUNIT/4 || mo->momx < -FRACUNIT/4
  563. || mo->momy > FRACUNIT/4 || mo->momy < -FRACUNIT/4)
  564. {
  565. if(mo->floorz != mo->subsector->sector->floorheight)
  566. {
  567. return;
  568. }
  569. }
  570. }
  571. if(mo->momx > -STOPSPEED && mo->momx < STOPSPEED
  572. && mo->momy > -STOPSPEED && mo->momy < STOPSPEED
  573. && (!player || (player->cmd.forwardmove == 0
  574. && player->cmd.sidemove == 0)))
  575. { // If in a walking frame, stop moving
  576. if(player)
  577. {
  578. if((unsigned)((player->mo->state-states)
  579. -PStateRun[player->class]) < 4)
  580. {
  581. P_SetMobjState(player->mo, PStateNormal[player->class]);
  582. }
  583. }
  584. mo->momx = 0;
  585. mo->momy = 0;
  586. }
  587. else
  588. {
  589. if(mo->flags2&MF2_FLY && !(mo->z <= mo->floorz)
  590. &&!(mo->flags2&MF2_ONMOBJ))
  591. {
  592. mo->momx = FixedMul(mo->momx, FRICTION_FLY);
  593. mo->momy = FixedMul(mo->momy, FRICTION_FLY);
  594. }
  595. else if(P_GetThingFloorType(mo) == FLOOR_ICE)
  596. {
  597. mo->momx = FixedMul(mo->momx, FRICTION_LOW);
  598. mo->momy = FixedMul(mo->momy, FRICTION_LOW);
  599. }
  600. else
  601. {
  602. mo->momx = FixedMul(mo->momx, FRICTION_NORMAL);
  603. mo->momy = FixedMul(mo->momy, FRICTION_NORMAL);
  604. }
  605. }
  606. }
  607. // Move this to p_inter ***
  608. void P_MonsterFallingDamage(mobj_t *mo)
  609. {
  610. int damage;
  611. int mom;
  612. mom = abs(mo->momz);
  613. if(mom > 35*FRACUNIT)
  614. { // automatic death
  615. damage=10000;
  616. }
  617. else
  618. {
  619. damage = ((mom - (23*FRACUNIT) )*6)>>FRACBITS;
  620. }
  621. damage=10000; // always kill 'em
  622. P_DamageMobj(mo, NULL, NULL, damage);
  623. }
  624. /*
  625. ===============
  626. =
  627. = P_ZMovement
  628. =
  629. ===============
  630. */
  631. void P_ZMovement(mobj_t *mo)
  632. {
  633. int dist;
  634. int delta;
  635. //
  636. // check for smooth step up
  637. //
  638. if (mo->player && mo->z < mo->floorz)
  639. {
  640. mo->player->viewheight -= mo->floorz-mo->z;
  641. mo->player->deltaviewheight = (VIEWHEIGHT - mo->player->viewheight)>>3;
  642. }
  643. //
  644. // adjust height
  645. //
  646. mo->z += mo->momz;
  647. if(mo->flags&MF_FLOAT && mo->target)
  648. { // float down towards target if too close
  649. if(!(mo->flags&MF_SKULLFLY) && !(mo->flags&MF_INFLOAT))
  650. {
  651. dist = P_AproxDistance(mo->x-mo->target->x, mo->y-mo->target->y);
  652. delta =( mo->target->z+(mo->height>>1))-mo->z;
  653. if (delta < 0 && dist < -(delta*3))
  654. mo->z -= FLOATSPEED;
  655. else if (delta > 0 && dist < (delta*3))
  656. mo->z += FLOATSPEED;
  657. }
  658. }
  659. if(mo->player && mo->flags2&MF2_FLY && !(mo->z <= mo->floorz)
  660. && leveltime&2)
  661. {
  662. mo->z += finesine[(FINEANGLES/20*leveltime>>2)&FINEMASK];
  663. }
  664. //
  665. // clip movement
  666. //
  667. if(mo->z <= mo->floorz)
  668. { // Hit the floor
  669. if(mo->flags&MF_MISSILE)
  670. {
  671. mo->z = mo->floorz;
  672. if(mo->flags2&MF2_FLOORBOUNCE)
  673. {
  674. P_FloorBounceMissile(mo);
  675. return;
  676. }
  677. else if(mo->type == MT_HOLY_FX)
  678. { // The spirit struck the ground
  679. mo->momz = 0;
  680. P_HitFloor(mo);
  681. return;
  682. }
  683. else if(mo->type == MT_MNTRFX2 || mo->type == MT_LIGHTNING_FLOOR)
  684. { // Minotaur floor fire can go up steps
  685. return;
  686. }
  687. else
  688. {
  689. P_HitFloor(mo);
  690. P_ExplodeMissile(mo);
  691. return;
  692. }
  693. }
  694. if(mo->flags&MF_COUNTKILL) // Blasted mobj falling
  695. {
  696. if(mo->momz < -(23*FRACUNIT))
  697. {
  698. P_MonsterFallingDamage(mo);
  699. }
  700. }
  701. if(mo->z-mo->momz > mo->floorz)
  702. { // Spawn splashes, etc.
  703. P_HitFloor(mo);
  704. }
  705. mo->z = mo->floorz;
  706. if(mo->momz < 0)
  707. {
  708. if(mo->flags2&MF2_ICEDAMAGE && mo->momz < -GRAVITY*8)
  709. {
  710. mo->tics = 1;
  711. mo->momx = 0;
  712. mo->momy = 0;
  713. mo->momz = 0;
  714. return;
  715. }
  716. if(mo->player)
  717. {
  718. mo->player->jumpTics = 7;// delay any jumping for a short time
  719. if(mo->momz < -GRAVITY*8 && !(mo->flags2&MF2_FLY))
  720. { // squat down
  721. mo->player->deltaviewheight = mo->momz>>3;
  722. if(mo->momz < -23*FRACUNIT)
  723. {
  724. P_FallingDamage(mo->player);
  725. P_NoiseAlert(mo, mo);
  726. }
  727. else if(mo->momz < -GRAVITY*12 && !mo->player->morphTics)
  728. {
  729. S_StartSound(mo, SFX_PLAYER_LAND);
  730. switch(mo->player->class)
  731. {
  732. case PCLASS_FIGHTER:
  733. S_StartSound(mo, SFX_PLAYER_FIGHTER_GRUNT);
  734. break;
  735. case PCLASS_CLERIC:
  736. S_StartSound(mo, SFX_PLAYER_CLERIC_GRUNT);
  737. break;
  738. case PCLASS_MAGE:
  739. S_StartSound(mo, SFX_PLAYER_MAGE_GRUNT);
  740. break;
  741. default:
  742. break;
  743. }
  744. }
  745. else if ((P_GetThingFloorType(mo) < FLOOR_LIQUID) &&
  746. (!mo->player->morphTics))
  747. {
  748. S_StartSound(mo, SFX_PLAYER_LAND);
  749. }
  750. #ifdef __WATCOMC__
  751. if(!useexterndriver)
  752. {
  753. mo->player->centering = true;
  754. }
  755. #else
  756. mo->player->centering = true;
  757. #endif
  758. }
  759. }
  760. else if(mo->type >= MT_POTTERY1
  761. && mo->type <= MT_POTTERY3)
  762. {
  763. P_DamageMobj(mo, NULL, NULL, 25);
  764. }
  765. else if(mo->flags&MF_COUNTKILL)
  766. {
  767. if(mo->momz < -23*FRACUNIT)
  768. {
  769. // Doesn't get here
  770. }
  771. }
  772. mo->momz = 0;
  773. }
  774. if(mo->flags&MF_SKULLFLY)
  775. { // The skull slammed into something
  776. mo->momz = -mo->momz;
  777. }
  778. if(mo->info->crashstate &&
  779. (mo->flags&MF_CORPSE) &&
  780. !(mo->flags2&MF2_ICEDAMAGE))
  781. {
  782. P_SetMobjState(mo, mo->info->crashstate);
  783. return;
  784. }
  785. }
  786. else if(mo->flags2&MF2_LOGRAV)
  787. {
  788. if(mo->momz == 0)
  789. mo->momz = -(GRAVITY>>3)*2;
  790. else
  791. mo->momz -= GRAVITY>>3;
  792. }
  793. else if (! (mo->flags & MF_NOGRAVITY) )
  794. {
  795. if (mo->momz == 0)
  796. mo->momz = -GRAVITY*2;
  797. else
  798. mo->momz -= GRAVITY;
  799. }
  800. if (mo->z + mo->height > mo->ceilingz)
  801. { // hit the ceiling
  802. if (mo->momz > 0)
  803. mo->momz = 0;
  804. mo->z = mo->ceilingz - mo->height;
  805. if(mo->flags2&MF2_FLOORBOUNCE)
  806. {
  807. // Maybe reverse momentum here for ceiling bounce
  808. // Currently won't happen
  809. if(mo->info->seesound)
  810. {
  811. S_StartSound(mo, mo->info->seesound);
  812. }
  813. return;
  814. }
  815. if (mo->flags & MF_SKULLFLY)
  816. { // the skull slammed into something
  817. mo->momz = -mo->momz;
  818. }
  819. if(mo->flags&MF_MISSILE)
  820. {
  821. if(mo->type == MT_LIGHTNING_CEILING)
  822. {
  823. return;
  824. }
  825. if(mo->subsector->sector->ceilingpic == skyflatnum)
  826. {
  827. if(mo->type == MT_BLOODYSKULL)
  828. {
  829. mo->momx = mo->momy = 0;
  830. mo->momz = -FRACUNIT;
  831. }
  832. else if(mo->type == MT_HOLY_FX)
  833. {
  834. P_ExplodeMissile(mo);
  835. }
  836. else
  837. {
  838. P_RemoveMobj(mo);
  839. }
  840. return;
  841. }
  842. P_ExplodeMissile(mo);
  843. return;
  844. }
  845. }
  846. }
  847. //----------------------------------------------------------------------------
  848. //
  849. // PROC P_BlasterMobjThinker
  850. //
  851. //
  852. //----------------------------------------------------------------------------
  853. void P_BlasterMobjThinker(mobj_t *mobj)
  854. {
  855. int i;
  856. fixed_t xfrac;
  857. fixed_t yfrac;
  858. fixed_t zfrac;
  859. fixed_t z;
  860. boolean changexy;
  861. mobj_t *mo;
  862. // Handle movement
  863. if(mobj->momx || mobj->momy ||
  864. (mobj->z != mobj->floorz) || mobj->momz)
  865. {
  866. xfrac = mobj->momx>>3;
  867. yfrac = mobj->momy>>3;
  868. zfrac = mobj->momz>>3;
  869. changexy = xfrac || yfrac;
  870. for(i = 0; i < 8; i++)
  871. {
  872. if(changexy)
  873. {
  874. if(!P_TryMove(mobj, mobj->x+xfrac, mobj->y+yfrac))
  875. { // Blocked move
  876. P_ExplodeMissile(mobj);
  877. return;
  878. }
  879. }
  880. mobj->z += zfrac;
  881. if(mobj->z <= mobj->floorz)
  882. { // Hit the floor
  883. mobj->z = mobj->floorz;
  884. P_HitFloor(mobj);
  885. P_ExplodeMissile(mobj);
  886. return;
  887. }
  888. if(mobj->z+mobj->height > mobj->ceilingz)
  889. { // Hit the ceiling
  890. mobj->z = mobj->ceilingz-mobj->height;
  891. P_ExplodeMissile(mobj);
  892. return;
  893. }
  894. if(changexy)
  895. {
  896. if(mobj->type == MT_MWAND_MISSILE && (P_Random() < 128))
  897. {
  898. z = mobj->z-8*FRACUNIT;
  899. if(z < mobj->floorz)
  900. {
  901. z = mobj->floorz;
  902. }
  903. P_SpawnMobj(mobj->x, mobj->y, z, MT_MWANDSMOKE);
  904. }
  905. else if(!--mobj->special1)
  906. {
  907. mobj->special1 = 4;
  908. z = mobj->z-12*FRACUNIT;
  909. if(z < mobj->floorz)
  910. {
  911. z = mobj->floorz;
  912. }
  913. mo = P_SpawnMobj(mobj->x, mobj->y, z, MT_CFLAMEFLOOR);
  914. if(mo)
  915. {
  916. mo->angle = mobj->angle;
  917. }
  918. }
  919. }
  920. }
  921. }
  922. // Advance the state
  923. if(mobj->tics != -1)
  924. {
  925. mobj->tics--;
  926. while(!mobj->tics)
  927. {
  928. if(!P_SetMobjState(mobj, mobj->state->nextstate))
  929. { // mobj was removed
  930. return;
  931. }
  932. }
  933. }
  934. }
  935. //===========================================================================
  936. //
  937. // PlayerLandedOnThing
  938. //
  939. //===========================================================================
  940. static void PlayerLandedOnThing(mobj_t *mo, mobj_t *onmobj)
  941. {
  942. mo->player->deltaviewheight = mo->momz>>3;
  943. if(mo->momz < -23*FRACUNIT)
  944. {
  945. P_FallingDamage(mo->player);
  946. P_NoiseAlert(mo, mo);
  947. }
  948. else if(mo->momz < -GRAVITY*12
  949. && !mo->player->morphTics)
  950. {
  951. S_StartSound(mo, SFX_PLAYER_LAND);
  952. switch(mo->player->class)
  953. {
  954. case PCLASS_FIGHTER:
  955. S_StartSound(mo, SFX_PLAYER_FIGHTER_GRUNT);
  956. break;
  957. case PCLASS_CLERIC:
  958. S_StartSound(mo, SFX_PLAYER_CLERIC_GRUNT);
  959. break;
  960. case PCLASS_MAGE:
  961. S_StartSound(mo, SFX_PLAYER_MAGE_GRUNT);
  962. break;
  963. default:
  964. break;
  965. }
  966. }
  967. else if(!mo->player->morphTics)
  968. {
  969. S_StartSound(mo, SFX_PLAYER_LAND);
  970. }
  971. #ifdef __WATCOMC__
  972. if(!useexterndriver)
  973. {
  974. mo->player->centering = true;
  975. }
  976. #else
  977. mo->player->centering = true;
  978. #endif
  979. }
  980. //----------------------------------------------------------------------------
  981. //
  982. // PROC P_MobjThinker
  983. //
  984. //----------------------------------------------------------------------------
  985. void P_MobjThinker(mobj_t *mobj)
  986. {
  987. mobj_t *onmo;
  988. /*
  989. // Reset to not blasted when momentums are gone
  990. if((mobj->flags2&MF2_BLASTED) && (!(mobj->momx)) && (!(mobj->momy)))
  991. ResetBlasted(mobj);
  992. */
  993. // Handle X and Y momentums
  994. BlockingMobj = NULL;
  995. if(mobj->momx || mobj->momy || (mobj->flags&MF_SKULLFLY))
  996. {
  997. P_XYMovement(mobj);
  998. if(mobj->thinker.function == (think_t)-1)
  999. { // mobj was removed
  1000. return;
  1001. }
  1002. }
  1003. else if(mobj->flags2&MF2_BLASTED)
  1004. { // Reset to not blasted when momentums are gone
  1005. ResetBlasted(mobj);
  1006. }
  1007. if(mobj->flags2&MF2_FLOATBOB)
  1008. { // Floating item bobbing motion (special1 is height)
  1009. mobj->z = mobj->floorz +
  1010. mobj->special1 +
  1011. FloatBobOffsets[(mobj->health++)&63];
  1012. }
  1013. else if((mobj->z != mobj->floorz) || mobj->momz || BlockingMobj)
  1014. { // Handle Z momentum and gravity
  1015. if(mobj->flags2&MF2_PASSMOBJ)
  1016. {
  1017. if(!(onmo = P_CheckOnmobj(mobj)))
  1018. {
  1019. P_ZMovement(mobj);
  1020. if(mobj->player && mobj->flags&MF2_ONMOBJ)
  1021. {
  1022. mobj->flags2 &= ~MF2_ONMOBJ;
  1023. }
  1024. }
  1025. else
  1026. {
  1027. if(mobj->player)
  1028. {
  1029. if(mobj->momz < -GRAVITY*8 && !(mobj->flags2&MF2_FLY))
  1030. {
  1031. PlayerLandedOnThing(mobj, onmo);
  1032. }
  1033. if(onmo->z+onmo->height-mobj->z <= 24*FRACUNIT)
  1034. {
  1035. mobj->player->viewheight -= onmo->z+onmo->height
  1036. -mobj->z;
  1037. mobj->player->deltaviewheight =
  1038. (VIEWHEIGHT-mobj->player->viewheight)>>3;
  1039. mobj->z = onmo->z+onmo->height;
  1040. mobj->flags2 |= MF2_ONMOBJ;
  1041. mobj->momz = 0;
  1042. }
  1043. else
  1044. { // hit the bottom of the blocking mobj
  1045. mobj->momz = 0;
  1046. }
  1047. }
  1048. /* Landing on another player, and mimicking his movements
  1049. if(mobj->player && onmo->player)
  1050. {
  1051. mobj->momx = onmo->momx;
  1052. mobj->momy = onmo->momy;
  1053. if(onmo->z < onmo->floorz)
  1054. {
  1055. mobj->z += onmo->floorz-onmo->z;
  1056. if(onmo->player)
  1057. {
  1058. onmo->player->viewheight -= onmo->floorz-onmo->z;
  1059. onmo->player->deltaviewheight = (VIEWHEIGHT-
  1060. onmo->player->viewheight)>>3;
  1061. }
  1062. onmo->z = onmo->floorz;
  1063. }
  1064. }
  1065. */
  1066. }
  1067. }
  1068. else
  1069. {
  1070. P_ZMovement(mobj);
  1071. }
  1072. if(mobj->thinker.function == (think_t)-1)
  1073. { // mobj was removed
  1074. return;
  1075. }
  1076. }
  1077. // Cycle through states, calling action functions at transitions
  1078. if(mobj->tics != -1)
  1079. {
  1080. mobj->tics--;
  1081. // you can cycle through multiple states in a tic
  1082. while(!mobj->tics)
  1083. {
  1084. if(!P_SetMobjState(mobj, mobj->state->nextstate))
  1085. { // mobj was removed
  1086. return;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. //==========================================================================
  1092. //
  1093. // P_SpawnMobj
  1094. //
  1095. //==========================================================================
  1096. mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
  1097. {
  1098. mobj_t *mobj;
  1099. state_t *st;
  1100. mobjinfo_t *info;
  1101. fixed_t space;
  1102. mobj = Z_Malloc(sizeof(*mobj), PU_LEVEL, NULL);
  1103. memset(mobj, 0, sizeof(*mobj));
  1104. info = &mobjinfo[type];
  1105. mobj->type = type;
  1106. mobj->info = info;
  1107. mobj->x = x;
  1108. mobj->y = y;
  1109. mobj->radius = info->radius;
  1110. mobj->height = info->height;
  1111. mobj->flags = info->flags;
  1112. mobj->flags2 = info->flags2;
  1113. mobj->damage = info->damage;
  1114. mobj->health = info->spawnhealth;
  1115. if(gameskill != sk_nightmare)
  1116. {
  1117. mobj->reactiontime = info->reactiontime;
  1118. }
  1119. mobj->lastlook = P_Random()%MAXPLAYERS;
  1120. // Set the state, but do not use P_SetMobjState, because action
  1121. // routines can't be called yet. If the spawnstate has an action
  1122. // routine, it will not be called.
  1123. st = &states[info->spawnstate];
  1124. mobj->state = st;
  1125. mobj->tics = st->tics;
  1126. mobj->sprite = st->sprite;
  1127. mobj->frame = st->frame;
  1128. // Set subsector and/or block links.
  1129. P_SetThingPosition(mobj);
  1130. mobj->floorz = mobj->subsector->sector->floorheight;
  1131. mobj->ceilingz = mobj->subsector->sector->ceilingheight;
  1132. if(z == ONFLOORZ)
  1133. {
  1134. mobj->z = mobj->floorz;
  1135. }
  1136. else if(z == ONCEILINGZ)
  1137. {
  1138. mobj->z = mobj->ceilingz-mobj->info->height;
  1139. }
  1140. else if(z == FLOATRANDZ)
  1141. {
  1142. space = ((mobj->ceilingz)-(mobj->info->height))-mobj->floorz;
  1143. if(space > 48*FRACUNIT)
  1144. {
  1145. space -= 40*FRACUNIT;
  1146. mobj->z = ((space*P_Random())>>8)+mobj->floorz+40*FRACUNIT;
  1147. }
  1148. else
  1149. {
  1150. mobj->z = mobj->floorz;
  1151. }
  1152. }
  1153. else if (mobj->flags2&MF2_FLOATBOB)
  1154. {
  1155. mobj->z = mobj->floorz + z; // artifact z passed in as height
  1156. }
  1157. else
  1158. {
  1159. mobj->z = z;
  1160. }
  1161. if(mobj->flags2&MF2_FLOORCLIP && P_GetThingFloorType(mobj) >= FLOOR_LIQUID
  1162. && mobj->z == mobj->subsector->sector->floorheight)
  1163. {
  1164. mobj->floorclip = 10*FRACUNIT;
  1165. }
  1166. else
  1167. {
  1168. mobj->floorclip = 0;
  1169. }
  1170. mobj->thinker.function = P_MobjThinker;
  1171. P_AddThinker(&mobj->thinker);
  1172. return(mobj);
  1173. }
  1174. //==========================================================================
  1175. //
  1176. // P_RemoveMobj
  1177. //
  1178. //==========================================================================
  1179. void P_RemoveMobj(mobj_t *mobj)
  1180. {
  1181. // Remove from creature queue
  1182. if(mobj->flags&MF_COUNTKILL &&
  1183. mobj->flags&MF_CORPSE)
  1184. {
  1185. A_DeQueueCorpse(mobj);
  1186. }
  1187. if(mobj->tid)
  1188. { // Remove from TID list
  1189. P_RemoveMobjFromTIDList(mobj);
  1190. }
  1191. // Unlink from sector and block lists
  1192. P_UnsetThingPosition(mobj);
  1193. // Stop any playing sound
  1194. S_StopSound(mobj);
  1195. // Free block
  1196. P_RemoveThinker((thinker_t *)mobj);
  1197. }
  1198. //==========================================================================
  1199. //
  1200. // P_SpawnPlayer
  1201. //
  1202. // Called when a player is spawned on the level. Most of the player
  1203. // structure stays unchanged between levels.
  1204. //
  1205. //==========================================================================
  1206. void P_SpawnPlayer(mapthing_t *mthing)
  1207. {
  1208. player_t *p;
  1209. fixed_t x, y, z;
  1210. mobj_t *mobj;
  1211. if(!playeringame[mthing->type-1])
  1212. { // Not playing
  1213. return;
  1214. }
  1215. p = &players[mthing->type-1];
  1216. if(p->playerstate == PST_REBORN)
  1217. {
  1218. G_PlayerReborn(mthing->type-1);
  1219. }
  1220. x = mthing->x << FRACBITS;
  1221. y = mthing->y << FRACBITS;
  1222. z = ONFLOORZ;
  1223. if(randomclass && deathmatch)
  1224. {
  1225. p->class = P_Random()%3;
  1226. if(p->class == PlayerClass[mthing->type-1])
  1227. {
  1228. p->class = (p->class+1)%3;
  1229. }
  1230. PlayerClass[mthing->type-1] = p->class;
  1231. SB_SetClassData();
  1232. }
  1233. else
  1234. {
  1235. p->class = PlayerClass[mthing->type-1];
  1236. }
  1237. switch(p->class)
  1238. {
  1239. case PCLASS_FIGHTER:
  1240. mobj = P_SpawnMobj(x, y, z, MT_PLAYER_FIGHTER);
  1241. break;
  1242. case PCLASS_CLERIC:
  1243. mobj = P_SpawnMobj(x, y, z, MT_PLAYER_CLERIC);
  1244. break;
  1245. case PCLASS_MAGE:
  1246. mobj = P_SpawnMobj(x, y, z, MT_PLAYER_MAGE);
  1247. break;
  1248. default:
  1249. I_Error("P_SpawnPlayer: Unknown class type");
  1250. break;
  1251. }
  1252. // Set translation table data
  1253. if(p->class == PCLASS_FIGHTER && (mthing->type == 1 || mthing->type == 3))
  1254. {
  1255. // The first type should be blue, and the third should be the
  1256. // Fighter's original gold color
  1257. if(mthing->type == 1)
  1258. {
  1259. mobj->flags |= 2<<MF_TRANSSHIFT;
  1260. }
  1261. }
  1262. else if(mthing->type > 1)
  1263. { // Set color translation bits for player sprites
  1264. mobj->flags |= (mthing->type-1)<<MF_TRANSSHIFT;
  1265. }
  1266. mobj->angle = ANG45 * (mthing->angle/45);
  1267. mobj->player = p;
  1268. mobj->health = p->health;
  1269. p->mo = mobj;
  1270. p->playerstate = PST_LIVE;
  1271. p->refire = 0;
  1272. P_ClearMessage(p);
  1273. p->damagecount = 0;
  1274. p->bonuscount = 0;
  1275. p->poisoncount = 0;
  1276. p->morphTics = 0;
  1277. p->extralight = 0;
  1278. p->fixedcolormap = 0;
  1279. p->viewheight = VIEWHEIGHT;
  1280. P_SetupPsprites(p);
  1281. if(deathmatch)
  1282. { // Give all keys in death match mode
  1283. p->keys = 2047;
  1284. }
  1285. }
  1286. //==========================================================================
  1287. //
  1288. // P_SpawnMapThing
  1289. //
  1290. // The fields of the mapthing should already be in host byte order.
  1291. //
  1292. //==========================================================================
  1293. void P_SpawnMapThing(mapthing_t *mthing)
  1294. {
  1295. int i;
  1296. unsigned int spawnMask;
  1297. mobj_t *mobj;
  1298. fixed_t x, y, z;
  1299. static unsigned int classFlags[] =
  1300. {
  1301. MTF_FIGHTER,
  1302. MTF_CLERIC,
  1303. MTF_MAGE
  1304. };
  1305. // Count deathmatch start positions
  1306. if(mthing->type == 11)
  1307. {
  1308. if(deathmatch_p < &deathmatchstarts[MAXDEATHMATCHSTARTS])
  1309. {
  1310. memcpy(deathmatch_p, mthing, sizeof(*mthing));
  1311. deathmatch_p++;
  1312. }
  1313. return;
  1314. }
  1315. if(mthing->type == PO_ANCHOR_TYPE)
  1316. { // Polyobj Anchor Pt.
  1317. return;
  1318. }
  1319. else if(mthing->type == PO_SPAWN_TYPE
  1320. || mthing->type == PO_SPAWNCRUSH_TYPE)
  1321. { // Polyobj Anchor Pt.
  1322. po_NumPolyobjs++;
  1323. return;
  1324. }
  1325. // Check for player starts 1 to 4
  1326. if(mthing->type <= 4)
  1327. {
  1328. playerstarts[mthing->arg1][mthing->type-1] = *mthing;
  1329. if(!deathmatch && !mthing->arg1)
  1330. {
  1331. P_SpawnPlayer(mthing);
  1332. }
  1333. return;
  1334. }
  1335. // Check for player starts 5 to 8
  1336. if(mthing->type >= 9100 && mthing->type <= 9103)
  1337. {
  1338. mthing->type = 5+mthing->type-9100; // Translate to 5 - 8
  1339. playerstarts[mthing->arg1][mthing->type-1] = *mthing;
  1340. if(!deathmatch && !mthing->arg1)
  1341. {
  1342. P_SpawnPlayer(mthing);
  1343. }
  1344. return;
  1345. }
  1346. if(mthing->type >= 1400 && mthing->type < 1410)
  1347. {
  1348. R_PointInSubsector(mthing->x<<FRACBITS,
  1349. mthing->y<<FRACBITS)->sector->seqType = mthing->type-1400;
  1350. return;
  1351. }
  1352. // Check current game type with spawn flags
  1353. if(netgame == false)
  1354. {
  1355. spawnMask = MTF_GSINGLE;
  1356. }
  1357. else if(deathmatch)
  1358. {
  1359. spawnMask = MTF_GDEATHMATCH;
  1360. }
  1361. else
  1362. {
  1363. spawnMask = MTF_GCOOP;
  1364. }
  1365. if(!(mthing->options&spawnMask))
  1366. {
  1367. return;
  1368. }
  1369. // Check current skill with spawn flags
  1370. if(gameskill == sk_baby || gameskill == sk_easy)
  1371. {
  1372. spawnMask = MTF_EASY;
  1373. }
  1374. else if(gameskill == sk_hard || gameskill == sk_nightmare)
  1375. {
  1376. spawnMask = MTF_HARD;
  1377. }
  1378. else
  1379. {
  1380. spawnMask = MTF_NORMAL;
  1381. }
  1382. if(!(mthing->options&spawnMask))
  1383. {
  1384. return;
  1385. }
  1386. // Check current character classes with spawn flags
  1387. if(netgame == false)
  1388. { // Single player
  1389. if((mthing->options&classFlags[PlayerClass[0]]) == 0)
  1390. { // Not for current class
  1391. return;
  1392. }
  1393. }
  1394. else if(deathmatch == false)
  1395. { // Cooperative
  1396. spawnMask = 0;
  1397. for(i = 0; i < MAXPLAYERS; i++)
  1398. {
  1399. if(playeringame[i])
  1400. {
  1401. spawnMask |= classFlags[PlayerClass[i]];
  1402. }
  1403. }
  1404. if((mthing->options&spawnMask) == 0)
  1405. {
  1406. return;
  1407. }
  1408. }
  1409. // Find which type to spawn
  1410. for(i = 0; i < NUMMOBJTYPES; i++)
  1411. {
  1412. if(mthing->type == mobjinfo[i].doomednum)
  1413. {
  1414. break;
  1415. }
  1416. }
  1417. if(i == NUMMOBJTYPES)
  1418. { // Can't find thing type
  1419. I_Error("P_SpawnMapThing: Unknown type %i at (%i, %i)",
  1420. mthing->type, mthing->x, mthing->y);
  1421. }
  1422. // Don't spawn keys and players in deathmatch
  1423. if(deathmatch && mobjinfo[i].flags&MF_NOTDMATCH)
  1424. {
  1425. return;
  1426. }
  1427. // Don't spawn monsters if -nomonsters
  1428. if(nomonsters && (mobjinfo[i].flags&MF_COUNTKILL))
  1429. {
  1430. return;
  1431. }
  1432. x = mthing->x<<FRACBITS;
  1433. y = mthing->y<<FRACBITS;
  1434. if(mobjinfo[i].flags&MF_SPAWNCEILING)
  1435. {
  1436. z = ONCEILINGZ;
  1437. }
  1438. else if(mobjinfo[i].flags2&MF2_SPAWNFLOAT)
  1439. {
  1440. z = FLOATRANDZ;
  1441. }
  1442. else if(mobjinfo[i].flags2&MF2_FLOATBOB)
  1443. {
  1444. z = mthing->height<<FRACBITS;
  1445. }
  1446. else
  1447. {
  1448. z = ONFLOORZ;
  1449. }
  1450. switch(i)
  1451. { // Special stuff
  1452. case MT_ZLYNCHED_NOHEART:
  1453. P_SpawnMobj(x, y, ONFLOORZ, MT_BLOODPOOL);
  1454. break;
  1455. default:
  1456. break;
  1457. }
  1458. mobj = P_SpawnMobj(x, y, z, i);
  1459. if(z == ONFLOORZ)
  1460. {
  1461. mobj->z += mthing->height<<FRACBITS;
  1462. }
  1463. else if(z == ONCEILINGZ)
  1464. {
  1465. mobj->z -= mthing->height<<FRACBITS;
  1466. }
  1467. mobj->tid = mthing->tid;
  1468. mobj->special = mthing->special;
  1469. mobj->args[0] = mthing->arg1;
  1470. mobj->args[1] = mthing->arg2;
  1471. mobj->args[2] = mthing->arg3;
  1472. mobj->args[3] = mthing->arg4;
  1473. mobj->args[4] = mthing->arg5;
  1474. if(mobj->flags2&MF2_FLOATBOB)
  1475. { // Seed random starting index for bobbing motion
  1476. mobj->health = P_Random();
  1477. mobj->special1 = mthing->height<<FRACBITS;
  1478. }
  1479. if(mobj->tics > 0)
  1480. {
  1481. mobj->tics = 1+(P_Random()%mobj->tics);
  1482. }
  1483. // if(mobj->flags&MF_COUNTITEM)
  1484. // {
  1485. // totalitems++;
  1486. // }
  1487. if (mobj->flags&MF_COUNTKILL)
  1488. {
  1489. // Quantize angle to 45 degree increments
  1490. mobj->angle = ANG45*(mthing->angle/45);
  1491. }
  1492. else
  1493. {
  1494. // Scale angle correctly (source is 0..359)
  1495. mobj->angle = ((mthing->angle<<8)/360)<<24;
  1496. }
  1497. if(mthing->options&MTF_AMBUSH)
  1498. {
  1499. mobj->flags |= MF_AMBUSH;
  1500. }
  1501. if(mthing->options&MTF_DORMANT)
  1502. {
  1503. mobj->flags2 |= MF2_DORMANT;
  1504. if(mobj->type == MT_ICEGUY)
  1505. {
  1506. P_SetMobjState(mobj, S_ICEGUY_DORMANT);
  1507. }
  1508. mobj->tics = -1;
  1509. }
  1510. }
  1511. //==========================================================================
  1512. //
  1513. // P_CreateTIDList
  1514. //
  1515. //==========================================================================
  1516. void P_CreateTIDList(void)
  1517. {
  1518. int i;
  1519. mobj_t *mobj;
  1520. thinker_t *t;
  1521. i = 0;
  1522. for(t = thinkercap.next; t != &thinkercap; t = t->next)
  1523. { // Search all current thinkers
  1524. if(t->function != P_MobjThinker)
  1525. { // Not a mobj thinker
  1526. continue;
  1527. }
  1528. mobj = (mobj_t *)t;
  1529. if(mobj->tid != 0)
  1530. { // Add to list
  1531. if(i == MAX_TID_COUNT)
  1532. {
  1533. I_Error("P_CreateTIDList: MAX_TID_COUNT (%d) exceeded.",
  1534. MAX_TID_COUNT);
  1535. }
  1536. TIDList[i] = mobj->tid;
  1537. TIDMobj[i++] = mobj;
  1538. }
  1539. }
  1540. // Add termination marker
  1541. TIDList[i] = 0;
  1542. }
  1543. //==========================================================================
  1544. //
  1545. // P_InsertMobjIntoTIDList
  1546. //
  1547. //==========================================================================
  1548. void P_InsertMobjIntoTIDList(mobj_t *mobj, int tid)
  1549. {
  1550. int i;
  1551. int index;
  1552. index = -1;
  1553. for(i = 0; TIDList[i] != 0; i++)
  1554. {
  1555. if(TIDList[i] == -1)
  1556. { // Found empty slot
  1557. index = i;
  1558. break;
  1559. }
  1560. }
  1561. if(index == -1)
  1562. { // Append required
  1563. if(i == MAX_TID_COUNT)
  1564. {
  1565. I_Error("P_InsertMobjIntoTIDList: MAX_TID_COUNT (%d)"
  1566. "exceeded.", MAX_TID_COUNT);
  1567. }
  1568. index = i;
  1569. TIDList[index+1] = 0;
  1570. }
  1571. mobj->tid = tid;
  1572. TIDList[index] = tid;
  1573. TIDMobj[index] = mobj;
  1574. }
  1575. //==========================================================================
  1576. //
  1577. // P_RemoveMobjFromTIDList
  1578. //
  1579. //==========================================================================
  1580. void P_RemoveMobjFromTIDList(mobj_t *mobj)
  1581. {
  1582. int i;
  1583. for(i = 0; TIDList[i] != 0; i++)
  1584. {
  1585. if(TIDMobj[i] == mobj)
  1586. {
  1587. TIDList[i] = -1;
  1588. TIDMobj[i] = NULL;
  1589. mobj->tid = 0;
  1590. return;
  1591. }
  1592. }
  1593. mobj->tid = 0;
  1594. }
  1595. //==========================================================================
  1596. //
  1597. // P_FindMobjFromTID
  1598. //
  1599. //==========================================================================
  1600. mobj_t *P_FindMobjFromTID(int tid, int *searchPosition)
  1601. {
  1602. int i;
  1603. for(i = *searchPosition+1; TIDList[i] != 0; i++)
  1604. {
  1605. if(TIDList[i] == tid)
  1606. {
  1607. *searchPosition = i;
  1608. return TIDMobj[i];
  1609. }
  1610. }
  1611. *searchPosition = -1;
  1612. return NULL;
  1613. }
  1614. /*
  1615. ===============================================================================
  1616. GAME SPAWN FUNCTIONS
  1617. ===============================================================================
  1618. */
  1619. //---------------------------------------------------------------------------
  1620. //
  1621. // PROC P_SpawnPuff
  1622. //
  1623. //---------------------------------------------------------------------------
  1624. extern fixed_t attackrange;
  1625. void P_SpawnPuff(fixed_t x, fixed_t y, fixed_t z)
  1626. {
  1627. mobj_t *puff;
  1628. z += ((P_Random()-P_Random())<<10);
  1629. puff = P_SpawnMobj(x, y, z, PuffType);
  1630. if(linetarget && puff->info->seesound)
  1631. { // Hit thing sound
  1632. S_StartSound(puff, puff->info->seesound);
  1633. }
  1634. else if(puff->info->attacksound)
  1635. {
  1636. S_StartSound(puff, puff->info->attacksound);
  1637. }
  1638. switch(PuffType)
  1639. {
  1640. case MT_PUNCHPUFF:
  1641. puff->momz = FRACUNIT;
  1642. break;
  1643. case MT_HAMMERPUFF:
  1644. puff->momz = .8*FRACUNIT;
  1645. break;
  1646. default:
  1647. break;
  1648. }
  1649. PuffSpawned = puff;
  1650. }
  1651. /*
  1652. ================
  1653. =
  1654. = P_SpawnBlood
  1655. =
  1656. ================
  1657. */
  1658. /*
  1659. void P_SpawnBlood (fixed_t x, fixed_t y, fixed_t z, int damage)
  1660. {
  1661. mobj_t *th;
  1662. z += ((P_Random()-P_Random())<<10);
  1663. th = P_SpawnMobj (x,y,z, MT_BLOOD);
  1664. th->momz = FRACUNIT*2;
  1665. th->tics -= P_Random()&3;
  1666. if (damage <= 12 && damage >= 9)
  1667. P_SetMobjState (th,S_BLOOD2);
  1668. else if (damage < 9)
  1669. P_SetMobjState (th,S_BLOOD3);
  1670. }
  1671. */
  1672. //---------------------------------------------------------------------------
  1673. //
  1674. // PROC P_BloodSplatter
  1675. //
  1676. //---------------------------------------------------------------------------
  1677. void P_BloodSplatter(fixed_t x, fixed_t y, fixed_t z, mobj_t *originator)
  1678. {
  1679. mobj_t *mo;
  1680. mo = P_SpawnMobj(x, y, z, MT_BLOODSPLATTER);
  1681. mo->target = originator;
  1682. mo->momx = (P_Random()-P_Random())<<10;
  1683. mo->momy = (P_Random()-P_Random())<<10;
  1684. mo->momz = 3*FRACUNIT;
  1685. }
  1686. //===========================================================================
  1687. //
  1688. // P_BloodSplatter2
  1689. //
  1690. //===========================================================================
  1691. void P_BloodSplatter2(fixed_t x, fixed_t y, fixed_t z, mobj_t *originator)
  1692. {
  1693. mobj_t *mo;
  1694. mo = P_SpawnMobj(x+((P_Random()-128)<<11), y+((P_Random()-128)<<11), z,
  1695. MT_AXEBLOOD);
  1696. mo->target = originator;
  1697. }
  1698. //---------------------------------------------------------------------------
  1699. //
  1700. // PROC P_RipperBlood
  1701. //
  1702. //---------------------------------------------------------------------------
  1703. void P_RipperBlood(mobj_t *mo)
  1704. {
  1705. mobj_t *th;
  1706. fixed_t x, y, z;
  1707. x = mo->x+((P_Random()-P_Random())<<12);
  1708. y = mo->y+((P_Random()-P_Random())<<12);
  1709. z = mo->z+((P_Random()-P_Random())<<12);
  1710. th = P_SpawnMobj(x, y, z, MT_BLOOD);
  1711. // th->flags |= MF_NOGRAVITY;
  1712. th->momx = mo->momx>>1;
  1713. th->momy = mo->momy>>1;
  1714. th->tics += P_Random()&3;
  1715. }
  1716. //---------------------------------------------------------------------------
  1717. //
  1718. // FUNC P_GetThingFloorType
  1719. //
  1720. //---------------------------------------------------------------------------
  1721. int P_GetThingFloorType(mobj_t *thing)
  1722. {
  1723. if(thing->floorpic)
  1724. {
  1725. return(TerrainTypes[thing->floorpic]);
  1726. }
  1727. else
  1728. {
  1729. return(TerrainTypes[thing->subsector->sector->floorpic]);
  1730. }
  1731. /*
  1732. if(thing->subsector->sector->floorpic
  1733. == W_GetNumForName("FLTWAWA1")-firstflat)
  1734. {
  1735. return(FLOOR_WATER);
  1736. }
  1737. else
  1738. {
  1739. return(FLOOR_SOLID);
  1740. }
  1741. */
  1742. }
  1743. //---------------------------------------------------------------------------
  1744. //
  1745. // FUNC P_HitFloor
  1746. //
  1747. //---------------------------------------------------------------------------
  1748. #define SMALLSPLASHCLIP 12<<FRACBITS;
  1749. int P_HitFloor(mobj_t *thing)
  1750. {
  1751. mobj_t *mo;
  1752. int smallsplash=false;
  1753. if(thing->floorz != thing->subsector->sector->floorheight)
  1754. { // don't splash if landing on the edge above water/lava/etc....
  1755. return(FLOOR_SOLID);
  1756. }
  1757. // Things that don't splash go here
  1758. switch(thing->type)
  1759. {
  1760. case MT_LEAF1:
  1761. case MT_LEAF2:
  1762. // case MT_BLOOD: // I set these to low mass -- pm
  1763. // case MT_BLOODSPLATTER:
  1764. case MT_SPLASH:
  1765. case MT_SLUDGECHUNK:
  1766. return(FLOOR_SOLID);
  1767. default:
  1768. break;
  1769. }
  1770. // Small splash for small masses
  1771. if (thing->info->mass < 10) smallsplash = true;
  1772. switch(P_GetThingFloorType(thing))
  1773. {
  1774. case FLOOR_WATER:
  1775. if (smallsplash)
  1776. {
  1777. mo=P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_SPLASHBASE);
  1778. if (mo) mo->floorclip += SMALLSPLASHCLIP;
  1779. S_StartSound(mo, SFX_AMBIENT10); // small drip
  1780. }
  1781. else
  1782. {
  1783. mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_SPLASH);
  1784. mo->target = thing;
  1785. mo->momx = (P_Random()-P_Random())<<8;
  1786. mo->momy = (P_Random()-P_Random())<<8;
  1787. mo->momz = 2*FRACUNIT+(P_Random()<<8);
  1788. mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_SPLASHBASE);
  1789. if (thing->player) P_NoiseAlert(thing, thing);
  1790. S_StartSound(mo, SFX_WATER_SPLASH);
  1791. }
  1792. return(FLOOR_WATER);
  1793. case FLOOR_LAVA:
  1794. if (smallsplash)
  1795. {
  1796. mo=P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_LAVASPLASH);
  1797. if (mo) mo->floorclip += SMALLSPLASHCLIP;
  1798. }
  1799. else
  1800. {
  1801. mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_LAVASMOKE);
  1802. mo->momz = FRACUNIT+(P_Random()<<7);
  1803. mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_LAVASPLASH);
  1804. if (thing->player) P_NoiseAlert(thing, thing);
  1805. }
  1806. S_StartSound(mo, SFX_LAVA_SIZZLE);
  1807. if(thing->player && leveltime&31)
  1808. {
  1809. P_DamageMobj(thing, &LavaInflictor, NULL, 5);
  1810. }
  1811. return(FLOOR_LAVA);
  1812. case FLOOR_SLUDGE:
  1813. if (smallsplash)
  1814. {
  1815. mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ,
  1816. MT_SLUDGESPLASH);
  1817. if (mo) mo->floorclip += SMALLSPLASHCLIP;
  1818. }
  1819. else
  1820. {
  1821. mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_SLUDGECHUNK);
  1822. mo->target = thing;
  1823. mo->momx = (P_Random()-P_Random())<<8;
  1824. mo->momy = (P_Random()-P_Random())<<8;
  1825. mo->momz = FRACUNIT+(P_Random()<<8);
  1826. mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ,
  1827. MT_SLUDGESPLASH);
  1828. if (thing->player) P_NoiseAlert(thing, thing);
  1829. }
  1830. S_StartSound(mo, SFX_SLUDGE_GLOOP);
  1831. return(FLOOR_SLUDGE);
  1832. }
  1833. return(FLOOR_SOLID);
  1834. }
  1835. //---------------------------------------------------------------------------
  1836. //
  1837. // FUNC P_CheckMissileSpawn
  1838. //
  1839. // Returns true if the missile is at a valid spawn point, otherwise
  1840. // explodes it and returns false.
  1841. //
  1842. //---------------------------------------------------------------------------
  1843. boolean P_CheckMissileSpawn(mobj_t *missile)
  1844. {
  1845. //missile->tics -= P_Random()&3;
  1846. // move a little forward so an angle can be computed if it
  1847. // immediately explodes
  1848. missile->x += (missile->momx>>1);
  1849. missile->y += (missile->momy>>1);
  1850. missile->z += (missile->momz>>1);
  1851. if(!P_TryMove(missile, missile->x, missile->y))
  1852. {
  1853. P_ExplodeMissile(missile);
  1854. return(false);
  1855. }
  1856. return(true);
  1857. }
  1858. //---------------------------------------------------------------------------
  1859. //
  1860. // FUNC P_SpawnMissile
  1861. //
  1862. // Returns NULL if the missile exploded immediately, otherwise returns
  1863. // a mobj_t pointer to the missile.
  1864. //
  1865. //---------------------------------------------------------------------------
  1866. mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type)
  1867. {
  1868. fixed_t z;
  1869. mobj_t *th;
  1870. angle_t an;
  1871. int dist;
  1872. switch(type)
  1873. {
  1874. case MT_MNTRFX1: // Minotaur swing attack missile
  1875. z = source->z+40*FRACUNIT;
  1876. break;
  1877. case MT_MNTRFX2: // Minotaur floor fire missile
  1878. z = ONFLOORZ+source->floorclip;
  1879. break;
  1880. case MT_CENTAUR_FX:
  1881. z = source->z+45*FRACUNIT;
  1882. break;
  1883. case MT_ICEGUY_FX:
  1884. z = source->z+40*FRACUNIT;
  1885. break;
  1886. case MT_HOLY_MISSILE:
  1887. z = source->z+40*FRACUNIT;
  1888. break;
  1889. default:
  1890. z = source->z+32*FRACUNIT;
  1891. break;
  1892. }
  1893. z -= source->floorclip;
  1894. th = P_SpawnMobj(source->x, source->y, z, type);
  1895. if(th->info->seesound)
  1896. {
  1897. S_StartSound(th, th->info->seesound);
  1898. }
  1899. th->target = source; // Originator
  1900. an = R_PointToAngle2(source->x, source->y, dest->x, dest->y);
  1901. if(dest->flags&MF_SHADOW)
  1902. { // Invisible target
  1903. an += (P_Random()-P_Random())<<21;
  1904. }
  1905. th->angle = an;
  1906. an >>= ANGLETOFINESHIFT;
  1907. th->momx = FixedMul(th->info->speed, finecosine[an]);
  1908. th->momy = FixedMul(th->info->speed, finesine[an]);
  1909. dist = P_AproxDistance(dest->x - source->x, dest->y - source->y);
  1910. dist = dist/th->info->speed;
  1911. if(dist < 1)
  1912. {
  1913. dist = 1;
  1914. }
  1915. th->momz = (dest->z-source->z)/dist;
  1916. return(P_CheckMissileSpawn(th) ? th : NULL);
  1917. }
  1918. //---------------------------------------------------------------------------
  1919. //
  1920. // FUNC P_SpawnMissileXYZ
  1921. //
  1922. // Returns NULL if the missile exploded immediately, otherwise returns
  1923. // a mobj_t pointer to the missile.
  1924. //
  1925. //---------------------------------------------------------------------------
  1926. mobj_t *P_SpawnMissileXYZ(fixed_t x, fixed_t y, fixed_t z,
  1927. mobj_t *source, mobj_t *dest, mobjtype_t type)
  1928. {
  1929. mobj_t *th;
  1930. angle_t an;
  1931. int dist;
  1932. z -= source->floorclip;
  1933. th = P_SpawnMobj(x, y, z, type);
  1934. if(th->info->seesound)
  1935. {
  1936. S_StartSound(th, th->info->seesound);
  1937. }
  1938. th->target = source; // Originator
  1939. an = R_PointToAngle2(source->x, source->y, dest->x, dest->y);
  1940. if(dest->flags&MF_SHADOW)
  1941. { // Invisible target
  1942. an += (P_Random()-P_Random())<<21;
  1943. }
  1944. th->angle = an;
  1945. an >>= ANGLETOFINESHIFT;
  1946. th->momx = FixedMul(th->info->speed, finecosine[an]);
  1947. th->momy = FixedMul(th->info->speed, finesine[an]);
  1948. dist = P_AproxDistance(dest->x - source->x, dest->y - source->y);
  1949. dist = dist/th->info->speed;
  1950. if(dist < 1)
  1951. {
  1952. dist = 1;
  1953. }
  1954. th->momz = (dest->z-source->z)/dist;
  1955. return(P_CheckMissileSpawn(th) ? th : NULL);
  1956. }
  1957. //---------------------------------------------------------------------------
  1958. //
  1959. // FUNC P_SpawnMissileAngle
  1960. //
  1961. // Returns NULL if the missile exploded immediately, otherwise returns
  1962. // a mobj_t pointer to the missile.
  1963. //
  1964. //---------------------------------------------------------------------------
  1965. mobj_t *P_SpawnMissileAngle(mobj_t *source, mobjtype_t type,
  1966. angle_t angle, fixed_t momz)
  1967. {
  1968. fixed_t z;
  1969. mobj_t *mo;
  1970. switch(type)
  1971. {
  1972. case MT_MNTRFX1: // Minotaur swing attack missile
  1973. z = source->z+40*FRACUNIT;
  1974. break;
  1975. case MT_MNTRFX2: // Minotaur floor fire missile
  1976. z = ONFLOORZ+source->floorclip;
  1977. break;
  1978. case MT_ICEGUY_FX2: // Secondary Projectiles of the Ice Guy
  1979. z = source->z+3*FRACUNIT;
  1980. break;
  1981. case MT_MSTAFF_FX2:
  1982. z = source->z+40*FRACUNIT;
  1983. break;
  1984. default:
  1985. z = source->z+32*FRACUNIT;
  1986. break;
  1987. }
  1988. z -= source->floorclip;
  1989. mo = P_SpawnMobj(source->x, source->y, z, type);
  1990. if(mo->info->seesound)
  1991. {
  1992. S_StartSound(mo, mo->info->seesound);
  1993. }
  1994. mo->target = source; // Originator
  1995. mo->angle = angle;
  1996. angle >>= ANGLETOFINESHIFT;
  1997. mo->momx = FixedMul(mo->info->speed, finecosine[angle]);
  1998. mo->momy = FixedMul(mo->info->speed, finesine[angle]);
  1999. mo->momz = momz;
  2000. return(P_CheckMissileSpawn(mo) ? mo : NULL);
  2001. }
  2002. //---------------------------------------------------------------------------
  2003. //
  2004. // FUNC P_SpawnMissileAngleSpeed
  2005. //
  2006. // Returns NULL if the missile exploded immediately, otherwise returns
  2007. // a mobj_t pointer to the missile.
  2008. //
  2009. //---------------------------------------------------------------------------
  2010. mobj_t *P_SpawnMissileAngleSpeed(mobj_t *source, mobjtype_t type,
  2011. angle_t angle, fixed_t momz, fixed_t speed)
  2012. {
  2013. fixed_t z;
  2014. mobj_t *mo;
  2015. z = source->z;
  2016. z -= source->floorclip;
  2017. mo = P_SpawnMobj(source->x, source->y, z, type);
  2018. if(mo->info->seesound)
  2019. {
  2020. //S_StartSound(mo, mo->info->seesound);
  2021. }
  2022. mo->target = source; // Originator
  2023. mo->angle = angle;
  2024. angle >>= ANGLETOFINESHIFT;
  2025. mo->momx = FixedMul(speed, finecosine[angle]);
  2026. mo->momy = FixedMul(speed, finesine[angle]);
  2027. mo->momz = momz;
  2028. return(P_CheckMissileSpawn(mo) ? mo : NULL);
  2029. }
  2030. /*
  2031. ================
  2032. =
  2033. = P_SpawnPlayerMissile
  2034. =
  2035. = Tries to aim at a nearby monster
  2036. ================
  2037. */
  2038. mobj_t *P_SpawnPlayerMissile(mobj_t *source, mobjtype_t type)
  2039. {
  2040. angle_t an;
  2041. fixed_t x, y, z, slope;
  2042. // Try to find a target
  2043. an = source->angle;
  2044. slope = P_AimLineAttack(source, an, 16*64*FRACUNIT);
  2045. if(!linetarget)
  2046. {
  2047. an += 1<<26;
  2048. slope = P_AimLineAttack(source, an, 16*64*FRACUNIT);
  2049. if(!linetarget)
  2050. {
  2051. an -= 2<<26;
  2052. slope = P_AimLineAttack(source, an, 16*64*FRACUNIT);
  2053. }
  2054. if(!linetarget)
  2055. {
  2056. an = source->angle;
  2057. slope = ((source->player->lookdir)<<FRACBITS)/173;
  2058. }
  2059. }
  2060. x = source->x;
  2061. y = source->y;
  2062. if(type == MT_LIGHTNING_FLOOR)
  2063. {
  2064. z = ONFLOORZ;
  2065. slope = 0;
  2066. }
  2067. else if(type == MT_LIGHTNING_CEILING)
  2068. {
  2069. z = ONCEILINGZ;
  2070. slope = 0;
  2071. }
  2072. else
  2073. {
  2074. z = source->z + 4*8*FRACUNIT+((source->player->lookdir)<<FRACBITS)/173;
  2075. z -= source->floorclip;
  2076. }
  2077. MissileMobj = P_SpawnMobj(x, y, z, type);
  2078. if(MissileMobj->info->seesound)
  2079. {
  2080. //S_StartSound(MissileMobj, MissileMobj->info->seesound);
  2081. }
  2082. MissileMobj->target = source;
  2083. MissileMobj->angle = an;
  2084. MissileMobj->momx = FixedMul(MissileMobj->info->speed,
  2085. finecosine[an>>ANGLETOFINESHIFT]);
  2086. MissileMobj->momy = FixedMul(MissileMobj->info->speed,
  2087. finesine[an>>ANGLETOFINESHIFT]);
  2088. MissileMobj->momz = FixedMul(MissileMobj->info->speed, slope);
  2089. if(MissileMobj->type == MT_MWAND_MISSILE
  2090. || MissileMobj->type == MT_CFLAME_MISSILE)
  2091. { // Ultra-fast ripper spawning missile
  2092. MissileMobj->x += (MissileMobj->momx>>3);
  2093. MissileMobj->y += (MissileMobj->momy>>3);
  2094. MissileMobj->z += (MissileMobj->momz>>3);
  2095. }
  2096. else
  2097. { // Normal missile
  2098. MissileMobj->x += (MissileMobj->momx>>1);
  2099. MissileMobj->y += (MissileMobj->momy>>1);
  2100. MissileMobj->z += (MissileMobj->momz>>1);
  2101. }
  2102. if(!P_TryMove(MissileMobj, MissileMobj->x, MissileMobj->y))
  2103. { // Exploded immediately
  2104. P_ExplodeMissile(MissileMobj);
  2105. return(NULL);
  2106. }
  2107. return(MissileMobj);
  2108. }
  2109. //----------------------------------------------------------------------------
  2110. //
  2111. // P_SpawnPlayerMinotaur -
  2112. //
  2113. // Special missile that has larger blocking than player
  2114. //----------------------------------------------------------------------------
  2115. /*
  2116. mobj_t *P_SpawnPlayerMinotaur(mobj_t *source, mobjtype_t type)
  2117. {
  2118. angle_t an;
  2119. fixed_t x, y, z;
  2120. fixed_t dist=0 *FRACUNIT;
  2121. an = source->angle;
  2122. x = source->x + FixedMul(dist, finecosine[an>>ANGLETOFINESHIFT]);
  2123. y = source->y + FixedMul(dist, finesine[an>>ANGLETOFINESHIFT]);
  2124. z = source->z + 4*8*FRACUNIT+((source->player->lookdir)<<FRACBITS)/173;
  2125. z -= source->floorclip;
  2126. MissileMobj = P_SpawnMobj(x, y, z, type);
  2127. if(MissileMobj->info->seesound)
  2128. {
  2129. //S_StartSound(MissileMobj, MissileMobj->info->seesound);
  2130. }
  2131. MissileMobj->target = source;
  2132. MissileMobj->angle = an;
  2133. MissileMobj->momx = FixedMul(MissileMobj->info->speed,
  2134. finecosine[an>>ANGLETOFINESHIFT]);
  2135. MissileMobj->momy = FixedMul(MissileMobj->info->speed,
  2136. finesine[an>>ANGLETOFINESHIFT]);
  2137. MissileMobj->momz = 0;
  2138. // MissileMobj->x += (MissileMobj->momx>>3);
  2139. // MissileMobj->y += (MissileMobj->momy>>3);
  2140. // MissileMobj->z += (MissileMobj->momz>>3);
  2141. if(!P_TryMove(MissileMobj, MissileMobj->x, MissileMobj->y))
  2142. { // Wouln't fit
  2143. return(NULL);
  2144. }
  2145. return(MissileMobj);
  2146. }
  2147. */
  2148. //---------------------------------------------------------------------------
  2149. //
  2150. // PROC P_SPMAngle
  2151. //
  2152. //---------------------------------------------------------------------------
  2153. mobj_t *P_SPMAngle(mobj_t *source, mobjtype_t type, angle_t angle)
  2154. {
  2155. mobj_t *th;
  2156. angle_t an;
  2157. fixed_t x, y, z, slope;
  2158. //
  2159. // see which target is to be aimed at
  2160. //
  2161. an = angle;
  2162. slope = P_AimLineAttack (source, an, 16*64*FRACUNIT);
  2163. if (!linetarget)
  2164. {
  2165. an += 1<<26;
  2166. slope = P_AimLineAttack (source, an, 16*64*FRACUNIT);
  2167. if (!linetarget)
  2168. {
  2169. an -= 2<<26;
  2170. slope = P_AimLineAttack (source, an, 16*64*FRACUNIT);
  2171. }
  2172. if (!linetarget)
  2173. {
  2174. an = angle;
  2175. slope = ((source->player->lookdir)<<FRACBITS)/173;
  2176. }
  2177. }
  2178. x = source->x;
  2179. y = source->y;
  2180. z = source->z + 4*8*FRACUNIT+((source->player->lookdir)<<FRACBITS)/173;
  2181. z -= source->floorclip;
  2182. th = P_SpawnMobj(x, y, z, type);
  2183. // if(th->info->seesound)
  2184. // {
  2185. // S_StartSound(th, th->info->seesound);
  2186. // }
  2187. th->target = source;
  2188. th->angle = an;
  2189. th->momx = FixedMul(th->info->speed, finecosine[an>>ANGLETOFINESHIFT]);
  2190. th->momy = FixedMul(th->info->speed, finesine[an>>ANGLETOFINESHIFT]);
  2191. th->momz = FixedMul(th->info->speed, slope);
  2192. return(P_CheckMissileSpawn(th) ? th : NULL);
  2193. }
  2194. //===========================================================================
  2195. //
  2196. // P_SPMAngleXYZ
  2197. //
  2198. //===========================================================================
  2199. mobj_t *P_SPMAngleXYZ(mobj_t *source, fixed_t x, fixed_t y,
  2200. fixed_t z, mobjtype_t type, angle_t angle)
  2201. {
  2202. mobj_t *th;
  2203. angle_t an;
  2204. fixed_t slope;
  2205. //
  2206. // see which target is to be aimed at
  2207. //
  2208. an = angle;
  2209. slope = P_AimLineAttack (source, an, 16*64*FRACUNIT);
  2210. if (!linetarget)
  2211. {
  2212. an += 1<<26;
  2213. slope = P_AimLineAttack (source, an, 16*64*FRACUNIT);
  2214. if (!linetarget)
  2215. {
  2216. an -= 2<<26;
  2217. slope = P_AimLineAttack (source, an, 16*64*FRACUNIT);
  2218. }
  2219. if (!linetarget)
  2220. {
  2221. an = angle;
  2222. slope = ((source->player->lookdir)<<FRACBITS)/173;
  2223. }
  2224. }
  2225. z += 4*8*FRACUNIT+((source->player->lookdir)<<FRACBITS)/173;
  2226. z -= source->floorclip;
  2227. th = P_SpawnMobj(x, y, z, type);
  2228. // if(th->info->seesound)
  2229. // {
  2230. // S_StartSound(th, th->info->seesound);
  2231. // }
  2232. th->target = source;
  2233. th->angle = an;
  2234. th->momx = FixedMul(th->info->speed, finecosine[an>>ANGLETOFINESHIFT]);
  2235. th->momy = FixedMul(th->info->speed, finesine[an>>ANGLETOFINESHIFT]);
  2236. th->momz = FixedMul(th->info->speed, slope);
  2237. return(P_CheckMissileSpawn(th) ? th : NULL);
  2238. }
  2239. mobj_t *P_SpawnKoraxMissile(fixed_t x, fixed_t y, fixed_t z,
  2240. mobj_t *source, mobj_t *dest, mobjtype_t type)
  2241. {
  2242. mobj_t *th;
  2243. angle_t an;
  2244. int dist;
  2245. z -= source->floorclip;
  2246. th = P_SpawnMobj(x, y, z, type);
  2247. if(th->info->seesound)
  2248. {
  2249. S_StartSound(th, th->info->seesound);
  2250. }
  2251. th->target = source; // Originator
  2252. an = R_PointToAngle2(x, y, dest->x, dest->y);
  2253. if(dest->flags&MF_SHADOW)
  2254. { // Invisible target
  2255. an += (P_Random()-P_Random())<<21;
  2256. }
  2257. th->angle = an;
  2258. an >>= ANGLETOFINESHIFT;
  2259. th->momx = FixedMul(th->info->speed, finecosine[an]);
  2260. th->momy = FixedMul(th->info->speed, finesine[an]);
  2261. dist = P_AproxDistance(dest->x - x, dest->y - y);
  2262. dist = dist/th->info->speed;
  2263. if(dist < 1)
  2264. {
  2265. dist = 1;
  2266. }
  2267. th->momz = (dest->z-z+(30*FRACUNIT))/dist;
  2268. return(P_CheckMissileSpawn(th) ? th : NULL);
  2269. }