Skip to content

Commit 359c599

Browse files
committed
[s2482] Implement creature and go zone and area generation into db
1 parent f2bc448 commit 359c599

File tree

8 files changed

+117
-2
lines changed

8 files changed

+117
-2
lines changed

sql/base/mangos.sql

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ DROP TABLE IF EXISTS `db_version`;
2323
CREATE TABLE `db_version` (
2424
`version` varchar(120) DEFAULT NULL,
2525
`creature_ai_version` varchar(120) DEFAULT NULL,
26-
`required_s2481_01_mangos_reputation_spillover` bit(1) DEFAULT NULL
26+
`required_s2482_01_mangos_spawn_zone` bit(1) DEFAULT NULL
2727
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Used DB version notes';
2828

2929
--
@@ -808,6 +808,14 @@ LOCK TABLES `creature_addon` WRITE;
808808
/*!40000 ALTER TABLE `creature_addon` ENABLE KEYS */;
809809
UNLOCK TABLES;
810810

811+
DROP TABLE IF EXISTS `creature_zone`;
812+
CREATE TABLE `creature_zone` (
813+
`Guid` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Global Unique Identifier',
814+
`ZoneId` mediumint unsigned NOT NULL DEFAULT '0' COMMENT 'Zone Identifier',
815+
`AreaId` mediumint unsigned NOT NULL DEFAULT '0' COMMENT 'Area Identifier',
816+
PRIMARY KEY(`Guid`)
817+
);
818+
811819
--
812820
-- Table structure for table `creature_ai_scripts`
813821
--
@@ -2063,6 +2071,14 @@ CREATE TABLE `gameobject_addon` (
20632071
PRIMARY KEY(`guid`)
20642072
);
20652073

2074+
DROP TABLE IF EXISTS `gameobject_zone`;
2075+
CREATE TABLE `gameobject_zone` (
2076+
`Guid` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Global Unique Identifier',
2077+
`ZoneId` mediumint unsigned NOT NULL DEFAULT '0' COMMENT 'Zone Identifier',
2078+
`AreaId` mediumint unsigned NOT NULL DEFAULT '0' COMMENT 'Area Identifier',
2079+
PRIMARY KEY(`Guid`)
2080+
);
2081+
20662082
DROP TABLE IF EXISTS `gameobject_spawn_entry`;
20672083
CREATE TABLE `gameobject_spawn_entry`(
20682084
`guid` INT UNSIGNED NOT NULL COMMENT 'Gameobject table guid',
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ALTER TABLE db_version CHANGE COLUMN required_s2481_01_mangos_reputation_spillover required_s2482_01_mangos_spawn_zone bit;
2+
3+
DROP TABLE IF EXISTS `creature_zone`;
4+
CREATE TABLE `creature_zone` (
5+
`Guid` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Global Unique Identifier',
6+
`ZoneId` mediumint unsigned NOT NULL DEFAULT '0' COMMENT 'Zone Identifier',
7+
`AreaId` mediumint unsigned NOT NULL DEFAULT '0' COMMENT 'Area Identifier',
8+
PRIMARY KEY(`Guid`)
9+
);
10+
11+
DROP TABLE IF EXISTS `gameobject_zone`;
12+
CREATE TABLE `gameobject_zone` (
13+
`Guid` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Global Unique Identifier',
14+
`ZoneId` mediumint unsigned NOT NULL DEFAULT '0' COMMENT 'Zone Identifier',
15+
`AreaId` mediumint unsigned NOT NULL DEFAULT '0' COMMENT 'Area Identifier',
16+
PRIMARY KEY(`Guid`)
17+
);
18+

src/game/Globals/ObjectMgr.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include "OutdoorPvP/OutdoorPvP.h"
4848
#include "World/WorldState.h"
4949

50+
#include "MotionGenerators/MoveMap.h"
51+
5052
#include "Entities/ItemEnchantmentMgr.h"
5153
#include "Loot/LootMgr.h"
5254

@@ -6476,6 +6478,69 @@ void ObjectMgr::LoadAreatriggerLocales()
64766478
sLog.outString();
64776479
}
64786480

6481+
void ObjectMgr::GenerateZoneAndAreaIds()
6482+
{
6483+
WorldDatabase.DirectExecute("TRUNCATE creature_zone");
6484+
WorldDatabase.DirectExecute("TRUNCATE gameobject_zone");
6485+
6486+
std::string baseCreature = "INSERT INTO creature_zone(Guid, ZoneId, AreaId) VALUES";
6487+
int i = 0;
6488+
int total = 0;
6489+
std::string query = "";
6490+
for (auto& data : mCreatureDataMap)
6491+
{
6492+
CreatureData const& creature = data.second;
6493+
uint32 zoneId, areaId;
6494+
TerrainInfo* info = sTerrainMgr.LoadTerrain(creature.mapid);
6495+
MMAP::MMapFactory::createOrGetMMapManager()->loadMapInstance(sWorld.GetDataPath(), creature.mapid, 0);
6496+
CellPair p = MaNGOS::ComputeCellPair(creature.posX, creature.posY);
6497+
Cell cell(p);
6498+
GridPair gp(cell.GridX(), cell.GridY());
6499+
int gx = (MAX_NUMBER_OF_GRIDS - 1) - gp.x_coord;
6500+
int gy = (MAX_NUMBER_OF_GRIDS - 1) - gp.y_coord;
6501+
info->LoadMapAndVMap(gx, gy);
6502+
info->GetZoneAndAreaId(zoneId, areaId, creature.posX, creature.posY, creature.posZ);
6503+
6504+
query += "(" + std::to_string(data.first) + "," + std::to_string(zoneId) + "," + std::to_string(areaId) + "),";
6505+
++i; ++total;
6506+
if (i >= 100)
6507+
{
6508+
std::string finalQuery = baseCreature + query;
6509+
finalQuery[finalQuery.length() - 1] = ';';
6510+
WorldDatabase.DirectExecute(finalQuery.c_str());
6511+
query = "";
6512+
i = 0;
6513+
}
6514+
}
6515+
6516+
std::string baseGo = "INSERT INTO gameobject_zone(Guid, ZoneId, AreaId) VALUES";
6517+
for (auto& data : mGameObjectDataMap)
6518+
{
6519+
GameObjectData const& go = data.second;
6520+
uint32 zoneId, areaId;
6521+
TerrainInfo* info = sTerrainMgr.LoadTerrain(go.mapid);
6522+
MMAP::MMapFactory::createOrGetMMapManager()->loadMapInstance(sWorld.GetDataPath(), go.mapid, 0);
6523+
CellPair p = MaNGOS::ComputeCellPair(go.posX, go.posY);
6524+
Cell cell(p);
6525+
GridPair gp(cell.GridX(), cell.GridY());
6526+
int gx = (MAX_NUMBER_OF_GRIDS - 1) - gp.x_coord;
6527+
int gy = (MAX_NUMBER_OF_GRIDS - 1) - gp.y_coord;
6528+
info->LoadMapAndVMap(gx, gy);
6529+
info->GetZoneAndAreaId(zoneId, areaId, go.posX, go.posY, go.posZ + 1);
6530+
6531+
query += "(" + std::to_string(data.first) + "," + std::to_string(zoneId) + "," + std::to_string(areaId) + "),";
6532+
++i; ++total;
6533+
if (i >= 100)
6534+
{
6535+
std::string finalQuery = baseGo + query;
6536+
finalQuery[finalQuery.length() - 1] = ';';
6537+
WorldDatabase.DirectExecute(finalQuery.c_str());
6538+
query = "";
6539+
i = 0;
6540+
}
6541+
}
6542+
}
6543+
64796544
// not very fast function but it is called only once a day, or on starting-up
64806545
/// @param serverUp true if the server is already running, false when the server is started
64816546
void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)

