Frikbot Item desirability

Discuss Artificial Intelligence and Bot programming.
Post Reply
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Frikbot Item desirability

Post by frag.machine »

Lightning Hunter wrote:Frag Machine, I'm not sure what that's from. :P
WHAT ?! I am confiscating your nerd credentials, sir. :o
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Lightning Hunter
Posts: 169
Joined: Wed Nov 28, 2007 6:15 am

Re: Frikbot Item desirability

Post by Lightning Hunter »

Shadowborg, could you make sure I got it right this time? In particular, the code in bot_fight. I had to modify it a bit different than how you had it.
http://fbe.am/uc2

Edit: I observed the bots some more, and did in fact see them fire at buildings almost point blank range quite a few times, but not always in the direction of other bots! On a few occasions, I saw the bots fire when they were pointing toward a wall on the outside of the map, where no bots could possibly be on the other side. I think they were firing before they hand a chance to aim. In other words, maybe the bots aren't seeing other bots through walls, but instead are failing to aim before firing their weapon. Or maybe it is a combination of factors. Fragtwn4.bsp is a great map to test the RL. On the positive side of things, they no longer seem to shoot straight down at the floor!

Edit #2: In maps with lots of tight rooms and hallways, your aim code works almost flawlessly, Shadowborg. It's only large maps like Fragtown in which bots shoot themselves on buildings. Maybe it is a traceline issue? I don't know.
frag.machine wrote:
Lightning Hunter wrote:Frag Machine, I'm not sure what that's from. :P
WHAT ?! I am confiscating your nerd credentials, sir. :o
Don't worry, we still have Quake. That's nerdish enough. :wink:
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Re: Frikbot Item desirability

Post by Dr. Shadowborg »

Re: bot_fight.qc

Just replace weapon_range with this:

Code: Select all

vector(float wep) weapon_range =
{
 local vector returnvalue, grendist;
 local float heightdiff;
 
	if (wep == 4096) // IT_AXE
	 returnvalue = '48 0 64';
	else if (wep == 1) // IT_SHOTGUN
	 returnvalue = '128 8 3000';
	else if (wep == 2) // IT_SUPER_SHOTGUN
	 returnvalue = '128 0 3000';
	else if (wep == 4) // IT_NAILGUN
	 returnvalue = '180 0 3000';
	else if (wep == 8) // IT_SUPER_NAILGUN
	 returnvalue = '180 0 3000';
	else if (wep == 16) // IT_GRENADE_LAUNCHER
	  returnvalue = '180 48 600';
	else if (wep == 32) // IT_ROCKET_LAUNCHER
	 returnvalue = '180 48 3000';
	else if (wep == 64) // IT_LIGHTNING
	 returnvalue = '350 0 512';
  
  return returnvalue;
};
And it will be the same as what I have.

I'm still working on the fragtown shooting bug, I'll let you know when its fixed.
Lightning Hunter
Posts: 169
Joined: Wed Nov 28, 2007 6:15 am

Re: Frikbot Item desirability

Post by Lightning Hunter »

So all this stuff was removed from bot_fight?

Code: Select all

     if(self.enemy != world)
      {
       heightdiff = self.origin_z - self.enemy.origin_z;
       grendist = normalize(self.enemy.origin - self.origin);
      grendist = grendist * 600;
       grendist_z = grendist_z + mathlib_cos(vlen(self.enemy.origin - self.origin));
       if(vlen(grendist) > 600 && heightdiff > 0)
       {
        returnvalue_z = returnvalue_z + rint(heightdiff*2);

        if(vlen(grendist) > 600)
         returnvalue_z = 512;
       }
       dprint(ftos(rint(heightdiff)));
       dprint(" heightdiff\n");
      }
    }
Lightning Hunter
Posts: 169
Joined: Wed Nov 28, 2007 6:15 am

Re: Frikbot Item desirability

Post by Lightning Hunter »

