SHARE
TWEET

movement.cpp

a guest Apr 3rd, 2014 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////////////////////////////////////////////
  2. // OpenTibia - an opensource roleplaying game
  3. ////////////////////////////////////////////////////////////////////////
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ////////////////////////////////////////////////////////////////////////
  17.  
  18. #ifndef __MOVEMENT__
  19. #define __MOVEMENT__
  20.  
  21. #include "baseevents.h"
  22. #include "creature.h"
  23.  
  24. class MoveEvent;
  25. class MoveEventScript : public LuaInterface
  26. {
  27.         public:
  28.                 MoveEventScript() : LuaInterface("MoveEvents Interface") {}
  29.                 virtual ~MoveEventScript() {}
  30.  
  31.                 static MoveEvent* event;
  32.  
  33.         protected:
  34.                 virtual void registerFunctions();
  35.                 static int32_t luaCallFunction(lua_State* L);
  36. };
  37.  
  38. enum MoveEvent_t
  39. {
  40.         MOVE_EVENT_FIRST = 0,
  41.         MOVE_EVENT_STEP_IN = MOVE_EVENT_FIRST,
  42.         MOVE_EVENT_STEP_OUT = 1,
  43.         MOVE_EVENT_EQUIP = 2,
  44.         MOVE_EVENT_DE_EQUIP = 3,
  45.         MOVE_EVENT_ADD_ITEM = 4,
  46.         MOVE_EVENT_REMOVE_ITEM = 5,
  47.         MOVE_EVENT_ADD_TILEITEM = 6,
  48.         MOVE_EVENT_REMOVE_TILEITEM = 7,
  49.         MOVE_EVENT_NONE = 8,
  50.         MOVE_EVENT_LAST = MOVE_EVENT_REMOVE_TILEITEM
  51. };
  52.  
  53. typedef std::list<MoveEvent*> EventList;
  54. class MoveEvents : public BaseEvents
  55. {
  56.         public:
  57.                 MoveEvents();
  58.                 virtual ~MoveEvents() {clear();}
  59.  
  60.                 uint32_t onCreatureMove(Creature* actor, Creature* creature, const Tile* fromTile, const Tile* toTile, bool isStepping);
  61.                 bool onPlayerEquip(Player* player, Item* item, slots_t slot, bool isCheck);
  62.                 bool onPlayerDeEquip(Player* player, Item* item, slots_t slot, bool isRemoval);
  63.                 uint32_t onItemMove(Creature* actor, Item* item, Tile* tile, bool isAdd);
  64.  
  65.                 MoveEvent* getEvent(Item* item, MoveEvent_t eventType);
  66.                 bool hasEquipEvent(Item* item);
  67.                 bool hasTileEvent(Item* item);
  68.  
  69.                 void onRemoveTileItem(const Tile* tile, Item* item);
  70.                 void onAddTileItem(const Tile* tile, Item* item);
  71.  
  72.         protected:
  73.                 struct MoveEventList
  74.                 {
  75.                         EventList moveEvent[MOVE_EVENT_NONE];
  76.                 };
  77.  
  78.                 virtual std::string getScriptBaseName() const {return "movements";}
  79.                 virtual void clear();
  80.  
  81.                 virtual Event* getEvent(const std::string& nodeName);
  82.                 virtual bool registerEvent(Event* event, xmlNodePtr p, bool override);
  83.  
  84.                 virtual LuaInterface& getInterface() {return m_interface;}
  85.                 MoveEventScript m_interface;
  86.  
  87.                 void registerItemID(int32_t itemId, MoveEvent_t eventType);
  88.                 void registerActionID(int32_t actionId, MoveEvent_t eventType);
  89.                 void registerUniqueID(int32_t uniqueId, MoveEvent_t eventType);
  90.  
  91.                 typedef std::map<int32_t, MoveEventList> MoveListMap;
  92.                 MoveListMap m_itemIdMap;
  93.                 MoveListMap m_uniqueIdMap;
  94.                 MoveListMap m_actionIdMap;
  95.  
  96.                 typedef std::map<Position, MoveEventList> MovePosListMap;
  97.                 MovePosListMap m_positionMap;
  98.                 void clearMap(MoveListMap& map);
  99.  
  100.                 void addEvent(MoveEvent* moveEvent, int32_t id, MoveListMap& map, bool override);
  101.                 MoveEvent* getEvent(Item* item, MoveEvent_t eventType, slots_t slot);
  102.  
  103.                 void addEvent(MoveEvent* moveEvent, Position pos, MovePosListMap& map, bool override);
  104.                 MoveEvent* getEvent(const Tile* tile, MoveEvent_t eventType);
  105.  
  106.                 const Tile* m_lastCacheTile;
  107.                 std::vector<Item*> m_lastCacheItemVector;
  108. };
  109.  
  110. typedef uint32_t (MoveFunction)(Item* item);
  111. typedef uint32_t (StepFunction)(Creature* creature, Item* item);
  112. typedef bool (EquipFunction)(MoveEvent* moveEvent, Player* player, Item* item, slots_t slot, bool boolean);
  113.  
  114. class MoveEvent : public Event
  115. {
  116.         public:
  117.                 MoveEvent(LuaInterface* _interface);
  118.                 MoveEvent(const MoveEvent* copy);
  119.                 virtual ~MoveEvent() {}
  120.  
  121.                 MoveEvent_t getEventType() const;
  122.                 void setEventType(MoveEvent_t type);
  123.  
  124.                 virtual bool configureEvent(xmlNodePtr p);
  125.                 virtual bool loadFunction(const std::string& functionName);
  126.  
  127.                 uint32_t fireStepEvent(Creature* actor, Creature* creature, Item* item, const Position& pos, const Position& fromPos, const Position& toPos);
  128.                 uint32_t fireAddRemItem(Creature* actor, Item* item, Item* tileItem, const Position& pos);
  129.                 bool fireEquip(Player* player, Item* item, slots_t slot, bool boolean);
  130.  
  131.                 uint32_t executeStep(Creature* actor, Creature* creature, Item* item, const Position& pos, const Position& fromPos, const Position& toPos);
  132.                 bool executeEquip(Player* player, Item* item, slots_t slot, bool boolean);
  133.                 uint32_t executeAddRemItem(Creature* actor, Item* item, Item* tileItem, const Position& pos);
  134.  
  135.                 static StepFunction StepInField;
  136.                 static MoveFunction AddItemField;
  137.                 static EquipFunction EquipItem;
  138.                 static EquipFunction DeEquipItem;
  139.  
  140.                 uint32_t getWieldInfo() const {return wieldInfo;}
  141.                 uint32_t getSlot() const {return slot;}
  142.                 int32_t getReqLevel() const {return reqLevel;}
  143.                 int32_t getReqMagLv() const {return reqMagLevel;}
  144.                 bool isPremium() const {return premium;}
  145.  
  146.                 const VocationMap& getVocEquipMap() const {return vocEquipMap;}
  147.                 const std::string& getVocationString() const {return vocationString;}
  148.  
  149.         protected:
  150.                 MoveEvent_t m_eventType;
  151.  
  152.                 virtual std::string getScriptEventName() const;
  153.                 virtual std::string getScriptEventParams() const;
  154.  
  155.                 MoveFunction* moveFunction;
  156.                 StepFunction* stepFunction;
  157.                 EquipFunction* equipFunction;
  158.  
  159.                 uint32_t wieldInfo, slot;
  160.                 int32_t reqLevel, reqMagLevel;
  161.                 bool premium;
  162.  
  163.                 VocationMap vocEquipMap;
  164.                 std::string vocationString;
  165. };
  166. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top