Skip to content

Commit

Permalink
Heretic|Scripting: Added World.Thing.attack() method
Browse files Browse the repository at this point in the history
Higher-level melee/missile attack. Returns nonzero if attack was made; 1 if melee, 2 if missile.
  • Loading branch information
skyjake committed Jan 20, 2019
1 parent 447ad66 commit ae826b7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
21 changes: 21 additions & 0 deletions doomsday/apps/plugins/common/src/common.cpp
Expand Up @@ -173,6 +173,20 @@ static de::Value *Function_Thing_SpawnMissile(de::Context &ctx, const de::Functi
return nullptr;
}

#if defined(__JHERETIC__)
static de::Value *Function_Thing_Attack(de::Context &ctx, const de::Function::ArgumentValues &args)
{
using namespace de;

mobj_t *src = &instanceMobj(ctx);

const int meleeDamage = args.at(0)->asInt();
const mobjtype_t missileId = mobjtype_t(Defs().getMobjNum(args.at(1)->asText()));

return new NumberValue(P_Attack(src, meleeDamage, missileId));
}
#endif

void Common_Load()
{
using namespace de;
Expand All @@ -181,9 +195,16 @@ void Common_Load()
spawnMissileArgs["angle"] = new NoneValue;
spawnMissileArgs["momz"] = new NumberValue(0.0);

Function::Defaults attackArgs;
attackArgs["damage"] = new NumberValue(0.0);
attackArgs["missile"] = new NoneValue;

DENG2_ASSERT(gameBindings == nullptr);
gameBindings = new Binder;
gameBindings->init(ScriptSystem::get().builtInClass("World", "Thing"))
#if defined(__JHERETIC__)
<< DENG2_FUNC_DEFS(Thing_Attack, "attack", "damage" << "missile", attackArgs)
#endif
<< DENG2_FUNC_DEFS(Thing_SpawnMissile, "spawnMissile", "id" << "angle" << "momz", spawnMissileArgs);
}

Expand Down
3 changes: 2 additions & 1 deletion doomsday/apps/plugins/heretic/include/p_enemy.h
Expand Up @@ -38,7 +38,8 @@ extern "C" {

void P_ClearBodyQueue(void);
int P_Massacre(void);
void P_NoiseAlert(mobj_t* target, mobj_t* emmiter);
void P_NoiseAlert(mobj_t* target, mobj_t* emitter);
int P_Attack(mobj_t *actor, int meleeDamage, mobjtype_t missileType);
void P_DSparilTeleport(mobj_t* actor);

#ifdef __cplusplus
Expand Down
18 changes: 18 additions & 0 deletions doomsday/apps/plugins/heretic/src/p_enemy.c
Expand Up @@ -1576,6 +1576,24 @@ void C_DECL A_MntrFloorFire(mobj_t* actor)
}
}

int P_Attack(mobj_t *actor, int meleeDamage, mobjtype_t missileType)
{
if (actor->target)
{
if (P_CheckMeleeRange(actor))
{
P_DamageMobj(actor->target, actor, actor, meleeDamage, false);
return 1;
}
else
{
P_SpawnMissile(missileType, actor, actor->target, true);
return 2;
}
}
return 0;
}

void C_DECL A_BeastAttack(mobj_t* actor)
{
if(!actor->target)
Expand Down

0 comments on commit ae826b7

Please sign in to comment.