View Single Post
  #1  
Old 06-04-2010, 09:12 AM
joligario's Avatar
joligario
Developer
 
Join Date: Mar 2003
Posts: 1,490
Default COMMITTED: Grid Waypoints

Changes which allow the mob AI to use headings from the grid entries table. Also changes to the #wp and #wpadd commands to save heading data when adding a new grid entry.

zone/command.cpp
Code:
Index: zone/command.cpp
===================================================================
--- zone/command.cpp	(revision 1520)
+++ zone/command.cpp	(working copy)
@@ -2433,7 +2433,7 @@
 	if (strcasecmp("add",sep->arg[1]) == 0) {
 		if (wp == 0) //AndMetal: default to highest if it's left blank, or we enter 0
 			wp = database.GetHighestWaypoint(zone->GetZoneID(), atoi(sep->arg[2])) + 1;
-		database.AddWP(c, atoi(sep->arg[2]),wp, c->GetX(), c->GetY(), c->GetZ(), atoi(sep->arg[3]),zone->GetZoneID());
+		database.AddWP(c, atoi(sep->arg[2]),wp, c->GetX(), c->GetY(), c->GetZ(), atoi(sep->arg[3]),zone->GetZoneID(), c->GetHeading());
 	}
 	else if (strcasecmp("delete",sep->arg[1]) == 0)
 		database.DeleteWaypoint(c, atoi(sep->arg[2]),wp,zone->GetZoneID());
@@ -5955,7 +5955,7 @@
 				return;
 			}
 		}
-		int32 tmp_grid = database.AddWPForSpawn(c, s2info->GetID(), c->GetX(),c->GetY(),c->GetZ(), pause, type1, type2, zone->GetZoneID());
+		int32 tmp_grid = database.AddWPForSpawn(c, s2info->GetID(), c->GetX(),c->GetY(),c->GetZ(), pause, type1, type2, zone->GetZoneID(),c->GetHeading());
 		if (tmp_grid)
 			t->CastToNPC()->SetGrid(tmp_grid);
zone/mob.h
Code:
Index: zone/mob.h
===================================================================
--- zone/mob.h	(revision 1520)
+++ zone/mob.h	(working copy)
@@ -1199,6 +1200,7 @@
 	float cur_wp_y;
 	float cur_wp_z;
 	int cur_wp_pause;
+	float cur_wp_heading;
 
 	int patrol;
 	float fear_walkto_x;
zone/MobAI.cpp
Code:
Index: zone/MobAI.cpp
===================================================================
--- zone/MobAI.cpp	(revision 1520)
+++ zone/MobAI.cpp	(working copy)
@@ -1594,6 +1594,7 @@
 				if (cur_wp_x == GetX() && cur_wp_y == GetY()) 
 				{	// are we there yet? then stop
 					mlog(AI__WAYPOINTS, "We have reached waypoint %d (%.3f,%.3f,%.3f) on grid %d", cur_wp, GetX(), GetY(), GetZ(), GetGrid());
+					SetHeading(cur_wp_heading);
 					SetWaypointPause();
 					SetAppearance(eaStanding, false);
 					SetMoving(false);
Index: zone/waypoints.cpp
Code:
Index: waypoints.cpp
===================================================================
--- waypoints.cpp	(revision 1520)
+++ waypoints.cpp	(working copy)
@@ -202,6 +202,7 @@
 	cur_wp_y = mty;
 	cur_wp_z = mtz;
 	cur_wp_pause = 0;
+	cur_wp_heading = mth;
 }
 
 void NPC::UpdateWaypoint(int wp_index)
@@ -218,7 +219,8 @@
 	cur_wp_y = cur->y;
 	cur_wp_z = cur->z;
 	cur_wp_pause = cur->pause;
-	mlog(AI__WAYPOINTS, "Next waypoint %d: (%.3f, %.3f, %.3f)", wp_index, cur_wp_x, cur_wp_y, cur_wp_z);
+	cur_wp_heading = cur->heading;
+	mlog(AI__WAYPOINTS, "Next waypoint %d: (%.3f, %.3f, %.3f, %.3f)", wp_index, cur_wp_x, cur_wp_y, cur_wp_z, cur_wp_heading);
 		
 	//fix up pathing Z
 	if(zone->HasMap() && RuleB(Map, FixPathingZAtWaypoints))
@@ -847,7 +849,7 @@
 	    adverrorinfo = 7561;
 
 	    // Retrieve all waypoints for this grid
-	    if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT `x`,`y`,`z`,`pause` FROM grid_entries WHERE `gridid`=%i AND `zoneid`=%i ORDER BY `number`",grid,zone->GetZoneID()),errbuf,&result))
+	    if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT `x`,`y`,`z`,`pause`,`heading` FROM grid_entries WHERE `gridid`=%i AND `zoneid`=%i ORDER BY `number`",grid,zone->GetZoneID()),errbuf,&result))
 	    {
 	    	roamer = true;
 			max_wp = -1;	// Initialize it; will increment it for each waypoint successfully added to the list
@@ -878,6 +880,7 @@
 				}
 
 				newwp.pause = atoi(row[3]);
+				newwp.heading = atof(row[4]);
 				Waypoints.push_back(newwp);
 			    }
 			}
