summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-05-08 00:08:29 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-05-11 23:31:16 +0200
commit74f773e1448b7023feb49b0a3c8ab62c70c46003 (patch)
treea7e64080b21357fd93c92121b300bfde9541bf4f
parent633fad1a9c38a92da32907e763e1dab42c0dcf8d (diff)
downloadmanaserv-74f773e1448b7023feb49b0a3c8ab62c70c46003.tar.gz
manaserv-74f773e1448b7023feb49b0a3c8ab62c70c46003.tar.xz
manaserv-74f773e1448b7023feb49b0a3c8ab62c70c46003.zip
Added look_at bind
-rw-r--r--src/scripting/lua.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 447b2ca..2a02b3c 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1398,6 +1398,38 @@ static int entity_destination(lua_State *s)
return 2;
}
+/** LUA entity:entity_look_at (being)
+ * local x, y = entity:entity_look_at(entity other)
+ * local x, y = entity:entity_look_at(int x, int y)
+ **
+ * Valid only for being entities.
+ *
+ * Makes the being looking at another being or a point.
+ */
+static int entity_look_at(lua_State *s)
+{
+ Entity *being = checkBeing(s, 1);
+
+ auto &ownPosition = being->getComponent<ActorComponent>()->getPosition();
+
+ Point otherPoint;
+ if (lua_gettop(s) > 2)
+ {
+ otherPoint.x = luaL_checkint(s, 2);
+ otherPoint.y = luaL_checkint(s, 3);
+ }
+ else
+ {
+ Entity *other = checkBeing(s, 2);
+ otherPoint = other->getComponent<ActorComponent>()->getPosition();
+ }
+
+ being->getComponent<BeingComponent>()->updateDirection(*being, ownPosition,
+ otherPoint);
+
+ return 0;
+}
+
/** LUA entity:heal (being)
* entity:heal([int value])
**
@@ -3384,6 +3416,7 @@ LuaScript::LuaScript():
{ "cooldown_ability", entity_cooldown_ability },
{ "walk", entity_walk },
{ "destination", entity_destination },
+ { "look_at", entity_look_at },
{ "heal", entity_heal },
{ "name", entity_get_name },
{ "type", entity_get_type },