Page 1 of 1

Hacked NearestPoint (backward compatible)

Posted: Sat Mar 08, 2008 10:47 am
by federico
I've modified some script commands but I'm trying to keep them backward compatible so that old script sould work exactly in the same way.
This is a modified version of the NearestPoint command. The command search t the area specified by the Minimum and Maximum distance for a valid ScriptPoint, but chooses only a scriptpoint that starts with the word specified in an additional parameter.

Example:

Code: Select all

if(NearestPoint(0, 500, "PWAY"))
                {
                    ideal_yaw=GetYawToPoint();
                    ChangeYaw();
                }
This script finds ScriptPoint in a distance between 0 and 500 texels whose name starts with PWAY (it could be PWAY, PWAY1, PWAY2, PWAY_WHATEVER,...) and makes it the pawn current ScriptPoint.

Code: Select all

case 183:	// NearestPoint(float MinDistance, float MaxDistance)
				// NearestPoint(float MinDistance, float MaxDistance, char *PointName)
		{
			PARMCHECK(2);

			returnValue = false;
				
			//if(!TargetActor)
			//	return true;

			geEntity_EntitySet *pSet;
			geEntity *pEntity;
			// Ok, check to see if there are ScriptPoints in this world
			pSet = geWorld_GetEntitySet(CCD->World(), "ScriptPoint");
	
			if(!pSet) 
				return true;
						
			geVec3d Pos, Dist;//TargetPos, 
			float minDist2, MinDistance2, MaxDistance2;//minTargetDist2, 
			float newDist2;//, newTargetDist2;

			MinDistance2 = arguments[0].floatValue()*arguments[0].floatValue();
			MaxDistance2 = arguments[1].floatValue()*arguments[1].floatValue();
			minDist2 = MaxDistance2;
			//minTargetDist2 = minDist2*10000.f;
			
			CCD->ActorManager()->GetPosition(Actor,	&Pos);
			//CCD->ActorManager()->GetPosition(TargetActor, &TargetPos);
			
			// Ok, we have ScriptPoints somewhere.  Dig through 'em all.
			for(pEntity=geEntity_EntitySetGetNextEntity(pSet, NULL); pEntity;
				pEntity=geEntity_EntitySetGetNextEntity(pSet, pEntity)) 
			{
				ScriptPoint *pSource = (ScriptPoint*)geEntity_GetUserData(pEntity);
								
				if(arguments.entries() < 3)
				{
					//calc new dist
					geVec3d_Subtract(&pSource->origin, &Pos, &Dist);
					newDist2 = geVec3d_LengthSquared(&Dist);
					//geVec3d_Subtract(&pSource->origin, &TargetPos, &Dist);
					//newTargetDist2 = geVec3d_LengthSquared(&Dist);

					// point is too close
					if(newDist2<MinDistance2 || newDist2>MaxDistance2)
						continue;
							
					if(newDist2<minDist2)// && newTargetDist2<=minTargetDist2)
					{
						// probably slowest test... 
						if(CCD->Pawns()->CanSeePoint(FOV, Actor, &(pSource->origin), FOVBone))
						{
							minDist2 = newDist2;
							//minTargetDist2 = newTargetDist2;
							strcpy(Point, pSource->szEntityName);
							CurrentPoint= pSource->origin;
							ValidPoint = true;
							returnValue = true;
						} 
					}
				}
				else
				{
					strcpy(param0, arguments[2].str());
					int StrLength = (int)strlen(param0);
 
					char str2[64];
					strncpy (str2,pSource->szEntityName,StrLength);
					str2[StrLength]='\0';
					
					if(!stricmp(param0, str2))
					{

						//calc new dist
						geVec3d_Subtract(&pSource->origin, &Pos, &Dist);
						newDist2 = geVec3d_LengthSquared(&Dist);
						//geVec3d_Subtract(&pSource->origin, &TargetPos, &Dist);
						//newTargetDist2 = geVec3d_LengthSquared(&Dist);

						// point is too close
						if(newDist2<MinDistance2 || newDist2>MaxDistance2)
							continue;
								
						if(newDist2<minDist2)// && newTargetDist2<=minTargetDist2)
						{
							// probably slowest test... 
							//if(CCD->Pawns()->CanSeePoint(FOV, Actor, &(pSource->origin), FOVBone))
							//{
								minDist2 = newDist2;
								//minTargetDist2 = newTargetDist2;
								strcpy(Point, pSource->szEntityName);
								CurrentPoint= pSource->origin;
								ValidPoint = true;
								returnValue = true;
							//} 
						}
					}
					else
					{
						continue;
					}
				}
			}
			
			return true;
		}
