zaela-Server/zone/spawngroup.cpp

232 lines
7.8 KiB
C++
Raw Permalink Normal View History

2013-05-09 10:44:08 -04:00
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
2013-02-16 16:14:39 -08:00
2013-05-09 10:44:08 -04:00
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.
2013-05-06 13:07:41 -04:00
2013-05-09 10:44:08 -04:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
2013-02-16 16:14:39 -08:00
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
2013-05-09 10:44:08 -04:00
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
2013-05-06 13:07:41 -04:00
2013-05-09 10:44:08 -04:00
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
2013-02-16 16:14:39 -08:00
*/
#include "../common/debug.h"
#include "spawngroup.h"
#include "entity.h"
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include "../common/types.h"
#include "zonedb.h"
2014-08-21 19:33:02 -07:00
#include "../common/misc_functions.h"
#include "../common/string_util.h"
2013-02-16 16:14:39 -08:00
extern EntityList entity_list;
Changed zone process window title format, example: 'crushbone :: clients: 6 inst_id: 1 inst_ver: 0 :: port: 7015' Most of the following changes are QueryServ related, fully implemented its original functionality to be able to offload intensive or metric based logging to a remote server process that could exist on another server entirely Implemented Player Event Logging Types (Go to table `qs_player_events`): 1 = Player_Log_Quest, 2 = Player_Log_Zoning, 3 = Player_Log_Deaths, 4 = Player_Log_Connect_State, 5 = Player_Log_Levels, 6 = Player_Log_Keyring_Addition, 7 = Player_Log_QGlobal_Update, 8 = Player_Log_Task_Updates, 9 = Player_Log_AA_Purchases, 10 = Player_Log_Trade_Skill_Events, 11 = Player_Log_Issued_Commands, 12 = Player_Log_Money_Transactions, 13 = Player_Log_Alternate_Currency_Transactions, - All QueryServ logging will be implemented with a front end in EoC 2.0 very soon Changed all QS Error related logging to 'QUERYSERV__ERROR' (Natedog) (Crash Fix) Legacy MySQL bug revert for loading AA's COALESCE( from COALESCE ( Implemented Perl Quest objects (LUA still needed to be exported): - quest::qs_send_query("MySQL query") - Will send a raw query to the QueryServ process, useful for custom logging - quest::qs_player_event(char_id, event_desc); - Will process a quest type event to table `qs_player_events` Added MySQL Tables: - `qs_player_aa_rate_hourly` - `qs_player_events` - Source table structures from: - utils\sql\git\queryserv\required\08_23_2014_player_events_and_player_aa_rate_hourly To get the complete QueryServ schema, source from here: - utils\sql\git\queryserv\required\Complete_QueryServ_Table_Structures.sql Added rules for each logging type, source rules here with them enabled by default: - utils\sql\git\queryserv\required\Complete_QueryServ_Rules_Enabled.sql Spawn related logging cleanup General code cleanup Added queryserv.cpp and queryserv.h with QueryServ class
2014-08-23 23:59:20 -05:00
SpawnEntry::SpawnEntry( uint32 in_NPCType, int in_chance, uint8 in_npc_spawn_limit ) {
2013-02-16 16:14:39 -08:00
NPCType = in_NPCType;
chance = in_chance;
npc_spawn_limit = in_npc_spawn_limit;
}
SpawnGroup::SpawnGroup( uint32 in_id, char* name, int in_group_spawn_limit, float dist, float maxx, float minx, float maxy, float miny, int delay_in, int despawn_in, uint32 despawn_timer_in, int min_delay_in ) {
2013-02-16 16:14:39 -08:00
id = in_id;
strn0cpy( name_, name, 120);
group_spawn_limit = in_group_spawn_limit;
roambox[0]=maxx;
roambox[1]=minx;
roambox[2]=maxy;
roambox[3]=miny;
roamdist=dist;
min_delay=min_delay_in;
2013-02-16 16:14:39 -08:00
delay=delay_in;
despawn=despawn_in;
despawn_timer=despawn_timer_in;
}
uint32 SpawnGroup::GetNPCType() {
#if EQDEBUG >= 10
LogFile->write(EQEMuLog::Debug, "SpawnGroup[%08x]::GetNPCType()", (uint32) this);
#endif
int npcType = 0;
int totalchance = 0;
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
if(!entity_list.LimitCheckGroup(id, group_spawn_limit))
return(0);
2013-05-06 13:07:41 -04:00
std::list<SpawnEntry*>::iterator cur,end;
std::list<SpawnEntry*> possible;
2013-02-16 16:14:39 -08:00
cur = list_.begin();
end = list_.end();
for(; cur != end; ++cur) {
2013-02-16 16:14:39 -08:00
SpawnEntry *se = *cur;
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
if(!entity_list.LimitCheckType(se->NPCType, se->npc_spawn_limit))
continue;
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
totalchance += se->chance;
possible.push_back(se);
}
if(totalchance == 0)
return 0;
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
int32 roll = 0;
roll = MakeRandomInt(0, totalchance-1);
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
cur = possible.begin();
end = possible.end();
for(; cur != end; ++cur) {
2013-02-16 16:14:39 -08:00
SpawnEntry *se = *cur;
if (roll < se->chance) {
npcType = se->NPCType;
break;
} else {
roll -= se->chance;
}
}
return npcType;
}
void SpawnGroup::AddSpawnEntry( SpawnEntry* newEntry ) {
list_.push_back( newEntry );
}
SpawnGroup::~SpawnGroup() {
std::list<SpawnEntry*>::iterator cur,end;
2013-02-16 16:14:39 -08:00
cur = list_.begin();
end = list_.end();
for(; cur != end; ++cur) {
2013-02-16 16:14:39 -08:00
SpawnEntry* tmp = *cur;
safe_delete(tmp);
}
list_.clear();
}
SpawnGroupList::~SpawnGroupList() {
std::map<uint32, SpawnGroup*>::iterator cur,end;
2013-02-16 16:14:39 -08:00
cur = groups.begin();
end = groups.end();
for(; cur != end; ++cur) {
2013-02-16 16:14:39 -08:00
SpawnGroup* tmp = cur->second;
safe_delete(tmp);
}
groups.clear();
}
void SpawnGroupList::AddSpawnGroup(SpawnGroup* newGroup) {
2013-05-04 18:06:58 -07:00
if(newGroup == nullptr)
2013-02-16 16:14:39 -08:00
return;
groups[newGroup->id] = newGroup;
}
SpawnGroup* SpawnGroupList::GetSpawnGroup(uint32 in_id) {
if(groups.count(in_id) != 1)
2013-05-23 20:22:42 -04:00
return nullptr;
2013-02-16 16:14:39 -08:00
return(groups[in_id]);
}
bool SpawnGroupList::RemoveSpawnGroup(uint32 in_id) {
if(groups.count(in_id) != 1)
return(false);
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
groups.erase(in_id);
return(true);
}
bool ZoneDatabase::LoadSpawnGroups(const char* zone_name, uint16 version, SpawnGroupList* spawn_group_list) {
2013-05-06 13:07:41 -04:00
std::string query = StringFormat("SELECT DISTINCT(spawngroupID), spawngroup.name, spawngroup.spawn_limit, "
"spawngroup.dist, spawngroup.max_x, spawngroup.min_x, "
"spawngroup.max_y, spawngroup.min_y, spawngroup.delay, "
"spawngroup.despawn, spawngroup.despawn_timer, spawngroup.mindelay "
"FROM spawn2, spawngroup WHERE spawn2.spawngroupID = spawngroup.ID "
"AND spawn2.version = %u and zone = '%s'", version, zone_name);
auto results = QueryDatabase(query);
if (!results.Success()) {
_log(ZONE__SPAWNS, "Error2 in PopulateZoneLists query '%s' ", query.c_str());
2013-02-16 16:14:39 -08:00
return false;
}
for (auto row = results.begin(); row != results.end(); ++row) {
SpawnGroup* newSpawnGroup = new SpawnGroup(atoi(row[0]), row[1], atoi(row[2]), atof(row[3]),
atof(row[4]), atof(row[5]), atof(row[6]), atof(row[7]),
atoi(row[8]), atoi(row[9]), atoi(row[10]), atoi(row[11]));
spawn_group_list->AddSpawnGroup(newSpawnGroup);
}
query = StringFormat("SELECT DISTINCT spawnentry.spawngroupID, npcid, chance, "
"npc_types.spawn_limit AS sl "
"FROM spawnentry, spawn2, npc_types "
"WHERE spawnentry.npcID=npc_types.id "
"AND spawnentry.spawngroupID = spawn2.spawngroupID "
"AND zone = '%s'", zone_name);
results = QueryDatabase(query);
if (!results.Success()) {
_log(ZONE__SPAWNS, "Error2 in PopulateZoneLists query '%'", query.c_str());
return false;
}
2013-02-16 16:14:39 -08:00
for (auto row = results.begin(); row != results.end(); ++row) {
SpawnEntry* newSpawnEntry = new SpawnEntry( atoi(row[1]), atoi(row[2]), row[3]?atoi(row[3]):0);
SpawnGroup *sg = spawn_group_list->GetSpawnGroup(atoi(row[0]));
if (!sg) {
_log(ZONE__SPAWNS, "Error in LoadSpawnGroups %s ", query.c_str());
continue;
2013-02-16 16:14:39 -08:00
}
sg->AddSpawnEntry(newSpawnEntry);
}
2013-02-16 16:14:39 -08:00
return true;
}
bool ZoneDatabase::LoadSpawnGroupsByID(int spawngroupid, SpawnGroupList* spawn_group_list) {
std::string query = StringFormat("SELECT DISTINCT(spawngroup.id), spawngroup.name, spawngroup.spawn_limit, "
"spawngroup.dist, spawngroup.max_x, spawngroup.min_x, "
"spawngroup.max_y, spawngroup.min_y, spawngroup.delay, "
"spawngroup.despawn, spawngroup.despawn_timer, spawngroup.mindelay "
"FROM spawngroup WHERE spawngroup.ID = '%i'", spawngroupid);
auto results = QueryDatabase(query);
if (!results.Success()) {
_log(ZONE__SPAWNS, "Error2 in PopulateZoneLists query %s", query.c_str());
2013-02-16 16:14:39 -08:00
return false;
}
2013-02-16 16:14:39 -08:00
for (auto row = results.begin(); row != results.end(); ++row) {
SpawnGroup* newSpawnGroup = new SpawnGroup(atoi(row[0]), row[1], atoi(row[2]), atof(row[3]), atof(row[4]), atof(row[5]), atof(row[6]), atof(row[7]), atoi(row[8]), atoi(row[9]), atoi(row[10]), atoi(row[11]));
spawn_group_list->AddSpawnGroup(newSpawnGroup);
}
query = StringFormat("SELECT DISTINCT(spawnentry.spawngroupID), spawnentry.npcid, "
"spawnentry.chance, spawngroup.spawn_limit FROM spawnentry, spawngroup "
"WHERE spawnentry.spawngroupID = '%i' AND spawngroup.spawn_limit = '0' "
"ORDER BY chance", spawngroupid);
results = QueryDatabase(query);
if (!results.Success()) {
_log(ZONE__SPAWNS, "Error3 in PopulateZoneLists query '%s'", query.c_str());
2013-02-16 16:14:39 -08:00
return false;
}
for(auto row = results.begin(); row != results.end(); ++row) {
SpawnEntry* newSpawnEntry = new SpawnEntry( atoi(row[1]), atoi(row[2]), row[3]?atoi(row[3]):0);
SpawnGroup *sg = spawn_group_list->GetSpawnGroup(atoi(row[0]));
if (!sg) {
_log(ZONE__SPAWNS, "Error in SpawngroupID: %s ", row[0]);
continue;
}
sg->AddSpawnEntry(newSpawnEntry);
}
2013-02-16 16:14:39 -08:00
return true;
}