src/game/Globals/ObjectMgr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ class ObjectMgr
720720
void LoadMailLevelRewards();
721721
void LoadAreatriggerLocales();
722722

723+
void GenerateZoneAndAreaIds();
724+
723725
void LoadGossipText();
724726

725727
void LoadAreaTriggerTeleports();

src/game/World/World.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,8 @@ void World::LoadConfigSettings(bool reload)
874874

875875
setConfig(CONFIG_BOOL_LFG_ENABLED, "Lfg.Enabled", true);
876876

877+
setConfig(CONFIG_BOOL_REGEN_ZONE_AREA_ON_STARTUP, "Spawns.ZoneArea", false);
878+
877879
sLog.outString();
878880
}
879881

@@ -1112,6 +1114,12 @@ void World::SetInitialWorldSettings()
11121114
sLog.outString("Loading Gameobject Data...");
11131115
sObjectMgr.LoadGameObjects();
11141116

1117+
if (getConfig(CONFIG_BOOL_REGEN_ZONE_AREA_ON_STARTUP))
1118+
{
1119+
sLog.outString("Generating zone and area ids for creatures and gameobjects...");
1120+
sObjectMgr.GenerateZoneAndAreaIds();
1121+
}
1122+
11151123
sLog.outString("Loading SpellsScriptTarget...");
11161124
sSpellMgr.LoadSpellScriptTarget(); // must be after LoadCreatureTemplates, LoadCreatures and LoadGameobjectInfo
11171125

src/game/World/World.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ enum eConfigBoolValues
391391
CONFIG_BOOL_DISABLE_INSTANCE_RELOCATE,
392392
CONFIG_BOOL_PRELOAD_MMAP_TILES,
393393
CONFIG_BOOL_LFG_ENABLED,
394+
CONFIG_BOOL_REGEN_ZONE_AREA_ON_STARTUP,
394395
CONFIG_BOOL_VALUE_COUNT
395396
};
396397

src/mangosd/mangosd.conf.dist.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ ConfVersion=2024020101
7272
# SD2ErrorLogFile
7373
# Log File for SD2-Errors
7474
#
75+
# Spawns.ZoneArea
76+
# Regenerates table creature_zone and gameobject_zone
77+
# Default: 0 - turned off
78+
#
7579
###################################################################################################################
7680

7781
RealmID = 1
@@ -89,6 +93,7 @@ MaxPingTime = 30
8993
WorldServerPort = 8085
9094
BindIP = "0.0.0.0"
9195
SD2ErrorLogFile = "SD2Errors.log"
96+
Spawns.ZoneArea = 0
9297

9398
###################################################################################################################
9499
# PERFORMANCE SETTINGS

src/shared/revision_sql.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#define REVISION_DB_REALMD "required_s2474_01_realmd_joindate_datetime"
44
#define REVISION_DB_LOGS "required_s2433_01_logs_anticheat"
55
#define REVISION_DB_CHARACTERS "required_s2473_01_characters_item_instance_text_id_fix"
6-
#define REVISION_DB_MANGOS "required_s2481_01_mangos_reputation_spillover"
6+
#define REVISION_DB_MANGOS "required_s2482_01_mangos_spawn_zone"
77
#endif // __REVISION_SQL_H__

0 commit comments

Comments
 (0)