From f566571153e15c66bc4d066fd4ac2fbad00567cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Wed, 11 Dec 2019 11:21:47 +0200 Subject: [PATCH] World|Scripting: Added World.Thing.recoil() IssueID #2349 --- .../client/src/world/base/bindings_world.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/doomsday/apps/client/src/world/base/bindings_world.cpp b/doomsday/apps/client/src/world/base/bindings_world.cpp index eee34afb51..923394a2d6 100644 --- a/doomsday/apps/client/src/world/base/bindings_world.cpp +++ b/doomsday/apps/client/src/world/base/bindings_world.cpp @@ -63,6 +63,20 @@ static Value *Function_Thing_StartSound(Context &ctx, const Function::ArgumentVa return nullptr; } +static Value *Function_Thing_Recoil(Context &ctx, const Function::ArgumentValues &args) +{ + mobj_t & mo = ClientServerWorld::contextMobj(ctx); + const double force = args.at(0)->asNumber(); + + const angle_t angle = mo.angle + ANG180; + const float angle_f = float(angle) / float(ANGLE_180) * PIf; + + mo.mom[MX] += force * cos(angle_f); + mo.mom[MY] += force * sin(angle_f); + + return nullptr; +} + void initBindings(Binder &binder, Record &worldModule) { // Global functions. @@ -81,8 +95,8 @@ void initBindings(Binder &binder, Record &worldModule) binder.init(thing) << DENG2_FUNC_NOARG(Thing_Id, "id") << DENG2_FUNC_NOARG(Thing_Health, "health") - << DENG2_FUNC_DEFS (Thing_StartSound, "startSound", "id" << "volume", startSoundArgs); - + << DENG2_FUNC_DEFS (Thing_StartSound, "startSound", "id" << "volume", startSoundArgs) + << DENG2_FUNC (Thing_Recoil, "recoil", "force"); } }