Frikbots in QW?
Moderator: InsideQC Admins
26 posts
• Page 2 of 2 • 1, 2
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
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.
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
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
-

redrum - Posts: 410
- Joined: Wed Mar 28, 2007 11:35 pm
- Location: Long Island, New York
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...
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
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)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 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)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
26 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 1 guest