I disabled the CanSee test for the points found using the name, assuming that the name is the relevant criterion. I use this command in different ways.
1.diversify the pawn's actions and paths. When the character is angry or he's attacking or is taking cover he can choose a different path.
2.This command can provide a basic pathfinding method. I have different rooms with a door in each one. My pawn is free searching the rooms for the player. When he reachs the bottom wall (where the door is) of every room, I trigger him to search for a script point (I use an hint brush flagged as 'Lava'). I placed a Point named "PWAY...." in every door passage. So the pawn heads to the door and goes in the other room. The same scriptpoint can be used also in the other direction (to return back from the other room) and I can find the door passage just when I need it, also if the pawn is nearer ro other useless scriptpoints.

I hope this could help. :wink:

Re: Hacked NearestPoint (backward compatible)

Posted: Sat Mar 08, 2008 11:49 am
by Juutis
Excellent! Little things like this really make me happy. I've been thinking of a way to make the pawn look for different paths depending on what it is doing. This makes it very easy. Another step towards a more intelligent AI. Great work! :D

Re: Hacked NearestPoint (backward compatible)

Posted: Sat Mar 08, 2008 5:44 pm
by darksmaster923
oh thats sweet!
you can make a scriptpoint called escape and make the pawn follow it if hes hurt, scriptpoint named rush if the pawn wants to rush the player!

Re: Hacked NearestPoint (backward compatible)

Posted: Wed Mar 12, 2008 6:58 pm
by darksmaster923
you install this by throwin that code into the source and compilin, right?

Re: Hacked NearestPoint (backward compatible)

Posted: Wed Mar 12, 2008 8:11 pm
by Jay
Yeah, if you know where to put it. It's in CPawnLow.cpp. You may have to search a bit until you find the 'case 183' entry. Then you just override this entry and compile.

Re: Hacked NearestPoint (backward compatible)

Posted: Wed Mar 12, 2008 8:18 pm
by fps
exelent, you dont know how many times ive gotten stuck trying to hash out an easy way to do this on my own.
Jay, are you putting this in there with your scripted projectiles, ect.. release? (btw, how is that coming along. im sort of waiting around for the next release to resume work on my project)

Re: Hacked NearestPoint (backward compatible)

Posted: Wed Mar 12, 2008 11:16 pm
by federico
sorry, you are right. Just override the case 183 switch in CPawlow.cpp
:wink:

Re: Hacked NearestPoint (backward compatible)

Posted: Fri Aug 15, 2008 2:20 pm
by Veleran
Is this command included in Rf0.76?I did nt see it in the features list.
If it will be on the future,maybe the script federico uses,can fit in generic wandering pawn bosses -or sub bosses that you can re-encounter if they escape.
I imagine federico may have placed this pawn in every level,and the pawn script is checking at the start of each level if the pawn is still alive.

Re: Hacked NearestPoint (backward compatible)

Posted: Thu Jan 08, 2009 2:28 pm
by Juutis
Since 076 didn't have this change I decided to compile RF for the first time in my life. Here ya go:
http://koti.mbnet.fi/jutkula/RF_hacked_NearestPoint.rar