@@ -1033,7 +1036,7 @@
 	char errbuff[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),errbuff,&result)) {
+	if (RunQuery(query, MakeAnyLenString(&query,"SELECT x, y, z, pause, heading from grid_entries where gridid = %i and number = %i and zoneid = %i",grid,num,zoneid),errbuff,&result)) {
 		safe_delete_array(query);
 		if (mysql_num_rows(result) == 1) {
 			row = mysql_fetch_row(result);
@@ -1042,6 +1045,7 @@
 				wp->y = atof( row[1] );
 				wp->z = atof( row[2] );
 				wp->pause = atoi( row[3] );
+				wp->heading = atof( row[4] );
 			}
 			mysql_free_result(result);
 			return true;
@@ -1204,12 +1208,12 @@
 * AddWP - Adds a new waypoint to a specific grid for a specific zone.
 */
 
-void ZoneDatabase::AddWP(Client *c, int32 gridid, int32 wpnum, float xpos, float ypos, float zpos, int32 pause, int16 zoneid)
+void ZoneDatabase::AddWP(Client *c, int32 gridid, int32 wpnum, float xpos, float ypos, float zpos, int32 pause, int16 zoneid, float heading)
 {   
 	char *query = 0;
 	char errbuf[MYSQL_ERRMSG_SIZE];
 
-	if(!RunQuery(query,MakeAnyLenString(&query,"INSERT INTO grid_entries (gridid,zoneid,`number`,x,y,z,pause) values (%i,%i,%i,%f,%f,%f,%i)",gridid,zoneid,wpnum,xpos,ypos,zpos,pause), errbuf)) {
+	if(!RunQuery(query,MakeAnyLenString(&query,"INSERT INTO grid_entries (gridid,zoneid,`number`,x,y,z,pause,heading) values (%i,%i,%i,%f,%f,%f,%i,%f)",gridid,zoneid,wpnum,xpos,ypos,zpos,pause,heading), errbuf)) {
 		LogFile->write(EQEMuLog::Error, "Error adding waypoint '%s': '%s'", query, errbuf);
 	} else {
 		if(c) c->LogSQL(query);
@@ -1251,7 +1255,7 @@
 * the created grid is returned.
 */
 
-int32 ZoneDatabase::AddWPForSpawn(Client *c, int32 spawn2id, float xpos, float ypos, float zpos, int32 pause, int type1, int type2, int16 zoneid) {
+int32 ZoneDatabase::AddWPForSpawn(Client *c, int32 spawn2id, float xpos, float ypos, float zpos, int32 pause, int type1, int type2, int16 zoneid, float heading) {
 	char	*query = 0;
     int32	grid_num,	// The grid number the spawn is assigned to (if spawn has no grid, will be the grid number we end up creating)
 		next_wp_num;	// The waypoint number we should be assigning to the new waypoint
@@ -1323,7 +1327,7 @@
 	}
 
 	query = 0;
-	if(!RunQuery(query, MakeAnyLenString(&query,"INSERT INTO grid_entries(gridid,zoneid,`number`,x,y,z,pause) VALUES (%i,%i,%i,%f,%f,%f,%i)",grid_num,zoneid,next_wp_num,xpos,ypos,zpos,pause), errbuf)) {
+	if(!RunQuery(query, MakeAnyLenString(&query,"INSERT INTO grid_entries(gridid,zoneid,`number`,x,y,z,pause,heading) VALUES (%i,%i,%i,%f,%f,%f,%i,%f)",grid_num,zoneid,next_wp_num,xpos,ypos,zpos,pause,heading), errbuf)) {
 		LogFile->write(EQEMuLog::Error, "Error adding grid entry '%s': '%s'", query, errbuf);
 	} else {
 		if(c) c->LogSQL(query);
zone/zonedb.h
Code:
===================================================================
--- zone/zonedb.h	(revision 1520)
+++ zone/zonedb.h	(working copy)
@@ -12,6 +12,7 @@
 	float y;
 	float z;
 	int	  pause;
+	float heading;
 };
 
 #pragma pack(1)
@@ -226,8 +227,8 @@
 	void	DeleteGrid(Client *c, int32 sg2, int32 grid_num, bool grid_too,int16 zoneid);
 	void	DeleteWaypoint(Client *c, int32 grid_num, int32 wp_num,int16 zoneid);
 //	int32	AddWP(Client *c, int32 sg2, int16 grid_num, int8 wp_num, float xpos, float ypos, float zpos, int32 pause, float xpos1, float ypos1, float zpos1, int type1, int type2,int16 zoneid);
-	void	AddWP(Client *c, int32 gridid, int32 wpnum, float xpos, float ypos, float zpos, int32 pause, int16 zoneid);
-	int32	AddWPForSpawn(Client *c, int32 spawn2id, float xpos, float ypos, float zpos, int32 pause, int type1, int type2, int16 zoneid);
+	void	AddWP(Client *c, int32 gridid, int32 wpnum, float xpos, float ypos, float zpos, int32 pause, int16 zoneid, float heading);
+	int32	AddWPForSpawn(Client *c, int32 spawn2id, float xpos, float ypos, float zpos, int32 pause, int type1, int type2, int16 zoneid, float heading);
 	void	ModifyGrid(Client *c, bool remove, int32 id, int8 type = 0, int8 type2 = 0,int16 zoneid = 0);
 	void    ModifyWP(Client *c, int32 grid_id, int32 wp_num, float xpos, float ypos, float zpos, int32 script=0,int16 zoneid =0);
 	int8    GetGridType(int32 grid,int32 zoneid);
Reply With Quote