From 4b57962ee4c10e48956c2888199605bebdb17b8f Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Wed, 3 Apr 2013 14:32:57 +0200 Subject: Moved the Monster class to a Component Things done: - Allowed to create new Attributes outside of the protected scope of Being - Moved Monster to MonsterComponent - Some minor cleanup in the Attribute setting code of monsters --- src/scripting/lua.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index a02f84e4..993508a2 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -355,12 +355,13 @@ static int monster_create(lua_State *s) const int y = luaL_checkint(s, 3); MapComposite *m = checkCurrentMap(s); - Monster *q = new Monster(monsterClass); - q->setMap(m); - q->setPosition(Point(x, y)); - GameState::enqueueInsert(q); + Being *monster = new Being(OBJECT_MONSTER); + monster->addComponent(new MonsterComponent(*monster, monsterClass)); + monster->setMap(m); + monster->setPosition(Point(x, y)); + GameState::enqueueInsert(monster); - lua_pushlightuserdata(s, q); + lua_pushlightuserdata(s, monster); return 1; } @@ -374,7 +375,7 @@ static int monster_create(lua_State *s) static int monster_remove(lua_State *s) { bool monsterRemoved = false; - if (Monster *m = getMonster(s, 1)) + if (Being *m = getMonster(s, 1)) { GameState::remove(m); monsterRemoved = true; @@ -2245,8 +2246,10 @@ static int chr_take_special(lua_State *s) */ static int monster_get_id(lua_State *s) { - Monster *monster = checkMonster(s, 1); - lua_pushinteger(s, monster->getSpecy()->getId()); + Being *monster = checkMonster(s, 1); + MonsterComponent *monsterComponent = + monster->getComponent(); + lua_pushinteger(s, monsterComponent->getSpecy()->getId()); return 1; } @@ -2258,10 +2261,10 @@ static int monster_get_id(lua_State *s) */ static int monster_change_anger(lua_State *s) { - Monster *monster = checkMonster(s, 1); + Being *monster = checkMonster(s, 1); Being *being = checkBeing(s, 2); const int anger = luaL_checkint(s, 3); - monster->changeAnger(being, anger); + monster->getComponent()->changeAnger(being, anger); return 0; } @@ -2272,9 +2275,9 @@ static int monster_change_anger(lua_State *s) */ static int monster_drop_anger(lua_State *s) { - Monster *monster = checkMonster(s, 1); + Being *monster = checkMonster(s, 1); Being *being = checkBeing(s, 2); - monster->forgetTarget(being); + monster->getComponent()->forgetTarget(being); return 0; } @@ -2286,8 +2289,10 @@ static int monster_drop_anger(lua_State *s) */ static int monster_get_angerlist(lua_State *s) { - Monster *monster = checkMonster(s, 1); - pushSTLContainer(s, monster->getAngerList()); + Being *monster = checkMonster(s, 1); + MonsterComponent *monsterComponent = + monster->getComponent(); + pushSTLContainer(s, monsterComponent->getAngerList()); return 1; } -- cgit v1.2.3-70-g09d2