2007-01-28 03:53:06 +01:00
|
|
|
// Emacs style mode select -*- C++ -*-
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// $Id:$
|
|
|
|
//
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
//
|
|
|
|
// This source is available for distribution and/or modification
|
|
|
|
// only under the terms of the DOOM Source Code License as
|
|
|
|
// published by id Software. All rights reserved.
|
|
|
|
//
|
|
|
|
// The source is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
// $Log:$
|
|
|
|
//
|
|
|
|
// DESCRIPTION:
|
2007-02-13 05:00:47 +01:00
|
|
|
// Movement, collision handling.
|
|
|
|
// Shooting and aiming.
|
2007-01-28 03:53:06 +01:00
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static const char
|
|
|
|
rcsid[] = "$Id: p_map.c,v 1.5 1997/02/03 22:45:11 b1 Exp $";
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
#include "doomtype.h"
|
2007-01-28 03:53:06 +01:00
|
|
|
#include "m_bbox.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
|
|
|
|
#include "s_sound.h"
|
|
|
|
|
|
|
|
// State.
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "r_state.h"
|
|
|
|
// Data.
|
|
|
|
#include "sounds.h"
|
|
|
|
|
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t tmbbox[4];
|
|
|
|
mobj_t* tmthing;
|
|
|
|
int tmflags;
|
|
|
|
fixed_t tmx;
|
|
|
|
fixed_t tmy;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
// If "floatok" true, move would be ok
|
|
|
|
// if within "tmfloorz - tmceilingz".
|
2007-02-13 05:00:47 +01:00
|
|
|
boolean floatok;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t tmfloorz;
|
|
|
|
fixed_t tmceilingz;
|
|
|
|
fixed_t tmdropoffz;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// keep track of the line that lowers the ceiling,
|
|
|
|
// so missiles don't explode against sky hack walls
|
2007-02-13 05:00:47 +01:00
|
|
|
line_t* ceilingline;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// keep track of special lines as they are hit,
|
|
|
|
// but don't process them until the move is proven valid
|
2007-02-13 05:00:47 +01:00
|
|
|
#define MAXSPECIALCROSS 8
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
line_t* spechit[MAXSPECIALCROSS];
|
|
|
|
int numspechit;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// TELEPORT MOVE
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// PIT_StompThing
|
|
|
|
//
|
|
|
|
boolean PIT_StompThing (mobj_t* thing)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t blockdist;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (!(thing->flags & MF_SHOOTABLE) )
|
2007-02-13 05:00:47 +01:00
|
|
|
return true;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
blockdist = thing->radius + tmthing->radius;
|
|
|
|
|
|
|
|
if ( abs(thing->x - tmx) >= blockdist
|
2007-02-13 05:00:47 +01:00
|
|
|
|| abs(thing->y - tmy) >= blockdist )
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
// didn't hit it
|
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// don't clip against self
|
|
|
|
if (thing == tmthing)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// monsters don't stomp things except on boss level
|
|
|
|
if ( !tmthing->player && gamemap != 30)
|
2007-02-13 05:00:47 +01:00
|
|
|
return false;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
P_DamageMobj (thing, tmthing, tmthing, 10000);
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_TeleportMove
|
|
|
|
//
|
|
|
|
boolean
|
|
|
|
P_TeleportMove
|
2007-02-13 05:00:47 +01:00
|
|
|
( mobj_t* thing,
|
|
|
|
fixed_t x,
|
|
|
|
fixed_t y )
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
int xl;
|
|
|
|
int xh;
|
|
|
|
int yl;
|
|
|
|
int yh;
|
|
|
|
int bx;
|
|
|
|
int by;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
subsector_t* newsubsec;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// kill anything occupying the position
|
|
|
|
tmthing = thing;
|
|
|
|
tmflags = thing->flags;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
tmx = x;
|
|
|
|
tmy = y;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
tmbbox[BOXTOP] = y + tmthing->radius;
|
|
|
|
tmbbox[BOXBOTTOM] = y - tmthing->radius;
|
|
|
|
tmbbox[BOXRIGHT] = x + tmthing->radius;
|
|
|
|
tmbbox[BOXLEFT] = x - tmthing->radius;
|
|
|
|
|
|
|
|
newsubsec = R_PointInSubsector (x,y);
|
|
|
|
ceilingline = NULL;
|
|
|
|
|
|
|
|
// The base floor/ceiling is from the subsector
|
|
|
|
// that contains the point.
|
|
|
|
// Any contacted lines the step closer together
|
|
|
|
// will adjust them.
|
|
|
|
tmfloorz = tmdropoffz = newsubsec->sector->floorheight;
|
|
|
|
tmceilingz = newsubsec->sector->ceilingheight;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
validcount++;
|
|
|
|
numspechit = 0;
|
|
|
|
|
|
|
|
// stomp on any things contacted
|
|
|
|
xl = (tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS)>>MAPBLOCKSHIFT;
|
|
|
|
xh = (tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS)>>MAPBLOCKSHIFT;
|
|
|
|
yl = (tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS)>>MAPBLOCKSHIFT;
|
|
|
|
yh = (tmbbox[BOXTOP] - bmaporgy + MAXRADIUS)>>MAPBLOCKSHIFT;
|
|
|
|
|
|
|
|
for (bx=xl ; bx<=xh ; bx++)
|
2007-02-13 05:00:47 +01:00
|
|
|
for (by=yl ; by<=yh ; by++)
|
|
|
|
if (!P_BlockThingsIterator(bx,by,PIT_StompThing))
|
|
|
|
return false;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// the move is ok,
|
|
|
|
// so link the thing into its new position
|
|
|
|
P_UnsetThingPosition (thing);
|
|
|
|
|
|
|
|
thing->floorz = tmfloorz;
|
2007-02-13 05:00:47 +01:00
|
|
|
thing->ceilingz = tmceilingz;
|
2007-01-28 03:53:06 +01:00
|
|
|
thing->x = x;
|
|
|
|
thing->y = y;
|
|
|
|
|
|
|
|
P_SetThingPosition (thing);
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// MOVEMENT ITERATOR FUNCTIONS
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// PIT_CheckLine
|
|
|
|
// Adjusts tmfloorz and tmceilingz as lines are contacted
|
|
|
|
//
|
|
|
|
boolean PIT_CheckLine (line_t* ld)
|
|
|
|
{
|
|
|
|
if (tmbbox[BOXRIGHT] <= ld->bbox[BOXLEFT]
|
2007-02-13 05:00:47 +01:00
|
|
|
|| tmbbox[BOXLEFT] >= ld->bbox[BOXRIGHT]
|
|
|
|
|| tmbbox[BOXTOP] <= ld->bbox[BOXBOTTOM]
|
|
|
|
|| tmbbox[BOXBOTTOM] >= ld->bbox[BOXTOP] )
|
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if (P_BoxOnLineSide (tmbbox, ld) != -1)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
// A line has been hit
|
|
|
|
|
|
|
|
// The moving thing's destination position will cross
|
|
|
|
// the given line.
|
|
|
|
// If this should not be allowed, return false.
|
|
|
|
// If the line is special, keep track of it
|
|
|
|
// to process later if the move is proven ok.
|
|
|
|
// NOTE: specials are NOT sorted by order,
|
|
|
|
// so two special lines that are only 8 pixels apart
|
|
|
|
// could be crossed in either order.
|
|
|
|
|
|
|
|
if (!ld->backsector)
|
2007-02-13 05:00:47 +01:00
|
|
|
return false; // one sided line
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (!(tmthing->flags & MF_MISSILE) )
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
if ( ld->flags & ML_BLOCKING )
|
|
|
|
return false; // explicitly blocking everything
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
if ( !tmthing->player && ld->flags & ML_BLOCKMONSTERS )
|
|
|
|
return false; // block monsters only
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// set openrange, opentop, openbottom
|
2007-02-13 05:00:47 +01:00
|
|
|
P_LineOpening (ld);
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
// adjust floor / ceiling heights
|
|
|
|
if (opentop < tmceilingz)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
tmceilingz = opentop;
|
|
|
|
ceilingline = ld;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (openbottom > tmfloorz)
|
2007-02-13 05:00:47 +01:00
|
|
|
tmfloorz = openbottom;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if (lowfloor < tmdropoffz)
|
2007-02-13 05:00:47 +01:00
|
|
|
tmdropoffz = lowfloor;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
// if contacted a special line, add it to the list
|
|
|
|
if (ld->special)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
spechit[numspechit] = ld;
|
|
|
|
numspechit++;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// PIT_CheckThing
|
|
|
|
//
|
|
|
|
boolean PIT_CheckThing (mobj_t* thing)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t blockdist;
|
|
|
|
boolean solid;
|
|
|
|
int damage;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (!(thing->flags & (MF_SOLID|MF_SPECIAL|MF_SHOOTABLE) ))
|
2007-02-13 05:00:47 +01:00
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
blockdist = thing->radius + tmthing->radius;
|
|
|
|
|
|
|
|
if ( abs(thing->x - tmx) >= blockdist
|
2007-02-13 05:00:47 +01:00
|
|
|
|| abs(thing->y - tmy) >= blockdist )
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
// didn't hit it
|
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// don't clip against self
|
|
|
|
if (thing == tmthing)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// check for skulls slamming into things
|
|
|
|
if (tmthing->flags & MF_SKULLFLY)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
damage = ((P_Random()%8)+1)*tmthing->info->damage;
|
|
|
|
|
|
|
|
P_DamageMobj (thing, tmthing, tmthing, damage);
|
|
|
|
|
|
|
|
tmthing->flags &= ~MF_SKULLFLY;
|
|
|
|
tmthing->momx = tmthing->momy = tmthing->momz = 0;
|
|
|
|
|
|
|
|
P_SetMobjState (tmthing, tmthing->info->spawnstate);
|
|
|
|
|
|
|
|
return false; // stop moving
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// missiles can hit other things
|
|
|
|
if (tmthing->flags & MF_MISSILE)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
// see if it went over / under
|
|
|
|
if (tmthing->z > thing->z + thing->height)
|
|
|
|
return true; // overhead
|
|
|
|
if (tmthing->z+tmthing->height < thing->z)
|
|
|
|
return true; // underneath
|
|
|
|
|
|
|
|
if (tmthing->target && (
|
|
|
|
tmthing->target->type == thing->type ||
|
|
|
|
(tmthing->target->type == MT_KNIGHT && thing->type == MT_BRUISER)||
|
|
|
|
(tmthing->target->type == MT_BRUISER && thing->type == MT_KNIGHT) ) )
|
|
|
|
{
|
|
|
|
// Don't hit same species as originator.
|
|
|
|
if (thing == tmthing->target)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (thing->type != MT_PLAYER)
|
|
|
|
{
|
|
|
|
// Explode, but do no damage.
|
|
|
|
// Let players missile other players.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! (thing->flags & MF_SHOOTABLE) )
|
|
|
|
{
|
|
|
|
// didn't do any damage
|
|
|
|
return !(thing->flags & MF_SOLID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// damage / explode
|
|
|
|
damage = ((P_Random()%8)+1)*tmthing->info->damage;
|
|
|
|
P_DamageMobj (thing, tmthing, tmthing->target, damage);
|
|
|
|
|
|
|
|
// don't traverse any more
|
|
|
|
return false;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for special pickup
|
|
|
|
if (thing->flags & MF_SPECIAL)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
solid = thing->flags&MF_SOLID;
|
|
|
|
if (tmflags&MF_PICKUP)
|
|
|
|
{
|
|
|
|
// can remove thing
|
|
|
|
P_TouchSpecialThing (thing, tmthing);
|
|
|
|
}
|
|
|
|
return !solid;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
return !(thing->flags & MF_SOLID);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// MOVEMENT CLIPPING
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_CheckPosition
|
|
|
|
// This is purely informative, nothing is modified
|
|
|
|
// (except things picked up).
|
|
|
|
//
|
|
|
|
// in:
|
|
|
|
// a mobj_t (can be valid or invalid)
|
|
|
|
// a position to be checked
|
|
|
|
// (doesn't need to be related to the mobj_t->x,y)
|
|
|
|
//
|
|
|
|
// during:
|
|
|
|
// special things are touched if MF_PICKUP
|
|
|
|
// early out on solid lines?
|
|
|
|
//
|
|
|
|
// out:
|
|
|
|
// newsubsec
|
|
|
|
// floorz
|
|
|
|
// ceilingz
|
|
|
|
// tmdropoffz
|
|
|
|
// the lowest point contacted
|
|
|
|
// (monsters won't move to a dropoff)
|
|
|
|
// speciallines[]
|
|
|
|
// numspeciallines
|
|
|
|
//
|
|
|
|
boolean
|
|
|
|
P_CheckPosition
|
2007-02-13 05:00:47 +01:00
|
|
|
( mobj_t* thing,
|
|
|
|
fixed_t x,
|
|
|
|
fixed_t y )
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
int xl;
|
|
|
|
int xh;
|
|
|
|
int yl;
|
|
|
|
int yh;
|
|
|
|
int bx;
|
|
|
|
int by;
|
|
|
|
subsector_t* newsubsec;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
tmthing = thing;
|
|
|
|
tmflags = thing->flags;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
tmx = x;
|
|
|
|
tmy = y;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
tmbbox[BOXTOP] = y + tmthing->radius;
|
|
|
|
tmbbox[BOXBOTTOM] = y - tmthing->radius;
|
|
|
|
tmbbox[BOXRIGHT] = x + tmthing->radius;
|
|
|
|
tmbbox[BOXLEFT] = x - tmthing->radius;
|
|
|
|
|
|
|
|
newsubsec = R_PointInSubsector (x,y);
|
|
|
|
ceilingline = NULL;
|
|
|
|
|
|
|
|
// The base floor / ceiling is from the subsector
|
|
|
|
// that contains the point.
|
|
|
|
// Any contacted lines the step closer together
|
|
|
|
// will adjust them.
|
|
|
|
tmfloorz = tmdropoffz = newsubsec->sector->floorheight;
|
|
|
|
tmceilingz = newsubsec->sector->ceilingheight;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
validcount++;
|
|
|
|
numspechit = 0;
|
|
|
|
|
|
|
|
if ( tmflags & MF_NOCLIP )
|
2007-02-13 05:00:47 +01:00
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// Check things first, possibly picking things up.
|
|
|
|
// The bounding box is extended by MAXRADIUS
|
|
|
|
// because mobj_ts are grouped into mapblocks
|
|
|
|
// based on their origin point, and can overlap
|
|
|
|
// into adjacent blocks by up to MAXRADIUS units.
|
|
|
|
xl = (tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS)>>MAPBLOCKSHIFT;
|
|
|
|
xh = (tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS)>>MAPBLOCKSHIFT;
|
|
|
|
yl = (tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS)>>MAPBLOCKSHIFT;
|
|
|
|
yh = (tmbbox[BOXTOP] - bmaporgy + MAXRADIUS)>>MAPBLOCKSHIFT;
|
|
|
|
|
|
|
|
for (bx=xl ; bx<=xh ; bx++)
|
2007-02-13 05:00:47 +01:00
|
|
|
for (by=yl ; by<=yh ; by++)
|
|
|
|
if (!P_BlockThingsIterator(bx,by,PIT_CheckThing))
|
|
|
|
return false;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// check lines
|
|
|
|
xl = (tmbbox[BOXLEFT] - bmaporgx)>>MAPBLOCKSHIFT;
|
|
|
|
xh = (tmbbox[BOXRIGHT] - bmaporgx)>>MAPBLOCKSHIFT;
|
|
|
|
yl = (tmbbox[BOXBOTTOM] - bmaporgy)>>MAPBLOCKSHIFT;
|
|
|
|
yh = (tmbbox[BOXTOP] - bmaporgy)>>MAPBLOCKSHIFT;
|
|
|
|
|
|
|
|
for (bx=xl ; bx<=xh ; bx++)
|
2007-02-13 05:00:47 +01:00
|
|
|
for (by=yl ; by<=yh ; by++)
|
|
|
|
if (!P_BlockLinesIterator (bx,by,PIT_CheckLine))
|
|
|
|
return false;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_TryMove
|
|
|
|
// Attempt to move to a new position,
|
|
|
|
// crossing special lines unless MF_TELEPORT is set.
|
|
|
|
//
|
|
|
|
boolean
|
|
|
|
P_TryMove
|
2007-02-13 05:00:47 +01:00
|
|
|
( mobj_t* thing,
|
|
|
|
fixed_t x,
|
|
|
|
fixed_t y )
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t oldx;
|
|
|
|
fixed_t oldy;
|
|
|
|
int side;
|
|
|
|
int oldside;
|
|
|
|
line_t* ld;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
floatok = false;
|
|
|
|
if (!P_CheckPosition (thing, x, y))
|
2007-02-13 05:00:47 +01:00
|
|
|
return false; // solid wall or thing
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if ( !(thing->flags & MF_NOCLIP) )
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
if (tmceilingz - tmfloorz < thing->height)
|
|
|
|
return false; // doesn't fit
|
|
|
|
|
|
|
|
floatok = true;
|
|
|
|
|
|
|
|
if ( !(thing->flags&MF_TELEPORT)
|
|
|
|
&&tmceilingz - thing->z < thing->height)
|
|
|
|
return false; // mobj must lower itself to fit
|
|
|
|
|
|
|
|
if ( !(thing->flags&MF_TELEPORT)
|
|
|
|
&& tmfloorz - thing->z > 24*FRACUNIT )
|
|
|
|
return false; // too big a step up
|
|
|
|
|
|
|
|
if ( !(thing->flags&(MF_DROPOFF|MF_FLOAT))
|
|
|
|
&& tmfloorz - tmdropoffz > 24*FRACUNIT )
|
|
|
|
return false; // don't stand over a dropoff
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// the move is ok,
|
|
|
|
// so link the thing into its new position
|
|
|
|
P_UnsetThingPosition (thing);
|
|
|
|
|
|
|
|
oldx = thing->x;
|
|
|
|
oldy = thing->y;
|
|
|
|
thing->floorz = tmfloorz;
|
2007-02-13 05:00:47 +01:00
|
|
|
thing->ceilingz = tmceilingz;
|
2007-01-28 03:53:06 +01:00
|
|
|
thing->x = x;
|
|
|
|
thing->y = y;
|
|
|
|
|
|
|
|
P_SetThingPosition (thing);
|
|
|
|
|
|
|
|
// if any special lines were hit, do the effect
|
|
|
|
if (! (thing->flags&(MF_TELEPORT|MF_NOCLIP)) )
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
while (numspechit--)
|
|
|
|
{
|
|
|
|
// see if the line was crossed
|
|
|
|
ld = spechit[numspechit];
|
|
|
|
side = P_PointOnLineSide (thing->x, thing->y, ld);
|
|
|
|
oldside = P_PointOnLineSide (oldx, oldy, ld);
|
|
|
|
if (side != oldside)
|
|
|
|
{
|
|
|
|
if (ld->special)
|
|
|
|
P_CrossSpecialLine (ld-lines, oldside, thing);
|
|
|
|
}
|
|
|
|
}
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_ThingHeightClip
|
|
|
|
// Takes a valid thing and adjusts the thing->floorz,
|
|
|
|
// thing->ceilingz, and possibly thing->z.
|
|
|
|
// This is called for all nearby monsters
|
|
|
|
// whenever a sector changes height.
|
|
|
|
// If the thing doesn't fit,
|
|
|
|
// the z will be set to the lowest value
|
|
|
|
// and false will be returned.
|
|
|
|
//
|
|
|
|
boolean P_ThingHeightClip (mobj_t* thing)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
boolean onfloor;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
onfloor = (thing->z == thing->floorz);
|
2007-02-13 05:00:47 +01:00
|
|
|
|
|
|
|
P_CheckPosition (thing, thing->x, thing->y);
|
2007-01-28 03:53:06 +01:00
|
|
|
// what about stranding a monster partially off an edge?
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
thing->floorz = tmfloorz;
|
|
|
|
thing->ceilingz = tmceilingz;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (onfloor)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
// walking monsters rise and fall with the floor
|
|
|
|
thing->z = thing->floorz;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
// don't adjust a floating monster unless forced to
|
|
|
|
if (thing->z+thing->height > thing->ceilingz)
|
|
|
|
thing->z = thing->ceilingz - thing->height;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (thing->ceilingz - thing->floorz < thing->height)
|
2007-02-13 05:00:47 +01:00
|
|
|
return false;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// SLIDE MOVE
|
|
|
|
// Allows the player to slide along any angled walls.
|
|
|
|
//
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t bestslidefrac;
|
|
|
|
fixed_t secondslidefrac;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
line_t* bestslideline;
|
|
|
|
line_t* secondslideline;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
mobj_t* slidemo;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t tmxmove;
|
|
|
|
fixed_t tmymove;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_HitSlideLine
|
|
|
|
// Adjusts the xmove / ymove
|
|
|
|
// so that the next move will slide along the wall.
|
|
|
|
//
|
|
|
|
void P_HitSlideLine (line_t* ld)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
int side;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
angle_t lineangle;
|
|
|
|
angle_t moveangle;
|
|
|
|
angle_t deltaangle;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t movelen;
|
|
|
|
fixed_t newlen;
|
|
|
|
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (ld->slopetype == ST_HORIZONTAL)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
tmymove = 0;
|
|
|
|
return;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ld->slopetype == ST_VERTICAL)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
tmxmove = 0;
|
|
|
|
return;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
side = P_PointOnLineSide (slidemo->x, slidemo->y, ld);
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
lineangle = R_PointToAngle2 (0,0, ld->dx, ld->dy);
|
|
|
|
|
|
|
|
if (side == 1)
|
2007-02-13 05:00:47 +01:00
|
|
|
lineangle += ANG180;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
moveangle = R_PointToAngle2 (0,0, tmxmove, tmymove);
|
|
|
|
deltaangle = moveangle-lineangle;
|
|
|
|
|
|
|
|
if (deltaangle > ANG180)
|
2007-02-13 05:00:47 +01:00
|
|
|
deltaangle += ANG180;
|
|
|
|
// I_Error ("SlideLine: ang>ANG180");
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
lineangle >>= ANGLETOFINESHIFT;
|
|
|
|
deltaangle >>= ANGLETOFINESHIFT;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
movelen = P_AproxDistance (tmxmove, tmymove);
|
|
|
|
newlen = FixedMul (movelen, finecosine[deltaangle]);
|
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
tmxmove = FixedMul (newlen, finecosine[lineangle]);
|
|
|
|
tmymove = FixedMul (newlen, finesine[lineangle]);
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// PTR_SlideTraverse
|
|
|
|
//
|
|
|
|
boolean PTR_SlideTraverse (intercept_t* in)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
line_t* li;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (!in->isaline)
|
2007-02-13 05:00:47 +01:00
|
|
|
I_Error ("PTR_SlideTraverse: not a line?");
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
li = in->d.line;
|
|
|
|
|
|
|
|
if ( ! (li->flags & ML_TWOSIDED) )
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
if (P_PointOnLineSide (slidemo->x, slidemo->y, li))
|
|
|
|
{
|
|
|
|
// don't hit the back side
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
goto isblocking;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// set openrange, opentop, openbottom
|
|
|
|
P_LineOpening (li);
|
|
|
|
|
|
|
|
if (openrange < slidemo->height)
|
2007-02-13 05:00:47 +01:00
|
|
|
goto isblocking; // doesn't fit
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (opentop - slidemo->z < slidemo->height)
|
2007-02-13 05:00:47 +01:00
|
|
|
goto isblocking; // mobj is too high
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if (openbottom - slidemo->z > 24*FRACUNIT )
|
2007-02-13 05:00:47 +01:00
|
|
|
goto isblocking; // too big a step up
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// this line doesn't block movement
|
2007-02-13 05:00:47 +01:00
|
|
|
return true;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
// the line does block movement,
|
|
|
|
// see if it is closer than best so far
|
2007-02-13 05:00:47 +01:00
|
|
|
isblocking:
|
2007-01-28 03:53:06 +01:00
|
|
|
if (in->frac < bestslidefrac)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
secondslidefrac = bestslidefrac;
|
|
|
|
secondslideline = bestslideline;
|
|
|
|
bestslidefrac = in->frac;
|
|
|
|
bestslideline = li;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
2007-02-13 05:00:47 +01:00
|
|
|
|
|
|
|
return false; // stop
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_SlideMove
|
|
|
|
// The momx / momy move is bad, so try to slide
|
|
|
|
// along a wall.
|
|
|
|
// Find the first line hit, move flush to it,
|
|
|
|
// and slide along it
|
|
|
|
//
|
|
|
|
// This is a kludgy mess.
|
|
|
|
//
|
|
|
|
void P_SlideMove (mobj_t* mo)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t leadx;
|
|
|
|
fixed_t leady;
|
|
|
|
fixed_t trailx;
|
|
|
|
fixed_t traily;
|
|
|
|
fixed_t newx;
|
|
|
|
fixed_t newy;
|
|
|
|
int hitcount;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
slidemo = mo;
|
|
|
|
hitcount = 0;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
if (++hitcount == 3)
|
2007-02-13 05:00:47 +01:00
|
|
|
goto stairstep; // don't loop forever
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
// trace along the three leading corners
|
|
|
|
if (mo->momx > 0)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
leadx = mo->x + mo->radius;
|
|
|
|
trailx = mo->x - mo->radius;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
leadx = mo->x - mo->radius;
|
|
|
|
trailx = mo->x + mo->radius;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (mo->momy > 0)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
leady = mo->y + mo->radius;
|
|
|
|
traily = mo->y - mo->radius;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
leady = mo->y - mo->radius;
|
|
|
|
traily = mo->y + mo->radius;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
bestslidefrac = FRACUNIT+1;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
P_PathTraverse ( leadx, leady, leadx+mo->momx, leady+mo->momy,
|
2007-02-13 05:00:47 +01:00
|
|
|
PT_ADDLINES, PTR_SlideTraverse );
|
2007-01-28 03:53:06 +01:00
|
|
|
P_PathTraverse ( trailx, leady, trailx+mo->momx, leady+mo->momy,
|
2007-02-13 05:00:47 +01:00
|
|
|
PT_ADDLINES, PTR_SlideTraverse );
|
2007-01-28 03:53:06 +01:00
|
|
|
P_PathTraverse ( leadx, traily, leadx+mo->momx, traily+mo->momy,
|
2007-02-13 05:00:47 +01:00
|
|
|
PT_ADDLINES, PTR_SlideTraverse );
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// move up to the wall
|
|
|
|
if (bestslidefrac == FRACUNIT+1)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
// the move most have hit the middle, so stairstep
|
2007-01-28 03:53:06 +01:00
|
|
|
stairstep:
|
2007-02-13 05:00:47 +01:00
|
|
|
if (!P_TryMove (mo, mo->x, mo->y + mo->momy))
|
|
|
|
P_TryMove (mo, mo->x + mo->momx, mo->y);
|
|
|
|
return;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// fudge a bit to make sure it doesn't hit
|
2007-02-13 05:00:47 +01:00
|
|
|
bestslidefrac -= 0x800;
|
2007-01-28 03:53:06 +01:00
|
|
|
if (bestslidefrac > 0)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
newx = FixedMul (mo->momx, bestslidefrac);
|
|
|
|
newy = FixedMul (mo->momy, bestslidefrac);
|
|
|
|
|
|
|
|
if (!P_TryMove (mo, mo->x+newx, mo->y+newy))
|
|
|
|
goto stairstep;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now continue along the wall.
|
|
|
|
// First calculate remainder.
|
|
|
|
bestslidefrac = FRACUNIT-(bestslidefrac+0x800);
|
|
|
|
|
|
|
|
if (bestslidefrac > FRACUNIT)
|
2007-02-13 05:00:47 +01:00
|
|
|
bestslidefrac = FRACUNIT;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if (bestslidefrac <= 0)
|
2007-02-13 05:00:47 +01:00
|
|
|
return;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
tmxmove = FixedMul (mo->momx, bestslidefrac);
|
|
|
|
tmymove = FixedMul (mo->momy, bestslidefrac);
|
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
P_HitSlideLine (bestslideline); // clip the moves
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
mo->momx = tmxmove;
|
|
|
|
mo->momy = tmymove;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (!P_TryMove (mo, mo->x+tmxmove, mo->y+tmymove))
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
goto retry;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_LineAttack
|
|
|
|
//
|
2007-02-13 05:00:47 +01:00
|
|
|
mobj_t* linetarget; // who got hit (or NULL)
|
|
|
|
mobj_t* shootthing;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// Height if not aiming up or down
|
|
|
|
// ???: use slope for monsters?
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t shootz;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
int la_damage;
|
|
|
|
fixed_t attackrange;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t aimslope;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// slopes to top and bottom of target
|
2007-02-13 05:00:47 +01:00
|
|
|
extern fixed_t topslope;
|
|
|
|
extern fixed_t bottomslope;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// PTR_AimTraverse
|
|
|
|
// Sets linetaget and aimslope when a target is aimed at.
|
|
|
|
//
|
|
|
|
boolean
|
|
|
|
PTR_AimTraverse (intercept_t* in)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
line_t* li;
|
|
|
|
mobj_t* th;
|
|
|
|
fixed_t slope;
|
|
|
|
fixed_t thingtopslope;
|
|
|
|
fixed_t thingbottomslope;
|
|
|
|
fixed_t dist;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (in->isaline)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
li = in->d.line;
|
|
|
|
|
|
|
|
if ( !(li->flags & ML_TWOSIDED) )
|
|
|
|
return false; // stop
|
|
|
|
|
|
|
|
// Crosses a two sided line.
|
|
|
|
// A two sided line will restrict
|
|
|
|
// the possible target ranges.
|
|
|
|
P_LineOpening (li);
|
|
|
|
|
|
|
|
if (openbottom >= opentop)
|
|
|
|
return false; // stop
|
|
|
|
|
|
|
|
dist = FixedMul (attackrange, in->frac);
|
|
|
|
|
|
|
|
if (li->frontsector->floorheight != li->backsector->floorheight)
|
|
|
|
{
|
|
|
|
slope = FixedDiv (openbottom - shootz , dist);
|
|
|
|
if (slope > bottomslope)
|
|
|
|
bottomslope = slope;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (li->frontsector->ceilingheight != li->backsector->ceilingheight)
|
|
|
|
{
|
|
|
|
slope = FixedDiv (opentop - shootz , dist);
|
|
|
|
if (slope < topslope)
|
|
|
|
topslope = slope;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topslope <= bottomslope)
|
|
|
|
return false; // stop
|
|
|
|
|
|
|
|
return true; // shot continues
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// shoot a thing
|
|
|
|
th = in->d.thing;
|
|
|
|
if (th == shootthing)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true; // can't shoot self
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if (!(th->flags&MF_SHOOTABLE))
|
2007-02-13 05:00:47 +01:00
|
|
|
return true; // corpse or something
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// check angles to see if the thing can be aimed at
|
|
|
|
dist = FixedMul (attackrange, in->frac);
|
|
|
|
thingtopslope = FixedDiv (th->z+th->height - shootz , dist);
|
|
|
|
|
|
|
|
if (thingtopslope < bottomslope)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true; // shot over the thing
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
thingbottomslope = FixedDiv (th->z - shootz, dist);
|
|
|
|
|
|
|
|
if (thingbottomslope > topslope)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true; // shot under the thing
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// this thing can be hit!
|
|
|
|
if (thingtopslope > topslope)
|
2007-02-13 05:00:47 +01:00
|
|
|
thingtopslope = topslope;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if (thingbottomslope < bottomslope)
|
2007-02-13 05:00:47 +01:00
|
|
|
thingbottomslope = bottomslope;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
aimslope = (thingtopslope+thingbottomslope)/2;
|
|
|
|
linetarget = th;
|
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
return false; // don't go any farther
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// PTR_ShootTraverse
|
|
|
|
//
|
|
|
|
boolean PTR_ShootTraverse (intercept_t* in)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t x;
|
|
|
|
fixed_t y;
|
|
|
|
fixed_t z;
|
|
|
|
fixed_t frac;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
line_t* li;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
mobj_t* th;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t slope;
|
|
|
|
fixed_t dist;
|
|
|
|
fixed_t thingtopslope;
|
|
|
|
fixed_t thingbottomslope;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (in->isaline)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
li = in->d.line;
|
|
|
|
|
|
|
|
if (li->special)
|
|
|
|
P_ShootSpecialLine (shootthing, li);
|
|
|
|
|
|
|
|
if ( !(li->flags & ML_TWOSIDED) )
|
|
|
|
goto hitline;
|
|
|
|
|
|
|
|
// crosses a two sided line
|
|
|
|
P_LineOpening (li);
|
|
|
|
|
|
|
|
dist = FixedMul (attackrange, in->frac);
|
|
|
|
|
|
|
|
if (li->frontsector->floorheight != li->backsector->floorheight)
|
|
|
|
{
|
|
|
|
slope = FixedDiv (openbottom - shootz , dist);
|
|
|
|
if (slope > aimslope)
|
|
|
|
goto hitline;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (li->frontsector->ceilingheight != li->backsector->ceilingheight)
|
|
|
|
{
|
|
|
|
slope = FixedDiv (opentop - shootz , dist);
|
|
|
|
if (slope < aimslope)
|
|
|
|
goto hitline;
|
|
|
|
}
|
|
|
|
|
|
|
|
// shot continues
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
// hit line
|
2007-01-28 03:53:06 +01:00
|
|
|
hitline:
|
2007-02-13 05:00:47 +01:00
|
|
|
// position a bit closer
|
|
|
|
frac = in->frac - FixedDiv (4*FRACUNIT,attackrange);
|
|
|
|
x = trace.x + FixedMul (trace.dx, frac);
|
|
|
|
y = trace.y + FixedMul (trace.dy, frac);
|
|
|
|
z = shootz + FixedMul (aimslope, FixedMul(frac, attackrange));
|
|
|
|
|
|
|
|
if (li->frontsector->ceilingpic == skyflatnum)
|
|
|
|
{
|
|
|
|
// don't shoot the sky!
|
|
|
|
if (z > li->frontsector->ceilingheight)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// it's a sky hack wall
|
|
|
|
if (li->backsector && li->backsector->ceilingpic == skyflatnum)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spawn bullet puffs.
|
|
|
|
P_SpawnPuff (x,y,z);
|
|
|
|
|
|
|
|
// don't go any farther
|
|
|
|
return false;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// shoot a thing
|
|
|
|
th = in->d.thing;
|
|
|
|
if (th == shootthing)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true; // can't shoot self
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if (!(th->flags&MF_SHOOTABLE))
|
2007-02-13 05:00:47 +01:00
|
|
|
return true; // corpse or something
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
// check angles to see if the thing can be aimed at
|
|
|
|
dist = FixedMul (attackrange, in->frac);
|
|
|
|
thingtopslope = FixedDiv (th->z+th->height - shootz , dist);
|
|
|
|
|
|
|
|
if (thingtopslope < aimslope)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true; // shot over the thing
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
thingbottomslope = FixedDiv (th->z - shootz, dist);
|
|
|
|
|
|
|
|
if (thingbottomslope > aimslope)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true; // shot under the thing
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
// hit thing
|
|
|
|
// position a bit closer
|
|
|
|
frac = in->frac - FixedDiv (10*FRACUNIT,attackrange);
|
|
|
|
|
|
|
|
x = trace.x + FixedMul (trace.dx, frac);
|
|
|
|
y = trace.y + FixedMul (trace.dy, frac);
|
|
|
|
z = shootz + FixedMul (aimslope, FixedMul(frac, attackrange));
|
|
|
|
|
|
|
|
// Spawn bullet puffs or blod spots,
|
|
|
|
// depending on target type.
|
|
|
|
if (in->d.thing->flags & MF_NOBLOOD)
|
2007-02-13 05:00:47 +01:00
|
|
|
P_SpawnPuff (x,y,z);
|
2007-01-28 03:53:06 +01:00
|
|
|
else
|
2007-02-13 05:00:47 +01:00
|
|
|
P_SpawnBlood (x,y,z, la_damage);
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if (la_damage)
|
2007-02-13 05:00:47 +01:00
|
|
|
P_DamageMobj (th, shootthing, shootthing, la_damage);
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// don't go any farther
|
|
|
|
return false;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_AimLineAttack
|
|
|
|
//
|
|
|
|
fixed_t
|
|
|
|
P_AimLineAttack
|
2007-02-13 05:00:47 +01:00
|
|
|
( mobj_t* t1,
|
|
|
|
angle_t angle,
|
|
|
|
fixed_t distance )
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t x2;
|
|
|
|
fixed_t y2;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
angle >>= ANGLETOFINESHIFT;
|
|
|
|
shootthing = t1;
|
|
|
|
|
|
|
|
x2 = t1->x + (distance>>FRACBITS)*finecosine[angle];
|
|
|
|
y2 = t1->y + (distance>>FRACBITS)*finesine[angle];
|
|
|
|
shootz = t1->z + (t1->height>>1) + 8*FRACUNIT;
|
|
|
|
|
|
|
|
// can't shoot outside view angles
|
2007-02-13 05:00:47 +01:00
|
|
|
topslope = 100*FRACUNIT/160;
|
2007-01-28 03:53:06 +01:00
|
|
|
bottomslope = -100*FRACUNIT/160;
|
|
|
|
|
|
|
|
attackrange = distance;
|
|
|
|
linetarget = NULL;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
P_PathTraverse ( t1->x, t1->y,
|
2007-02-13 05:00:47 +01:00
|
|
|
x2, y2,
|
|
|
|
PT_ADDLINES|PT_ADDTHINGS,
|
|
|
|
PTR_AimTraverse );
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (linetarget)
|
2007-02-13 05:00:47 +01:00
|
|
|
return aimslope;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_LineAttack
|
|
|
|
// If damage == 0, it is just a test trace
|
|
|
|
// that will leave linetarget set.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
P_LineAttack
|
2007-02-13 05:00:47 +01:00
|
|
|
( mobj_t* t1,
|
|
|
|
angle_t angle,
|
|
|
|
fixed_t distance,
|
|
|
|
fixed_t slope,
|
|
|
|
int damage )
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t x2;
|
|
|
|
fixed_t y2;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
angle >>= ANGLETOFINESHIFT;
|
|
|
|
shootthing = t1;
|
|
|
|
la_damage = damage;
|
|
|
|
x2 = t1->x + (distance>>FRACBITS)*finecosine[angle];
|
|
|
|
y2 = t1->y + (distance>>FRACBITS)*finesine[angle];
|
|
|
|
shootz = t1->z + (t1->height>>1) + 8*FRACUNIT;
|
|
|
|
attackrange = distance;
|
|
|
|
aimslope = slope;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
P_PathTraverse ( t1->x, t1->y,
|
2007-02-13 05:00:47 +01:00
|
|
|
x2, y2,
|
|
|
|
PT_ADDLINES|PT_ADDTHINGS,
|
|
|
|
PTR_ShootTraverse );
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// USE LINES
|
|
|
|
//
|
2007-02-13 05:00:47 +01:00
|
|
|
mobj_t* usething;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
boolean PTR_UseTraverse (intercept_t* in)
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
int side;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (!in->d.line->special)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
P_LineOpening (in->d.line);
|
|
|
|
if (openrange <= 0)
|
|
|
|
{
|
|
|
|
S_StartSound (usething, sfx_noway);
|
|
|
|
|
|
|
|
// can't use through a wall
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// not a special line, but keep checking
|
|
|
|
return true ;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
side = 0;
|
|
|
|
if (P_PointOnLineSide (usething->x, usething->y, in->d.line) == 1)
|
2007-02-13 05:00:47 +01:00
|
|
|
side = 1;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
// return false; // don't use back side
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
P_UseSpecialLine (usething, in->d.line, side);
|
|
|
|
|
|
|
|
// can't use for than one special line in a row
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_UseLines
|
|
|
|
// Looks for special lines in front of the player to activate.
|
|
|
|
//
|
2007-02-13 05:00:47 +01:00
|
|
|
void P_UseLines (player_t* player)
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
int angle;
|
|
|
|
fixed_t x1;
|
|
|
|
fixed_t y1;
|
|
|
|
fixed_t x2;
|
|
|
|
fixed_t y2;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
usething = player->mo;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
angle = player->mo->angle >> ANGLETOFINESHIFT;
|
|
|
|
|
|
|
|
x1 = player->mo->x;
|
|
|
|
y1 = player->mo->y;
|
|
|
|
x2 = x1 + (USERANGE>>FRACBITS)*finecosine[angle];
|
|
|
|
y2 = y1 + (USERANGE>>FRACBITS)*finesine[angle];
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
P_PathTraverse ( x1, y1, x2, y2, PT_ADDLINES, PTR_UseTraverse );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// RADIUS ATTACK
|
|
|
|
//
|
2007-02-13 05:00:47 +01:00
|
|
|
mobj_t* bombsource;
|
|
|
|
mobj_t* bombspot;
|
|
|
|
int bombdamage;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// PIT_RadiusAttack
|
|
|
|
// "bombsource" is the creature
|
|
|
|
// that caused the explosion at "bombspot".
|
|
|
|
//
|
|
|
|
boolean PIT_RadiusAttack (mobj_t* thing)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t dx;
|
|
|
|
fixed_t dy;
|
|
|
|
fixed_t dist;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (!(thing->flags & MF_SHOOTABLE) )
|
2007-02-13 05:00:47 +01:00
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
// Boss spider and cyborg
|
|
|
|
// take no damage from concussion.
|
|
|
|
if (thing->type == MT_CYBORG
|
2007-02-13 05:00:47 +01:00
|
|
|
|| thing->type == MT_SPIDER)
|
|
|
|
return true;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
dx = abs(thing->x - bombspot->x);
|
|
|
|
dy = abs(thing->y - bombspot->y);
|
|
|
|
|
|
|
|
dist = dx>dy ? dx : dy;
|
|
|
|
dist = (dist - thing->radius) >> FRACBITS;
|
|
|
|
|
|
|
|
if (dist < 0)
|
2007-02-13 05:00:47 +01:00
|
|
|
dist = 0;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if (dist >= bombdamage)
|
2007-02-13 05:00:47 +01:00
|
|
|
return true; // out of range
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
if ( P_CheckSight (thing, bombspot) )
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
// must be in direct path
|
|
|
|
P_DamageMobj (thing, bombspot, bombsource, bombdamage - dist);
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_RadiusAttack
|
|
|
|
// Source is the creature that caused the explosion at spot.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
P_RadiusAttack
|
2007-02-13 05:00:47 +01:00
|
|
|
( mobj_t* spot,
|
|
|
|
mobj_t* source,
|
|
|
|
int damage )
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
int x;
|
|
|
|
int y;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
int xl;
|
|
|
|
int xh;
|
|
|
|
int yl;
|
|
|
|
int yh;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
fixed_t dist;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
dist = (damage+MAXRADIUS)<<FRACBITS;
|
|
|
|
yh = (spot->y + dist - bmaporgy)>>MAPBLOCKSHIFT;
|
|
|
|
yl = (spot->y - dist - bmaporgy)>>MAPBLOCKSHIFT;
|
|
|
|
xh = (spot->x + dist - bmaporgx)>>MAPBLOCKSHIFT;
|
|
|
|
xl = (spot->x - dist - bmaporgx)>>MAPBLOCKSHIFT;
|
|
|
|
bombspot = spot;
|
|
|
|
bombsource = source;
|
|
|
|
bombdamage = damage;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
for (y=yl ; y<=yh ; y++)
|
2007-02-13 05:00:47 +01:00
|
|
|
for (x=xl ; x<=xh ; x++)
|
|
|
|
P_BlockThingsIterator (x, y, PIT_RadiusAttack );
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// SECTOR HEIGHT CHANGING
|
|
|
|
// After modifying a sectors floor or ceiling height,
|
|
|
|
// call this routine to adjust the positions
|
|
|
|
// of all things that touch the sector.
|
|
|
|
//
|
|
|
|
// If anything doesn't fit anymore, true will be returned.
|
|
|
|
// If crunch is true, they will take damage
|
|
|
|
// as they are being crushed.
|
|
|
|
// If Crunch is false, you should set the sector height back
|
|
|
|
// the way it was and call P_ChangeSector again
|
|
|
|
// to undo the changes.
|
|
|
|
//
|
2007-02-13 05:00:47 +01:00
|
|
|
boolean crushchange;
|
|
|
|
boolean nofit;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// PIT_ChangeSector
|
|
|
|
//
|
2007-02-13 05:00:47 +01:00
|
|
|
boolean PIT_ChangeSector (mobj_t* thing)
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
mobj_t* mo;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
if (P_ThingHeightClip (thing))
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
// keep checking
|
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// crunch bodies to giblets
|
|
|
|
if (thing->health <= 0)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
P_SetMobjState (thing, S_GIBS);
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
thing->flags &= ~MF_SOLID;
|
|
|
|
thing->height = 0;
|
|
|
|
thing->radius = 0;
|
2007-01-28 03:53:06 +01:00
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
// keep checking
|
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// crunch dropped items
|
|
|
|
if (thing->flags & MF_DROPPED)
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
P_RemoveMobj (thing);
|
|
|
|
|
|
|
|
// keep checking
|
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! (thing->flags & MF_SHOOTABLE) )
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
// assume it is bloody gibs or something
|
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nofit = true;
|
|
|
|
|
|
|
|
if (crushchange && !(leveltime&3) )
|
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
P_DamageMobj(thing,NULL,NULL,10);
|
|
|
|
|
|
|
|
// spray blood in a random direction
|
|
|
|
mo = P_SpawnMobj (thing->x,
|
|
|
|
thing->y,
|
|
|
|
thing->z + thing->height/2, MT_BLOOD);
|
|
|
|
|
|
|
|
mo->momx = (P_Random() - P_Random ())<<12;
|
|
|
|
mo->momy = (P_Random() - P_Random ())<<12;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
2007-02-13 05:00:47 +01:00
|
|
|
// keep checking (crush other things)
|
|
|
|
return true;
|
2007-01-28 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_ChangeSector
|
|
|
|
//
|
|
|
|
boolean
|
|
|
|
P_ChangeSector
|
2007-02-13 05:00:47 +01:00
|
|
|
( sector_t* sector,
|
|
|
|
boolean crunch )
|
2007-01-28 03:53:06 +01:00
|
|
|
{
|
2007-02-13 05:00:47 +01:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
nofit = false;
|
|
|
|
crushchange = crunch;
|
2007-02-13 05:00:47 +01:00
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
// re-check heights for all things near the moving sector
|
|
|
|
for (x=sector->blockbox[BOXLEFT] ; x<= sector->blockbox[BOXRIGHT] ; x++)
|
2007-02-13 05:00:47 +01:00
|
|
|
for (y=sector->blockbox[BOXBOTTOM];y<= sector->blockbox[BOXTOP] ; y++)
|
|
|
|
P_BlockThingsIterator (x, y, PIT_ChangeSector);
|
|
|
|
|
|
|
|
|
2007-01-28 03:53:06 +01:00
|
|
|
return nofit;
|
|
|
|
}
|
|
|
|
|