/
bindings_world.cpp
103 lines (86 loc) · 3.25 KB
/
bindings_world.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/** @file bindings_world.cpp World related Doomsday Script bindings.
*
* @authors Copyright (c) 2015-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#include "world/bindings_world.h"
#include "world/clientserverworld.h"
#include "world/map.h"
#include "world/thinkers.h"
#include "world/p_players.h"
#include "audio/audiosystem.h"
#include "dd_main.h"
#include <doomsday/defs/ded.h>
#include <doomsday/world/mobj.h>
#include <de/Context>
using namespace de;
namespace world {
static Value *Function_World_ConsolePlayer(Context &, const Function::ArgumentValues &)
{
return new NumberValue(consolePlayer);
}
static Value *Function_Thing_Id(Context &ctx, const Function::ArgumentValues &)
{
return new NumberValue(ClientServerWorld::contextMobj(ctx).thinker.id);
}
static Value *Function_Thing_Health(Context &ctx, const Function::ArgumentValues &)
{
return new NumberValue(ClientServerWorld::contextMobj(ctx).health);
}
static Value *Function_Thing_StartSound(Context &ctx, const Function::ArgumentValues &args)
{
const mobj_t &mo = ClientServerWorld::contextMobj(ctx);
const int sound = DED_Definitions()->getSoundNum(args.at(0)->asText());
const float volume = float(args.at(1)->asNumber());
if (sound >= 0)
{
S_StartSoundAtVolume(sound, &mo, volume);
}
else
{
throw Error("Function_Thing_StartSound", "Undefined sound: " + args.at(0)->asText());
}
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.
{
binder.init(worldModule)
<< DENG2_FUNC_NOARG(World_ConsolePlayer, "consolePlayer");
}
// Thing
{
Record &thing = worldModule.addSubrecord("Thing");
Function::Defaults startSoundArgs;
startSoundArgs["volume"] = new NumberValue(1.0);
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 (Thing_Recoil, "recoil", "force");
}
}
} // namespace world