Server: Some AI targeting improvements

This commit is contained in:
Steam Deck User 2022-12-22 11:44:13 -05:00
parent 950c072fa1
commit 3802fadefa
2 changed files with 69 additions and 40 deletions

View file

@ -67,44 +67,71 @@ void() Respawn =
entity(entity blarg) find_new_enemy =
{
local entity player;
local entity closest;
local float bestdist;
local float dist;
bestdist = 10000;
closest = 0;
entity targets;
entity best_target;
float best_distance;
float distance;
best_distance = 10000;
best_target = world;
if(self.classname == "ai_zombie" || self.classname == "ai_dog") {
player = find(world,classname,"monkey");
if(player) {
return player;
if (blarg.classname == "ai_zombie" || blarg.classname == "ai_dog") {
// Monkey Bomb (TODO -- if multiple, target first one thrown)
targets = find(world, classname, "monkey_bomb");
if (targets != world && blarg.classname != "ai_dog") {
best_target = targets;
return best_target;
}
player = find(world,classname,"player");
///////////////////////////////
if(!player) {
return world;
}
//////////////////////////////
while(player) {
if (player.downed == true) {
player = find(player,classname,"player");
// Now, try and find a viable player
targets = find(world, classname, "player");
while(targets != world) {
// Don't target downed players.
if (targets.downed == true) {
targets = find(targets, classname, "player");
continue;
}
dist = vlen(self.origin - player.origin);
if (dist < bestdist) {
closest = player;
bestdist = dist;
// Found one, let's see if it's closer than our last ideal target.
distance = vlen(blarg.origin - targets.origin);
if (distance < best_distance) {
best_target = targets;
best_distance = distance;
}
player = find(player,classname,"player");
// Continue iterating
targets = find(targets, classname, "player");
}
return closest;
// Return a good player if we found one.
if (best_target != world)
return best_target;
// We couldn't find a good player. How about a horde point?
targets = find(world, classname, "zombie_horde_point");
while(targets != world) {
// Found one, let's see if it's closer than our last ideal target.
distance = vlen(blarg.origin - targets.origin);
if (distance < best_distance) {
best_target = targets;
best_distance = distance;
}
// Continue iterating
targets = find(targets, classname, "zombie_horde_point");
}
// Return a horde point if we found one.
if (best_target != world)
return best_target;
}
if (self.classname != "wunder")
bprint(PRINT_HIGH, "Error: Find_New_Enemy returns world! \n");
return world;
// We didn't have much luck, just return the world.
return best_target;
};
float() avoid_zombies =
@ -605,7 +632,7 @@ float(vector start, vector min, vector max, vector end, float nomonsters, entity
#endif
void(float dist) Inside_Walk = {
if(self.enemy_timeout < time || self.enemy == world) {
if(self.enemy_timeout < time || self.enemy == world || self.enemy.downed == true) {
self.enemy_timeout = time + 5;
local entity oldEnemy;
oldEnemy = self.enemy;
@ -613,13 +640,15 @@ void(float dist) Inside_Walk = {
}
//================Check for proximity to player ===========
if(vlen(self.enemy.origin - self.origin) < 60) {
if(self.enemy.classname == "monkey") {
if(self.enemy.classname == "monkey_bomb") {
self.th_idle();
}
if(self.attack_delay < time) {
self.attack_delay = time + 1 + (1 * random());
self.th_melee();
if (self.enemy.downed == true)
self.enemy = find_new_enemy(self);
self.goalentity = self.enemy;
self.chase_time = time + 5;
}
@ -642,9 +671,9 @@ void(float dist) Inside_Walk = {
self.chase_time = 0;
}
//============= No Target ====================
if(self.goalentity == world) {//not sure when this would ever occur... but whatever.
self.goalentity = self.goaldummy;
}
//if(self.goalentity == world) {//not sure when this would ever occur... but whatever.
// self.goalentity = self.goaldummy;
//}
//============ GoalDummy is Target ============
if(self.goalentity == self.goaldummy) {
if(nearby(self.goaldummy.origin)) {

View file

@ -856,22 +856,22 @@ void() zombie_attack2;
$frame attack1 attack2 attack3 attack4 attack5
void() zombie_attackA1 =[ $attack1, zombie_attackA2 ] {self.frame = 102;SetZombieHitBox(BASE_BBOX);Zombie_Think();self.solid = SOLID_BBOX;};
void() zombie_attackA1 =[ $attack1, zombie_attackA2 ] {self.frame = 102;SetZombieHitBox(BASE_BBOX);Zombie_Think();};
void() zombie_attackA2 =[ $attack2, zombie_attackA3 ] {self.frame = 103;Zombie_Think();};
void() zombie_attackA3 =[ $attack3, zombie_attackA4 ] {self.frame = 104;Zombie_Think();};
void() zombie_attackA4 =[ $attack4, zombie_attackA5 ] {zombie_attack2();self.frame = 105;Zombie_Think();};
void() zombie_attackA5 =[ $attack5, zombie_decide ] {self.frame = 106;Zombie_Think();self.solid = SOLID_CORPSE;};
void() zombie_attackA5 =[ $attack5, zombie_decide ] {self.frame = 106;Zombie_Think();};
///////////////////////////////////////////////////////////////////////// ZOMBIE ATTACK 2// Swipe with left arm
//91-96
$frame attackb1 attackb2 attackb3 attackb4 attackb5 attackb6
void() zombie_attackB1 =[ $attackb1, zombie_attackB2 ] {self.frame = 107;SetZombieHitBox(BASE_BBOX);Zombie_Think();self.solid = SOLID_BBOX;};
void() zombie_attackB1 =[ $attackb1, zombie_attackB2 ] {self.frame = 107;SetZombieHitBox(BASE_BBOX);Zombie_Think();};
void() zombie_attackB2 =[ $attackb2, zombie_attackB3 ] {self.frame = 108;Zombie_Think();};
void() zombie_attackB3 =[ $attackb3, zombie_attackB4 ] {self.frame = 109;Zombie_Think();};
void() zombie_attackB4 =[ $attackb4, zombie_attackB5 ] {zombie_attack2(); self.frame = 110;Zombie_Think();};
void() zombie_attackB5 =[ $attackb5, zombie_attackB6 ] {self.frame = 111;Zombie_Think();};
void() zombie_attackB6 =[ $attackb6, zombie_decide ] {self.frame = 112;Zombie_Think();self.solid = SOLID_CORPSE;};
void() zombie_attackB6 =[ $attackb6, zombie_decide ] {self.frame = 112;Zombie_Think();};
void() zombie_attack =