- scriptified useflechette CCMD's item finding code.

This commit is contained in:
Christoph Oelckers 2019-01-02 11:53:53 +01:00
commit bc47fdfa78
4 changed files with 47 additions and 34 deletions

View file

@ -467,40 +467,17 @@ CCMD (drop)
}
}
PClassActor *GetFlechetteType(AActor *other);
CCMD (useflechette)
{ // Select from one of arti_poisonbag1-3, whichever the player has
static const ENamedName bagnames[3] =
{
if (who == nullptr) return;
IFVIRTUALPTR(who, APlayerPawn, GetFlechetteItem)
{
NAME_ArtiPoisonBag3, // use type 3 first because that's the default when the player has none specified.
NAME_ArtiPoisonBag1,
NAME_ArtiPoisonBag2
};
VMValue params[] = { who };
AActor *cls;
VMReturn ret((void**)&cls);
VMCall(func, params, 1, &ret, 1);
if (who == NULL)
return;
PClassActor *type = who->FlechetteType;
if (type != NULL)
{
AActor *item;
if ( (item = who->FindInventory (type) ))
{
SendItemUse = item;
return;
}
}
// The default flechette could not be found, or the player had no default. Try all 3 types then.
for (int j = 0; j < 3; ++j)
{
AActor *item;
if ( (item = who->FindInventory (bagnames[j])) )
{
SendItemUse = item;
break;
}
if (cls != nullptr) SendItemUse = cls;
}
}