2015-01-30 01:30:26 +00:00
/*
2016-02-04 21:15:29 +00:00
* * thingdef_codeptr . cpp
2015-01-30 01:30:26 +00:00
* *
* * Code pointers for Actor definitions
* *
* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* * Copyright 2002 - 2006 Christoph Oelckers
* * Copyright 2004 - 2006 Randy Heit
* * All rights reserved .
* *
* * Redistribution and use in source and binary forms , with or without
* * modification , are permitted provided that the following conditions
* * are met :
* *
* * 1. Redistributions of source code must retain the above copyright
* * notice , this list of conditions and the following disclaimer .
* * 2. Redistributions in binary form must reproduce the above copyright
* * notice , this list of conditions and the following disclaimer in the
* * documentation and / or other materials provided with the distribution .
* * 3. The name of the author may not be used to endorse or promote products
* * derived from this software without specific prior written permission .
* * 4. When not used as part of ZDoom or a ZDoom derivative , this code will be
* * covered by 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 SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* * IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* * INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* * NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* * DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* * THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* * THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* *
*/
# include "gi.h"
# include "g_level.h"
# include "actor.h"
# include "info.h"
# include "sc_man.h"
# include "tarray.h"
# include "w_wad.h"
# include "templates.h"
# include "r_defs.h"
# include "a_pickups.h"
# include "s_sound.h"
# include "cmdlib.h"
# include "p_lnspec.h"
2015-12-08 09:58:24 +00:00
# include "p_effect.h"
2015-01-30 01:30:26 +00:00
# include "p_enemy.h"
# include "decallib.h"
# include "m_random.h"
# include "i_system.h"
# include "p_local.h"
# include "c_console.h"
# include "doomerrors.h"
# include "a_sharedglobal.h"
# include "v_video.h"
# include "v_font.h"
# include "doomstat.h"
# include "v_palette.h"
# include "g_shared/a_specialspot.h"
# include "actorptrselect.h"
# include "m_bbox.h"
# include "r_data/r_translate.h"
# include "p_trace.h"
2015-04-15 18:10:27 +00:00
# include "p_setup.h"
2015-01-30 01:30:26 +00:00
# include "gstrings.h"
2016-02-15 01:14:34 +00:00
# include "d_player.h"
# include "p_maputl.h"
# include "p_spec.h"
2016-09-04 08:22:59 +00:00
# include "templates.h"
2016-11-13 11:02:41 +00:00
# include "v_text.h"
2016-10-12 17:22:33 +00:00
# include "thingdef.h"
2016-03-11 14:45:47 +00:00
# include "math/cmath.h"
2017-01-08 17:45:30 +00:00
# include "g_levellocals.h"
2017-02-05 17:07:12 +00:00
# include "r_utility.h"
2017-02-26 17:46:06 +00:00
# include "sbar.h"
2017-03-10 08:57:10 +00:00
# include "actorinlines.h"
2017-04-12 23:12:04 +00:00
# include "vm.h"
# include "types.h"
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
AActor * SingleActorFromTID ( int tid , AActor * defactor ) ;
2015-01-30 01:30:26 +00:00
static FRandom pr_camissile ( " CustomActorfire " ) ;
static FRandom pr_cabullet ( " CustomBullet " ) ;
static FRandom pr_cajump ( " CustomJump " ) ;
static FRandom pr_cwbullet ( " CustomWpBullet " ) ;
static FRandom pr_cwjump ( " CustomWpJump " ) ;
static FRandom pr_cwpunch ( " CustomWpPunch " ) ;
static FRandom pr_grenade ( " ThrowGrenade " ) ;
static FRandom pr_crailgun ( " CustomRailgun " ) ;
static FRandom pr_spawndebris ( " SpawnDebris " ) ;
static FRandom pr_spawnitemex ( " SpawnItemEx " ) ;
static FRandom pr_burst ( " Burst " ) ;
static FRandom pr_monsterrefire ( " MonsterRefire " ) ;
static FRandom pr_teleport ( " A_Teleport " ) ;
2016-06-14 00:38:00 +00:00
static FRandom pr_bfgselfdamage ( " BFGSelfDamage " ) ;
2015-01-30 01:30:26 +00:00
//==========================================================================
//
// ACustomInventory :: CallStateChain
//
// Executes the code pointers in a chain of states
// until there is no next state
//
//==========================================================================
2017-01-19 19:56:31 +00:00
bool AStateProvider : : CallStateChain ( AActor * actor , FState * state )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
INTBOOL result = false ;
2015-01-30 01:30:26 +00:00
int counter = 0 ;
2016-02-04 21:15:29 +00:00
VMValue params [ 3 ] = { actor , this , 0 } ;
2016-02-19 04:05:10 +00:00
// We accept return types of `state`, `(int|bool)` or `state, (int|bool)`.
// The last one is for the benefit of A_Warp and A_Teleport.
int retval , numret ;
FState * nextstate ;
VMReturn ret [ 2 ] ;
ret [ 0 ] . PointerAt ( ( void * * ) & nextstate ) ;
ret [ 1 ] . IntAt ( & retval ) ;
2016-02-04 21:15:29 +00:00
FState * savedstate = this - > state ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
while ( state ! = NULL )
2015-01-30 01:30:26 +00:00
{
2016-11-14 23:18:57 +00:00
if ( ! ( state - > UseFlags & SUF_ITEM ) )
{
2017-04-13 07:17:11 +00:00
Printf ( TEXTCOLOR_RED " State %s not flagged for use in CustomInventory state chains. \n " , FState : : StaticGetStateName ( state ) . GetChars ( ) ) ;
2016-11-14 23:18:57 +00:00
return false ;
}
2016-02-04 21:15:29 +00:00
this - > state = state ;
2016-02-19 04:05:10 +00:00
nextstate = NULL ; // assume no jump
2016-02-04 21:15:29 +00:00
if ( state - > ActionFunc ! = NULL )
2015-01-30 01:30:26 +00:00
{
2016-11-13 11:02:41 +00:00
if ( state - > ActionFunc - > Unsafe )
{
// If an unsafe function (i.e. one that accesses user variables) is being detected, print a warning once and remove the bogus function. We may not call it because that would inevitably crash.
auto owner = FState : : StaticFindStateOwner ( state ) ;
2017-04-11 19:48:41 +00:00
Printf ( TEXTCOLOR_RED " Unsafe state call in state %s to %s which accesses user variables. The action function has been removed from this state \n " ,
2017-04-13 07:17:11 +00:00
FState : : StaticGetStateName ( state ) . GetChars ( ) , state - > ActionFunc - > PrintableName . GetChars ( ) ) ;
2016-11-13 11:02:41 +00:00
state - > ActionFunc = nullptr ;
}
2016-02-19 04:05:10 +00:00
PPrototype * proto = state - > ActionFunc - > Proto ;
VMReturn * wantret ;
2016-06-16 14:11:00 +00:00
FStateParamInfo stp = { state , STATE_StateChain , PSP_WEAPON } ;
2015-01-30 01:30:26 +00:00
2017-04-10 14:06:18 +00:00
params [ 2 ] = VMValue ( & stp ) ;
2016-02-19 04:05:10 +00:00
retval = true ; // assume success
wantret = NULL ; // assume no return value wanted
numret = 0 ;
// For functions that return nothing (or return some type
// we don't care about), we pretend they return true,
// thanks to the values set just above.
2017-01-20 11:39:51 +00:00
if ( proto - > ReturnTypes . Size ( ) > = 2 & &
proto - > ReturnTypes [ 0 ] = = TypeState & &
( proto - > ReturnTypes [ 1 ] = = TypeSInt32 | | proto - > ReturnTypes [ 0 ] = = TypeUInt32 | | proto - > ReturnTypes [ 1 ] = = TypeBool ) )
{ // Function returns a state and an int or bool
wantret = & ret [ 0 ] ;
numret = 2 ;
2016-02-19 04:05:10 +00:00
}
2017-01-20 11:39:51 +00:00
else if ( proto - > ReturnTypes . Size ( ) = = 1 & & proto - > ReturnTypes [ 0 ] = = TypeState )
{ // Function returns a state
wantret = & ret [ 0 ] ;
retval = false ; // this is a jump function which never affects the success state.
2017-01-22 00:28:37 +00:00
numret = 1 ;
2017-01-20 11:39:51 +00:00
}
else if ( proto - > ReturnTypes . Size ( ) > = 1 & &
( proto - > ReturnTypes [ 0 ] = = TypeSInt32 | | proto - > ReturnTypes [ 0 ] = = TypeUInt32 | | proto - > ReturnTypes [ 0 ] = = TypeBool ) )
{ // Function returns an int or bool
wantret = & ret [ 1 ] ;
numret = 1 ;
2016-02-19 04:05:10 +00:00
}
2016-12-03 11:23:13 +00:00
try
{
2017-04-12 23:12:04 +00:00
VMCall ( state - > ActionFunc , params , state - > ActionFunc - > ImplicitArgs , wantret , numret ) ;
2016-12-03 11:23:13 +00:00
}
catch ( CVMAbortException & err )
{
err . MaybePrintMessage ( ) ;
2017-04-13 07:17:11 +00:00
err . stacktrace . AppendFormat ( " Called from state %s in inventory state chain in %s \n " , FState : : StaticGetStateName ( state ) . GetChars ( ) , GetClass ( ) - > TypeName . GetChars ( ) ) ;
2016-12-03 11:23:13 +00:00
throw ;
}
2016-02-04 21:15:29 +00:00
// As long as even one state succeeds, the whole chain succeeds unless aborted below.
2016-02-19 04:05:10 +00:00
// A state that wants to jump does not count as "succeeded".
2016-02-20 04:09:35 +00:00
if ( nextstate = = NULL )
2016-02-19 04:05:10 +00:00
{
result | = retval ;
}
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
// Since there are no delays it is a good idea to check for infinite loops here!
counter + + ;
if ( counter > = 10000 ) break ;
2016-02-19 04:05:10 +00:00
if ( nextstate = = NULL )
2015-01-30 01:30:26 +00:00
{
2016-02-19 04:05:10 +00:00
nextstate = state - > GetNextState ( ) ;
2016-02-04 21:15:29 +00:00
2016-02-19 04:05:10 +00:00
if ( state = = nextstate )
2016-02-04 21:15:29 +00:00
{ // Abort immediately if the state jumps to itself!
result = false ;
break ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-19 04:05:10 +00:00
state = nextstate ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
this - > state = savedstate ;
return ! ! result ;
}
2017-01-19 19:56:31 +00:00
DEFINE_ACTION_FUNCTION ( ACustomInventory , CallStateChain )
2017-01-19 18:14:22 +00:00
{
2017-01-19 19:56:31 +00:00
PARAM_SELF_PROLOGUE ( AStateProvider ) ;
2017-01-19 18:14:22 +00:00
PARAM_OBJECT ( affectee , AActor ) ;
2017-01-20 18:55:57 +00:00
PARAM_POINTER ( state , FState ) ;
2017-01-19 18:14:22 +00:00
ACTION_RETURN_BOOL ( self - > CallStateChain ( affectee , state ) ) ;
}
2016-10-27 13:53:53 +00:00
//==========================================================================
//
// GetPointer
//
// resolve AAPTR_*
//
//==========================================================================
DEFINE_ACTION_FUNCTION ( AActor , GetPointer )
{
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_INT ( ptr ) ;
ACTION_RETURN_OBJECT ( COPY_AAPTR ( self , ptr ) ) ;
}
2016-02-04 21:15:29 +00:00
//==========================================================================
//
// CheckClass
//
// NON-ACTION function to check a pointer's class.
//
//==========================================================================
DEFINE_ACTION_FUNCTION ( AActor , CheckClass )
{
if ( numret > 0 )
{
assert ( ret ! = NULL ) ;
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( checktype , AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( pick_pointer ) ;
PARAM_BOOL_DEF ( match_superclass ) ;
2016-02-04 21:15:29 +00:00
self = COPY_AAPTR ( self , pick_pointer ) ;
2016-12-02 11:06:49 +00:00
if ( self = = nullptr | | checktype = = nullptr )
2016-02-04 21:15:29 +00:00
{
ret - > SetInt ( false ) ;
}
else if ( match_superclass )
{
ret - > SetInt ( self - > IsKindOf ( checktype ) ) ;
}
else
{
ret - > SetInt ( self - > GetClass ( ) = = checktype ) ;
}
return 1 ;
}
return 0 ;
}
2016-09-19 01:45:22 +00:00
//==========================================================================
//
// CheckClass
//
// NON-ACTION function to calculate missile damage for the given actor
//
//==========================================================================
DEFINE_ACTION_FUNCTION ( AActor , GetMissileDamage )
{
if ( numret > 0 )
{
assert ( ret ! = NULL ) ;
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_INT ( mask ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT ( add ) ;
PARAM_INT_DEF ( pick_pointer ) ;
2016-09-19 01:45:22 +00:00
self = COPY_AAPTR ( self , pick_pointer ) ;
if ( self = = NULL )
{
ret - > SetInt ( 0 ) ;
}
else
{
ret - > SetInt ( self - > GetMissileDamage ( mask , add ) ) ;
}
return 1 ;
}
return 0 ;
}
2016-02-05 03:45:31 +00:00
//==========================================================================
//
// CountInv
//
// NON-ACTION function to return the inventory count of an item.
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CountInv )
2016-02-05 03:45:31 +00:00
{
if ( numret > 0 )
{
assert ( ret ! = NULL ) ;
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-05 03:45:31 +00:00
PARAM_CLASS ( itemtype , AInventory ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( pick_pointer ) ;
2016-02-05 03:45:31 +00:00
self = COPY_AAPTR ( self , pick_pointer ) ;
if ( self = = NULL | | itemtype = = NULL )
{
2016-02-09 04:21:42 +00:00
ret - > SetInt ( 0 ) ;
2016-02-05 03:45:31 +00:00
}
else
{
AInventory * item = self - > FindInventory ( itemtype ) ;
ret - > SetInt ( item ? item - > Amount : 0 ) ;
}
2016-02-09 04:21:42 +00:00
return 1 ;
2016-02-05 03:45:31 +00:00
}
return 0 ;
}
2016-02-10 23:13:50 +00:00
//==========================================================================
//
// GetDistance
//
// NON-ACTION function to get the distance in double.
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , GetDistance )
2016-02-10 23:13:50 +00:00
{
if ( numret > 0 )
{
assert ( ret ! = NULL ) ;
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-10 23:13:50 +00:00
PARAM_BOOL ( checkz ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr ) ;
2016-02-10 23:13:50 +00:00
AActor * target = COPY_AAPTR ( self , ptr ) ;
if ( ! target | | target = = self )
{
2016-02-11 00:04:59 +00:00
ret - > SetFloat ( 0 ) ;
2016-02-10 23:13:50 +00:00
}
else
{
2016-03-24 23:59:14 +00:00
DVector3 diff = self - > Vec3To ( target ) ;
2016-02-11 00:04:59 +00:00
if ( checkz )
2016-03-24 23:59:14 +00:00
diff . Z + = ( target - > Height - self - > Height ) / 2 ;
2016-06-20 21:39:33 +00:00
else
diff . Z = 0. ;
2016-02-11 00:04:59 +00:00
2016-03-24 23:59:14 +00:00
ret - > SetFloat ( diff . Length ( ) ) ;
2016-02-10 23:13:50 +00:00
}
return 1 ;
}
return 0 ;
}
2016-04-27 09:52:52 +00:00
//==========================================================================
//
// GetAngle
//
// NON-ACTION function to get the angle in degrees (normalized to -180..180)
//
//==========================================================================
2016-06-24 18:19:49 +00:00
enum GAFlags
{
GAF_RELATIVE = 1 ,
GAF_SWITCH = 1 < < 1 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , GetAngle )
2016-04-27 09:52:52 +00:00
{
if ( numret > 0 )
{
assert ( ret ! = NULL ) ;
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-06-24 18:19:49 +00:00
PARAM_INT ( flags ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr )
2016-04-27 09:52:52 +00:00
AActor * target = COPY_AAPTR ( self , ptr ) ;
if ( ! target | | target = = self )
{
ret - > SetFloat ( 0 ) ;
}
else
{
2016-06-24 18:19:49 +00:00
DVector3 diff = ( flags & GAF_SWITCH ) ? target - > Vec3To ( self ) : self - > Vec3To ( target ) ;
2016-04-27 09:52:52 +00:00
DAngle angto = diff . Angle ( ) ;
2016-06-24 18:19:49 +00:00
DAngle yaw = ( flags & GAF_SWITCH ) ? target - > Angles . Yaw : self - > Angles . Yaw ;
if ( flags & GAF_RELATIVE ) angto = deltaangle ( yaw , angto ) ;
2016-04-27 09:52:52 +00:00
ret - > SetFloat ( angto . Degrees ) ;
}
return 1 ;
}
return 0 ;
}
2016-02-25 16:08:08 +00:00
//==========================================================================
//
// GetSpawnHealth
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , GetSpawnHealth )
2016-02-25 16:08:08 +00:00
{
if ( numret > 0 )
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-25 16:08:08 +00:00
ret - > SetInt ( self - > SpawnHealth ( ) ) ;
return 1 ;
}
return 0 ;
}
2016-07-28 20:52:20 +00:00
//==========================================================================
//
// GetSpriteAngle
//
// NON-ACTION function returns the sprite angle of a pointer.
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , GetSpriteAngle )
2016-07-28 20:52:20 +00:00
{
if ( numret > 0 )
{
assert ( ret ! = NULL ) ;
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr ) ;
2016-07-28 20:52:20 +00:00
AActor * target = COPY_AAPTR ( self , ptr ) ;
if ( target = = nullptr )
{
ret - > SetFloat ( 0.0 ) ;
}
else
{
const double ang = target - > SpriteAngle . Degrees ;
ret - > SetFloat ( ang ) ;
}
return 1 ;
}
return 0 ;
}
//==========================================================================
//
// GetSpriteRotation
//
// NON-ACTION function returns the sprite rotation of a pointer.
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , GetSpriteRotation )
2016-07-28 20:52:20 +00:00
{
if ( numret > 0 )
{
assert ( ret ! = NULL ) ;
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr ) ;
2016-07-28 20:52:20 +00:00
AActor * target = COPY_AAPTR ( self , ptr ) ;
if ( target = = nullptr )
{
ret - > SetFloat ( 0.0 ) ;
}
else
{
const double ang = target - > SpriteRotation . Degrees ;
ret - > SetFloat ( ang ) ;
}
return 1 ;
}
return 0 ;
}
2016-05-05 23:33:36 +00:00
//==========================================================================
//
// GetZAt
//
// NON-ACTION function to get the floor or ceiling z at (x, y) with
// relativity being an option.
//==========================================================================
enum GZFlags
{
2016-05-12 18:23:10 +00:00
GZF_ABSOLUTEPOS = 1 , // Use the absolute position instead of an offsetted one.
GZF_ABSOLUTEANG = 1 < < 1 , // Don't add the actor's angle to the parameter.
GZF_CEILING = 1 < < 2 , // Check the ceiling instead of the floor.
GZF_3DRESTRICT = 1 < < 3 , // Ignore midtextures and 3D floors above the pointer's z.
GZF_NOPORTALS = 1 < < 4 , // Don't pass through any portals.
GZF_NO3DFLOOR = 1 < < 5 , // Pass all 3D floors.
2016-05-05 23:33:36 +00:00
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , GetZAt )
2016-05-05 23:33:36 +00:00
{
if ( numret > 0 )
{
assert ( ret ! = NULL ) ;
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( px ) ;
PARAM_FLOAT_DEF ( py ) ;
PARAM_ANGLE_DEF ( angle ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_INT_DEF ( pick_pointer ) ;
2016-05-05 23:33:36 +00:00
AActor * mobj = COPY_AAPTR ( self , pick_pointer ) ;
if ( mobj = = nullptr )
{
ret - > SetFloat ( 0 ) ;
}
else
{
2016-05-12 18:23:10 +00:00
// [MC] At any time, the NextLowest/Highest functions could be changed to include
// more FFC flags to check. Don't risk it by just passing flags straight to it.
2016-05-05 23:33:36 +00:00
DVector2 pos = { px , py } ;
double z = 0. ;
2016-05-12 18:23:10 +00:00
int pflags = ( flags & GZF_3DRESTRICT ) ? FFCF_3DRESTRICT : 0 ;
if ( flags & GZF_NOPORTALS ) pflags | = FFCF_NOPORTALS ;
2016-05-05 23:33:36 +00:00
if ( ! ( flags & GZF_ABSOLUTEPOS ) )
{
if ( ! ( flags & GZF_ABSOLUTEANG ) )
{
angle + = mobj - > Angles . Yaw ;
}
double s = angle . Sin ( ) ;
double c = angle . Cos ( ) ;
pos = mobj - > Vec2Offset ( pos . X * c + pos . Y * s , pos . X * s - pos . Y * c ) ;
}
2016-05-12 19:47:00 +00:00
sector_t * sec = P_PointInSector ( pos ) ;
2016-05-05 23:33:36 +00:00
2016-05-12 19:47:00 +00:00
if ( sec )
2016-05-05 23:33:36 +00:00
{
if ( flags & GZF_CEILING )
{
2016-05-12 18:23:10 +00:00
if ( ( flags & GZF_NO3DFLOOR ) & & ( flags & GZF_NOPORTALS ) )
{
2016-05-12 19:47:00 +00:00
z = sec - > ceilingplane . ZatPoint ( pos ) ;
2016-05-12 18:23:10 +00:00
}
else if ( flags & GZF_NO3DFLOOR )
{
2016-05-12 19:47:00 +00:00
z = sec - > HighestCeilingAt ( pos ) ;
2016-05-12 18:23:10 +00:00
}
else
{ // [MC] Handle strict 3D floors and portal toggling via the flags passed to it.
2016-05-12 19:47:00 +00:00
z = sec - > NextHighestCeilingAt ( pos . X , pos . Y , mobj - > Z ( ) , mobj - > Top ( ) , pflags ) ;
2016-05-12 18:23:10 +00:00
}
2016-05-05 23:33:36 +00:00
}
else
{
2016-05-12 18:23:10 +00:00
if ( ( flags & GZF_NO3DFLOOR ) & & ( flags & GZF_NOPORTALS ) )
{
2016-05-12 19:47:00 +00:00
z = sec - > floorplane . ZatPoint ( pos ) ;
2016-05-12 18:23:10 +00:00
}
else if ( flags & GZF_NO3DFLOOR )
{
2016-05-12 19:47:00 +00:00
z = sec - > LowestFloorAt ( pos ) ;
2016-05-12 18:23:10 +00:00
}
else
{
2016-05-12 19:47:00 +00:00
z = sec - > NextLowestFloorAt ( pos . X , pos . Y , mobj - > Z ( ) , pflags , mobj - > MaxStepHeight ) ;
2016-05-12 18:23:10 +00:00
}
2016-05-05 23:33:36 +00:00
}
}
ret - > SetFloat ( z ) ;
return 1 ;
}
}
return 0 ;
}
2016-05-28 16:26:04 +00:00
//==========================================================================
//
// GetCrouchFactor
//
// NON-ACTION function to retrieve a player's crouching factor.
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , GetCrouchFactor )
2016-05-28 16:26:04 +00:00
{
if ( numret > 0 )
{
assert ( ret ! = NULL ) ;
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr ) ;
2016-05-28 16:26:04 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
if ( ! mobj | | ! mobj - > player )
{
2016-05-29 10:48:27 +00:00
ret - > SetFloat ( 1 ) ;
2016-05-28 16:26:04 +00:00
}
else
{
ret - > SetFloat ( mobj - > player - > crouchfactor ) ;
}
return 1 ;
}
return 0 ;
}
2016-06-05 17:52:53 +00:00
//==========================================================================
//
// GetCVar
//
// NON-ACTION function that works like ACS's GetCVar.
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , GetCVar )
2016-06-05 17:52:53 +00:00
{
if ( numret > 0 )
{
assert ( ret ! = nullptr ) ;
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_STRING ( cvarname ) ;
FBaseCVar * cvar = GetCVar ( self , cvarname ) ;
if ( cvar = = nullptr )
{
ret - > SetFloat ( 0 ) ;
}
else
{
ret - > SetFloat ( cvar - > GetGenericRep ( CVAR_Float ) . Float ) ;
}
return 1 ;
}
return 0 ;
}
2017-03-28 19:36:57 +00:00
//==========================================================================
//
// GetCVar
//
// NON-ACTION function that works like ACS's GetCVar.
//
//==========================================================================
DEFINE_ACTION_FUNCTION ( AActor , GetCVarString )
{
if ( numret > 0 )
{
assert ( ret ! = nullptr ) ;
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_STRING ( cvarname ) ;
FBaseCVar * cvar = GetCVar ( self , cvarname ) ;
if ( cvar = = nullptr )
{
ret - > SetString ( " " ) ;
}
else
{
ret - > SetString ( cvar - > GetGenericRep ( CVAR_String ) . String ) ;
}
return 1 ;
}
return 0 ;
}
2016-06-20 13:49:57 +00:00
//==========================================================================
//
// GetPlayerInput
//
// NON-ACTION function that works like ACS's GetPlayerInput.
// Takes a pointer as anyone may or may not be a player.
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , GetPlayerInput )
2016-06-20 13:49:57 +00:00
{
if ( numret > 0 )
{
assert ( ret ! = nullptr ) ;
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_INT ( inputnum ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr ) ;
2016-06-20 13:49:57 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
//Need a player.
if ( ! mobj | | ! mobj - > player )
{
ret - > SetInt ( 0 ) ;
}
else
{
2016-06-20 14:41:46 +00:00
ret - > SetInt ( P_Thing_CheckInputNum ( mobj - > player , inputnum ) ) ;
2016-06-20 13:49:57 +00:00
}
return 1 ;
}
return 0 ;
}
2016-07-29 17:50:15 +00:00
//==========================================================================
//
2016-07-29 18:07:26 +00:00
// CountProximity
2016-07-29 17:50:15 +00:00
//
// NON-ACTION function of A_CheckProximity that returns how much it counts.
// Takes a pointer as anyone may or may not be a player.
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CountProximity )
2016-07-29 17:50:15 +00:00
{
if ( numret > 0 )
{
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_CLASS ( classname , AActor ) ;
PARAM_FLOAT ( distance ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
PARAM_INT_DEF ( ptr ) ;
2016-07-29 17:50:15 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
if ( mobj = = nullptr )
{
ret - > SetInt ( 0 ) ;
}
else
{
ret - > SetInt ( P_Thing_CheckProximity ( self , classname , distance , 0 , flags , ptr , true ) ) ;
}
return 1 ;
}
return 0 ;
}
2016-02-19 06:29:19 +00:00
//===========================================================================
//
2016-03-01 17:36:15 +00:00
// __decorate_internal_int__
// __decorate_internal_bool__
// __decorate_internal_float__
2016-02-19 06:29:19 +00:00
//
2016-03-01 17:36:15 +00:00
// Placeholders for forcing DECORATE to cast numbers. If actually called,
// returns whatever was passed.
2016-02-19 06:29:19 +00:00
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , __decorate_internal_int__ )
2016-02-19 06:29:19 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-19 06:29:19 +00:00
PARAM_INT ( returnme ) ;
ACTION_RETURN_INT ( returnme ) ;
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , __decorate_internal_bool__ )
2016-02-19 06:29:19 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-19 06:29:19 +00:00
PARAM_BOOL ( returnme ) ;
ACTION_RETURN_BOOL ( returnme ) ;
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , __decorate_internal_float__ )
2016-03-01 17:36:15 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-03-01 17:36:15 +00:00
PARAM_FLOAT ( returnme ) ;
if ( numret > 0 )
{
ret - > SetFloat ( returnme ) ;
return 1 ;
}
return 0 ;
}
2015-01-30 01:30:26 +00:00
//==========================================================================
//
// A_RearrangePointers
//
// Allow an actor to change its relationship to other actors by
// copying pointers freely between TARGET MASTER and TRACER.
// Can also assign null value, but does not duplicate A_ClearTarget.
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RearrangePointers )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( ptr_target ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr_master ) ;
PARAM_INT_DEF ( ptr_tracer ) ;
PARAM_INT_DEF ( flags ) ;
2015-01-30 01:30:26 +00:00
// Rearrange pointers internally
// Fetch all values before modification, so that all fields can get original values
AActor
* gettarget = self - > target ,
* getmaster = self - > master ,
* gettracer = self - > tracer ;
switch ( ptr_target ) // pick the new target
{
case AAPTR_MASTER :
self - > target = getmaster ;
if ( ! ( PTROP_UNSAFETARGET & flags ) ) VerifyTargetChain ( self ) ;
break ;
case AAPTR_TRACER :
self - > target = gettracer ;
if ( ! ( PTROP_UNSAFETARGET & flags ) ) VerifyTargetChain ( self ) ;
break ;
case AAPTR_NULL :
self - > target = NULL ;
// THIS IS NOT "A_ClearTarget", so no other targeting info is removed
break ;
}
// presently permitting non-monsters to set master
switch ( ptr_master ) // pick the new master
{
case AAPTR_TARGET :
self - > master = gettarget ;
if ( ! ( PTROP_UNSAFEMASTER & flags ) ) VerifyMasterChain ( self ) ;
break ;
case AAPTR_TRACER :
self - > master = gettracer ;
if ( ! ( PTROP_UNSAFEMASTER & flags ) ) VerifyMasterChain ( self ) ;
break ;
case AAPTR_NULL :
self - > master = NULL ;
break ;
}
switch ( ptr_tracer ) // pick the new tracer
{
case AAPTR_TARGET :
self - > tracer = gettarget ;
break ; // no verification deemed necessary; the engine never follows a tracer chain(?)
case AAPTR_MASTER :
self - > tracer = getmaster ;
break ; // no verification deemed necessary; the engine never follows a tracer chain(?)
case AAPTR_NULL :
self - > tracer = NULL ;
break ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_TransferPointer
//
// Copy one pointer (MASTER, TARGET or TRACER) from this actor (SELF),
// or from this actor's MASTER, TARGET or TRACER.
//
// You can copy any one of that actor's pointers
//
// Assign the copied pointer to any one pointer in SELF,
// MASTER, TARGET or TRACER.
//
// Any attempt to make an actor point to itself will replace the pointer
// with a null value.
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_TransferPointer )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( ptr_source ) ;
PARAM_INT ( ptr_recipient ) ;
PARAM_INT ( ptr_sourcefield ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr_recipientfield ) ;
PARAM_INT_DEF ( flags ) ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
AActor * source , * recipient ;
2015-01-30 01:30:26 +00:00
// Exchange pointers with actors to whom you have pointers (or with yourself, if you must)
source = COPY_AAPTR ( self , ptr_source ) ;
2016-02-04 21:15:29 +00:00
recipient = COPY_AAPTR ( self , ptr_recipient ) ; // pick an actor to store the provided pointer value
if ( recipient = = NULL )
{
return 0 ;
}
2015-01-30 01:30:26 +00:00
// convert source from dataprovider to data
source = COPY_AAPTR ( source , ptr_sourcefield ) ;
2016-02-04 21:15:29 +00:00
if ( source = = recipient )
{ // The recepient should not acquire a pointer to itself; will write NULL}
source = NULL ;
}
if ( ptr_recipientfield = = AAPTR_DEFAULT )
{ // If default: Write to same field as data was read from
ptr_recipientfield = ptr_sourcefield ;
}
2016-01-19 15:09:44 +00:00
ASSIGN_AAPTR ( recipient , ptr_recipientfield , source , flags ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_CopyFriendliness
//
// Join forces with one of the actors you are pointing to (MASTER by default)
//
// Normal CopyFriendliness reassigns health. This function will not.
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_CopyFriendliness )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr_source ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( self - > player ! = NULL )
{
return 0 ;
}
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
AActor * source = COPY_AAPTR ( self , ptr_source ) ;
if ( source ! = NULL )
{ // No change in current target or health
self - > CopyFriendliness ( source , false , false ) ;
}
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// Custom sound functions.
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_PlaySound )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_SOUND_DEF ( soundid ) ;
PARAM_INT_DEF ( channel ) ;
PARAM_FLOAT_DEF ( volume ) ;
PARAM_BOOL_DEF ( looping ) ;
PARAM_FLOAT_DEF ( attenuation ) ;
2016-11-02 13:15:09 +00:00
PARAM_BOOL_DEF ( local ) ;
2015-01-30 01:30:26 +00:00
if ( ! looping )
{
2017-02-14 21:51:53 +00:00
if ( ! ( channel & CHAN_NOSTOP ) | | ! S_IsActorPlayingSomething ( self , channel & 7 , soundid ) )
{
S_PlaySound ( self , channel , soundid , ( float ) volume , ( float ) attenuation , local ) ;
}
2015-01-30 01:30:26 +00:00
}
else
{
if ( ! S_IsActorPlayingSomething ( self , channel & 7 , soundid ) )
{
2016-10-15 18:50:21 +00:00
S_PlaySound ( self , channel | CHAN_LOOP , soundid , ( float ) volume , ( float ) attenuation , local ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_StopSound )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( slot ) ;
2015-01-30 01:30:26 +00:00
S_StopSound ( self , slot ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2017-08-31 06:45:09 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SoundVolume )
{
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_INT ( channel ) ;
PARAM_FLOAT ( volume ) ;
S_ChangeSoundVolume ( self , channel , static_cast < float > ( volume ) ) ;
return 0 ;
}
2018-01-06 23:42:37 +00:00
2015-01-30 01:30:26 +00:00
//==========================================================================
//
// These come from a time when DECORATE constants did not exist yet and
// the sound interface was less flexible. As a result the parameters are
// not optimal and these functions have been deprecated in favor of extending
// A_PlaySound and A_StopSound.
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_PlaySoundEx )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_SOUND ( soundid ) ;
PARAM_NAME ( channel ) ;
2016-10-27 13:53:53 +00:00
PARAM_BOOL_DEF ( looping ) ;
PARAM_INT_DEF ( attenuation_raw ) ;
2015-01-30 01:30:26 +00:00
float attenuation ;
switch ( attenuation_raw )
{
case - 1 : attenuation = ATTN_STATIC ; break ; // drop off rapidly
default :
case 0 : attenuation = ATTN_NORM ; break ; // normal
case 1 :
case 2 : attenuation = ATTN_NONE ; break ; // full volume
}
if ( channel < NAME_Auto | | channel > NAME_SoundSlot7 )
{
channel = NAME_Auto ;
}
if ( ! looping )
{
S_Sound ( self , int ( channel ) - NAME_Auto , soundid , 1 , attenuation ) ;
}
else
{
if ( ! S_IsActorPlayingSomething ( self , int ( channel ) - NAME_Auto , soundid ) )
{
S_Sound ( self , ( int ( channel ) - NAME_Auto ) | CHAN_LOOP , soundid , 1 , attenuation ) ;
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_StopSoundEx )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_NAME ( channel ) ;
2015-01-30 01:30:26 +00:00
if ( channel > NAME_Auto & & channel < = NAME_SoundSlot7 )
{
S_StopSound ( self , int ( channel ) - NAME_Auto ) ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// Generic seeker missile function
//
//==========================================================================
static FRandom pr_seekermissile ( " SeekerMissile " ) ;
enum
{
SMF_LOOK = 1 ,
SMF_PRECISE = 2 ,
SMF_CURSPEED = 4 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SeekerMissile )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( ang1 ) ;
PARAM_INT ( ang2 ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
PARAM_INT_DEF ( chance ) ;
PARAM_INT_DEF ( distance ) ;
2015-01-30 01:30:26 +00:00
2017-02-25 15:56:49 +00:00
if ( ( flags & SMF_LOOK ) & & ( self - > tracer = = nullptr ) & & ( pr_seekermissile ( ) < chance ) )
2015-01-30 01:30:26 +00:00
{
self - > tracer = P_RoughMonsterSearch ( self , distance , true ) ;
}
2016-03-21 21:20:10 +00:00
if ( ! P_SeekerMissile ( self , clamp < int > ( ang1 , 0 , 90 ) , clamp < int > ( ang2 , 0 , 90 ) , ! ! ( flags & SMF_PRECISE ) , ! ! ( flags & SMF_CURSPEED ) ) )
2015-01-30 01:30:26 +00:00
{
if ( flags & SMF_LOOK )
{ // This monster is no longer seekable, so let us look for another one next time.
self - > tracer = NULL ;
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// Hitscan attack with a customizable amount of bullets (specified in damage)
//
//==========================================================================
DEFINE_ACTION_FUNCTION ( AActor , A_BulletAttack )
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
int i ;
2016-02-04 21:15:29 +00:00
if ( ! self - > target ) return 0 ;
2015-01-30 01:30:26 +00:00
A_FaceTarget ( self ) ;
2016-03-17 10:38:56 +00:00
DAngle slope = P_AimLineAttack ( self , self - > Angles . Yaw , MISSILERANGE ) ;
2015-01-30 01:30:26 +00:00
S_Sound ( self , CHAN_WEAPON , self - > AttackSound , 1 , ATTN_NORM ) ;
for ( i = self - > GetMissileDamage ( 0 , 1 ) ; i > 0 ; - - i )
{
2016-03-17 10:38:56 +00:00
DAngle angle = self - > Angles . Yaw + pr_cabullet . Random2 ( ) * ( 5.625 / 256. ) ;
2015-01-30 01:30:26 +00:00
int damage = ( ( pr_cabullet ( ) % 5 ) + 1 ) * 3 ;
P_LineAttack ( self , angle , MISSILERANGE , slope , damage ,
NAME_Hitscan , NAME_BulletPuff ) ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// State jump function
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Jump )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
PARAM_ACTION_PROLOGUE ( AActor ) ;
2016-10-29 11:10:27 +00:00
PARAM_INT ( maxchance ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
paramnum + + ; // Increment paramnum to point at the first jump target
int count = numparam - paramnum ;
if ( count > 0 & & ( maxchance > = 256 | | pr_cajump ( ) < maxchance ) )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
int jumpnum = ( count = = 1 ? 0 : ( pr_cajump ( ) % count ) ) ;
2016-11-14 13:12:27 +00:00
PARAM_STATE_ACTION_AT ( paramnum + jumpnum , jumpto ) ;
2016-02-19 02:39:40 +00:00
ACTION_RETURN_STATE ( jumpto ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_STATE ( NULL ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// State jump function
//
//==========================================================================
2016-11-14 13:12:27 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckInventory )
2015-01-30 01:30:26 +00:00
{
2016-10-27 13:53:53 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-22 01:21:39 +00:00
PARAM_CLASS ( itemtype , AInventory ) ;
PARAM_INT ( itemamount ) ;
2016-11-14 13:12:27 +00:00
PARAM_INT_DEF ( setowner ) ;
2015-01-30 01:30:26 +00:00
2016-11-14 13:12:27 +00:00
if ( itemtype = = nullptr )
2016-02-04 21:15:29 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-04 21:15:29 +00:00
}
2016-11-14 13:12:27 +00:00
AActor * owner = COPY_AAPTR ( self , setowner ) ;
if ( owner = = nullptr )
2016-02-04 21:15:29 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
AInventory * item = owner - > FindInventory ( itemtype ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( item )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
if ( itemamount > 0 )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
if ( item - > Amount > = itemamount )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( true ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
else if ( item - > Amount > = item - > MaxAmount )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( true ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// Parameterized version of A_Explode
//
//==========================================================================
enum
{
2016-08-12 17:49:55 +00:00
XF_HURTSOURCE = 1 ,
XF_NOTMISSILE = 4 ,
XF_NOACTORTYPE = 1 < < 3 ,
2016-10-30 17:41:39 +00:00
XF_NOSPLASH = 16 ,
2015-01-30 01:30:26 +00:00
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Explode )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( damage ) ;
PARAM_INT_DEF ( distance ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_BOOL_DEF ( alert ) ;
PARAM_INT_DEF ( fulldmgdistance ) ;
PARAM_INT_DEF ( nails ) ;
PARAM_INT_DEF ( naildamage ) ;
PARAM_CLASS_DEF ( pufftype , AActor ) ;
PARAM_NAME_DEF ( damagetype ) ;
2015-01-30 01:30:26 +00:00
if ( damage < 0 ) // get parameters from metadata
{
2017-02-28 09:51:32 +00:00
damage = self - > IntVar ( NAME_ExplosionDamage ) ;
distance = self - > IntVar ( NAME_ExplosionRadius ) ;
flags = ! self - > BoolVar ( NAME_DontHurtShooter ) ;
2015-01-30 01:30:26 +00:00
alert = false ;
}
2016-02-04 21:15:29 +00:00
if ( distance < = 0 ) distance = damage ;
2015-01-30 01:30:26 +00:00
// NailBomb effect, from SMMU but not from its source code: instead it was implemented and
// generalized from the documentation at http://www.doomworld.com/eternity/engine/codeptrs.html
if ( nails )
{
2016-03-17 10:38:56 +00:00
DAngle ang ;
2015-01-30 01:30:26 +00:00
for ( int i = 0 ; i < nails ; i + + )
{
2016-03-17 10:38:56 +00:00
ang = i * 360. / nails ;
2015-01-30 01:30:26 +00:00
// Comparing the results of a test wad with Eternity, it seems A_NailBomb does not aim
2016-12-26 19:37:04 +00:00
P_LineAttack ( self , ang , MISSILERANGE , 0. ,
2015-01-30 01:30:26 +00:00
//P_AimLineAttack (self, ang, MISSILERANGE),
2016-12-26 19:37:04 +00:00
naildamage , NAME_Hitscan , pufftype , ( self - > flags & MF_MISSILE ) ? LAF_TARGETISSOURCE : 0 ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-08-12 17:49:55 +00:00
if ( ! ( flags & XF_NOACTORTYPE ) & & damagetype = = NAME_None )
{
damagetype = self - > DamageType ;
}
2016-09-07 16:24:04 +00:00
int pflags = 0 ;
if ( flags & XF_HURTSOURCE ) pflags | = RADF_HURTSOURCE ;
if ( flags & XF_NOTMISSILE ) pflags | = RADF_SOURCEISSPOT ;
int count = P_RadiusAttack ( self , self - > target , damage , distance , damagetype , pflags , fulldmgdistance ) ;
2016-10-30 17:41:39 +00:00
if ( ! ( flags & XF_NOSPLASH ) ) P_CheckSplash ( self , distance ) ;
2015-01-30 01:30:26 +00:00
if ( alert & & self - > target ! = NULL & & self - > target - > player ! = NULL )
{
2016-05-25 09:30:11 +00:00
P_NoiseAlert ( self - > target , self ) ;
2015-01-30 01:30:26 +00:00
}
2016-08-08 18:01:43 +00:00
ACTION_RETURN_INT ( count ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_RadiusThrust
//
//==========================================================================
enum
{
2016-05-11 11:59:11 +00:00
RTF_AFFECTSOURCE = 1 ,
RTF_NOIMPACTDAMAGE = 2 ,
RTF_NOTMISSILE = 4 ,
2015-01-30 01:30:26 +00:00
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RadiusThrust )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( force ) ;
PARAM_INT_DEF ( distance ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_INT_DEF ( fullthrustdistance ) ;
2015-01-30 01:30:26 +00:00
bool sourcenothrust = false ;
if ( force = = 0 ) force = 128 ;
if ( distance < = 0 ) distance = abs ( force ) ;
// Temporarily negate MF2_NODMGTHRUST on the shooter, since it renders this function useless.
if ( ! ( flags & RTF_NOTMISSILE ) & & self - > target ! = NULL & & self - > target - > flags2 & MF2_NODMGTHRUST )
{
sourcenothrust = true ;
self - > target - > flags2 & = ~ MF2_NODMGTHRUST ;
}
P_RadiusAttack ( self , self - > target , force , distance , self - > DamageType , flags | RADF_NODAMAGE , fullthrustdistance ) ;
2016-03-20 15:51:42 +00:00
P_CheckSplash ( self , distance ) ;
2015-01-30 01:30:26 +00:00
if ( sourcenothrust )
{
self - > target - > flags2 | = MF2_NODMGTHRUST ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2016-06-14 00:38:00 +00:00
//==========================================================================
//
// A_RadiusDamageSelf
//
//==========================================================================
enum
{
RDSF_BFGDAMAGE = 1 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RadiusDamageSelf )
2016-06-14 00:38:00 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( damage ) ;
PARAM_FLOAT_DEF ( distance ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_CLASS_DEF ( flashtype , AActor ) ;
2016-06-14 00:38:00 +00:00
int i ;
int damageSteps ;
int actualDamage ;
double actualDistance ;
actualDistance = self - > Distance3D ( self - > target ) ;
if ( actualDistance < distance )
{
// [XA] Decrease damage with distance. Use the BFG damage
// calculation formula if the flag is set (essentially
// a generalization of SMMU's BFG11K behavior, used
// with fraggle's blessing.)
damageSteps = damage - int ( damage * actualDistance / distance ) ;
if ( flags & RDSF_BFGDAMAGE )
{
actualDamage = 0 ;
for ( i = 0 ; i < damageSteps ; + + i )
actualDamage + = ( pr_bfgselfdamage ( ) & 7 ) + 1 ;
}
else
{
actualDamage = damageSteps ;
}
// optional "flash" effect -- spawn an actor on
// the player to indicate bad things happened.
AActor * flash = NULL ;
if ( flashtype ! = NULL )
flash = Spawn ( flashtype , self - > target - > PosPlusZ ( self - > target - > Height / 4 ) , ALLOW_REPLACE ) ;
int dmgFlags = 0 ;
FName dmgType = NAME_BFGSplash ;
if ( flash ! = NULL )
{
if ( flash - > flags5 & MF5_PUFFGETSOWNER ) flash - > target = self - > target ;
if ( flash - > flags3 & MF3_FOILINVUL ) dmgFlags | = DMG_FOILINVUL ;
if ( flash - > flags7 & MF7_FOILBUDDHA ) dmgFlags | = DMG_FOILBUDDHA ;
dmgType = flash - > DamageType ;
}
int newdam = P_DamageMobj ( self - > target , self , self - > target , actualDamage , dmgType , dmgFlags ) ;
P_TraceBleed ( newdam > 0 ? newdam : actualDamage , self - > target , self ) ;
}
return 0 ;
}
2015-01-30 01:30:26 +00:00
//==========================================================================
//
// The ultimate code pointer: Fully customizable missiles!
//
//==========================================================================
enum CM_Flags
{
CMF_AIMMODE = 3 ,
CMF_TRACKOWNER = 4 ,
CMF_CHECKTARGETDEAD = 8 ,
CMF_ABSOLUTEPITCH = 16 ,
CMF_OFFSETPITCH = 32 ,
CMF_SAVEPITCH = 64 ,
2016-12-24 13:46:34 +00:00
CMF_ABSOLUTEANGLE = 128 ,
CMF_BADPITCH = 256
2015-01-30 01:30:26 +00:00
} ;
2016-12-24 13:46:34 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SpawnProjectile )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( ti , AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( Spawnheight ) ;
PARAM_FLOAT_DEF ( Spawnofs_xy ) ;
PARAM_ANGLE_DEF ( Angle ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_ANGLE_DEF ( Pitch ) ;
PARAM_INT_DEF ( ptr ) ;
2015-01-30 01:30:26 +00:00
AActor * ref = COPY_AAPTR ( self , ptr ) ;
int aimmode = flags & CMF_AIMMODE ;
AActor * targ ;
2017-01-20 11:39:51 +00:00
AActor * missile = nullptr ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ref ! = NULL | | aimmode = = 2 )
2015-01-30 01:30:26 +00:00
{
if ( ti )
{
2016-03-23 11:21:52 +00:00
DAngle angle = self - > Angles . Yaw - 90 ;
double x = Spawnofs_xy * angle . Cos ( ) ;
double y = Spawnofs_xy * angle . Sin ( ) ;
double z = Spawnheight + self - > GetBobOffset ( ) - 32 + ( self - > player ? self - > player - > crouchoffset : 0. ) ;
2015-01-30 01:30:26 +00:00
2016-03-23 11:21:52 +00:00
DVector3 pos = self - > Pos ( ) ;
2015-01-30 01:30:26 +00:00
switch ( aimmode )
{
case 0 :
default :
// same adjustment as above (in all 3 directions this time) - for better aiming!
2016-01-19 19:15:45 +00:00
self - > SetXYZ ( self - > Vec3Offset ( x , y , z ) ) ;
2016-03-23 09:42:41 +00:00
missile = P_SpawnMissileXYZ ( self - > PosPlusZ ( 32. ) , self , ref , ti , false ) ;
2016-01-19 19:15:45 +00:00
self - > SetXYZ ( pos ) ;
2015-01-30 01:30:26 +00:00
break ;
case 1 :
2016-03-23 11:21:52 +00:00
missile = P_SpawnMissileXYZ ( self - > Vec3Offset ( x , y , self - > GetBobOffset ( ) + Spawnheight ) , self , ref , ti , false ) ;
2015-01-30 01:30:26 +00:00
break ;
case 2 :
2016-03-23 11:21:52 +00:00
self - > SetXYZ ( self - > Vec3Offset ( x , y , 0. ) ) ;
missile = P_SpawnMissileAngleZSpeed ( self , self - > Z ( ) + self - > GetBobOffset ( ) + Spawnheight , ti , self - > Angles . Yaw , 0 , GetDefaultByType ( ti ) - > Speed , self , false ) ;
2016-01-19 19:15:45 +00:00
self - > SetXYZ ( pos ) ;
2015-01-30 01:30:26 +00:00
flags | = CMF_ABSOLUTEPITCH ;
break ;
}
2016-01-19 15:09:44 +00:00
if ( missile ! = NULL )
2015-01-30 01:30:26 +00:00
{
// Use the actual velocity instead of the missile's Speed property
// so that this can handle missiles with a high vertical velocity
// component properly.
2016-03-19 23:54:18 +00:00
double missilespeed ;
2015-01-30 01:30:26 +00:00
if ( ( CMF_ABSOLUTEPITCH | CMF_OFFSETPITCH ) & flags )
{
if ( CMF_OFFSETPITCH & flags )
{
2016-03-19 23:54:18 +00:00
Pitch + = missile - > Vel . Pitch ( ) ;
2015-01-30 01:30:26 +00:00
}
2016-03-19 23:54:18 +00:00
missilespeed = fabs ( Pitch . Cos ( ) * missile - > Speed ) ;
2016-12-11 10:39:46 +00:00
missile - > Vel . Z = Pitch . Sin ( ) * missile - > Speed ;
2016-12-24 13:46:34 +00:00
if ( ! ( flags & CMF_BADPITCH ) ) missile - > Vel . Z * = - 1 ;
2015-01-30 01:30:26 +00:00
}
else
{
2016-03-19 23:54:18 +00:00
missilespeed = missile - > VelXYToSpeed ( ) ;
2015-01-30 01:30:26 +00:00
}
if ( CMF_SAVEPITCH & flags )
{
2016-03-16 11:41:26 +00:00
missile - > Angles . Pitch = Pitch ;
2015-01-30 01:30:26 +00:00
// In aimmode 0 and 1 without absolutepitch or offsetpitch, the pitch parameter
// contains the unapplied parameter. In that case, it is set as pitch without
// otherwise affecting the spawned actor.
}
2016-03-19 23:54:18 +00:00
missile - > Angles . Yaw = ( CMF_ABSOLUTEANGLE & flags ) ? Angle : missile - > Angles . Yaw + Angle ;
2016-03-16 11:41:26 +00:00
missile - > VelFromAngle ( missilespeed ) ;
2015-01-30 01:30:26 +00:00
// handle projectile shooting projectiles - track the
// links back to a real owner
if ( self - > isMissile ( ! ! ( flags & CMF_TRACKOWNER ) ) )
{
2016-01-19 15:09:44 +00:00
AActor * owner = self ; //->target;
while ( owner - > isMissile ( ! ! ( flags & CMF_TRACKOWNER ) ) & & owner - > target )
owner = owner - > target ;
targ = owner ;
missile - > target = owner ;
2015-01-30 01:30:26 +00:00
// automatic handling of seeker missiles
2015-10-13 07:13:37 +00:00
if ( self - > flags2 & missile - > flags2 & MF2_SEEKERMISSILE )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
missile - > tracer = self - > tracer ;
2015-01-30 01:30:26 +00:00
}
}
2016-01-19 15:09:44 +00:00
else if ( missile - > flags2 & MF2_SEEKERMISSILE )
2015-01-30 01:30:26 +00:00
{
// automatic handling of seeker missiles
2016-01-19 15:09:44 +00:00
missile - > tracer = self - > target ;
2015-01-30 01:30:26 +00:00
}
// we must redo the spectral check here because the owner is set after spawning so the FriendPlayer value may be wrong
if ( missile - > flags4 & MF4_SPECTRAL )
{
if ( missile - > target ! = NULL )
{
missile - > SetFriendPlayer ( missile - > target - > player ) ;
}
else
{
missile - > FriendPlayer = 0 ;
}
}
P_CheckMissileSpawn ( missile , self - > radius ) ;
}
}
}
else if ( flags & CMF_CHECKTARGETDEAD )
{
// Target is dead and the attack shall be aborted.
2016-01-19 15:09:44 +00:00
if ( self - > SeeState ! = NULL & & ( self - > health > 0 | | ! ( self - > flags3 & MF3_ISMONSTER ) ) )
self - > SetState ( self - > SeeState ) ;
2015-01-30 01:30:26 +00:00
}
2017-01-20 11:39:51 +00:00
ACTION_RETURN_OBJECT ( missile ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// An even more customizable hitscan attack
//
//==========================================================================
enum CBA_Flags
{
CBAF_AIMFACING = 1 ,
CBAF_NORANDOM = 2 ,
CBAF_EXPLICITANGLE = 4 ,
CBAF_NOPITCH = 8 ,
CBAF_NORANDOMPUFFZ = 16 ,
2016-05-30 23:08:43 +00:00
CBAF_PUFFTARGET = 32 ,
CBAF_PUFFMASTER = 64 ,
CBAF_PUFFTRACER = 128 ,
2015-01-30 01:30:26 +00:00
} ;
2016-07-13 15:15:10 +00:00
static void AimBulletMissile ( AActor * proj , AActor * puff , int flags , bool temp , bool cba ) ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_CustomBulletAttack )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_ANGLE ( spread_xy ) ;
PARAM_ANGLE ( spread_z ) ;
PARAM_INT ( numbullets ) ;
PARAM_INT ( damageperbullet ) ;
2016-10-27 13:53:53 +00:00
PARAM_CLASS_DEF ( pufftype , AActor ) ;
PARAM_FLOAT_DEF ( range ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_INT_DEF ( ptr ) ;
PARAM_CLASS_DEF ( missile , AActor ) ;
PARAM_FLOAT_DEF ( Spawnheight ) ;
PARAM_FLOAT_DEF ( Spawnofs_xy ) ;
2015-01-30 01:30:26 +00:00
AActor * ref = COPY_AAPTR ( self , ptr ) ;
2016-01-19 15:09:44 +00:00
if ( range = = 0 )
range = MISSILERANGE ;
2015-01-30 01:30:26 +00:00
int i ;
2016-03-17 10:38:56 +00:00
DAngle bangle ;
DAngle bslope = 0. ;
2016-01-19 15:09:44 +00:00
int laflags = ( flags & CBAF_NORANDOMPUFFZ ) ? LAF_NORANDOMPUFFZ : 0 ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ref ! = NULL | | ( flags & CBAF_AIMFACING ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( ! ( flags & CBAF_AIMFACING ) )
2015-01-30 01:30:26 +00:00
{
A_Face ( self , ref ) ;
}
2016-03-17 10:38:56 +00:00
bangle = self - > Angles . Yaw ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ! ( flags & CBAF_NOPITCH ) ) bslope = P_AimLineAttack ( self , bangle , MISSILERANGE ) ;
2016-05-27 09:39:44 +00:00
if ( pufftype = = nullptr ) pufftype = PClass : : FindActor ( NAME_BulletPuff ) ;
2015-01-30 01:30:26 +00:00
S_Sound ( self , CHAN_WEAPON , self - > AttackSound , 1 , ATTN_NORM ) ;
2016-01-19 15:09:44 +00:00
for ( i = 0 ; i < numbullets ; i + + )
2015-01-30 01:30:26 +00:00
{
2016-03-17 10:38:56 +00:00
DAngle angle = bangle ;
DAngle slope = bslope ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( flags & CBAF_EXPLICITANGLE )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
angle + = spread_xy ;
slope + = spread_z ;
2015-01-30 01:30:26 +00:00
}
else
{
2016-05-30 20:29:23 +00:00
angle + = spread_xy * ( pr_cwbullet . Random2 ( ) / 255. ) ;
slope + = spread_z * ( pr_cwbullet . Random2 ( ) / 255. ) ;
2015-01-30 01:30:26 +00:00
}
2016-01-19 15:09:44 +00:00
int damage = damageperbullet ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ! ( flags & CBAF_NORANDOM ) )
2015-01-30 01:30:26 +00:00
damage * = ( ( pr_cabullet ( ) % 3 ) + 1 ) ;
2016-05-30 20:16:05 +00:00
AActor * puff = P_LineAttack ( self , angle , range , slope , damage , NAME_Hitscan , pufftype , laflags ) ;
2016-07-13 14:48:24 +00:00
if ( missile ! = nullptr & & pufftype ! = nullptr )
2016-05-30 20:16:05 +00:00
{
double x = Spawnofs_xy * angle . Cos ( ) ;
double y = Spawnofs_xy * angle . Sin ( ) ;
2016-07-13 14:48:24 +00:00
DVector3 pos = self - > Pos ( ) ;
self - > SetXYZ ( self - > Vec3Offset ( x , y , 0. ) ) ;
AActor * proj = P_SpawnMissileAngleZSpeed ( self , self - > Z ( ) + self - > GetBobOffset ( ) + Spawnheight , missile , self - > Angles . Yaw , 0 , GetDefaultByType ( missile ) - > Speed , self , false ) ;
self - > SetXYZ ( pos ) ;
2016-05-30 20:16:05 +00:00
if ( proj )
{
2016-07-13 14:48:24 +00:00
bool temp = ( puff = = nullptr ) ;
if ( ! puff )
2016-06-19 15:59:00 +00:00
{
2016-07-13 14:48:24 +00:00
puff = P_LineAttack ( self , angle , range , slope , 0 , NAME_Hitscan , pufftype , laflags | LAF_NOINTERACT ) ;
}
if ( puff )
{
2016-07-13 15:15:10 +00:00
AimBulletMissile ( proj , puff , flags , temp , true ) ;
2016-06-19 15:59:00 +00:00
}
2016-05-30 20:16:05 +00:00
}
}
2015-01-30 01:30:26 +00:00
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A fully customizable melee attack
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_CustomMeleeAttack )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( damage ) ;
PARAM_SOUND_DEF ( meleesound ) ;
PARAM_SOUND_DEF ( misssound ) ;
PARAM_NAME_DEF ( damagetype ) ;
PARAM_BOOL_DEF ( bleed ) ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( damagetype = = NAME_None )
damagetype = NAME_Melee ; // Melee is the default type
2015-01-30 01:30:26 +00:00
if ( ! self - > target )
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
A_FaceTarget ( self ) ;
if ( self - > CheckMeleeRange ( ) )
{
2016-01-19 15:09:44 +00:00
if ( meleesound )
S_Sound ( self , CHAN_WEAPON , meleesound , 1 , ATTN_NORM ) ;
int newdam = P_DamageMobj ( self - > target , self , self , damage , damagetype ) ;
if ( bleed )
P_TraceBleed ( newdam > 0 ? newdam : damage , self - > target , self ) ;
2015-01-30 01:30:26 +00:00
}
else
{
2016-01-19 15:09:44 +00:00
if ( misssound )
S_Sound ( self , CHAN_WEAPON , misssound , 1 , ATTN_NORM ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A fully customizable combo attack
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_CustomComboAttack )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( ti , AActor ) ;
2016-03-23 11:21:52 +00:00
PARAM_FLOAT ( spawnheight ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( damage ) ;
2016-10-27 13:53:53 +00:00
PARAM_SOUND_DEF ( meleesound ) ;
PARAM_NAME_DEF ( damagetype ) ;
PARAM_BOOL_DEF ( bleed ) ;
2015-01-30 01:30:26 +00:00
if ( ! self - > target )
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
A_FaceTarget ( self ) ;
2016-01-19 15:09:44 +00:00
if ( self - > CheckMeleeRange ( ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( damagetype = = NAME_None )
damagetype = NAME_Melee ; // Melee is the default type
if ( meleesound )
S_Sound ( self , CHAN_WEAPON , meleesound , 1 , ATTN_NORM ) ;
int newdam = P_DamageMobj ( self - > target , self , self , damage , damagetype ) ;
if ( bleed )
P_TraceBleed ( newdam > 0 ? newdam : damage , self - > target , self ) ;
2015-01-30 01:30:26 +00:00
}
else if ( ti )
{
// This seemingly senseless code is needed for proper aiming.
2016-03-23 11:21:52 +00:00
double add = spawnheight + self - > GetBobOffset ( ) - 32 ;
self - > AddZ ( add ) ;
2016-03-23 09:42:41 +00:00
AActor * missile = P_SpawnMissileXYZ ( self - > PosPlusZ ( 32. ) , self , self - > target , ti , false ) ;
2016-03-23 11:21:52 +00:00
self - > AddZ ( - add ) ;
2015-01-30 01:30:26 +00:00
if ( missile )
{
// automatic handling of seeker missiles
2016-01-19 15:09:44 +00:00
if ( missile - > flags2 & MF2_SEEKERMISSILE )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
missile - > tracer = self - > target ;
2015-01-30 01:30:26 +00:00
}
P_CheckMissileSpawn ( missile , self - > radius ) ;
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// State jump function
//
//==========================================================================
2016-12-02 17:52:58 +00:00
DEFINE_ACTION_FUNCTION ( AStateProvider , A_JumpIfNoAmmo )
2015-01-30 01:30:26 +00:00
{
2016-12-02 17:52:58 +00:00
PARAM_ACTION_PROLOGUE ( AStateProvider ) ;
2016-11-14 13:12:27 +00:00
PARAM_STATE_ACTION ( jump ) ;
2015-01-30 01:30:26 +00:00
2016-06-17 07:35:10 +00:00
if ( ! ACTION_CALL_FROM_PSPRITE ( ) | | self - > player - > ReadyWeapon = = nullptr )
2016-02-19 02:39:40 +00:00
{
ACTION_RETURN_STATE ( NULL ) ;
}
2015-01-30 01:30:26 +00:00
if ( ! self - > player - > ReadyWeapon - > CheckAmmo ( self - > player - > ReadyWeapon - > bAltFire , false , true ) )
{
2016-02-19 02:39:40 +00:00
ACTION_RETURN_STATE ( jump ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_STATE ( NULL ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// An even more customizable hitscan attack
//
//==========================================================================
enum FB_Flags
{
FBF_USEAMMO = 1 ,
FBF_NORANDOM = 2 ,
FBF_EXPLICITANGLE = 4 ,
FBF_NOPITCH = 8 ,
FBF_NOFLASH = 16 ,
FBF_NORANDOMPUFFZ = 32 ,
2016-05-30 23:08:43 +00:00
FBF_PUFFTARGET = 64 ,
FBF_PUFFMASTER = 128 ,
FBF_PUFFTRACER = 256 ,
2015-01-30 01:30:26 +00:00
} ;
2016-07-13 15:15:10 +00:00
static void AimBulletMissile ( AActor * proj , AActor * puff , int flags , bool temp , bool cba )
2016-05-30 20:16:05 +00:00
{
2016-07-13 14:48:24 +00:00
if ( proj & & puff )
2016-05-30 20:16:05 +00:00
{
if ( proj )
{
2016-06-19 15:59:00 +00:00
// FAF_BOTTOM = 1
// Aim for the base of the puff as that's where blood puffs will spawn... roughly.
A_Face ( proj , puff , 0. , 0. , 0. , 0. , 1 ) ;
2016-12-24 14:10:07 +00:00
proj - > Vel3DFromAngle ( proj - > Angles . Pitch , proj - > Speed ) ;
2016-06-19 15:59:00 +00:00
2016-07-13 14:48:24 +00:00
if ( ! temp )
2016-06-19 15:59:00 +00:00
{
2016-07-13 15:15:10 +00:00
if ( cba )
{
if ( flags & CBAF_PUFFTARGET ) proj - > target = puff ;
if ( flags & CBAF_PUFFMASTER ) proj - > master = puff ;
if ( flags & CBAF_PUFFTRACER ) proj - > tracer = puff ;
}
else
{
if ( flags & FBF_PUFFTARGET ) proj - > target = puff ;
if ( flags & FBF_PUFFMASTER ) proj - > master = puff ;
if ( flags & FBF_PUFFTRACER ) proj - > tracer = puff ;
}
2016-06-19 15:59:00 +00:00
}
2016-05-30 20:16:05 +00:00
}
}
2016-07-13 14:48:24 +00:00
if ( puff & & temp )
{
puff - > Destroy ( ) ;
}
2016-05-30 20:16:05 +00:00
}
2016-12-02 17:52:58 +00:00
DEFINE_ACTION_FUNCTION ( AStateProvider , A_FireBullets )
2015-01-30 01:30:26 +00:00
{
2016-12-02 17:52:58 +00:00
PARAM_ACTION_PROLOGUE ( AStateProvider ) ;
2016-02-04 21:15:29 +00:00
PARAM_ANGLE ( spread_xy ) ;
PARAM_ANGLE ( spread_z ) ;
PARAM_INT ( numbullets ) ;
PARAM_INT ( damageperbullet ) ;
2016-10-27 13:53:53 +00:00
PARAM_CLASS_DEF ( pufftype , AActor ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_FLOAT_DEF ( range ) ;
PARAM_CLASS_DEF ( missile , AActor ) ;
PARAM_FLOAT_DEF ( Spawnheight ) ;
PARAM_FLOAT_DEF ( Spawnofs_xy ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( ! self - > player ) return 0 ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
player_t * player = self - > player ;
AWeapon * weapon = player - > ReadyWeapon ;
2015-01-30 01:30:26 +00:00
int i ;
2016-03-17 10:38:56 +00:00
DAngle bangle ;
DAngle bslope = 0. ;
2016-01-19 15:09:44 +00:00
int laflags = ( flags & FBF_NORANDOMPUFFZ ) ? LAF_NORANDOMPUFFZ : 0 ;
2015-01-30 01:30:26 +00:00
2016-06-17 07:26:33 +00:00
if ( ( flags & FBF_USEAMMO ) & & weapon & & ACTION_CALL_FROM_PSPRITE ( ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( ! weapon - > DepleteAmmo ( weapon - > bAltFire , true ) )
2016-02-04 21:15:29 +00:00
return 0 ; // out of ammo
2015-01-30 01:30:26 +00:00
}
2016-03-24 23:59:14 +00:00
if ( range = = 0 ) range = PLAYERMISSILERANGE ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ! ( flags & FBF_NOFLASH ) ) static_cast < APlayerPawn * > ( self ) - > PlayAttacking2 ( ) ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ! ( flags & FBF_NOPITCH ) ) bslope = P_BulletSlope ( self ) ;
2016-03-17 10:38:56 +00:00
bangle = self - > Angles . Yaw ;
2015-01-30 01:30:26 +00:00
2016-03-24 23:59:14 +00:00
if ( pufftype = = NULL ) pufftype = PClass : : FindActor ( NAME_BulletPuff ) ;
2015-01-30 01:30:26 +00:00
if ( weapon ! = NULL )
{
2016-01-19 15:09:44 +00:00
S_Sound ( self , CHAN_WEAPON , weapon - > AttackSound , 1 , ATTN_NORM ) ;
2015-01-30 01:30:26 +00:00
}
2016-01-19 15:09:44 +00:00
if ( ( numbullets = = 1 & & ! player - > refire ) | | numbullets = = 0 )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
int damage = damageperbullet ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ! ( flags & FBF_NORANDOM ) )
2015-01-30 01:30:26 +00:00
damage * = ( ( pr_cwbullet ( ) % 3 ) + 1 ) ;
2016-05-30 20:16:05 +00:00
AActor * puff = P_LineAttack ( self , bangle , range , bslope , damage , NAME_Hitscan , pufftype , laflags ) ;
2016-06-19 15:59:00 +00:00
2016-07-13 14:48:24 +00:00
if ( missile ! = nullptr )
2016-06-19 15:59:00 +00:00
{
2016-07-13 14:48:24 +00:00
bool temp = false ;
DAngle ang = self - > Angles . Yaw - 90 ;
DVector2 ofs = ang . ToVector ( Spawnofs_xy ) ;
AActor * proj = P_SpawnPlayerMissile ( self , ofs . X , ofs . Y , Spawnheight , missile , bangle , nullptr , nullptr , false , true ) ;
if ( proj )
{
if ( ! puff )
{
temp = true ;
puff = P_LineAttack ( self , bangle , range , bslope , 0 , NAME_Hitscan , pufftype , laflags | LAF_NOINTERACT ) ;
}
2016-07-13 15:15:10 +00:00
AimBulletMissile ( proj , puff , flags , temp , false ) ;
2016-07-13 14:48:24 +00:00
}
2016-06-19 15:59:00 +00:00
}
2015-01-30 01:30:26 +00:00
}
else
{
2016-01-19 15:09:44 +00:00
if ( numbullets < 0 )
numbullets = 1 ;
for ( i = 0 ; i < numbullets ; i + + )
2015-01-30 01:30:26 +00:00
{
2016-03-17 10:38:56 +00:00
DAngle angle = bangle ;
DAngle slope = bslope ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( flags & FBF_EXPLICITANGLE )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
angle + = spread_xy ;
slope + = spread_z ;
2015-01-30 01:30:26 +00:00
}
else
{
2016-03-17 10:38:56 +00:00
angle + = spread_xy * ( pr_cwbullet . Random2 ( ) / 255. ) ;
slope + = spread_z * ( pr_cwbullet . Random2 ( ) / 255. ) ;
2015-01-30 01:30:26 +00:00
}
2016-01-19 15:09:44 +00:00
int damage = damageperbullet ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ! ( flags & FBF_NORANDOM ) )
2015-01-30 01:30:26 +00:00
damage * = ( ( pr_cwbullet ( ) % 3 ) + 1 ) ;
2016-05-30 20:16:05 +00:00
AActor * puff = P_LineAttack ( self , angle , range , slope , damage , NAME_Hitscan , pufftype , laflags ) ;
2016-06-19 15:59:00 +00:00
2016-07-13 14:48:24 +00:00
if ( missile ! = nullptr )
2016-06-19 15:59:00 +00:00
{
2016-07-13 14:48:24 +00:00
bool temp = false ;
DAngle ang = self - > Angles . Yaw - 90 ;
DVector2 ofs = ang . ToVector ( Spawnofs_xy ) ;
AActor * proj = P_SpawnPlayerMissile ( self , ofs . X , ofs . Y , Spawnheight , missile , angle , nullptr , nullptr , false , true ) ;
if ( proj )
{
if ( ! puff )
{
temp = true ;
puff = P_LineAttack ( self , angle , range , slope , 0 , NAME_Hitscan , pufftype , laflags | LAF_NOINTERACT ) ;
}
2016-07-13 15:15:10 +00:00
AimBulletMissile ( proj , puff , flags , temp , false ) ;
2016-07-13 14:48:24 +00:00
}
2016-06-19 15:59:00 +00:00
}
2015-01-30 01:30:26 +00:00
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_FireProjectile
//
//==========================================================================
enum FP_Flags
{
FPF_AIMATANGLE = 1 ,
FPF_TRANSFERTRANSLATION = 2 ,
2015-09-08 15:40:21 +00:00
FPF_NOAUTOAIM = 4 ,
2015-01-30 01:30:26 +00:00
} ;
2016-12-24 15:34:45 +00:00
DEFINE_ACTION_FUNCTION ( AStateProvider , A_FireProjectile )
2015-01-30 01:30:26 +00:00
{
2016-12-02 17:52:58 +00:00
PARAM_ACTION_PROLOGUE ( AStateProvider ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( ti , AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_ANGLE_DEF ( angle ) ;
PARAM_BOOL_DEF ( useammo ) ;
PARAM_FLOAT_DEF ( spawnofs_xy ) ;
PARAM_FLOAT_DEF ( spawnheight ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_ANGLE_DEF ( pitch ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( ! self - > player )
2017-01-20 11:39:51 +00:00
ACTION_RETURN_OBJECT ( nullptr ) ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
player_t * player = self - > player ;
AWeapon * weapon = player - > ReadyWeapon ;
2016-03-01 15:38:45 +00:00
FTranslatedLineTarget t ;
2015-01-30 01:30:26 +00:00
2015-03-10 15:58:10 +00:00
// Only use ammo if called from a weapon
2016-06-17 07:26:33 +00:00
if ( useammo & & ACTION_CALL_FROM_PSPRITE ( ) & & weapon )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( ! weapon - > DepleteAmmo ( weapon - > bAltFire , true ) )
2017-01-20 11:39:51 +00:00
ACTION_RETURN_OBJECT ( nullptr ) ; // out of ammo
2015-01-30 01:30:26 +00:00
}
if ( ti )
{
2016-03-21 23:30:56 +00:00
DAngle ang = self - > Angles . Yaw - 90 ;
2016-03-27 12:20:14 +00:00
DVector2 ofs = ang . ToVector ( spawnofs_xy ) ;
2016-03-16 11:41:26 +00:00
DAngle shootangle = self - > Angles . Yaw ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( flags & FPF_AIMATANGLE ) shootangle + = angle ;
2015-01-30 01:30:26 +00:00
// Temporarily adjusts the pitch
2016-03-16 11:41:26 +00:00
DAngle saved_player_pitch = self - > Angles . Pitch ;
2017-03-13 09:03:42 +00:00
self - > Angles . Pitch + = pitch ;
2016-03-27 12:20:14 +00:00
AActor * misl = P_SpawnPlayerMissile ( self , ofs . X , ofs . Y , spawnheight , ti , shootangle , & t , NULL , false , ( flags & FPF_NOAUTOAIM ) ! = 0 ) ;
2016-03-16 11:41:26 +00:00
self - > Angles . Pitch = saved_player_pitch ;
2015-01-30 01:30:26 +00:00
// automatic handling of seeker missiles
if ( misl )
{
2016-01-19 15:09:44 +00:00
if ( flags & FPF_TRANSFERTRANSLATION )
misl - > Translation = self - > Translation ;
2016-03-01 15:38:45 +00:00
if ( t . linetarget & & ! t . unlinked & & ( misl - > flags2 & MF2_SEEKERMISSILE ) )
misl - > tracer = t . linetarget ;
2016-01-19 15:09:44 +00:00
if ( ! ( flags & FPF_AIMATANGLE ) )
2015-01-30 01:30:26 +00:00
{
// This original implementation is to aim straight ahead and then offset
// the angle from the resulting direction.
2016-03-16 11:41:26 +00:00
misl - > Angles . Yaw + = angle ;
2016-03-19 23:54:18 +00:00
misl - > VelFromAngle ( misl - > VelXYToSpeed ( ) ) ;
2015-01-30 01:30:26 +00:00
}
}
2017-01-20 11:39:51 +00:00
ACTION_RETURN_OBJECT ( misl ) ;
2015-01-30 01:30:26 +00:00
}
2017-01-20 11:39:51 +00:00
ACTION_RETURN_OBJECT ( nullptr ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_CustomPunch
//
// Berserk is not handled here. That can be done with A_CheckIfInventory
//
//==========================================================================
enum
{
CPF_USEAMMO = 1 ,
CPF_DAGGER = 2 ,
CPF_PULLIN = 4 ,
CPF_NORANDOMPUFFZ = 8 ,
CPF_NOTURN = 16 ,
CPF_STEALARMOR = 32 ,
} ;
2016-12-02 17:52:58 +00:00
DEFINE_ACTION_FUNCTION ( AStateProvider , A_CustomPunch )
2015-01-30 01:30:26 +00:00
{
2016-12-02 17:52:58 +00:00
PARAM_ACTION_PROLOGUE ( AStateProvider ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( damage ) ;
2016-10-27 13:53:53 +00:00
PARAM_BOOL_DEF ( norandom ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_CLASS_DEF ( pufftype , AActor ) ;
PARAM_FLOAT_DEF ( range ) ;
PARAM_FLOAT_DEF ( lifesteal ) ;
PARAM_INT_DEF ( lifestealmax ) ;
2017-01-18 19:23:13 +00:00
PARAM_CLASS_DEF ( armorbonustype , AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_SOUND_DEF ( MeleeSound ) ;
PARAM_SOUND_DEF ( MissSound ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( ! self - > player )
return 0 ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
player_t * player = self - > player ;
AWeapon * weapon = player - > ReadyWeapon ;
2015-01-30 01:30:26 +00:00
2016-03-17 10:38:56 +00:00
DAngle angle ;
DAngle pitch ;
2016-03-01 15:38:45 +00:00
FTranslatedLineTarget t ;
2015-01-30 01:30:26 +00:00
int actualdamage ;
2016-01-19 15:09:44 +00:00
if ( ! norandom )
damage * = pr_cwpunch ( ) % 8 + 1 ;
2015-01-30 01:30:26 +00:00
2016-03-17 10:38:56 +00:00
angle = self - > Angles . Yaw + pr_cwpunch . Random2 ( ) * ( 5.625 / 256 ) ;
2016-12-10 15:35:48 +00:00
if ( range = = 0 ) range = DEFMELEERANGE ;
2016-03-01 15:38:45 +00:00
pitch = P_AimLineAttack ( self , angle , range , & t ) ;
2015-01-30 01:30:26 +00:00
// only use ammo when actually hitting something!
2016-06-17 07:26:33 +00:00
if ( ( flags & CPF_USEAMMO ) & & t . linetarget & & weapon & & ACTION_CALL_FROM_PSPRITE ( ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( ! weapon - > DepleteAmmo ( weapon - > bAltFire , true ) )
2016-02-04 21:15:29 +00:00
return 0 ; // out of ammo
2015-01-30 01:30:26 +00:00
}
2016-01-19 15:09:44 +00:00
if ( pufftype = = NULL )
2016-02-04 21:15:29 +00:00
pufftype = PClass : : FindActor ( NAME_BulletPuff ) ;
2015-01-30 01:30:26 +00:00
int puffFlags = LAF_ISMELEEATTACK | ( ( flags & CPF_NORANDOMPUFFZ ) ? LAF_NORANDOMPUFFZ : 0 ) ;
2016-03-01 15:38:45 +00:00
P_LineAttack ( self , angle , range , pitch , damage , NAME_Melee , pufftype , puffFlags , & t , & actualdamage ) ;
2015-01-30 01:30:26 +00:00
2016-03-01 15:38:45 +00:00
if ( ! t . linetarget )
2015-11-30 17:42:08 +00:00
{
if ( MissSound ) S_Sound ( self , CHAN_WEAPON , MissSound , 1 , ATTN_NORM ) ;
}
else
2015-01-30 01:30:26 +00:00
{
2016-03-24 23:59:14 +00:00
if ( lifesteal > 0 & & ! ( t . linetarget - > flags5 & MF5_DONTDRAIN ) )
2015-01-30 01:30:26 +00:00
{
if ( flags & CPF_STEALARMOR )
{
2016-01-19 15:09:44 +00:00
if ( armorbonustype = = NULL )
2015-01-30 01:30:26 +00:00
{
2017-01-18 19:23:13 +00:00
armorbonustype = PClass : : FindActor ( " ArmorBonus " ) ;
2016-01-19 15:09:44 +00:00
}
if ( armorbonustype ! = NULL )
{
2017-01-18 19:23:13 +00:00
auto armorbonus = Spawn ( armorbonustype ) ;
armorbonus - > IntVar ( NAME_SaveAmount ) * = int ( actualdamage * lifesteal ) ;
if ( lifestealmax > 0 ) armorbonus - > IntVar ( " MaxSaveAmount " ) = lifestealmax ;
2015-01-30 01:30:26 +00:00
armorbonus - > flags | = MF_DROPPED ;
armorbonus - > ClearCounters ( ) ;
2017-01-18 19:23:13 +00:00
if ( ! static_cast < AInventory * > ( armorbonus ) - > CallTryPickup ( self ) )
2015-01-30 01:30:26 +00:00
{
armorbonus - > Destroy ( ) ;
}
}
}
else
{
2016-03-24 23:59:14 +00:00
P_GiveBody ( self , int ( actualdamage * lifesteal ) , lifestealmax ) ;
2015-01-30 01:30:26 +00:00
}
}
if ( weapon ! = NULL )
{
2015-11-30 17:42:08 +00:00
if ( MeleeSound ) S_Sound ( self , CHAN_WEAPON , MeleeSound , 1 , ATTN_NORM ) ;
else S_Sound ( self , CHAN_WEAPON , weapon - > AttackSound , 1 , ATTN_NORM ) ;
2015-01-30 01:30:26 +00:00
}
if ( ! ( flags & CPF_NOTURN ) )
{
// turn to face target
2016-03-16 11:41:26 +00:00
self - > Angles . Yaw = t . angleFromSource ;
2015-01-30 01:30:26 +00:00
}
if ( flags & CPF_PULLIN ) self - > flags | = MF_JUSTATTACKED ;
2016-03-01 15:38:45 +00:00
if ( flags & CPF_DAGGER ) P_DaggerAlert ( self , t . linetarget ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// customizable railgun attack function
//
//==========================================================================
2016-12-02 17:52:58 +00:00
DEFINE_ACTION_FUNCTION ( AStateProvider , A_RailAttack )
2015-01-30 01:30:26 +00:00
{
2016-12-02 17:52:58 +00:00
PARAM_ACTION_PROLOGUE ( AStateProvider ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( damage ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( spawnofs_xy ) ;
PARAM_BOOL_DEF ( useammo ) ;
PARAM_COLOR_DEF ( color1 ) ;
PARAM_COLOR_DEF ( color2 ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_FLOAT_DEF ( maxdiff ) ;
PARAM_CLASS_DEF ( pufftype , AActor ) ;
PARAM_ANGLE_DEF ( spread_xy ) ;
PARAM_ANGLE_DEF ( spread_z ) ;
PARAM_FLOAT_DEF ( range ) ;
PARAM_INT_DEF ( duration ) ;
PARAM_FLOAT_DEF ( sparsity ) ;
PARAM_FLOAT_DEF ( driftspeed ) ;
PARAM_CLASS_DEF ( spawnclass , AActor ) ;
PARAM_FLOAT_DEF ( spawnofs_z ) ;
PARAM_INT_DEF ( SpiralOffset ) ;
PARAM_INT_DEF ( limit ) ;
2015-01-30 01:30:26 +00:00
2016-03-24 23:59:14 +00:00
if ( range = = 0 ) range = 8192 ;
2016-01-19 15:09:44 +00:00
if ( sparsity = = 0 ) sparsity = 1.0 ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( self - > player = = NULL )
return 0 ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
AWeapon * weapon = self - > player - > ReadyWeapon ;
2015-01-30 01:30:26 +00:00
// only use ammo when actually hitting something!
2016-06-17 07:26:33 +00:00
if ( useammo & & weapon ! = NULL & & ACTION_CALL_FROM_PSPRITE ( ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( ! weapon - > DepleteAmmo ( weapon - > bAltFire , true ) )
2016-02-04 21:15:29 +00:00
return 0 ; // out of ammo
2015-01-30 01:30:26 +00:00
}
2016-03-24 23:59:14 +00:00
if ( ! ( flags & RAF_EXPLICITANGLE ) )
{
spread_xy = spread_xy * pr_crailgun . Random2 ( ) / 255 ;
spread_z = spread_z * pr_crailgun . Random2 ( ) / 255 ;
}
FRailParams p ;
p . source = self ;
p . damage = damage ;
p . offset_xy = spawnofs_xy ;
p . offset_z = spawnofs_z ;
p . color1 = color1 ;
p . color2 = color2 ;
p . maxdiff = maxdiff ;
p . flags = flags ;
p . puff = pufftype ;
p . angleoffset = spread_xy ;
p . pitchoffset = spread_z ;
p . distance = range ;
p . duration = duration ;
p . sparsity = sparsity ;
p . drift = driftspeed ;
p . spawnclass = spawnclass ;
p . SpiralOffset = SpiralOffset ;
2016-06-14 23:20:43 +00:00
p . limit = limit ;
2016-03-24 23:59:14 +00:00
P_RailAttack ( & p ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// also for monsters
//
//==========================================================================
enum
{
CRF_DONTAIM = 0 ,
CRF_AIMPARALLEL = 1 ,
CRF_AIMDIRECT = 2 ,
CRF_EXPLICITANGLE = 4 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_CustomRailgun )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( damage ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( spawnofs_xy )
PARAM_COLOR_DEF ( color1 )
PARAM_COLOR_DEF ( color2 )
PARAM_INT_DEF ( flags )
PARAM_INT_DEF ( aim )
PARAM_FLOAT_DEF ( maxdiff )
PARAM_CLASS_DEF ( pufftype , AActor )
PARAM_ANGLE_DEF ( spread_xy )
PARAM_ANGLE_DEF ( spread_z )
PARAM_FLOAT_DEF ( range )
PARAM_INT_DEF ( duration )
PARAM_FLOAT_DEF ( sparsity )
PARAM_FLOAT_DEF ( driftspeed )
PARAM_CLASS_DEF ( spawnclass , AActor )
PARAM_FLOAT_DEF ( spawnofs_z )
PARAM_INT_DEF ( SpiralOffset )
PARAM_INT_DEF ( limit )
2017-01-10 19:08:23 +00:00
PARAM_FLOAT_DEF ( veleffect )
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
if ( range = = 0 ) range = 8192. ;
2016-01-19 15:09:44 +00:00
if ( sparsity = = 0 ) sparsity = 1 ;
2015-01-30 01:30:26 +00:00
2016-03-01 15:38:45 +00:00
FTranslatedLineTarget t ;
2015-01-30 01:30:26 +00:00
2016-03-20 22:42:27 +00:00
DVector3 savedpos = self - > Pos ( ) ;
2016-03-16 11:41:26 +00:00
DAngle saved_angle = self - > Angles . Yaw ;
DAngle saved_pitch = self - > Angles . Pitch ;
2015-01-30 01:30:26 +00:00
if ( aim & & self - > target = = NULL )
{
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
// [RH] Andy Baker's stealth monsters
if ( self - > flags & MF_STEALTH )
{
self - > visdir = 1 ;
}
self - > flags & = ~ MF_AMBUSH ;
if ( aim )
{
2016-03-16 23:07:37 +00:00
self - > Angles . Yaw = self - > AngleTo ( self - > target ) ;
2015-01-30 01:30:26 +00:00
}
2016-03-17 10:38:56 +00:00
self - > Angles . Pitch = P_AimLineAttack ( self , self - > Angles . Yaw , MISSILERANGE , & t , 60. , 0 , aim ? self - > target : NULL ) ;
2016-03-01 15:38:45 +00:00
if ( t . linetarget = = NULL & & aim )
2015-01-30 01:30:26 +00:00
{
// We probably won't hit the target, but aim at it anyway so we don't look stupid.
2016-03-20 22:42:27 +00:00
DVector2 xydiff = self - > Vec2To ( self - > target ) ;
double zdiff = self - > target - > Center ( ) - self - > Center ( ) - self - > Floorclip ;
2016-12-24 17:10:37 +00:00
self - > Angles . Pitch = - VecToAngle ( xydiff . Length ( ) , zdiff ) ;
2015-01-30 01:30:26 +00:00
}
// Let the aim trail behind the player
if ( aim )
{
2017-01-10 19:08:23 +00:00
saved_angle = self - > Angles . Yaw = self - > AngleTo ( self - > target , - self - > target - > Vel . X * veleffect , - self - > target - > Vel . Y * veleffect ) ;
2015-01-30 01:30:26 +00:00
if ( aim = = CRF_AIMDIRECT )
{
// Tricky: We must offset to the angle of the current position
// but then change the angle again to ensure proper aim.
2016-01-19 19:15:45 +00:00
self - > SetXY ( self - > Vec2Offset (
2016-03-24 23:59:14 +00:00
spawnofs_xy * self - > Angles . Yaw . Cos ( ) ,
spawnofs_xy * self - > Angles . Yaw . Sin ( ) ) ) ;
2016-01-19 15:09:44 +00:00
spawnofs_xy = 0 ;
2017-01-10 19:08:23 +00:00
self - > Angles . Yaw = self - > AngleTo ( self - > target , - self - > target - > Vel . X * veleffect , - self - > target - > Vel . Y * veleffect ) ;
2015-01-30 01:30:26 +00:00
}
if ( self - > target - > flags & MF_SHADOW )
{
2016-03-16 11:41:26 +00:00
DAngle rnd = pr_crailgun . Random2 ( ) * ( 45. / 256. ) ;
self - > Angles . Yaw + = rnd ;
2015-01-30 01:30:26 +00:00
}
}
2016-03-24 23:59:14 +00:00
if ( ! ( flags & CRF_EXPLICITANGLE ) )
2015-01-30 01:30:26 +00:00
{
2016-03-24 23:59:14 +00:00
spread_xy = spread_xy * pr_crailgun . Random2 ( ) / 255 ;
spread_z = spread_z * pr_crailgun . Random2 ( ) / 255 ;
2015-01-30 01:30:26 +00:00
}
2016-03-24 23:59:14 +00:00
FRailParams p ;
p . source = self ;
p . damage = damage ;
p . offset_xy = spawnofs_xy ;
p . offset_z = spawnofs_z ;
p . color1 = color1 ;
p . color2 = color2 ;
p . maxdiff = maxdiff ;
p . flags = flags ;
p . puff = pufftype ;
p . angleoffset = spread_xy ;
p . pitchoffset = spread_z ;
p . distance = range ;
p . duration = duration ;
p . sparsity = sparsity ;
p . drift = driftspeed ;
p . spawnclass = spawnclass ;
p . SpiralOffset = SpiralOffset ;
2016-06-14 23:20:43 +00:00
p . limit = 0 ;
2016-03-24 23:59:14 +00:00
P_RailAttack ( & p ) ;
2015-01-30 01:30:26 +00:00
2016-01-19 19:15:45 +00:00
self - > SetXYZ ( savedpos ) ;
2016-03-16 11:41:26 +00:00
self - > Angles . Yaw = saved_angle ;
self - > Angles . Pitch = saved_pitch ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// DoGiveInventory
//
//===========================================================================
2016-02-19 02:39:40 +00:00
static bool DoGiveInventory ( AActor * receiver , bool orresult , VM_ARGS )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
int paramnum = 0 ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( mi , AInventory ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( amount )
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( ! orresult )
2015-01-30 01:38:16 +00:00
{
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( setreceiver )
2016-02-04 21:15:29 +00:00
receiver = COPY_AAPTR ( receiver , setreceiver ) ;
}
if ( receiver = = NULL )
{ // If there's nothing to receive it, it's obviously a fail, right?
2016-02-19 02:39:40 +00:00
return false ;
2015-01-30 01:38:16 +00:00
}
2016-11-12 13:48:10 +00:00
// Owned inventory items cannot own anything because their Inventory pointer is repurposed for the owner's linked list.
if ( receiver - > IsKindOf ( RUNTIME_CLASS ( AInventory ) ) & & static_cast < AInventory * > ( receiver ) - > Owner ! = nullptr )
{
return false ;
}
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( amount < = 0 )
{
amount = 1 ;
}
2015-01-30 01:30:26 +00:00
if ( mi )
{
2016-03-21 13:00:05 +00:00
AInventory * item = static_cast < AInventory * > ( Spawn ( mi ) ) ;
2016-02-04 21:15:29 +00:00
if ( item = = NULL )
2015-01-30 01:38:16 +00:00
{
2016-02-19 02:39:40 +00:00
return false ;
2015-01-30 01:38:16 +00:00
}
2017-02-08 14:47:22 +00:00
if ( item - > IsKindOf ( NAME_Health ) )
2015-01-30 01:30:26 +00:00
{
item - > Amount * = amount ;
}
else
{
item - > Amount = amount ;
}
item - > flags | = MF_DROPPED ;
item - > ClearCounters ( ) ;
2016-02-04 21:15:29 +00:00
if ( ! item - > CallTryPickup ( receiver ) )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
item - > Destroy ( ) ;
2016-02-19 02:39:40 +00:00
return false ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
else
{
2016-02-19 02:39:40 +00:00
return true ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
}
2016-02-19 02:39:40 +00:00
return false ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_GiveInventory )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-21 03:27:42 +00:00
ACTION_RETURN_BOOL ( DoGiveInventory ( self , false , VM_ARGS_NAMES ) ) ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_GiveToTarget )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-21 03:27:42 +00:00
ACTION_RETURN_BOOL ( DoGiveInventory ( self - > target , false , VM_ARGS_NAMES ) ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_GiveToChildren )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
2016-02-04 21:15:29 +00:00
AActor * mo ;
2016-02-19 02:39:40 +00:00
int count = 0 ;
2015-01-30 01:30:26 +00:00
while ( ( mo = it . Next ( ) ) )
{
2016-02-04 21:15:29 +00:00
if ( mo - > master = = self )
{
2016-02-19 02:39:40 +00:00
count + = DoGiveInventory ( mo , true , VM_ARGS_NAMES ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_INT ( count ) ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_GiveToSiblings )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
2016-02-04 21:15:29 +00:00
AActor * mo ;
2016-02-19 02:39:40 +00:00
int count = 0 ;
2015-01-30 01:30:26 +00:00
if ( self - > master ! = NULL )
{
while ( ( mo = it . Next ( ) ) )
{
2016-02-04 21:15:29 +00:00
if ( mo - > master = = self - > master & & mo ! = self )
{
2016-02-19 02:39:40 +00:00
count + = DoGiveInventory ( mo , true , VM_ARGS_NAMES ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
}
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_INT ( count ) ;
2015-01-30 01:30:26 +00:00
}
2016-10-11 19:44:31 +00:00
//===========================================================================
//
// A_SetInventory
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetInventory )
2016-10-11 19:44:31 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-11 19:44:31 +00:00
PARAM_CLASS ( itemtype , AInventory ) ;
PARAM_INT ( amount ) ;
2016-11-14 14:48:34 +00:00
PARAM_INT_DEF ( ptr ) ;
PARAM_BOOL_DEF ( beyondMax ) ;
2016-10-11 19:44:31 +00:00
bool res = false ;
if ( itemtype = = nullptr )
{
ACTION_RETURN_BOOL ( false ) ;
}
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
if ( mobj = = nullptr )
{
ACTION_RETURN_BOOL ( false ) ;
}
2017-01-07 13:29:04 +00:00
// Do not run this function on voodoo dolls because the way they transfer the inventory to the player will not work with the code below.
if ( mobj - > player ! = nullptr )
{
mobj = mobj - > player - > mo ;
}
2017-03-14 10:44:21 +00:00
ACTION_RETURN_BOOL ( mobj - > SetInventory ( itemtype , amount , beyondMax ) ) ;
2016-10-11 19:44:31 +00:00
}
2015-01-30 01:30:26 +00:00
//===========================================================================
//
// A_TakeInventory
//
//===========================================================================
enum
{
TIF_NOTAKEINFINITE = 1 ,
} ;
2016-02-19 02:39:40 +00:00
bool DoTakeInventory ( AActor * receiver , bool orresult , VM_ARGS )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
int paramnum = 0 ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( itemtype , AInventory ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( amount ) ;
PARAM_INT_DEF ( flags ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( itemtype = = NULL )
2015-01-30 01:38:16 +00:00
{
2016-04-04 20:51:03 +00:00
return false ;
2016-02-04 21:15:29 +00:00
}
if ( ! orresult )
{
2016-10-27 22:32:52 +00:00
PARAM_INT_DEF ( setreceiver ) ;
2016-02-04 21:15:29 +00:00
receiver = COPY_AAPTR ( receiver , setreceiver ) ;
2015-01-30 01:38:16 +00:00
}
2016-02-04 21:15:29 +00:00
if ( receiver = = NULL )
2015-01-30 01:38:16 +00:00
{
2016-02-19 02:39:40 +00:00
return false ;
2015-01-30 01:38:16 +00:00
}
2015-01-30 01:30:26 +00:00
2016-02-19 02:39:40 +00:00
return receiver - > TakeInventory ( itemtype , amount , true , ( flags & TIF_NOTAKEINFINITE ) ! = 0 ) ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_TakeInventory )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-21 03:27:42 +00:00
ACTION_RETURN_BOOL ( DoTakeInventory ( self , false , VM_ARGS_NAMES ) ) ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_TakeFromTarget )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-21 03:27:42 +00:00
ACTION_RETURN_BOOL ( DoTakeInventory ( self - > target , false , VM_ARGS_NAMES ) ) ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_TakeFromChildren )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
2016-02-19 02:39:40 +00:00
AActor * mo ;
int count = 0 ;
2015-01-30 01:30:26 +00:00
while ( ( mo = it . Next ( ) ) )
{
2016-02-04 21:15:29 +00:00
if ( mo - > master = = self )
{
2016-02-19 02:39:40 +00:00
count + = DoTakeInventory ( mo , true , VM_ARGS_NAMES ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_INT ( count ) ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_TakeFromSiblings )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
2016-02-19 02:39:40 +00:00
AActor * mo ;
int count = 0 ;
2015-01-30 01:30:26 +00:00
if ( self - > master ! = NULL )
{
while ( ( mo = it . Next ( ) ) )
{
2016-02-04 21:15:29 +00:00
if ( mo - > master = = self - > master & & mo ! = self )
{
2016-02-19 02:39:40 +00:00
count + = DoTakeInventory ( mo , true , VM_ARGS_NAMES ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
}
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_INT ( count ) ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// Common code for A_SpawnItem and A_SpawnItemEx
//
//===========================================================================
enum SIX_Flags
{
2015-02-07 16:04:33 +00:00
SIXF_TRANSFERTRANSLATION = 0x00000001 ,
SIXF_ABSOLUTEPOSITION = 0x00000002 ,
SIXF_ABSOLUTEANGLE = 0x00000004 ,
SIXF_ABSOLUTEVELOCITY = 0x00000008 ,
SIXF_SETMASTER = 0x00000010 ,
SIXF_NOCHECKPOSITION = 0x00000020 ,
SIXF_TELEFRAG = 0x00000040 ,
SIXF_CLIENTSIDE = 0x00000080 , // only used by Skulldronum
SIXF_TRANSFERAMBUSHFLAG = 0x00000100 ,
SIXF_TRANSFERPITCH = 0x00000200 ,
SIXF_TRANSFERPOINTERS = 0x00000400 ,
SIXF_USEBLOODCOLOR = 0x00000800 ,
SIXF_CLEARCALLERTID = 0x00001000 ,
SIXF_MULTIPLYSPEED = 0x00002000 ,
SIXF_TRANSFERSCALE = 0x00004000 ,
SIXF_TRANSFERSPECIAL = 0x00008000 ,
SIXF_CLEARCALLERSPECIAL = 0x00010000 ,
SIXF_TRANSFERSTENCILCOL = 0x00020000 ,
SIXF_TRANSFERALPHA = 0x00040000 ,
SIXF_TRANSFERRENDERSTYLE = 0x00080000 ,
SIXF_SETTARGET = 0x00100000 ,
SIXF_SETTRACER = 0x00200000 ,
SIXF_NOPOINTERS = 0x00400000 ,
SIXF_ORIGINATOR = 0x00800000 ,
SIXF_TRANSFERSPRITEFRAME = 0x01000000 ,
2015-02-14 22:51:05 +00:00
SIXF_TRANSFERROLL = 0x02000000 ,
2015-08-09 19:06:22 +00:00
SIXF_ISTARGET = 0x04000000 ,
SIXF_ISMASTER = 0x08000000 ,
SIXF_ISTRACER = 0x10000000 ,
2015-01-30 01:30:26 +00:00
} ;
static bool InitSpawnedItem ( AActor * self , AActor * mo , int flags )
{
if ( mo = = NULL )
{
return false ;
}
AActor * originator = self ;
if ( ! ( mo - > flags2 & MF2_DONTTRANSLATE ) )
{
if ( flags & SIXF_TRANSFERTRANSLATION )
{
mo - > Translation = self - > Translation ;
}
else if ( flags & SIXF_USEBLOODCOLOR )
{
// [XA] Use the spawning actor's BloodColor to translate the newly-spawned object.
2017-03-02 09:26:23 +00:00
mo - > Translation = self - > BloodTranslation ;
2015-01-30 01:30:26 +00:00
}
}
if ( flags & SIXF_TRANSFERPOINTERS )
{
mo - > target = self - > target ;
mo - > master = self - > master ; // This will be overridden later if SIXF_SETMASTER is set
mo - > tracer = self - > tracer ;
}
2016-03-16 11:41:26 +00:00
mo - > Angles . Yaw = self - > Angles . Yaw ;
2015-01-30 01:30:26 +00:00
if ( flags & SIXF_TRANSFERPITCH )
{
2016-03-16 11:41:26 +00:00
mo - > Angles . Pitch = self - > Angles . Pitch ;
2015-01-30 01:30:26 +00:00
}
if ( ! ( flags & SIXF_ORIGINATOR ) )
{
while ( originator & & originator - > isMissile ( ) )
{
originator = originator - > target ;
}
2016-01-19 15:09:44 +00:00
}
2015-01-30 01:30:26 +00:00
if ( flags & SIXF_TELEFRAG )
{
2016-01-19 19:15:45 +00:00
P_TeleportMove ( mo , mo - > Pos ( ) , true ) ;
2015-01-30 01:30:26 +00:00
// This is needed to ensure consistent behavior.
// Otherwise it will only spawn if nothing gets telefragged
flags | = SIXF_NOCHECKPOSITION ;
}
if ( mo - > flags3 & MF3_ISMONSTER )
{
if ( ! ( flags & SIXF_NOCHECKPOSITION ) & & ! P_TestMobjLocation ( mo ) )
{
// The monster is blocked so don't spawn it at all!
mo - > ClearCounters ( ) ;
mo - > Destroy ( ) ;
return false ;
}
else if ( originator & & ! ( flags & SIXF_NOPOINTERS ) )
{
if ( originator - > flags3 & MF3_ISMONSTER )
{
// If this is a monster transfer all friendliness information
mo - > CopyFriendliness ( originator , true ) ;
}
else if ( originator - > player )
{
// A player always spawns a monster friendly to him
mo - > flags | = MF_FRIENDLY ;
mo - > SetFriendPlayer ( originator - > player ) ;
AActor * attacker = originator - > player - > attacker ;
if ( attacker )
{
if ( ! ( attacker - > flags & MF_FRIENDLY ) | |
( deathmatch & & attacker - > FriendPlayer ! = 0 & & attacker - > FriendPlayer ! = mo - > FriendPlayer ) )
{
// Target the monster which last attacked the player
mo - > LastHeard = mo - > target = attacker ;
}
}
}
}
}
else if ( ! ( flags & SIXF_TRANSFERPOINTERS ) )
{
// If this is a missile or something else set the target to the originator
mo - > target = originator ? originator : self ;
}
if ( flags & SIXF_NOPOINTERS )
{
//[MC]Intentionally eliminate pointers. Overrides TRANSFERPOINTERS, but is overridden by SETMASTER/TARGET/TRACER.
mo - > LastHeard = NULL ; //Sanity check.
mo - > target = NULL ;
mo - > master = NULL ;
mo - > tracer = NULL ;
}
if ( flags & SIXF_SETMASTER )
2016-01-19 15:09:44 +00:00
{ // don't let it attack you (optional)!
2015-01-30 01:30:26 +00:00
mo - > master = originator ;
}
if ( flags & SIXF_SETTARGET )
{
mo - > target = originator ;
}
if ( flags & SIXF_SETTRACER )
{
mo - > tracer = originator ;
}
if ( flags & SIXF_TRANSFERSCALE )
{
2016-03-20 11:13:00 +00:00
mo - > Scale = self - > Scale ;
2015-01-30 01:30:26 +00:00
}
if ( flags & SIXF_TRANSFERAMBUSHFLAG )
{
mo - > flags = ( mo - > flags & ~ MF_AMBUSH ) | ( self - > flags & MF_AMBUSH ) ;
}
if ( flags & SIXF_CLEARCALLERTID )
{
self - > RemoveFromHash ( ) ;
self - > tid = 0 ;
}
if ( flags & SIXF_TRANSFERSPECIAL )
{
mo - > special = self - > special ;
memcpy ( mo - > args , self - > args , sizeof ( self - > args ) ) ;
}
if ( flags & SIXF_CLEARCALLERSPECIAL )
{
self - > special = 0 ;
memset ( self - > args , 0 , sizeof ( self - > args ) ) ;
}
if ( flags & SIXF_TRANSFERSTENCILCOL )
{
mo - > fillcolor = self - > fillcolor ;
}
if ( flags & SIXF_TRANSFERALPHA )
{
2016-03-21 11:18:46 +00:00
mo - > Alpha = self - > Alpha ;
2015-01-30 01:30:26 +00:00
}
if ( flags & SIXF_TRANSFERRENDERSTYLE )
{
mo - > RenderStyle = self - > RenderStyle ;
}
2015-02-07 16:04:33 +00:00
2015-04-04 16:40:43 +00:00
if ( flags & SIXF_TRANSFERSPRITEFRAME )
{
mo - > sprite = self - > sprite ;
mo - > frame = self - > frame ;
2015-02-07 16:04:33 +00:00
}
2015-01-30 01:30:26 +00:00
2015-02-14 22:51:05 +00:00
if ( flags & SIXF_TRANSFERROLL )
{
2016-03-16 11:41:26 +00:00
mo - > Angles . Roll = self - > Angles . Roll ;
2015-02-14 22:51:05 +00:00
}
2015-08-09 19:06:22 +00:00
if ( flags & SIXF_ISTARGET )
{
self - > target = mo ;
}
if ( flags & SIXF_ISMASTER )
{
self - > master = mo ;
}
if ( flags & SIXF_ISTRACER )
{
self - > tracer = mo ;
}
2015-01-30 01:30:26 +00:00
return true ;
}
//===========================================================================
//
// A_SpawnItem
//
// Spawns an item in front of the caller like Heretic's time bomb
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SpawnItem )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_ACTION_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_CLASS_DEF ( missile , AActor )
PARAM_FLOAT_DEF ( distance )
PARAM_FLOAT_DEF ( zheight )
PARAM_BOOL_DEF ( useammo )
2017-01-20 11:39:51 +00:00
PARAM_BOOL_DEF ( transfer_translation ) ;
2017-04-10 13:17:39 +00:00
if ( numret > 1 ) ret [ 1 ] . SetObject ( nullptr ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( missile = = NULL )
2015-01-30 01:30:26 +00:00
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( false ) ;
return MIN ( numret , 2 ) ;
2015-01-30 01:30:26 +00:00
}
// Don't spawn monsters if this actor has been massacred
2016-02-04 21:15:29 +00:00
if ( self - > DamageType = = NAME_Massacre & & ( GetDefaultByType ( missile ) - > flags3 & MF3_ISMONSTER ) )
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( true ) ;
return MIN ( numret , 2 ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
2016-06-17 07:26:33 +00:00
if ( ACTION_CALL_FROM_PSPRITE ( ) )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
// Used from a weapon, so use some ammo
AWeapon * weapon = self - > player - > ReadyWeapon ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( weapon = = NULL )
2016-02-19 03:39:13 +00:00
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( true ) ;
return MIN ( numret , 2 ) ;
2016-02-19 03:39:13 +00:00
}
2016-02-04 21:15:29 +00:00
if ( useammo & & ! weapon - > DepleteAmmo ( weapon - > bAltFire ) )
2016-02-19 03:39:13 +00:00
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( true ) ;
return MIN ( numret , 2 ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
}
2016-03-23 09:42:41 +00:00
AActor * mo = Spawn ( missile , self - > Vec3Angle ( distance , self - > Angles . Yaw , - self - > Floorclip + self - > GetBobOffset ( ) + zheight ) , ALLOW_REPLACE ) ;
2015-01-30 01:30:26 +00:00
int flags = ( transfer_translation ? SIXF_TRANSFERTRANSLATION : 0 ) + ( useammo ? SIXF_SETMASTER : 0 ) ;
2017-01-20 11:39:51 +00:00
bool res = InitSpawnedItem ( self , mo , flags ) ; // for an inventory item's use state
if ( numret > 0 ) ret [ 0 ] . SetInt ( res ) ;
2017-04-10 13:17:39 +00:00
if ( numret > 1 ) ret [ 1 ] . SetObject ( mo ) ;
2017-01-20 11:39:51 +00:00
return MIN ( numret , 2 ) ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SpawnItemEx
//
// Enhanced spawning function
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SpawnItemEx )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( missile , AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( xofs )
PARAM_FLOAT_DEF ( yofs )
PARAM_FLOAT_DEF ( zofs )
PARAM_FLOAT_DEF ( xvel )
PARAM_FLOAT_DEF ( yvel )
PARAM_FLOAT_DEF ( zvel )
PARAM_ANGLE_DEF ( angle )
PARAM_INT_DEF ( flags )
PARAM_INT_DEF ( chance )
PARAM_INT_DEF ( tid )
2016-02-04 21:15:29 +00:00
2017-04-10 13:17:39 +00:00
if ( numret > 1 ) ret [ 1 ] . SetObject ( nullptr ) ;
2017-01-20 11:39:51 +00:00
2016-02-04 21:15:29 +00:00
if ( missile = = NULL )
2015-01-30 01:30:26 +00:00
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( false ) ;
return MIN ( numret , 2 ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
if ( chance > 0 & & pr_spawnitemex ( ) < chance )
2016-02-19 03:39:13 +00:00
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( true ) ;
return MIN ( numret , 2 ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
// Don't spawn monsters if this actor has been massacred
2016-02-04 21:15:29 +00:00
if ( self - > DamageType = = NAME_Massacre & & ( GetDefaultByType ( missile ) - > flags3 & MF3_ISMONSTER ) )
2016-02-19 03:39:13 +00:00
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( true ) ;
return MIN ( numret , 2 ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
2016-03-23 09:42:41 +00:00
DVector2 pos ;
2015-01-30 01:30:26 +00:00
if ( ! ( flags & SIXF_ABSOLUTEANGLE ) )
{
2016-03-16 11:41:26 +00:00
angle + = self - > Angles . Yaw ;
2015-01-30 01:30:26 +00:00
}
2016-03-16 11:41:26 +00:00
double s = angle . Sin ( ) ;
double c = angle . Cos ( ) ;
2015-01-30 01:30:26 +00:00
if ( flags & SIXF_ABSOLUTEPOSITION )
{
2016-01-19 19:15:45 +00:00
pos = self - > Vec2Offset ( xofs , yofs ) ;
2015-01-30 01:30:26 +00:00
}
else
{
// in relative mode negative y values mean 'left' and positive ones mean 'right'
// This is the inverse orientation of the absolute mode!
2016-03-23 09:42:41 +00:00
pos = self - > Vec2Offset ( xofs * c + yofs * s , xofs * s - yofs * c ) ;
2015-01-30 01:30:26 +00:00
}
if ( ! ( flags & SIXF_ABSOLUTEVELOCITY ) )
{
// Same orientation issue here!
2016-03-19 23:54:18 +00:00
double newxvel = xvel * c + yvel * s ;
yvel = xvel * s - yvel * c ;
2015-01-30 01:30:26 +00:00
xvel = newxvel ;
}
2016-03-23 09:42:41 +00:00
AActor * mo = Spawn ( missile , DVector3 ( pos , self - > Z ( ) - self - > Floorclip + self - > GetBobOffset ( ) + zofs ) , ALLOW_REPLACE ) ;
2015-01-30 01:30:26 +00:00
bool res = InitSpawnedItem ( self , mo , flags ) ;
if ( res )
{
if ( tid ! = 0 )
{
assert ( mo - > tid = = 0 ) ;
mo - > tid = tid ;
mo - > AddToHash ( ) ;
}
2016-03-19 23:54:18 +00:00
mo - > Vel = { xvel , yvel , zvel } ;
2015-01-30 01:30:26 +00:00
if ( flags & SIXF_MULTIPLYSPEED )
{
2016-03-19 23:54:18 +00:00
mo - > Vel * = mo - > Speed ;
2015-01-30 01:30:26 +00:00
}
2016-03-16 11:41:26 +00:00
mo - > Angles . Yaw = angle ;
2015-01-30 01:30:26 +00:00
}
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( res ) ;
2017-04-10 13:17:39 +00:00
if ( numret > 1 ) ret [ 1 ] . SetObject ( mo ) ;
2017-01-20 11:39:51 +00:00
return MIN ( numret , 2 ) ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_ThrowGrenade
//
// Throws a grenade (like Hexen's fighter flechette)
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_ThrowGrenade )
2015-01-30 01:30:26 +00:00
{
2016-10-27 13:53:53 +00:00
PARAM_ACTION_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( missile , AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( zheight )
PARAM_FLOAT_DEF ( xyvel )
PARAM_FLOAT_DEF ( zvel )
PARAM_BOOL_DEF ( useammo )
2015-01-30 01:30:26 +00:00
2017-04-10 13:17:39 +00:00
if ( numret > 1 ) ret [ 1 ] . SetObject ( nullptr ) ;
2017-01-20 11:39:51 +00:00
2016-02-04 21:15:29 +00:00
if ( missile = = NULL )
2016-02-19 03:39:13 +00:00
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( false ) ;
return MIN ( numret , 2 ) ;
2016-02-19 03:39:13 +00:00
}
2016-06-17 07:26:33 +00:00
if ( ACTION_CALL_FROM_PSPRITE ( ) )
2015-01-30 01:30:26 +00:00
{
// Used from a weapon, so use some ammo
AWeapon * weapon = self - > player - > ReadyWeapon ;
2016-02-04 21:15:29 +00:00
if ( weapon = = NULL )
2016-02-19 03:39:13 +00:00
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( true ) ;
return MIN ( numret , 2 ) ;
2016-02-19 03:39:13 +00:00
}
2016-02-04 21:15:29 +00:00
if ( useammo & & ! weapon - > DepleteAmmo ( weapon - > bAltFire ) )
2016-02-19 03:39:13 +00:00
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( true ) ;
return MIN ( numret , 2 ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
AActor * bo ;
2015-01-30 01:30:26 +00:00
2016-01-19 19:15:45 +00:00
bo = Spawn ( missile ,
2016-03-23 09:42:41 +00:00
self - > PosPlusZ ( - self - > Floorclip + self - > GetBobOffset ( ) + zheight + 35 + ( self - > player ? self - > player - > crouchoffset : 0. ) ) ,
2015-01-30 01:30:26 +00:00
ALLOW_REPLACE ) ;
if ( bo )
{
P_PlaySpawnSound ( bo , self ) ;
if ( xyvel ! = 0 )
bo - > Speed = xyvel ;
2016-03-16 11:41:26 +00:00
bo - > Angles . Yaw = self - > Angles . Yaw + ( ( ( pr_grenade ( ) & 7 ) - 4 ) * ( 360. / 256. ) ) ;
2015-01-30 01:30:26 +00:00
2016-03-19 23:54:18 +00:00
DAngle pitch = - self - > Angles . Pitch ;
DAngle angle = bo - > Angles . Yaw ;
2015-01-30 01:30:26 +00:00
// There are two vectors we are concerned about here: xy and z. We rotate
// them separately according to the shooter's pitch and then sum them to
// get the final velocity vector to shoot with.
2016-03-19 23:54:18 +00:00
double xy_xyscale = bo - > Speed * pitch . Cos ( ) ;
double xy_velz = bo - > Speed * pitch . Sin ( ) ;
double xy_velx = xy_xyscale * angle . Cos ( ) ;
double xy_vely = xy_xyscale * angle . Sin ( ) ;
2015-01-30 01:30:26 +00:00
2016-03-19 23:54:18 +00:00
pitch = self - > Angles . Pitch ;
double z_xyscale = zvel * pitch . Sin ( ) ;
double z_velz = zvel * pitch . Cos ( ) ;
double z_velx = z_xyscale * angle . Cos ( ) ;
double z_vely = z_xyscale * angle . Sin ( ) ;
2015-01-30 01:30:26 +00:00
2016-03-19 23:54:18 +00:00
bo - > Vel . X = xy_velx + z_velx + self - > Vel . X / 2 ;
bo - > Vel . Y = xy_vely + z_vely + self - > Vel . Y / 2 ;
bo - > Vel . Z = xy_velz + z_velz ;
2015-01-30 01:30:26 +00:00
bo - > target = self ;
2017-01-20 11:39:51 +00:00
if ( ! P_CheckMissileSpawn ( bo , self - > radius ) ) bo = nullptr ;
if ( numret > 0 ) ret [ 0 ] . SetInt ( true ) ;
2017-04-10 13:17:39 +00:00
if ( numret > 1 ) ret [ 1 ] . SetObject ( bo ) ;
2017-01-20 11:39:51 +00:00
return MIN ( numret , 2 ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
else
{
2017-01-20 11:39:51 +00:00
if ( numret > 0 ) ret [ 0 ] . SetInt ( false ) ;
return MIN ( numret , 2 ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_Recoil
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Recoil )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-03-19 23:54:18 +00:00
PARAM_FLOAT ( xyvel ) ;
2015-01-30 01:30:26 +00:00
2016-03-19 23:54:18 +00:00
self - > Thrust ( self - > Angles . Yaw + 180. , xyvel ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SelectWeapon
//
//===========================================================================
2016-07-29 23:48:54 +00:00
enum SW_Flags
{
SWF_SELECTPRIORITY = 1 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SelectWeapon )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( cls , AWeapon ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
2016-07-29 23:48:54 +00:00
bool selectPriority = ! ! ( flags & SWF_SELECTPRIORITY ) ;
2015-01-30 01:30:26 +00:00
2016-07-29 23:48:54 +00:00
if ( ( ! selectPriority & & cls = = NULL ) | | self - > player = = NULL )
2015-01-30 01:30:26 +00:00
{
2016-02-19 02:39:40 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
AWeapon * weaponitem = static_cast < AWeapon * > ( self - > FindInventory ( cls ) ) ;
2015-01-30 01:30:26 +00:00
2017-02-08 14:47:22 +00:00
if ( weaponitem ! = NULL & & weaponitem - > IsKindOf ( NAME_Weapon ) )
2015-01-30 01:30:26 +00:00
{
if ( self - > player - > ReadyWeapon ! = weaponitem )
{
self - > player - > PendingWeapon = weaponitem ;
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_BOOL ( true ) ;
2015-01-30 01:30:26 +00:00
}
2016-07-29 23:48:54 +00:00
else if ( selectPriority )
{
// [XA] if the named weapon cannot be found (or is a dummy like 'None'),
// select the next highest priority weapon. This is basically
// the same as A_CheckReload minus the ammo check. Handy.
self - > player - > mo - > PickNewWeapon ( NULL ) ;
ACTION_RETURN_BOOL ( true ) ;
}
2016-02-04 21:15:29 +00:00
else
{
2016-02-19 02:39:40 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_Print
//
//===========================================================================
EXTERN_CVAR ( Float , con_midtime )
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Print )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_STRING ( text ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( time ) ;
PARAM_NAME_DEF ( fontname ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( text [ 0 ] = = ' $ ' ) text = GStrings ( & text [ 1 ] ) ;
2015-01-30 01:30:26 +00:00
if ( self - > CheckLocalView ( consoleplayer ) | |
2016-02-04 21:15:29 +00:00
( self - > target ! = NULL & & self - > target - > CheckLocalView ( consoleplayer ) ) )
2015-01-30 01:30:26 +00:00
{
float saved = con_midtime ;
FFont * font = NULL ;
if ( fontname ! = NAME_None )
{
font = V_GetFont ( fontname ) ;
}
if ( time > 0 )
{
2016-02-04 21:15:29 +00:00
con_midtime = float ( time ) ;
2015-01-30 01:30:26 +00:00
}
FString formatted = strbin1 ( text ) ;
C_MidPrint ( font ! = NULL ? font : SmallFont , formatted . GetChars ( ) ) ;
con_midtime = saved ;
}
2016-02-19 02:39:40 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_PrintBold
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_PrintBold )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_STRING ( text ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( time ) ;
PARAM_NAME_DEF ( fontname ) ;
2015-01-30 01:30:26 +00:00
float saved = con_midtime ;
FFont * font = NULL ;
2016-02-04 21:15:29 +00:00
if ( text [ 0 ] = = ' $ ' ) text = GStrings ( & text [ 1 ] ) ;
2015-01-30 01:30:26 +00:00
if ( fontname ! = NAME_None )
{
font = V_GetFont ( fontname ) ;
}
if ( time > 0 )
{
2016-02-04 21:15:29 +00:00
con_midtime = float ( time ) ;
2015-01-30 01:30:26 +00:00
}
FString formatted = strbin1 ( text ) ;
C_MidPrintBold ( font ! = NULL ? font : SmallFont , formatted . GetChars ( ) ) ;
con_midtime = saved ;
2016-02-19 02:39:40 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_Log
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Log )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_STRING ( text ) ;
2017-01-13 10:48:05 +00:00
PARAM_BOOL_DEF ( local ) ;
if ( local & & ! self - > CheckLocalView ( consoleplayer ) ) return 0 ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( text [ 0 ] = = ' $ ' ) text = GStrings ( & text [ 1 ] ) ;
2015-01-30 01:30:26 +00:00
FString formatted = strbin1 ( text ) ;
2015-02-26 14:46:01 +00:00
Printf ( " %s \n " , formatted . GetChars ( ) ) ;
2016-02-19 02:39:40 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//=========================================================================
//
// A_LogInt
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_LogInt )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( num ) ;
2017-01-13 10:48:05 +00:00
PARAM_BOOL_DEF ( local ) ;
if ( local & & ! self - > CheckLocalView ( consoleplayer ) ) return 0 ;
2015-01-30 01:30:26 +00:00
Printf ( " %d \n " , num ) ;
2016-02-19 02:39:40 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2016-04-03 20:36:23 +00:00
//=========================================================================
//
// A_LogFloat
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_LogFloat )
2016-04-03 20:36:23 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-04-03 20:36:23 +00:00
PARAM_FLOAT ( num ) ;
2017-01-13 10:48:05 +00:00
PARAM_BOOL_DEF ( local ) ;
if ( local & & ! self - > CheckLocalView ( consoleplayer ) ) return 0 ;
2016-04-03 20:36:23 +00:00
IGNORE_FORMAT_PRE
Printf ( " %H \n " , num ) ;
IGNORE_FORMAT_POST
return 0 ;
}
2015-01-30 01:30:26 +00:00
//===========================================================================
//
// A_SetTranslucent
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetTranslucent )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-03-21 11:18:46 +00:00
PARAM_FLOAT ( alpha ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( mode ) ;
2015-01-30 01:30:26 +00:00
mode = mode = = 0 ? STYLE_Translucent : mode = = 2 ? STYLE_Fuzzy : STYLE_Add ;
self - > RenderStyle . Flags & = ~ STYLEF_Alpha1 ;
2016-03-21 11:18:46 +00:00
self - > Alpha = clamp ( alpha , 0. , 1. ) ;
2015-01-30 01:30:26 +00:00
self - > RenderStyle = ERenderStyle ( mode ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2016-10-01 22:43:05 +00:00
//===========================================================================
//
// A_SetRenderStyle
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetRenderStyle )
2016-10-01 22:43:05 +00:00
{
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_FLOAT ( alpha ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( mode ) ;
2016-10-01 22:43:05 +00:00
self - > Alpha = clamp ( alpha , 0. , 1. ) ;
self - > RenderStyle = ERenderStyle ( mode ) ;
return 0 ;
}
2015-01-30 01:30:26 +00:00
//===========================================================================
//
// A_FadeIn
//
// Fades the actor in
//
//===========================================================================
enum FadeFlags
{
FTF_REMOVE = 1 < < 0 ,
FTF_CLAMP = 1 < < 1 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_FadeIn )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( reduce ) ;
PARAM_INT_DEF ( flags ) ;
2015-01-30 01:30:26 +00:00
if ( reduce = = 0 )
{
2016-03-21 11:18:46 +00:00
reduce = 0.1 ;
2015-01-30 01:30:26 +00:00
}
self - > RenderStyle . Flags & = ~ STYLEF_Alpha1 ;
2016-03-21 11:18:46 +00:00
self - > Alpha + = reduce ;
2015-01-30 01:30:26 +00:00
2016-03-21 11:18:46 +00:00
if ( self - > Alpha > = 1. )
2015-01-30 01:30:26 +00:00
{
if ( flags & FTF_CLAMP )
2016-01-19 15:09:44 +00:00
{
2016-03-21 11:18:46 +00:00
self - > Alpha = 1. ;
2016-01-19 15:09:44 +00:00
}
2015-01-30 01:30:26 +00:00
if ( flags & FTF_REMOVE )
2016-01-19 15:09:44 +00:00
{
2016-01-14 02:26:15 +00:00
P_RemoveThing ( self ) ;
2016-01-19 15:09:44 +00:00
}
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_FadeOut
//
// fades the actor out and destroys it when done
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_FadeOut )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( reduce ) ;
PARAM_INT_DEF ( flags ) ;
2015-01-30 01:30:26 +00:00
if ( reduce = = 0 )
{
2016-03-21 11:18:46 +00:00
reduce = 0.1 ;
2015-01-30 01:30:26 +00:00
}
self - > RenderStyle . Flags & = ~ STYLEF_Alpha1 ;
2016-03-21 11:18:46 +00:00
self - > Alpha - = reduce ;
if ( self - > Alpha < = 0 )
2015-01-30 01:30:26 +00:00
{
if ( flags & FTF_CLAMP )
2016-01-19 15:09:44 +00:00
{
2016-03-21 11:18:46 +00:00
self - > Alpha = 0 ;
2016-01-19 15:09:44 +00:00
}
2015-01-30 01:30:26 +00:00
if ( flags & FTF_REMOVE )
2016-01-19 15:09:44 +00:00
{
2016-01-14 02:26:15 +00:00
P_RemoveThing ( self ) ;
2016-01-19 15:09:44 +00:00
}
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_FadeTo
//
// fades the actor to a specified transparency by a specified amount and
// destroys it if so desired
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_FadeTo )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-03-21 11:18:46 +00:00
PARAM_FLOAT ( target ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( amount ) ;
PARAM_INT_DEF ( flags ) ;
2015-01-30 01:30:26 +00:00
self - > RenderStyle . Flags & = ~ STYLEF_Alpha1 ;
2016-03-21 11:18:46 +00:00
if ( self - > Alpha > target )
2015-01-30 01:30:26 +00:00
{
2016-03-21 11:18:46 +00:00
self - > Alpha - = amount ;
2015-01-30 01:30:26 +00:00
2016-03-21 11:18:46 +00:00
if ( self - > Alpha < target )
2015-01-30 01:30:26 +00:00
{
2016-03-21 11:18:46 +00:00
self - > Alpha = target ;
2015-01-30 01:30:26 +00:00
}
}
2016-03-21 11:18:46 +00:00
else if ( self - > Alpha < target )
2015-01-30 01:30:26 +00:00
{
2016-03-21 11:18:46 +00:00
self - > Alpha + = amount ;
2015-01-30 01:30:26 +00:00
2016-03-21 11:18:46 +00:00
if ( self - > Alpha > target )
2015-01-30 01:30:26 +00:00
{
2016-03-21 11:18:46 +00:00
self - > Alpha = target ;
2015-01-30 01:30:26 +00:00
}
}
if ( flags & FTF_CLAMP )
{
2016-03-21 11:18:46 +00:00
self - > Alpha = clamp ( self - > Alpha , 0. , 1. ) ;
2015-01-30 01:30:26 +00:00
}
2016-03-21 11:18:46 +00:00
if ( self - > Alpha = = target & & ( flags & FTF_REMOVE ) )
2015-01-30 01:30:26 +00:00
{
2016-01-14 02:26:15 +00:00
P_RemoveThing ( self ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SpawnDebris
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SpawnDebris )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( debris , AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_BOOL_DEF ( transfer_translation )
PARAM_FLOAT_DEF ( mult_h )
PARAM_FLOAT_DEF ( mult_v )
2015-01-30 01:30:26 +00:00
int i ;
2016-02-04 21:15:29 +00:00
AActor * mo ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( debris = = NULL )
return 0 ;
2015-01-30 01:30:26 +00:00
// only positive values make sense here
2016-03-19 23:54:18 +00:00
if ( mult_v < = 0 ) mult_v = 1 ;
if ( mult_h < = 0 ) mult_h = 1 ;
2015-01-30 01:30:26 +00:00
for ( i = 0 ; i < GetDefaultByType ( debris ) - > health ; i + + )
{
2016-03-23 09:42:41 +00:00
double xo = ( pr_spawndebris ( ) - 128 ) / 16. ;
double yo = ( pr_spawndebris ( ) - 128 ) / 16. ;
double zo = pr_spawndebris ( ) * self - > Height / 256 + self - > GetBobOffset ( ) ;
2016-01-20 08:25:30 +00:00
mo = Spawn ( debris , self - > Vec3Offset ( xo , yo , zo ) , ALLOW_REPLACE ) ;
2015-01-30 01:30:26 +00:00
if ( mo )
{
if ( transfer_translation )
{
mo - > Translation = self - > Translation ;
}
2017-04-11 20:44:35 +00:00
if ( i < mo - > GetInfo ( ) - > NumOwnedStates )
2015-01-30 01:30:26 +00:00
{
2017-04-11 20:44:35 +00:00
mo - > SetState ( mo - > GetInfo ( ) - > OwnedStates + i ) ;
2015-01-30 01:30:26 +00:00
}
2016-03-19 23:54:18 +00:00
mo - > Vel . X = mult_h * pr_spawndebris . Random2 ( ) / 64. ;
mo - > Vel . Y = mult_h * pr_spawndebris . Random2 ( ) / 64. ;
mo - > Vel . Z = mult_v * ( ( pr_spawndebris ( ) & 7 ) + 5 ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2015-12-08 09:58:24 +00:00
//===========================================================================
//
// A_SpawnParticle
//
//===========================================================================
2016-01-21 22:36:58 +00:00
enum SPFflag
{
2016-02-04 21:15:29 +00:00
SPF_FULLBRIGHT = 1 ,
SPF_RELPOS = 1 < < 1 ,
SPF_RELVEL = 1 < < 2 ,
SPF_RELACCEL = 1 < < 3 ,
SPF_RELANG = 1 < < 4 ,
2016-06-10 23:15:43 +00:00
SPF_NOTIMEFREEZE = 1 < < 5 ,
2016-01-21 22:36:58 +00:00
} ;
2016-01-21 23:58:42 +00:00
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SpawnParticle )
2015-12-08 09:58:24 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_COLOR ( color ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags )
PARAM_INT_DEF ( lifetime )
PARAM_FLOAT_DEF ( size )
PARAM_ANGLE_DEF ( angle )
PARAM_FLOAT_DEF ( xoff )
PARAM_FLOAT_DEF ( yoff )
PARAM_FLOAT_DEF ( zoff )
PARAM_FLOAT_DEF ( xvel )
PARAM_FLOAT_DEF ( yvel )
PARAM_FLOAT_DEF ( zvel )
PARAM_FLOAT_DEF ( accelx )
PARAM_FLOAT_DEF ( accely )
PARAM_FLOAT_DEF ( accelz )
PARAM_FLOAT_DEF ( startalpha )
PARAM_FLOAT_DEF ( fadestep )
PARAM_FLOAT_DEF ( sizestep )
2016-03-25 11:57:22 +00:00
startalpha = clamp ( startalpha , 0. , 1. ) ;
if ( fadestep > 0 ) fadestep = clamp ( fadestep , 0. , 1. ) ;
2016-06-10 23:15:43 +00:00
size = fabs ( size ) ;
2015-12-08 09:58:24 +00:00
if ( lifetime ! = 0 )
2016-01-21 16:04:52 +00:00
{
2016-03-25 11:57:22 +00:00
if ( flags & SPF_RELANG ) angle + = self - > Angles . Yaw ;
double s = angle . Sin ( ) ;
double c = angle . Cos ( ) ;
DVector3 pos ( xoff , yoff , zoff ) ;
DVector3 vel ( xvel , yvel , zvel ) ;
DVector3 acc ( accelx , accely , accelz ) ;
2016-01-21 22:36:58 +00:00
//[MC] Code ripped right out of A_SpawnItemEx.
if ( flags & SPF_RELPOS )
{
// in relative mode negative y values mean 'left' and positive ones mean 'right'
// This is the inverse orientation of the absolute mode!
2016-03-25 11:57:22 +00:00
pos . X = xoff * c + yoff * s ;
pos . Y = xoff * s - yoff * c ;
2016-01-21 22:36:58 +00:00
}
if ( flags & SPF_RELVEL )
{
2016-03-25 11:57:22 +00:00
vel . X = xvel * c + yvel * s ;
vel . Y = xvel * s - yvel * c ;
2016-01-21 22:36:58 +00:00
}
if ( flags & SPF_RELACCEL )
{
2016-03-25 11:57:22 +00:00
acc . X = accelx * c + accely * s ;
acc . Y = accelx * s - accely * c ;
2016-01-21 22:36:58 +00:00
}
2016-06-11 13:05:29 +00:00
P_SpawnParticle ( self - > Vec3Offset ( pos ) , vel , acc , color , startalpha , lifetime , size , fadestep , sizestep , flags ) ;
2016-01-21 16:04:52 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-12-08 09:58:24 +00:00
}
2015-01-30 01:30:26 +00:00
//===========================================================================
//
// A_CheckSight
// jumps if no player can see this actor
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckIfSeen )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2015-01-30 01:30:26 +00:00
for ( int i = 0 ; i < MAXPLAYERS ; i + + )
{
if ( playeringame [ i ] )
{
// Always check sight from each player.
if ( P_CheckSight ( players [ i ] . mo , self , SF_IGNOREVISIBILITY ) )
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
// If a player is viewing from a non-player, then check that too.
if ( players [ i ] . camera ! = NULL & & players [ i ] . camera - > player = = NULL & &
P_CheckSight ( players [ i ] . camera , self , SF_IGNOREVISIBILITY ) )
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
}
}
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( true ) ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_CheckSightOrRange
// Jumps if this actor is out of range of all players *and* out of sight.
// Useful for maps with many multi-actor special effects.
//
//===========================================================================
2016-03-25 11:57:22 +00:00
static bool DoCheckSightOrRange ( AActor * self , AActor * camera , double range , bool twodi , bool checksight )
2015-01-30 01:30:26 +00:00
{
if ( camera = = NULL )
{
return false ;
}
// Check distance first, since it's cheaper than checking sight.
2016-03-25 11:57:22 +00:00
DVector2 pos = camera - > Vec2To ( self ) ;
double dz ;
double eyez = camera - > Center ( ) ;
2016-01-19 19:15:45 +00:00
if ( eyez > self - > Top ( ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 19:15:45 +00:00
dz = self - > Top ( ) - eyez ;
2015-01-30 01:30:26 +00:00
}
2016-01-19 19:15:45 +00:00
else if ( eyez < self - > Z ( ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 19:15:45 +00:00
dz = self - > Z ( ) - eyez ;
2015-01-30 01:30:26 +00:00
}
else
{
dz = 0 ;
}
2016-03-25 11:57:22 +00:00
double distance = DVector3 ( pos , twodi ? 0. : dz ) . LengthSquared ( ) ;
2016-04-15 16:46:31 +00:00
if ( distance < = range )
2016-03-25 11:57:22 +00:00
{
2015-01-30 01:30:26 +00:00
// Within range
return true ;
}
// Now check LOS.
2016-03-25 11:57:22 +00:00
if ( checksight & & P_CheckSight ( camera , self , SF_IGNOREVISIBILITY ) )
2015-01-30 01:30:26 +00:00
{ // Visible
return true ;
}
return false ;
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckSightOrRange )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-22 01:21:39 +00:00
PARAM_FLOAT ( range ) ;
2016-10-27 13:53:53 +00:00
PARAM_BOOL_DEF ( twodi ) ;
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
range * = range ;
2015-01-30 01:30:26 +00:00
for ( int i = 0 ; i < MAXPLAYERS ; + + i )
{
if ( playeringame [ i ] )
{
// Always check from each player.
2016-03-25 11:57:22 +00:00
if ( DoCheckSightOrRange ( self , players [ i ] . mo , range , twodi , true ) )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
// If a player is viewing from a non-player, check that too.
if ( players [ i ] . camera ! = NULL & & players [ i ] . camera - > player = = NULL & &
2016-03-25 11:57:22 +00:00
DoCheckSightOrRange ( self , players [ i ] . camera , range , twodi , true ) )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
}
}
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( true ) ;
2015-01-30 01:30:26 +00:00
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckRange )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-22 01:21:39 +00:00
PARAM_FLOAT ( range ) ;
2016-10-27 13:53:53 +00:00
PARAM_BOOL_DEF ( twodi ) ;
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
range * = range ;
2015-01-30 01:30:26 +00:00
for ( int i = 0 ; i < MAXPLAYERS ; + + i )
{
if ( playeringame [ i ] )
{
// Always check from each player.
2016-03-25 11:57:22 +00:00
if ( DoCheckSightOrRange ( self , players [ i ] . mo , range , twodi , false ) )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
// If a player is viewing from a non-player, check that too.
if ( players [ i ] . camera ! = NULL & & players [ i ] . camera - > player = = NULL & &
2016-03-25 11:57:22 +00:00
DoCheckSightOrRange ( self , players [ i ] . camera , range , twodi , false ) )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
}
}
2016-11-14 16:50:09 +00:00
ACTION_RETURN_BOOL ( true ) ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// Inventory drop
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_DropInventory )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( drop , AInventory ) ;
2017-02-23 19:55:12 +00:00
PARAM_INT_DEF ( amount ) ;
2015-01-30 01:30:26 +00:00
if ( drop )
{
2016-02-04 21:15:29 +00:00
AInventory * inv = self - > FindInventory ( drop ) ;
2015-01-30 01:30:26 +00:00
if ( inv )
{
2017-02-23 19:55:12 +00:00
self - > DropInventory ( inv , amount ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SetBlend
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetBlend )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_COLOR ( color ) ;
PARAM_FLOAT ( alpha ) ;
PARAM_INT ( tics ) ;
2016-10-27 13:53:53 +00:00
PARAM_COLOR_DEF ( color2 ) ;
2017-12-28 01:21:11 +00:00
PARAM_FLOAT_DEF ( alpha2 ) ;
2016-02-04 21:15:29 +00:00
if ( color = = MAKEARGB ( 255 , 255 , 255 , 255 ) )
color = 0 ;
if ( color2 = = MAKEARGB ( 255 , 255 , 255 , 255 ) )
color2 = 0 ;
2017-12-28 01:21:11 +00:00
// if (color2.a == 0)
// color2 = color;
2015-01-30 01:30:26 +00:00
2017-04-14 11:31:58 +00:00
Create < DFlashFader > ( color . r / 255.f , color . g / 255.f , color . b / 255.f , float ( alpha ) ,
2017-12-28 01:21:11 +00:00
color2 . r / 255.f , color2 . g / 255.f , color2 . b / 255.f , float ( alpha2 ) ,
2017-12-28 04:24:23 +00:00
float ( tics ) / TICRATE , self , true ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_CountdownArg
//
//===========================================================================
2016-02-17 10:42:45 +00:00
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_CountdownArg )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-17 10:42:45 +00:00
PARAM_INT ( cnt ) ;
2016-10-27 13:53:53 +00:00
PARAM_STATE_DEF ( state )
2015-01-30 01:30:26 +00:00
2016-02-17 11:36:56 +00:00
if ( cnt < 0 | | cnt > = 5 ) return 0 ;
2016-02-17 10:42:45 +00:00
if ( ! self - > args [ cnt ] - - )
2015-01-30 01:30:26 +00:00
{
2016-02-17 10:42:45 +00:00
if ( self - > flags & MF_MISSILE )
2015-01-30 01:30:26 +00:00
{
2016-02-17 10:42:45 +00:00
P_ExplodeMissile ( self , NULL , NULL ) ;
}
else if ( self - > flags & MF_SHOOTABLE )
{
P_DamageMobj ( self , NULL , NULL , self - > health , NAME_None , DMG_FORCED ) ;
2015-01-30 01:30:26 +00:00
}
else
{
2016-10-27 13:53:53 +00:00
if ( state = = nullptr ) state = self - > FindState ( NAME_Death ) ;
2015-01-30 01:30:26 +00:00
self - > SetState ( state ) ;
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//============================================================================
//
// A_Burst
//
//============================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Burst )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( chunk , AActor ) ;
2015-01-30 01:30:26 +00:00
int i , numChunks ;
AActor * mo ;
2016-02-04 21:15:29 +00:00
if ( chunk = = NULL )
{
return 0 ;
}
2015-01-30 01:30:26 +00:00
2016-03-19 23:54:18 +00:00
self - > Vel . Zero ( ) ;
2016-03-20 19:55:06 +00:00
self - > Height = self - > GetDefault ( ) - > Height ;
2015-01-30 01:30:26 +00:00
// [RH] In Hexen, this creates a random number of shards (range [24,56])
// with no relation to the size of the self shattering. I think it should
// base the number of shards on the size of the dead thing, so bigger
// things break up into more shards than smaller things.
// An self with radius 20 and height 64 creates ~40 chunks.
2016-03-22 15:35:41 +00:00
numChunks = MAX < int > ( 4 , int ( self - > radius * self - > Height ) / 32 ) ;
2015-01-30 01:30:26 +00:00
i = ( pr_burst . Random2 ( ) ) % ( numChunks / 4 ) ;
for ( i = MAX ( 24 , numChunks + i ) ; i > = 0 ; i - - )
{
2016-03-22 15:35:41 +00:00
double xo = ( pr_burst ( ) - 128 ) * self - > radius / 128 ;
double yo = ( pr_burst ( ) - 128 ) * self - > radius / 128 ;
double zo = ( pr_burst ( ) * self - > Height / 255 ) ;
2016-01-20 08:25:30 +00:00
mo = Spawn ( chunk , self - > Vec3Offset ( xo , yo , zo ) , ALLOW_REPLACE ) ;
2015-01-30 01:30:26 +00:00
if ( mo )
{
2016-05-24 07:32:30 +00:00
mo - > Vel . Z = 4 * ( mo - > Z ( ) - self - > Z ( ) ) / self - > Height ;
2016-03-19 23:54:18 +00:00
mo - > Vel . X = pr_burst . Random2 ( ) / 128. ;
mo - > Vel . Y = pr_burst . Random2 ( ) / 128. ;
2015-01-30 01:30:26 +00:00
mo - > RenderStyle = self - > RenderStyle ;
2016-03-21 11:18:46 +00:00
mo - > Alpha = self - > Alpha ;
2015-01-30 01:30:26 +00:00
mo - > CopyFriendliness ( self , true ) ;
}
}
// [RH] Do some stuff to make this more useful outside Hexen
if ( self - > flags4 & MF4_BOSSDEATH )
{
2016-02-10 12:57:21 +00:00
A_BossDeath ( self ) ;
2015-01-30 01:30:26 +00:00
}
A_Unblock ( self , true ) ;
self - > Destroy ( ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_Stop
// resets all velocity of the actor to 0
//
//===========================================================================
DEFINE_ACTION_FUNCTION ( AActor , A_Stop )
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-03-19 23:54:18 +00:00
self - > Vel . Zero ( ) ;
2015-01-30 01:30:26 +00:00
if ( self - > player & & self - > player - > mo = = self & & ! ( self - > player - > cheats & CF_PREDICTING ) )
{
self - > player - > mo - > PlayIdle ( ) ;
2016-03-19 23:54:18 +00:00
self - > player - > Vel . Zero ( ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
static void CheckStopped ( AActor * self )
{
if ( self - > player ! = NULL & &
self - > player - > mo = = self & &
2016-03-19 23:54:18 +00:00
! ( self - > player - > cheats & CF_PREDICTING ) & & ! self - > Vel . isZero ( ) )
2015-01-30 01:30:26 +00:00
{
self - > player - > mo - > PlayIdle ( ) ;
2016-03-19 23:54:18 +00:00
self - > player - > Vel . Zero ( ) ;
2015-01-30 01:30:26 +00:00
}
}
//===========================================================================
//
// A_Respawn
//
//===========================================================================
enum RS_Flags
{
RSF_FOG = 1 ,
RSF_KEEPTARGET = 2 ,
RSF_TELEFRAG = 4 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Respawn )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
bool oktorespawn = false ;
2016-03-23 09:42:41 +00:00
DVector3 pos = self - > Pos ( ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
self - > flags | = MF_SOLID ;
2016-03-20 19:55:06 +00:00
self - > Height = self - > GetDefault ( ) - > Height ;
2015-08-11 15:12:16 +00:00
self - > radius = self - > GetDefault ( ) - > radius ;
2016-11-30 16:15:01 +00:00
self - > RestoreSpecialPosition ( ) ;
2015-01-30 01:30:26 +00:00
if ( flags & RSF_TELEFRAG )
{
// [KS] DIE DIE DIE DIE erm *ahem* =)
2016-01-19 19:15:45 +00:00
oktorespawn = P_TeleportMove ( self , self - > Pos ( ) , true , false ) ;
2015-01-30 01:30:26 +00:00
}
else
{
2016-03-23 09:42:41 +00:00
oktorespawn = P_CheckPosition ( self , self - > Pos ( ) , true ) ;
2015-01-30 01:30:26 +00:00
}
if ( oktorespawn )
{
AActor * defs = self - > GetDefault ( ) ;
self - > health = defs - > health ;
// [KS] Don't keep target, because it could be self if the monster committed suicide
// ...Actually it's better off an option, so you have better control over monster behavior.
if ( ! ( flags & RSF_KEEPTARGET ) )
{
self - > target = NULL ;
self - > LastHeard = NULL ;
self - > lastenemy = NULL ;
}
else
{
// Don't attack yourself (Re: "Marine targets itself after suicide")
2016-01-19 15:09:44 +00:00
if ( self - > target = = self )
self - > target = NULL ;
if ( self - > lastenemy = = self )
self - > lastenemy = NULL ;
2015-01-30 01:30:26 +00:00
}
self - > flags = ( defs - > flags & ~ MF_FRIENDLY ) | ( self - > flags & MF_FRIENDLY ) ;
self - > flags2 = defs - > flags2 ;
self - > flags3 = ( defs - > flags3 & ~ ( MF3_NOSIGHTCHECK | MF3_HUNTPLAYERS ) ) | ( self - > flags3 & ( MF3_NOSIGHTCHECK | MF3_HUNTPLAYERS ) ) ;
self - > flags4 = ( defs - > flags4 & ~ MF4_NOHATEPLAYERS ) | ( self - > flags4 & MF4_NOHATEPLAYERS ) ;
self - > flags5 = defs - > flags5 ;
self - > flags6 = defs - > flags6 ;
self - > flags7 = defs - > flags7 ;
2017-05-14 16:26:31 +00:00
self - > flags8 = defs - > flags8 ;
2015-01-30 01:30:26 +00:00
self - > SetState ( self - > SpawnState ) ;
self - > renderflags & = ~ RF_INVISIBLE ;
if ( flags & RSF_FOG )
{
2016-01-19 19:15:45 +00:00
P_SpawnTeleportFog ( self , pos , true , true ) ;
P_SpawnTeleportFog ( self , self - > Pos ( ) , false , true ) ;
2015-01-30 01:30:26 +00:00
}
if ( self - > CountsAsKill ( ) )
{
level . total_monsters + + ;
}
}
else
{
self - > flags & = ~ MF_SOLID ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_PlayerSkinCheck
//
//==========================================================================
2016-11-14 13:12:27 +00:00
DEFINE_ACTION_FUNCTION ( AActor , PlayerSkinCheck )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2015-01-30 01:30:26 +00:00
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( self - > player ! = NULL & &
2017-02-17 20:51:23 +00:00
Skins [ self - > player - > userinfo . GetSkin ( ) ] . othergame ) ;
2015-01-30 01:30:26 +00:00
}
// [KS] *** Start of my modifications ***
//==========================================================================
//
// A_CheckLOF (state jump, int flags = CRF_AIM_VERT|CRF_AIM_HOR,
// fixed range = 0, angle angle = 0, angle pitch = 0,
// fixed offsetheight = 32, fixed offsetwidth = 0,
// int ptr_target = AAPTR_DEFAULT (target) )
//
//==========================================================================
enum CLOF_flags
{
CLOFF_NOAIM_VERT = 0x00000001 ,
CLOFF_NOAIM_HORZ = 0x00000002 ,
CLOFF_JUMPENEMY = 0x00000004 ,
CLOFF_JUMPFRIEND = 0x00000008 ,
CLOFF_JUMPOBJECT = 0x00000010 ,
CLOFF_JUMPNONHOSTILE = 0x00000020 ,
CLOFF_SKIPENEMY = 0x00000040 ,
CLOFF_SKIPFRIEND = 0x00000080 ,
CLOFF_SKIPOBJECT = 0x00000100 ,
CLOFF_SKIPNONHOSTILE = 0x00000200 ,
CLOFF_MUSTBESHOOTABLE = 0x00000400 ,
CLOFF_SKIPTARGET = 0x00000800 ,
CLOFF_ALLOWNULL = 0x00001000 ,
CLOFF_CHECKPARTIAL = 0x00002000 ,
CLOFF_MUSTBEGHOST = 0x00004000 ,
CLOFF_IGNOREGHOST = 0x00008000 ,
CLOFF_MUSTBESOLID = 0x00010000 ,
CLOFF_BEYONDTARGET = 0x00020000 ,
CLOFF_FROMBASE = 0x00040000 ,
CLOFF_MUL_HEIGHT = 0x00080000 ,
CLOFF_MUL_WIDTH = 0x00100000 ,
CLOFF_JUMP_ON_MISS = 0x00200000 ,
CLOFF_AIM_VERT_NOOFFSET = 0x00400000 ,
CLOFF_SETTARGET = 0x00800000 ,
CLOFF_SETMASTER = 0x01000000 ,
CLOFF_SETTRACER = 0x02000000 ,
} ;
struct LOFData
{
AActor * Self ;
AActor * Target ;
int Flags ;
bool BadActor ;
} ;
ETraceStatus CheckLOFTraceFunc ( FTraceResults & trace , void * userdata )
{
LOFData * data = ( LOFData * ) userdata ;
int flags = data - > Flags ;
if ( trace . HitType ! = TRACE_HitActor )
{
return TRACE_Stop ;
}
if ( trace . Actor = = data - > Target )
{
if ( flags & CLOFF_SKIPTARGET )
{
if ( flags & CLOFF_BEYONDTARGET )
{
return TRACE_Skip ;
}
return TRACE_Abort ;
}
return TRACE_Stop ;
}
if ( flags & CLOFF_MUSTBESHOOTABLE )
{ // all shootability checks go here
if ( ! ( trace . Actor - > flags & MF_SHOOTABLE ) )
{
return TRACE_Skip ;
}
if ( trace . Actor - > flags2 & MF2_NONSHOOTABLE )
{
return TRACE_Skip ;
}
}
if ( ( flags & CLOFF_MUSTBESOLID ) & & ! ( trace . Actor - > flags & MF_SOLID ) )
{
return TRACE_Skip ;
}
if ( flags & CLOFF_MUSTBEGHOST )
{
if ( ! ( trace . Actor - > flags3 & MF3_GHOST ) )
{
return TRACE_Skip ;
}
}
else if ( flags & CLOFF_IGNOREGHOST )
{
if ( trace . Actor - > flags3 & MF3_GHOST )
{
return TRACE_Skip ;
}
}
if (
( ( flags & CLOFF_JUMPENEMY ) & & data - > Self - > IsHostile ( trace . Actor ) ) | |
( ( flags & CLOFF_JUMPFRIEND ) & & data - > Self - > IsFriend ( trace . Actor ) ) | |
( ( flags & CLOFF_JUMPOBJECT ) & & ! ( trace . Actor - > flags3 & MF3_ISMONSTER ) ) | |
( ( flags & CLOFF_JUMPNONHOSTILE ) & & ( trace . Actor - > flags3 & MF3_ISMONSTER ) & & ! data - > Self - > IsHostile ( trace . Actor ) )
)
{
return TRACE_Stop ;
}
if (
( ( flags & CLOFF_SKIPENEMY ) & & data - > Self - > IsHostile ( trace . Actor ) ) | |
( ( flags & CLOFF_SKIPFRIEND ) & & data - > Self - > IsFriend ( trace . Actor ) ) | |
( ( flags & CLOFF_SKIPOBJECT ) & & ! ( trace . Actor - > flags3 & MF3_ISMONSTER ) ) | |
( ( flags & CLOFF_SKIPNONHOSTILE ) & & ( trace . Actor - > flags3 & MF3_ISMONSTER ) & & ! data - > Self - > IsHostile ( trace . Actor ) )
)
{
return TRACE_Skip ;
}
data - > BadActor = true ;
return TRACE_Abort ;
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckLOF )
2015-01-30 01:30:26 +00:00
{
// Check line of fire
/*
Not accounted for / I don ' t know how it works : FLOORCLIP
*/
AActor * target ;
2016-03-25 11:57:22 +00:00
DVector3 pos ;
DVector3 vel ;
2015-01-30 01:30:26 +00:00
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 15:47:46 +00:00
PARAM_INT_DEF ( flags )
PARAM_FLOAT_DEF ( range )
PARAM_FLOAT_DEF ( minrange )
PARAM_ANGLE_DEF ( angle )
PARAM_ANGLE_DEF ( pitch )
PARAM_FLOAT_DEF ( offsetheight )
PARAM_FLOAT_DEF ( offsetwidth )
PARAM_INT_DEF ( ptr_target )
PARAM_FLOAT_DEF ( offsetforward )
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
DAngle ang ;
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
target = COPY_AAPTR ( self , ptr_target = = AAPTR_DEFAULT ? AAPTR_TARGET | AAPTR_PLAYER_GETTARGET | AAPTR_NULL : ptr_target ) ; // no player-support by default
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
if ( flags & CLOFF_MUL_HEIGHT )
{
if ( self - > player ! = NULL )
2015-01-30 01:30:26 +00:00
{
2016-03-25 11:57:22 +00:00
// Synced with hitscan: self->player->mo->height is strangely conscientious about getting the right actor for player
offsetheight * = self - > player - > mo - > Height * self - > player - > crouchfactor ;
2015-01-30 01:30:26 +00:00
}
2016-03-25 11:57:22 +00:00
else
2015-01-30 01:30:26 +00:00
{
2016-03-25 11:57:22 +00:00
offsetheight * = self - > Height ;
2015-01-30 01:30:26 +00:00
}
2016-03-25 11:57:22 +00:00
}
if ( flags & CLOFF_MUL_WIDTH )
{
offsetforward * = self - > radius ;
offsetwidth * = self - > radius ;
2016-04-03 19:26:57 +00:00
}
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
pos = self - > PosPlusZ ( offsetheight - self - > Floorclip ) ;
2015-01-30 01:30:26 +00:00
if ( ! ( flags & CLOFF_FROMBASE ) )
{ // default to hitscan origin
2016-03-25 17:19:54 +00:00
// Synced with hitscan: self->Height is strangely NON-conscientious about getting the right actor for player
2016-03-25 11:57:22 +00:00
pos . Z + = self - > Height * 0.5 ;
2015-01-30 01:30:26 +00:00
if ( self - > player ! = NULL )
{
2016-03-25 11:57:22 +00:00
pos . Z + = self - > player - > mo - > AttackZOffset * self - > player - > crouchfactor ;
2015-01-30 01:30:26 +00:00
}
else
{
2016-03-25 11:57:22 +00:00
pos . Z + = 8 ;
2015-01-30 01:30:26 +00:00
}
}
if ( target )
{
2016-03-17 10:38:56 +00:00
if ( range > 0 & & ! ( flags & CLOFF_CHECKPARTIAL ) )
2015-01-30 01:30:26 +00:00
{
2016-03-17 10:38:56 +00:00
double distance = self - > Distance3D ( target ) ;
2016-02-04 21:15:29 +00:00
if ( distance > range )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
}
2016-03-25 11:57:22 +00:00
if ( flags & CLOFF_NOAIM_HORZ )
2015-01-30 01:30:26 +00:00
{
2016-03-25 11:57:22 +00:00
ang = self - > Angles . Yaw ;
}
else ang = self - > AngleTo ( target ) ;
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
angle + = ang ;
2016-01-19 19:15:45 +00:00
2016-03-25 11:57:22 +00:00
double s = ang . Sin ( ) ;
double c = ang . Cos ( ) ;
2016-03-17 10:38:56 +00:00
2016-03-25 11:57:22 +00:00
DVector2 xy = self - > Vec2Offset ( offsetforward * c + offsetwidth * s , offsetforward * s - offsetwidth * c ) ;
2016-01-19 19:15:45 +00:00
2016-03-25 11:57:22 +00:00
pos . X = xy . X ;
pos . Y = xy . Y ;
2015-01-30 01:30:26 +00:00
2016-03-17 10:38:56 +00:00
double xydist = self - > Distance2D ( target ) ;
2015-01-30 01:30:26 +00:00
if ( flags & CLOFF_NOAIM_VERT )
{
2016-03-17 10:38:56 +00:00
pitch + = self - > Angles . Pitch ;
2015-01-30 01:30:26 +00:00
}
else if ( flags & CLOFF_AIM_VERT_NOOFFSET )
{
2016-03-25 11:57:22 +00:00
pitch - = VecToAngle ( xydist , target - > Center ( ) - pos . Z + offsetheight ) ;
2015-01-30 01:30:26 +00:00
}
else
{
2016-04-03 19:26:57 +00:00
pitch - = VecToAngle ( xydist , target - > Center ( ) - pos . Z ) ;
2015-01-30 01:30:26 +00:00
}
}
else if ( flags & CLOFF_ALLOWNULL )
{
2016-03-17 10:38:56 +00:00
angle + = self - > Angles . Yaw ;
pitch + = self - > Angles . Pitch ;
2015-01-30 01:30:26 +00:00
2016-03-17 10:38:56 +00:00
double s = angle . Sin ( ) ;
double c = angle . Cos ( ) ;
2016-01-19 19:15:45 +00:00
2016-03-25 11:57:22 +00:00
DVector2 xy = self - > Vec2Offset ( offsetforward * c + offsetwidth * s , offsetforward * s - offsetwidth * c ) ;
2016-01-19 19:15:45 +00:00
2016-03-25 11:57:22 +00:00
pos . X = xy . X ;
pos . Y = xy . Y ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
else
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
2016-03-17 10:38:56 +00:00
double cp = pitch . Cos ( ) ;
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
vel = { cp * angle . Cos ( ) , cp * angle . Sin ( ) , - pitch . Sin ( ) } ;
2015-01-30 01:30:26 +00:00
/* Variable set:
jump , flags , target
2016-03-25 11:57:22 +00:00
pos ( trace point of origin )
vel ( trace unit vector )
2015-01-30 01:30:26 +00:00
range
*/
2016-03-25 11:57:22 +00:00
sector_t * sec = P_PointInSector ( pos ) ;
2015-01-30 01:30:26 +00:00
if ( range = = 0 )
{
range = ( self - > player ! = NULL ) ? PLAYERMISSILERANGE : MISSILERANGE ;
}
FTraceResults trace ;
LOFData lof_data ;
lof_data . Self = self ;
lof_data . Target = target ;
lof_data . Flags = flags ;
lof_data . BadActor = false ;
2016-03-25 11:57:22 +00:00
Trace ( pos , sec , vel , range , ActorFlags : : FromInt ( 0xFFFFFFFF ) , ML_BLOCKEVERYTHING , self , trace , TRACE_PortalRestrict ,
2015-01-30 01:30:26 +00:00
CheckLOFTraceFunc , & lof_data ) ;
if ( trace . HitType = = TRACE_HitActor | |
( ( flags & CLOFF_JUMP_ON_MISS ) & & ! lof_data . BadActor & & trace . HitType ! = TRACE_HitNone ) )
{
if ( minrange > 0 & & trace . Distance < minrange )
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
if ( ( trace . HitType = = TRACE_HitActor ) & & ( trace . Actor ! = NULL ) & & ! ( lof_data . BadActor ) )
{
if ( flags & ( CLOFF_SETTARGET ) ) self - > target = trace . Actor ;
if ( flags & ( CLOFF_SETMASTER ) ) self - > master = trace . Actor ;
if ( flags & ( CLOFF_SETTRACER ) ) self - > tracer = trace . Actor ;
}
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( true ) ;
2015-01-30 01:30:26 +00:00
}
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_JumpIfTargetInLOS (state label, optional fixed fov, optional int flags,
// optional fixed dist_max, optional fixed dist_close)
//
// Jumps if the actor can see its target, or if the player has a linetarget.
// ProjectileTarget affects how projectiles are treated. If set, it will use
// the target of the projectile for seekers, and ignore the target for
// normal projectiles. If not set, it will use the missile's owner instead
// (the default). ProjectileTarget is now flag JLOSF_PROJECTILE. dist_max
// sets the maximum distance that actor can see, 0 means forever. dist_close
// uses special behavior if certain flags are set, 0 means no checks.
//
//==========================================================================
enum JLOS_flags
{
2016-02-04 21:15:29 +00:00
JLOSF_PROJECTILE = 1 < < 0 ,
2015-01-30 01:30:26 +00:00
JLOSF_NOSIGHT = 1 < < 1 ,
2016-02-04 21:15:29 +00:00
JLOSF_CLOSENOFOV = 1 < < 2 ,
2015-01-30 01:30:26 +00:00
JLOSF_CLOSENOSIGHT = 1 < < 3 ,
JLOSF_CLOSENOJUMP = 1 < < 4 ,
JLOSF_DEADNOJUMP = 1 < < 5 ,
JLOSF_CHECKMASTER = 1 < < 6 ,
JLOSF_TARGETLOS = 1 < < 7 ,
JLOSF_FLIPFOV = 1 < < 8 ,
JLOSF_ALLYNOJUMP = 1 < < 9 ,
JLOSF_COMBATANTONLY = 1 < < 10 ,
JLOSF_NOAUTOAIM = 1 < < 11 ,
JLOSF_CHECKTRACER = 1 < < 12 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckIfTargetInLOS )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_ANGLE_DEF ( fov )
PARAM_INT_DEF ( flags )
PARAM_FLOAT_DEF ( dist_max )
PARAM_FLOAT_DEF ( dist_close )
2015-01-30 01:30:26 +00:00
AActor * target , * viewport ;
2016-03-01 15:38:45 +00:00
FTranslatedLineTarget t ;
2015-01-30 01:30:26 +00:00
bool doCheckSight ;
if ( ! self - > player )
{
if ( flags & JLOSF_CHECKMASTER )
{
target = self - > master ;
}
else if ( ( self - > flags & MF_MISSILE & & ( flags & JLOSF_PROJECTILE ) ) | | ( flags & JLOSF_CHECKTRACER ) )
{
if ( ( self - > flags2 & MF2_SEEKERMISSILE ) | | ( flags & JLOSF_CHECKTRACER ) )
target = self - > tracer ;
else
target = NULL ;
}
else
{
target = self - > target ;
}
2016-01-19 15:09:44 +00:00
if ( target = = NULL )
2016-02-19 03:39:13 +00:00
{ // [KS] Let's not call P_CheckSight unnecessarily in this case.
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2016-01-19 15:09:44 +00:00
if ( ( flags & JLOSF_DEADNOJUMP ) & & ( target - > health < = 0 ) )
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-01-19 15:09:44 +00:00
}
2015-01-30 01:30:26 +00:00
doCheckSight = ! ( flags & JLOSF_NOSIGHT ) ;
}
else
{
// Does the player aim at something that can be shot?
2016-03-17 10:38:56 +00:00
P_AimLineAttack ( self , self - > Angles . Yaw , MISSILERANGE , & t , ( flags & JLOSF_NOAUTOAIM ) ? 0.5 : 0. , ALF_PORTALRESTRICT ) ;
2015-01-30 01:30:26 +00:00
2016-03-01 15:38:45 +00:00
if ( ! t . linetarget )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2016-03-01 15:38:45 +00:00
target = t . linetarget ;
2015-01-30 01:30:26 +00:00
switch ( flags & ( JLOSF_TARGETLOS | JLOSF_FLIPFOV ) )
{
case JLOSF_TARGETLOS | JLOSF_FLIPFOV :
// target makes sight check, player makes fov check; player has verified fov
2016-03-25 11:57:22 +00:00
fov = 0. ;
2015-01-30 01:30:26 +00:00
// fall-through
case JLOSF_TARGETLOS :
doCheckSight = ! ( flags & JLOSF_NOSIGHT ) ; // The target is responsible for sight check and fov
break ;
default :
// player has verified sight and fov
2016-03-25 11:57:22 +00:00
fov = 0. ;
2015-01-30 01:30:26 +00:00
// fall-through
case JLOSF_FLIPFOV : // Player has verified sight, but target must verify fov
doCheckSight = false ;
break ;
}
}
// [FDARI] If target is not a combatant, don't jump
2016-02-04 21:15:29 +00:00
if ( ( flags & JLOSF_COMBATANTONLY ) & & ( ! target - > player ) & & ! ( target - > flags3 & MF3_ISMONSTER ) )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
// [FDARI] If actors share team, don't jump
2016-02-04 21:15:29 +00:00
if ( ( flags & JLOSF_ALLYNOJUMP ) & & self - > IsFriend ( target ) )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2016-03-25 11:57:22 +00:00
double distance = self - > Distance3D ( target ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( dist_max & & ( distance > dist_max ) )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
if ( dist_close & & ( distance < dist_close ) )
{
if ( flags & JLOSF_CLOSENOJUMP )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
if ( flags & JLOSF_CLOSENOFOV )
2016-03-25 11:57:22 +00:00
fov = 0. ;
2015-01-30 01:30:26 +00:00
if ( flags & JLOSF_CLOSENOSIGHT )
doCheckSight = false ;
}
if ( flags & JLOSF_TARGETLOS ) { viewport = target ; target = self ; }
else { viewport = self ; }
if ( doCheckSight & & ! P_CheckSight ( viewport , target , SF_IGNOREVISIBILITY ) )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
if ( flags & JLOSF_FLIPFOV )
{
if ( viewport = = self ) { viewport = target ; target = self ; }
else { target = viewport ; viewport = self ; }
}
2016-09-04 08:22:59 +00:00
fov = MIN < DAngle > ( fov , 360. ) ;
2016-09-04 06:33:19 +00:00
if ( fov > 0 )
2015-01-30 01:30:26 +00:00
{
2016-03-25 11:57:22 +00:00
DAngle an = absangle ( viewport - > AngleTo ( target ) , viewport - > Angles . Yaw ) ;
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
if ( an > ( fov / 2 ) )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ; // [KS] Outside of FOV - return
2015-01-30 01:30:26 +00:00
}
}
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( true ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_JumpIfInTargetLOS (state label, optional fixed fov, optional int flags
// optional fixed dist_max, optional fixed dist_close)
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckIfInTargetLOS )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_ANGLE_DEF ( fov )
PARAM_INT_DEF ( flags )
PARAM_FLOAT_DEF ( dist_max )
PARAM_FLOAT_DEF ( dist_close )
2015-01-30 01:30:26 +00:00
AActor * target ;
if ( flags & JLOSF_CHECKMASTER )
{
target = self - > master ;
}
else if ( self - > flags & MF_MISSILE & & ( flags & JLOSF_PROJECTILE ) )
{
if ( self - > flags2 & MF2_SEEKERMISSILE )
target = self - > tracer ;
else
target = NULL ;
}
else
{
target = self - > target ;
}
2016-02-04 21:15:29 +00:00
if ( target = = NULL )
{ // [KS] Let's not call P_CheckSight unnecessarily in this case.
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( ( flags & JLOSF_DEADNOJUMP ) & & ( target - > health < = 0 ) )
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
double distance = self - > Distance3D ( target ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
if ( dist_max & & ( distance > dist_max ) )
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
bool doCheckSight = ! ( flags & JLOSF_NOSIGHT ) ;
if ( dist_close & & ( distance < dist_close ) )
{
if ( flags & JLOSF_CLOSENOJUMP )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2015-01-30 01:30:26 +00:00
if ( flags & JLOSF_CLOSENOFOV )
2016-03-25 11:57:22 +00:00
fov = 0. ;
2015-01-30 01:30:26 +00:00
if ( flags & JLOSF_CLOSENOSIGHT )
doCheckSight = false ;
}
2016-03-25 11:57:22 +00:00
if ( fov > 0 & & ( fov < 360. ) )
2015-01-30 01:30:26 +00:00
{
2016-03-25 11:57:22 +00:00
DAngle an = absangle ( target - > AngleTo ( self ) , target - > Angles . Yaw ) ;
2015-01-30 01:30:26 +00:00
2016-03-25 11:57:22 +00:00
if ( an > ( fov / 2 ) )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ; // [KS] Outside of FOV - return
2015-01-30 01:30:26 +00:00
}
}
if ( doCheckSight & & ! P_CheckSight ( target , self , SF_IGNOREVISIBILITY ) )
2016-02-19 03:39:13 +00:00
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( true ) ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// Modified code pointer from Skulltag
//
//===========================================================================
2016-12-02 17:52:58 +00:00
DEFINE_ACTION_FUNCTION ( AStateProvider , A_CheckForReload )
2015-01-30 01:30:26 +00:00
{
2016-12-02 17:52:58 +00:00
PARAM_ACTION_PROLOGUE ( AStateProvider ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
if ( self - > player = = NULL | | self - > player - > ReadyWeapon = = NULL )
2016-02-19 03:39:13 +00:00
{
2016-02-19 02:39:40 +00:00
ACTION_RETURN_STATE ( NULL ) ;
2016-02-19 03:39:13 +00:00
}
2016-02-22 01:21:39 +00:00
PARAM_INT ( count ) ;
2016-11-14 13:12:27 +00:00
PARAM_STATE_ACTION ( jump ) ;
2016-10-27 13:53:53 +00:00
PARAM_BOOL_DEF ( dontincrement ) ;
2015-01-30 01:30:26 +00:00
2016-02-19 02:39:40 +00:00
if ( numret > 0 )
{
2017-04-10 13:17:39 +00:00
ret - > SetPointer ( NULL ) ;
2016-02-19 02:39:40 +00:00
numret = 1 ;
}
2015-01-30 01:30:26 +00:00
AWeapon * weapon = self - > player - > ReadyWeapon ;
int ReloadCounter = weapon - > ReloadCounter ;
2016-02-04 21:15:29 +00:00
if ( ! dontincrement | | ReloadCounter ! = 0 )
2015-01-30 01:30:26 +00:00
ReloadCounter = ( weapon - > ReloadCounter + 1 ) % count ;
else // 0 % 1 = 1? So how do we check if the weapon was never fired? We should only do this when we're not incrementing the counter though.
ReloadCounter = 1 ;
// If we have not made our last shot...
if ( ReloadCounter ! = 0 )
{
// Go back to the refire frames, instead of continuing on to the reload frames.
2016-02-19 02:39:40 +00:00
if ( numret ! = 0 )
{
2017-04-10 13:17:39 +00:00
ret - > SetPointer ( jump ) ;
2016-02-19 02:39:40 +00:00
}
2015-01-30 01:30:26 +00:00
}
else
{
// We need to reload. However, don't reload if we're out of ammo.
2016-01-19 15:09:44 +00:00
weapon - > CheckAmmo ( false , false ) ;
2015-01-30 01:30:26 +00:00
}
2016-01-19 15:09:44 +00:00
if ( ! dontincrement )
2016-02-19 02:39:40 +00:00
{
2015-01-30 01:30:26 +00:00
weapon - > ReloadCounter = ReloadCounter ;
2016-02-19 02:39:40 +00:00
}
return numret ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// Resets the counter for the above function
//
//===========================================================================
2016-12-02 17:52:58 +00:00
DEFINE_ACTION_FUNCTION ( AStateProvider , A_ResetReloadCounter )
2015-01-30 01:30:26 +00:00
{
2016-12-02 17:52:58 +00:00
PARAM_ACTION_PROLOGUE ( AStateProvider ) ;
2016-02-04 21:15:29 +00:00
if ( self - > player = = NULL | | self - > player - > ReadyWeapon = = NULL )
return 0 ;
2015-01-30 01:30:26 +00:00
AWeapon * weapon = self - > player - > ReadyWeapon ;
weapon - > ReloadCounter = 0 ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_ChangeFlag
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_ChangeFlag )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_STRING ( flagname ) ;
PARAM_BOOL ( value ) ;
2015-01-30 01:30:26 +00:00
2016-08-24 10:21:46 +00:00
ModActorFlag ( self , flagname , value ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_CheckFlag
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckFlag )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-22 01:21:39 +00:00
PARAM_STRING ( flagname ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( checkpointer ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
AActor * owner = COPY_AAPTR ( self , checkpointer ) ;
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( owner ! = nullptr & & CheckActorFlag ( owner , flagname ) ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_ChangeCountFlags )
2016-10-25 08:15:24 +00:00
{
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( kill ) ;
PARAM_INT_DEF ( item ) ;
PARAM_INT_DEF ( secret ) ;
2016-10-25 08:15:24 +00:00
if ( self - > CountsAsKill ( ) & & self - > health > 0 ) - - level . total_monsters ;
if ( self - > flags & MF_COUNTITEM ) - - level . total_items ;
if ( self - > flags5 & MF5_COUNTSECRET ) - - level . total_secrets ;
if ( kill ! = - 1 )
{
2016-10-25 11:29:58 +00:00
if ( kill = = 0 ) self - > flags & = ~ MF_COUNTKILL ;
2016-10-25 08:15:24 +00:00
else self - > flags | = MF_COUNTKILL ;
}
if ( item ! = - 1 )
{
2016-10-25 11:29:58 +00:00
if ( item = = 0 ) self - > flags & = ~ MF_COUNTITEM ;
2016-10-25 08:15:24 +00:00
else self - > flags | = MF_COUNTITEM ;
}
if ( secret ! = - 1 )
{
2016-10-25 11:29:58 +00:00
if ( secret = = 0 ) self - > flags5 & = ~ MF5_COUNTSECRET ;
2016-10-25 08:15:24 +00:00
else self - > flags5 | = MF5_COUNTSECRET ;
}
if ( self - > CountsAsKill ( ) & & self - > health > 0 ) + + level . total_monsters ;
if ( self - > flags & MF_COUNTITEM ) + + level . total_items ;
if ( self - > flags5 & MF5_COUNTSECRET ) + + level . total_secrets ;
return 0 ;
}
2017-02-26 16:50:48 +00:00
enum ERaise
{
RF_TRANSFERFRIENDLINESS = 1 ,
RF_NOCHECKPOSITION = 2
} ;
2015-01-30 01:30:26 +00:00
//===========================================================================
//
// A_RaiseMaster
//
//===========================================================================
2016-02-04 21:15:29 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RaiseMaster )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2017-02-26 16:50:48 +00:00
PARAM_INT_DEF ( flags ) ;
2015-01-30 01:30:26 +00:00
2017-02-26 16:50:48 +00:00
bool copy = ! ! ( flags & RF_TRANSFERFRIENDLINESS ) ;
2015-01-30 01:30:26 +00:00
if ( self - > master ! = NULL )
{
2017-02-26 16:50:48 +00:00
P_Thing_Raise ( self - > master , copy ? self : NULL , ( flags & RF_NOCHECKPOSITION ) ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_RaiseChildren
//
//===========================================================================
2016-02-04 21:15:29 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RaiseChildren )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2017-02-26 16:50:48 +00:00
PARAM_INT_DEF ( flags ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
AActor * mo ;
2017-02-26 16:50:48 +00:00
bool copy = ! ! ( flags & RF_TRANSFERFRIENDLINESS ) ;
2015-01-30 01:30:26 +00:00
while ( ( mo = it . Next ( ) ) ! = NULL )
{
if ( mo - > master = = self )
{
2017-02-26 16:50:48 +00:00
P_Thing_Raise ( mo , copy ? self : NULL , ( flags & RF_NOCHECKPOSITION ) ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_RaiseSiblings
//
//===========================================================================
2016-02-04 21:15:29 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RaiseSiblings )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2017-02-26 16:50:48 +00:00
PARAM_INT_DEF ( flags ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
AActor * mo ;
2017-02-26 16:50:48 +00:00
bool copy = ! ! ( flags & RF_TRANSFERFRIENDLINESS ) ;
2015-01-30 01:30:26 +00:00
if ( self - > master ! = NULL )
{
while ( ( mo = it . Next ( ) ) ! = NULL )
{
if ( mo - > master = = self - > master & & mo ! = self )
{
2017-02-26 16:50:48 +00:00
P_Thing_Raise ( mo , copy ? self : NULL , ( flags & RF_NOCHECKPOSITION ) ) ;
2015-01-30 01:30:26 +00:00
}
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
//===========================================================================
//
// A_MonsterRefire
//
// Keep firing unless target got out of sight
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_MonsterRefire )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-22 01:21:39 +00:00
PARAM_INT ( prob ) ;
PARAM_STATE ( jump ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
A_FaceTarget ( self ) ;
2015-01-30 01:30:26 +00:00
if ( pr_monsterrefire ( ) < prob )
2016-02-19 03:39:13 +00:00
{
2016-02-19 02:39:40 +00:00
ACTION_RETURN_STATE ( NULL ) ;
2016-02-19 03:39:13 +00:00
}
2016-01-19 15:09:44 +00:00
if ( self - > target = = NULL
2015-01-30 01:30:26 +00:00
| | P_HitFriend ( self )
| | self - > target - > health < = 0
| | ! P_CheckSight ( self , self - > target , SF_SEEPASTBLOCKEVERYTHING | SF_SEEPASTSHOOTABLELINES ) )
{
2016-02-19 02:39:40 +00:00
ACTION_RETURN_STATE ( jump ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_STATE ( NULL ) ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SetAngle
//
// Set actor's angle (in degrees).
//
//===========================================================================
enum
{
SPF_FORCECLAMP = 1 , // players always clamp
SPF_INTERPOLATE = 2 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetAngle )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( angle ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_INT_DEF ( ptr ) ;
2015-01-30 01:30:26 +00:00
AActor * ref = COPY_AAPTR ( self , ptr ) ;
2016-02-04 21:15:29 +00:00
if ( ref ! = NULL )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
ref - > SetAngle ( angle , ! ! ( flags & SPF_INTERPOLATE ) ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SetPitch
//
// Set actor's pitch (in degrees).
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetPitch )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-03-16 11:41:26 +00:00
PARAM_FLOAT ( pitch ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
PARAM_INT_DEF ( ptr ) ;
2015-01-30 01:30:26 +00:00
AActor * ref = COPY_AAPTR ( self , ptr ) ;
2016-04-20 02:09:15 +00:00
if ( ref ! = NULL )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
ref - > SetPitch ( pitch , ! ! ( flags & SPF_INTERPOLATE ) , ! ! ( flags & SPF_FORCECLAMP ) ) ;
2016-02-04 21:15:29 +00:00
}
return 0 ;
2015-01-30 01:30:26 +00:00
}
2015-04-04 16:40:43 +00:00
//===========================================================================
//
// [Nash] A_SetRoll
//
// Set actor's roll (in degrees).
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetRoll )
2015-04-04 16:40:43 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-03-16 11:41:26 +00:00
PARAM_FLOAT ( roll ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
PARAM_INT_DEF ( ptr ) ;
2015-01-30 01:30:26 +00:00
AActor * ref = COPY_AAPTR ( self , ptr ) ;
2016-02-04 21:15:29 +00:00
if ( ref ! = NULL )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
ref - > SetRoll ( roll , ! ! ( flags & SPF_INTERPOLATE ) ) ;
2015-04-04 16:40:43 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-04-04 16:40:43 +00:00
}
2015-01-30 01:30:26 +00:00
//===========================================================================
//
// A_ScaleVelocity
//
// Scale actor's velocity.
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_ScaleVelocity )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-03-19 23:54:18 +00:00
PARAM_FLOAT ( scale ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr ) ;
2015-01-30 01:30:26 +00:00
AActor * ref = COPY_AAPTR ( self , ptr ) ;
2016-02-04 21:15:29 +00:00
if ( ref = = NULL )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2016-03-19 23:54:18 +00:00
bool was_moving = ! ref - > Vel . isZero ( ) ;
2015-01-30 01:30:26 +00:00
2016-03-19 23:54:18 +00:00
ref - > Vel * = scale ;
2015-01-30 01:30:26 +00:00
// If the actor was previously moving but now is not, and is a player,
// update its player variables. (See A_Stop.)
if ( was_moving )
{
CheckStopped ( ref ) ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_ChangeVelocity
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_ChangeVelocity )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( x )
PARAM_FLOAT_DEF ( y )
PARAM_FLOAT_DEF ( z )
PARAM_INT_DEF ( flags )
PARAM_INT_DEF ( ptr )
2015-01-30 01:30:26 +00:00
AActor * ref = COPY_AAPTR ( self , ptr ) ;
2016-02-04 21:15:29 +00:00
if ( ref = = NULL )
2015-01-30 01:30:26 +00:00
{
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2016-03-19 23:54:18 +00:00
INTBOOL was_moving = ! ref - > Vel . isZero ( ) ;
2015-01-30 01:30:26 +00:00
2016-03-19 23:54:18 +00:00
DVector3 vel ( x , y , z ) ;
double sina = ref - > Angles . Yaw . Sin ( ) ;
double cosa = ref - > Angles . Yaw . Cos ( ) ;
2015-01-30 01:30:26 +00:00
if ( flags & 1 ) // relative axes - make x, y relative to actor's current angle
{
2016-03-19 23:54:18 +00:00
vel . X = x * cosa - y * sina ;
vel . Y = x * sina + y * cosa ;
2015-01-30 01:30:26 +00:00
}
if ( flags & 2 ) // discard old velocity - replace old velocity with new velocity
{
2016-03-19 23:54:18 +00:00
ref - > Vel = vel ;
2015-01-30 01:30:26 +00:00
}
else // add new velocity to old velocity
{
2016-03-19 23:54:18 +00:00
ref - > Vel + = vel ;
2015-01-30 01:30:26 +00:00
}
if ( was_moving )
{
2015-07-27 17:20:32 +00:00
CheckStopped ( ref ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SetUserVar
//
//===========================================================================
2016-04-19 04:18:34 +00:00
static PField * GetVar ( DObject * self , FName varname )
2015-01-30 01:30:26 +00:00
{
2017-04-12 11:08:41 +00:00
PField * var = dyn_cast < PField > ( self - > GetClass ( ) - > FindSymbol ( varname , true ) ) ;
2015-01-30 01:30:26 +00:00
2017-04-13 10:47:41 +00:00
if ( var = = NULL | | ( var - > Flags & ( VARF_Native | VARF_Private | VARF_Protected | VARF_Static ) ) | | ! var - > Type - > isScalar ( ) )
2015-01-30 01:30:26 +00:00
{
Printf ( " %s is not a user variable in class %s \n " , varname . GetChars ( ) ,
self - > GetClass ( ) - > TypeName . GetChars ( ) ) ;
2016-03-30 03:14:31 +00:00
return nullptr ;
}
return var ;
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetUserVar )
2016-03-30 03:14:31 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( DObject ) ;
2016-03-30 03:14:31 +00:00
PARAM_NAME ( varname ) ;
PARAM_INT ( value ) ;
// Set the value of the specified user variable.
PField * var = GetVar ( self , varname ) ;
if ( var ! = nullptr )
{
2017-03-08 14:20:00 +00:00
var - > Type - > SetValue ( reinterpret_cast < uint8_t * > ( self ) + var - > Offset , value ) ;
2015-01-30 01:30:26 +00:00
}
2016-03-30 03:14:31 +00:00
return 0 ;
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetUserVarFloat )
2016-03-30 03:14:31 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( DObject ) ;
2016-03-30 03:14:31 +00:00
PARAM_NAME ( varname ) ;
PARAM_FLOAT ( value ) ;
2015-01-30 01:30:26 +00:00
// Set the value of the specified user variable.
2016-03-30 03:14:31 +00:00
PField * var = GetVar ( self , varname ) ;
if ( var ! = nullptr )
{
2017-03-08 14:20:00 +00:00
var - > Type - > SetValue ( reinterpret_cast < uint8_t * > ( self ) + var - > Offset , value ) ;
2016-03-30 03:14:31 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SetUserArray
//
//===========================================================================
2016-04-19 04:18:34 +00:00
static PField * GetArrayVar ( DObject * self , FName varname , int pos )
2015-01-30 01:30:26 +00:00
{
2017-04-12 11:08:41 +00:00
PField * var = dyn_cast < PField > ( self - > GetClass ( ) - > FindSymbol ( varname , true ) ) ;
2015-01-30 01:30:26 +00:00
2016-11-05 08:50:53 +00:00
if ( var = = NULL | | ( var - > Flags & ( VARF_Native | VARF_Private | VARF_Protected | VARF_Static ) ) | |
2017-04-13 13:13:14 +00:00
! var - > Type - > isArray ( ) | | ! static_cast < PArray * > ( var - > Type ) - > ElementType - > isScalar ( ) )
2015-01-30 01:30:26 +00:00
{
Printf ( " %s is not a user array in class %s \n " , varname . GetChars ( ) ,
self - > GetClass ( ) - > TypeName . GetChars ( ) ) ;
2016-03-30 03:14:31 +00:00
return nullptr ;
2015-01-30 01:30:26 +00:00
}
2016-03-30 03:14:31 +00:00
if ( ( unsigned ) pos > = static_cast < PArray * > ( var - > Type ) - > ElementCount )
2015-01-30 01:30:26 +00:00
{
Printf ( " %d is out of bounds in array %s in class %s \n " , pos , varname . GetChars ( ) ,
self - > GetClass ( ) - > TypeName . GetChars ( ) ) ;
2016-03-30 03:14:31 +00:00
return nullptr ;
}
return var ;
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetUserArray )
2016-03-30 03:14:31 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( DObject ) ;
2016-03-30 03:14:31 +00:00
PARAM_NAME ( varname ) ;
PARAM_INT ( pos ) ;
PARAM_INT ( value ) ;
// Set the value of the specified user array at index pos.
PField * var = GetArrayVar ( self , varname , pos ) ;
if ( var ! = nullptr )
{
PArray * arraytype = static_cast < PArray * > ( var - > Type ) ;
2017-03-08 14:20:00 +00:00
arraytype - > ElementType - > SetValue ( reinterpret_cast < uint8_t * > ( self ) + var - > Offset + arraytype - > ElementSize * pos , value ) ;
2015-01-30 01:30:26 +00:00
}
2016-03-30 03:14:31 +00:00
return 0 ;
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetUserArrayFloat )
2016-03-30 03:14:31 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( DObject ) ;
2016-03-30 03:14:31 +00:00
PARAM_NAME ( varname ) ;
PARAM_INT ( pos ) ;
PARAM_FLOAT ( value ) ;
2015-01-30 01:30:26 +00:00
// Set the value of the specified user array at index pos.
2016-03-30 03:14:31 +00:00
PField * var = GetArrayVar ( self , varname , pos ) ;
if ( var ! = nullptr )
{
PArray * arraytype = static_cast < PArray * > ( var - > Type ) ;
2017-03-08 14:20:00 +00:00
arraytype - > ElementType - > SetValue ( reinterpret_cast < uint8_t * > ( self ) + var - > Offset + arraytype - > ElementSize * pos , value ) ;
2016-03-30 03:14:31 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
2015-04-07 16:14:02 +00:00
// A_Teleport([state teleportstate, [class targettype,
// [class fogtype, [int flags, [fixed mindist,
// [fixed maxdist]]]]]])
2015-01-30 01:30:26 +00:00
//
// Attempts to teleport to a targettype at least mindist away and at most
// maxdist away (0 means unlimited). If successful, spawn a fogtype at old
// location and place calling actor in teleportstate.
//
//===========================================================================
enum T_Flags
{
TF_TELEFRAG = 0x00000001 , // Allow telefrag in order to teleport.
TF_RANDOMDECIDE = 0x00000002 , // Randomly fail based on health. (A_Srcr2Decide)
TF_FORCED = 0x00000004 , // Forget what's in the way. TF_Telefrag takes precedence though.
TF_KEEPVELOCITY = 0x00000008 , // Preserve velocity.
TF_KEEPANGLE = 0x00000010 , // Keep angle.
TF_USESPOTZ = 0x00000020 , // Set the z to the spot's z, instead of the floor.
TF_NOSRCFOG = 0x00000040 , // Don't leave any fog behind when teleporting.
TF_NODESTFOG = 0x00000080 , // Don't spawn any fog at the arrival position.
TF_USEACTORFOG = 0x00000100 , // Use the actor's TeleFogSourceType and TeleFogDestType fogs.
TF_NOJUMP = 0x00000200 , // Don't jump after teleporting.
2015-05-01 13:32:07 +00:00
TF_OVERRIDE = 0x00000400 , // Ignore NOTELEPORT.
2015-12-17 16:34:38 +00:00
TF_SENSITIVEZ = 0x00000800 , // Fail if the actor wouldn't fit in the position (for Z).
2015-01-30 01:30:26 +00:00
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Teleport )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
PARAM_ACTION_PROLOGUE ( AActor ) ;
2017-02-09 10:22:36 +00:00
PARAM_STATE_ACTION_DEF ( teleport_state )
2016-10-27 13:53:53 +00:00
PARAM_CLASS_DEF ( target_type , ASpecialSpot )
PARAM_CLASS_DEF ( fog_type , AActor )
PARAM_INT_DEF ( flags )
PARAM_FLOAT_DEF ( mindist )
PARAM_FLOAT_DEF ( maxdist )
PARAM_INT_DEF ( ptr )
2015-04-07 16:14:02 +00:00
AActor * ref = COPY_AAPTR ( self , ptr ) ;
2016-02-19 02:39:40 +00:00
// A_Teleport and A_Warp were the only codepointers that can state jump
// *AND* have a meaningful inventory state chain result. Grrr.
if ( numret > 1 )
{
ret [ 1 ] . SetInt ( false ) ;
numret = 2 ;
}
if ( numret > 0 )
{
2017-04-10 13:17:39 +00:00
ret [ 0 ] . SetPointer ( NULL ) ;
2016-02-19 02:39:40 +00:00
}
2015-04-07 16:14:02 +00:00
if ( ! ref )
{
2016-02-04 21:15:29 +00:00
return numret ;
2015-04-07 16:14:02 +00:00
}
2016-01-19 15:09:44 +00:00
if ( ( ref - > flags2 & MF2_NOTELEPORT ) & & ! ( flags & TF_OVERRIDE ) )
2015-05-01 13:32:07 +00:00
{
2016-02-04 21:15:29 +00:00
return numret ;
2015-05-01 13:32:07 +00:00
}
2015-01-30 01:30:26 +00:00
// Randomly choose not to teleport like A_Srcr2Decide.
2016-01-19 15:09:44 +00:00
if ( flags & TF_RANDOMDECIDE )
2015-01-30 01:30:26 +00:00
{
static const int chance [ ] =
{
192 , 120 , 120 , 120 , 64 , 64 , 32 , 16 , 0
} ;
2015-04-07 16:14:02 +00:00
unsigned int chanceindex = ref - > health / ( ( ref - > SpawnHealth ( ) / 8 = = 0 ) ? 1 : ref - > SpawnHealth ( ) / 8 ) ;
2015-01-30 01:30:26 +00:00
if ( chanceindex > = countof ( chance ) )
{
chanceindex = countof ( chance ) - 1 ;
}
2016-02-04 21:15:29 +00:00
if ( pr_teleport ( ) > = chance [ chanceindex ] )
{
return numret ;
}
2015-01-30 01:30:26 +00:00
}
DSpotState * state = DSpotState : : GetSpotState ( ) ;
2015-05-01 13:32:07 +00:00
if ( state = = NULL )
{
2016-02-04 21:15:29 +00:00
return numret ;
2015-05-01 13:32:07 +00:00
}
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( target_type = = NULL )
{
2016-02-04 21:15:29 +00:00
target_type = PClass : : FindActor ( " BossSpot " ) ;
2016-01-19 15:09:44 +00:00
}
2015-01-30 01:30:26 +00:00
2016-02-19 02:39:40 +00:00
AActor * spot = state - > GetSpotWithMinMaxDistance ( target_type , ref - > X ( ) , ref - > Y ( ) , mindist , maxdist ) ;
2016-02-04 21:15:29 +00:00
if ( spot = = NULL )
2015-05-01 13:32:07 +00:00
{
2016-02-04 21:15:29 +00:00
return numret ;
2015-05-01 13:32:07 +00:00
}
2015-01-30 01:30:26 +00:00
2015-12-17 16:34:38 +00:00
// [MC] By default, the function adjusts the actor's Z if it's below the floor or above the ceiling.
// This can be an issue as actors designed to maintain specific z positions wind up teleporting
// anyway when they should not, such as a floor rising above or ceiling lowering below the position
// of the spot.
2016-01-21 00:18:00 +00:00
if ( flags & TF_SENSITIVEZ )
2015-12-17 16:34:38 +00:00
{
2016-03-20 18:52:35 +00:00
double posz = ( flags & TF_USESPOTZ ) ? spot - > Z ( ) : spot - > floorz ;
2016-03-20 19:55:06 +00:00
if ( ( posz + ref - > Height > spot - > ceilingz ) | | ( posz < spot - > floorz ) )
2015-12-17 16:34:38 +00:00
{
2016-02-04 21:15:29 +00:00
return numret ;
2015-12-17 16:34:38 +00:00
}
}
2016-03-20 18:52:35 +00:00
DVector3 prev = ref - > Pos ( ) ;
double aboveFloor = spot - > Z ( ) - spot - > floorz ;
double finalz = spot - > floorz + aboveFloor ;
2015-01-30 01:30:26 +00:00
2016-03-20 18:52:35 +00:00
if ( spot - > Top ( ) > spot - > ceilingz )
2016-03-20 19:55:06 +00:00
finalz = spot - > ceilingz - ref - > Height ;
2016-01-19 19:15:45 +00:00
else if ( spot - > Z ( ) < spot - > floorz )
2015-01-30 01:30:26 +00:00
finalz = spot - > floorz ;
2016-03-20 18:52:35 +00:00
DVector3 tpos = spot - > PosAtZ ( finalz ) ;
2015-01-30 01:30:26 +00:00
//Take precedence and cooperate with telefragging first.
2016-03-20 18:52:35 +00:00
bool tele_result = P_TeleportMove ( ref , tpos , ! ! ( flags & TF_TELEFRAG ) ) ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ! tele_result & & ( flags & TF_FORCED ) )
2015-01-30 01:30:26 +00:00
{
//If for some reason the original move didn't work, regardless of telefrag, force it to move.
2016-03-20 18:52:35 +00:00
ref - > SetOrigin ( tpos , false ) ;
2016-01-19 15:09:44 +00:00
tele_result = true ;
2015-01-30 01:30:26 +00:00
}
2015-04-07 16:14:02 +00:00
AActor * fog1 = NULL , * fog2 = NULL ;
2016-01-19 15:09:44 +00:00
if ( tele_result )
2015-01-30 01:30:26 +00:00
{
//If a fog type is defined in the parameter, or the user wants to use the actor's predefined fogs,
//and if there's no desire to be fogless, spawn a fog based upon settings.
2016-01-19 15:09:44 +00:00
if ( fog_type | | ( flags & TF_USEACTORFOG ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( ! ( flags & TF_NOSRCFOG ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( flags & TF_USEACTORFOG )
2016-01-19 19:15:45 +00:00
P_SpawnTeleportFog ( ref , prev , true , true ) ;
2015-01-30 01:30:26 +00:00
else
2015-04-07 16:14:02 +00:00
{
2016-01-19 19:15:45 +00:00
fog1 = Spawn ( fog_type , prev , ALLOW_REPLACE ) ;
2015-04-07 16:14:02 +00:00
if ( fog1 ! = NULL )
fog1 - > target = ref ;
}
2015-01-30 01:30:26 +00:00
}
2016-01-19 15:09:44 +00:00
if ( ! ( flags & TF_NODESTFOG ) )
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( flags & TF_USEACTORFOG )
2016-01-19 19:15:45 +00:00
P_SpawnTeleportFog ( ref , ref - > Pos ( ) , false , true ) ;
2015-01-30 01:30:26 +00:00
else
2015-04-07 16:14:02 +00:00
{
2016-01-19 19:15:45 +00:00
fog2 = Spawn ( fog_type , ref - > Pos ( ) , ALLOW_REPLACE ) ;
2015-04-07 16:14:02 +00:00
if ( fog2 ! = NULL )
fog2 - > target = ref ;
}
2015-01-30 01:30:26 +00:00
}
}
2016-01-19 19:15:45 +00:00
ref - > SetZ ( ( flags & TF_USESPOTZ ) ? spot - > Z ( ) : ref - > floorz , false ) ;
2016-01-19 15:09:44 +00:00
if ( ! ( flags & TF_KEEPANGLE ) )
2016-03-16 11:41:26 +00:00
ref - > Angles . Yaw = spot - > Angles . Yaw ;
2015-01-30 01:30:26 +00:00
2016-03-19 23:54:18 +00:00
if ( ! ( flags & TF_KEEPVELOCITY ) ) ref - > Vel . Zero ( ) ;
2015-01-30 01:30:26 +00:00
2016-01-19 15:09:44 +00:00
if ( ! ( flags & TF_NOJUMP ) ) //The state jump should only happen with the calling actor.
2015-01-30 01:30:26 +00:00
{
2016-01-19 15:09:44 +00:00
if ( teleport_state = = NULL )
2015-01-30 01:30:26 +00:00
{
// Default to Teleport.
2016-01-19 15:09:44 +00:00
teleport_state = self - > FindState ( " Teleport " ) ;
2015-01-30 01:30:26 +00:00
// If still nothing, then return.
2016-01-19 15:09:44 +00:00
if ( teleport_state = = NULL )
2016-02-04 21:15:29 +00:00
{
return numret ;
}
2015-01-30 01:30:26 +00:00
}
2016-02-19 02:39:40 +00:00
if ( numret > 0 )
{
2017-04-10 13:17:39 +00:00
ret [ 0 ] . SetPointer ( teleport_state ) ;
2016-02-19 02:39:40 +00:00
}
2016-02-04 21:15:29 +00:00
return numret ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-19 02:39:40 +00:00
if ( numret > 1 )
{
ret [ 1 ] . SetInt ( tele_result ) ;
}
2016-02-04 21:15:29 +00:00
return numret ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_Quake
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Quake )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( intensity ) ;
PARAM_INT ( duration ) ;
PARAM_INT ( damrad ) ;
PARAM_INT ( tremrad ) ;
2016-10-27 13:53:53 +00:00
PARAM_SOUND_DEF ( sound ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
P_StartQuake ( self , 0 , intensity , duration , damrad , tremrad , sound ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2015-02-14 21:58:39 +00:00
//===========================================================================
//
// A_QuakeEx
//
// Extended version of A_Quake. Takes individual axis into account and can
2016-03-23 13:03:10 +00:00
// take flags.
2015-02-14 21:58:39 +00:00
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_QuakeEx )
2015-02-14 21:58:39 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( intensityX ) ;
PARAM_INT ( intensityY ) ;
PARAM_INT ( intensityZ ) ;
PARAM_INT ( duration ) ;
PARAM_INT ( damrad ) ;
PARAM_INT ( tremrad ) ;
2016-10-27 13:53:53 +00:00
PARAM_SOUND_DEF ( sound ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_FLOAT_DEF ( mulWaveX ) ;
PARAM_FLOAT_DEF ( mulWaveY ) ;
PARAM_FLOAT_DEF ( mulWaveZ ) ;
PARAM_INT_DEF ( falloff ) ;
PARAM_INT_DEF ( highpoint ) ;
PARAM_FLOAT_DEF ( rollIntensity ) ;
PARAM_FLOAT_DEF ( rollWave ) ;
2016-04-25 14:56:01 +00:00
P_StartQuakeXYZ ( self , 0 , intensityX , intensityY , intensityZ , duration , damrad , tremrad , sound , flags , mulWaveX , mulWaveY , mulWaveZ , falloff , highpoint ,
rollIntensity , rollWave ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-02-14 21:58:39 +00:00
}
2015-01-30 01:30:26 +00:00
//===========================================================================
//
// A_Weave
//
//===========================================================================
2016-03-21 13:00:05 +00:00
void A_Weave ( AActor * self , int xyspeed , int zspeed , double xydist , double zdist )
2015-01-30 01:30:26 +00:00
{
2016-03-21 13:00:05 +00:00
DVector2 newpos ;
2015-01-30 01:30:26 +00:00
int weaveXY , weaveZ ;
2016-03-21 13:00:05 +00:00
DAngle angle ;
double dist ;
2015-01-30 01:30:26 +00:00
weaveXY = self - > WeaveIndexXY & 63 ;
weaveZ = self - > WeaveIndexZ & 63 ;
2016-03-21 13:00:05 +00:00
angle = self - > Angles . Yaw + 90 ;
2015-01-30 01:30:26 +00:00
if ( xydist ! = 0 & & xyspeed ! = 0 )
{
2016-03-21 13:00:05 +00:00
dist = BobSin ( weaveXY ) * xydist ;
newpos = self - > Pos ( ) . XY ( ) - angle . ToVector ( dist ) ;
2015-01-30 01:30:26 +00:00
weaveXY = ( weaveXY + xyspeed ) & 63 ;
2016-03-21 13:00:05 +00:00
dist = BobSin ( weaveXY ) * xydist ;
newpos + = angle . ToVector ( dist ) ;
2015-01-30 01:30:26 +00:00
if ( ! ( self - > flags5 & MF5_NOINTERACTION ) )
{
2016-03-21 13:00:05 +00:00
P_TryMove ( self , newpos , true ) ;
2015-01-30 01:30:26 +00:00
}
else
{
2016-12-25 21:40:26 +00:00
FLinkContext ctx ;
self - > UnlinkFromWorld ( & ctx ) ;
2015-01-30 01:30:26 +00:00
self - > flags | = MF_NOBLOCKMAP ;
2016-03-08 13:41:37 +00:00
// We need to do portal offsetting here explicitly, because SetXY cannot do that.
2016-03-21 13:00:05 +00:00
newpos - = self - > Pos ( ) . XY ( ) ;
self - > SetXY ( self - > Vec2Offset ( newpos . X , newpos . Y ) ) ;
2016-12-25 21:40:26 +00:00
self - > LinkToWorld ( & ctx ) ;
2015-01-30 01:30:26 +00:00
}
self - > WeaveIndexXY = weaveXY ;
}
if ( zdist ! = 0 & & zspeed ! = 0 )
{
2016-03-21 13:00:05 +00:00
self - > AddZ ( - BobSin ( weaveZ ) * zdist ) ;
2015-01-30 01:30:26 +00:00
weaveZ = ( weaveZ + zspeed ) & 63 ;
2016-03-21 13:00:05 +00:00
self - > AddZ ( BobSin ( weaveZ ) * zdist ) ;
2015-01-30 01:30:26 +00:00
self - > WeaveIndexZ = weaveZ ;
}
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Weave )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( xspeed ) ;
PARAM_INT ( yspeed ) ;
2016-03-21 13:00:05 +00:00
PARAM_FLOAT ( xdist ) ;
PARAM_FLOAT ( ydist ) ;
2015-01-30 01:30:26 +00:00
A_Weave ( self , xspeed , yspeed , xdist , ydist ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_LineEffect
//
// This allows linedef effects to be activated inside deh frames.
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_LineEffect )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( special ) ;
PARAM_INT_DEF ( tag ) ;
2015-01-30 01:30:26 +00:00
2016-02-04 21:15:29 +00:00
line_t junk ;
maplinedef_t oldjunk ;
2015-01-30 01:30:26 +00:00
bool res = false ;
if ( ! ( self - > flags6 & MF6_LINEDONE ) ) // Unless already used up
{
if ( ( oldjunk . special = special ) ) // Linedef type
{
oldjunk . tag = tag ; // Sector tag for linedef
2015-04-19 15:51:34 +00:00
P_TranslateLineDef ( & junk , & oldjunk ) ; // Turn into native type
2015-01-30 01:30:26 +00:00
res = ! ! P_ExecuteSpecial ( junk . special , NULL , self , false , junk . args [ 0 ] ,
junk . args [ 1 ] , junk . args [ 2 ] , junk . args [ 3 ] , junk . args [ 4 ] ) ;
if ( res & & ! ( junk . flags & ML_REPEAT_SPECIAL ) ) // If only once,
self - > flags6 | = MF6_LINEDONE ; // no more for this thing
}
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_BOOL ( res ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A Wolf3D-style attack codepointer
//
//==========================================================================
enum WolfAttackFlags
{
WAF_NORANDOM = 1 ,
WAF_USEPUFF = 2 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_WolfAttack )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags )
PARAM_SOUND_DEF ( sound )
PARAM_FLOAT_DEF ( snipe )
PARAM_INT_DEF ( maxdamage )
PARAM_INT_DEF ( blocksize )
PARAM_INT_DEF ( pointblank )
PARAM_INT_DEF ( longrange )
PARAM_FLOAT_DEF ( runspeed )
PARAM_CLASS_DEF ( pufftype , AActor )
2015-01-30 01:30:26 +00:00
if ( ! self - > target )
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
// Enemy can't see target
if ( ! P_CheckSight ( self , self - > target ) )
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
A_FaceTarget ( self ) ;
// Target can dodge if it can see enemy
2016-03-25 11:57:22 +00:00
DAngle angle = absangle ( self - > target - > Angles . Yaw , self - > target - > AngleTo ( self ) ) ;
bool dodge = ( P_CheckSight ( self - > target , self ) & & angle < 30. * 256. / 360. ) ; // 30 byteangles ~ 21<32>
2015-01-30 01:30:26 +00:00
// Distance check is simplistic
2016-03-25 11:57:22 +00:00
DVector2 vec = self - > Vec2To ( self - > target ) ;
double dx = fabs ( vec . X ) ;
double dy = fabs ( vec . Y ) ;
double dist = dx > dy ? dx : dy ;
2015-01-30 01:30:26 +00:00
// Some enemies are more precise
2016-03-25 11:57:22 +00:00
dist * = snipe ;
2015-01-30 01:30:26 +00:00
// Convert distance into integer number of blocks
2016-03-25 11:57:22 +00:00
int idist = int ( dist / blocksize ) ;
2015-01-30 01:30:26 +00:00
// Now for the speed accuracy thingie
2016-03-25 11:57:22 +00:00
double speed = self - > target - > Vel . LengthSquared ( ) ;
2015-01-30 01:30:26 +00:00
int hitchance = speed < runspeed ? 256 : 160 ;
// Distance accuracy (factoring dodge)
2016-03-25 11:57:22 +00:00
hitchance - = idist * ( dodge ? 16 : 8 ) ;
2015-01-30 01:30:26 +00:00
// While we're here, we may as well do something for this:
if ( self - > target - > flags & MF_SHADOW )
{
hitchance > > = 2 ;
}
// The attack itself
if ( pr_cabullet ( ) < hitchance )
{
// Compute position for spawning blood/puff
2016-03-25 11:57:22 +00:00
DAngle angle = self - > target - > AngleTo ( self ) ;
DVector3 BloodPos = self - > target - > Vec3Angle ( self - > target - > radius , angle , self - > target - > Height / 2 ) ;
2015-01-30 01:30:26 +00:00
int damage = flags & WAF_NORANDOM ? maxdamage : ( 1 + ( pr_cabullet ( ) % maxdamage ) ) ;
if ( dist > = pointblank )
damage > > = 1 ;
if ( dist > = longrange )
damage > > = 1 ;
FName mod = NAME_None ;
bool spawnblood = ! ( ( self - > target - > flags & MF_NOBLOOD )
| | ( self - > target - > flags2 & ( MF2_INVULNERABLE | MF2_DORMANT ) ) ) ;
if ( flags & WAF_USEPUFF & & pufftype )
{
2016-02-04 21:15:29 +00:00
AActor * dpuff = GetDefaultByType ( pufftype - > GetReplacement ( ) ) ;
2015-01-30 01:30:26 +00:00
mod = dpuff - > DamageType ;
if ( dpuff - > flags2 & MF2_THRUGHOST & & self - > target - > flags3 & MF3_GHOST )
damage = 0 ;
if ( ( 0 & & dpuff - > flags3 & MF3_PUFFONACTORS ) | | ! spawnblood )
{
spawnblood = false ;
2016-03-25 11:57:22 +00:00
P_SpawnPuff ( self , pufftype , BloodPos , angle , angle , 0 ) ;
2015-01-30 01:30:26 +00:00
}
}
else if ( self - > target - > flags3 & MF3_GHOST )
damage > > = 2 ;
if ( damage )
{
int newdam = P_DamageMobj ( self - > target , self , self , damage , mod , DMG_THRUSTLESS ) ;
if ( spawnblood )
{
2016-03-25 11:57:22 +00:00
P_SpawnBlood ( BloodPos , angle , newdam > 0 ? newdam : damage , self - > target ) ;
2016-02-25 15:50:03 +00:00
P_TraceBleed ( newdam > 0 ? newdam : damage , self - > target , self ) ;
2015-01-30 01:30:26 +00:00
}
}
}
// And finally, let's play the sound
S_Sound ( self , CHAN_WEAPON , sound , 1 , ATTN_NORM ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_Warp
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Warp )
2015-01-30 01:30:26 +00:00
{
2016-11-14 13:12:27 +00:00
PARAM_ACTION_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( destination_selector ) ;
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( xofs )
PARAM_FLOAT_DEF ( yofs )
PARAM_FLOAT_DEF ( zofs )
PARAM_ANGLE_DEF ( angle )
PARAM_INT_DEF ( flags )
2017-02-09 10:22:36 +00:00
PARAM_STATE_ACTION_DEF ( success_state )
2016-10-27 13:53:53 +00:00
PARAM_FLOAT_DEF ( heightoffset )
PARAM_FLOAT_DEF ( radiusoffset )
PARAM_ANGLE_DEF ( pitch )
2015-07-31 12:54:01 +00:00
AActor * reference ;
2016-02-04 21:15:29 +00:00
2016-02-19 02:39:40 +00:00
// A_Teleport and A_Warp were the only codepointers that can state jump
// *AND* have a meaningful inventory state chain result. Grrr.
if ( numret > 1 )
{
ret [ 1 ] . SetInt ( false ) ;
numret = 2 ;
}
if ( numret > 0 )
{
2017-04-10 13:17:39 +00:00
ret [ 0 ] . SetPointer ( NULL ) ;
2016-02-19 02:39:40 +00:00
}
2016-02-04 21:15:29 +00:00
if ( ( flags & WARPF_USETID ) )
2015-07-31 12:54:01 +00:00
{
reference = SingleActorFromTID ( destination_selector , self ) ;
}
else
{
reference = COPY_AAPTR ( self , destination_selector ) ;
}
2015-01-30 01:30:26 +00:00
//If there is no actor to warp to, fail.
if ( ! reference )
{
2016-02-04 21:15:29 +00:00
return numret ;
2015-01-30 01:30:26 +00:00
}
2015-10-03 22:28:54 +00:00
if ( P_Thing_Warp ( self , reference , xofs , yofs , zofs , angle , flags , heightoffset , radiusoffset , pitch ) )
2015-01-30 01:30:26 +00:00
{
2016-02-22 01:21:39 +00:00
if ( success_state )
2015-01-30 01:30:26 +00:00
{
2016-02-19 02:39:40 +00:00
// Jumps should never set the result for inventory state chains!
2015-01-30 01:30:26 +00:00
// in this case, you have the statejump to help you handle all the success anyway.
2016-02-19 02:39:40 +00:00
if ( numret > 0 )
{
2017-04-10 13:17:39 +00:00
ret [ 0 ] . SetPointer ( success_state ) ;
2016-02-19 02:39:40 +00:00
}
}
else if ( numret > 1 )
{
ret [ 1 ] . SetInt ( true ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-04 21:15:29 +00:00
return numret ;
2015-01-30 01:30:26 +00:00
}
- Significant A_RadiusGive update.
- Added filter and species parameter.
- Added new flags: RGF_INCLUSIVE, RGF_ITEMS, RGF_KILLED, RGF_EXFILTER, RGF_EXSPECIES, and RGF_EITHER.
- RGF_ITEMS: Items can receive inventory.
- RGF_KILLED: Actors who are truly dead might not be corpses, and vice versa.
- RGF_EXFILTER: Blacklists the specified actor filter. All but the filtered actor can receive the item.
- RGF_EXSPECIES: Blacklists the specified species. All but the filtered species can receive the item.
- RGF_EITHER: The actor can receive the item if it satisfies either the filter or the species. Only useful when both are used.
- RGF_INCLUSIVE: An actor marked as more than one pointer to the calling actor can ignore the exclusion pointers, but only if at least one is missing. I.e. an actor who is a target and tracer of the calling actor can still receive the item, if the calling actor doesn't pass RGF_NOTARGET and NOTRACER at the same time. RGF_INCLUSIVE only works with the pointer filtering flags. By default, if not specified, the actor will not be loopholed the item if they are under any one of the three filters.
- Fixed discrepancies and dependencies upon several flags and actor conditions which caused the function to fail.
2015-07-22 21:46:14 +00:00
static bool DoCheckSpecies ( AActor * mo , FName filterSpecies , bool exclude )
{
FName actorSpecies = mo - > GetSpecies ( ) ;
if ( filterSpecies = = NAME_None ) return true ;
return exclude ? ( actorSpecies ! = filterSpecies ) : ( actorSpecies = = filterSpecies ) ;
}
2016-02-04 21:15:29 +00:00
static bool DoCheckClass ( AActor * mo , PClassActor * filterClass , bool exclude )
- Significant A_RadiusGive update.
- Added filter and species parameter.
- Added new flags: RGF_INCLUSIVE, RGF_ITEMS, RGF_KILLED, RGF_EXFILTER, RGF_EXSPECIES, and RGF_EITHER.
- RGF_ITEMS: Items can receive inventory.
- RGF_KILLED: Actors who are truly dead might not be corpses, and vice versa.
- RGF_EXFILTER: Blacklists the specified actor filter. All but the filtered actor can receive the item.
- RGF_EXSPECIES: Blacklists the specified species. All but the filtered species can receive the item.
- RGF_EITHER: The actor can receive the item if it satisfies either the filter or the species. Only useful when both are used.
- RGF_INCLUSIVE: An actor marked as more than one pointer to the calling actor can ignore the exclusion pointers, but only if at least one is missing. I.e. an actor who is a target and tracer of the calling actor can still receive the item, if the calling actor doesn't pass RGF_NOTARGET and NOTRACER at the same time. RGF_INCLUSIVE only works with the pointer filtering flags. By default, if not specified, the actor will not be loopholed the item if they are under any one of the three filters.
- Fixed discrepancies and dependencies upon several flags and actor conditions which caused the function to fail.
2015-07-22 21:46:14 +00:00
{
const PClass * actorClass = mo - > GetClass ( ) ;
if ( filterClass = = NULL ) return true ;
return exclude ? ( actorClass ! = filterClass ) : ( actorClass = = filterClass ) ;
}
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
//==========================================================================
//
- Significant A_RadiusGive update.
- Added filter and species parameter.
- Added new flags: RGF_INCLUSIVE, RGF_ITEMS, RGF_KILLED, RGF_EXFILTER, RGF_EXSPECIES, and RGF_EITHER.
- RGF_ITEMS: Items can receive inventory.
- RGF_KILLED: Actors who are truly dead might not be corpses, and vice versa.
- RGF_EXFILTER: Blacklists the specified actor filter. All but the filtered actor can receive the item.
- RGF_EXSPECIES: Blacklists the specified species. All but the filtered species can receive the item.
- RGF_EITHER: The actor can receive the item if it satisfies either the filter or the species. Only useful when both are used.
- RGF_INCLUSIVE: An actor marked as more than one pointer to the calling actor can ignore the exclusion pointers, but only if at least one is missing. I.e. an actor who is a target and tracer of the calling actor can still receive the item, if the calling actor doesn't pass RGF_NOTARGET and NOTRACER at the same time. RGF_INCLUSIVE only works with the pointer filtering flags. By default, if not specified, the actor will not be loopholed the item if they are under any one of the three filters.
- Fixed discrepancies and dependencies upon several flags and actor conditions which caused the function to fail.
2015-07-22 21:46:14 +00:00
// A_RadiusGive(item, distance, flags, amount, filter, species)
2015-01-30 01:30:26 +00:00
//
// Uses code roughly similar to A_Explode (but without all the compatibility
- Significant A_RadiusGive update.
- Added filter and species parameter.
- Added new flags: RGF_INCLUSIVE, RGF_ITEMS, RGF_KILLED, RGF_EXFILTER, RGF_EXSPECIES, and RGF_EITHER.
- RGF_ITEMS: Items can receive inventory.
- RGF_KILLED: Actors who are truly dead might not be corpses, and vice versa.
- RGF_EXFILTER: Blacklists the specified actor filter. All but the filtered actor can receive the item.
- RGF_EXSPECIES: Blacklists the specified species. All but the filtered species can receive the item.
- RGF_EITHER: The actor can receive the item if it satisfies either the filter or the species. Only useful when both are used.
- RGF_INCLUSIVE: An actor marked as more than one pointer to the calling actor can ignore the exclusion pointers, but only if at least one is missing. I.e. an actor who is a target and tracer of the calling actor can still receive the item, if the calling actor doesn't pass RGF_NOTARGET and NOTRACER at the same time. RGF_INCLUSIVE only works with the pointer filtering flags. By default, if not specified, the actor will not be loopholed the item if they are under any one of the three filters.
- Fixed discrepancies and dependencies upon several flags and actor conditions which caused the function to fail.
2015-07-22 21:46:14 +00:00
// baggage and damage computation code) to give an item to all eligible mobjs
2015-01-30 01:30:26 +00:00
// in range.
//
//==========================================================================
enum RadiusGiveFlags
{
RGF_GIVESELF = 1 < < 0 ,
RGF_PLAYERS = 1 < < 1 ,
RGF_MONSTERS = 1 < < 2 ,
RGF_OBJECTS = 1 < < 3 ,
RGF_VOODOO = 1 < < 4 ,
RGF_CORPSES = 1 < < 5 ,
RGF_NOTARGET = 1 < < 6 ,
RGF_NOTRACER = 1 < < 7 ,
RGF_NOMASTER = 1 < < 8 ,
RGF_CUBE = 1 < < 9 ,
RGF_NOSIGHT = 1 < < 10 ,
RGF_MISSILES = 1 < < 11 ,
- Significant A_RadiusGive update.
- Added filter and species parameter.
- Added new flags: RGF_INCLUSIVE, RGF_ITEMS, RGF_KILLED, RGF_EXFILTER, RGF_EXSPECIES, and RGF_EITHER.
- RGF_ITEMS: Items can receive inventory.
- RGF_KILLED: Actors who are truly dead might not be corpses, and vice versa.
- RGF_EXFILTER: Blacklists the specified actor filter. All but the filtered actor can receive the item.
- RGF_EXSPECIES: Blacklists the specified species. All but the filtered species can receive the item.
- RGF_EITHER: The actor can receive the item if it satisfies either the filter or the species. Only useful when both are used.
- RGF_INCLUSIVE: An actor marked as more than one pointer to the calling actor can ignore the exclusion pointers, but only if at least one is missing. I.e. an actor who is a target and tracer of the calling actor can still receive the item, if the calling actor doesn't pass RGF_NOTARGET and NOTRACER at the same time. RGF_INCLUSIVE only works with the pointer filtering flags. By default, if not specified, the actor will not be loopholed the item if they are under any one of the three filters.
- Fixed discrepancies and dependencies upon several flags and actor conditions which caused the function to fail.
2015-07-22 21:46:14 +00:00
RGF_INCLUSIVE = 1 < < 12 ,
RGF_ITEMS = 1 < < 13 ,
RGF_KILLED = 1 < < 14 ,
RGF_EXFILTER = 1 < < 15 ,
RGF_EXSPECIES = 1 < < 16 ,
RGF_EITHER = 1 < < 17 ,
2016-02-19 02:39:40 +00:00
RGF_MASK = /*2111*/
RGF_GIVESELF |
RGF_PLAYERS |
RGF_MONSTERS |
RGF_OBJECTS |
RGF_VOODOO |
2016-07-14 14:27:29 +00:00
RGF_CORPSES |
2016-08-09 21:09:24 +00:00
RGF_KILLED |
2016-07-14 14:27:29 +00:00
RGF_MISSILES |
RGF_ITEMS ,
2015-01-30 01:30:26 +00:00
} ;
2016-03-25 11:57:22 +00:00
static bool DoRadiusGive ( AActor * self , AActor * thing , PClassActor * item , int amount , double distance , int flags , PClassActor * filter , FName species , double mindist )
2016-01-27 20:54:46 +00:00
{
2016-08-09 21:09:24 +00:00
bool doPass = false ;
// Always allow self to give, no matter what other flags are specified. Otherwise, not at all.
2016-01-27 21:22:05 +00:00
if ( thing = = self )
{
if ( ! ( flags & RGF_GIVESELF ) )
return false ;
2016-08-09 21:09:24 +00:00
doPass = true ;
2016-01-27 21:22:05 +00:00
}
2016-07-14 14:55:13 +00:00
else if ( thing - > flags & MF_MISSILE )
2016-01-27 21:22:05 +00:00
{
2016-08-09 21:09:24 +00:00
if ( ! ( flags & RGF_MISSILES ) )
2016-01-27 21:22:05 +00:00
return false ;
2016-08-09 21:09:24 +00:00
doPass = true ;
}
else if ( ( ( flags & RGF_ITEMS ) & & thing - > IsKindOf ( RUNTIME_CLASS ( AInventory ) ) ) | |
( ( flags & RGF_CORPSES ) & & thing - > flags & MF_CORPSE ) | |
( ( flags & RGF_KILLED ) & & thing - > flags6 & MF6_KILLED ) )
{
doPass = true ;
}
else if ( ( flags & ( RGF_MONSTERS | RGF_OBJECTS | RGF_PLAYERS | RGF_VOODOO ) ) )
{
// Make sure it's alive as we're not looking for corpses or killed here.
if ( ! doPass & & thing - > health > 0 )
{
if ( thing - > player ! = nullptr )
{
if ( ( ( flags & RGF_PLAYERS ) & & ( thing - > player - > mo = = thing ) ) | |
( ( flags & RGF_VOODOO ) & & ( thing - > player - > mo ! = thing ) ) )
{
doPass = true ;
}
}
else
{
if ( ( ( flags & RGF_MONSTERS ) & & ( thing - > flags3 & MF3_ISMONSTER ) ) | |
( ( flags & RGF_OBJECTS ) & & ( ! ( thing - > flags3 & MF3_ISMONSTER ) ) & &
( thing - > flags & MF_SHOOTABLE | | thing - > flags6 & MF6_VULNERABLE ) ) )
{
doPass = true ;
}
}
}
2016-01-27 21:22:05 +00:00
}
2016-08-09 21:09:24 +00:00
// Nothing matched up so don't bother with the rest.
if ( ! doPass )
return false ;
2016-01-27 20:54:46 +00:00
//[MC] Check for a filter, species, and the related exfilter/expecies/either flag(s).
bool filterpass = DoCheckClass ( thing , filter , ! ! ( flags & RGF_EXFILTER ) ) ,
speciespass = DoCheckSpecies ( thing , species , ! ! ( flags & RGF_EXSPECIES ) ) ;
if ( ( flags & RGF_EITHER ) ? ( ! ( filterpass | | speciespass ) ) : ( ! ( filterpass & & speciespass ) ) )
{
2016-02-04 21:15:29 +00:00
if ( thing ! = self ) //Don't let filter and species obstruct RGF_GIVESELF.
2016-01-27 20:54:46 +00:00
return false ;
}
if ( ( thing ! = self ) & & ( flags & ( RGF_NOTARGET | RGF_NOMASTER | RGF_NOTRACER ) ) )
{
2016-08-09 21:09:24 +00:00
//Check for target, master, and tracer flagging.
bool targetPass = true ;
bool masterPass = true ;
bool tracerPass = true ;
bool ptrPass = false ;
2016-01-27 20:54:46 +00:00
if ( ( thing = = self - > target ) & & ( flags & RGF_NOTARGET ) )
targetPass = false ;
if ( ( thing = = self - > master ) & & ( flags & RGF_NOMASTER ) )
masterPass = false ;
if ( ( thing = = self - > tracer ) & & ( flags & RGF_NOTRACER ) )
tracerPass = false ;
ptrPass = ( flags & RGF_INCLUSIVE ) ? ( targetPass | | masterPass | | tracerPass ) : ( targetPass & & masterPass & & tracerPass ) ;
//We should not care about what the actor is here. It's safe to abort this actor.
if ( ! ptrPass )
return false ;
}
2016-08-09 21:09:24 +00:00
if ( doPass )
2016-01-27 20:54:46 +00:00
{
2016-03-25 11:57:22 +00:00
DVector3 diff = self - > Vec3To ( thing ) ;
diff . Z + = thing - > Height * 0.5 ;
2016-01-27 20:54:46 +00:00
if ( flags & RGF_CUBE )
{ // check if inside a cube
2016-03-25 11:57:22 +00:00
double dx = fabs ( diff . X ) ;
double dy = fabs ( diff . Y ) ;
double dz = fabs ( diff . Z ) ;
if ( ( dx > distance | | dy > distance | | dz > distance ) | | ( mindist & & ( dx < mindist & & dy < mindist & & dz < mindist ) ) )
2016-01-27 20:54:46 +00:00
{
return false ;
}
}
else
{ // check if inside a sphere
2016-03-25 11:57:22 +00:00
double lengthsquared = diff . LengthSquared ( ) ;
if ( lengthsquared > distance * distance | | ( mindist & & ( lengthsquared < mindist * mindist ) ) )
2016-01-27 20:54:46 +00:00
{
return false ;
}
}
if ( ( flags & RGF_NOSIGHT ) | | P_CheckSight ( thing , self , SF_IGNOREVISIBILITY | SF_IGNOREWATERBOUNDARY ) )
{ // OK to give; target is in direct path, or the monster doesn't care about it being in line of sight.
2016-03-21 13:00:05 +00:00
AInventory * gift = static_cast < AInventory * > ( Spawn ( item ) ) ;
2017-02-08 14:47:22 +00:00
if ( gift - > IsKindOf ( NAME_Health ) )
2016-01-27 20:54:46 +00:00
{
gift - > Amount * = amount ;
}
else
{
gift - > Amount = amount ;
}
gift - > flags | = MF_DROPPED ;
gift - > ClearCounters ( ) ;
if ( ! gift - > CallTryPickup ( thing ) )
{
gift - > Destroy ( ) ;
return false ;
}
else
{
return true ;
}
}
}
return false ;
}
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RadiusGive )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( item , AInventory ) ;
2016-03-25 11:57:22 +00:00
PARAM_FLOAT ( distance ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( flags ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( amount ) ;
PARAM_CLASS_DEF ( filter , AActor ) ;
PARAM_NAME_DEF ( species ) ;
PARAM_FLOAT_DEF ( mindist ) ;
PARAM_INT_DEF ( limit ) ;
2015-01-30 01:30:26 +00:00
// We need a valid item, valid targets, and a valid range
2016-05-24 02:11:26 +00:00
if ( item = = nullptr | | ( flags & RGF_MASK ) = = 0 | | ! flags | | distance < = 0 | | mindist > = distance )
2015-01-30 01:30:26 +00:00
{
2016-02-19 02:39:40 +00:00
ACTION_RETURN_INT ( 0 ) ;
2015-01-30 01:30:26 +00:00
}
2016-05-24 02:11:26 +00:00
bool unlimited = ( limit < = 0 ) ;
2015-01-30 01:30:26 +00:00
if ( amount = = 0 )
{
amount = 1 ;
}
AActor * thing ;
2016-02-19 02:39:40 +00:00
int given = 0 ;
2016-01-27 21:22:05 +00:00
if ( flags & RGF_MISSILES )
2015-01-30 01:30:26 +00:00
{
2016-01-27 21:22:05 +00:00
TThinkerIterator < AActor > it ;
2016-05-24 02:11:26 +00:00
while ( ( thing = it . Next ( ) ) & & ( ( unlimited ) | | ( given < limit ) ) )
2015-01-30 01:30:26 +00:00
{
2016-02-19 02:39:40 +00:00
given + = DoRadiusGive ( self , thing , item , amount , distance , flags , filter , species , mindist ) ;
2015-01-30 01:30:26 +00:00
}
2016-01-27 21:22:05 +00:00
}
else
{
2016-02-28 22:08:32 +00:00
FPortalGroupArray check ( FPortalGroupArray : : PGA_Full3d ) ;
2016-03-25 11:57:22 +00:00
double mid = self - > Center ( ) ;
2016-03-10 13:22:18 +00:00
FMultiBlockThingsIterator it ( check , self - > X ( ) , self - > Y ( ) , mid - distance , mid + distance , distance , false , self - > Sector ) ;
2016-02-28 22:08:32 +00:00
FMultiBlockThingsIterator : : CheckResult cres ;
2016-05-24 02:11:26 +00:00
while ( ( it . Next ( & cres ) ) & & ( ( unlimited ) | | ( given < limit ) ) )
- Significant A_RadiusGive update.
- Added filter and species parameter.
- Added new flags: RGF_INCLUSIVE, RGF_ITEMS, RGF_KILLED, RGF_EXFILTER, RGF_EXSPECIES, and RGF_EITHER.
- RGF_ITEMS: Items can receive inventory.
- RGF_KILLED: Actors who are truly dead might not be corpses, and vice versa.
- RGF_EXFILTER: Blacklists the specified actor filter. All but the filtered actor can receive the item.
- RGF_EXSPECIES: Blacklists the specified species. All but the filtered species can receive the item.
- RGF_EITHER: The actor can receive the item if it satisfies either the filter or the species. Only useful when both are used.
- RGF_INCLUSIVE: An actor marked as more than one pointer to the calling actor can ignore the exclusion pointers, but only if at least one is missing. I.e. an actor who is a target and tracer of the calling actor can still receive the item, if the calling actor doesn't pass RGF_NOTARGET and NOTRACER at the same time. RGF_INCLUSIVE only works with the pointer filtering flags. By default, if not specified, the actor will not be loopholed the item if they are under any one of the three filters.
- Fixed discrepancies and dependencies upon several flags and actor conditions which caused the function to fail.
2015-07-22 21:46:14 +00:00
{
2016-02-28 22:08:32 +00:00
given + = DoRadiusGive ( self , cres . thing , item , amount , distance , flags , filter , species , mindist ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_INT ( given ) ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_SetTics
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetTics )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_ACTION_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( tics_to_set ) ;
2015-01-30 01:30:26 +00:00
2016-06-17 07:26:33 +00:00
if ( ACTION_CALL_FROM_PSPRITE ( ) )
2016-06-16 14:11:00 +00:00
{
DPSprite * pspr = self - > player - > FindPSprite ( stateinfo - > mPSPIndex ) ;
if ( pspr ! = nullptr )
2015-01-30 01:30:26 +00:00
{
2016-06-16 14:11:00 +00:00
pspr - > Tics = tics_to_set ;
return 0 ;
2015-01-30 01:30:26 +00:00
}
}
2016-06-16 14:11:00 +00:00
else if ( ACTION_CALL_FROM_ACTOR ( ) )
{
// Just set tics for self.
self - > tics = tics_to_set ;
}
// for inventory state chains this needs to be ignored.
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//==========================================================================
//
// A_DropItem
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_DropItem )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( spawntype , AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( amount ) ;
PARAM_INT_DEF ( chance ) ;
2015-01-30 01:30:26 +00:00
P_DropItem ( self , spawntype , amount , chance ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// Common A_Damage handler
//
// A_Damage* (int amount, str damagetype, int flags, str filter, str species)
// Damages the specified actor by the specified amount. Negative values heal.
// Flags: See below.
// Filter: Specified actor is the only type allowed to be affected.
// Species: Specified species is the only type allowed to be affected.
//
// Examples:
// A_Damage(20,"Normal",DMSS_FOILINVUL,0,"DemonicSpecies") <--Only actors
// with a species "DemonicSpecies" will be affected. Use 0 to not filter by actor.
//
//===========================================================================
enum DMSS
{
DMSS_FOILINVUL = 1 , //Foil invulnerability
DMSS_AFFECTARMOR = 2 , //Make it affect armor
DMSS_KILL = 4 , //Damages them for their current health
DMSS_NOFACTOR = 8 , //Ignore DamageFactors
DMSS_FOILBUDDHA = 16 , //Can kill actors with Buddha flag, except the player.
DMSS_NOPROTECT = 32 , //Ignores PowerProtection entirely
DMSS_EXFILTER = 64 , //Changes filter into a blacklisted class instead of whitelisted.
DMSS_EXSPECIES = 128 , // ^ but with species instead.
DMSS_EITHER = 256 , //Allow either type or species to be affected.
2016-07-19 01:59:07 +00:00
DMSS_INFLICTORDMGTYPE = 512 , //Ignore the passed damagetype and use the inflictor's instead.
2015-01-30 01:30:26 +00:00
} ;
2016-05-17 16:22:29 +00:00
static void DoDamage ( AActor * dmgtarget , AActor * inflictor , AActor * source , int amount , FName DamageType , int flags , PClassActor * filter , FName species )
2015-01-30 01:30:26 +00:00
{
2015-03-27 08:57:33 +00:00
bool filterpass = DoCheckClass ( dmgtarget , filter , ! ! ( flags & DMSS_EXFILTER ) ) ,
speciespass = DoCheckSpecies ( dmgtarget , species , ! ! ( flags & DMSS_EXSPECIES ) ) ;
2015-01-30 01:30:26 +00:00
if ( ( flags & DMSS_EITHER ) ? ( filterpass | | speciespass ) : ( filterpass & & speciespass ) )
{
int dmgFlags = 0 ;
if ( flags & DMSS_FOILINVUL )
2015-03-27 08:40:47 +00:00
dmgFlags | = DMG_FOILINVUL ;
2015-01-30 01:30:26 +00:00
if ( flags & DMSS_FOILBUDDHA )
2015-03-27 08:40:47 +00:00
dmgFlags | = DMG_FOILBUDDHA ;
if ( flags & ( DMSS_KILL | DMSS_NOFACTOR ) ) //Kill implies NoFactor
dmgFlags | = DMG_NO_FACTOR ;
2015-01-30 01:30:26 +00:00
if ( ! ( flags & DMSS_AFFECTARMOR ) | | ( flags & DMSS_KILL ) ) //Kill overrides AffectArmor
2015-03-27 08:40:47 +00:00
dmgFlags | = DMG_NO_ARMOR ;
2015-01-30 01:30:26 +00:00
if ( flags & DMSS_KILL ) //Kill adds the value of the damage done to it. Allows for more controlled extreme death types.
amount + = dmgtarget - > health ;
if ( flags & DMSS_NOPROTECT ) //Ignore PowerProtection.
2015-03-27 08:40:47 +00:00
dmgFlags | = DMG_NO_PROTECT ;
2015-01-30 01:30:26 +00:00
if ( amount > 0 )
2016-02-04 21:15:29 +00:00
{ //Should wind up passing them through just fine.
2016-07-19 01:59:07 +00:00
if ( flags & DMSS_INFLICTORDMGTYPE )
DamageType = inflictor - > DamageType ;
2016-05-17 16:22:29 +00:00
P_DamageMobj ( dmgtarget , inflictor , source , amount , DamageType , dmgFlags ) ;
2016-02-04 21:15:29 +00:00
}
2015-01-30 01:30:26 +00:00
else if ( amount < 0 )
{
amount = - amount ;
P_GiveBody ( dmgtarget , amount ) ;
}
}
}
//===========================================================================
//
//
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_DamageSelf )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( amount ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2015-01-30 01:30:26 +00:00
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
DoDamage ( self , inflictor , source , amount , damagetype , flags , filter , species ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
//
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_DamageTarget )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( amount ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
if ( self - > target ! = NULL )
2016-05-17 16:22:29 +00:00
DoDamage ( self - > target , inflictor , source , amount , damagetype , flags , filter , species ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
//
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_DamageTracer )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( amount ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
if ( self - > tracer ! = NULL )
2016-05-17 16:22:29 +00:00
DoDamage ( self - > tracer , inflictor , source , amount , damagetype , flags , filter , species ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
//
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_DamageMaster )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( amount ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
if ( self - > master ! = NULL )
2016-05-17 16:22:29 +00:00
DoDamage ( self - > master , inflictor , source , amount , damagetype , flags , filter , species ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
//
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_DamageChildren )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( amount ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
2016-02-04 21:15:29 +00:00
AActor * mo ;
2015-01-30 01:30:26 +00:00
while ( ( mo = it . Next ( ) ) )
{
if ( mo - > master = = self )
2016-05-17 16:22:29 +00:00
DoDamage ( mo , inflictor , source , amount , damagetype , flags , filter , species ) ;
2015-01-30 01:30:26 +00:00
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
//
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_DamageSiblings )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( amount ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
2016-02-04 21:15:29 +00:00
AActor * mo ;
2015-01-30 01:30:26 +00:00
if ( self - > master ! = NULL )
{
while ( ( mo = it . Next ( ) ) )
{
if ( mo - > master = = self - > master & & mo ! = self )
2016-05-17 16:22:29 +00:00
DoDamage ( mo , inflictor , source , amount , damagetype , flags , filter , species ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_Kill*(damagetype, int flags)
//
//===========================================================================
enum KILS
{
KILS_FOILINVUL = 1 < < 0 ,
KILS_KILLMISSILES = 1 < < 1 ,
KILS_NOMONSTERS = 1 < < 2 ,
KILS_FOILBUDDHA = 1 < < 3 ,
KILS_EXFILTER = 1 < < 4 ,
KILS_EXSPECIES = 1 < < 5 ,
KILS_EITHER = 1 < < 6 ,
} ;
2016-05-17 16:22:29 +00:00
static void DoKill ( AActor * killtarget , AActor * inflictor , AActor * source , FName damagetype , int flags , PClassActor * filter , FName species )
2015-01-30 01:30:26 +00:00
{
2015-03-27 08:57:33 +00:00
bool filterpass = DoCheckClass ( killtarget , filter , ! ! ( flags & KILS_EXFILTER ) ) ,
speciespass = DoCheckSpecies ( killtarget , species , ! ! ( flags & KILS_EXSPECIES ) ) ;
2015-01-30 01:30:26 +00:00
if ( ( flags & KILS_EITHER ) ? ( filterpass | | speciespass ) : ( filterpass & & speciespass ) ) //Check this first. I think it'll save the engine a lot more time this way.
{
2015-03-27 08:40:47 +00:00
int dmgFlags = DMG_NO_ARMOR | DMG_NO_FACTOR ;
2015-01-30 01:30:26 +00:00
2017-08-13 14:48:49 +00:00
if ( flags & KILS_FOILINVUL )
2015-03-27 08:40:47 +00:00
dmgFlags | = DMG_FOILINVUL ;
2017-08-13 14:48:49 +00:00
if ( flags & KILS_FOILBUDDHA )
2015-03-27 08:40:47 +00:00
dmgFlags | = DMG_FOILBUDDHA ;
2015-01-30 01:30:26 +00:00
if ( ( killtarget - > flags & MF_MISSILE ) & & ( flags & KILS_KILLMISSILES ) )
{
//[MC] Now that missiles can set masters, lets put in a check to properly destroy projectiles. BUT FIRST! New feature~!
//Check to see if it's invulnerable. Disregarded if foilinvul is on, but never works on a missile with NODAMAGE
//since that's the whole point of it.
if ( ( ! ( killtarget - > flags2 & MF2_INVULNERABLE ) | | ( flags & KILS_FOILINVUL ) ) & &
2015-03-27 15:58:21 +00:00
( ! ( killtarget - > flags7 & MF7_BUDDHA ) | | ( flags & KILS_FOILBUDDHA ) ) & &
2015-03-27 08:40:47 +00:00
! ( killtarget - > flags5 & MF5_NODAMAGE ) )
2015-01-30 01:30:26 +00:00
{
P_ExplodeMissile ( killtarget , NULL , NULL ) ;
}
}
if ( ! ( flags & KILS_NOMONSTERS ) )
{
2016-05-17 16:22:29 +00:00
P_DamageMobj ( killtarget , inflictor , source , killtarget - > health , damagetype , dmgFlags ) ;
2015-01-30 01:30:26 +00:00
}
}
}
//===========================================================================
//
// A_KillTarget(damagetype, int flags)
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_KillTarget )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
if ( self - > target ! = NULL )
2016-05-17 16:22:29 +00:00
DoKill ( self - > target , inflictor , source , damagetype , flags , filter , species ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_KillTracer(damagetype, int flags)
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_KillTracer )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
if ( self - > tracer ! = NULL )
2016-05-17 16:22:29 +00:00
DoKill ( self - > tracer , inflictor , source , damagetype , flags , filter , species ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_KillMaster(damagetype, int flags)
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_KillMaster )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
2016-10-27 13:53:53 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
2016-05-17 16:22:29 +00:00
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
if ( self - > master ! = NULL )
2016-05-17 16:22:29 +00:00
DoKill ( self - > master , inflictor , source , damagetype , flags , filter , species ) ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_KillChildren(damagetype, int flags)
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_KillChildren )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
AActor * mo ;
while ( ( mo = it . Next ( ) ) )
{
if ( mo - > master = = self )
{
2016-05-17 16:22:29 +00:00
DoKill ( mo , inflictor , source , damagetype , flags , filter , species ) ;
2015-01-30 01:30:26 +00:00
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_KillSiblings(damagetype, int flags)
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_KillSiblings )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_NAME_DEF ( damagetype )
PARAM_INT_DEF ( flags )
PARAM_CLASS_DEF ( filter , AActor )
PARAM_NAME_DEF ( species )
PARAM_INT_DEF ( src )
PARAM_INT_DEF ( inflict )
2016-05-17 16:22:29 +00:00
AActor * source = COPY_AAPTR ( self , src ) ;
AActor * inflictor = COPY_AAPTR ( self , inflict ) ;
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
AActor * mo ;
if ( self - > master ! = NULL )
{
while ( ( mo = it . Next ( ) ) )
{
if ( mo - > master = = self - > master & & mo ! = self )
{
2016-05-17 16:22:29 +00:00
DoKill ( mo , inflictor , source , damagetype , flags , filter , species ) ;
2015-01-30 01:30:26 +00:00
}
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// DoRemove
//
//===========================================================================
enum RMVF_flags
{
RMVF_MISSILES = 1 < < 0 ,
RMVF_NOMONSTERS = 1 < < 1 ,
RMVF_MISC = 1 < < 2 ,
RMVF_EVERYTHING = 1 < < 3 ,
RMVF_EXFILTER = 1 < < 4 ,
RMVF_EXSPECIES = 1 < < 5 ,
RMVF_EITHER = 1 < < 6 ,
} ;
2016-02-04 21:15:29 +00:00
static void DoRemove ( AActor * removetarget , int flags , PClassActor * filter , FName species )
2015-01-30 01:30:26 +00:00
{
2015-03-27 08:57:33 +00:00
bool filterpass = DoCheckClass ( removetarget , filter , ! ! ( flags & RMVF_EXFILTER ) ) ,
speciespass = DoCheckSpecies ( removetarget , species , ! ! ( flags & RMVF_EXSPECIES ) ) ;
2015-01-30 01:30:26 +00:00
if ( ( flags & RMVF_EITHER ) ? ( filterpass | | speciespass ) : ( filterpass & & speciespass ) )
{
if ( ( flags & RMVF_EVERYTHING ) )
{
P_RemoveThing ( removetarget ) ;
}
if ( ( flags & RMVF_MISC ) & & ! ( ( removetarget - > flags3 & MF3_ISMONSTER ) & & ( removetarget - > flags & MF_MISSILE ) ) )
{
P_RemoveThing ( removetarget ) ;
}
if ( ( removetarget - > flags3 & MF3_ISMONSTER ) & & ! ( flags & RMVF_NOMONSTERS ) )
{
P_RemoveThing ( removetarget ) ;
}
if ( ( removetarget - > flags & MF_MISSILE ) & & ( flags & RMVF_MISSILES ) )
{
P_RemoveThing ( removetarget ) ;
}
}
}
//===========================================================================
//
// A_RemoveTarget
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RemoveTarget )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
PARAM_CLASS_DEF ( filter , AActor ) ;
PARAM_NAME_DEF ( species ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
if ( self - > target ! = NULL )
{
DoRemove ( self - > target , flags , filter , species ) ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_RemoveTracer
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RemoveTracer )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
PARAM_CLASS_DEF ( filter , AActor ) ;
PARAM_NAME_DEF ( species ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
if ( self - > tracer ! = NULL )
{
DoRemove ( self - > tracer , flags , filter , species ) ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_RemoveMaster
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RemoveMaster )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
PARAM_CLASS_DEF ( filter , AActor ) ;
PARAM_NAME_DEF ( species ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
if ( self - > master ! = NULL )
{
DoRemove ( self - > master , flags , filter , species ) ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_RemoveChildren
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RemoveChildren )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_BOOL_DEF ( removeall ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_CLASS_DEF ( filter , AActor ) ;
PARAM_NAME_DEF ( species ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
AActor * mo ;
while ( ( mo = it . Next ( ) ) ! = NULL )
{
if ( mo - > master = = self & & ( mo - > health < = 0 | | removeall ) )
{
DoRemove ( mo , flags , filter , species ) ;
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_RemoveSiblings
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_RemoveSiblings )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_BOOL_DEF ( removeall ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_CLASS_DEF ( filter , AActor ) ;
PARAM_NAME_DEF ( species ) ;
2016-02-04 21:15:29 +00:00
2015-01-30 01:30:26 +00:00
TThinkerIterator < AActor > it ;
AActor * mo ;
if ( self - > master ! = NULL )
{
while ( ( mo = it . Next ( ) ) ! = NULL )
{
if ( mo - > master = = self - > master & & mo ! = self & & ( mo - > health < = 0 | | removeall ) )
{
DoRemove ( mo , flags , filter , species ) ;
}
}
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_Remove
//
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_Remove )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT ( removee ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_CLASS_DEF ( filter , AActor ) ;
PARAM_NAME_DEF ( species ) ;
2015-01-30 01:30:26 +00:00
AActor * reference = COPY_AAPTR ( self , removee ) ;
if ( reference ! = NULL )
{
DoRemove ( reference , flags , filter , species ) ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SetTeleFog
//
// Sets the teleport fog(s) for the calling actor.
2015-03-31 07:24:16 +00:00
// Takes a name of the classes for the source and destination.
2015-01-30 01:30:26 +00:00
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetTeleFog )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( oldpos , AActor ) ;
PARAM_CLASS ( newpos , AActor ) ;
2015-01-30 01:30:26 +00:00
2015-03-31 07:24:16 +00:00
self - > TeleFogSourceType = oldpos ;
self - > TeleFogDestType = newpos ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SwapTeleFog
//
// Switches the source and dest telefogs around.
//===========================================================================
DEFINE_ACTION_FUNCTION ( AActor , A_SwapTeleFog )
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2015-01-30 01:30:26 +00:00
if ( ( self - > TeleFogSourceType ! = self - > TeleFogDestType ) ) //Does nothing if they're the same.
{
2016-02-04 21:15:29 +00:00
PClassActor * temp = self - > TeleFogSourceType ;
2015-01-30 01:30:26 +00:00
self - > TeleFogSourceType = self - > TeleFogDestType ;
self - > TeleFogDestType = temp ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
//
// A_SetFloatBobPhase
//
// Changes the FloatBobPhase of the actor.
//===========================================================================
//===========================================================================
// A_SetHealth
//
// Changes the health of the actor.
// Takes a pointer as well.
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetHealth )
2015-01-30 01:30:26 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_INT ( health ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr ) ;
2015-01-30 01:30:26 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
if ( ! mobj )
{
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
player_t * player = mobj - > player ;
if ( player )
{
if ( health < = 0 )
player - > mo - > health = mobj - > health = player - > health = 1 ; //Copied from the buddha cheat.
else
player - > mo - > health = mobj - > health = player - > health = health ;
}
else if ( mobj )
{
if ( health < = 0 )
mobj - > health = 1 ;
else
mobj - > health = health ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
//===========================================================================
// A_ResetHealth
//
// Resets the health of the actor to default, except if their dead.
// Takes a pointer.
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_ResetHealth )
2015-01-30 01:30:26 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr ) ;
2015-01-30 01:30:26 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
if ( ! mobj )
{
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
player_t * player = mobj - > player ;
if ( player & & ( player - > mo - > health > 0 ) )
{
player - > health = player - > mo - > health = player - > mo - > GetDefault ( ) - > health ; //Copied from the resurrect cheat.
}
else if ( mobj & & ( mobj - > health > 0 ) )
{
mobj - > health = mobj - > SpawnHealth ( ) ;
}
2016-02-04 21:15:29 +00:00
return 0 ;
2015-01-30 01:30:26 +00:00
}
2015-08-24 17:45:10 +00:00
//===========================================================================
// A_SetSpecies(str species, ptr)
//
// Sets the species of the calling actor('s pointer).
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetSpecies )
2015-08-24 17:45:10 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_NAME ( species ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( ptr ) ;
2016-02-04 21:15:29 +00:00
2015-08-24 17:45:10 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
if ( ! mobj )
{
2016-02-04 21:15:29 +00:00
return 0 ;
2015-08-24 17:45:10 +00:00
}
2015-08-25 13:15:23 +00:00
mobj - > Species = species ;
2016-02-04 21:15:29 +00:00
return 0 ;
2015-08-24 17:45:10 +00:00
}
2015-04-30 13:15:48 +00:00
2015-10-12 16:06:55 +00:00
//===========================================================================
//
// A_SetChaseThreshold(int threshold, bool def, int ptr)
//
// Sets the current chase threshold of the actor (pointer). If def is true,
// changes the default threshold which the actor resets to once it switches
// targets and doesn't have the +QUICKTORETALIATE flag.
//===========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetChaseThreshold )
2015-10-12 16:06:55 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-05 04:41:02 +00:00
PARAM_INT ( threshold ) ;
2016-10-27 13:53:53 +00:00
PARAM_BOOL_DEF ( def ) ;
PARAM_INT_DEF ( ptr ) ;
2016-02-05 04:41:02 +00:00
2015-10-12 16:06:55 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
if ( ! mobj )
{
2016-02-05 04:41:02 +00:00
return 0 ;
2015-10-12 16:06:55 +00:00
}
if ( def )
mobj - > DefThreshold = ( threshold > = 0 ) ? threshold : 0 ;
else
mobj - > threshold = ( threshold > = 0 ) ? threshold : 0 ;
2016-02-05 04:41:02 +00:00
return 0 ;
2015-10-12 16:06:55 +00:00
}
2015-11-28 16:53:34 +00:00
//==========================================================================
//
// A_CheckProximity(jump, classname, distance, count, flags, ptr)
//
// Checks to see if a certain actor class is close to the
// actor/pointer within distance, in numbers.
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckProximity )
2015-11-28 16:53:34 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-02-04 21:15:29 +00:00
PARAM_CLASS ( classname , AActor ) ;
2016-03-25 11:57:22 +00:00
PARAM_FLOAT ( distance ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( count ) ;
PARAM_INT_DEF ( flags ) ;
PARAM_INT_DEF ( ptr ) ;
2015-11-28 16:53:34 +00:00
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( ! ! P_Thing_CheckProximity ( self , classname , distance , count , flags , ptr ) ) ;
2015-11-28 16:53:34 +00:00
}
2015-10-04 21:00:40 +00:00
/*===========================================================================
A_CheckBlock
( state block , int flags , int ptr )
Checks if something is blocking the actor ( ' s pointer ) ' ptr ' .
The SET pointer flags only affect the caller , not the pointer .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
enum CBF
{
2016-03-03 02:35:54 +00:00
CBF_NOLINES = 1 < < 0 , //Don't check lines.
2015-10-04 21:00:40 +00:00
CBF_SETTARGET = 1 < < 1 , //Sets the caller/pointer's target to the actor blocking it. Actors only.
CBF_SETMASTER = 1 < < 2 , //^ but with master.
CBF_SETTRACER = 1 < < 3 , //^ but with tracer.
CBF_SETONPTR = 1 < < 4 , //Sets the pointer change on the actor doing the checking instead of self.
2016-01-31 15:45:41 +00:00
CBF_DROPOFF = 1 < < 5 , //Check for dropoffs.
2016-03-03 02:35:54 +00:00
CBF_NOACTORS = 1 < < 6 , //Don't check actors.
2016-03-10 18:54:23 +00:00
CBF_ABSOLUTEPOS = 1 < < 7 , //Absolute position for offsets.
CBF_ABSOLUTEANGLE = 1 < < 8 , //Absolute angle for offsets.
2015-10-04 21:00:40 +00:00
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , CheckBlock )
2015-10-04 21:00:40 +00:00
{
2016-04-20 02:09:15 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags )
PARAM_INT_DEF ( ptr )
PARAM_FLOAT_DEF ( xofs )
PARAM_FLOAT_DEF ( yofs )
PARAM_FLOAT_DEF ( zofs )
PARAM_ANGLE_DEF ( angle )
2015-10-04 21:00:40 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
//Needs at least one state jump to work.
if ( ! mobj )
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-10-04 21:00:40 +00:00
}
2016-03-10 18:54:23 +00:00
if ( ! ( flags & CBF_ABSOLUTEANGLE ) )
{
2016-03-25 11:57:22 +00:00
angle + = self - > Angles . Yaw ;
2016-03-10 18:54:23 +00:00
}
2016-03-25 11:57:22 +00:00
DVector3 oldpos = mobj - > Pos ( ) ;
DVector3 pos ;
2016-03-10 18:54:23 +00:00
if ( flags & CBF_ABSOLUTEPOS )
{
2016-03-25 11:57:22 +00:00
pos = { xofs , yofs , zofs } ;
2016-03-10 18:54:23 +00:00
}
else
{
2016-03-25 11:57:22 +00:00
double s = angle . Sin ( ) ;
double c = angle . Cos ( ) ;
pos = mobj - > Vec3Offset ( xofs * c + yofs * s , xofs * s - yofs * c , zofs ) ;
2016-03-10 18:54:23 +00:00
}
// Next, try checking the position based on the sensitivity desired.
// If checking for dropoffs, set the z so we can have maximum flexibility.
// Otherwise, set origin and set it back after testing.
bool checker = false ;
if ( flags & CBF_DROPOFF )
{
2016-04-10 16:51:40 +00:00
// Unfortunately, whenever P_CheckMove returned false, that means it could
// ignore a variety of flags mainly because of P_CheckPosition. This
// results in picking up false positives due to actors or lines being in the way
// when they clearly should not be.
int fpass = PCM_DROPOFF ;
if ( flags & CBF_NOACTORS ) fpass | = PCM_NOACTORS ;
if ( flags & CBF_NOLINES ) fpass | = PCM_NOLINES ;
2016-03-25 11:57:22 +00:00
mobj - > SetZ ( pos . Z ) ;
2016-04-10 16:51:40 +00:00
checker = P_CheckMove ( mobj , pos , fpass ) ;
2016-03-25 11:57:22 +00:00
mobj - > SetZ ( oldpos . Z ) ;
2016-03-10 18:54:23 +00:00
}
else
{
mobj - > SetOrigin ( pos , true ) ;
checker = P_TestMobjLocation ( mobj ) ;
mobj - > SetOrigin ( oldpos , true ) ;
}
2016-02-19 03:39:13 +00:00
if ( checker )
{
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( false ) ;
2016-02-19 03:39:13 +00:00
}
2015-10-04 21:00:40 +00:00
if ( mobj - > BlockingMobj )
{
AActor * setter = ( flags & CBF_SETONPTR ) ? mobj : self ;
if ( setter )
{
if ( flags & CBF_SETTARGET ) setter - > target = mobj - > BlockingMobj ;
if ( flags & CBF_SETMASTER ) setter - > master = mobj - > BlockingMobj ;
if ( flags & CBF_SETTRACER ) setter - > tracer = mobj - > BlockingMobj ;
}
}
2016-03-03 02:35:54 +00:00
//[MC] I don't know why I let myself be persuaded not to include a flag.
//If an actor is loaded with pointers, they don't really have any options to spare.
2016-04-09 19:44:17 +00:00
//Also, fail if a dropoff or a step is too great to pass over when checking for dropoffs.
2016-04-10 16:51:40 +00:00
2016-11-14 13:12:27 +00:00
ACTION_RETURN_BOOL ( ( ! ( flags & CBF_NOACTORS ) & & ( mobj - > BlockingMobj ) ) | | ( ! ( flags & CBF_NOLINES ) & & mobj - > BlockingLine ! = NULL ) | |
( ( flags & CBF_DROPOFF ) & & ! checker ) ) ;
2015-11-28 16:53:34 +00:00
}
2015-11-25 07:44:19 +00:00
//===========================================================================
//
2016-01-27 16:12:13 +00:00
// A_FaceMovementDirection(angle offset, bool pitch, ptr)
2015-11-25 07:44:19 +00:00
//
// Sets the actor('s pointer) to face the direction of travel.
//===========================================================================
2016-01-27 16:12:13 +00:00
enum FMDFlags
2015-11-25 07:44:19 +00:00
{
2016-01-27 16:12:13 +00:00
FMDF_NOPITCH = 1 < < 0 ,
FMDF_INTERPOLATE = 1 < < 1 ,
FMDF_NOANGLE = 1 < < 2 ,
2015-11-25 07:44:19 +00:00
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_FaceMovementDirection )
2015-11-25 07:44:19 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_ANGLE_DEF ( offset )
PARAM_ANGLE_DEF ( anglelimit )
PARAM_ANGLE_DEF ( pitchlimit )
PARAM_INT_DEF ( flags )
PARAM_INT_DEF ( ptr )
2015-11-25 07:44:19 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
//Need an actor.
2016-01-27 16:12:13 +00:00
if ( ! mobj | | ( ( flags & FMDF_NOPITCH ) & & ( flags & FMDF_NOANGLE ) ) )
2015-11-25 07:44:19 +00:00
{
2016-02-19 02:39:40 +00:00
ACTION_RETURN_BOOL ( false ) ;
2015-11-25 07:44:19 +00:00
}
2016-02-04 21:15:29 +00:00
2015-11-25 07:44:19 +00:00
//Don't bother calculating this if we don't have any horizontal movement.
2016-03-19 23:54:18 +00:00
if ( ! ( flags & FMDF_NOANGLE ) & & ( mobj - > Vel . X ! = 0 | | mobj - > Vel . Y ! = 0 ) )
2015-11-25 07:44:19 +00:00
{
2016-03-25 11:57:22 +00:00
DAngle current = mobj - > Angles . Yaw ;
DAngle angle = mobj - > Vel . Angle ( ) ;
2015-11-26 03:49:25 +00:00
//Done because using anglelimit directly causes a signed/unsigned mismatch.
//Code borrowed from A_Face*.
2016-03-25 11:57:22 +00:00
if ( anglelimit > 0 )
2015-11-26 03:49:25 +00:00
{
2016-03-25 21:17:28 +00:00
DAngle delta = - deltaangle ( current , angle ) ;
2016-03-25 11:57:22 +00:00
if ( fabs ( delta ) > anglelimit )
2015-11-26 03:49:25 +00:00
{
2016-03-25 11:57:22 +00:00
if ( delta < 0 )
{
current + = anglelimit + offset ;
}
else if ( delta > 0 )
{
current - = anglelimit + offset ;
}
2016-01-27 16:12:13 +00:00
mobj - > SetAngle ( current , ! ! ( flags & FMDF_INTERPOLATE ) ) ;
2015-11-26 03:49:25 +00:00
}
2016-08-18 20:05:18 +00:00
else
mobj - > SetAngle ( angle + offset , ! ! ( flags & FMDF_INTERPOLATE ) ) ;
2015-11-26 03:49:25 +00:00
}
else
2016-01-27 16:12:13 +00:00
mobj - > SetAngle ( angle + offset , ! ! ( flags & FMDF_INTERPOLATE ) ) ;
2015-11-25 07:44:19 +00:00
}
2016-01-27 16:12:13 +00:00
if ( ! ( flags & FMDF_NOPITCH ) )
2015-11-25 07:44:19 +00:00
{
2016-03-25 11:57:22 +00:00
DAngle current = mobj - > Angles . Pitch ;
const DVector2 velocity = mobj - > Vel . XY ( ) ;
2016-12-24 17:10:37 +00:00
DAngle pitch = - VecToAngle ( velocity . Length ( ) , mobj - > Vel . Z ) ;
2015-11-26 03:49:25 +00:00
if ( pitchlimit > 0 )
{
2016-12-24 17:10:37 +00:00
DAngle pdelta = deltaangle ( current , pitch ) ;
2016-02-04 21:15:29 +00:00
2016-03-25 11:57:22 +00:00
if ( fabs ( pdelta ) > pitchlimit )
2015-11-26 03:49:25 +00:00
{
2016-03-25 11:57:22 +00:00
if ( pdelta > 0 )
2015-11-26 03:49:25 +00:00
{
2016-03-25 11:57:22 +00:00
current - = MIN ( pitchlimit , pdelta ) ;
2015-11-26 03:49:25 +00:00
}
2016-03-25 11:57:22 +00:00
else //if (pdelta < 0)
2015-11-26 03:49:25 +00:00
{
2016-03-25 11:57:22 +00:00
current + = MIN ( pitchlimit , - pdelta ) ;
2015-11-26 03:49:25 +00:00
}
2016-01-27 16:12:13 +00:00
mobj - > SetPitch ( current , ! ! ( flags & FMDF_INTERPOLATE ) ) ;
2015-11-26 03:49:25 +00:00
}
else
{
2016-01-27 16:12:13 +00:00
mobj - > SetPitch ( pitch , ! ! ( flags & FMDF_INTERPOLATE ) ) ;
2015-11-26 03:49:25 +00:00
}
2016-02-04 21:15:29 +00:00
2015-11-26 03:49:25 +00:00
}
2015-11-25 07:44:19 +00:00
else
{
2016-01-27 16:12:13 +00:00
mobj - > SetPitch ( pitch , ! ! ( flags & FMDF_INTERPOLATE ) ) ;
2015-11-25 07:44:19 +00:00
}
}
2016-02-19 02:39:40 +00:00
ACTION_RETURN_BOOL ( true ) ;
2015-11-26 05:17:13 +00:00
}
2016-05-01 13:45:50 +00:00
2016-07-24 16:40:05 +00:00
//==========================================================================
//
// A_CopySpriteFrame(from, to, flags)
//
// Copies the sprite and/or frame from one pointer to another.
//==========================================================================
enum CPSFFlags
{
CPSF_NOSPRITE = 1 ,
CPSF_NOFRAME = 1 < < 1 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_CopySpriteFrame )
2016-07-24 16:40:05 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-07-24 16:40:05 +00:00
PARAM_INT ( from ) ;
PARAM_INT ( to ) ;
2016-10-27 13:53:53 +00:00
PARAM_INT_DEF ( flags ) ;
2016-07-24 16:40:05 +00:00
AActor * copyfrom = COPY_AAPTR ( self , from ) ;
AActor * copyto = COPY_AAPTR ( self , to ) ;
if ( copyfrom = = copyto | | copyfrom = = nullptr | | copyto = = nullptr | | ( ( flags & CPSF_NOSPRITE ) & & ( flags & CPSF_NOFRAME ) ) )
{
ACTION_RETURN_BOOL ( false ) ;
}
if ( ! ( flags & CPSF_NOSPRITE ) ) copyto - > sprite = copyfrom - > sprite ;
if ( ! ( flags & CPSF_NOFRAME ) ) copyto - > frame = copyfrom - > frame ;
ACTION_RETURN_BOOL ( true ) ;
}
2016-07-28 20:52:20 +00:00
2016-09-18 20:07:08 +00:00
//==========================================================================
//
// A_SetMaskRotation(anglestart, angleend, pitchstart, pitchend, flags, ptr)
//
// Specifies how much to fake a sprite rotation.
//==========================================================================
enum VRFFlags
{
VRF_NOANGLESTART = 1 ,
VRF_NOANGLEEND = 1 < < 1 ,
VRF_NOPITCHSTART = 1 < < 2 ,
VRF_NOPITCHEND = 1 < < 3 ,
} ;
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetVisibleRotation )
2016-09-18 20:07:08 +00:00
{
2016-10-22 15:49:08 +00:00
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-10-27 13:53:53 +00:00
PARAM_ANGLE_DEF ( anglestart )
PARAM_ANGLE_DEF ( angleend )
PARAM_ANGLE_DEF ( pitchstart )
PARAM_ANGLE_DEF ( pitchend )
PARAM_INT_DEF ( flags )
PARAM_INT_DEF ( ptr )
2016-09-18 20:07:08 +00:00
AActor * mobj = COPY_AAPTR ( self , ptr ) ;
if ( mobj = = nullptr )
{
ACTION_RETURN_BOOL ( false ) ;
}
if ( ! ( flags & VRF_NOANGLESTART ) )
{
mobj - > VisibleStartAngle = anglestart ;
}
if ( ! ( flags & VRF_NOANGLEEND ) )
{
mobj - > VisibleEndAngle = angleend ;
}
if ( ! ( flags & VRF_NOPITCHSTART ) )
{
mobj - > VisibleStartPitch = pitchstart ;
}
if ( ! ( flags & VRF_NOPITCHEND ) )
{
mobj - > VisibleEndPitch = pitchend ;
}
ACTION_RETURN_BOOL ( true ) ;
}
2016-10-02 12:09:45 +00:00
//==========================================================================
//
//
//
//==========================================================================
2016-11-16 00:36:21 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetTranslation )
2016-10-02 12:09:45 +00:00
{
PARAM_SELF_PROLOGUE ( AActor ) ;
2016-11-25 15:05:03 +00:00
PARAM_NAME ( trname ) ;
2016-10-02 12:09:45 +00:00
self - > SetTranslation ( trname ) ;
return 0 ;
}
2016-11-28 22:30:14 +00:00
//==========================================================================
//
//
//
//==========================================================================
DEFINE_ACTION_FUNCTION ( AActor , A_CheckTerrain )
{
PARAM_SELF_PROLOGUE ( AActor ) ;
sector_t * sec = self - > Sector ;
if ( self - > Z ( ) = = sec - > floorplane . ZatPoint ( self ) & & sec - > PortalBlocksMovement ( sector_t : : floor ) )
{
if ( sec - > special = = Damage_InstantDeath )
{
P_DamageMobj ( self , NULL , NULL , 999 , NAME_InstantDeath ) ;
}
else if ( sec - > special = = Scroll_StrifeCurrent )
{
int anglespeed = tagManager . GetFirstSectorTag ( sec ) - 100 ;
double speed = ( anglespeed % 10 ) / 16. ;
DAngle an = ( anglespeed / 10 ) * ( 360 / 8. ) ;
self - > Thrust ( an , speed ) ;
}
}
return 0 ;
}
2016-12-17 18:46:40 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetSize )
{
PARAM_SELF_PROLOGUE ( AActor ) ;
2018-03-30 23:06:46 +00:00
PARAM_FLOAT_DEF ( newradius ) ;
2016-12-17 18:46:40 +00:00
PARAM_FLOAT_DEF ( newheight ) ;
2016-12-18 00:31:25 +00:00
PARAM_BOOL_DEF ( testpos ) ;
2016-12-17 18:46:40 +00:00
if ( newradius < 0. ) newradius = self - > radius ;
if ( newheight < 0. ) newheight = self - > Height ;
2016-12-18 00:31:25 +00:00
double oldradius = self - > radius ;
double oldheight = self - > Height ;
2016-12-25 21:40:26 +00:00
FLinkContext ctx ;
self - > UnlinkFromWorld ( & ctx ) ;
2016-12-17 18:46:40 +00:00
self - > radius = newradius ;
self - > Height = newheight ;
2016-12-25 21:40:26 +00:00
self - > LinkToWorld ( & ctx ) ;
2016-12-18 00:31:25 +00:00
if ( testpos & & ! P_TestMobjLocation ( self ) )
{
2016-12-25 21:40:26 +00:00
self - > UnlinkFromWorld ( & ctx ) ;
2016-12-18 00:31:25 +00:00
self - > radius = oldradius ;
self - > Height = oldheight ;
2016-12-25 21:40:26 +00:00
self - > LinkToWorld ( & ctx ) ;
2016-12-18 00:31:25 +00:00
ACTION_RETURN_BOOL ( false ) ;
}
2017-01-23 23:12:06 +00:00
if ( self - > player & & self - > player - > mo = = self )
{
self - > player - > mo - > FullHeight = newheight ;
}
2016-12-18 00:31:25 +00:00
ACTION_RETURN_BOOL ( true ) ;
2016-12-17 18:46:40 +00:00
}
2017-02-05 17:07:12 +00:00
DEFINE_ACTION_FUNCTION ( AActor , SetCamera )
{
PARAM_ACTION_PROLOGUE ( AActor ) ;
PARAM_OBJECT ( cam , AActor ) ;
PARAM_BOOL_DEF ( revert ) ;
if ( self - > player = = nullptr | | self - > player - > mo ! = self ) return 0 ;
2017-02-08 14:30:00 +00:00
if ( cam = = nullptr )
2017-02-05 17:07:12 +00:00
{
2017-02-08 14:30:00 +00:00
cam = self ;
2017-02-05 17:07:12 +00:00
revert = false ;
}
AActor * oldcamera = self - > player - > camera ;
2017-02-08 14:30:00 +00:00
self - > player - > camera = cam ;
2017-02-05 17:07:12 +00:00
if ( revert ) self - > player - > cheats | = CF_REVERTPLEASE ;
2017-02-08 14:30:00 +00:00
if ( oldcamera ! = cam )
2017-02-05 17:07:12 +00:00
{
2017-02-08 14:30:00 +00:00
R_ClearPastViewer ( cam ) ;
2017-02-05 17:07:12 +00:00
}
return 0 ;
}
2017-02-26 17:37:12 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SprayDecal )
{
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_STRING ( name ) ;
2017-04-14 14:28:54 +00:00
PARAM_FLOAT_DEF ( dist ) ;
SprayDecal ( self , name , dist ) ;
2017-02-26 17:37:12 +00:00
return 0 ;
}
2017-02-26 17:46:06 +00:00
DEFINE_ACTION_FUNCTION ( AActor , A_SetMugshotState )
{
PARAM_SELF_PROLOGUE ( AActor ) ;
PARAM_STRING ( name ) ;
if ( self - > CheckLocalView ( consoleplayer ) )
StatusBar - > SetMugShotState ( name ) ;
return 0 ;
2017-03-15 09:36:41 +00:00
}
// This needs to account for the fact that internally renderstyles are stored as a series of operations,
// but the script side only cares about symbolic constants.
DEFINE_ACTION_FUNCTION ( AActor , GetRenderStyle )
{
PARAM_SELF_PROLOGUE ( AActor ) ;
for ( unsigned i = 0 ; i < STYLE_Count ; i + + )
{
if ( self - > RenderStyle = = LegacyRenderStyles [ i ] ) ACTION_RETURN_INT ( i ) ;
}
ACTION_RETURN_INT ( - 1 ) ; // no symbolic constant exists to handle this style.
}