Hey Shadowborg, I just noticed a critial bug that was introduced in your new code somehow. Bots no longer aim properly at shootable buttons. Instead, they fire off in some random direction that is not even close to the button (like at the sky or the floor). This was probably recently introduced with your aiming code!
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Re: Frikbot Item desirability

Post by Dr. Shadowborg »

Lightning Hunter wrote:So all this stuff was removed from bot_fight?

Code: Select all

     if(self.enemy != world)
      {
       heightdiff = self.origin_z - self.enemy.origin_z;
       grendist = normalize(self.enemy.origin - self.origin);
      grendist = grendist * 600;
       grendist_z = grendist_z + mathlib_cos(vlen(self.enemy.origin - self.origin));
       if(vlen(grendist) > 600 && heightdiff > 0)
       {
        returnvalue_z = returnvalue_z + rint(heightdiff*2);

        if(vlen(grendist) > 600)
         returnvalue_z = 512;
       }
       dprint(ftos(rint(heightdiff)));
       dprint(" heightdiff\n");
      }
    }
Yes, its no longer needed, grenade maxrange is 600qu. As is, that code wouldn't even properly work anymore.
Lightning Hunter wrote:Hey Shadowborg, I just noticed a critial bug that was introduced in your new code somehow. Bots no longer aim properly at shootable buttons. Instead, they fire off in some random direction that is not even close to the button (like at the sky or the floor). This was probably recently introduced with your aiming code!
Yeah, I see that. I've traced the problem down to them not setting their angle properly for some odd reason. It isn't a problem with the traceline checking code, somewhere the view just isn't being set like it should be. I'm still trying to figure out where its going wrong...
Lightning Hunter
Posts: 169
Joined: Wed Nov 28, 2007 6:15 am

Re: Frikbot Item desirability

Post by Lightning Hunter »

Dr. Shadowborg wrote: Yeah, I see that. I've traced the problem down to them not setting their angle properly for some odd reason. It isn't a problem with the traceline checking code, somewhere the view just isn't being set like it should be. I'm still trying to figure out where its going wrong...
I have a feeling if you fix it, you might also fix the problem with the bots shooting themselves randomly in Fragtown.
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Re: Frikbot Item desirability

Post by Dr. Shadowborg »

Okay, button shooting is fixed and I *think* I've fixed the wierdo fragtown shooting stuff. (doesn't help that I'd thought I had fixed it in FTE, only to find that it wasn't working right when tested in winquake. Argh. Fighting engine bugs = no fun :shock: )

