- scriptified A_SelectWeapon

This commit is contained in:
Christoph Oelckers 2018-12-04 17:31:25 +01:00
parent 9348baeeb1
commit 44e43c48b5
3 changed files with 58 additions and 66 deletions

View file

@ -1529,54 +1529,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Recoil)
}
//===========================================================================
//
// A_SelectWeapon
//
//===========================================================================
enum SW_Flags
{
SWF_SELECTPRIORITY = 1,
};
DEFINE_ACTION_FUNCTION(AActor, A_SelectWeapon)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_CLASS(cls, AActor);
PARAM_INT(flags);
bool selectPriority = !!(flags & SWF_SELECTPRIORITY);
if ((!selectPriority && cls == NULL) || self->player == NULL)
{
ACTION_RETURN_BOOL(false);
}
auto weaponitem = self->FindInventory(cls);
if (weaponitem != NULL && weaponitem->IsKindOf(NAME_Weapon))
{
if (self->player->ReadyWeapon != weaponitem)
{
self->player->PendingWeapon = weaponitem;
}
ACTION_RETURN_BOOL(true);
}
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);
}
else
{
ACTION_RETURN_BOOL(false);
}
}
//===========================================================================
///===========================================================================
//
// A_Print
//

View file

@ -1067,7 +1067,7 @@ class Actor : Thinker native
native void A_QueueCorpse();
native void A_DeQueueCorpse();
native void A_ClearLastHeard();
native bool A_SelectWeapon(class<Weapon> whichweapon, int flags = 0);
native void A_ClassBossHealth();
native void A_SetAngle(double angle = 0, int flags = 0, int ptr = AAPTR_DEFAULT);
native void A_SetPitch(double pitch, int flags = 0, int ptr = AAPTR_DEFAULT);

View file

@ -730,8 +730,47 @@ extend class Actor
return false;
}
//===========================================================================
//
// A_SelectWeapon
//
//===========================================================================
bool A_SelectWeapon(class<Weapon> whichweapon, int flags = 0)
{
bool selectPriority = !!(flags & SWF_SELECTPRIORITY);
let player = self.player;
if ((!selectPriority && whichweapon == NULL) || player == NULL)
{
return false;
}
let weaponitem = Weapon(FindInventory(whichweapon));
if (weaponitem != NULL)
{
if (player.ReadyWeapon != weaponitem)
{
player.PendingWeapon = weaponitem;
}
return true;
}
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.
player.mo.PickNewWeapon(NULL);
return true;
}
else
{
return false;
}
}
}