View Single Post
  #7  
Old 09-16-2003, 12:08 PM
Scorpious2k's Avatar
Scorpious2k
Demi-God
 
Join Date: Mar 2003
Location: USA
Posts: 1,067
Default

ok, the celebration was a bit premature. yes it worked, but it was more of a band-aid than a cure. I wasn't happy with it, and felt it wasn't right. Timing pauses on npcs proved it. So I dug back in and ended up redoing a lot of the logic. It now works *perfectly*. But this is a major overhaul, not just a simple fix...

There were several problems. When spawned, the npc never paused at the first wp. The program logic actually assigned the pause time and started the timer at the time of the wp change. So the timer started at the time the npc started moving towards the next wp not when it got there. There were a few others, but who cares, right? All you want is the fix.

this is for 4.4 (of course) here it is....

in mob.h add the declaration

Code:
	void	SetWaypointPause();
in mobAI.cpp Mob::AI_Process add this var at the top

Code:
	int16 gridno;
if you added the enable timer previously discussed, get rid of it
move the following from its position near the top

Code:
	if (AIwalking_timer->Check())
	{
		timercompleted=true;
		AIwalking_timer->Disable();
	}
to immediately after the else if (roamer) and add the line gridno = this->CastToNPC()->GetGrid(); so it looks like this

Code:
		else if (roamer) 
		{
                                   if   (AIwalking_timer->Check())	
                                  {
		           	timercompleted=true;
			AIwalking_timer->Disable();
                                   }
			
                                   gridno = this->CastToNPC()->GetGrid();
at this point I should mention that I have been installing boats on the Scorpious2k server and changed the "rules" for boats. Any grid number from 1-49 is considered a boat in that it makes a single run along the grid from 1 to the end and then depops. the following code reflects that. if that causes problems for you, you will want to change it.

anway, replace the rest of Mob::AI_Process from this point down with the following so that starting at the else if (roamer) it looks like this

Code:
					else if (roamer) 
					{
						if (AIwalking_timer->Check())	// this really belongs here not at the top
						{
							timercompleted=true;
							AIwalking_timer->Disable();
						}
						
						gridno = this->CastToNPC()->GetGrid();

						if (gridno > 0)
						{
							if (timercompleted==true)	
							{
								if (gridno < 50 && cur_wp == max_wp)
								{
									printf("Depoping Ship\n");
									this->CastToNPC()->Depop();
								}
								else
								{
										timercompleted=false;
										char temp[100];
										parse->Event(7,this->GetNPCTypeID(), itoa(cur_wp,temp,10), this->CastToMob(), 0);
										CalculateNewWaypoint();
										SetAppearance(0, false);
								}
							}
							else if (!(AIwalking_timer->Enabled()) 
								&& cur_wp_x == GetX() && cur_wp_y == GetY())
							{
									SetWaypointPause();
							}
		
						}
							CalculateNewPosition(cur_wp_x, cur_wp_y, cur_wp_z, GetWalkspeed());
						}
						else if (!(GetGuardX() == 0 && GetGuardY() == 0 && GetGuardZ() == 0)) 
						{
							if (!CalculateNewPosition(GetGuardX(), GetGuardY(), GetGuardZ(), GetWalkspeed())) 
							{
								if (!GetTarget() || (GetTarget() && CalculateDistance(GetTarget()->GetX(),GetTarget()->GetY(),GetTarget()->GetZ()) >= 5) ) SetHeading(GetGuardHeading());
								else { FaceTarget(GetTarget(), true); 
							}
						}
					}
				}
			}
		} // else if (AImovement_timer->Check())
	}
in Mob::CalculateNewWaypoint remove

Code:
	
	//Declare time to wait on current WP
	
	if (cur_wp_pause == 0) {
		AIwalking_timer->Start(100);
	}
	else
	{
		
		switch (pausetype)
		{
		case 0: //Random Half
			AIwalking_timer->Start((cur_wp_pause - rand()%cur_wp_pause/2)*1000);
			break;
		case 1: //Full
			AIwalking_timer->Start(cur_wp_pause*1000);
			break;
		case 2: //Random Full
			AIwalking_timer->Start((rand()%cur_wp_pause)*1000);
			break;
		}
	}
and create a new function
Code:
void Mob::SetWaypointPause()
{
	//Declare time to wait on current WP
	
	if (cur_wp_pause == 0) {
		AIwalking_timer->Start(100);
	}
	else
	{
		
		switch (pausetype)
		{
		case 0: //Random Half
			AIwalking_timer->Start((cur_wp_pause - rand()%cur_wp_pause/2)*1000);
			break;
		case 1: //Full
			AIwalking_timer->Start(cur_wp_pause*1000);
			break;
		case 2: //Random Full
			AIwalking_timer->Start((rand()%cur_wp_pause)*1000);
			break;
		}
	}
}
That will fix the npc grid pause timing problems. It might be interesting to note that I use the fact that the timer is disabled to indicate that the npc is in transition between waypoints, so the previous "fix" will break it.

Finally in Mob::AssignWaypoints after the following
Code:
			else { //Retrieve a waypoint
				wplist * newwp = new wplist;
				adverrorinfo = 7564;
				Seperator sep(wpstruct, ' ', 4);
				newwp->x	 = atof(sep.arg[0]);
				newwp->y	 = atof(sep.arg[1]);
				newwp->z	 = atof(sep.arg[2]);
				newwp->pause = atoi(sep.arg[3]);
				newwp->index = i-2;
//				printf("New Waypoint: X: %f - Y: %f - Z: %f - P: %d - Index: %d - MaxWp: %d\n", newwp->x, newwp->y, newwp->z, newwp->pause, newwp->index, max_wp);
				if (newwp->x && newwp->y && newwp->z) {
					max_wp		 = newwp->index;
					Waypoints.AddItem(newwp);
				}
			}
add the lines

Code:
			UpdateWaypoint(0);
			SetWaypointPause();
that fixes the problem with a new spawn not pausing in the first wp

<whew>

hope I didn't forget anything... I posted this in a hurry so I could get the info out. might even be useful in 5.0. [/b]
__________________
Maybe I should try making one of these servers...
Reply With Quote