- started with a ScriptUtil class which will allow moving function implementations for ACS and FraggleScript to zscript.txt

So far 3 functions for testing implemented.
This commit is contained in:
Christoph Oelckers 2018-11-24 13:06:01 +01:00
commit 6fc63b9b78
10 changed files with 280 additions and 130 deletions

View file

@ -48,6 +48,7 @@
#include "r_utility.h"
#include "g_levellocals.h"
#include "actorinlines.h"
#include "scriptutil.h"
static FRandom pr_script("FScript");
@ -283,6 +284,17 @@ static int T_GetPlayerNum(const svalue_t &arg)
return playernum;
}
APlayerPawn *T_GetPlayerActor(const svalue_t &arg)
{
int num = T_GetPlayerNum(arg);
return num == -1 ? nullptr : players[num].mo;
}
PClassActor *T_ClassType(const svalue_t &arg)
{
return PClass::FindActor(stringvalue(arg));
}
//==========================================================================
//
// Finds a sector from a tag. This has been extended to allow looking for
@ -2834,34 +2846,8 @@ void FParser::SF_SetWeapon()
{
if (CheckArgs(2))
{
int playernum=T_GetPlayerNum(t_argv[0]);
if (playernum!=-1)
{
AInventory *item = players[playernum].mo->FindInventory (PClass::FindActor (stringvalue(t_argv[1])));
if (item == NULL || !item->IsKindOf(NAME_Weapon))
{
}
else if (players[playernum].ReadyWeapon == item)
{
// The weapon is already selected, so setweapon succeeds by default,
// but make sure the player isn't switching away from it.
players[playernum].PendingWeapon = WP_NOCHANGE;
t_return.value.i = 1;
}
else
{
auto weap = static_cast<AWeapon *> (item);
if (weap->CheckAmmo (AWeapon::EitherFire, false))
{
// There's enough ammo, so switch to it.
t_return.value.i = 1;
players[playernum].PendingWeapon = weap;
}
}
}
t_return.value.i = 0;
t_return.type = svt_int;
t_return.value.i = ScriptUtil::Exec(NAME_SetWeapon, ScriptUtil::Pointer, T_GetPlayerActor(t_argv[0]), ScriptUtil::Class, T_ClassType(t_argv[1]), ScriptUtil::End);
}
}