Anyway, this update adds shot verification stuffs (original frikbot didn't HAVE proper LOS shot verification), so they probably won't be quite as shooty as they were in the past. Fun fact: Use of fisible in bot_shoot() basically means they will shoot at players they can see the bounding box edges of. Fragtwn4's used car lot unfortunatly has walls that make it such that you may not be able to see players, but the bots CAN.

First, in bot.qc, right below the redeclaration of mathlib_cos() add:

Code: Select all

.float dontshoot;
Next, in bot_fight.qc, within bot_fight_style, right below teammate shooting avoidance add this so that it looks like the following:

Code: Select all

			// try to avoid shooting teammates
			if (trace_ent.classname == "player")
				if ((trace_ent.team == self.team && teamplay) || (coop))
					return;
			// DRS: If dontshoot is TRUE, that means we don't have a straight line shot
			if(self.dontshoot == TRUE)
			 return;
Next, in bot_ai.qc, replace your bot_angle_set function with this:

Code: Select all

void() bot_angle_set =
{
	local float h;
	local vector view, voffset;
    local vector offset, spot1, oldview;
    local float offset_amt, dist1, dist2;
	
	if (self.enemy)
	{
		if (self.enemy.items & 524288)
			if (random() > 0.01)
				return;
		if (self.missile_speed == 0)
			self.missile_speed = 10000;
		if (self.enemy.solid == SOLID_BSP)
		{
			view = (((self.enemy.absmin + self.enemy.absmax) * 0.5)); // - self.origin
			self.dontshoot = FALSE;
            view = normalize(view - (self.origin + self.view_ofs));
		}
		else
		{
			view = self.enemy.origin;

			 // find lead point on target
			 // then traceline to it, if blocked before full dist,
			 // set targetpoint to stopped origin
			 // then trace again to check if there's a clear path to
			 // target, if not, just target enemy.origin.
			 // also, check to see if trace endpoint is within 140 qu
			 // of the bot, if so, aim at the enemy.origin, because
			 // we are looking at a wall, and that could hurt if it's a rocketlauncher
				h = vlen(view - self.origin) / self.missile_speed; // need to get the speed of projectile
				if (self.enemy.flags & FL_ONGROUND)
					view = self.enemy.velocity * h; // Aim straight at enemy, not at his feet, that will be handled later
				else
					view = (self.enemy.velocity - (sv_gravity * '0 0 1') * h) * h; // hes in the air, lead accordingly
				view = self.enemy.origin + view; // set our leadpoint
				traceline(self.enemy.origin, view, FALSE, self); // trace from enemy.origin to lead aimpoint
				view = trace_endpos; // set view origin to lead aimpoint
				traceline(self.origin + self.view_ofs, view, FALSE, self); // do a trace to view from self.
				spot1 = trace_endpos; // get trace_endpos
				dist1 = vlen(spot1 - (self.origin + self.view_ofs)); // range from self to trace
				dist2 = vlen(view - (self.origin + self.view_ofs)); // range from self to aimpoint
				if((dist1 < 140) && (dist1 != dist2)) // too close, shoot at enemy.origin
				 view = self.enemy.origin;
				else if(vlen(view - spot1) > 32 && trace_ent.takedamage == DAMAGE_NO)
				 view = self.enemy.origin; // something that can't be damaged in the way, just shoot at enemy.origin.
				 dist2 = vlen(view - (self.origin+self.view_ofs));
				 
// DRS: Tweaked Supa Aimcode (wazat inspired) below
// DRS: FIXME: Change this so that it's not so consistent...
            if(self.weapon != IT_GRENADE_LAUNCHER) // Grenade Launcher should not jitter
			 {
             if(self.b_skill == 0) 
			   offset_amt = 55;  //110
             else if (self.b_skill == 1) 
			        offset_amt = 45;  //80
             else if (self.b_skill == 2)
			   offset_amt = 36; //60
             else if (self.b_skill == 3)
			   offset_amt = 15; //0

             offset_x = crandom() * offset_amt;
             offset_y = crandom() * offset_amt;
             offset_z = crandom() * offset_amt;
			}

		    if(self.weapon == IT_GRENADE_LAUNCHER) // using grenades? Aim properly then!
            {
			   local float realrange, flitime;
			   local vector grndir;

			   grndir = normalize(view - (self.origin + self.view_ofs));//normalize(self.enemy.origin - self.origin);
			   realrange = dist2*mathlib_cos(grndir_x);
			   flitime = realrange / self.missile_speed;
			  
               view = view + '0 0 -20'; // aim at feet
			   grndir = normalize(view - (self.origin + self.view_ofs));//normalize(self.enemy.origin - self.origin);
	    	   grndir = grndir * 600;
			   grndir_z = grndir_z + (sv_gravity*flitime) * 0.3;
			   view = normalize(grndir);
			}
			if(self.weapon == IT_ROCKET_LAUNCHER && (self.enemy.flags & FL_ONGROUND)) // Rocketlauncher?  Aim at feet if they're on the ground!
			{
			 oldview = view;
			 view = view + '0 0 -20'; // aim at feet
			 traceline(self.origin + self.view_ofs, view, FALSE, self);
			  if(vlen(view - trace_endpos) > 32)
			   view = oldview;
			}
		 // DRS: Do a viability test on whether we actually should shoot or not
         if(self.enemy.solid != SOLID_BSP)
	      {
		   traceline(self.origin+self.view_ofs, view, TRUE, self);
		   if(vlen(trace_endpos - (self.origin+self.view_ofs)) < (dist2 - 32))
		    self.dontshoot = TRUE;
		   else if(vlen(trace_endpos - (self.origin+self.view_ofs)) > (dist2 + 32))
		    self.dontshoot = TRUE;
		   else self.dontshoot = FALSE;
		  }
				
		 if(self.weapon != IT_GRENADE_LAUNCHER)
           view = normalize((view + offset) - (self.origin + self.view_ofs));
		}	
		view = vectoangles(view);
		view_x = view_x * -1;
		self.b_angle = view;
	}
	else if (self.target1)
	{
		view = realorigin(self.target1);
		if (self.target1.flags & FL_ITEM)
				view = view + '0 0 48';
		view = view - (self.origin + self.view_ofs);
		view = vectoangles(view);
		view_x = view_x * -1;
		self.b_angle = view;
		self.dontshoot = TRUE;
	}
	else
	 {
      self.b_angle_x = 0;
	  self.dontshoot = TRUE;
	 }

	// HACK HACK HACK HACK
	// The bot falls off ledges a lot because of "turning around"
	// so let the bot use instant turn around when not hunting a player
	if (self.b_skill == 3)
	{
		if (self.b_angle_x < -180)
			self.b_angle_x = self.b_angle_x + 360;
		if (self.b_angle_x > 180)
			self.b_angle_x = self.b_angle_x - 360;
			
		self.keys = self.keys & 63;	
		self.v_angle = self.b_angle;
	}
	else if ((self.enemy == world || self.enemy.movetype == MOVETYPE_PUSH) && self.target1.classname != "player")
	{
		if (self.b_angle_x < -180)
			self.b_angle_x = self.b_angle_x + 360;
		if (self.b_angle_x > 180)
			self.b_angle_x = self.b_angle_x - 360;

		self.keys = self.keys & 63;
		self.v_angle = self.b_angle;
	}
	else if (self.b_skill < 1) // skill 2 handled in bot_phys
	{
		if (self.b_angle_x > 180)
			self.b_angle_x = self.b_angle_x - 360;
		self.keys = self.keys & 63;

		if (angcomp(self.b_angle_y, self.v_angle_y) > 10)
			self.keys = self.keys | KEY_LOOKLEFT;
		else if (angcomp(self.b_angle_y, self.v_angle_y) < -10)
			self.keys = self.keys | KEY_LOOKRIGHT;
		if (angcomp(self.b_angle_x, self.v_angle_x) < -10)
			self.keys = self.keys | KEY_LOOKUP;
		else if (angcomp(self.b_angle_x, self.v_angle_x) > 10)
			self.keys = self.keys | KEY_LOOKDOWN;
	}
};
Give that a try and let me know how it works out.
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Frikbot Item desirability

Post by Cobalt »

I think you mean the Realorigin () function in the FRikbot system?

I was experimenting one day on map DM2, and the bot was near the ssg where the teleporter and red armor and 200 health is near the lava. I entered via the stars heading toward the button, and the bot fired and never hit me....even if I stood still. This was because there is a BSP obstruction cutting off the view so that only partially I could be seen through the groove. I thought I altered the QC and got it working better but cant remember how. I first thought of doing (3) tracelines not just one. One for the head and one for the feet, but still not completely solving the problem.
Dr. Shadowborg wrote: Fun fact: Use of fisible in bot_shoot() basically means they will shoot at players they can see the bounding box edges of. Fragtwn4's used car lot unfortunatly has walls that make it such that you may not be able to see players, but the bots CAN.
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Re: Frikbot Item desirability

Post by Dr. Shadowborg »

Cobalt wrote:I think you mean the Realorigin () function in the FRikbot system?

I was experimenting one day on map DM2, and the bot was near the ssg where the teleporter and red armor and 200 health is near the lava. I entered via the stars heading toward the button, and the bot fired and never hit me....even if I stood still. This was because there is a BSP obstruction cutting off the view so that only partially I could be seen through the groove. I thought I altered the QC and got it working better but cant remember how. I first thought of doing (3) tracelines not just one. One for the head and one for the feet, but still not completely solving the problem.
Dr. Shadowborg wrote: Fun fact: Use of fisible in bot_shoot() basically means they will shoot at players they can see the bounding box edges of. Fragtwn4's used car lot unfortunatly has walls that make it such that you may not be able to see players, but the bots CAN.
No I mean fisible. fisible() is all that stock frikbots have in the way of shot verification ability (it only checks to see if they can see a player), but it doesn't cause them to aim at the bounding boxes. They didn't even have lead aimpoint verification, which is why they blew themselves up on maps like the fragtown series so much. (thus they will shoot, shoot, shoot away, but never actually hit you.)

My code does some amount of verification, but the "proper" way would be to fold all the checks fisible makes into bot_angle_set, not use fisible at all, and control whether the bot is allowed to shoot from bot_angle_set. (I do the latter, but not the former in this latest code revision) The problem with doing that, is that it will make the bots too good, appearing to give them knowledge of where you are all the time before you even step out into the open. As they are now, they will actually wait until they feel they have a clear shot at you.

Old AI Behavior:
Shoot at leadpoint, without regard for ability to hit said leadpoint. Results in a lot of self-detonations, misses, etc. when using RL. (also causes improper aiming of nail weapons too, because they ALWAYS aim at your feet, unless you're in the air)

Current AI behavior:
Attempt to lead target, if target lead cannot be achieved (due to something being in the way), fall back on target's actual origin, (the reasoning here being that if they go toward a wall, this will box the target in when they evade and the shots will come closer and closer, if they move away from the wall, a leadpoint may become available.) Additional checks are performed for the RL, where they will check to see if they can hit your feet if you're on the ground, GL they will always try to aim for your feet.
Lightning Hunter
Posts: 169
Joined: Wed Nov 28, 2007 6:15 am

Re: Frikbot Item desirability

Post by Lightning Hunter »

I did see your updates, in case you are wondering. I've just been too busy lately to try them out (my job is always either really slow, or really busy - and it suddenly got very busy). I will try to get around to it tonight. Thanks for the continued work on this, Shadowborg!
Lightning Hunter
Posts: 169
Joined: Wed Nov 28, 2007 6:15 am

Re: Frikbot Item desirability

Post by Lightning Hunter »

I finally got a chance to test out the new code. Overall, the bots are significantly better at aiming now! I didn't see them try to shoot through any more buildings or suicide on the floor. I did see them misjudge the edge of a building or lift a few times and kill themselves trying to shoot down over the edge, but not often enough to be a huge issue. The bots don't seem to have a range limit on how close they can shoot another bot with the RL, so they do sometimes kill themselves from splash damage being too close to another bot. However, these suicides are not much more often than the average human player, I would think. This is definitely a massive improvement over the original code, which would have a "bot was bored of life" message every 5 seconds in a match.

Do you plan to tackle any of the other bugs next? This is my current "wishlist" of all the issues I have mentioned in this thread so far:

-Teleporter bug:
-Teleporters are sometimes buggy with bots, but I'm not sure if this would be impossible to fix or not. Sometimes, bots will enter a teleporter, and somehow be on the wrong path and go back toward a waypoint they can't reach. It's hard to explain exactly what is happening, but they just don't seem to always register that they passed through a teleporter. This can be helped somewhat with the precision flag, but not always. There is a map I just waypointed recently that had a troublesome teleporter. The bots would pass through the teleporter, then run toward a waypoint on the other side of the map - colliding in to random walls along the way. I can upload that map if you want to look at this issue.
On the other hand, I was lucky enough to find a map that has the teleport bug almost 100% of the time. I'm sorry the map has to be so large (it has 6 waypoint files), but I helped you out by deleting ALL important items except a Quad damage that I added on the other side of the teleporter. you will likely see the bug within 15-30 seconds if you add a bot and follow it around using the chasecam. The bot might collect the Quad damage from the back way without teleporting, in which case you can restart the map or wait for the Quad to respawn. The teleporter that causes problems is right next to a pit of water. When bots go through this teleporter, they get confused and run to a different waypoint than the one they are supposed to. After teleporting, you will notice the bots run off a ledge, in to some water, and stare at a wall to reach a waypoint they can't get to. They do eventually reset the path, but only after they mess everything up first. I'm guessing something happens that makes them not register that they went through the teleporter, and makes them try to get to the wrong waypoint.
Download the map here:
http://fbe.am/u2b
-Spawn Radius detection for bots:
Randomized player spawning is a great feature that I believe should be kept - but I was wondering if it's at all difficult to add another feature that causes bots/players to spawn a certain distance away from other bots/players. This feature was added to NewDM, but unfortunately does not have a source code. This feature would prevent easy killing of bots that just spawned. It would also prevent the frustration of being spawn-killed by bots. The code should randomly choose a starting point, but skip any starts that are within a certain distance to bots or players (if possible).
-The navigation bug in which bots try to get to a previous waypoint after death
Well, add another bug to your list Shadowborg... I noticed that sometimes when a bot dies, it will try to get to the waypoint it was aiming for before it died, rather than resetting its path when it respawns. I think this mostly happens when they are blown up (possibly when they die in the air). I'm mentioning this bug so you can see if you spot it while you are testing the bots with these other issues. Once again though, I think the aiming bugs and other such issues take the top priority. Just keep an eye out for this one in case it's an easy fix.
-Precision mode not turning off sometimes, even though bots have passed the waypoint. I have seen it a few times in Fragtwn4, when the bots are trying to jump from one rooftop to another (I just saw it a few times watching your new aim code). The bots keep precision mode on and completely miss the jump from one rooftop to another, since their speed is too low.

-Bots using the RL to open func_secret_door (although I still haven't found a map that is a good example).
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Re: Frikbot Item desirability

Post by Dr. Shadowborg »

Glad to hear the new aim code is working out!

I'll take a look tomorrow to see if I can do anything about those last few bugs / features.
Lightning Hunter
Posts: 169
Joined: Wed Nov 28, 2007 6:15 am

Re: Frikbot Item desirability

Post by Lightning Hunter »

Dr. Shadowborg wrote:Glad to hear the new aim code is working out!

I'll take a look tomorrow to see if I can do anything about those last few bugs / features.
Thanks. :D

I think I figured out that Frikbots are not programmed to avoid the use of the RL with "Func_Door_Secret". They might be programmed to avoid using the RL to shoot buttons and other objects, but they will most definitely walk up and shoot a typical secret door with the RL (and usually at point blank range). I saw them do this multiple times in this map (I do apologize once again that it's a big map, but at least I found an example map for you):
http://fbe.am/uix
Last edited by Lightning Hunter on Fri Sep 19, 2014 11:24 pm, edited 2 times in total.
Lightning Hunter
Posts: 169
Joined: Wed Nov 28, 2007 6:15 am

Re: Frikbot Item desirability

Post by Lightning Hunter »

I noticed a very small issue with the Grenade Launcher aiming. The bots don't always seem to fire when their target is moving a lot. They will point at the target and attempt to aim, but never actually fire. I just saw a bot with a SG kill another bot with a GL, because the bot with the GL never fired once. He just kept trying to find the correct aiming. This is not a huge issue, but I think maybe the bots should be forced to fire, even if they aren't 100% sure of their aim. If there is no easy fix for this, then don't worry about it. The whole GL aim code doesn't need to be rewritten or anything to fix this, if that much work needs to be done.
Post Reply