1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528 |
- #include "doomdef.h"
- #include "doomstat.h"
- #include "m_random.h"
- #include "r_main.h"
- #include "p_maputl.h"
- #include "p_map.h"
- #include "p_tick.h"
- #include "sounds.h"
- #include "st_stuff.h"
- #include "hu_stuff.h"
- #include "s_sound.h"
- #include "info.h"
- #include "g_game.h"
- #include "p_inter.h"
- #include "lprintf.h"
- #include "r_demo.h"
- boolean P_SetMobjState(mobj_t* mobj,statenum_t state)
- {
- state_t* st;
-
- static statenum_t seenstate_tab[NUMSTATES];
- statenum_t *seenstate = seenstate_tab;
- static int recursion;
- statenum_t i = state;
- boolean ret = true;
- statenum_t tempstate[NUMSTATES];
- if (recursion++)
- memset(seenstate=tempstate,0,sizeof tempstate);
- do
- {
- if (state == S_NULL)
- {
- mobj->state = (state_t *) S_NULL;
- P_RemoveMobj (mobj);
- ret = false;
- break;
- }
- st = &states[state];
- mobj->state = st;
- mobj->tics = st->tics;
- mobj->sprite = st->sprite;
- mobj->frame = st->frame;
-
-
- if (st->action)
- st->action(mobj);
- seenstate[state] = 1 + st->nextstate;
- state = st->nextstate;
- } while (!mobj->tics && !seenstate[state]);
- if (ret && !mobj->tics)
- doom_printf("Warning: State Cycle Detected");
- if (!--recursion)
- for (;(state=seenstate[i]);i=state-1)
- seenstate[i] = 0;
- return ret;
- }
- void P_ExplodeMissile (mobj_t* mo)
- {
- mo->momx = mo->momy = mo->momz = 0;
- P_SetMobjState (mo, mobjinfo[mo->type].deathstate);
- mo->tics -= P_Random(pr_explode)&3;
- if (mo->tics < 1)
- mo->tics = 1;
- mo->flags &= ~MF_MISSILE;
- if (mo->info->deathsound)
- S_StartSound (mo, mo->info->deathsound);
- }
- static void P_XYMovement (mobj_t* mo)
- {
- player_t *player;
- fixed_t xmove, ymove;
-
- fixed_t oldx,oldy;
- #if 0
- fixed_t ptryx;
- fixed_t ptryy;
- fixed_t xmove;
- fixed_t ymove;
- fixed_t oldx,oldy;
-
- #endif
- if (!(mo->momx | mo->momy))
- {
- if (mo->flags & MF_SKULLFLY)
- {
-
- mo->flags &= ~MF_SKULLFLY;
- mo->momz = 0;
- P_SetMobjState (mo, mo->info->spawnstate);
- }
- return;
- }
- player = mo->player;
- if (mo->momx > MAXMOVE)
- mo->momx = MAXMOVE;
- else if (mo->momx < -MAXMOVE)
- mo->momx = -MAXMOVE;
- if (mo->momy > MAXMOVE)
- mo->momy = MAXMOVE;
- else if (mo->momy < -MAXMOVE)
- mo->momy = -MAXMOVE;
- xmove = mo->momx;
- ymove = mo->momy;
- oldx = mo->x;
- oldy = mo->y;
-
- do
- {
- fixed_t ptryx, ptryy;
-
-
-
-
-
- if (xmove > MAXMOVE/2 || ymove > MAXMOVE/2 ||
- (!comp[comp_moveblock]
- && (xmove < -MAXMOVE/2 || ymove < -MAXMOVE/2)))
- {
- ptryx = mo->x + xmove/2;
- ptryy = mo->y + ymove/2;
- xmove >>= 1;
- ymove >>= 1;
- }
- else
- {
- ptryx = mo->x + xmove;
- ptryy = mo->y + ymove;
- xmove = ymove = 0;
- }
-
- if (!P_TryMove (mo, ptryx, ptryy, true))
- {
-
-
-
-
- if (!(mo->flags & MF_MISSILE) &&
- mbf_features &&
- (mo->flags & MF_BOUNCES ||
- (!player && blockline &&
- variable_friction && mo->z <= mo->floorz &&
- P_GetFriction(mo, NULL) > ORIG_FRICTION)))
- {
- if (blockline)
- {
- fixed_t r = ((blockline->dx >> FRACBITS) * mo->momx +
- (blockline->dy >> FRACBITS) * mo->momy) /
- ((blockline->dx >> FRACBITS)*(blockline->dx >> FRACBITS)+
- (blockline->dy >> FRACBITS)*(blockline->dy >> FRACBITS));
- fixed_t x = FixedMul(r, blockline->dx);
- fixed_t y = FixedMul(r, blockline->dy);
-
- mo->momx = x*2 - mo->momx;
- mo->momy = y*2 - mo->momy;
-
-
- if (!(mo->flags & MF_NOGRAVITY))
- {
- mo->momx = (mo->momx + x)/2;
- mo->momy = (mo->momy + y)/2;
- }
- }
- else
- mo->momx = mo->momy = 0;
- }
- else
- if (player)
- P_SlideMove (mo);
- else
- if (mo->flags & MF_MISSILE)
- {
-
- if (ceilingline &&
- ceilingline->backsector &&
- ceilingline->backsector->ceilingpic == skyflatnum)
- if (demo_compatibility ||
- mo->z > ceilingline->backsector->ceilingheight)
- {
-
-
-
- P_RemoveMobj (mo);
- return;
- }
- P_ExplodeMissile (mo);
- }
- else
- mo->momx = mo->momy = 0;
- }
- } while (xmove || ymove);
-
- #if 0
- if (player && player->cheats & CF_NOMOMENTUM)
- {
-
- mo->momx = mo->momy = 0;
- player->momx = player->momy = 0;
- return;
- }
- #endif
-
- if (mo->flags & (MF_MISSILE | MF_SKULLFLY) || mo->z > mo->floorz)
- return;
-
- if (((mo->flags & MF_BOUNCES && mo->z > mo->dropoffz) ||
- mo->flags & MF_CORPSE || mo->intflags & MIF_FALLING) &&
- (mo->momx > FRACUNIT/4 || mo->momx < -FRACUNIT/4 ||
- mo->momy > FRACUNIT/4 || mo->momy < -FRACUNIT/4) &&
- mo->floorz != mo->subsector->sector->floorheight)
- return;
-
-
-
- if (mo->momx > -STOPSPEED && mo->momx < STOPSPEED &&
- mo->momy > -STOPSPEED && mo->momy < STOPSPEED &&
- (!player || !(player->cmd.forwardmove | player->cmd.sidemove) ||
- (player->mo != mo && compatibility_level >= lxdoom_1_compatibility)))
- {
-
-
-
- if (player && (unsigned)(player->mo->state - states - S_PLAY_RUN1) < 4
- && (player->mo == mo || compatibility_level >= lxdoom_1_compatibility))
- P_SetMobjState(player->mo, S_PLAY);
- mo->momx = mo->momy = 0;
-
- if (player && player->mo == mo)
- player->momx = player->momy = 0;
- }
- else
- {
-
-
- if (compatibility_level <= boom_201_compatibility)
- {
-
-
-
-
- mo->momx = FixedMul(mo->momx,mo->friction);
- mo->momy = FixedMul(mo->momy,mo->friction);
- mo->friction = ORIG_FRICTION;
- }
- else if (compatibility_level <= lxdoom_1_compatibility)
- {
-
- if ((oldx == mo->x) && (oldy == mo->y))
- {
-
-
- mo->momx = FixedMul(mo->momx,ORIG_FRICTION);
- mo->momy = FixedMul(mo->momy,ORIG_FRICTION);
- }
- else
- {
- mo->momx = FixedMul(mo->momx,mo->friction);
- mo->momy = FixedMul(mo->momy,mo->friction);
- }
- mo->friction = ORIG_FRICTION;
- }
- else
- {
- fixed_t friction = P_GetFriction(mo, NULL);
- mo->momx = FixedMul(mo->momx, friction);
- mo->momy = FixedMul(mo->momy, friction);
-
- if (player && player->mo == mo)
- {
- player->momx = FixedMul(player->momx, ORIG_FRICTION);
- player->momy = FixedMul(player->momy, ORIG_FRICTION);
- }
- }
- }
- }
- static void P_ZMovement (mobj_t* mo)
- {
-
- if (mo->flags & MF_BOUNCES && mo->momz) {
- mo->z += mo->momz;
- if (mo->z <= mo->floorz) {
- mo->z = mo->floorz;
- if (mo->momz < 0) {
- mo->momz = -mo->momz;
- if (!(mo->flags & MF_NOGRAVITY)) {
- mo->momz = mo->flags & MF_FLOAT ?
- mo->flags & MF_DROPOFF ?
- FixedMul(mo->momz, (fixed_t)(FRACUNIT*.85)) :
- FixedMul(mo->momz, (fixed_t)(FRACUNIT*.70)) :
- FixedMul(mo->momz, (fixed_t)(FRACUNIT*.45)) ;
-
- if (D_abs(mo->momz) <= mo->info->mass*(GRAVITY*4/256))
- mo->momz = 0;
- }
-
- if (mo->flags & MF_TOUCHY && mo->intflags & MIF_ARMED
- && mo->health > 0)
- P_DamageMobj(mo, NULL, NULL, mo->health);
- else if (mo->flags & MF_FLOAT && sentient(mo))
- goto floater;
- return;
- }
- } else if (mo->z >= mo->ceilingz - mo->height) {
-
- mo->z = mo->ceilingz - mo->height;
- if (mo->momz > 0) {
- if (mo->subsector->sector->ceilingpic != skyflatnum)
- mo->momz = -mo->momz;
- else if (mo->flags & MF_MISSILE)
- P_RemoveMobj(mo);
- else if (mo->flags & MF_NOGRAVITY)
- mo->momz = -mo->momz;
- if (mo->flags & MF_FLOAT && sentient(mo))
- goto floater;
- return;
- }
- } else {
- if (!(mo->flags & MF_NOGRAVITY))
- mo->momz -= mo->info->mass*(GRAVITY/256);
- if (mo->flags & MF_FLOAT && sentient(mo)) goto floater;
- return;
- }
-
- mo->momz = 0;
- if (mo->flags & MF_MISSILE) {
- if (ceilingline &&
- ceilingline->backsector &&
- ceilingline->backsector->ceilingpic == skyflatnum &&
- mo->z > ceilingline->backsector->ceilingheight)
- P_RemoveMobj(mo);
- else
- P_ExplodeMissile(mo);
- }
- if (mo->flags & MF_FLOAT && sentient(mo)) goto floater;
- return;
- }
-
-
- if (mo->player &&
- mo->player->mo == mo &&
- mo->z < mo->floorz)
- {
- mo->player->viewheight -= mo->floorz-mo->z;
- mo->player->deltaviewheight = (VIEWHEIGHT - mo->player->viewheight)>>3;
- }
-
- mo->z += mo->momz;
- floater:
- if ((mo->flags & MF_FLOAT) && mo->target)
-
- if (!((mo->flags ^ MF_FLOAT) & (MF_FLOAT | MF_SKULLFLY | MF_INFLOAT)) &&
- mo->target)
- {
- fixed_t delta;
- if (P_AproxDistance(mo->x - mo->target->x, mo->y - mo->target->y) <
- D_abs(delta = mo->target->z + (mo->height>>1) - mo->z)*3)
- mo->z += delta < 0 ? -FLOATSPEED : FLOATSPEED;
- }
-
- if (mo->z <= mo->floorz)
- {
-
-
- if (mo->flags & MF_SKULLFLY &&
- (!comp[comp_soul] ||
- (compatibility_level > doom2_19_compatibility &&
- compatibility_level < prboom_4_compatibility)
- ))
- mo->momz = -mo->momz;
- if (mo->momz < 0)
- {
-
- if (mo->flags & MF_TOUCHY && mo->intflags & MIF_ARMED && mo->health > 0)
- P_DamageMobj(mo, NULL, NULL, mo->health);
- else
- if (mo->player &&
- mo->player->mo == mo && mo->momz < -GRAVITY*8)
- {
-
-
-
-
- mo->player->deltaviewheight = mo->momz>>3;
-
- if (comp[comp_sound] || mo->health > 0)
- S_StartSound (mo, sfx_oof);
- }
- mo->momz = 0;
- }
- mo->z = mo->floorz;
-
- if (mo->flags & MF_SKULLFLY &&
- compatibility_level <= doom2_19_compatibility)
- mo->momz = -mo->momz;
- if ( (mo->flags & MF_MISSILE) && !(mo->flags & MF_NOCLIP) )
- {
- P_ExplodeMissile (mo);
- return;
- }
- }
- else
- if (!(mo->flags & MF_NOGRAVITY))
- {
- if (!mo->momz)
- mo->momz = -GRAVITY;
- mo->momz -= GRAVITY;
- }
- if (mo->z + mo->height > mo->ceilingz)
- {
-
- if (!comp[comp_soul] && mo->flags & MF_SKULLFLY)
- mo->momz = -mo->momz;
-
- if (mo->momz > 0)
- mo->momz = 0;
- mo->z = mo->ceilingz - mo->height;
-
- if (comp[comp_soul] && mo->flags & MF_SKULLFLY)
- mo->momz = -mo->momz;
- if ( (mo->flags & MF_MISSILE) && !(mo->flags & MF_NOCLIP) )
- {
- P_ExplodeMissile (mo);
- return;
- }
- }
- }
- static void P_NightmareRespawn(mobj_t* mobj)
- {
- fixed_t x;
- fixed_t y;
- fixed_t z;
- subsector_t* ss;
- mobj_t* mo;
- mapthing_t* mthing;
- x = mobj->spawnpoint.x << FRACBITS;
- y = mobj->spawnpoint.y << FRACBITS;
-
- if(!comp[comp_respawn] && !x && !y)
- {
-
- x = mobj->x;
- y = mobj->y;
- }
-
- if (!P_CheckPosition (mobj, x, y) )
- return;
-
-
- mo = P_SpawnMobj (mobj->x,
- mobj->y,
- mobj->subsector->sector->floorheight,
- MT_TFOG);
-
- S_StartSound (mo, sfx_telept);
-
- ss = R_PointInSubsector (x,y);
- mo = P_SpawnMobj (x, y, ss->sector->floorheight , MT_TFOG);
- S_StartSound (mo, sfx_telept);
-
- mthing = &mobj->spawnpoint;
- if (mobj->info->flags & MF_SPAWNCEILING)
- z = ONCEILINGZ;
- else
- z = ONFLOORZ;
-
- mo = P_SpawnMobj (x,y,z, mobj->type);
- mo->spawnpoint = mobj->spawnpoint;
- mo->angle = ANG45 * (mthing->angle/45);
- if (mthing->options & MTF_AMBUSH)
- mo->flags |= MF_AMBUSH;
-
- mo->flags = (mo->flags & ~MF_FRIEND) | (mobj->flags & MF_FRIEND);
- mo->reactiontime = 18;
-
- P_RemoveMobj (mobj);
- }
- void P_MobjThinker (mobj_t* mobj)
- {
-
-
-
- mobj->PrevX = mobj->x;
- mobj->PrevY = mobj->y;
- mobj->PrevZ = mobj->z;
-
- if (mobj->momx | mobj->momy || mobj->flags & MF_SKULLFLY)
- {
- P_XYMovement(mobj);
- if (mobj->thinker.function != P_MobjThinker)
- return;
- }
- if (mobj->z != mobj->floorz || mobj->momz)
- {
- P_ZMovement(mobj);
- if (mobj->thinker.function != P_MobjThinker)
- return;
- }
- else
- if (!(mobj->momx | mobj->momy) && !sentient(mobj))
- {
- mobj->intflags |= MIF_ARMED;
-
-
- if (mobj->z > mobj->dropoffz &&
- !(mobj->flags & MF_NOGRAVITY) &&
- !comp[comp_falloff])
- P_ApplyTorque(mobj);
- else
- mobj->intflags &= ~MIF_FALLING, mobj->gear = 0;
- }
-
-
- if (mobj->tics != -1)
- {
- mobj->tics--;
-
- if (!mobj->tics)
- if (!P_SetMobjState (mobj, mobj->state->nextstate) )
- return;
- }
- else
- {
-
- if (! (mobj->flags & MF_COUNTKILL) )
- return;
- if (!respawnmonsters)
- return;
- mobj->movecount++;
- if (mobj->movecount < 12*35)
- return;
- if (leveltime & 31)
- return;
- if (P_Random (pr_respawn) > 4)
- return;
- P_NightmareRespawn (mobj);
- }
- }
- mobj_t* P_SpawnMobj(fixed_t x,fixed_t y,fixed_t z,mobjtype_t type)
- {
- mobj_t* mobj;
- state_t* st;
- mobjinfo_t* info;
- mobj = Z_Malloc (sizeof(*mobj), PU_LEVEL, NULL);
- memset (mobj, 0, sizeof (*mobj));
- info = &mobjinfo[type];
- mobj->type = type;
- mobj->info = info;
- mobj->x = x;
- mobj->y = y;
- mobj->radius = info->radius;
- mobj->height = info->height;
- mobj->flags = info->flags;
-
- if (!mbf_features)
- mobj->flags &= ~(MF_BOUNCES | MF_FRIEND | MF_TOUCHY);
- else
- if (type == MT_PLAYER)
- mobj->flags |= MF_FRIEND;
- mobj->health = info->spawnhealth;
- if (gameskill != sk_nightmare)
- mobj->reactiontime = info->reactiontime;
- mobj->lastlook = P_Random (pr_lastlook) % MAXPLAYERS;
-
-
- st = &states[info->spawnstate];
- mobj->state = st;
- mobj->tics = st->tics;
- mobj->sprite = st->sprite;
- mobj->frame = st->frame;
- mobj->touching_sectorlist = NULL;
-
- P_SetThingPosition (mobj);
- mobj->dropoffz =
- mobj->floorz = mobj->subsector->sector->floorheight;
- mobj->ceilingz = mobj->subsector->sector->ceilingheight;
- mobj->z = z == ONFLOORZ ? mobj->floorz : z == ONCEILINGZ ?
- mobj->ceilingz - mobj->height : z;
- mobj->PrevX = mobj->x;
- mobj->PrevY = mobj->y;
- mobj->PrevZ = mobj->z;
- mobj->thinker.function = P_MobjThinker;
-
- mobj->friction = ORIG_FRICTION;
- mobj->target = mobj->tracer = mobj->lastenemy = NULL;
- P_AddThinker (&mobj->thinker);
- if (!((mobj->flags ^ MF_COUNTKILL) & (MF_FRIEND | MF_COUNTKILL)))
- totallive++;
- return mobj;
- }
- static mapthing_t itemrespawnque[ITEMQUESIZE];
- static int itemrespawntime[ITEMQUESIZE];
- int iquehead;
- int iquetail;
- void P_RemoveMobj (mobj_t* mobj)
- {
- if ((mobj->flags & MF_SPECIAL)
- && !(mobj->flags & MF_DROPPED)
- && (mobj->type != MT_INV)
- && (mobj->type != MT_INS))
- {
- itemrespawnque[iquehead] = mobj->spawnpoint;
- itemrespawntime[iquehead] = leveltime;
- iquehead = (iquehead+1)&(ITEMQUESIZE-1);
-
- if (iquehead == iquetail)
- iquetail = (iquetail+1)&(ITEMQUESIZE-1);
- }
-
- P_UnsetThingPosition (mobj);
-
- if (sector_list)
- {
- P_DelSeclist(sector_list);
- sector_list = NULL;
- }
-
- S_StopSound (mobj);
-
-
-
-
-
-
-
-
-
- if ((compatibility_level >= lxdoom_1_compatibility) ||
- (!demorecording && !demoplayback)) {
- P_SetTarget(&mobj->target, NULL);
- P_SetTarget(&mobj->tracer, NULL);
- P_SetTarget(&mobj->lastenemy, NULL);
- }
-
- P_RemoveThinker (&mobj->thinker);
- }
- static PUREFUNC int P_FindDoomedNum(unsigned type)
- {
- static struct { int first, next; } *hash;
- register int i;
- if (!hash)
- {
- hash = Z_Malloc(sizeof *hash * NUMMOBJTYPES, PU_CACHE, (void **) &hash);
- for (i=0; i<NUMMOBJTYPES; i++)
- hash[i].first = NUMMOBJTYPES;
- for (i=0; i<NUMMOBJTYPES; i++)
- if (mobjinfo[i].doomednum != -1)
- {
- unsigned h = (unsigned) mobjinfo[i].doomednum % NUMMOBJTYPES;
- hash[i].next = hash[h].first;
- hash[h].first = i;
- }
- }
- i = hash[type % NUMMOBJTYPES].first;
- while ((i < NUMMOBJTYPES) && ((unsigned)mobjinfo[i].doomednum != type))
- i = hash[i].next;
- return i;
- }
- void P_RespawnSpecials (void)
- {
- fixed_t x;
- fixed_t y;
- fixed_t z;
- subsector_t* ss;
- mobj_t* mo;
- mapthing_t* mthing;
- int i;
-
- if (deathmatch != 2 && deathmatch != 3)
- return;
-
- if (iquehead == iquetail)
- return;
-
- if (leveltime - itemrespawntime[iquetail] < 30*35)
- return;
- mthing = &itemrespawnque[iquetail];
- x = mthing->x << FRACBITS;
- y = mthing->y << FRACBITS;
-
- ss = R_PointInSubsector (x,y);
- mo = P_SpawnMobj (x, y, ss->sector->floorheight , MT_IFOG);
- S_StartSound (mo, sfx_itmbk);
-
-
- i = P_FindDoomedNum(mthing->type);
-
- if (mobjinfo[i].flags & MF_SPAWNCEILING)
- z = ONCEILINGZ;
- else
- z = ONFLOORZ;
- mo = P_SpawnMobj (x,y,z, i);
- mo->spawnpoint = *mthing;
- mo->angle = ANG45 * (mthing->angle/45);
-
- iquetail = (iquetail+1)&(ITEMQUESIZE-1);
- }
- extern byte playernumtotrans[MAXPLAYERS];
- void P_SpawnPlayer (int n, const mapthing_t* mthing)
- {
- player_t* p;
- fixed_t x;
- fixed_t y;
- fixed_t z;
- mobj_t* mobj;
- int i;
-
- if (!playeringame[n])
- return;
- p = &players[n];
- if (p->playerstate == PST_REBORN)
- G_PlayerReborn (mthing->type-1);
-
- if (!mthing->options)
- I_Error("P_SpawnPlayer: attempt to spawn player at unavailable start point");
-
- x = mthing->x << FRACBITS;
- y = mthing->y << FRACBITS;
- z = ONFLOORZ;
- mobj = P_SpawnMobj (x,y,z, MT_PLAYER);
-
- mobj->flags |= playernumtotrans[n]<<MF_TRANSSHIFT;
- mobj->angle = ANG45 * (mthing->angle/45);
- mobj->player = p;
- mobj->health = p->health;
- p->mo = mobj;
- p->playerstate = PST_LIVE;
- p->refire = 0;
- p->message = NULL;
- p->damagecount = 0;
- p->bonuscount = 0;
- p->extralight = 0;
- p->fixedcolormap = 0;
- p->viewheight = VIEWHEIGHT;
- p->momx = p->momy = 0;
-
- P_SetupPsprites (p);
-
- if (deathmatch)
- for (i = 0 ; i < NUMCARDS ; i++)
- p->cards[i] = true;
- if (mthing->type-1 == consoleplayer)
- {
- ST_Start();
- HU_Start();
- }
- R_SmoothPlaying_Reset(p);
- }
- boolean P_IsDoomnumAllowed(int doomnum)
- {
-
- if (gamemode != commercial)
- switch(doomnum)
- {
- case 64:
- case 65:
- case 66:
- case 67:
- case 68:
- case 69:
- case 71:
- case 84:
- case 88:
- case 89:
- return false;
- }
- return true;
- }
- void P_SpawnMapThing (const mapthing_t* mthing)
- {
- int i;
-
- mobj_t* mobj;
- fixed_t x;
- fixed_t y;
- fixed_t z;
- int options = mthing->options;
-
-
- switch(mthing->type)
- {
- case 0:
- case DEN_PLAYER5:
- case DEN_PLAYER6:
- case DEN_PLAYER7:
- case DEN_PLAYER8:
- return;
- }
-
-
-
-
-
-
-
- if (demo_compatibility ||
- (compatibility_level >= lxdoom_1_compatibility &&
- options & MTF_RESERVED)) {
- if (!demo_compatibility)
- lprintf(LO_WARN, "P_SpawnMapThing: correcting bad flags (%u) (thing type %d)\n",
- options, mthing->type);
- options &= MTF_EASY|MTF_NORMAL|MTF_HARD|MTF_AMBUSH|MTF_NOTSINGLE;
- }
-
-
- if (mthing->type == 11)
- {
- if (!(!compatibility || deathmatch_p-deathmatchstarts < 10)) {
- return;
- } else {
-
- size_t offset = deathmatch_p - deathmatchstarts;
- if (offset >= num_deathmatchstarts)
- {
- num_deathmatchstarts = num_deathmatchstarts ?
- num_deathmatchstarts*2 : 16;
- deathmatchstarts = realloc(deathmatchstarts,
- num_deathmatchstarts *
- sizeof(*deathmatchstarts));
- deathmatch_p = deathmatchstarts + offset;
- }
- memcpy(deathmatch_p++, mthing, sizeof(*mthing));
- (deathmatch_p-1)->options = 1;
- return;
- }
- }
-
- if (mthing->type <= 4 && mthing->type > 0)
- {
- #ifdef DOGS
-
- if (!netgame && mthing->type > 1 && mthing->type <= dogs+1 &&
- !players[mthing->type-1].secretcount)
- {
- players[mthing->type-1].secretcount = 1;
-
- options |= MTF_FRIEND;
- if(HelperThing != -1)
- {
- int type = HelperThing - 1;
- if(type >= 0 && type < NUMMOBJTYPES)
- {
- i = type;
- }
- else
- {
- doom_printf("Invalid value %i for helper, ignored.", HelperThing);
- i = MT_DOGS;
- }
- }
- else {
- i = MT_DOGS;
- }
- goto spawnit;
- }
- #endif
-
- playerstarts[mthing->type-1] = *mthing;
-
- playerstarts[mthing->type-1].options = 1;
- if (!deathmatch)
- P_SpawnPlayer (mthing->type-1, &playerstarts[mthing->type-1]);
- return;
- }
-
-
- if (!netgame && options & MTF_NOTSINGLE)
- return;
-
- if (netgame && deathmatch && options & MTF_NOTDM)
- return;
-
- if (netgame && !deathmatch && options & MTF_NOTCOOP)
- return;
-
- if (gameskill == sk_baby || gameskill == sk_easy ?
- !(options & MTF_EASY) :
- gameskill == sk_hard || gameskill == sk_nightmare ?
- !(options & MTF_HARD) : !(options & MTF_NORMAL))
- return;
-
-
- i = P_FindDoomedNum(mthing->type);
-
-
-
- if (i == NUMMOBJTYPES)
- {
- doom_printf("Unknown Thing type %i at (%i, %i)",mthing->type,mthing->x,mthing->y);
- return;
- }
-
- if (deathmatch && mobjinfo[i].flags & MF_NOTDMATCH)
- return;
-
- if (nomonsters && (i == MT_SKULL || (mobjinfo[i].flags & MF_COUNTKILL)))
- return;
-
- #ifdef DOGS
- spawnit:
- #endif
- x = mthing->x << FRACBITS;
- y = mthing->y << FRACBITS;
- if (mobjinfo[i].flags & MF_SPAWNCEILING)
- z = ONCEILINGZ;
- else
- z = ONFLOORZ;
- mobj = P_SpawnMobj (x,y,z, i);
- mobj->spawnpoint = *mthing;
- if (mobj->tics > 0)
- mobj->tics = 1 + (P_Random (pr_spawnthing) % mobj->tics);
- if (!(mobj->flags & MF_FRIEND) &&
- options & MTF_FRIEND &&
- mbf_features)
- {
- mobj->flags |= MF_FRIEND;
- P_UpdateThinker(&mobj->thinker);
- }
-
- if (!((mobj->flags ^ MF_COUNTKILL) & (MF_FRIEND | MF_COUNTKILL)))
- totalkills++;
- if (mobj->flags & MF_COUNTITEM)
- totalitems++;
- mobj->angle = ANG45 * (mthing->angle/45);
- if (options & MTF_AMBUSH)
- mobj->flags |= MF_AMBUSH;
- }
- extern fixed_t attackrange;
- void P_SpawnPuff(fixed_t x,fixed_t y,fixed_t z)
- {
- mobj_t* th;
-
- int t = P_Random(pr_spawnpuff);
- z += (t - P_Random(pr_spawnpuff))<<10;
- th = P_SpawnMobj (x,y,z, MT_PUFF);
- th->momz = FRACUNIT;
- th->tics -= P_Random(pr_spawnpuff)&3;
- if (th->tics < 1)
- th->tics = 1;
-
- if (attackrange == MELEERANGE)
- P_SetMobjState (th, S_PUFF3);
- }
- void P_SpawnBlood(fixed_t x,fixed_t y,fixed_t z,int damage)
- {
- mobj_t* th;
-
- int t = P_Random(pr_spawnblood);
- z += (t - P_Random(pr_spawnblood))<<10;
- th = P_SpawnMobj(x,y,z, MT_BLOOD);
- th->momz = FRACUNIT*2;
- th->tics -= P_Random(pr_spawnblood)&3;
- if (th->tics < 1)
- th->tics = 1;
- if (damage <= 12 && damage >= 9)
- P_SetMobjState (th,S_BLOOD2);
- else if (damage < 9)
- P_SetMobjState (th,S_BLOOD3);
- }
- void P_CheckMissileSpawn (mobj_t* th)
- {
- th->tics -= P_Random(pr_missile)&3;
- if (th->tics < 1)
- th->tics = 1;
-
-
- th->x += (th->momx>>1);
- th->y += (th->momy>>1);
- th->z += (th->momz>>1);
-
- if (!(th->flags & MF_MISSILE) && mbf_features)
- return;
-
- if (!P_TryMove (th, th->x, th->y, false))
- P_ExplodeMissile (th);
- }
- mobj_t* P_SpawnMissile(mobj_t* source,mobj_t* dest,mobjtype_t type)
- {
- mobj_t* th;
- angle_t an;
- int dist;
- th = P_SpawnMobj (source->x,source->y,source->z + 4*8*FRACUNIT,type);
- if (th->info->seesound)
- S_StartSound (th, th->info->seesound);
- P_SetTarget(&th->target, source);
- an = R_PointToAngle2 (source->x, source->y, dest->x, dest->y);
-
- if (dest->flags & MF_SHADOW)
- {
- int t = P_Random(pr_shadow);
- an += (t - P_Random(pr_shadow))<<20;
- }
- th->angle = an;
- an >>= ANGLETOFINESHIFT;
- th->momx = FixedMul (th->info->speed, finecosine[an]);
- th->momy = FixedMul (th->info->speed, finesine[an]);
- dist = P_AproxDistance (dest->x - source->x, dest->y - source->y);
- dist = dist / th->info->speed;
- if (dist < 1)
- dist = 1;
- th->momz = (dest->z - source->z) / dist;
- P_CheckMissileSpawn (th);
- return th;
- }
- void P_SpawnPlayerMissile(mobj_t* source,mobjtype_t type)
- {
- mobj_t *th;
- fixed_t x, y, z, slope = 0;
-
- angle_t an = source->angle;
-
- {
-
- uint_64_t mask = mbf_features ? MF_FRIEND : 0;
- do
- {
- slope = P_AimLineAttack(source, an, 16*64*FRACUNIT, mask);
- if (!linetarget)
- slope = P_AimLineAttack(source, an += 1<<26, 16*64*FRACUNIT, mask);
- if (!linetarget)
- slope = P_AimLineAttack(source, an -= 2<<26, 16*64*FRACUNIT, mask);
- if (!linetarget)
- an = source->angle, slope = 0;
- }
- while (mask && (mask=0, !linetarget));
- }
- x = source->x;
- y = source->y;
- z = source->z + 4*8*FRACUNIT;
- th = P_SpawnMobj (x,y,z, type);
- if (th->info->seesound)
- S_StartSound (th, th->info->seesound);
- P_SetTarget(&th->target, source);
- th->angle = an;
- th->momx = FixedMul(th->info->speed,finecosine[an>>ANGLETOFINESHIFT]);
- th->momy = FixedMul(th->info->speed,finesine[an>>ANGLETOFINESHIFT]);
- th->momz = FixedMul(th->info->speed,slope);
- P_CheckMissileSpawn(th);
- }
|