📄 p_mobj.c
字号:
// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: p_mobj.c,v 1.27 2001/04/02 18:54:32 bpereira Exp $//// Copyright (C) 1993-1996 by id Software, Inc.// Portions Copyright (C) 1998-2000 by DooM Legacy Team.//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.////// $Log: p_mobj.c,v $// Revision 1.27 2001/04/02 18:54:32 bpereira// no message//// Revision 1.26 2001/04/01 17:35:06 bpereira// no message//// Revision 1.25 2001/03/30 17:12:50 bpereira// no message//// Revision 1.24 2001/03/13 22:14:19 stroggonmeth// Long time no commit. 3D floors, FraggleScript, portals, ect.//// Revision 1.23 2001/03/03 06:17:33 bpereira// no message//// Revision 1.22 2001/02/24 13:35:20 bpereira// no message//// Revision 1.21 2001/02/10 12:27:14 bpereira// no message//// Revision 1.20 2001/01/25 22:15:43 bpereira// added heretic support//// Revision 1.19 2000/11/04 16:23:43 bpereira// no message//// Revision 1.18 2000/11/02 19:49:36 bpereira// no message//// Revision 1.17 2000/11/02 17:50:08 stroggonmeth// Big 3Dfloors & FraggleScript commit!!//// Revision 1.16 2000/10/21 08:43:30 bpereira// no message//// Revision 1.15 2000/10/16 20:02:30 bpereira// no message//// Revision 1.14 2000/10/01 10:18:18 bpereira// no message//// Revision 1.13 2000/09/28 20:57:16 bpereira// no message//// Revision 1.12 2000/08/31 14:30:55 bpereira// no message//// Revision 1.11 2000/08/11 19:10:13 metzgermeister// *** empty log message ***//// Revision 1.10 2000/04/16 18:38:07 bpereira// no message//// Revision 1.9 2000/04/11 19:07:24 stroggonmeth// Finished my logs, fixed a crashing bug.//// Revision 1.8 2000/04/08 17:29:25 stroggonmeth// no message//// Revision 1.7 2000/04/06 20:40:22 hurdler// Mostly remove warnings under windows//// Revision 1.6 2000/04/05 15:47:46 stroggonmeth// Added hack for Dehacked lumps. Transparent sprites are now affected by colormaps.//// Revision 1.5 2000/04/04 00:32:47 stroggonmeth// Initial Boom compatability plus few misc changes all around.//// Revision 1.4 2000/03/29 19:39:48 bpereira// no message//// Revision 1.3 2000/02/27 00:42:10 hurdler// fix CR+LF problem//// Revision 1.2 2000/02/26 00:28:42 hurdler// Mostly bug fix (see borislog.txt 23-2-2000, 24-2-2000)////// DESCRIPTION:// Moving object handling. Spawn functions.////-----------------------------------------------------------------------------#include "doomdef.h"#include "g_game.h"#include "g_input.h"#include "st_stuff.h"#include "hu_stuff.h"#include "p_local.h"#include "p_inter.h"#include "p_setup.h" //levelflats to test if mobj in water sector#include "r_main.h"#include "r_things.h"#include "r_sky.h"#include "s_sound.h"#include "z_zone.h"#include "m_random.h"#include "d_clisrv.h"#include "r_splats.h" //faB: in dev.// protos.CV_PossibleValue_t viewheight_cons_t[]={{16,"MIN"},{56,"MAX"},{0,NULL}};consvar_t cv_viewheight = {"viewheight", VIEWHEIGHTS,0,viewheight_cons_t,NULL};//Fab:26-07-98:consvar_t cv_gravity = {"gravity","1",CV_NETVAR|CV_FLOAT|CV_SHOWMODIF};consvar_t cv_splats = {"splats","1",CV_SAVE,CV_OnOff};static const fixed_t FloatBobOffsets[64] ={ 0, 51389, 102283, 152192, 200636, 247147, 291278, 332604, 370727, 405280, 435929, 462380, 484378, 501712, 514213, 521763, 524287, 521763, 514213, 501712, 484378, 462380, 435929, 405280, 370727, 332604, 291278, 247147, 200636, 152192, 102283, 51389, -1, -51390, -102284, -152193, -200637, -247148, -291279, -332605, -370728, -405281, -435930, -462381, -484380, -501713, -514215, -521764, -524288, -521764, -514214, -501713, -484379, -462381, -435930, -405280, -370728, -332605, -291279, -247148, -200637, -152193, -102284, -51389};//// P_SetMobjState// Returns true if the mobj is still present.////SoM: 4/7/2000: Boom code...boolean P_SetMobjState ( mobj_t* mobj, statenum_t state ){ state_t* st; //remember states seen, to detect cycles: static statenum_t seenstate_tab[NUMSTATES]; // fast transition table statenum_t *seenstate = seenstate_tab; // pointer to table static int recursion; // detects recursion statenum_t i = state; // initial state boolean ret = true; // return value statenum_t tempstate[NUMSTATES]; // for use with recursion if (recursion++) // if recursion detected, memset(seenstate=tempstate,0,sizeof tempstate); // clear state table do { if (state == S_NULL) { mobj->state = (state_t *) S_NULL; P_RemoveMobj (mobj); ret = false; break; // killough 4/9/98 } st = &states[state]; mobj->state = st; mobj->tics = st->tics; mobj->sprite = st->sprite; mobj->frame = st->frame; // Modified handling. // Call action functions when the state is set if (st->action.acp1) st->action.acp1(mobj); seenstate[state] = 1 + st->nextstate; // killough 4/9/98 state = st->nextstate; } while (!mobj->tics && !seenstate[state]); // killough 4/9/98 if (ret && !mobj->tics) // killough 4/9/98: detect state cycles CONS_Printf("Warning: State Cycle Detected"); if (!--recursion) for (;(state=seenstate[i]);i=state-1) seenstate[i] = 0; // killough 4/9/98: erase memory of states return ret;}//----------------------------------------------------------------------------//// FUNC P_SetMobjStateNF//// Same as P_SetMobjState, but does not call the state function.////----------------------------------------------------------------------------boolean P_SetMobjStateNF(mobj_t *mobj, statenum_t state){ state_t *st; if(state == S_NULL) { // Remove mobj P_RemoveMobj(mobj); return(false); } st = &states[state]; mobj->state = st; mobj->tics = st->tics; mobj->sprite = st->sprite; mobj->frame = st->frame; return(true);}//// P_ExplodeMissile//void P_ExplodeMissile (mobj_t* mo){ if(mo->type == MT_WHIRLWIND) if(++mo->special2 < 60) return; mo->momx = mo->momy = mo->momz = 0; P_SetMobjState (mo, mobjinfo[mo->type].deathstate); if( gamemode != heretic ) { mo->tics -= P_Random()&3; if (mo->tics < 1) mo->tics = 1; } mo->flags &= ~MF_MISSILE; if (mo->info->deathsound) S_StartSound (mo, mo->info->deathsound);}//----------------------------------------------------------------------------//// PROC P_FloorBounceMissile////----------------------------------------------------------------------------void P_FloorBounceMissile(mobj_t *mo){ mo->momz = -mo->momz; P_SetMobjState(mo, mobjinfo[mo->type].deathstate);}//----------------------------------------------------------------------------//// PROC P_ThrustMobj////----------------------------------------------------------------------------void P_ThrustMobj(mobj_t *mo, angle_t angle, fixed_t move){ angle >>= ANGLETOFINESHIFT; mo->momx += FixedMul(move, finecosine[angle]); mo->momy += FixedMul(move, finesine[angle]);}//// P_XYMovement//#define STOPSPEED (0x1000/NEWTICRATERATIO)#define FRICTION 0xe800 //0.90625#define FRICTION_LOW 0xf900#define FRICTION_FLY 0xeb00//added:22-02-98: adds friction on the xy planevoid P_XYFriction (mobj_t* mo, fixed_t oldx, fixed_t oldy, boolean oldfriction){ //valid only if player avatar player_t* player = mo->player; if (mo->momx > -STOPSPEED && mo->momx < STOPSPEED && mo->momy > -STOPSPEED && mo->momy < STOPSPEED && (!player || (player->cmd.forwardmove== 0 && player->cmd.sidemove == 0 ) ) ) { // if in a walking frame, stop moving if ( player && (mo->type!=MT_SPIRIT) ) { if(player->chickenTics) { if((unsigned)((player->mo->state-states) -S_CHICPLAY_RUN1) < 4) P_SetMobjState(player->mo, S_CHICPLAY); } else { if((unsigned)((player->mo->state-states) -S_PLAY_RUN1) < 4) P_SetMobjState(player->mo, S_PLAY); } } mo->momx = 0; mo->momy = 0; } else { if( gamemode == heretic ) { if(mo->flags2&MF2_FLY && !(mo->z <= mo->floorz) &&!(mo->flags2&MF2_ONMOBJ)) { mo->momx = FixedMul(mo->momx, FRICTION_FLY); mo->momy = FixedMul(mo->momy, FRICTION_FLY); } else if(mo->subsector->sector->special == 15) // Friction_Low { mo->momx = FixedMul(mo->momx, FRICTION_LOW); mo->momy = FixedMul(mo->momy, FRICTION_LOW); } else { mo->momx = FixedMul(mo->momx, FRICTION); mo->momy = FixedMul(mo->momy, FRICTION); } } else if(oldfriction) { mo->momx = FixedMul (mo->momx, FRICTION); mo->momy = FixedMul (mo->momy, FRICTION); } else { //SoM: 3/28/2000: Use boom friction. if ((oldx == mo->x) && (oldy == mo->y)) // Did you go anywhere? { 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; } }}void P_XYMovement (mobj_t* mo){ fixed_t ptryx; fixed_t ptryy; player_t* player; fixed_t xmove; fixed_t ymove; fixed_t oldx, oldy; //reducing bobbing/momentum on ice //when up against walls static int windTab[3] = {2048*5, 2048*10, 2048*25}; //added:18-02-98: if it's stopped if (!mo->momx && !mo->momy) { if (mo->flags & MF_SKULLFLY) { // the skull slammed into something mo->flags &= ~MF_SKULLFLY; mo->momx = mo->momy = mo->momz = 0; //added:18-02-98: comment: set in 'search new direction' state? P_SetMobjState (mo, gamemode == heretic ? mo->info->seestate : mo->info->spawnstate); } return; } if(mo->flags2&MF2_WINDTHRUST) { int special = mo->subsector->sector->special; switch(special) { case 40: case 41: case 42: // Wind_East P_ThrustMobj(mo, 0, windTab[special-40]); break; case 43: case 44: case 45: // Wind_North P_ThrustMobj(mo, ANG90, windTab[special-43]); break; case 46: case 47: case 48: // Wind_South P_ThrustMobj(mo, ANG270, windTab[special-46]); break; case 49: case 50: case 51: // Wind_West P_ThrustMobj(mo, ANG180, windTab[special-49]); break; } } player = mo->player; //valid only if player avatar 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 { if (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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -