Hacked NearestPoint (backward compatible)

Programming Reality Factory and Genesis3D.
Post Reply
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Hacked NearestPoint (backward compatible)

Post 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:
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Hacked NearestPoint (backward compatible)

Post 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
Pain is only psychological.
User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA

Re: Hacked NearestPoint (backward compatible)

Post 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!
Herp derp.
User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA

Re: Hacked NearestPoint (backward compatible)

Post by darksmaster923 »

you install this by throwin that code into the source and compilin, right?
Herp derp.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: Hacked NearestPoint (backward compatible)

Post 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.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

Re: Hacked NearestPoint (backward compatible)

Post 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)
1 wrote:
for the internet is a cruel and dark place at times, and there's sex and blood everywhere.

2 wrote:
You say that like it's a bad thing.

1 wrote:
You are a bad thing.
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Re: Hacked NearestPoint (backward compatible)

Post by federico »

sorry, you are right. Just override the case 183 switch in CPawlow.cpp
:wink:
Veleran
Posts: 898
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Hacked NearestPoint (backward compatible)

Post 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.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Hacked NearestPoint (backward compatible)

Post 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
Pain is only psychological.
Post Reply