sandy |
07-17-2004 12:00 PM |
2 grids system
Here is the 2 grids table system I have done
not sure if lines correspond exactly =(
in database.h :
line 117 :
add this :
Code:
struct wplist {
int index;
float x;
float y;
float z;
int pause;
};
line 404 :
replace by this :
Code:
void ModifyGrid(bool remove, int16 id, int8 type = 0, int8 type2 = 0,int16 zoneid = 0);
void ModifyWP(int16 grid_id, int16 wp_num, float xpos, float ypos, float zpos, int32 script=0,int16 zoneid =0);
int8 GetGridType(int16 grid,int16 zoneid);
int8 GetGridType2(int16 grid,int16 zoneid);
bool GetWaypoints(int16 grid, int16 zoneid, int16 num, wplist* wp);
void AssignGrid(Client *client, float x, float y, int32 id);
in database.cpp :
add the functions :
Code:
int8 Database::GetGridType(int16 grid,int16 zoneid ) {
char *query = 0;
char errbuf[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result;
MYSQL_ROW row;
int type = 0;
if (RunQuery(query, MakeAnyLenString(&query,"SELECT type from grid where id = %i and zoneid = %i",grid,zoneid),errbuf,&result)) {
safe_delete_array(query);
if (mysql_num_rows(result) == 1) {
row = mysql_fetch_row(result);
type = atoi( row[0] );
}
mysql_free_result(result);
} else {
cerr << "Error in GetGridType query '" << query << "' " << errbuf << endl;
safe_delete_array(query);
}
return type;
}
int8 Database::GetGridType2(int16 grid,int16 zoneid ) {
char *query = 0;
char errbuf[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result;
MYSQL_ROW row;
int type2 = 0;
if (RunQuery(query, MakeAnyLenString(&query,"SELECT type2 from grid where id = %i and zoneid = %i",grid,zoneid),errbuf,&result)) {
safe_delete_array(query);
if (mysql_num_rows(result) == 1) {
row = mysql_fetch_row(result);
type2 = atoi( row[0] );
}
mysql_free_result(result);
} else {
cerr << "Error in GetGridType2 query '" << query << "' " << errbuf << endl;
safe_delete_array(query);
}
return type2;
}
replace all these functions by :
Code:
bool Database::GetWaypoints(int16 grid,int16 zoneid, int16 num, wplist* wp) {
char *query = 0;
char errbuf[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result;
MYSQL_ROW row;
if (RunQuery(query, MakeAnyLenString(&query,"SELECT x, y, z, pause from grid_entries where gridid = %i and number = %i and zoneid = %i",grid,num,zoneid),errbuf,&result)) {
safe_delete_array(query);
if (mysql_num_rows(result) == 1) {
row = mysql_fetch_row(result);
if ( wp ) {
wp->index = num;
wp->x = atof( row[0] );
wp->y = atof( row[1] );
wp->z = atof( row[2] );
wp->pause = atoi( row[3] );
}
mysql_free_result(result);
return true;
}
mysql_free_result(result);
}
else {
cerr << "Error in GetWaypoints query '" << query << "' " << errbuf << endl;
safe_delete_array(query);
}
return false;
}
void Database::ModifyGrid(bool remove, int16 id, int8 type, int8 type2, int16 zoneid)
{
char *query = 0;
if (!remove)
{
RunQuery(query, MakeAnyLenString(&query,"UPDATE grid SET type=%i, type2=%i WHERE id=%i and zoneid=%i)",type,type2,id,zoneid));
safe_delete_array(query);
}
else
{
RunQuery(query, MakeAnyLenString(&query,"DELETE FROM grid where id=%i",id));
safe_delete_array(query);
}
}
void Database::ModifyWP(int16 grid_id, int16 wp_num, float xpos, float ypos, float zpos, int32 script, int16 zoneid)
{
char *query = 0;
RunQuery(query, MakeAnyLenString(&query,"UPDATE grid_entries set x=%f, y=%f, z=%f, pause=%i where id = %i and zoneid = %i and number = %i",xpos,ypos,zpos,script,grid_id,zoneid,wp_num));
safe_delete_array(query);
}
void Database::DeleteGrid(int32 sg2, int16 grid_num, bool grid_too, int16 zoneid)
{
char *query=0;
RunQuery(query, MakeAnyLenString(&query,"insert into spawn2 set pathgrid='0' where spawngroupID='%i'", sg2));
query = 0;
if (grid_too) {
RunQuery(query, MakeAnyLenString(&query,"delete from grid where id='%i' and zoneid = %i", grid_num,zoneid));
query = 0;
RunQuery(query, MakeAnyLenString(&query,"delete from grid_entries where gridid='%i' and zoneid = %i", grid_num,zoneid));
query = 0;
}
}
void Database::DeleteWaypoint(int16 grid_num, int32 wp_num, int16 zoneid)
{
char *query=0;
RunQuery(query, MakeAnyLenString(&query,"delete from grid_entries where gridid='%i' and zoneid = %i and number = %i", grid_num,zoneid, wp_num));
query = 0;
}
in mobai.cpp :
line 1320 :
replace by :
Code:
int16 ranmax = cur_wp;
int16 ranmax2 = max_wp - cur_wp;
replace the function Mob::AssignWaypoints by :
Code:
void Mob::AssignWaypoints(int16 grid)
{
Waypoints.ClearListAndData();
#ifdef _EQDEBUG
cout<<"Assigning waypoints for grid "<<grid<<" to "<<name<<"...\n";
#endif
if (!database.GetWaypoints(grid,zone->GetZoneID(), 1, NULL))
return;
wandertype = database.GetGridType( grid,zone->GetZoneID() );
pausetype = database.GetGridType2( grid,zone->GetZoneID() );
adverrorinfo = 7561;
this->CastToNPC()->SetGrid(grid); //Assign grid number
roamer = true; //This is a roamer
wplist* wpstruct = new wplist;
int i = 1;
while ( database.GetWaypoints(grid,zone->GetZoneID(), i, wpstruct)) {
wplist * newwp = new wplist;
adverrorinfo = 7564;
newwp->x = wpstruct->x;
newwp->y = wpstruct->y;
newwp->z = wpstruct->z;
newwp->pause = wpstruct->pause;
newwp->index = i-1;
i++;
if (newwp->x && newwp->y && newwp->z) {
max_wp = newwp->index;
Waypoints.AddItem(newwp);
}
}
UpdateWaypoint(0);
SetWaypointPause();
safe_delete( wpstruct );
#ifdef _EQDEBUG
cout<<" done."<<endl;
#endif
adverrorinfo = 7565;
// UpdateWaypoint(0);
this->SendTo(cur_wp_x, cur_wp_y, cur_wp_z);
if (wandertype == 1 || wandertype == 2)
CalculateNewWaypoint();
}
here's the sql tables :
Code:
#
# Structure de la table `grid`
#
CREATE TABLE `grid` (
`id` int(10) NOT NULL default '0',
`zoneid` int(10) NOT NULL default '0',
`type` int(10) NOT NULL default '0',
`type2` int(10) NOT NULL default '0',
KEY `zoneid` (`zoneid`),
KEY `id` (`id`)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Structure de la table `grid_entries`
#
CREATE TABLE `grid_entries` (
`gridid` int(10) NOT NULL default '0',
`zoneid` int(10) NOT NULL default '0',
`number` int(10) 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',
`pause` int(10) NOT NULL default '0',
KEY `number` (`number`),
KEY `gridid` (`gridid`),
KEY `zoneid` (`zoneid`)
) TYPE=MyISAM;
|