Forum

Frikbots in QW?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Postby redrum » Mon Oct 18, 2010 2:19 pm

WOW!
This thread went from suck to blow!
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby Spirit » Mon Oct 18, 2010 3:26 pm

I am not a programmer nor experienced with QuakeC, but is this a bitflag operation that adds 127 (01111111) to the items bitmask?
Improve Quaddicted, send me a pull request: https://github.com/SpiritQuaddicted/Quaddicted-reviews
Spirit
 
Posts: 1031
Joined: Sat Nov 20, 2004 9:00 pm

Postby redrum » Mon Oct 18, 2010 4:14 pm

I am now more confused. :?
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby Spirit » Mon Oct 18, 2010 8:06 pm

Well, & is usually a bitwise AND.
self.items probably is a bitmask that uses 1s and 0s to toggle the presence of items.

https://secure.wikimedia.org/wikipedia/ ... _operation
https://secure.wikimedia.org/wikipedia/en/wiki/Bitmask

Your code snippet is completely out of context and "it" could stand for anything. So I really have no further clues. As I said, I am not sure if my guess is right at all. It seems reasonable though.

Check what self.items' value is. Check what 01111111 "ANDed" to it would get you. Check what items you would have then.
Improve Quaddicted, send me a pull request: https://github.com/SpiritQuaddicted/Quaddicted-reviews
Spirit
 
Posts: 1031
Joined: Sat Nov 20, 2004 9:00 pm

Postby redrum » Tue Oct 19, 2010 4:11 pm

The code was from bot_fight.qc (frikbots). Here's the whole function.

Code: Select all
void(float brange) bot_weapon_switch =
{
   local   float   it, flag, pulse;
   local vector v;

   it = self.items & 127;

   while(it)
   {
      if ((self.ammo_rockets >= 1) && (it & 32))
      {
         flag = 32;
         pulse = 7;
      }
      else if (self.waterlevel <= 1 && self.ammo_cells >= 1 && (it & 64))
      {
         flag = 64;
         pulse = 8;
      }
      else if(self.ammo_nails >= 2 && (it & 8))
      {
         flag = 8;
         pulse = 5;
      }
      else if ((self.ammo_rockets >= 1) && (it & 16))
      {
         flag = 16;
         pulse = 6;
      }
      else if(self.ammo_shells >= 2 && (it & 2))
      {
         flag = 2;
         pulse = 3;
      }
      else if(self.ammo_nails >= 1 && (it & 4))
      {
         flag = 4;
         pulse = 4;
      }
      else if(self.ammo_shells >= 1 && (it & 1))
      {
         flag = 1;
         pulse = 2;
      }
      else
      {
         if (pulse)
            self.impulse = pulse;
         return;
      }

      if (brange == -1)
      {
         if (pulse)
            self.impulse = pulse;
         return;
      }

      v = weapon_range(flag);
      if (brange < v_y || brange > v_z)
         it = it - flag;
      else
      {
         if (pulse)
            self.impulse = pulse;
         return;
      }
   }
};
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby FrikaC » Thu Oct 21, 2010 5:09 pm

So this code only looks at the weapons 1, 2, 4, 8, 16, 32 and 64 (hence items & 127, add all those numbers up and you get 127)

So the first line there it = self.items & 127, self items is what items the bot (self) has filtered by just the weapons we care about. The axe is 4096 thus is never considered by this function.

It then takes the filtered value (if there are no weapons at all, the value would be zero) then looks at each ammo type and if the bot has the weapon. If he's not in a valid range to use the weapon, it is subtracted from "it" then it loops again. This function could be written way better...
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Postby redrum » Fri Oct 22, 2010 3:57 am

So does that mean that the bot must have all the weapons for the function to work correctly?
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby frag.machine » Fri Oct 22, 2010 11:43 am

No, this means the bot needs AT LEAST one of the weapons, and as is, it will NEVER uses the axe.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby redrum » Tue Oct 26, 2010 2:57 am

OK, if I add 4096 it will then include the axe right?
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby frag.machine » Tue Oct 26, 2010 12:15 pm

redrum wrote:OK, if I add 4096 it will then include the axe right?


Yeah, but for the sake of clarity, I'd suggest to do something like this:

Code: Select all
local float mask = IT_AXE + (All the IT_* weapons constants you want enable your bot to use);

it = self.items & mask;


This way, anyone who looks your code can quickly understand what's going on - including you, in about 6 months from now ;)
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby redrum » Tue Oct 26, 2010 2:25 pm

LOL, Thanks!
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Previous

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest