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

This commit is contained in:
KimLS 2013-05-16 23:24:47 -07:00
parent b10de6f4e7
commit 3ddc61420b
14 changed files with 121 additions and 56 deletions

View File

@ -1636,6 +1636,7 @@ void SharedDatabase::LoadSpells(void *data, int max_spells) {
} }
++counter; ++counter;
sp[tempid].id = tempid;
strn0cpy(sp[tempid].name, row[1], sizeof(sp[tempid].name)); 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].player_1, row[2], sizeof(sp[tempid].player_1));
strn0cpy(sp[tempid].teleport_zone, row[3], sizeof(sp[tempid].teleport_zone)); strn0cpy(sp[tempid].teleport_zone, row[3], sizeof(sp[tempid].teleport_zone));

View File

@ -603,7 +603,7 @@ typedef enum {
// //
struct SPDat_Spell_Struct struct SPDat_Spell_Struct
{ {
/* 000 */ //int id; // not used /* 000 */ int id; // not used
/* 001 */ char name[64]; // Name of the spell /* 001 */ char name[64]; // Name of the spell
/* 002 */ char player_1[32]; // "PLAYER_1" /* 002 */ char player_1[32]; // "PLAYER_1"
/* 003 */ char teleport_zone[64]; // Teleport zone, pet name summoned, or item summoned /* 003 */ char teleport_zone[64]; // Teleport zone, pet name summoned, or item summoned

View File

@ -38,6 +38,7 @@ SET(zone_sources
lua_npc.cpp lua_npc.cpp
lua_parser.cpp lua_parser.cpp
lua_parser_events.cpp lua_parser_events.cpp
lua_spell.cpp
embperl.cpp embperl.cpp
embxs.cpp embxs.cpp
entity.cpp entity.cpp
@ -136,6 +137,8 @@ SET(zone_headers
lua_npc.h lua_npc.h
lua_parser.h lua_parser.h
lua_parser_events.h lua_parser_events.h
lua_ptr.h
lua_spell.h
map.h map.h
masterentity.h masterentity.h
maxskill.h maxskill.h

View File

@ -10,13 +10,14 @@ class Lua_Client : public Lua_Mob
{ {
typedef Client NativeType; typedef Client NativeType;
public: public:
Lua_Client() { d_ = nullptr; } Lua_Client() { }
Lua_Client(NativeType *d) { d_ = d; } Lua_Client(Client *d) { SetLuaPtrData(d); }
virtual ~Lua_Client() { } virtual ~Lua_Client() { }
operator NativeType* () { operator Client*() {
if(d_) { void *d = GetLuaPtrData();
return reinterpret_cast<NativeType*>(d_); if(d) {
return reinterpret_cast<Client*>(d);
} }
return nullptr; return nullptr;

View File

@ -6,14 +6,6 @@
#include "lua_client.h" #include "lua_client.h"
#include "lua_npc.h" #include "lua_npc.h"
bool Lua_Entity::Null() {
return d_ == nullptr;
}
bool Lua_Entity::Valid() {
return d_ != nullptr;
}
bool Lua_Entity::IsClient() { bool Lua_Entity::IsClient() {
Lua_Safe_Call_Bool(); Lua_Safe_Call_Bool();
return self->IsClient(); return self->IsClient();
@ -75,17 +67,20 @@ int Lua_Entity::GetID() {
} }
Lua_Client Lua_Entity::CastToClient() { Lua_Client Lua_Entity::CastToClient() {
Client *m = reinterpret_cast<Client*>(d_); void *d = GetLuaPtrData();
Client *m = reinterpret_cast<Client*>(d);
return Lua_Client(m); return Lua_Client(m);
} }
Lua_NPC Lua_Entity::CastToNPC() { Lua_NPC Lua_Entity::CastToNPC() {
NPC *m = reinterpret_cast<NPC*>(d_); void *d = GetLuaPtrData();
NPC *m = reinterpret_cast<NPC*>(d);
return Lua_NPC(m); return Lua_NPC(m);
} }
Lua_Mob Lua_Entity::CastToMob() { Lua_Mob Lua_Entity::CastToMob() {
Mob *m = reinterpret_cast<Mob*>(d_); void *d = GetLuaPtrData();
Mob *m = reinterpret_cast<Mob*>(d);
return Lua_Mob(m); return Lua_Mob(m);
} }

View File

@ -2,6 +2,8 @@
#define EQEMU_LUA_ENTITY_H #define EQEMU_LUA_ENTITY_H
#ifdef LUA_EQEMU #ifdef LUA_EQEMU
#include "lua_ptr.h"
class Entity; class Entity;
class Lua_Client; class Lua_Client;
class Lua_NPC; class Lua_NPC;
@ -24,24 +26,23 @@ class Lua_Mob;
#define Lua_Safe_Call_NPC() if(!d_) { return Lua_NPC(); } NativeType *self = reinterpret_cast<NativeType*>(d_) #define Lua_Safe_Call_NPC() if(!d_) { return Lua_NPC(); } NativeType *self = reinterpret_cast<NativeType*>(d_)
#define Lua_Safe_Call_Client() if(!d_) { return Lua_Client(); } NativeType *self = reinterpret_cast<Type*>(d_) #define Lua_Safe_Call_Client() if(!d_) { return Lua_Client(); } NativeType *self = reinterpret_cast<Type*>(d_)
class Lua_Entity class Lua_Entity : public Lua_Ptr
{ {
typedef Entity NativeType; typedef Entity NativeType;
public: public:
Lua_Entity() { d_ = nullptr; } Lua_Entity() { }
Lua_Entity(NativeType *d) : d_(d) { } Lua_Entity(Entity *d) : Lua_Ptr(d) { }
virtual ~Lua_Entity() { } virtual ~Lua_Entity() { }
operator NativeType* () { operator Entity*() {
if(d_) { void *d = GetLuaPtrData();
return reinterpret_cast<NativeType*>(d_); if(d) {
return reinterpret_cast<Entity*>(d);
} }
return nullptr; return nullptr;
} }
bool Null();
bool Valid();
bool IsClient(); bool IsClient();
bool IsNPC(); bool IsNPC();
bool IsMob(); bool IsMob();
@ -64,8 +65,6 @@ public:
//Lua_Doors CastToDoors(); //Lua_Doors CastToDoors();
//Lua_Trap CastToTrap(); //Lua_Trap CastToTrap();
//Lua_Beacon CastToBeacon(); //Lua_Beacon CastToBeacon();
void *d_;
}; };
#endif #endif

View File

@ -3,12 +3,4 @@
#include "masterentity.h" #include "masterentity.h"
#include "lua_item.h" #include "lua_item.h"
bool Lua_Item::Null() {
return d_ == nullptr;
}
bool Lua_Item::Valid() {
return d_ != nullptr;
}
#endif #endif

View File

@ -2,27 +2,26 @@
#define EQEMU_LUA_ITEM_H #define EQEMU_LUA_ITEM_H
#ifdef LUA_EQEMU #ifdef LUA_EQEMU
#include "lua_ptr.h"
class ItemInst; class ItemInst;
class Lua_Item class Lua_Item : public Lua_Ptr
{ {
typedef ItemInst NativeType;
public: public:
Lua_Item() { d_ = nullptr; } Lua_Item() { }
Lua_Item(ItemInst *d) { d_ = d; } Lua_Item(ItemInst *d) : Lua_Ptr(d) { }
virtual ~Lua_Item() { } virtual ~Lua_Item() { }
operator ItemInst* () { operator ItemInst*() {
if(d_) { void *d = GetLuaPtrData();
return reinterpret_cast<ItemInst*>(d_); if(d) {
return reinterpret_cast<ItemInst*>(d);
} }
return nullptr; return nullptr;
} }
bool Null();
bool Valid();
void *d_;
}; };
#endif #endif

View File

@ -10,13 +10,14 @@ class Lua_Mob : public Lua_Entity
{ {
typedef Mob NativeType; typedef Mob NativeType;
public: public:
Lua_Mob() { d_ = nullptr; } Lua_Mob() { }
Lua_Mob(NativeType *d) { d_ = d; } Lua_Mob(Mob *d) { SetLuaPtrData(d); }
virtual ~Lua_Mob() { } virtual ~Lua_Mob() { }
operator NativeType* () { operator Mob*() {
if(d_) { void *d = GetLuaPtrData();
return reinterpret_cast<NativeType*>(d_); if(d) {
return reinterpret_cast<Mob*>(d);
} }
return nullptr; return nullptr;

View File

@ -10,13 +10,14 @@ class Lua_NPC : public Lua_Mob
{ {
typedef NPC NativeType; typedef NPC NativeType;
public: public:
Lua_NPC() { d_ = nullptr; } Lua_NPC() { }
Lua_NPC(NativeType *d) { d_ = d; } Lua_NPC(NPC *d) { SetLuaPtrData(d); }
virtual ~Lua_NPC() { } virtual ~Lua_NPC() { }
operator NativeType* () { operator NPC*() {
if(d_) { void *d = GetLuaPtrData();
return reinterpret_cast<NativeType*>(d_); if(d) {
return reinterpret_cast<NPC*>(d);
} }
return nullptr; return nullptr;

View File

@ -5,6 +5,7 @@
#include <boost/any.hpp> #include <boost/any.hpp>
#include "masterentity.h" #include "masterentity.h"
#include "../common/spdat.h"
#include "../common/seperator.h" #include "../common/seperator.h"
#include "lua_entity.h" #include "lua_entity.h"
#include "lua_mob.h" #include "lua_mob.h"

38
zone/lua_ptr.h Normal file
View File

@ -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

6
zone/lua_spell.cpp Normal file
View File

@ -0,0 +1,6 @@
#ifdef LUA_EQEMU
#include "../common/spdat.h"
#include "lua_spell.h"
#endif

28
zone/lua_spell.h Normal file
View File

@ -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<SPDat_Spell_Struct*>(d);
}
return nullptr;
}
};
#endif
#endif