Merge pull request #23 from addtheice/master

Fixed missing include that blocked compile on linux.
This commit is contained in:
Alex 2013-03-05 23:05:27 -08:00
commit f7469412f1
11 changed files with 1223 additions and 1222 deletions

View File

@ -11,24 +11,24 @@ class EmuTCPServer : public TCPServer<EmuTCPConnection> {
public: public:
EmuTCPServer(uint16 iPort = 0, bool iOldFormat = false); EmuTCPServer(uint16 iPort = 0, bool iOldFormat = false);
virtual ~EmuTCPServer(); virtual ~EmuTCPServer();
//packet broadcast routines. //packet broadcast routines.
void SendPacket(ServerPacket* pack); void SendPacket(ServerPacket* pack);
void SendPacket(EmuTCPNetPacket_Struct** tnps); void SendPacket(EmuTCPNetPacket_Struct** tnps);
//special crap for relay management //special crap for relay management
EmuTCPConnection *FindConnection(uint32 iID); EmuTCPConnection *FindConnection(uint32 iID);
//exposed for some crap we pull. Do not call from outside this object. //exposed for some crap we pull. Do not call from outside this object.
TCPServer<EmuTCPConnection>::AddConnection; using TCPServer<EmuTCPConnection>::AddConnection;
protected: protected:
virtual void Process(); virtual void Process();
virtual void CreateNewConnection(uint32 ID, SOCKET in_socket, uint32 irIP, uint16 irPort); virtual void CreateNewConnection(uint32 ID, SOCKET in_socket, uint32 irIP, uint16 irPort);
bool pOldFormat; bool pOldFormat;
//broadcast packet queue.. //broadcast packet queue..
void CheckInQueue(); void CheckInQueue();
Mutex MInQueue; Mutex MInQueue;

View File

@ -4,13 +4,13 @@
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product; are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -23,6 +23,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#endif #endif
#include "types.h" #include "types.h"
#include "eqemu_exception.h" #include "eqemu_exception.h"
@ -53,8 +54,8 @@ namespace EQEmu {
#else #else
std::string final_name = name; std::string final_name = name;
final_name += ".lock"; final_name += ".lock";
imp_->fd_ = open(final_name.c_str(), imp_->fd_ = open(final_name.c_str(),
O_RDWR | O_CREAT | O_CLOEXEC, O_RDWR | O_CREAT | O_CLOEXEC,
S_IRUSR | S_IWUSR); S_IRUSR | S_IWUSR);

View File

@ -118,7 +118,7 @@ static char *temp=NULL;
return false; return false;
} }
ptr++; ptr++;
for(i=(name_pos-1);i<(max_field-1);i++) { for(i=(name_pos-1);i<(max_field-1);i++) {
end=ptr-1; end=ptr-1;
while((end=strchr(end+1,'|'))!=NULL) { while((end=strchr(end+1,'|'))!=NULL) {
@ -463,7 +463,7 @@ bool in_quote=false;
} }
if (in_quote) if (in_quote)
continue; continue;
if (seps.find(c)!=string::npos) { if (seps.find(c)!=string::npos) {
break; break;
} }
} }
@ -554,7 +554,7 @@ void build_hex_line(const char *buffer, unsigned long length, unsigned long offs
char *ptr=out_buffer; char *ptr=out_buffer;
int i; int i;
char printable[17]; char printable[17];
ptr+=sprintf(ptr,"%0*i:",padding,offset); ptr+=sprintf(ptr,"%0*lu:",padding,offset);
for(i=0;i<16; i++) { for(i=0;i<16; i++) {
if (i==8) { if (i==8) {
strcpy(ptr," -"); strcpy(ptr," -");

View File

@ -48,7 +48,7 @@ to store them in the DB: Load and Store.
All durations are in seconds. All durations are in seconds.
Each persistent timer is attached to a character, and given Each persistent timer is attached to a character, and given
a specific type. A given character can only have one timer a specific type. A given character can only have one timer
of each type. While the type is just an arbitrary number, of each type. While the type is just an arbitrary number,
please record what you are using it for in the enum for please record what you are using it for in the enum for
@ -59,7 +59,7 @@ client has a facility called p_timers which should handle
most of what you need. The idea is that instead of making most of what you need. The idea is that instead of making
your own PersistentTimer, you use the methods on p_timers: your own PersistentTimer, you use the methods on p_timers:
Start, Check, Clear, GetRemainingTime to access them. You Start, Check, Clear, GetRemainingTime to access them. You
starting a timer which does not exist will create it. If starting a timer which does not exist will create it. If
you need to do more than that with your timer, you should you need to do more than that with your timer, you should
still use p_timers, just use the Get() method to get direct still use p_timers, just use the Get() method to get direct
access to the PersistentTimer. All timers in the p_timers access to the PersistentTimer. All timers in the p_timers
@ -101,7 +101,7 @@ PersistentTimer *PersistentTimer::LoadTimer(Database *db, uint32 char_id, pTimer
PersistentTimer::PersistentTimer(uint32 char_id, pTimerType type, uint32 in_timer_time) { PersistentTimer::PersistentTimer(uint32 char_id, pTimerType type, uint32 in_timer_time) {
_char_id = char_id; _char_id = char_id;
_type = type; _type = type;
timer_time = in_timer_time; timer_time = in_timer_time;
start_time = get_current_time(); start_time = get_current_time();
if (timer_time == 0) { if (timer_time == 0) {
@ -117,7 +117,7 @@ PersistentTimer::PersistentTimer(uint32 char_id, pTimerType type, uint32 in_time
PersistentTimer::PersistentTimer(uint32 char_id, pTimerType type, uint32 in_start_time, uint32 in_timer_time, bool in_enable) { PersistentTimer::PersistentTimer(uint32 char_id, pTimerType type, uint32 in_start_time, uint32 in_timer_time, bool in_enable) {
_char_id = char_id; _char_id = char_id;
_type = type; _type = type;
timer_time = in_timer_time; timer_time = in_timer_time;
start_time = in_start_time; start_time = in_start_time;
enabled = in_enable; enabled = in_enable;
@ -133,14 +133,14 @@ bool PersistentTimer::Load(Database *db) {
char *query = 0; char *query = 0;
uint32 qlen = 0; uint32 qlen = 0;
uint32 qcount = 0; uint32 qcount = 0;
qlen = MakeAnyLenString(&query, "SELECT start,duration,enable " qlen = MakeAnyLenString(&query, "SELECT start,duration,enable "
" FROM timers WHERE char_id=%lu AND type=%u", (unsigned long)_char_id, _type); " FROM timers WHERE char_id=%lu AND type=%u", (unsigned long)_char_id, _type);
#ifdef DEBUG_PTIMERS #ifdef DEBUG_PTIMERS
printf("Loading timer: char %lu of type %u\n", (unsigned long)_char_id, _type); printf("Loading timer: char %lu of type %u\n", (unsigned long)_char_id, _type);
#endif #endif
if (!db->RunQuery(query, qlen, errbuf, &result)) { if (!db->RunQuery(query, qlen, errbuf, &result)) {
safe_delete_array(query); safe_delete_array(query);
#if EQDEBUG > 5 #if EQDEBUG > 5
@ -149,39 +149,39 @@ bool PersistentTimer::Load(Database *db) {
return(false); return(false);
} }
safe_delete_array(query); safe_delete_array(query);
bool res = false; bool res = false;
qcount = mysql_num_rows(result); qcount = mysql_num_rows(result);
if(qcount == 1 && (row = mysql_fetch_row(result)) ) { if(qcount == 1 && (row = mysql_fetch_row(result)) ) {
start_time = strtoul(row[0], NULL, 10); start_time = strtoul(row[0], NULL, 10);
timer_time = strtoul(row[1], NULL, 10); timer_time = strtoul(row[1], NULL, 10);
enabled = (row[2][0] == '1'); enabled = (row[2][0] == '1');
res = true; res = true;
} }
mysql_free_result(result); mysql_free_result(result);
return(res); return(res);
} }
bool PersistentTimer::Store(Database *db) { bool PersistentTimer::Store(Database *db) {
if(Expired(db, false)) //dont need to store expired timers. if(Expired(db, false)) //dont need to store expired timers.
return(true); return(true);
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
uint32 qlen = 0; uint32 qlen = 0;
qlen = MakeAnyLenString(&query, "REPLACE INTO timers " qlen = MakeAnyLenString(&query, "REPLACE INTO timers "
" (char_id,type,start,duration,enable) " " (char_id,type,start,duration,enable) "
" VALUES(%lu,%u,%lu,%lu,%d)", " VALUES(%lu,%u,%lu,%lu,%d)",
(unsigned long)_char_id, _type, (unsigned long)start_time, (unsigned long)timer_time, enabled?1:0); (unsigned long)_char_id, _type, (unsigned long)start_time, (unsigned long)timer_time, enabled?1:0);
#ifdef DEBUG_PTIMERS #ifdef DEBUG_PTIMERS
printf("Storing timer: char %lu of type %u: '%s'\n", (unsigned long)_char_id, _type, query); printf("Storing timer: char %lu of type %u: '%s'\n", (unsigned long)_char_id, _type, query);
#endif #endif
if (!db->RunQuery(query, qlen, errbuf)) { if (!db->RunQuery(query, qlen, errbuf)) {
safe_delete_array(query); safe_delete_array(query);
#if EQDEBUG > 5 #if EQDEBUG > 5
@ -190,7 +190,7 @@ bool PersistentTimer::Store(Database *db) {
return(false); return(false);
} }
safe_delete_array(query); safe_delete_array(query);
return(true); return(true);
} }
@ -198,15 +198,15 @@ bool PersistentTimer::Clear(Database *db) {
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
uint32 qlen = 0; uint32 qlen = 0;
qlen = MakeAnyLenString(&query, "DELETE FROM timers " qlen = MakeAnyLenString(&query, "DELETE FROM timers "
" WHERE char_id=%lu AND type=%u ", " WHERE char_id=%lu AND type=%u ",
(unsigned long)_char_id, _type); (unsigned long)_char_id, _type);
#ifdef DEBUG_PTIMERS #ifdef DEBUG_PTIMERS
printf("Clearing timer: char %lu of type %u: '%s'\n", (unsigned long)_char_id, _type, query); printf("Clearing timer: char %lu of type %u: '%s'\n", (unsigned long)_char_id, _type, query);
#endif #endif
if (!db->RunQuery(query, qlen, errbuf)) { if (!db->RunQuery(query, qlen, errbuf)) {
safe_delete_array(query); safe_delete_array(query);
#if EQDEBUG > 5 #if EQDEBUG > 5
@ -215,15 +215,15 @@ bool PersistentTimer::Clear(Database *db) {
return(false); return(false);
} }
safe_delete_array(query); safe_delete_array(query);
return(true); return(true);
} }
/* This function checks if the timer triggered */ /* This function checks if the timer triggered */
bool PersistentTimer::Expired(Database *db, bool iReset) { bool PersistentTimer::Expired(Database *db, bool iReset) {
if (this == NULL) { if (this == NULL) {
LogFile->write(EQEMuLog::Error, "Null timer during ->Check()!?\n"); LogFile->write(EQEMuLog::Error, "Null timer during ->Check()!?\n");
return(true); return(true);
} }
uint32 current_time = get_current_time(); uint32 current_time = get_current_time();
@ -235,7 +235,7 @@ bool PersistentTimer::Expired(Database *db, bool iReset) {
} }
return(true); return(true);
} }
return(false); return(false);
} }
@ -287,7 +287,7 @@ uint32 PersistentTimer::get_current_time() {
PTimerList::PTimerList(uint32 char_id) { PTimerList::PTimerList(uint32 char_id) {
_char_id = char_id; _char_id = char_id;
} }
PTimerList::~PTimerList() { PTimerList::~PTimerList() {
map<pTimerType, PersistentTimer *>::iterator s; map<pTimerType, PersistentTimer *>::iterator s;
s = _list.begin(); s = _list.begin();
@ -308,21 +308,21 @@ bool PTimerList::Load(Database *db) {
s++; s++;
} }
_list.clear(); _list.clear();
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
char *query = 0; char *query = 0;
uint32 qlen = 0; uint32 qlen = 0;
uint32 qcount = 0; uint32 qcount = 0;
qlen = MakeAnyLenString(&query, "SELECT type,start,duration,enable " qlen = MakeAnyLenString(&query, "SELECT type,start,duration,enable "
" FROM timers WHERE char_id=%lu", (unsigned long)_char_id); " FROM timers WHERE char_id=%lu", (unsigned long)_char_id);
#ifdef DEBUG_PTIMERS #ifdef DEBUG_PTIMERS
printf("Loading all timers for char %lu\n", (unsigned long)_char_id); printf("Loading all timers for char %lu\n", (unsigned long)_char_id);
#endif #endif
if (!db->RunQuery(query, qlen, errbuf, &result)) { if (!db->RunQuery(query, qlen, errbuf, &result)) {
safe_delete_array(query); safe_delete_array(query);
#if EQDEBUG > 5 #if EQDEBUG > 5
@ -331,11 +331,11 @@ bool PTimerList::Load(Database *db) {
return(false); return(false);
} }
safe_delete_array(query); safe_delete_array(query);
pTimerType type; pTimerType type;
uint32 start_time, timer_time; uint32 start_time, timer_time;
bool enabled; bool enabled;
PersistentTimer *cur; PersistentTimer *cur;
qcount = mysql_num_rows(result); qcount = mysql_num_rows(result);
while((row = mysql_fetch_row(result)) ) { while((row = mysql_fetch_row(result)) ) {
@ -343,17 +343,17 @@ bool PTimerList::Load(Database *db) {
start_time = strtoul(row[1], NULL, 10); start_time = strtoul(row[1], NULL, 10);
timer_time = strtoul(row[2], NULL, 10); timer_time = strtoul(row[2], NULL, 10);
enabled = (row[3][0] == '1'); enabled = (row[3][0] == '1');
//if it expired allready, dont bother. //if it expired allready, dont bother.
cur = new PersistentTimer(_char_id, type, start_time, timer_time, enabled); cur = new PersistentTimer(_char_id, type, start_time, timer_time, enabled);
if(!cur->Expired(false)) if(!cur->Expired(NULL, false))
_list[type] = cur; _list[type] = cur;
else else
delete cur; delete cur;
} }
mysql_free_result(result); mysql_free_result(result);
return(true); return(true);
} }
@ -380,18 +380,18 @@ bool PTimerList::Store(Database *db) {
bool PTimerList::Clear(Database *db) { bool PTimerList::Clear(Database *db) {
_list.clear(); _list.clear();
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
uint32 qlen = 0; uint32 qlen = 0;
qlen = MakeAnyLenString(&query, "DELETE FROM timers " qlen = MakeAnyLenString(&query, "DELETE FROM timers "
" WHERE char_id=%lu ", (unsigned long)_char_id); " WHERE char_id=%lu ", (unsigned long)_char_id);
#ifdef DEBUG_PTIMERS #ifdef DEBUG_PTIMERS
printf("Storing all timers for char %lu: '%s'\n", (unsigned long)_char_id, query); printf("Storing all timers for char %lu: '%s'\n", (unsigned long)_char_id, query);
#endif #endif
if (!db->RunQuery(query, qlen, errbuf)) { if (!db->RunQuery(query, qlen, errbuf)) {
safe_delete_array(query); safe_delete_array(query);
#if EQDEBUG > 5 #if EQDEBUG > 5
@ -400,10 +400,10 @@ bool PTimerList::Clear(Database *db) {
return(false); return(false);
} }
safe_delete_array(query); safe_delete_array(query);
return(true); return(true);
} }
void PTimerList::Start(pTimerType type, uint32 duration) { void PTimerList::Start(pTimerType type, uint32 duration) {
if(_list.count(type) == 1 && _list[type] != NULL) { if(_list.count(type) == 1 && _list[type] != NULL) {
_list[type]->Start(duration); _list[type]->Start(duration);
@ -463,9 +463,9 @@ PersistentTimer *PTimerList::Get(pTimerType type) {
} }
void PTimerList::ToVector(vector< pair<pTimerType, PersistentTimer *> > &out) { void PTimerList::ToVector(vector< pair<pTimerType, PersistentTimer *> > &out) {
pair<pTimerType, PersistentTimer *> p; pair<pTimerType, PersistentTimer *> p;
map<pTimerType, PersistentTimer *>::iterator s; map<pTimerType, PersistentTimer *>::iterator s;
s = _list.begin(); s = _list.begin();
while(s != _list.end()) { while(s != _list.end()) {
@ -482,13 +482,13 @@ bool PTimerList::ClearOffline(Database *db, uint32 char_id, pTimerType type) {
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
uint32 qlen = 0; uint32 qlen = 0;
qlen = MakeAnyLenString(&query, "DELETE FROM timers WHERE char_id=%lu AND type=%u ",(unsigned long)char_id, type); qlen = MakeAnyLenString(&query, "DELETE FROM timers WHERE char_id=%lu AND type=%u ",(unsigned long)char_id, type);
#ifdef DEBUG_PTIMERS #ifdef DEBUG_PTIMERS
printf("Clearing timer (offline): char %lu of type %u: '%s'\n", (unsigned long)char_id, type, query); printf("Clearing timer (offline): char %lu of type %u: '%s'\n", (unsigned long)char_id, type, query);
#endif #endif
if (!db->RunQuery(query, qlen, errbuf)) { if (!db->RunQuery(query, qlen, errbuf)) {
safe_delete_array(query); safe_delete_array(query);
#if EQDEBUG > 5 #if EQDEBUG > 5
@ -497,7 +497,7 @@ bool PTimerList::ClearOffline(Database *db, uint32 char_id, pTimerType type) {
return(false); return(false);
} }
safe_delete_array(query); safe_delete_array(query);
return(true); return(true);

View File

@ -4,13 +4,13 @@
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product; are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -25,7 +25,7 @@
/* /*
FatherNitwit: Added new rules subsystem to allow game rules to be changed FatherNitwit: Added new rules subsystem to allow game rules to be changed
at runtime. more about this will come as time goes on. at runtime. more about this will come as time goes on.
FatherNitwit: Added #rules command to manage rules data from in game. FatherNitwit: Added #rules command to manage rules data from in game.
FatherNitwit: Renamed old #rules to #serverrules FatherNitwit: Renamed old #rules to #serverrules
@ -162,12 +162,12 @@ bool RuleManager::GetRule(const char *rule_name, std::string &ret_val) {
bool RuleManager::SetRule(const char *rule_name, const char *rule_value, Database *db, bool db_save) { bool RuleManager::SetRule(const char *rule_name, const char *rule_value, Database *db, bool db_save) {
if(rule_name == NULL || rule_value == NULL) if(rule_name == NULL || rule_value == NULL)
return(false); return(false);
RuleType type; RuleType type;
uint16 index; uint16 index;
if(!_FindRule(rule_name, type, index)) if(!_FindRule(rule_name, type, index))
return(false); return(false);
switch(type) { switch(type) {
case IntRule: case IntRule:
m_RuleIntValues [index] = atoi(rule_value); m_RuleIntValues [index] = atoi(rule_value);
@ -181,11 +181,11 @@ bool RuleManager::SetRule(const char *rule_name, const char *rule_value, Databas
uint32 val = 0; uint32 val = 0;
if(!strcasecmp(rule_value, "on") || !strcasecmp(rule_value, "true") || !strcasecmp(rule_value, "yes") || !strcasecmp(rule_value, "enabled") || !strcmp(rule_value, "1")) if(!strcasecmp(rule_value, "on") || !strcasecmp(rule_value, "true") || !strcasecmp(rule_value, "yes") || !strcasecmp(rule_value, "enabled") || !strcmp(rule_value, "1"))
val = 1; val = 1;
m_RuleBoolValues[index] = val; m_RuleBoolValues[index] = val;
_log(RULES__CHANGE, "Set rule %s to value %s", rule_name, m_RuleBoolValues[index] == 1 ?"true":"false"); _log(RULES__CHANGE, "Set rule %s to value %s", rule_name, m_RuleBoolValues[index] == 1 ?"true":"false");
break; break;
} }
if(db_save) if(db_save)
_SaveRule(db, type, index); _SaveRule(db, type, index);
@ -206,7 +206,7 @@ void RuleManager::ResetRules() {
bool RuleManager::_FindRule(const char *rule_name, RuleType &type_into, uint16 &index_into) { bool RuleManager::_FindRule(const char *rule_name, RuleType &type_into, uint16 &index_into) {
if(rule_name == NULL) if(rule_name == NULL)
return(false); return(false);
int r; int r;
int rcount = CountRules(); int rcount = CountRules();
for(r = 0; r < rcount; r++) { for(r = 0; r < rcount; r++) {
@ -253,7 +253,7 @@ void RuleManager::SaveRules(Database *db, const char *ruleset) {
} else { } else {
_log(RULES__CHANGE, "Saving running rules into running rule set %s", m_activeName.c_str(), m_activeRuleset); _log(RULES__CHANGE, "Saving running rules into running rule set %s", m_activeName.c_str(), m_activeRuleset);
} }
int r; int r;
for(r = 0; r < _IntRuleCount; r++) { for(r = 0; r < _IntRuleCount; r++) {
_SaveRule(db, IntRule, r); _SaveRule(db, IntRule, r);
@ -284,15 +284,15 @@ bool RuleManager::LoadRules(Database *db, const char *ruleset) {
m_activeRuleset = rsid; m_activeRuleset = rsid;
m_activeName = ruleset; m_activeName = ruleset;
if (db->RunQuery(query, MakeAnyLenString(&query, if (db->RunQuery(query, MakeAnyLenString(&query,
"SELECT rule_name, rule_value" "SELECT rule_name, rule_value"
" FROM rule_values" " FROM rule_values"
" WHERE ruleset_id=%d", rsid), errbuf, &result)) " WHERE ruleset_id=%d", rsid), errbuf, &result))
{ {
safe_delete_array(query); safe_delete_array(query);
while((row = mysql_fetch_row(result))) { while((row = mysql_fetch_row(result))) {
if(!SetRule(row[0], row[1], false)) if(!SetRule(row[0], row[1],NULL, false))
_log(RULES__ERROR, "Unable to interpret rule record for %s", row[0]); _log(RULES__ERROR, "Unable to interpret rule record for %s", row[0]);
} }
mysql_free_result(result); mysql_free_result(result);
@ -319,10 +319,10 @@ void RuleManager::_SaveRule(Database *db, RuleType type, uint16 index) {
sprintf(vstr, "%s", m_RuleBoolValues[index]?"true":"false"); sprintf(vstr, "%s", m_RuleBoolValues[index]?"true":"false");
break; break;
} }
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char* query = 0; char* query = 0;
if (!db->RunQuery(query, MakeAnyLenString(&query, if (!db->RunQuery(query, MakeAnyLenString(&query,
"REPLACE INTO rule_values (ruleset_id, rule_name, rule_value) " "REPLACE INTO rule_values (ruleset_id, rule_name, rule_value) "
" VALUES(%d, '%s', '%s')", " VALUES(%d, '%s', '%s')",
m_activeRuleset, _GetRuleName(type, index), vstr),errbuf)) m_activeRuleset, _GetRuleName(type, index), vstr),errbuf))
@ -338,14 +338,14 @@ int RuleManager::GetRulesetID(Database *db, const char *rulesetname) {
char *query = 0; char *query = 0;
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
uint32 len = strlen(rulesetname); uint32 len = strlen(rulesetname);
char* rst = new char[2*len+1]; char* rst = new char[2*len+1];
db->DoEscapeString(rst, rulesetname, len); db->DoEscapeString(rst, rulesetname, len);
int res = -1; int res = -1;
if (db->RunQuery(query, MakeAnyLenString(&query, if (db->RunQuery(query, MakeAnyLenString(&query,
"SELECT ruleset_id" "SELECT ruleset_id"
" FROM rule_sets" " FROM rule_sets"
" WHERE name='%s'", rst), errbuf, &result)) " WHERE name='%s'", rst), errbuf, &result))
@ -369,7 +369,7 @@ int RuleManager::_FindOrCreateRuleset(Database *db, const char *ruleset) {
res = GetRulesetID(db, ruleset); res = GetRulesetID(db, ruleset);
if(res >= 0) if(res >= 0)
return(res); //found and existing one... return(res); //found and existing one...
uint32 len = strlen(ruleset); uint32 len = strlen(ruleset);
char* rst = new char[2*len+1]; char* rst = new char[2*len+1];
db->DoEscapeString(rst, ruleset, len); db->DoEscapeString(rst, ruleset, len);
@ -377,7 +377,7 @@ int RuleManager::_FindOrCreateRuleset(Database *db, const char *ruleset) {
uint32 new_id; uint32 new_id;
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char* query = 0; char* query = 0;
if (!db->RunQuery(query, MakeAnyLenString(&query, if (!db->RunQuery(query, MakeAnyLenString(&query,
"INSERT INTO rule_sets (ruleset_id, name) " "INSERT INTO rule_sets (ruleset_id, name) "
" VALUES(0, '%s')", " VALUES(0, '%s')",
rst),errbuf,NULL,NULL,&new_id)) rst),errbuf,NULL,NULL,&new_id))
@ -399,8 +399,8 @@ std::string RuleManager::GetRulesetName(Database *db, int id) {
MYSQL_ROW row; MYSQL_ROW row;
std::string res; std::string res;
if (db->RunQuery(query, MakeAnyLenString(&query, if (db->RunQuery(query, MakeAnyLenString(&query,
"SELECT name" "SELECT name"
" FROM rule_sets" " FROM rule_sets"
" WHERE ruleset_id=%d", id), errbuf, &result)) " WHERE ruleset_id=%d", id), errbuf, &result))
@ -425,8 +425,8 @@ bool RuleManager::ListRulesets(Database *db, std::map<int, std::string> &into) {
//start out with the default set which is always present. //start out with the default set which is always present.
into[0] = "default"; into[0] = "default";
if (db->RunQuery(query, MakeAnyLenString(&query, if (db->RunQuery(query, MakeAnyLenString(&query,
"SELECT ruleset_id,name" "SELECT ruleset_id,name"
" FROM rule_sets"), errbuf, &result)) " FROM rule_sets"), errbuf, &result))
{ {
@ -444,18 +444,18 @@ bool RuleManager::ListRulesets(Database *db, std::map<int, std::string> &into) {
} }
int32 RuleManager::GetIntRule(RuleManager::IntType t) const int32 RuleManager::GetIntRule(RuleManager::IntType t) const
{ {
return(m_RuleIntValues[t]); return(m_RuleIntValues[t]);
} }
float RuleManager::GetRealRule(RuleManager::RealType t) const float RuleManager::GetRealRule(RuleManager::RealType t) const
{ {
return(m_RuleRealValues[t]); return(m_RuleRealValues[t]);
} }
bool RuleManager::GetBoolRule(RuleManager::BoolType t) const bool RuleManager::GetBoolRule(RuleManager::BoolType t) const
{ {
return (m_RuleBoolValues[t] == 1); return (m_RuleBoolValues[t] == 1);
} }

View File

@ -2,10 +2,10 @@
Father Nitwit's Zone to map conversion program. Father Nitwit's Zone to map conversion program.
Copyright (C) 2004 Father Nitwit (eqemu@8ass.com) Copyright (C) 2004 Father Nitwit (eqemu@8ass.com)
This thing uses code from freaku, so whatever license that comes under This thing uses code from freaku, so whatever license that comes under
is relavent, if you care. is relavent, if you care.
the rest of it is GPL, even though I hate the GPL. the rest of it is GPL, even though I hate the GPL.
@ -19,13 +19,13 @@
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product; are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -78,33 +78,33 @@ using namespace std;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
printf("AZONE2: EQEmu .MAP file generator with placeable object support.\n"); printf("AZONE2: EQEmu .MAP file generator with placeable object support.\n");
if(argc != 2) { if(argc != 2) {
printf("Usage: %s (zone short name)\n", argv[0]); printf("Usage: %s (zone short name)\n", argv[0]);
return(1); return(1);
} }
char bufm[250]; char bufm[250];
sprintf(bufm, "%s.map", argv[1]); sprintf(bufm, "%s.map", argv[1]);
QTBuilder QT; QTBuilder QT;
if(!QT.build(argv[1])) if(!QT.build(argv[1]))
return(1); return(1);
if(!QT.writeMap(bufm)) if(!QT.writeMap(bufm))
return(1); return(1);
return(0); return(0);
} }
QTBuilder::QTBuilder() { QTBuilder::QTBuilder() {
_root = NULL; _root = NULL;
faceCount = 0; faceCount = 0;
faceBlock = NULL; faceBlock = NULL;
#ifdef COUNT_MACTHES #ifdef COUNT_MACTHES
gEasyMatches = 0; gEasyMatches = 0;
gEasyExcludes = 0; gEasyExcludes = 0;
@ -123,8 +123,8 @@ QTBuilder::~QTBuilder() {
} }
bool QTBuilder::build(const char *shortname) { bool QTBuilder::build(const char *shortname) {
char bufs[96]; char bufs[96];
Archive *archive; Archive *archive;
FileLoader *fileloader; FileLoader *fileloader;
@ -133,12 +133,12 @@ bool QTBuilder::build(const char *shortname) {
EQFileType FileType = UNKNOWN; EQFileType FileType = UNKNOWN;
bool V4Zone = false; bool V4Zone = false;
sprintf(bufs, "%s.s3d", shortname); sprintf(bufs, "%s.s3d", shortname);
archive = new PFSLoader(); archive = new PFSLoader();
fff = fopen(bufs, "rb"); fff = fopen(bufs, "rb");
if(fff != NULL) if(fff != NULL)
FileType = S3D; FileType = S3D;
else { else {
sprintf(bufs, "%s.eqg", shortname); sprintf(bufs, "%s.eqg", shortname);
@ -158,7 +158,7 @@ bool QTBuilder::build(const char *shortname) {
} }
switch(FileType) { switch(FileType) {
case S3D: case S3D:
fileloader = new WLDLoader(); fileloader = new WLDLoader();
if(fileloader->Open(NULL, (char *) shortname, archive) == 0) { if(fileloader->Open(NULL, (char *) shortname, archive) == 0) {
printf("Error reading WLD from %s\n", bufs); printf("Error reading WLD from %s\n", bufs);
@ -183,7 +183,7 @@ bool QTBuilder::build(const char *shortname) {
} }
zm = fileloader->model_data.zone_model; zm = fileloader->model_data.zone_model;
long i; long i;
VERTEX v1, v2, v3; VERTEX v1, v2, v3;
for(i = 0; i < zm->poly_count; ++i) { for(i = 0; i < zm->poly_count; ++i) {
@ -211,11 +211,11 @@ bool QTBuilder::build(const char *shortname) {
v3.y = zm->verts[zm->polys[i]->v3]->y; v3.y = zm->verts[zm->polys[i]->v3]->y;
#endif #endif
v3.z = zm->verts[zm->polys[i]->v3]->z; v3.z = zm->verts[zm->polys[i]->v3]->z;
AddFace(v1, v2, v3); AddFace(v1, v2, v3);
} }
printf("There are %u vertices and %u faces.\n", _FaceList.size()*3, _FaceList.size()); printf("There are %lu vertices and %lu faces.\n", _FaceList.size()*3, _FaceList.size());
if(fileloader->model_data.plac_count) if(fileloader->model_data.plac_count)
{ {
@ -229,30 +229,30 @@ bool QTBuilder::build(const char *shortname) {
else else
AddPlaceable(fileloader, bufs, false); AddPlaceable(fileloader, bufs, false);
} }
else else
printf("No placeable objects (or perhaps %s_obj.s3d not present).\n", shortname); printf("No placeable objects (or perhaps %s_obj.s3d not present).\n", shortname);
printf("After processing placeable objects, there are %u vertices and %u faces.\n", _FaceList.size()*3, _FaceList.size()); printf("After processing placeable objects, there are %lu vertices and %lu faces.\n", _FaceList.size()*3, _FaceList.size());
unsigned long r; unsigned long r;
faceCount = _FaceList.size(); faceCount = _FaceList.size();
faceBlock = new FACE[faceCount]; faceBlock = new FACE[faceCount];
//im not going to assume I know vectors are stored in contiguous blocks //im not going to assume I know vectors are stored in contiguous blocks
for(r = 0; r < faceCount; r++) { for(r = 0; r < faceCount; r++) {
faceBlock[r] = _FaceList[r]; faceBlock[r] = _FaceList[r];
} }
//build quad tree... prolly much slower than it needs to be. //build quad tree... prolly much slower than it needs to be.
float minx, miny, maxx, maxy; float minx, miny, maxx, maxy;
minx = 1e12; minx = 1e12;
miny = 1e12; miny = 1e12;
maxx = -1e12; maxx = -1e12;
maxy = -1e12; maxy = -1e12;
//find our limits. //find our limits.
for(r = 0; r < faceCount; r++) { for(r = 0; r < faceCount; r++) {
//a bit of lazyness going on here... //a bit of lazyness going on here...
@ -290,17 +290,17 @@ bool QTBuilder::build(const char *shortname) {
miny = v.y; miny = v.y;
} }
} }
printf("Bounding box: %.2f < x < %.2f, %.2f < y < %.2f\n", minx, maxx, miny, maxy); printf("Bounding box: %.2f < x < %.2f, %.2f < y < %.2f\n", minx, maxx, miny, maxy);
printf("Building quadtree.\n"); printf("Building quadtree.\n");
_root = new QTNode(this, minx, maxx, miny, maxy); _root = new QTNode(this, minx, maxx, miny, maxy);
if(_root == NULL) { if(_root == NULL) {
printf("Unable to allocate new QTNode.\n"); printf("Unable to allocate new QTNode.\n");
return(false); return(false);
} }
//build our initial set of faces... all of them: //build our initial set of faces... all of them:
FACE *faceptr = faceBlock; FACE *faceptr = faceBlock;
_root->faces.resize(faceCount); _root->faces.resize(faceCount);
@ -309,9 +309,9 @@ bool QTBuilder::build(const char *shortname) {
_root->faces[r].index = r; _root->faces[r].index = r;
faceptr++; faceptr++;
} }
_root->divideYourself(0); _root->divideYourself(0);
printf("Done building quad tree...\n"); printf("Done building quad tree...\n");
#ifdef COUNT_MACTHES #ifdef COUNT_MACTHES
@ -334,39 +334,39 @@ bool QTBuilder::build(const char *shortname) {
bool QTBuilder::writeMap(const char *file) { bool QTBuilder::writeMap(const char *file) {
if(_root == NULL) if(_root == NULL)
return(false); return(false);
printf("Writing map file.\n"); printf("Writing map file.\n");
FILE *out = fopen(file, "wb"); FILE *out = fopen(file, "wb");
if(out == NULL) { if(out == NULL) {
printf("Unable to open output file '%s'.\n", file); printf("Unable to open output file '%s'.\n", file);
return(1); return(1);
} }
mapHeader head; mapHeader head;
head.version = MAP_VERSION; head.version = MAP_VERSION;
head.face_count = faceCount; head.face_count = faceCount;
head.node_count = _root->countNodes(); head.node_count = _root->countNodes();
head.facelist_count = _root->countFacelists(); head.facelist_count = _root->countFacelists();
if(fwrite(&head, sizeof(head), 1, out) != 1) { if(fwrite(&head, sizeof(head), 1, out) != 1) {
printf("Error writing map file header.\n"); printf("Error writing map file header.\n");
fclose(out); fclose(out);
return(1); return(1);
} }
printf("Map header: Version: 0x%08lX. %lu faces, %u nodes, %lu facelists\n", head.version, head.face_count, head.node_count, head.facelist_count); printf("Map header: Version: 0x%08lX. %lu faces, %u nodes, %lu facelists\n", head.version, head.face_count, head.node_count, head.facelist_count);
//write faceBlock //write faceBlock
if(fwrite(faceBlock, sizeof(FACE), faceCount, out) != faceCount) { if(fwrite(faceBlock, sizeof(FACE), faceCount, out) != faceCount) {
printf("Error writing map file faces.\n"); printf("Error writing map file faces.\n");
fclose(out); fclose(out);
return(1); return(1);
} }
//make our node blocks to write out... //make our node blocks to write out...
nodeHeader *nodes = new nodeHeader[head.node_count]; nodeHeader *nodes = new nodeHeader[head.node_count];
unsigned long *facelist = new unsigned long[head.facelist_count]; unsigned long *facelist = new unsigned long[head.facelist_count];
@ -375,11 +375,11 @@ bool QTBuilder::writeMap(const char *file) {
fclose(out); fclose(out);
return(1); //no memory return(1); //no memory
} }
unsigned long hindex = 0; unsigned long hindex = 0;
unsigned long findex = 0; unsigned long findex = 0;
_root->fillBlocks(nodes, facelist, hindex, findex); _root->fillBlocks(nodes, facelist, hindex, findex);
if(fwrite(nodes, sizeof(nodeHeader), head.node_count, out) != head.node_count) { if(fwrite(nodes, sizeof(nodeHeader), head.node_count, out) != head.node_count) {
printf("Error writing map file nodes.\n"); printf("Error writing map file nodes.\n");
fclose(out); fclose(out);
@ -390,15 +390,15 @@ bool QTBuilder::writeMap(const char *file) {
fclose(out); fclose(out);
return(1); return(1);
} }
long MapFileSize = ftell(out); long MapFileSize = ftell(out);
fclose(out); fclose(out);
delete[] nodes; delete[] nodes;
delete[] facelist; delete[] facelist;
printf("Done writing map (%3.2fMB).\n", (float)MapFileSize/1048576); printf("Done writing map (%3.2fMB).\n", (float)MapFileSize/1048576);
return(0); return(0);
} }
@ -414,7 +414,7 @@ QTNode::QTNode(QTBuilder *b, float Tminx, float Tmaxx, float Tminy, float Tmaxy)
maxy = Tmaxy; maxy = Tmaxy;
final = false; final = false;
buildVertexes(); buildVertexes();
builder = b; builder = b;
} }
@ -441,7 +441,7 @@ void QTNode::clearNodes() {
void QTNode::fillBlocks(nodeHeader *heads, unsigned long *flist, unsigned long &hindex, unsigned long &findex) { void QTNode::fillBlocks(nodeHeader *heads, unsigned long *flist, unsigned long &hindex, unsigned long &findex) {
nodeHeader *head = &heads[hindex]; nodeHeader *head = &heads[hindex];
hindex++; hindex++;
head->minx = minx; head->minx = minx;
head->maxx = maxx; head->maxx = maxx;
head->miny = miny; head->miny = miny;
@ -462,7 +462,7 @@ void QTNode::fillBlocks(nodeHeader *heads, unsigned long *flist, unsigned long &
} else { } else {
//branch node. //branch node.
head->flags = 0; head->flags = 0;
if(node1 != NULL) { if(node1 != NULL) {
head->nodes[0] = hindex; head->nodes[0] = hindex;
node1->fillBlocks(heads, flist, hindex, findex); node1->fillBlocks(heads, flist, hindex, findex);
@ -523,54 +523,54 @@ Map Format:
head.face_count x FACE head.face_count x FACE
head.node_count x nodeHeader head.node_count x nodeHeader
head.facelist_count x unsigned long (indexes into face array) head.facelist_count x unsigned long (indexes into face array)
*/ */
void QTNode::divideYourself(int depth) { void QTNode::divideYourself(int depth) {
// printf("Dividing in box (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n", // printf("Dividing in box (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n",
// minx, maxx, miny, maxy, depth, faces.size()); // minx, maxx, miny, maxy, depth, faces.size());
unsigned long cc; unsigned long cc;
cc = faces.size(); cc = faces.size();
#ifdef MAX_QUADRENT_FACES #ifdef MAX_QUADRENT_FACES
if(cc <= MAX_QUADRENT_FACES) { if(cc <= MAX_QUADRENT_FACES) {
#ifdef SPLIT_DEBUG #ifdef SPLIT_DEBUG
printf("Stopping (facecount) on box (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n", printf("Stopping (facecount) on box (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n",
minx, maxx, miny, maxy, depth, cc); minx, maxx, miny, maxy, depth, cc);
#endif #endif
final = true; final = true;
return; return;
} }
#endif #endif
#ifdef MIN_QUADRENT_SIZE #ifdef MIN_QUADRENT_SIZE
if((maxx - minx) < MIN_QUADRENT_SIZE || (maxy - miny) < MIN_QUADRENT_SIZE) { if((maxx - minx) < MIN_QUADRENT_SIZE || (maxy - miny) < MIN_QUADRENT_SIZE) {
#ifdef SPLIT_DEBUG #ifdef SPLIT_DEBUG
printf("Stopping on box (size) (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n", printf("Stopping on box (size) (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n",
minx, maxx, miny, maxy, depth, cc); minx, maxx, miny, maxy, depth, cc);
#endif #endif
final = true; final = true;
return; return;
} }
#endif #endif
doSplit(); doSplit();
//get counts on our split //get counts on our split
float c1, c2, c3, c4; float c1, c2, c3, c4;
c1 = node1? node1->faces.size() : 0; c1 = node1? node1->faces.size() : 0;
c2 = node2? node2->faces.size() : 0; c2 = node2? node2->faces.size() : 0;
c3 = node3? node3->faces.size() : 0; c3 = node3? node3->faces.size() : 0;
c4 = node4? node4->faces.size() : 0; c4 = node4? node4->faces.size() : 0;
#ifdef MIN_QUADRENT_GAIN #ifdef MIN_QUADRENT_GAIN
int miss = 0; int miss = 0;
float gain1 = 1.0 - c1 / cc; float gain1 = 1.0 - c1 / cc;
float gain2 = 1.0 - c2 / cc; float gain2 = 1.0 - c2 / cc;
float gain3 = 1.0 - c3 / cc; float gain3 = 1.0 - c3 / cc;
float gain4 = 1.0 - c4 / cc; float gain4 = 1.0 - c4 / cc;
//see how many missed the gain mark //see how many missed the gain mark
if(gain1 < MIN_QUADRENT_GAIN) if(gain1 < MIN_QUADRENT_GAIN)
miss++; miss++;
@ -580,33 +580,33 @@ printf("Stopping on box (size) (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d
miss++; miss++;
if(gain4 < MIN_QUADRENT_GAIN) if(gain4 < MIN_QUADRENT_GAIN)
miss++; miss++;
if(miss > MAX_QUADRENT_MISSES) { if(miss > MAX_QUADRENT_MISSES) {
#ifdef SPLIT_DEBUG #ifdef SPLIT_DEBUG
printf("Stopping (gain) on box (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n", printf("Stopping (gain) on box (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n",
minx, maxx, miny, maxy, depth, cc); minx, maxx, miny, maxy, depth, cc);
#endif #endif
final = true; final = true;
return; return;
} }
#endif #endif
//if all faces pass through all quadrents, then we are done //if all faces pass through all quadrents, then we are done
//partially obsoleted by gain test. //partially obsoleted by gain test.
if(c1 == c2 && c1 == c3 && c1 == c4) { if(c1 == c2 && c1 == c3 && c1 == c4) {
#ifdef SPLIT_DEBUG #ifdef SPLIT_DEBUG
printf("Stopping (empty) on box (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n", printf("Stopping (empty) on box (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d faces.\n",
minx, maxx, miny, maxy, depth, cc); minx, maxx, miny, maxy, depth, cc);
#endif #endif
final = true; final = true;
return; return;
} }
//there are prolly some more intelligent stopping criteria... //there are prolly some more intelligent stopping criteria...
depth++; depth++;
if(node1 != NULL) if(node1 != NULL)
node1->divideYourself(depth); node1->divideYourself(depth);
if(node2 != NULL) if(node2 != NULL)
@ -615,18 +615,18 @@ printf("Stopping (empty) on box (%.2f -> %.2f, %.2f -> %.2f) at depth %d with %d
node3->divideYourself(depth); node3->divideYourself(depth);
if(node4 != NULL) if(node4 != NULL)
node4->divideYourself(depth); node4->divideYourself(depth);
} }
void QTNode::buildVertexes() { void QTNode::buildVertexes() {
v[0].x = v[1].x = v[2].x = v[3].x = minx; v[0].x = v[1].x = v[2].x = v[3].x = minx;
v[4].x = v[5].x = v[6].x = v[7].x = maxx; v[4].x = v[5].x = v[6].x = v[7].x = maxx;
v[0].y = v[1].y = v[4].y = v[5].y = miny; v[0].y = v[1].y = v[4].y = v[5].y = miny;
v[2].y = v[3].y = v[6].y = v[7].y = maxy; v[2].y = v[3].y = v[6].y = v[7].y = maxy;
v[0].z = v[3].z = v[4].z = v[7].z = -999999; v[0].z = v[3].z = v[4].z = v[7].z = -999999;
v[1].z = v[2].z = v[5].z = v[6].z = 9999999; v[1].z = v[2].z = v[5].z = v[6].z = 9999999;
} }
@ -677,7 +677,7 @@ bool edges_cross(GPoint *pt1, GPoint *pt2, const VERTEX *pt3, const VERTEX *pt4)
(p2->x > p1->x? \ (p2->x > p1->x? \
(p1->z + ((inter - p1->x)/(p2->x - p1->x) * (p2->z - p1->z))) \ (p1->z + ((inter - p1->x)/(p2->x - p1->x) * (p2->z - p1->z))) \
:(p2->z + ((inter - p2->x)/(p1->x - p2->x) * (p1->z - p2->z)))) :(p2->z + ((inter - p2->x)/(p1->x - p2->x) * (p1->z - p2->z))))
float denom = IntersectDenom(pt1, pt2, pt3, pt4); float denom = IntersectDenom(pt1, pt2, pt3, pt4);
if(denom != 0) { if(denom != 0) {
@ -746,25 +746,25 @@ bool QTBuilder::FaceInNode(const QTNode *q, const FACE *f) {
const VERTEX *v1 = &f->a; const VERTEX *v1 = &f->a;
const VERTEX *v2 = &f->b; const VERTEX *v2 = &f->b;
const VERTEX *v3 = &f->c; const VERTEX *v3 = &f->c;
#ifdef COUNT_MACTHES #ifdef COUNT_MACTHES
gEasyMatches++; gEasyMatches++;
#endif #endif
//Easy matches, points are within the quadrant. //Easy matches, points are within the quadrant.
if( ! ( v1->x <= q->minx || v1->x > q->maxx if( ! ( v1->x <= q->minx || v1->x > q->maxx
|| v1->y <= q->miny || v1->y > q->maxy ) ) { || v1->y <= q->miny || v1->y > q->maxy ) ) {
return(true); return(true);
} }
if( ! ( v2->x <= q->minx || v2->x > q->maxx if( ! ( v2->x <= q->minx || v2->x > q->maxx
|| v2->y <= q->miny || v2->y > q->maxy ) ) { || v2->y <= q->miny || v2->y > q->maxy ) ) {
return(true); return(true);
} }
if( ! ( v3->x <= q->minx || v3->x > q->maxx if( ! ( v3->x <= q->minx || v3->x > q->maxx
|| v3->y <= q->miny || v3->y > q->maxy ) ) { || v3->y <= q->miny || v3->y > q->maxy ) ) {
return(true); return(true);
} }
#ifdef COUNT_MACTHES #ifdef COUNT_MACTHES
gEasyMatches--; gEasyMatches--;
gEasyExcludes++; gEasyExcludes++;
@ -779,41 +779,41 @@ bool QTBuilder::FaceInNode(const QTNode *q, const FACE *f) {
return(false); return(false);
if( v1->y > q->maxy && v2->y > q->maxy && v3->y > q->maxy ) if( v1->y > q->maxy && v2->y > q->maxy && v3->y > q->maxy )
return(false); return(false);
#ifdef COUNT_MACTHES #ifdef COUNT_MACTHES
gEasyExcludes--; gEasyExcludes--;
#endif #endif
#ifdef COUNT_MACTHES #ifdef COUNT_MACTHES
gHardMatches++; gHardMatches++;
#endif #endif
// return(true); // return(true);
//harder: no points are in the cube //harder: no points are in the cube
//4 points of this node //4 points of this node
GPoint pt1(q->minx, q->miny, 0), GPoint pt1(q->minx, q->miny, 0),
pt2(q->minx, q->maxy, 0), pt2(q->minx, q->maxy, 0),
pt3(q->maxx, q->miny, 0), pt3(q->maxx, q->miny, 0),
pt4(q->maxx, q->maxy, 0); pt4(q->maxx, q->maxy, 0);
/* /*
//box lines: //box lines:
pt1, pt2 pt1, pt2
pt3, pt4 pt3, pt4
pt1, pt3 pt1, pt3
pt2, pt4 pt2, pt4
//tri lines //tri lines
v1, v2 v1, v2
v1, v3 v1, v3
v2, v3 v2, v3
*/ */
#define CheckIntersect(p1, p2, p3, p4) \ #define CheckIntersect(p1, p2, p3, p4) \
(((p4->y - p3->y)*(p2.x - p1.x) - (p4->x - p3->x)*(p2.y - p1.y)) != 0) (((p4->y - p3->y)*(p2.x - p1.x) - (p4->x - p3->x)*(p2.y - p1.y)) != 0)
int finaltest = int finaltest =
(edges_cross(&pt1, &pt2, v1, v2) (edges_cross(&pt1, &pt2, v1, v2)
|| edges_cross(&pt1, &pt2, v1, v3) || edges_cross(&pt1, &pt2, v1, v3)
@ -829,7 +829,7 @@ bool QTBuilder::FaceInNode(const QTNode *q, const FACE *f) {
|| edges_cross(&pt2, &pt4, v2, v3)); || edges_cross(&pt2, &pt4, v2, v3));
if(finaltest) return finaltest; if(finaltest) return finaltest;
VERTEX Triangle[3]; VERTEX Triangle[3];
Triangle[0]=*v1; Triangle[1]=*v2; Triangle[2] = *v3; Triangle[0]=*v1; Triangle[1]=*v2; Triangle[2] = *v3;
finaltest = PointInTriangle(Triangle, q->minx, q->miny) || finaltest = PointInTriangle(Triangle, q->minx, q->miny) ||
@ -843,12 +843,12 @@ bool QTBuilder::FaceInNode(const QTNode *q, const FACE *f) {
void QTNode::doSplit() { void QTNode::doSplit() {
//find midpoints... //find midpoints...
float midx = minx + (maxx - minx) / 2.0; float midx = minx + (maxx - minx) / 2.0;
float midy = miny + (maxy - miny) / 2.0; float midy = miny + (maxy - miny) / 2.0;
//ordering following definitions in map.h //ordering following definitions in map.h
node1 = new QTNode(builder, midx, maxx, midy, maxy); node1 = new QTNode(builder, midx, maxx, midy, maxy);
node2 = new QTNode(builder, minx, midx, midy, maxy); node2 = new QTNode(builder, minx, midx, midy, maxy);
@ -858,7 +858,7 @@ void QTNode::doSplit() {
printf("Error: unable to allocate new QTNode, giving up.\n"); printf("Error: unable to allocate new QTNode, giving up.\n");
return; return;
} }
unsigned long r,l; unsigned long r,l;
l = faces.size(); l = faces.size();
for(r = 0; r < l; r++) { for(r = 0; r < l; r++) {
@ -872,7 +872,7 @@ void QTNode::doSplit() {
if(builder->FaceInNode(node4, cur.face)) if(builder->FaceInNode(node4, cur.face))
node4->faces.push_back(cur); node4->faces.push_back(cur);
} }
//clean up empty sets. //clean up empty sets.
if(node1->faces.size() == 0) { if(node1->faces.size() == 0) {
delete node1; delete node1;
@ -890,29 +890,29 @@ void QTNode::doSplit() {
delete node4; delete node4;
node4 = NULL; node4 = NULL;
} }
} }
void QTBuilder::AddFace(VERTEX &v1, VERTEX &v2, VERTEX &v3) { void QTBuilder::AddFace(VERTEX &v1, VERTEX &v2, VERTEX &v3) {
FACE f; FACE f;
#ifdef MAX_Z #ifdef MAX_Z
if(v1.z > MAX_Z && v2.z > MAX_Z && v3.z > MAX_Z) if(v1.z > MAX_Z && v2.z > MAX_Z && v3.z > MAX_Z)
return; return;
#endif #endif
//this still might not work //this still might not work
f.nx = (v2.y - v1.y)*(v3.z - v1.z) - (v2.z - v1.z)*(v3.y - v1.y); f.nx = (v2.y - v1.y)*(v3.z - v1.z) - (v2.z - v1.z)*(v3.y - v1.y);
f.ny = (v2.z - v1.z)*(v3.x - v1.x) - (v2.x - v1.x)*(v3.z - v1.z); f.ny = (v2.z - v1.z)*(v3.x - v1.x) - (v2.x - v1.x)*(v3.z - v1.z);
f.nz = (v2.x - v1.x)*(v3.y - v1.y) - (v2.y - v1.y)*(v3.x - v1.x); f.nz = (v2.x - v1.x)*(v3.y - v1.y) - (v2.y - v1.y)*(v3.x - v1.x);
NormalizeN(&f); NormalizeN(&f);
f.nd = - f.nx * v1.x - f.ny * v1.y - f.nz * v1.z; f.nd = - f.nx * v1.x - f.ny * v1.y - f.nz * v1.z;
f.a = v1; f.a = v1;
f.b = v2; f.b = v2;
f.c = v3; f.c = v3;
_FaceList.push_back(f); _FaceList.push_back(f);
} }
@ -989,75 +989,75 @@ void GVector::normalize() {
} }
//stolen from: http://gamecode.tripod.com/tut/tut04.htm //stolen from: http://gamecode.tripod.com/tut/tut04.htm
int QTBuilder::ClipPolygon(POLYGON *poly, GVector *plane) { int QTBuilder::ClipPolygon(POLYGON *poly, GVector *plane) {
/* Plan: cycle through the vertices, considering pairs of them. /* Plan: cycle through the vertices, considering pairs of them.
If both vertices are visible, add them to the new array. If both vertices are visible, add them to the new array.
If both vertices are invisible, add neither to the new array. If both vertices are invisible, add neither to the new array.
If one vertex is visible and the other is not, move the one If one vertex is visible and the other is not, move the one
that's not, and then add both vertices to the new array. that's not, and then add both vertices to the new array.
*/ */
float dist1, dist2; // distances of points to plane float dist1, dist2; // distances of points to plane
float distratio; // fraction of distance between two points float distratio; // fraction of distance between two points
// new vertices might be created. Don't change // new vertices might be created. Don't change
// polygon's vertices because we might still need // polygon's vertices because we might still need
// them. Instead, use tempvtx array and update vertices // them. Instead, use tempvtx array and update vertices
// array at the end. Create tempvtx array once only. // array at the end. Create tempvtx array once only.
int i, ii, j=0; int i, ii, j=0;
/* Check if plane is a valid plane */ /* Check if plane is a valid plane */
if (!(plane->x || plane->y || plane->z)) return -1; if (!(plane->x || plane->y || plane->z)) return -1;
// if not valid plane, don't change polygon and return an error; // if not valid plane, don't change polygon and return an error;
/* The vertices should, as for all functions, be arranged in cyclic /* The vertices should, as for all functions, be arranged in cyclic
order. That is, if a line was drawn from each vertex to the next order. That is, if a line was drawn from each vertex to the next
it would form the correct outline of the polygon in 3D space. it would form the correct outline of the polygon in 3D space.
This routine might create new vertices because of the clipping, This routine might create new vertices because of the clipping,
but the cyclic order will be preserved. but the cyclic order will be preserved.
*/ */
for (i=0; i<poly->count; i++) for (i=0; i<poly->count; i++)
{ {
ii = (i+1)%poly->count; ii = (i+1)%poly->count;
dist1 = plane->x * poly->c[i].x + plane->y * poly->c[i].y + dist1 = plane->x * poly->c[i].x + plane->y * poly->c[i].y +
plane->z * poly->c[i].z + plane->W; plane->z * poly->c[i].z + plane->W;
dist2 = plane->x * poly->c[ii].x + plane->y * poly->c[ii].y + dist2 = plane->x * poly->c[ii].x + plane->y * poly->c[ii].y +
plane->z * poly->c[ii].z + plane->W; plane->z * poly->c[ii].z + plane->W;
if (dist1<0 && dist2<0) // line unclipped and invisible if (dist1<0 && dist2<0) // line unclipped and invisible
continue; continue;
if (dist1>0 && dist2>0) // line unclipped and visible if (dist1>0 && dist2>0) // line unclipped and visible
tempvtx[j++]=poly->c[i]; tempvtx[j++]=poly->c[i];
else // line partially visible else // line partially visible
if (dist1>0) // first vertex is visible if (dist1>0) // first vertex is visible
{ {
distratio = dist1/(dist1-dist2); distratio = dist1/(dist1-dist2);
tempvtx[j] = poly->c[i]; tempvtx[j] = poly->c[i];
j++; // Copied 1st vertex j++; // Copied 1st vertex
tempvtx[j].x = poly->c[i].x + tempvtx[j].x = poly->c[i].x +
(poly->c[ii].x - poly->c[i].x) * distratio; (poly->c[ii].x - poly->c[i].x) * distratio;
tempvtx[j].y = poly->c[i].y + tempvtx[j].y = poly->c[i].y +
(poly->c[ii].y - poly->c[i].y) * distratio; (poly->c[ii].y - poly->c[i].y) * distratio;
tempvtx[j].z = poly->c[i].z + tempvtx[j].z = poly->c[i].z +
(poly->c[ii].z - poly->c[i].z) * distratio; (poly->c[ii].z - poly->c[i].z) * distratio;
j++; // Copied second vertex j++; // Copied second vertex
} }
else // second vertex is visible else // second vertex is visible
{ {
distratio = dist2/(dist2-dist1); distratio = dist2/(dist2-dist1);
tempvtx[j].x = poly->c[ii].x + tempvtx[j].x = poly->c[ii].x +
(poly->c[i].x - poly->c[ii].x) * distratio; (poly->c[i].x - poly->c[ii].x) * distratio;
tempvtx[j].y = poly->c[ii].y + tempvtx[j].y = poly->c[ii].y +
(poly->c[i].y - poly->c[ii].y) * distratio; (poly->c[i].y - poly->c[ii].y) * distratio;
tempvtx[j].z = poly->c[ii].z + tempvtx[j].z = poly->c[ii].z +
(poly->c[i].z - poly->c[ii].z) * distratio; (poly->c[i].z - poly->c[ii].z) * distratio;
j++; // Copy only first vertex. 2nd vertex will be copied j++; // Copy only first vertex. 2nd vertex will be copied
// in next iteration of loop // in next iteration of loop
} }
} }
for (i=0; i<j; i++) for (i=0; i<j; i++)
poly->c[i] = tempvtx[i]; // Update the vertices in polygon poly->c[i] = tempvtx[i]; // Update the vertices in polygon
poly->count = j; // Update the vertex count poly->count = j; // Update the vertex count
return j; return j;
} }
@ -1160,7 +1160,7 @@ void QTBuilder::AddPlaceable(FileLoader *fileloader, char *ZoneFileName, bool Li
continue; continue;
} }
IniBuffer[StrIndex++] = tolower(ch); IniBuffer[StrIndex++] = tolower(ch);
} }
fclose(IniFile); fclose(IniFile);
if(INIEntryFound) { if(INIEntryFound) {
@ -1173,7 +1173,7 @@ void QTBuilder::AddPlaceable(FileLoader *fileloader, char *ZoneFileName, bool Li
else { else {
printf("No azone.ini entry found for zone %s\n", ZoneFileName); printf("No azone.ini entry found for zone %s\n", ZoneFileName);
} }
for(int i = 0; i < fileloader->model_data.plac_count; ++i) { for(int i = 0; i < fileloader->model_data.plac_count; ++i) {
@ -1186,9 +1186,9 @@ void QTBuilder::AddPlaceable(FileLoader *fileloader, char *ZoneFileName, bool Li
fileloader->model_data.placeable[i]->x, fileloader->model_data.placeable[i]->x,
fileloader->model_data.placeable[i]->z, fileloader->model_data.placeable[i]->z,
fileloader->model_data.placeable[i]->model, fileloader->model_data.placeable[i]->model,
fileloader->model_data.models[fileloader->model_data.placeable[i]->model]->name); fileloader->model_data.models[fileloader->model_data.placeable[i]->model]->name);
if(!fileloader->model_data.models[fileloader->model_data.placeable[i]->model]->IncludeInMap) if(!fileloader->model_data.models[fileloader->model_data.placeable[i]->model]->IncludeInMap)
continue; continue;
printf("Including Placeable Object %4d using model %4d (%s).\n", i, printf("Including Placeable Object %4d using model %4d (%s).\n", i,
@ -1212,11 +1212,11 @@ void QTBuilder::AddPlaceable(FileLoader *fileloader, char *ZoneFileName, bool Li
Model *model = fileloader->model_data.models[fileloader->model_data.placeable[i]->model]; Model *model = fileloader->model_data.models[fileloader->model_data.placeable[i]->model];
for(int j = 0; j < model->poly_count; ++j) { for(int j = 0; j < model->poly_count; ++j) {
poly = model->polys[j]; poly = model->polys[j];
verts[0] = model->verts[poly->v1]; verts[0] = model->verts[poly->v1];
verts[1] = model->verts[poly->v2]; verts[1] = model->verts[poly->v2];
verts[2] = model->verts[poly->v3]; verts[2] = model->verts[poly->v3];
@ -1234,22 +1234,22 @@ void QTBuilder::AddPlaceable(FileLoader *fileloader, char *ZoneFileName, bool Li
ScaleVertex(v2, XScale, YScale, ZScale); ScaleVertex(v2, XScale, YScale, ZScale);
ScaleVertex(v3, XScale, YScale, ZScale); ScaleVertex(v3, XScale, YScale, ZScale);
TranslateVertex(v1, XOffset, YOffset, ZOffset); TranslateVertex(v1, XOffset, YOffset, ZOffset);
TranslateVertex(v2, XOffset, YOffset, ZOffset); TranslateVertex(v2, XOffset, YOffset, ZOffset);
TranslateVertex(v3, XOffset, YOffset, ZOffset); TranslateVertex(v3, XOffset, YOffset, ZOffset);
// Swap X & Y // Swap X & Y
// //
tmpv = v1; v1.x = tmpv.y; v1.y = tmpv.x; tmpv = v1; v1.x = tmpv.y; v1.y = tmpv.x;
tmpv = v2; v2.x = tmpv.y; v2.y = tmpv.x; tmpv = v2; v2.x = tmpv.y; v2.y = tmpv.x;
tmpv = v3; v3.x = tmpv.y; v3.y = tmpv.x; tmpv = v3; v3.x = tmpv.y; v3.y = tmpv.x;
AddFace(v1, v2, v3); AddFace(v1, v2, v3);
} }
} }
} }
void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool ListPlaceable) { void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool ListPlaceable) {
Polygon *poly; Polygon *poly;
@ -1262,7 +1262,7 @@ void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool
//return; //return;
printf("EQG V4 Placeable Zone Support\n"); printf("EQG V4 Placeable Zone Support\n");
printf("ObjectGroupCount = %i\n", fileloader->model_data.ObjectGroups.size()); printf("ObjectGroupCount = %lu\n", fileloader->model_data.ObjectGroups.size());
vector<ObjectGroupEntry>::iterator Iterator; vector<ObjectGroupEntry>::iterator Iterator;
@ -1302,7 +1302,7 @@ void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool
if((ch=='#')&&(StrIndex==0)) { // Discard comment lines beginning with a hash if((ch=='#')&&(StrIndex==0)) { // Discard comment lines beginning with a hash
while((ch!=EOF)&&(ch!='\n')) while((ch!=EOF)&&(ch!='\n'))
ch = fgetc(IniFile); ch = fgetc(IniFile);
continue; continue;
} }
if((ch=='\n') && (State==ReadingZoneName)) { if((ch=='\n') && (State==ReadingZoneName)) {
@ -1337,7 +1337,7 @@ void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool
{ {
if((ModelNumber >= 0) && ((unsigned int)ModelNumber < fileloader->model_data.ObjectGroups.size())) if((ModelNumber >= 0) && ((unsigned int)ModelNumber < fileloader->model_data.ObjectGroups.size()))
fileloader->model_data.ObjectGroups[ModelNumber].IncludeInMap = Exclude ? false : true; fileloader->model_data.ObjectGroups[ModelNumber].IncludeInMap = Exclude ? false : true;
} }
} }
break; break;
@ -1383,13 +1383,13 @@ void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool
{ {
if((ModelNumber >= 0) && ((unsigned int)ModelNumber < fileloader->model_data.ObjectGroups.size())) if((ModelNumber >= 0) && ((unsigned int)ModelNumber < fileloader->model_data.ObjectGroups.size()))
fileloader->model_data.ObjectGroups[ModelNumber].IncludeInMap = Exclude ? false : true; fileloader->model_data.ObjectGroups[ModelNumber].IncludeInMap = Exclude ? false : true;
} }
} }
continue; continue;
} }
IniBuffer[StrIndex++] = tolower(ch); IniBuffer[StrIndex++] = tolower(ch);
} }
fclose(IniFile); fclose(IniFile);
if(INIEntryFound) if(INIEntryFound)
@ -1397,7 +1397,7 @@ void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool
else else
printf("No azone.ini entry found for zone %s\n", ZoneFileName); printf("No azone.ini entry found for zone %s\n", ZoneFileName);
} }
Iterator = fileloader->model_data.ObjectGroups.begin(); Iterator = fileloader->model_data.ObjectGroups.begin();
while(Iterator != fileloader->model_data.ObjectGroups.end()) while(Iterator != fileloader->model_data.ObjectGroups.end())
@ -1429,11 +1429,11 @@ void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool
list<int>::iterator ModelIterator; list<int>::iterator ModelIterator;
ModelIterator = (*Iterator).SubObjects.begin(); ModelIterator = (*Iterator).SubObjects.begin();
while(ModelIterator != (*Iterator).SubObjects.end()) while(ModelIterator != (*Iterator).SubObjects.end())
{ {
int SubModel = (*ModelIterator); int SubModel = (*ModelIterator);
#ifdef DEBUG #ifdef DEBUG
printf(" SubModel: %i\n", (*ModelIterator)); printf(" SubModel: %i\n", (*ModelIterator));
#endif #endif
@ -1519,8 +1519,8 @@ void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool
RotateVertex(v1, RotX, 0, 0); RotateVertex(v1, RotX, 0, 0);
RotateVertex(v2, RotX, 0, 0); RotateVertex(v2, RotX, 0, 0);
RotateVertex(v3, RotX, 0, 0); RotateVertex(v3, RotX, 0, 0);
// Don't know why the Y rotation needs to be negative // Don't know why the Y rotation needs to be negative
// //
RotateVertex(v1, 0, -RotY, 0); RotateVertex(v1, 0, -RotY, 0);
RotateVertex(v2, 0, -RotY, 0); RotateVertex(v2, 0, -RotY, 0);
@ -1556,12 +1556,12 @@ void QTBuilder::AddPlaceableV4(FileLoader *fileloader, char *ZoneFileName, bool
TranslateVertex(v3, (*Iterator).x, (*Iterator).y, (*Iterator).z); TranslateVertex(v3, (*Iterator).x, (*Iterator).y, (*Iterator).z);
// Swap X & Y // Swap X & Y
// //
tmpv = v1; v1.x = tmpv.y; v1.y = tmpv.x; tmpv = v1; v1.x = tmpv.y; v1.y = tmpv.x;
tmpv = v2; v2.x = tmpv.y; v2.y = tmpv.x; tmpv = v2; v2.x = tmpv.y; v2.y = tmpv.x;
tmpv = v3; v3.x = tmpv.y; v3.y = tmpv.x; tmpv = v3; v3.x = tmpv.y; v3.y = tmpv.x;
AddFace(v1, v2, v3); AddFace(v1, v2, v3);
} }
++ModelIterator; ++ModelIterator;
} }
@ -1619,5 +1619,5 @@ void QTBuilder::TranslateVertex(VERTEX &v, float XOffset, float YOffset, float Z

View File

@ -4,13 +4,13 @@
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product; are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -38,11 +38,11 @@ void EQLConfig::LoadSettings() {
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
LauncherZone tmp; LauncherZone tmp;
char namebuf[128]; char namebuf[128];
database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64
namebuf[127] = '\0'; namebuf[127] = '\0';
if (database.RunQuery(query, MakeAnyLenString(&query, if (database.RunQuery(query, MakeAnyLenString(&query,
"SELECT dynamics FROM launcher WHERE name='%s'", "SELECT dynamics FROM launcher WHERE name='%s'",
namebuf) namebuf)
@ -56,7 +56,7 @@ void EQLConfig::LoadSettings() {
LogFile->write(EQEMuLog::Error, "EQLConfig::LoadSettings: %s", errbuf); LogFile->write(EQEMuLog::Error, "EQLConfig::LoadSettings: %s", errbuf);
} }
safe_delete_array(query); safe_delete_array(query);
if (database.RunQuery(query, MakeAnyLenString(&query, if (database.RunQuery(query, MakeAnyLenString(&query,
"SELECT zone,port FROM launcher_zones WHERE launcher='%s'", "SELECT zone,port FROM launcher_zones WHERE launcher='%s'",
namebuf) namebuf)
@ -78,20 +78,20 @@ void EQLConfig::LoadSettings() {
EQLConfig *EQLConfig::CreateLauncher(const char *name, uint8 dynamic_count) { EQLConfig *EQLConfig::CreateLauncher(const char *name, uint8 dynamic_count) {
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
char namebuf[128]; char namebuf[128];
database.DoEscapeString(namebuf, name, strlen(name)&0x3F); //limit len to 64 database.DoEscapeString(namebuf, name, strlen(name)&0x3F); //limit len to 64
namebuf[127] = '\0'; namebuf[127] = '\0';
if (!database.RunQuery(query, MakeAnyLenString(&query, if (!database.RunQuery(query, MakeAnyLenString(&query,
"INSERT INTO launcher (name,dynamics) VALUES('%s', %d)", "INSERT INTO launcher (name,dynamics) VALUES('%s', %d)",
namebuf, dynamic_count), errbuf)) { namebuf, dynamic_count), errbuf)) {
LogFile->write(EQEMuLog::Error, "Error in CreateLauncher query: %s", errbuf); LogFile->write(EQEMuLog::Error, "Error in CreateLauncher query: %s", errbuf);
safe_delete_array(query); safe_delete_array(query);
return false; return NULL;
} }
safe_delete_array(query); safe_delete_array(query);
return(new EQLConfig(name)); return(new EQLConfig(name));
} }
@ -123,27 +123,27 @@ vector<string> EQLConfig::ListZones() {
} }
void EQLConfig::DeleteLauncher() { void EQLConfig::DeleteLauncher() {
launcher_list.Remove(m_name.c_str()); launcher_list.Remove(m_name.c_str());
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
char namebuf[128]; char namebuf[128];
database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64
namebuf[127] = '\0'; namebuf[127] = '\0';
if (!database.RunQuery(query, MakeAnyLenString(&query, if (!database.RunQuery(query, MakeAnyLenString(&query,
"DELETE FROM launcher WHERE name='%s'", "DELETE FROM launcher WHERE name='%s'",
namebuf), errbuf)) { namebuf), errbuf)) {
LogFile->write(EQEMuLog::Error, "Error in DeleteLauncher 1 query: %s", errbuf); LogFile->write(EQEMuLog::Error, "Error in DeleteLauncher 1 query: %s", errbuf);
safe_delete_array(query); safe_delete_array(query);
return; return;
} }
safe_delete_array(query); safe_delete_array(query);
if (!database.RunQuery(query, MakeAnyLenString(&query, if (!database.RunQuery(query, MakeAnyLenString(&query,
"DELETE FROM launcher_zones WHERE launcher='%s'", "DELETE FROM launcher_zones WHERE launcher='%s'",
namebuf), errbuf)) { namebuf), errbuf)) {
LogFile->write(EQEMuLog::Error, "Error in DeleteLauncher 2 query: %s", errbuf); LogFile->write(EQEMuLog::Error, "Error in DeleteLauncher 2 query: %s", errbuf);
safe_delete_array(query); safe_delete_array(query);
@ -182,18 +182,18 @@ bool EQLConfig::BootStaticZone(Const_char *short_name, uint16 port) {
//make sure the short name is valid. //make sure the short name is valid.
if(database.GetZoneID(short_name) == 0) if(database.GetZoneID(short_name) == 0)
return(false); return(false);
//database update //database update
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
char namebuf[128]; char namebuf[128];
database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64
namebuf[127] = '\0'; namebuf[127] = '\0';
char zonebuf[32]; char zonebuf[32];
database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16 database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16
zonebuf[31] = '\0'; zonebuf[31] = '\0';
if (!database.RunQuery(query, MakeAnyLenString(&query, if (!database.RunQuery(query, MakeAnyLenString(&query,
"INSERT INTO launcher_zones (launcher,zone,port) VALUES('%s', '%s', %d)", "INSERT INTO launcher_zones (launcher,zone,port) VALUES('%s', '%s', %d)",
namebuf, zonebuf, port), errbuf)) { namebuf, zonebuf, port), errbuf)) {
@ -202,19 +202,19 @@ bool EQLConfig::BootStaticZone(Const_char *short_name, uint16 port) {
return false; return false;
} }
safe_delete_array(query); safe_delete_array(query);
//update our internal state. //update our internal state.
LauncherZone lz; LauncherZone lz;
lz.name = short_name; lz.name = short_name;
lz.port = port; lz.port = port;
m_zones[lz.name] = lz; m_zones[lz.name] = lz;
//if the launcher is connected, update it. //if the launcher is connected, update it.
LauncherLink *ll = launcher_list.Get(m_name.c_str()); LauncherLink *ll = launcher_list.Get(m_name.c_str());
if(ll != NULL) { if(ll != NULL) {
ll->BootZone(short_name, port); ll->BootZone(short_name, port);
} }
return(true); return(true);
} }
@ -222,7 +222,7 @@ bool EQLConfig::ChangeStaticZone(Const_char *short_name, uint16 port) {
//make sure the short name is valid. //make sure the short name is valid.
if(database.GetZoneID(short_name) == 0) if(database.GetZoneID(short_name) == 0)
return(false); return(false);
//check internal state //check internal state
map<string, LauncherZone>::iterator res; map<string, LauncherZone>::iterator res;
res = m_zones.find(short_name); res = m_zones.find(short_name);
@ -231,19 +231,19 @@ bool EQLConfig::ChangeStaticZone(Const_char *short_name, uint16 port) {
LogFile->write(EQEMuLog::Error, "Update for unknown zone %s", short_name); LogFile->write(EQEMuLog::Error, "Update for unknown zone %s", short_name);
return(false); return(false);
} }
//database update //database update
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
char namebuf[128]; char namebuf[128];
database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64
namebuf[127] = '\0'; namebuf[127] = '\0';
char zonebuf[32]; char zonebuf[32];
database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16 database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16
zonebuf[31] = '\0'; zonebuf[31] = '\0';
if (!database.RunQuery(query, MakeAnyLenString(&query, if (!database.RunQuery(query, MakeAnyLenString(&query,
"UPDATE launcher_zones SET port=%d WHERE launcher='%s' AND zone='%s'", "UPDATE launcher_zones SET port=%d WHERE launcher='%s' AND zone='%s'",
port, namebuf, zonebuf), errbuf)) { port, namebuf, zonebuf), errbuf)) {
@ -252,17 +252,17 @@ bool EQLConfig::ChangeStaticZone(Const_char *short_name, uint16 port) {
return false; return false;
} }
safe_delete_array(query); safe_delete_array(query);
//update internal state //update internal state
res->second.port = port; res->second.port = port;
//if the launcher is connected, update it. //if the launcher is connected, update it.
LauncherLink *ll = launcher_list.Get(m_name.c_str()); LauncherLink *ll = launcher_list.Get(m_name.c_str());
if(ll != NULL) { if(ll != NULL) {
ll->RestartZone(short_name); ll->RestartZone(short_name);
} }
return(true); return(true);
} }
@ -275,47 +275,47 @@ bool EQLConfig::DeleteStaticZone(Const_char *short_name) {
LogFile->write(EQEMuLog::Error, "Update for unknown zone %s", short_name); LogFile->write(EQEMuLog::Error, "Update for unknown zone %s", short_name);
return(false); return(false);
} }
//database update //database update
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
char namebuf[128]; char namebuf[128];
database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64
namebuf[127] = '\0'; namebuf[127] = '\0';
char zonebuf[32]; char zonebuf[32];
database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16 database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16
zonebuf[31] = '\0'; zonebuf[31] = '\0';
if (!database.RunQuery(query, MakeAnyLenString(&query, if (!database.RunQuery(query, MakeAnyLenString(&query,
"DELETE FROM launcher_zones WHERE launcher='%s' AND zone='%s'", "DELETE FROM launcher_zones WHERE launcher='%s' AND zone='%s'",
namebuf, zonebuf), errbuf)) { namebuf, zonebuf), errbuf)) {
LogFile->write(EQEMuLog::Error, "Error in DeleteStaticZone query: %s", errbuf); LogFile->write(EQEMuLog::Error, "Error in DeleteStaticZone query: %s", errbuf);
safe_delete_array(query); safe_delete_array(query);
return false; return false;
} }
safe_delete_array(query); safe_delete_array(query);
//internal update. //internal update.
m_zones.erase(res); m_zones.erase(res);
//if the launcher is connected, update it. //if the launcher is connected, update it.
LauncherLink *ll = launcher_list.Get(m_name.c_str()); LauncherLink *ll = launcher_list.Get(m_name.c_str());
if(ll != NULL) { if(ll != NULL) {
ll->StopZone(short_name); ll->StopZone(short_name);
} }
return true; return true;
} }
bool EQLConfig::SetDynamicCount(int count) { bool EQLConfig::SetDynamicCount(int count) {
char errbuf[MYSQL_ERRMSG_SIZE]; char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0; char *query = 0;
char namebuf[128]; char namebuf[128];
database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64
namebuf[127] = '\0'; namebuf[127] = '\0';
if (!database.RunQuery(query, MakeAnyLenString(&query, if (!database.RunQuery(query, MakeAnyLenString(&query,
"UPDATE launcher SET dynamics=%d WHERE name='%s'", "UPDATE launcher SET dynamics=%d WHERE name='%s'",
count, namebuf), errbuf)) { count, namebuf), errbuf)) {
@ -324,16 +324,16 @@ bool EQLConfig::SetDynamicCount(int count) {
return false; return false;
} }
safe_delete_array(query); safe_delete_array(query);
//update in-memory version. //update in-memory version.
m_dynamics = count; m_dynamics = count;
//if the launcher is connected, update it. //if the launcher is connected, update it.
LauncherLink *ll = launcher_list.Get(m_name.c_str()); LauncherLink *ll = launcher_list.Get(m_name.c_str());
if(ll != NULL) { if(ll != NULL) {
ll->BootDynamics(count); ll->BootDynamics(count);
} }
return(false); return(false);
} }
@ -343,7 +343,7 @@ int EQLConfig::GetDynamicCount() const {
map<string,string> EQLConfig::GetZoneDetails(Const_char *zone_ref) { map<string,string> EQLConfig::GetZoneDetails(Const_char *zone_ref) {
map<string,string> res; map<string,string> res;
LauncherLink *ll = launcher_list.Get(m_name.c_str()); LauncherLink *ll = launcher_list.Get(m_name.c_str());
if(ll == NULL) { if(ll == NULL) {
res["name"] = zone_ref; res["name"] = zone_ref;
@ -353,7 +353,7 @@ map<string,string> EQLConfig::GetZoneDetails(Const_char *zone_ref) {
} else { } else {
ll->GetZoneDetails(zone_ref, res); ll->GetZoneDetails(zone_ref, res);
} }
return(res); return(res);
} }

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@ const int MaxSpellTypes = 16;
const int MaxHealRotationMembers = 6; const int MaxHealRotationMembers = 6;
const int MaxHealRotationTargets = 3; const int MaxHealRotationTargets = 3;
typedef enum BotStanceType { enum BotStanceType {
BotStancePassive, BotStancePassive,
BotStanceBalanced, BotStanceBalanced,
BotStanceEfficient, BotStanceEfficient,
@ -42,7 +42,7 @@ typedef enum BotStanceType {
BotStanceBurnAE BotStanceBurnAE
}; };
typedef enum SpellTypeIndex { enum SpellTypeIndex {
SpellType_NukeIndex, SpellType_NukeIndex,
SpellType_HealIndex, SpellType_HealIndex,
SpellType_RootIndex, SpellType_RootIndex,
@ -64,7 +64,7 @@ typedef enum SpellTypeIndex {
class Bot : public NPC { class Bot : public NPC {
public: public:
// Class enums // Class enums
typedef enum BotfocusType { //focus types enum BotfocusType { //focus types
BotfocusSpellHaste = 1, BotfocusSpellHaste = 1,
BotfocusSpellDuration, BotfocusSpellDuration,
BotfocusRange, BotfocusRange,
@ -97,18 +97,18 @@ public:
BotfocusAdditionalHeal, BotfocusAdditionalHeal,
}; };
typedef enum BotTradeType { // types of trades a bot can do enum BotTradeType { // types of trades a bot can do
BotTradeClientNormal, BotTradeClientNormal,
BotTradeClientNoDropNoTrade BotTradeClientNoDropNoTrade
}; };
typedef enum BotRoleType { enum BotRoleType {
BotRoleMainAssist, BotRoleMainAssist,
BotRoleGroupHealer, BotRoleGroupHealer,
BotRoleRaidHealer BotRoleRaidHealer
}; };
typedef enum EqExpansions { enum EqExpansions {
ExpansionNone, ExpansionNone,
ExpansionEQ, ExpansionEQ,
ExpansionRoK, ExpansionRoK,
@ -143,7 +143,7 @@ public:
virtual bool HasGroup() { return (GetGroup() ? true : false); } virtual bool HasGroup() { return (GetGroup() ? true : false); }
virtual Raid* GetRaid() { return entity_list.GetRaidByMob(this); } virtual Raid* GetRaid() { return entity_list.GetRaidByMob(this); }
virtual Group* GetGroup() { return entity_list.GetGroupByMob(this); } virtual Group* GetGroup() { return entity_list.GetGroupByMob(this); }
// Common, but informal "interfaces" with Client object // Common, but informal "interfaces" with Client object
uint32 CharacterID() { return GetBotID(); } // Just returns the Bot Id uint32 CharacterID() { return GetBotID(); } // Just returns the Bot Id
inline bool IsInAGuild() const { return (_guildId != GUILD_NONE && _guildId != 0); } inline bool IsInAGuild() const { return (_guildId != GUILD_NONE && _guildId != 0); }
@ -237,7 +237,7 @@ public:
bool RemoveHealRotationTarget( Mob* target ); bool RemoveHealRotationTarget( Mob* target );
bool RemoveHealRotationTarget( int index); bool RemoveHealRotationTarget( int index);
void NotifyNextHealRotationMember( bool notifyNow = false ); void NotifyNextHealRotationMember( bool notifyNow = false );
void ClearHealRotationLeader() { _healRotationLeader = NULL; } void ClearHealRotationLeader() { _healRotationLeader = 0; }
void ClearHealRotationMembers(); void ClearHealRotationMembers();
void ClearHealRotationTargets(); void ClearHealRotationTargets();
inline virtual int16 GetMaxStat(); inline virtual int16 GetMaxStat();
@ -285,7 +285,7 @@ public:
int32 CalcEnduranceRegen(); //Calculates endurance regen used in DoEnduranceRegen() int32 CalcEnduranceRegen(); //Calculates endurance regen used in DoEnduranceRegen()
int32 GetEndurance() const {return cur_end;} //This gets our current endurance int32 GetEndurance() const {return cur_end;} //This gets our current endurance
int32 GetMaxEndurance() const {return max_end;} //This gets our endurance from the last CalcMaxEndurance() call int32 GetMaxEndurance() const {return max_end;} //This gets our endurance from the last CalcMaxEndurance() call
int32 CalcEnduranceRegenCap(); int32 CalcEnduranceRegenCap();
inline uint8 GetEndurancePercent() { return (uint8)((float)cur_end / (float)max_end * 100.0f); } inline uint8 GetEndurancePercent() { return (uint8)((float)cur_end / (float)max_end * 100.0f); }
void SetEndurance(int32 newEnd); //This sets the current endurance to the new value void SetEndurance(int32 newEnd); //This sets the current endurance to the new value
void DoEnduranceRegen(); //This Regenerates endurance void DoEnduranceRegen(); //This Regenerates endurance
@ -516,7 +516,7 @@ public:
inline virtual int16 GetPercMod() const { return itembonuses.percussionMod; } inline virtual int16 GetPercMod() const { return itembonuses.percussionMod; }
inline virtual int16 GetStringMod() const { return itembonuses.stringedMod; } inline virtual int16 GetStringMod() const { return itembonuses.stringedMod; }
inline virtual int16 GetWindMod() const { return itembonuses.windMod; } inline virtual int16 GetWindMod() const { return itembonuses.windMod; }
inline virtual int16 GetDelayDeath() const { return aabonuses.DelayDeath + spellbonuses.DelayDeath + itembonuses.DelayDeath; } inline virtual int16 GetDelayDeath() const { return aabonuses.DelayDeath + spellbonuses.DelayDeath + itembonuses.DelayDeath; }
inline InspectMessage_Struct& GetInspectMessage() { return _botInspectMessage; } inline InspectMessage_Struct& GetInspectMessage() { return _botInspectMessage; }

File diff suppressed because it is too large Load Diff

View File

@ -1812,7 +1812,7 @@ void Merc::AI_Process() {
//now off hand //now off hand
if(GetTarget() && attack_dw_timer.Check() && CanThisClassDualWield()) { if(GetTarget() && attack_dw_timer.Check() && CanThisClassDualWield()) {
int weapontype = NULL; int weapontype = 0; // No weapon type
bool bIsFist = true; bool bIsFist = true;
if(bIsFist || ((weapontype != ItemType2HS) && (weapontype != ItemType2HPierce) && (weapontype != ItemType2HB))) { if(bIsFist || ((weapontype != ItemType2HS) && (weapontype != ItemType2HPierce) && (weapontype != ItemType2HB))) {
@ -2362,8 +2362,8 @@ bool Merc::AICastSpell(int8 iChance, int32 iSpellTypes) {
if(!castedSpell && tar->GetPet()) { if(!castedSpell && tar->GetPet()) {
//don't cast group spells on pets //don't cast group spells on pets
if(IsGroupSpell(selectedMercSpell.spellid) if(IsGroupSpell(selectedMercSpell.spellid)
|| spells[selectedMercSpell.spellid].targettype == ST_Group || spells[selectedMercSpell.spellid].targettype == ST_Group
|| spells[selectedMercSpell.spellid].targettype == ST_GroupTeleport ) { || spells[selectedMercSpell.spellid].targettype == ST_GroupTeleport ) {
continue; continue;
} }
@ -5103,7 +5103,7 @@ bool Merc::Unsuspend(bool setMaxStats) {
uint32 suspendedTime = 0; uint32 suspendedTime = 0;
SetSuspended(false); SetSuspended(false);
mercOwner->GetMercInfo().mercid = GetMercID(); mercOwner->GetMercInfo().mercid = GetMercID();
mercOwner->GetMercInfo().IsSuspended = false; mercOwner->GetMercInfo().IsSuspended = false;
mercOwner->GetMercInfo().SuspendedTime = 0; mercOwner->GetMercInfo().SuspendedTime = 0;