Implement BG methods for TC and do other fixes

This commit is contained in:
Rochet2
2014-09-13 23:18:53 +03:00
parent 42ffd8aff8
commit 9add43bf2a
5 changed files with 146 additions and 128 deletions

View File

@@ -9,7 +9,6 @@
namespace LuaBattleGround namespace LuaBattleGround
{ {
#ifdef MANGOS // Currently only tested on Mangos. May need tweaking for TC
/** /**
* Returns the name of the [Battleground] * Returns the name of the [Battleground]
* *
@@ -216,6 +215,5 @@ namespace LuaBattleGround
Eluna::Push(L, bg->GetStatus()); Eluna::Push(L, bg->GetStatus());
return 1; return 1;
} }
#endif
}; };
#endif #endif

View File

@@ -7,7 +7,6 @@
// Required // Required
#include "AccountMgr.h" #include "AccountMgr.h"
#include "AuctionHouseMgr.h" #include "AuctionHouseMgr.h"
#include "BattleGround/BattleGroundMgr.h"
#include "Cell.h" #include "Cell.h"
#include "CellImpl.h" #include "CellImpl.h"
#include "Chat.h" #include "Chat.h"
@@ -42,10 +41,12 @@
#include "ScriptedCreature.h" #include "ScriptedCreature.h"
#include "SpellInfo.h" #include "SpellInfo.h"
#include "WeatherMgr.h" #include "WeatherMgr.h"
#include "Battleground.h"
#else #else
#include "Config/Config.h" #include "Config/Config.h"
#include "ReactorAI.h" #include "ReactorAI.h"
#include "revision_nr.h" #include "revision_nr.h"
#include "BattleGround/BattleGroundMgr.h"
#endif #endif
#if (!defined(TBC) && !defined(CLASSIC)) #if (!defined(TBC) && !defined(CLASSIC))
@@ -121,9 +122,3 @@ enum SelectAggroTarget
SELECT_TARGET_FARTHEST SELECT_TARGET_FARTHEST
}; };
#endif #endif
// Some dummy includes containing BOOST_VERSION:
// ObjectAccessor.h Config.h Log.h
#ifdef BOOST_VERSION
#define USING_BOOST
#endif

View File

@@ -14,147 +14,155 @@
#endif #endif
namespace LuaQuery namespace LuaQuery
{ {
/* BOOLEAN */ void CheckFields(lua_State* L, ElunaQuery* result)
int IsNull(lua_State* L, ElunaQuery* result) {
{ if (Eluna::CHECKVAL<uint32>(L, 2) >= RESULT->GetFieldCount())
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); luaL_argerror(L, 2, "invalid field index");
}
/* BOOLEAN */
int IsNull(lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(L, result);
#ifndef TRINITY #ifndef TRINITY
if (col < RESULT->GetFieldCount()) Eluna::Push(L, RESULT->Fetch()[col].IsNULL());
Eluna::Push(L, RESULT->Fetch()[col].IsNULL());
#else #else
if (col < RESULT->GetFieldCount()) Eluna::Push(L, RESULT->Fetch()[col].IsNull());
Eluna::Push(L, RESULT->Fetch()[col].IsNull());
#endif #endif
return 1; return 1;
} }
/* GETTERS */ /* GETTERS */
int GetColumnCount(lua_State* L, ElunaQuery* result) int GetColumnCount(lua_State* L, ElunaQuery* result)
{ {
Eluna::Push(L, RESULT->GetFieldCount()); Eluna::Push(L, RESULT->GetFieldCount());
return 1; return 1;
} }
int GetRowCount(lua_State* L, ElunaQuery* result) int GetRowCount(lua_State* L, ElunaQuery* result)
{ {
if (RESULT->GetRowCount() > (uint32)-1) if (RESULT->GetRowCount() > (uint32)-1)
Eluna::Push(L, (uint32)-1); Eluna::Push(L, (uint32)-1);
else else
Eluna::Push(L, RESULT->GetRowCount()); Eluna::Push(L, RESULT->GetRowCount());
return 1; return 1;
} }
int GetBool(lua_State* L, ElunaQuery* result) int GetBool(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetBool()); Eluna::Push(L, RESULT->Fetch()[col].GetBool());
return 1; return 1;
} }
int GetUInt8(lua_State* L, ElunaQuery* result) int GetUInt8(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt8()); Eluna::Push(L, RESULT->Fetch()[col].GetUInt8());
return 1; return 1;
} }
int GetUInt16(lua_State* L, ElunaQuery* result) int GetUInt16(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt16()); Eluna::Push(L, RESULT->Fetch()[col].GetUInt16());
return 1; return 1;
} }
int GetUInt32(lua_State* L, ElunaQuery* result) int GetUInt32(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt32()); Eluna::Push(L, RESULT->Fetch()[col].GetUInt32());
return 1; return 1;
} }
int GetUInt64(lua_State* L, ElunaQuery* result) int GetUInt64(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt64()); Eluna::Push(L, RESULT->Fetch()[col].GetUInt64());
return 1; return 1;
} }
int GetInt8(lua_State* L, ElunaQuery* result) int GetInt8(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt8()); Eluna::Push(L, RESULT->Fetch()[col].GetInt8());
return 1; return 1;
} }
int GetInt16(lua_State* L, ElunaQuery* result) int GetInt16(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt16()); Eluna::Push(L, RESULT->Fetch()[col].GetInt16());
return 1; return 1;
} }
int GetInt32(lua_State* L, ElunaQuery* result) int GetInt32(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt32()); Eluna::Push(L, RESULT->Fetch()[col].GetInt32());
return 1; return 1;
} }
int GetInt64(lua_State* L, ElunaQuery* result) int GetInt64(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt64()); Eluna::Push(L, RESULT->Fetch()[col].GetInt64());
return 1; return 1;
} }
int GetFloat(lua_State* L, ElunaQuery* result) int GetFloat(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetFloat()); Eluna::Push(L, RESULT->Fetch()[col].GetFloat());
return 1; return 1;
} }
int GetDouble(lua_State* L, ElunaQuery* result) int GetDouble(lua_State* L, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount()) CheckFields(L, result);
Eluna::Push(L, RESULT->Fetch()[col].GetDouble()); Eluna::Push(L, RESULT->Fetch()[col].GetDouble());
return 1; return 1;
} }
int GetString(lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(L, result);
int GetString(lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount())
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, RESULT->Fetch()[col].GetCppString()); Eluna::Push(L, RESULT->Fetch()[col].GetCppString());
#else #else
Eluna::Push(L, RESULT->Fetch()[col].GetString()); Eluna::Push(L, RESULT->Fetch()[col].GetString());
#endif #endif
return 1; return 1;
} }
int GetCString(lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
CheckFields(L, result);
int GetCString(lua_State* L, ElunaQuery* result)
{
uint32 col = Eluna::CHECKVAL<uint32>(L, 2);
if (col < RESULT->GetFieldCount())
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, RESULT->Fetch()[col].GetString()); Eluna::Push(L, RESULT->Fetch()[col].GetString());
#else #else
Eluna::Push(L, RESULT->Fetch()[col].GetCString()); Eluna::Push(L, RESULT->Fetch()[col].GetCString());
#endif #endif
return 1; return 1;
} }
/* OTHER */ /* OTHER */
@@ -182,7 +190,7 @@ namespace LuaQuery
{ {
lua_newtable(L); lua_newtable(L);
int tbl = lua_gettop(L); int tbl = lua_gettop(L);
uint32 col = RESULT->GetFieldCount(); uint32 col = RESULT->GetFieldCount();
Field* row = RESULT->Fetch(); Field* row = RESULT->Fetch();

View File

@@ -9,6 +9,8 @@
#include "Common.h" #include "Common.h"
#include "SharedDefines.h" #include "SharedDefines.h"
#include <unordered_map>
#include <unordered_set>
#ifdef TRINITY #ifdef TRINITY
#include "QueryResult.h" #include "QueryResult.h"
#ifdef CATA #ifdef CATA
@@ -19,6 +21,17 @@
#include "Database/QueryResult.h" #include "Database/QueryResult.h"
#endif #endif
// Some dummy includes containing BOOST_VERSION:
// ObjectAccessor.h Config.h Log.h
#ifdef BOOST_VERSION
#define USING_BOOST
#endif
#ifdef USING_BOOST
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>
#endif
#ifdef TRINITY #ifdef TRINITY
typedef QueryResult ElunaQuery; typedef QueryResult ElunaQuery;
#ifndef CATA #ifndef CATA

View File

@@ -27,6 +27,7 @@ extern "C"
#ifdef TRINITY #ifdef TRINITY
struct ItemTemplate; struct ItemTemplate;
typedef BattlegroundTypeId BattleGroundTypeId;
#else #else
struct ItemPrototype; struct ItemPrototype;
typedef ItemPrototype ItemTemplate; typedef ItemPrototype ItemTemplate;
@@ -38,7 +39,10 @@ typedef int Difficulty;
struct AreaTriggerEntry; struct AreaTriggerEntry;
class AuctionHouseObject; class AuctionHouseObject;
class BattleGround; #ifdef TRINITY
class Battleground;
typedef Battleground BattleGround;
#endif
class Channel; class Channel;
class Corpse; class Corpse;
class Creature; class Creature;