- scriptified cht_Takeweaps.

This commit is contained in:
Christoph Oelckers 2018-11-25 01:26:19 +01:00
parent bc86ec4c51
commit f218e95c4d
4 changed files with 53 additions and 37 deletions

View File

@ -793,19 +793,28 @@ void G_BuildTiccmd (ticcmd_t *cmd)
//[Graf Zahl] This really helps if the mouse update rate can't be increased!
CVAR (Bool, smooth_mouse, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE)
static int LookAdjust(int look)
{
look <<= 16;
if (players[consoleplayer].playerstate != PST_DEAD && // No adjustment while dead.
players[consoleplayer].ReadyWeapon != NULL) // No adjustment if no weapon.
{
auto scale = players[consoleplayer].ReadyWeapon->FOVScale;
if (scale > 0) // No adjustment if it is non-positive.
{
look = int(look * scale);
}
}
return look;
}
void G_AddViewPitch (int look, bool mouse)
{
if (gamestate == GS_TITLELEVEL)
{
return;
}
look <<= 16;
if (players[consoleplayer].playerstate != PST_DEAD && // No adjustment while dead.
players[consoleplayer].ReadyWeapon != NULL && // No adjustment if no weapon.
players[consoleplayer].ReadyWeapon->FOVScale > 0) // No adjustment if it is non-positive.
{
look = int(look * players[consoleplayer].ReadyWeapon->FOVScale);
}
look = LookAdjust(look);
if (!level.IsFreelookAllowed())
{
LocalViewPitch = 0;
@ -845,14 +854,9 @@ void G_AddViewAngle (int yaw, bool mouse)
if (gamestate == GS_TITLELEVEL)
{
return;
}
yaw <<= 16;
if (players[consoleplayer].playerstate != PST_DEAD && // No adjustment while dead.
players[consoleplayer].ReadyWeapon != NULL && // No adjustment if no weapon.
players[consoleplayer].ReadyWeapon->FOVScale > 0) // No adjustment if it is non-positive.
{
yaw = int(yaw * players[consoleplayer].ReadyWeapon->FOVScale);
}
yaw = LookAdjust(yaw);
LocalViewAngle -= yaw;
if (yaw != 0)
{

View File

@ -416,29 +416,7 @@ void cht_DoCheat (player_t *player, int cheat)
break;
case CHT_TAKEWEAPS:
if (player->morphTics || player->mo == NULL || player->mo->health <= 0)
{
return;
}
{
// Take away all weapons that are either non-wimpy or use ammo.
AInventory **invp = &player->mo->Inventory, **lastinvp;
for (item = *invp; item != NULL; item = *invp)
{
lastinvp = invp;
invp = &(*invp)->Inventory;
if (item->IsKindOf(NAME_Weapon))
{
AWeapon *weap = static_cast<AWeapon *> (item);
if (!(weap->WeaponFlags & WIF_WIMPY_WEAPON) ||
weap->AmmoType1 != NULL)
{
item->Destroy ();
invp = lastinvp;
}
}
}
}
cht_Takeweaps(player);
msg = GStrings("TXT_CHEATIDKFA");
break;
@ -613,6 +591,15 @@ void cht_Take (player_t *player, const char *name, int amount)
}
}
void cht_Takeweaps(player_t *player)
{
IFVIRTUALPTR(player->mo, APlayerPawn, CheatTakeWeaps)
{
VMValue params[3] = { player->mo };
VMCall(func, params, 1, nullptr, 0);
}
}
class DSuicider : public DThinker
{
DECLARE_CLASS(DSuicider, DThinker)

View File

@ -16,5 +16,6 @@ void cht_Take (player_t *player, const char *item, int amount=1);
void cht_SetInv(player_t *player, const char *item, int amount = 1, bool beyondMax = false);
void cht_Suicide (player_t *player);
FString cht_Morph (player_t *player, PClassActor *morphclass, bool quickundo);
void cht_Takeweaps(player_t *player);
#endif

View File

@ -426,4 +426,28 @@ extend class PlayerPawn
return "";
}
virtual void CheatTakeWeaps()
{
if (player.morphTics || health <= 0)
{
return;
}
// Do not mass-delete directly from the linked list. That can cause problems.
Array<Inventory> collect;
// Take away all weapons that are either non-wimpy or use ammo.
for(let item = Inv; item; item = item.Inv)
{
let weap = Weapon(item);
if (weap && (!weap.bWimpy_Weapon || weap.AmmoType1 != null))
{
collect.Push(item);
}
}
// Destroy them in a second loop. We have to look out for indirect destructions here as will happen with powered up weapons.
for(int i = 0; i < collect.Size(); i++)
{
let item = collect[i];
if (item) item.Destroy();
}
}
}