246 lines
No EOL
5.1 KiB
C++
246 lines
No EOL
5.1 KiB
C++
/*
|
|
=============================
|
|
xi.qc
|
|
coded by
|
|
Michael Rogers a.k.a Xsniper
|
|
ssj_xsniper@yahoo.com
|
|
http://www.xsniper.net/
|
|
|
|
Description:
|
|
XI stands for Xsniper Intelligence.
|
|
This file holds all of Xsniper Bot's Thinking Functions, better known as Artificial Intelligence.
|
|
=============================
|
|
*/
|
|
|
|
//Standing Thought
|
|
void() xi_stand =
|
|
{
|
|
local float x;
|
|
|
|
//set up x
|
|
x = 0;
|
|
|
|
//see if I'm on fire
|
|
AmBurning();
|
|
|
|
// check for liquid
|
|
check_for_liquid();
|
|
|
|
//search for monsters
|
|
search_for_monsters();
|
|
|
|
//wait around for a few seconds, then go roam around
|
|
if (time > self.pausetime)
|
|
{
|
|
//if we found an object then push us forward
|
|
if (self.object_found == 1)
|
|
{
|
|
//if we can walk forward one unit then keep walking forward
|
|
while (walkmove (self.angles_y, 1)){}
|
|
//reset our goal entity
|
|
self.goalentity = self.oldgoalentity;
|
|
}
|
|
self.nextthink = time + 0.1 + random();
|
|
self.think = self.th_walk;
|
|
}
|
|
};
|
|
|
|
//Walking Thought
|
|
void(float dist) xi_walk =
|
|
{
|
|
local float status;
|
|
|
|
// check for liquid
|
|
check_for_liquid();
|
|
|
|
if (!(self.flags & FL_ONGROUND))
|
|
return;
|
|
|
|
//check rules
|
|
CheckRules();
|
|
|
|
// find the admin if in coop mode
|
|
if (cvar("coop") > 0)
|
|
{
|
|
local entity player, tempplayer;
|
|
|
|
player = find(world, classname, "player");
|
|
|
|
while(player)
|
|
{
|
|
if (player.admin == 1)
|
|
tempplayer = player;
|
|
|
|
player = find(player, classname, "player");
|
|
}
|
|
|
|
player = tempplayer;
|
|
}
|
|
|
|
if (time > self.search_time)
|
|
{
|
|
if (cvar("coop") > 0)
|
|
self.goalentity = player;
|
|
else
|
|
self.goalentity = world;
|
|
self.waypoint = 0;
|
|
self.direction = 0;
|
|
self.object_found = 0;
|
|
}
|
|
|
|
if (self.goalentity == world)
|
|
{
|
|
//try to find a waypoint
|
|
waypoint_find();
|
|
|
|
//face our new goal entity
|
|
face_goalentity();
|
|
}
|
|
|
|
// make sure we move safely ^_^
|
|
status = move_safely();
|
|
if (status == 0) //DANGER
|
|
{
|
|
// Need to change direction (60 degrees should do it)
|
|
self.angles_y = self.angles_y + self.button1;
|
|
makevectors(self.angles);
|
|
self.flags = self.flags - (self.flags & FL_ONGROUND);
|
|
self.velocity = v_forward * (self.speed / 2); // slightly slower than normal
|
|
return;
|
|
}
|
|
else if (status == 2) // JUMPING
|
|
{
|
|
return;
|
|
}
|
|
|
|
//if we are airborne then lets drop to the floor
|
|
/*
|
|
if (!(self.flags & FL_ONGROUND))
|
|
{
|
|
if (!droptofloor())
|
|
return;
|
|
}
|
|
*/
|
|
|
|
//see if I'm on fire
|
|
AmBurning();
|
|
|
|
//search for monsters
|
|
search_for_monsters();
|
|
|
|
//if we have a waypoint then lets check for an item nearby
|
|
if (self.way_found == 1)
|
|
{
|
|
search_for_items(200);
|
|
grab_items();
|
|
}
|
|
|
|
//if there is a waypoint then lets go to it
|
|
if (visible(self.goalentity) && self.way_found == 1)
|
|
{
|
|
self.angles_y = vectoyaw(self.goalentity.origin - self.origin);
|
|
if (walkmove(self.angles_y, dist) == FALSE)
|
|
movetogoal(dist);
|
|
}
|
|
else if (!visible(self.goalentity) && self.way_found == 1)
|
|
movetogoal(dist);
|
|
else
|
|
{
|
|
//no waypoints or one isnt close by, so lets initiate our roaming code
|
|
search_for_items(500);
|
|
//make sure we don't pick up monsters or players
|
|
if (self.goalentity.monflag != "TRUE" && self.goalentity.classname != "player")
|
|
grab_items();
|
|
|
|
//move towards our goal entity
|
|
movetogoal(dist);
|
|
}
|
|
|
|
makevectors(self.angles);
|
|
self.flags = self.flags - (self.flags & FL_ONGROUND);
|
|
self.velocity = v_forward * self.speed;
|
|
|
|
//print out our current goal entity
|
|
//print_goalentity();
|
|
};
|
|
|
|
//Running Thought
|
|
void(float dist) xi_run =
|
|
{
|
|
// his fighting thoughts. after a short while, he'll give up
|
|
// on his enemy, but if he can see him, he'll always attack
|
|
|
|
// check for liquid
|
|
check_for_liquid();
|
|
|
|
if (!(self.flags & FL_ONGROUND))
|
|
return;
|
|
|
|
//print out our current goal entity
|
|
//print_goalentity();
|
|
|
|
CheckRules();
|
|
|
|
//see if I'm on fire
|
|
AmBurning();
|
|
|
|
//see if anyone else needs our help
|
|
check_monsters_enemy();
|
|
|
|
if (visible(self.enemy))
|
|
self.search_time = time + 6;
|
|
|
|
if (time > self.search_time || self.enemy.health <= 0 || self.enemy.solid == SOLID_NOT)
|
|
{
|
|
self.goalentity = self.oldgoalentity;
|
|
self.enemy = world;
|
|
self.pausetime = time + 4;
|
|
if (random() <= 0.02)
|
|
{
|
|
self.think = self.th_stand;
|
|
self.nextthink = time + 0.01;
|
|
}
|
|
else
|
|
{
|
|
self.think = self.th_walk;
|
|
self.nextthink = time + 0.01;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (visible(self.enemy) && time > self.attack_finished)
|
|
{
|
|
//pick a weapon
|
|
choose_weapon();
|
|
|
|
//make sure we have ammo
|
|
if (have_ammo() >= 1)
|
|
{
|
|
//lets execute our fighting style
|
|
execute_fighting_style();
|
|
return;
|
|
}
|
|
}
|
|
|
|
//if for some reason we get here then we better move toward our enemy
|
|
// Variable Velocity Movement System
|
|
velocity_move(dist);
|
|
};
|
|
|
|
//Jumping Thought
|
|
void() xi_jump =
|
|
{
|
|
//don't jump if we aren't standing on the ground
|
|
if (!(self.flags & FL_ONGROUND))
|
|
return;
|
|
|
|
//see if I'm on fire
|
|
AmBurning();
|
|
|
|
//lets jump forward
|
|
self.flags = self.flags - (self.flags & FL_ONGROUND);
|
|
makevectors(self.angles);
|
|
self.velocity = self.velocity + (v_forward * 250);
|
|
self.velocity_z = self.velocity_z + 250;
|
|
}; |