View Single Post
  #4  
Old 07-06-2009, 12:51 AM
Shendare
Dragon
 
Join Date: Apr 2009
Location: California
Posts: 814
Default

Technically, the best thing to do to utilize this availability without cluttering up the doors table with non-door objects would be to create a new table:

Code:
CREATE TABLE `static_objects` (
  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `zoneid` INTEGER UNSIGNED NOT NULL DEFAULT 0,
  `version` INTEGER UNSIGNED NOT NULL DEFAULT 0,
  `x` FLOAT NOT NULL DEFAULT 0,
  `y` FLOAT NOT NULL DEFAULT 0,
  `z` FLOAT NOT NULL DEFAULT 0,
  `heading` FLOAT NOT NULL DEFAULT 0,
  `size` SMALLINT UNSIGNED NOT NULL DEFAULT 100,
  `incline` INTEGER NOT NULL DEFAULT 0,
  `model` VARCHAR(32) NOT NULL,
  `solid` TINYINT UNSIGNED NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  INDEX `idx_staticobjects_zoneid`(`zoneid`),
  INDEX `idx_staticobjects_version`(`version`)
)
ENGINE = InnoDB;
Then piggy-back static object loading in the door spawns of the entity_list.

File: zone.h, Line 111 - Class Zone
Code:
...
  void LoadZoneDoors(const char* zone, int16 version);
+ void  LoadZoneStaticObjects(int32 zoneid, const char* shortname, int16 version);
  bool LoadZoneObjects();
...
File: zone.cpp, Line 698 - new function Zone::LoadZoneStaticObjects()
Code:
void Zone::LoadZoneStaticObjects(int32 zoneid, const char* shortname, int16 version)
{
  if ((!zoneid) || (!shortname))
  {
    return;
  }

  LogFile->write(EQEMuLog::Status, "Loading static objects for %s ...", shortname);
  
  int32 maxdoorid = 1;      // If there aren't any doors for this zone, start with #1
  int32 maxid = 2000000000; // Way out of range of normal use

  char errbuf[MYSQL_ERRMSG_SIZE];
  char query[256];

  MYSQL_RES *result;
  MYSQL_ROW row;
  
  sprintf(query, "SELECT MAX(doorid) FROM doors WHERE zone='%s' AND version=%u", shortname, version);
  if (database.RunQuery(query, strlen(query), errbuf, &result))
  {
    if (row = mysql_fetch_row(result))
    {
      maxdoorid = atoi(row[0]) + 1;
    }
    
    mysql_free_result(result);
  }

  sprintf(query, "SELECT MAX(id) FROM doors");
  if (database.RunQuery(query, strlen(query), errbuf, &result))
  {
    if (row = mysql_fetch_row(result))
    {
      maxid = atoi(row[0]) + 1;
    }
    
    mysql_free_result(result);
  }

  sprintf(query, "SELECT x, y, z, heading, size, incline, model, solid FROM static_objects WHERE zoneid=%d AND version=%d", zoneid, version);
  if (database.RunQuery(query, strlen(query), errbuf, &result))
  {
    Door newdoor;
    Doors* door;
    memset(&newdoor, 0, sizeof(Door));
    int32 r = 0;
    int32 c;

    strncpy(newdoor.zone_name, shortname, 16);
    memcpy(newdoor.dest_zone, "NONE", 5);

    for (r = 0; row = mysql_fetch_row(result); r++)
    {
      c = 0;
      newdoor.db_id = maxid + r;
      newdoor.door_id = maxdoorid + r;
      newdoor.pos_x = atof(row[c++]);
      newdoor.pos_y = atof(row[c++]);
      newdoor.pos_z = atof(row[c++]);
      newdoor.heading = atof(row[c++]);
      newdoor.size = atoi(row[c++]);
      newdoor.incline = atoi(row[c++]);
      strncpy(newdoor.door_name, row[c++], 32);
      switch (newdoor.opentype = atoi(row[c++]))
      {
        case 0:
          newdoor.opentype = 9;
          break;
        case 1:
          newdoor.opentype = 31;
          break;
      }

      door = new Doors(&newdoor);
      entity_list.AddDoor(door);
    }

    mysql_free_result(result);
  }
}
File: zone.cpp, Line 954 - Zone::Init()
Code:
...
  zone->LoadZoneDoors(zone->GetShortName(), zone->GetInstanceVersion());
+ zone->LoadZoneStaticObjects(zone->GetZoneID(), zone->GetShortName(), zone->GetInstanceVersion());
  zone->LoadBlockedSpells(zone->GetZoneID());
...
And it works!



If you're wondering why I'm sticking it in doors, instead of the zone objects table, it's because I couldn't figure out any way to use the zone objects system that didn't involve an openable tradeskill container or pickable ground spawn item.

Anyway, forget adding records to the doors table. Much better to use this new static_objects table!
Reply With Quote