diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-03 14:32:57 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-03 21:52:03 +0200 |
commit | 4b57962ee4c10e48956c2888199605bebdb17b8f (patch) | |
tree | 261b141a1ad61a64e93a7b99a8c68debfb48d055 /src/scripting | |
parent | 4a8080dcf73dab2b6e62b8500fec3bb996bcbf17 (diff) | |
download | manaserv-4b57962ee4c10e48956c2888199605bebdb17b8f.tar.gz manaserv-4b57962ee4c10e48956c2888199605bebdb17b8f.tar.bz2 manaserv-4b57962ee4c10e48956c2888199605bebdb17b8f.tar.xz manaserv-4b57962ee4c10e48956c2888199605bebdb17b8f.zip |
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
Diffstat (limited to 'src/scripting')
-rw-r--r-- | src/scripting/lua.cpp | 33 | ||||
-rw-r--r-- | src/scripting/luautil.cpp | 8 | ||||
-rw-r--r-- | src/scripting/luautil.h | 5 |
3 files changed, 25 insertions, 21 deletions
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<MonsterComponent>(); + 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<MonsterComponent>()->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<MonsterComponent>()->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<MonsterComponent>(); + pushSTLContainer(s, monsterComponent->getAngerList()); return 1; } diff --git a/src/scripting/luautil.cpp b/src/scripting/luautil.cpp index 24e9edf7..d082cbe7 100644 --- a/src/scripting/luautil.cpp +++ b/src/scripting/luautil.cpp @@ -158,14 +158,14 @@ ItemClass *getItemClass(lua_State *s, int p) return itemClass; } -Monster *getMonster(lua_State *s, int p) +Being *getMonster(lua_State *s, int p) { if (!lua_islightuserdata(s, p)) return 0; Entity *t = static_cast<Entity *>(lua_touserdata(s, p)); if (t->getType() != OBJECT_MONSTER) return 0; - return static_cast<Monster *>(t); + return static_cast<Being*>(t); } MonsterClass *getMonsterClass(lua_State *s, int p) @@ -220,9 +220,9 @@ ItemClass *checkItemClass(lua_State *s, int p) return itemClass; } -Monster *checkMonster(lua_State *s, int p) +Being *checkMonster(lua_State *s, int p) { - Monster *monster = getMonster(s, p); + Being *monster = getMonster(s, p); luaL_argcheck(s, monster, p, "monster expected"); return monster; } diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h index dd63c0f7..e76a15a1 100644 --- a/src/scripting/luautil.h +++ b/src/scripting/luautil.h @@ -43,7 +43,6 @@ class Entity; class ItemClass; class MapComposite; class MapObject; -class Monster; class MonsterClass; class StatusEffect; @@ -169,14 +168,14 @@ Script * getScript(lua_State *s); Being * getBeing(lua_State *s, int p); Character * getCharacter(lua_State *s, int p); ItemClass * getItemClass(lua_State *s, int p); -Monster * getMonster(lua_State *s, int p); +Being * getMonster(lua_State *s, int p); MonsterClass * getMonsterClass(lua_State *s, int p); Being * getNpc(lua_State *s, int p); Being * checkBeing(lua_State *s, int p); Character * checkCharacter(lua_State *s, int p); ItemClass * checkItemClass(lua_State *s, int p); -Monster * checkMonster(lua_State *s, int p); +Being * checkMonster(lua_State *s, int p); MonsterClass * checkMonsterClass(lua_State *s, int p); Being * checkNpc(lua_State *s, int p); int checkSkill(lua_State *s, int p); |