mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-10 06:40:26 +00:00
Remove trailing whitespace
This commit is contained in:
+136
-136
@@ -4,13 +4,13 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
|
||||
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
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
@@ -47,7 +47,7 @@ CREATE TABLE spawn_events (
|
||||
zone VARCHAR(16) NOT nullptr,
|
||||
cond_id MEDIUMINT UNSIGNED NOT nullptr,
|
||||
name VARCHAR(255) NOT nullptr DEFAULT '',
|
||||
|
||||
|
||||
#timing information
|
||||
period INT UNSIGNED NOT nullptr,
|
||||
next_minute TINYINT UNSIGNED NOT nullptr,
|
||||
@@ -56,7 +56,7 @@ CREATE TABLE spawn_events (
|
||||
next_month TINYINT UNSIGNED NOT nullptr,
|
||||
next_year INT UNSIGNED NOT nullptr,
|
||||
enabled TINYINT NOT nullptr DEFAULT '1',
|
||||
|
||||
|
||||
#action:
|
||||
action TINYINT UNSIGNED NOT nullptr DEFAULT '0',
|
||||
argument MEDIUMINT NOT nullptr DEFAULT '0'
|
||||
@@ -64,8 +64,8 @@ CREATE TABLE spawn_events (
|
||||
|
||||
*/
|
||||
|
||||
Spawn2::Spawn2(uint32 in_spawn2_id, uint32 spawngroup_id,
|
||||
float in_x, float in_y, float in_z, float in_heading,
|
||||
Spawn2::Spawn2(uint32 in_spawn2_id, uint32 spawngroup_id,
|
||||
float in_x, float in_y, float in_z, float in_heading,
|
||||
uint32 respawn, uint32 variance, uint32 timeleft, uint32 grid,
|
||||
uint16 in_cond_id, int16 in_min_value, bool in_enabled, EmuAppearance anim)
|
||||
: timer(100000), killcount(0)
|
||||
@@ -92,7 +92,7 @@ Spawn2::Spawn2(uint32 in_spawn2_id, uint32 spawngroup_id,
|
||||
//we have a timeleft from the DB or something
|
||||
timer.Start(timeleft);
|
||||
} else {
|
||||
//no timeleft at all, reset to
|
||||
//no timeleft at all, reset to
|
||||
timer.Start(resetTimer());
|
||||
timer.Trigger();
|
||||
}
|
||||
@@ -105,35 +105,35 @@ Spawn2::~Spawn2()
|
||||
uint32 Spawn2::resetTimer()
|
||||
{
|
||||
uint32 rspawn = respawn_ * 1000;
|
||||
|
||||
|
||||
if (variance_ != 0) {
|
||||
int var_over_2 = (variance_ * 1000) / 2;
|
||||
rspawn = MakeRandomInt(rspawn - var_over_2, rspawn + var_over_2);
|
||||
|
||||
|
||||
//put a lower bound on it, not a lot of difference below 100, so set that as the bound.
|
||||
if(rspawn < 100)
|
||||
rspawn = 100;
|
||||
}
|
||||
|
||||
|
||||
return (rspawn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint32 Spawn2::despawnTimer(uint32 despawn_timer)
|
||||
{
|
||||
uint32 dspawn = despawn_timer * 1000;
|
||||
|
||||
|
||||
if (variance_ != 0) {
|
||||
int var_over_2 = (variance_ * 1000) / 2;
|
||||
dspawn = MakeRandomInt(dspawn - var_over_2, dspawn + var_over_2);
|
||||
|
||||
|
||||
//put a lower bound on it, not a lot of difference below 100, so set that as the bound.
|
||||
if(dspawn < 100)
|
||||
dspawn = 100;
|
||||
}
|
||||
|
||||
|
||||
return (dspawn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool Spawn2::Process() {
|
||||
@@ -152,18 +152,18 @@ bool Spawn2::Process() {
|
||||
|
||||
if (timer.Check()) {
|
||||
timer.Disable();
|
||||
|
||||
|
||||
_log(SPAWNS__MAIN, "Spawn2 %d: Timer has triggered", spawn2_id);
|
||||
|
||||
|
||||
//first check our spawn condition, if this isnt active
|
||||
//then we reset the timer and try again next time.
|
||||
if(condition_id != SC_AlwaysEnabled
|
||||
if(condition_id != SC_AlwaysEnabled
|
||||
&& !zone->spawn_conditions.Check(condition_id, condition_min_value)) {
|
||||
_log(SPAWNS__CONDITIONS, "Spawn2 %d: spawning prevented by spawn condition %d", spawn2_id, condition_id);
|
||||
Reset();
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
if (sg == nullptr) {
|
||||
database.LoadSpawnGroupsByID(spawngroup_id_,&zone->spawn_group_list);
|
||||
sg = zone->spawn_group_list.GetSpawnGroup(spawngroup_id_);
|
||||
@@ -173,7 +173,7 @@ bool Spawn2::Process() {
|
||||
_log(SPAWNS__MAIN, "Spawn2 %d: Unable to locate spawn group %d. Disabling.", spawn2_id, spawngroup_id_);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//have the spawn group pick an NPC for us
|
||||
uint32 npcid = sg->GetNPCType();
|
||||
if (npcid == 0) {
|
||||
@@ -181,7 +181,7 @@ bool Spawn2::Process() {
|
||||
Reset(); //try again later (why?)
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
//try to find our NPC type.
|
||||
const NPCType* tmp = database.GetNPCType(npcid);
|
||||
if (tmp == nullptr) {
|
||||
@@ -192,7 +192,7 @@ bool Spawn2::Process() {
|
||||
|
||||
if(tmp->unique_spawn_by_name)
|
||||
{
|
||||
if(!entity_list.LimitCheckName(tmp->name))
|
||||
if(!entity_list.LimitCheckName(tmp->name))
|
||||
{
|
||||
_log(SPAWNS__MAIN, "Spawn2 %d: Spawn group %d yeilded NPC type %d, which is unique and one already exists.", spawn2_id, spawngroup_id_, npcid);
|
||||
timer.Start(5000); //try again in five seconds.
|
||||
@@ -216,7 +216,7 @@ bool Spawn2::Process() {
|
||||
|
||||
if(spawn2_id)
|
||||
database.UpdateSpawn2Timeleft(spawn2_id, zone->GetInstanceID(), 0);
|
||||
|
||||
|
||||
currentnpcid = npcid;
|
||||
NPC* npc = new NPC(tmp, this, x, y, z, heading, FlyMode3);
|
||||
|
||||
@@ -244,10 +244,10 @@ bool Spawn2::Process() {
|
||||
|
||||
void Spawn2::Disable()
|
||||
{
|
||||
if(npcthis)
|
||||
if(npcthis)
|
||||
{
|
||||
npcthis->Depop();
|
||||
}
|
||||
}
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
@@ -357,20 +357,20 @@ bool ZoneDatabase::PopulateZoneSpawnList(uint32 zoneid, LinkedList<Spawn2*> &spa
|
||||
char* query = 0;
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
|
||||
|
||||
const char *zone_name = database.GetZoneName(zoneid);
|
||||
|
||||
MakeAnyLenString(&query, "SELECT id, spawngroupID, x, y, z, heading, respawntime, variance, pathgrid, _condition, cond_value, enabled, animation FROM spawn2 WHERE zone='%s' AND version=%u", zone_name, version);
|
||||
MakeAnyLenString(&query, "SELECT id, spawngroupID, x, y, z, heading, respawntime, variance, pathgrid, _condition, cond_value, enabled, animation FROM spawn2 WHERE zone='%s' AND version=%u", zone_name, version);
|
||||
if (RunQuery(query, strlen(query), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
while((row = mysql_fetch_row(result)))
|
||||
{
|
||||
Spawn2* newSpawn = 0;
|
||||
|
||||
|
||||
bool perl_enabled = atoi(row[11]) == 1 ? true : false;
|
||||
uint32 spawnLeft = (GetSpawnTimeLeft(atoi(row[0]), zone->GetInstanceID()) * 1000);
|
||||
newSpawn = new Spawn2(atoi(row[0]), atoi(row[1]), atof(row[2]), atof(row[3]), atof(row[4]), atof(row[5]), atoi(row[6]), atoi(row[7]), spawnLeft, atoi(row[8]), atoi(row[9]), atoi(row[10]), perl_enabled, (EmuAppearance)atoi(row[12]));
|
||||
newSpawn = new Spawn2(atoi(row[0]), atoi(row[1]), atof(row[2]), atof(row[3]), atof(row[4]), atof(row[5]), atoi(row[6]), atoi(row[7]), spawnLeft, atoi(row[8]), atoi(row[9]), atoi(row[10]), perl_enabled, (EmuAppearance)atoi(row[12]));
|
||||
spawn2_list.Insert( newSpawn );
|
||||
}
|
||||
mysql_free_result(result);
|
||||
@@ -381,7 +381,7 @@ bool ZoneDatabase::PopulateZoneSpawnList(uint32 zoneid, LinkedList<Spawn2*> &spa
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -417,14 +417,14 @@ bool ZoneDatabase::CreateSpawn2(Client *c, uint32 spawngroup, const char* zone,
|
||||
|
||||
char *query = 0;
|
||||
uint32 affected_rows = 0;
|
||||
|
||||
|
||||
// if(GetInverseXY()==1) {
|
||||
// float temp=x;
|
||||
// x=y;
|
||||
// y=temp;
|
||||
// }
|
||||
if (RunQuery(query, MakeAnyLenString(&query,
|
||||
"INSERT INTO spawn2 (spawngroupID,zone,x,y,z,heading,respawntime,variance,_condition,cond_value) Values (%i, '%s', %f, %f, %f, %f, %i, %i, %u, %i)",
|
||||
if (RunQuery(query, MakeAnyLenString(&query,
|
||||
"INSERT INTO spawn2 (spawngroupID,zone,x,y,z,heading,respawntime,variance,_condition,cond_value) Values (%i, '%s', %f, %f, %f, %f, %i, %i, %u, %i)",
|
||||
spawngroup, zone, x, y, z, heading, respawn, variance, condition, cond_value
|
||||
), errbuf, 0, &affected_rows)) {
|
||||
safe_delete_array(query);
|
||||
@@ -441,7 +441,7 @@ bool ZoneDatabase::CreateSpawn2(Client *c, uint32 spawngroup, const char* zone,
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -508,16 +508,16 @@ void Zone::Despawn(uint32 spawn2ID) {
|
||||
void Spawn2::SpawnConditionChanged(const SpawnCondition &c, int16 old_value) {
|
||||
if(GetSpawnCondition() != c.condition_id)
|
||||
return;
|
||||
|
||||
|
||||
_log(SPAWNS__CONDITIONS, "Spawn2 %d: Notified that our spawn condition %d has changed from %d to %d. Our min value is %d.", spawn2_id, c.condition_id, old_value, c.value, condition_min_value);
|
||||
|
||||
|
||||
bool old_state = (old_value >= condition_min_value);
|
||||
bool new_state = (c.value >= condition_min_value);
|
||||
if(old_state == new_state) {
|
||||
_log(SPAWNS__CONDITIONS, "Spawn2 %d: Our threshold for this condition was not crossed. Doing nothing.", spawn2_id);
|
||||
return; //no change
|
||||
}
|
||||
|
||||
|
||||
switch(c.on_change) {
|
||||
case SpawnCondition::DoNothing:
|
||||
//that was easy.
|
||||
@@ -549,7 +549,7 @@ void Spawn2::SpawnConditionChanged(const SpawnCondition &c, int16 old_value) {
|
||||
|
||||
void Zone::SpawnConditionChanged(const SpawnCondition &c, int16 old_value) {
|
||||
_log(SPAWNS__CONDITIONS, "Zone notified that spawn condition %d has changed from %d to %d. Notifying all spawn points.", c.condition_id, old_value, c.value);
|
||||
|
||||
|
||||
LinkedListIterator<Spawn2*> iterator(spawn2_list);
|
||||
|
||||
iterator.Reset();
|
||||
@@ -586,28 +586,28 @@ SpawnConditionManager::SpawnConditionManager()
|
||||
void SpawnConditionManager::Process() {
|
||||
if(spawn_events.empty())
|
||||
return;
|
||||
|
||||
|
||||
if(minute_timer.Check()) {
|
||||
//check each spawn event.
|
||||
|
||||
|
||||
//get our current time
|
||||
TimeOfDay_Struct tod;
|
||||
zone->zone_time.getEQTimeOfDay(&tod);
|
||||
|
||||
|
||||
//see if time is past our nearest event.
|
||||
if(EQTime::IsTimeBefore(&next_event, &tod))
|
||||
return;
|
||||
|
||||
//at least one event should get triggered,
|
||||
|
||||
//at least one event should get triggered,
|
||||
vector<SpawnEvent>::iterator cur,end;
|
||||
cur = spawn_events.begin();
|
||||
end = spawn_events.end();
|
||||
for(; cur != end; cur++) {
|
||||
SpawnEvent &cevent = *cur;
|
||||
|
||||
|
||||
if(!cevent.enabled)
|
||||
continue;
|
||||
|
||||
|
||||
if(EQTime::IsTimeBefore(&tod, &cevent.next)) {
|
||||
//this event has been triggered.
|
||||
//execute the event
|
||||
@@ -637,11 +637,11 @@ void SpawnConditionManager::ExecEvent(SpawnEvent &event, bool send_update) {
|
||||
_log(SPAWNS__CONDITIONS, "Event %d: Unable to find condition %d to execute on.", event.id, event.condition_id);
|
||||
return; //unable to find the spawn condition to operate on
|
||||
}
|
||||
|
||||
|
||||
SpawnCondition &cond = condi->second;
|
||||
|
||||
|
||||
int16 new_value = cond.value;
|
||||
|
||||
|
||||
//we have our event and our condition, do our stuff.
|
||||
switch(event.action) {
|
||||
case SpawnEvent::ActionSet:
|
||||
@@ -668,7 +668,7 @@ void SpawnConditionManager::ExecEvent(SpawnEvent &event, bool send_update) {
|
||||
_log(SPAWNS__CONDITIONS, "Event %d: Invalid event action type %d", event.id, event.action);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//now set the condition to the new value
|
||||
if(send_update) //full blown update
|
||||
SetCondition(zone->GetShortName(), zone->GetInstanceID(), cond.condition_id, new_value);
|
||||
@@ -680,14 +680,14 @@ void SpawnConditionManager::UpdateDBEvent(SpawnEvent &event) {
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char* query = 0;
|
||||
int len;
|
||||
|
||||
|
||||
SpawnCondition cond;
|
||||
len = MakeAnyLenString(&query,
|
||||
len = MakeAnyLenString(&query,
|
||||
"UPDATE spawn_events SET "
|
||||
"next_minute=%d, next_hour=%d, next_day=%d, next_month=%d, "
|
||||
"next_year=%d, enabled=%d "
|
||||
"WHERE id=%d",
|
||||
event.next.minute, event.next.hour, event.next.day, event.next.month,
|
||||
event.next.minute, event.next.hour, event.next.day, event.next.month,
|
||||
event.next.year, event.enabled?1:0, event.id
|
||||
);
|
||||
if(!database.RunQuery(query, len, errbuf)) {
|
||||
@@ -700,9 +700,9 @@ void SpawnConditionManager::UpdateDBCondition(const char* zone_name, uint32 inst
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char* query = 0;
|
||||
int len;
|
||||
|
||||
|
||||
SpawnCondition cond;
|
||||
len = MakeAnyLenString(&query,
|
||||
len = MakeAnyLenString(&query,
|
||||
"REPLACE INTO spawn_condition_values (id, value, zone, instance_id) VALUES(%u, %u, '%s', %u)",
|
||||
cond_id, value, zone_name, instance_id
|
||||
);
|
||||
@@ -718,10 +718,10 @@ bool SpawnConditionManager::LoadDBEvent(uint32 event_id, SpawnEvent &event, stri
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
int len;
|
||||
|
||||
|
||||
bool ret = false;
|
||||
|
||||
len = MakeAnyLenString(&query,
|
||||
|
||||
len = MakeAnyLenString(&query,
|
||||
"SELECT id,cond_id,period,next_minute,next_hour,next_day,next_month,next_year,enabled,action,argument,zone "
|
||||
"FROM spawn_events WHERE id=%d", event_id);
|
||||
if (database.RunQuery(query, len, errbuf, &result)) {
|
||||
@@ -730,23 +730,23 @@ bool SpawnConditionManager::LoadDBEvent(uint32 event_id, SpawnEvent &event, stri
|
||||
event.id = atoi(row[0]);
|
||||
event.condition_id = atoi(row[1]);
|
||||
event.period = atoi(row[2]);
|
||||
|
||||
|
||||
event.next.minute = atoi(row[3]);
|
||||
event.next.hour = atoi(row[4]);
|
||||
event.next.day = atoi(row[5]);
|
||||
event.next.month = atoi(row[6]);
|
||||
event.next.year = atoi(row[7]);
|
||||
|
||||
|
||||
event.enabled = atoi(row[8])==0?false:true;
|
||||
event.action = (SpawnEvent::Action) atoi(row[9]);
|
||||
event.argument = atoi(row[10]);
|
||||
zone_name = row[11];
|
||||
|
||||
string t;
|
||||
EQTime::ToString(&event.next, t);
|
||||
EQTime::ToString(&event.next, t);
|
||||
_log(SPAWNS__CONDITIONS, "Loaded %s spawn event %d on condition %d with period %d, action %d, argument %d. Will trigger at %s",
|
||||
event.enabled?"enabled":"disabled", event.id, event.condition_id, event.period, event.action, event.argument, t.c_str());
|
||||
|
||||
|
||||
ret = true;
|
||||
}
|
||||
mysql_free_result(result);
|
||||
@@ -757,18 +757,18 @@ bool SpawnConditionManager::LoadDBEvent(uint32 event_id, SpawnEvent &event, stri
|
||||
return(ret);
|
||||
}
|
||||
|
||||
bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 instance_id)
|
||||
bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 instance_id)
|
||||
{
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char* query = 0;
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
int len;
|
||||
|
||||
|
||||
//clear out old stuff..
|
||||
spawn_conditions.clear();
|
||||
|
||||
//load spawn conditions
|
||||
|
||||
//load spawn conditions
|
||||
SpawnCondition cond;
|
||||
len = MakeAnyLenString(&query, "SELECT id, onchange, value FROM spawn_conditions WHERE zone='%s'", zone_name);
|
||||
if (database.RunQuery(query, len, errbuf, &result)) {
|
||||
@@ -778,7 +778,7 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
|
||||
cond.value = atoi(row[2]);
|
||||
cond.on_change = (SpawnCondition::OnChange) atoi(row[1]);
|
||||
spawn_conditions[cond.condition_id] = cond;
|
||||
|
||||
|
||||
_log(SPAWNS__CONDITIONS, "Loaded spawn condition %d with value %d and on_change %d", cond.condition_id, cond.value, cond.on_change);
|
||||
}
|
||||
mysql_free_result(result);
|
||||
@@ -792,8 +792,8 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
|
||||
len = MakeAnyLenString(&query, "SELECT id, value FROM spawn_condition_values WHERE zone='%s' and instance_id=%u", zone_name, instance_id);
|
||||
if (database.RunQuery(query, len, errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
while((row = mysql_fetch_row(result)))
|
||||
{
|
||||
while((row = mysql_fetch_row(result)))
|
||||
{
|
||||
std::map<uint16, SpawnCondition>::iterator iter = spawn_conditions.find(atoi(row[0]));
|
||||
if(iter != spawn_conditions.end())
|
||||
{
|
||||
@@ -801,18 +801,18 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
|
||||
}
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
LogFile->write(EQEMuLog::Error, "Error in LoadSpawnConditions query '%s': %s", query, errbuf);
|
||||
safe_delete_array(query);
|
||||
spawn_conditions.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//load spawn events
|
||||
SpawnEvent event;
|
||||
len = MakeAnyLenString(&query,
|
||||
len = MakeAnyLenString(&query,
|
||||
"SELECT id,cond_id,period,next_minute,next_hour,next_day,next_month,next_year,enabled,action,argument "
|
||||
"FROM spawn_events WHERE zone='%s'", zone_name);
|
||||
if (database.RunQuery(query, len, errbuf, &result)) {
|
||||
@@ -825,18 +825,18 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
|
||||
LogFile->write(EQEMuLog::Error, "Refusing to load spawn event #%d because it has a period of 0\n", event.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
event.next.minute = atoi(row[3]);
|
||||
event.next.hour = atoi(row[4]);
|
||||
event.next.day = atoi(row[5]);
|
||||
event.next.month = atoi(row[6]);
|
||||
event.next.year = atoi(row[7]);
|
||||
|
||||
|
||||
event.enabled = atoi(row[8])==0?false:true;
|
||||
event.action = (SpawnEvent::Action) atoi(row[9]);
|
||||
event.argument = atoi(row[10]);
|
||||
spawn_events.push_back(event);
|
||||
|
||||
|
||||
_log(SPAWNS__CONDITIONS, "Loaded %s spawn event %d on condition %d with period %d, action %d, argument %d",
|
||||
event.enabled?"enabled":"disabled", event.id, event.condition_id, event.period, event.action, event.argument);
|
||||
}
|
||||
@@ -846,10 +846,10 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
|
||||
safe_delete_array(query);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//now we need to catch up on events that happened while we were away
|
||||
//and use them to alter just the condition variables.
|
||||
|
||||
|
||||
//each spawn2 will then use its correct condition value when
|
||||
//it decides what to do. This essentially forces a 'depop' action
|
||||
//on spawn points which are turned off, and a 'repop' action on
|
||||
@@ -858,17 +858,17 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
|
||||
//get our current time
|
||||
TimeOfDay_Struct tod;
|
||||
zone->zone_time.getEQTimeOfDay(&tod);
|
||||
|
||||
|
||||
vector<SpawnEvent>::iterator cur,end;
|
||||
cur = spawn_events.begin();
|
||||
end = spawn_events.end();
|
||||
bool ran;
|
||||
for(; cur != end; cur++) {
|
||||
SpawnEvent &cevent = *cur;
|
||||
|
||||
|
||||
if(!cevent.enabled)
|
||||
continue;
|
||||
|
||||
|
||||
//watch for special case of all 0s, which means to reset next to now
|
||||
if(cevent.next.year == 0 && cevent.next.month == 0 && cevent.next.day == 0 && cevent.next.hour == 0 && cevent.next.minute == 0) {
|
||||
_log(SPAWNS__CONDITIONS, "Initial next trigger time set for spawn event %d", cevent.id);
|
||||
@@ -879,7 +879,7 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
|
||||
UpdateDBEvent(cevent);
|
||||
continue; //were done with this event.
|
||||
}
|
||||
|
||||
|
||||
ran = false;
|
||||
while(EQTime::IsTimeBefore(&tod, &cevent.next)) {
|
||||
_log(SPAWNS__CONDITIONS, "Catch up triggering on event %d", cevent.id);
|
||||
@@ -896,27 +896,27 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
|
||||
UpdateDBEvent(cevent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//now our event timers are all up to date, find our closest event.
|
||||
FindNearestEvent();
|
||||
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void SpawnConditionManager::FindNearestEvent() {
|
||||
//set a huge year which should never get reached normally
|
||||
next_event.year = 0xFFFFFF;
|
||||
|
||||
|
||||
vector<SpawnEvent>::iterator cur,end;
|
||||
cur = spawn_events.begin();
|
||||
end = spawn_events.end();
|
||||
int next_id = -1;
|
||||
for(; cur != end; cur++) {
|
||||
SpawnEvent &cevent = *cur;
|
||||
|
||||
|
||||
if(!cevent.enabled)
|
||||
continue;
|
||||
|
||||
|
||||
//see if this event is before our last nearest
|
||||
if(EQTime::IsTimeBefore(&next_event, &cevent.next)) {
|
||||
memcpy(&next_event, &cevent.next, sizeof(next_event));
|
||||
@@ -929,7 +929,7 @@ void SpawnConditionManager::FindNearestEvent() {
|
||||
_log(SPAWNS__CONDITIONS, "Next event determined to be event %d", next_id);
|
||||
}
|
||||
|
||||
void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance_id, uint16 condition_id, int16 new_value, bool world_update)
|
||||
void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance_id, uint16 condition_id, int16 new_value, bool world_update)
|
||||
{
|
||||
if(world_update) {
|
||||
//this is an update coming from another zone, they
|
||||
@@ -941,24 +941,24 @@ void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance
|
||||
_log(SPAWNS__CONDITIONS, "Condition update received from world for %d, but we do not have that conditon.", condition_id);
|
||||
return; //unable to find the spawn condition
|
||||
}
|
||||
|
||||
|
||||
SpawnCondition &cond = condi->second;
|
||||
|
||||
|
||||
if(cond.value == new_value) {
|
||||
_log(SPAWNS__CONDITIONS, "Condition update received from world for %d with value %d, which is what we already have.", condition_id, new_value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int16 old_value = cond.value;
|
||||
|
||||
|
||||
//set our local value
|
||||
cond.value = new_value;
|
||||
|
||||
|
||||
_log(SPAWNS__CONDITIONS, "Condition update received from world for %d with value %d", condition_id, new_value);
|
||||
|
||||
|
||||
//now we have to test each spawn point to see if it changed.
|
||||
zone->SpawnConditionChanged(cond, old_value);
|
||||
} else if(!strcasecmp(zone_short, zone->GetShortName()) && instance_id == zone->GetInstanceID())
|
||||
} else if(!strcasecmp(zone_short, zone->GetShortName()) && instance_id == zone->GetInstanceID())
|
||||
{
|
||||
//this is a local spawn condition, we need to update the DB,
|
||||
//our memory, then notify spawn points of the change.
|
||||
@@ -968,43 +968,43 @@ void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance
|
||||
_log(SPAWNS__CONDITIONS, "Local Condition update requested for %d, but we do not have that conditon.", condition_id);
|
||||
return; //unable to find the spawn condition
|
||||
}
|
||||
|
||||
|
||||
SpawnCondition &cond = condi->second;
|
||||
|
||||
|
||||
if(cond.value == new_value) {
|
||||
_log(SPAWNS__CONDITIONS, "Local Condition update requested for %d with value %d, which is what we already have.", condition_id, new_value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int16 old_value = cond.value;
|
||||
|
||||
|
||||
//set our local value
|
||||
cond.value = new_value;
|
||||
//save it in the DB too
|
||||
UpdateDBCondition(zone_short, instance_id, condition_id, new_value);
|
||||
|
||||
|
||||
_log(SPAWNS__CONDITIONS, "Local Condition update requested for %d with value %d", condition_id, new_value);
|
||||
|
||||
|
||||
//now we have to test each spawn point to see if it changed.
|
||||
zone->SpawnConditionChanged(cond, old_value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//this is a remote spawn condition, update the DB and send
|
||||
//an update packet to the zone if its up
|
||||
|
||||
|
||||
_log(SPAWNS__CONDITIONS, "Remote spawn condition %d set to %d. Updating DB and notifying world.", condition_id, new_value);
|
||||
|
||||
|
||||
UpdateDBCondition(zone_short, instance_id, condition_id, new_value);
|
||||
|
||||
|
||||
ServerPacket* pack = new ServerPacket(ServerOP_SpawnCondition, sizeof(ServerSpawnCondition_Struct));
|
||||
ServerSpawnCondition_Struct* ssc = (ServerSpawnCondition_Struct*)pack->pBuffer;
|
||||
|
||||
|
||||
ssc->zoneID = database.GetZoneID(zone_short);
|
||||
ssc->instanceID = instance_id;
|
||||
ssc->condition_id = condition_id;
|
||||
ssc->value = new_value;
|
||||
|
||||
|
||||
worldserver.SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
}
|
||||
@@ -1012,16 +1012,16 @@ void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance
|
||||
|
||||
void SpawnConditionManager::ReloadEvent(uint32 event_id) {
|
||||
string zone_short_name;
|
||||
|
||||
|
||||
_log(SPAWNS__CONDITIONS, "Requested to reload event %d from the database.", event_id);
|
||||
|
||||
|
||||
//first look for the event in our local event list
|
||||
vector<SpawnEvent>::iterator cur,end;
|
||||
cur = spawn_events.begin();
|
||||
end = spawn_events.end();
|
||||
for(; cur != end; cur++) {
|
||||
SpawnEvent &cevent = *cur;
|
||||
|
||||
|
||||
if(cevent.id == event_id) {
|
||||
//load the event into the old event slot
|
||||
if(!LoadDBEvent(event_id, cevent, zone_short_name)) {
|
||||
@@ -1034,7 +1034,7 @@ void SpawnConditionManager::ReloadEvent(uint32 event_id) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if we get here, it is a new event...
|
||||
SpawnEvent e;
|
||||
if(!LoadDBEvent(event_id, e, zone_short_name)) {
|
||||
@@ -1042,29 +1042,29 @@ void SpawnConditionManager::ReloadEvent(uint32 event_id) {
|
||||
_log(SPAWNS__CONDITIONS, "Failed to reload event %d from the database.", event_id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//we might want to check the next timer like we do on
|
||||
//regular load events, but we are assuming this is a new event
|
||||
//and anyways, this will get handled (albeit not optimally)
|
||||
//naturally by the event handling code.
|
||||
|
||||
|
||||
spawn_events.push_back(e);
|
||||
|
||||
|
||||
//sync up our nearest event
|
||||
FindNearestEvent();
|
||||
}
|
||||
|
||||
void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool reset_base) {
|
||||
|
||||
|
||||
_log(SPAWNS__CONDITIONS, "Request to %s spawn event %d %sresetting trigger time", enabled?"enable":"disable", event_id, reset_base?"":"without ");
|
||||
|
||||
|
||||
//first look for the event in our local event list
|
||||
vector<SpawnEvent>::iterator cur,end;
|
||||
cur = spawn_events.begin();
|
||||
end = spawn_events.end();
|
||||
for(; cur != end; cur++) {
|
||||
SpawnEvent &cevent = *cur;
|
||||
|
||||
|
||||
if(cevent.id == event_id) {
|
||||
//make sure were actually changing something
|
||||
if(cevent.enabled != enabled || reset_base) {
|
||||
@@ -1078,10 +1078,10 @@ void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool rese
|
||||
} else {
|
||||
_log(SPAWNS__CONDITIONS, "Spawn event %d located in this zone. State changed.", event_id);
|
||||
}
|
||||
|
||||
|
||||
//save the event in the DB
|
||||
UpdateDBEvent(cevent);
|
||||
|
||||
|
||||
//sync up our nearest event
|
||||
FindNearestEvent();
|
||||
} else {
|
||||
@@ -1091,13 +1091,13 @@ void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool rese
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if we get here, the condition must be in another zone.
|
||||
//first figure out what zone it applies to.
|
||||
//update the DB and send and send an update packet to
|
||||
//update the DB and send and send an update packet to
|
||||
//the zone if its up
|
||||
|
||||
//we need to load the event from the DB and then update
|
||||
|
||||
//we need to load the event from the DB and then update
|
||||
//the values in the DB, because we do not know if the zone
|
||||
//is up or not. The message to the zone will just tell it to
|
||||
//update its in-memory event list
|
||||
@@ -1112,7 +1112,7 @@ void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool rese
|
||||
_log(SPAWNS__CONDITIONS, "Spawn event %d is not located in this zone but no change was needed.", event_id);
|
||||
return; //no changes.
|
||||
}
|
||||
|
||||
|
||||
e.enabled = enabled;
|
||||
if(reset_base) {
|
||||
_log(SPAWNS__CONDITIONS, "Spawn event %d is in zone %s. State set. Trigger time reset (period %d). Notifying world.", event_id, zone_short_name.c_str(), e.period);
|
||||
@@ -1125,31 +1125,31 @@ void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool rese
|
||||
}
|
||||
//save the event in the DB
|
||||
UpdateDBEvent(e);
|
||||
|
||||
|
||||
|
||||
|
||||
//now notify the zone
|
||||
ServerPacket* pack = new ServerPacket(ServerOP_SpawnEvent, sizeof(ServerSpawnEvent_Struct));
|
||||
ServerSpawnEvent_Struct* sse = (ServerSpawnEvent_Struct*)pack->pBuffer;
|
||||
|
||||
|
||||
sse->zoneID = database.GetZoneID(zone_short_name.c_str());
|
||||
sse->event_id = event_id;
|
||||
|
||||
|
||||
worldserver.SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
}
|
||||
|
||||
int16 SpawnConditionManager::GetCondition(const char *zone_short, uint32 instance_id, uint16 condition_id) {
|
||||
if(!strcasecmp(zone_short, zone->GetShortName()) && instance_id == zone->GetInstanceID())
|
||||
if(!strcasecmp(zone_short, zone->GetShortName()) && instance_id == zone->GetInstanceID())
|
||||
{
|
||||
//this is a local spawn condition
|
||||
map<uint16, SpawnCondition>::iterator condi;
|
||||
condi = spawn_conditions.find(condition_id);
|
||||
if(condi == spawn_conditions.end())
|
||||
if(condi == spawn_conditions.end())
|
||||
{
|
||||
_log(SPAWNS__CONDITIONS, "Unable to find local condition %d in Get request.", condition_id);
|
||||
return(0); //unable to find the spawn condition
|
||||
}
|
||||
|
||||
|
||||
SpawnCondition &cond = condi->second;
|
||||
return(cond.value);
|
||||
} else {
|
||||
@@ -1159,12 +1159,12 @@ int16 SpawnConditionManager::GetCondition(const char *zone_short, uint32 instanc
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
int len;
|
||||
|
||||
|
||||
int16 value;
|
||||
|
||||
//load spawn conditions
|
||||
|
||||
//load spawn conditions
|
||||
SpawnCondition cond;
|
||||
len = MakeAnyLenString(&query, "SELECT value FROM spawn_condition_values WHERE zone='%s' AND instance_id=%u AND id=%d",
|
||||
len = MakeAnyLenString(&query, "SELECT value FROM spawn_condition_values WHERE zone='%s' AND instance_id=%u AND id=%d",
|
||||
zone_short, instance_id, condition_id);
|
||||
if (database.RunQuery(query, len, errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
@@ -1189,9 +1189,9 @@ bool SpawnConditionManager::Check(uint16 condition, int16 min_value) {
|
||||
condi = spawn_conditions.find(condition);
|
||||
if(condi == spawn_conditions.end())
|
||||
return(false); //unable to find the spawn condition
|
||||
|
||||
|
||||
SpawnCondition &cond = condi->second;
|
||||
|
||||
|
||||
return(cond.value >= min_value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user