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;
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));

View File

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

View File

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

View File

@ -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<NativeType*>(d_);
operator Client*() {
void *d = GetLuaPtrData();
if(d) {
return reinterpret_cast<Client*>(d);
}
return nullptr;

View File

@ -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<Client*>(d_);
void *d = GetLuaPtrData();
Client *m = reinterpret_cast<Client*>(d);
return Lua_Client(m);
}
Lua_NPC Lua_Entity::CastToNPC() {
NPC *m = reinterpret_cast<NPC*>(d_);
void *d = GetLuaPtrData();
NPC *m = reinterpret_cast<NPC*>(d);
return Lua_NPC(m);
}
Lua_Mob Lua_Entity::CastToMob() {
Mob *m = reinterpret_cast<Mob*>(d_);
void *d = GetLuaPtrData();
Mob *m = reinterpret_cast<Mob*>(d);
return Lua_Mob(m);
}

View File

@ -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<NativeType*>(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;
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<NativeType*>(d_);
operator Entity*() {
void *d = GetLuaPtrData();
if(d) {
return reinterpret_cast<Entity*>(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

View File

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

View File

@ -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<ItemInst*>(d_);
operator ItemInst*() {
void *d = GetLuaPtrData();
if(d) {
return reinterpret_cast<ItemInst*>(d);
}
return nullptr;
}
bool Null();
bool Valid();
void *d_;
};
#endif

View File

@ -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<NativeType*>(d_);
operator Mob*() {
void *d = GetLuaPtrData();
if(d) {
return reinterpret_cast<Mob*>(d);
}
return nullptr;

View File

@ -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<NativeType*>(d_);
operator NPC*() {
void *d = GetLuaPtrData();
if(d) {
return reinterpret_cast<NPC*>(d);
}
return nullptr;

View File

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