From 3ddc61420b28dcaf56c6f1f0664731d1dd070395 Mon Sep 17 00:00:00 2001 From: KimLS Date: Thu, 16 May 2013 23:24:47 -0700 Subject: [PATCH] Added id to spells so i can export them to lua correctly. Also made the lua_classes less messy by having them all derive from Lua_Ptr instead of reimplementing functionality --- common/shareddb.cpp | 1 + common/spdat.h | 2 +- zone/CMakeLists.txt | 3 +++ zone/lua_client.h | 11 ++++++----- zone/lua_entity.cpp | 17 ++++++----------- zone/lua_entity.h | 19 +++++++++---------- zone/lua_item.cpp | 8 -------- zone/lua_item.h | 21 ++++++++++----------- zone/lua_mob.h | 11 ++++++----- zone/lua_npc.h | 11 ++++++----- zone/lua_parser.cpp | 1 + zone/lua_ptr.h | 38 ++++++++++++++++++++++++++++++++++++++ zone/lua_spell.cpp | 6 ++++++ zone/lua_spell.h | 28 ++++++++++++++++++++++++++++ 14 files changed, 121 insertions(+), 56 deletions(-) create mode 100644 zone/lua_ptr.h create mode 100644 zone/lua_spell.cpp create mode 100644 zone/lua_spell.h diff --git a/common/shareddb.cpp b/common/shareddb.cpp index 87420550c..d8596bf22 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -1636,6 +1636,7 @@ void SharedDatabase::LoadSpells(void *data, int max_spells) { } ++counter; + sp[tempid].id = tempid; strn0cpy(sp[tempid].name, row[1], sizeof(sp[tempid].name)); strn0cpy(sp[tempid].player_1, row[2], sizeof(sp[tempid].player_1)); strn0cpy(sp[tempid].teleport_zone, row[3], sizeof(sp[tempid].teleport_zone)); diff --git a/common/spdat.h b/common/spdat.h index 7e3cd71a4..4b02ad7e2 100644 --- a/common/spdat.h +++ b/common/spdat.h @@ -603,7 +603,7 @@ typedef enum { // struct SPDat_Spell_Struct { -/* 000 */ //int id; // not used +/* 000 */ int id; // not used /* 001 */ char name[64]; // Name of the spell /* 002 */ char player_1[32]; // "PLAYER_1" /* 003 */ char teleport_zone[64]; // Teleport zone, pet name summoned, or item summoned diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 673ed99a4..40d3b88ac 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -38,6 +38,7 @@ SET(zone_sources lua_npc.cpp lua_parser.cpp lua_parser_events.cpp + lua_spell.cpp embperl.cpp embxs.cpp entity.cpp @@ -136,6 +137,8 @@ SET(zone_headers lua_npc.h lua_parser.h lua_parser_events.h + lua_ptr.h + lua_spell.h map.h masterentity.h maxskill.h diff --git a/zone/lua_client.h b/zone/lua_client.h index 406401efe..1ca7597d3 100644 --- a/zone/lua_client.h +++ b/zone/lua_client.h @@ -10,13 +10,14 @@ class Lua_Client : public Lua_Mob { typedef Client NativeType; public: - Lua_Client() { d_ = nullptr; } - Lua_Client(NativeType *d) { d_ = d; } + Lua_Client() { } + Lua_Client(Client *d) { SetLuaPtrData(d); } virtual ~Lua_Client() { } - operator NativeType* () { - if(d_) { - return reinterpret_cast(d_); + operator Client*() { + void *d = GetLuaPtrData(); + if(d) { + return reinterpret_cast(d); } return nullptr; diff --git a/zone/lua_entity.cpp b/zone/lua_entity.cpp index 423da06d6..39c42de5d 100644 --- a/zone/lua_entity.cpp +++ b/zone/lua_entity.cpp @@ -6,14 +6,6 @@ #include "lua_client.h" #include "lua_npc.h" -bool Lua_Entity::Null() { - return d_ == nullptr; -} - -bool Lua_Entity::Valid() { - return d_ != nullptr; -} - bool Lua_Entity::IsClient() { Lua_Safe_Call_Bool(); return self->IsClient(); @@ -75,17 +67,20 @@ int Lua_Entity::GetID() { } Lua_Client Lua_Entity::CastToClient() { - Client *m = reinterpret_cast(d_); + void *d = GetLuaPtrData(); + Client *m = reinterpret_cast(d); return Lua_Client(m); } Lua_NPC Lua_Entity::CastToNPC() { - NPC *m = reinterpret_cast(d_); + void *d = GetLuaPtrData(); + NPC *m = reinterpret_cast(d); return Lua_NPC(m); } Lua_Mob Lua_Entity::CastToMob() { - Mob *m = reinterpret_cast(d_); + void *d = GetLuaPtrData(); + Mob *m = reinterpret_cast(d); return Lua_Mob(m); } diff --git a/zone/lua_entity.h b/zone/lua_entity.h index ab8612779..afddc9798 100644 --- a/zone/lua_entity.h +++ b/zone/lua_entity.h @@ -2,6 +2,8 @@ #define EQEMU_LUA_ENTITY_H #ifdef LUA_EQEMU +#include "lua_ptr.h" + class Entity; class Lua_Client; class Lua_NPC; @@ -24,24 +26,23 @@ class Lua_Mob; #define Lua_Safe_Call_NPC() if(!d_) { return Lua_NPC(); } NativeType *self = reinterpret_cast(d_) #define Lua_Safe_Call_Client() if(!d_) { return Lua_Client(); } NativeType *self = reinterpret_cast(d_) -class Lua_Entity +class Lua_Entity : public Lua_Ptr { typedef Entity NativeType; public: - Lua_Entity() { d_ = nullptr; } - Lua_Entity(NativeType *d) : d_(d) { } + Lua_Entity() { } + Lua_Entity(Entity *d) : Lua_Ptr(d) { } virtual ~Lua_Entity() { } - operator NativeType* () { - if(d_) { - return reinterpret_cast(d_); + operator Entity*() { + void *d = GetLuaPtrData(); + if(d) { + return reinterpret_cast(d); } return nullptr; } - bool Null(); - bool Valid(); bool IsClient(); bool IsNPC(); bool IsMob(); @@ -64,8 +65,6 @@ public: //Lua_Doors CastToDoors(); //Lua_Trap CastToTrap(); //Lua_Beacon CastToBeacon(); - - void *d_; }; #endif diff --git a/zone/lua_item.cpp b/zone/lua_item.cpp index 228d211a8..cb0cbac7f 100644 --- a/zone/lua_item.cpp +++ b/zone/lua_item.cpp @@ -3,12 +3,4 @@ #include "masterentity.h" #include "lua_item.h" -bool Lua_Item::Null() { - return d_ == nullptr; -} - -bool Lua_Item::Valid() { - return d_ != nullptr; -} - #endif diff --git a/zone/lua_item.h b/zone/lua_item.h index d4b385a5a..d56bf4a04 100644 --- a/zone/lua_item.h +++ b/zone/lua_item.h @@ -2,27 +2,26 @@ #define EQEMU_LUA_ITEM_H #ifdef LUA_EQEMU +#include "lua_ptr.h" + class ItemInst; -class Lua_Item +class Lua_Item : public Lua_Ptr { + typedef ItemInst NativeType; public: - Lua_Item() { d_ = nullptr; } - Lua_Item(ItemInst *d) { d_ = d; } + Lua_Item() { } + Lua_Item(ItemInst *d) : Lua_Ptr(d) { } virtual ~Lua_Item() { } - operator ItemInst* () { - if(d_) { - return reinterpret_cast(d_); + operator ItemInst*() { + void *d = GetLuaPtrData(); + if(d) { + return reinterpret_cast(d); } return nullptr; } - - bool Null(); - bool Valid(); - - void *d_; }; #endif diff --git a/zone/lua_mob.h b/zone/lua_mob.h index 9752620a3..f12d66c3a 100644 --- a/zone/lua_mob.h +++ b/zone/lua_mob.h @@ -10,13 +10,14 @@ class Lua_Mob : public Lua_Entity { typedef Mob NativeType; public: - Lua_Mob() { d_ = nullptr; } - Lua_Mob(NativeType *d) { d_ = d; } + Lua_Mob() { } + Lua_Mob(Mob *d) { SetLuaPtrData(d); } virtual ~Lua_Mob() { } - operator NativeType* () { - if(d_) { - return reinterpret_cast(d_); + operator Mob*() { + void *d = GetLuaPtrData(); + if(d) { + return reinterpret_cast(d); } return nullptr; diff --git a/zone/lua_npc.h b/zone/lua_npc.h index e4ae7200d..9faa1bcea 100644 --- a/zone/lua_npc.h +++ b/zone/lua_npc.h @@ -10,13 +10,14 @@ class Lua_NPC : public Lua_Mob { typedef NPC NativeType; public: - Lua_NPC() { d_ = nullptr; } - Lua_NPC(NativeType *d) { d_ = d; } + Lua_NPC() { } + Lua_NPC(NPC *d) { SetLuaPtrData(d); } virtual ~Lua_NPC() { } - operator NativeType* () { - if(d_) { - return reinterpret_cast(d_); + operator NPC*() { + void *d = GetLuaPtrData(); + if(d) { + return reinterpret_cast(d); } return nullptr; diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 602287e56..83456929e 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -5,6 +5,7 @@ #include #include "masterentity.h" +#include "../common/spdat.h" #include "../common/seperator.h" #include "lua_entity.h" #include "lua_mob.h" diff --git a/zone/lua_ptr.h b/zone/lua_ptr.h new file mode 100644 index 000000000..7b8fc261d --- /dev/null +++ b/zone/lua_ptr.h @@ -0,0 +1,38 @@ +#ifndef EQEMU_LUA_PTR_H +#define EQEMU_LUA_PTR_H +#ifdef LUA_EQEMU + +class Lua_Ptr +{ +public: + Lua_Ptr() { + } + + Lua_Ptr(void *d) : d_(d) { + } + + ~Lua_Ptr() { + } + + void *GetLuaPtrData() { + return d_; + } + + void SetLuaPtrData(void *d) { + d_ = d; + } + + bool Null() { + return d_ == nullptr; + } + + bool Valid() { + return d_ != nullptr; + } + +protected: + void *d_; +}; + +#endif +#endif \ No newline at end of file diff --git a/zone/lua_spell.cpp b/zone/lua_spell.cpp new file mode 100644 index 000000000..a9a8db279 --- /dev/null +++ b/zone/lua_spell.cpp @@ -0,0 +1,6 @@ +#ifdef LUA_EQEMU + +#include "../common/spdat.h" +#include "lua_spell.h" + +#endif diff --git a/zone/lua_spell.h b/zone/lua_spell.h new file mode 100644 index 000000000..131b6f21f --- /dev/null +++ b/zone/lua_spell.h @@ -0,0 +1,28 @@ +#ifndef EQEMU_LUA_ITEM_H +#define EQEMU_LUA_ITEM_H +#ifdef LUA_EQEMU + +#include "lua_ptr.h" + +struct SPDat_Spell_Struct; + +class Lua_Spell : public Lua_Ptr +{ + typedef SPDat_Spell_Struct NativeType; +public: + Lua_Spell() { } + Lua_Spell(SPDat_Spell_Struct *d) : Lua_Ptr(d) { } + virtual ~Lua_Spell() { } + + operator SPDat_Spell_Struct*() { + void *d = GetLuaPtrData(); + if(d) { + return reinterpret_cast(d); + } + + return nullptr; + } +}; + +#endif +#endif