EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Archive::Development (https://www.eqemulator.org/forums/forumdisplay.php?f=621)
-   -   2 grids system (https://www.eqemulator.org/forums/showthread.php?t=14837)

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;


govtcheeze 07-17-2004 12:58 PM

The grid converter is at:

http://govtcheeze.eqemulator.net/download/

and download the file called updateGrids.rar

sotonin 07-17-2004 01:33 PM

I hope we can finally get this into the Official CVS. it's frustrating having to redo this every release. =(

Zkhava 07-17-2004 03:15 PM

Good Work


Sandy, ;)

Scorpious2k 07-17-2004 04:19 PM

I haven't merged this in yet, because I believe, looking at the code, the #wp command will quit working. I need to change and test before it goes into cvs.

sotonin 07-17-2004 06:54 PM

awesome. ) it's good to see it's finally being dealt with though.

The pathing just has way more potential for detail with the 2 grid system

Minuss 07-17-2004 08:44 PM

Great, I cant wait to test it :)
Now that we are talking about waypoints, could you please, if it don't take too much time, add a command that allow to check the waypoint number the npc is currently walking on or heading on, so we can trigger events when he reaches this waypoint.
This'd help me for a lot of my quests...
Thanks :wink:

Scorpious2k 07-17-2004 10:00 PM

Is event waypoint broken? The $wp variable should contain the current waypoint number during an event waypoint.

Minuss 07-17-2004 11:19 PM

Last time I tried something like this :
Code:

sub EVENT_WAYPOINT
{
 if($wp == 10)
 {
  quest::say("Hey I'm at wp 10");
 }

 elsif($wp == 15)
 {
  quest::say("Hey I'm at wp 15);
 }
}

it was not working... Any idea ?

sandy 07-20-2004 09:05 AM

yes scorpious i think it have to be completed with the last commands you created to edit grids ingame and for quests =)


All times are GMT -4. The time now is 09:21 PM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.