2019-09-21 12:29:42 -07:00
|
|
|
// ai_fight.qc: monster attack functions
|
2019-09-11 11:47:16 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
A monster is in fight mode if it thinks it can effectively attack its
|
|
|
|
enemy.
|
|
|
|
|
|
|
|
When it decides it can't attack, it goes into hunt mode.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
2019-09-20 20:24:56 -07:00
|
|
|
check_attack
|
2019-09-11 11:47:16 -07:00
|
|
|
|
|
|
|
The player is in view, so decide to move or launch an attack
|
|
|
|
Returns FALSE if movement should continue
|
|
|
|
============
|
|
|
|
*/
|
2019-09-20 20:24:56 -07:00
|
|
|
float() check_attack = {
|
2019-09-17 08:26:44 -07:00
|
|
|
vector spot1, spot2;
|
|
|
|
entity targ;
|
|
|
|
float chance;
|
2019-09-11 11:47:16 -07:00
|
|
|
|
|
|
|
targ = self.enemy;
|
|
|
|
|
|
|
|
// see if any entities are in the way of the shot
|
|
|
|
spot1 = self.origin + self.view_ofs;
|
|
|
|
spot2 = targ.origin + targ.view_ofs;
|
|
|
|
|
2019-09-20 20:24:56 -07:00
|
|
|
trace_line(spot1, spot2, FALSE, self);
|
2019-09-11 11:47:16 -07:00
|
|
|
|
|
|
|
if(trace_ent != targ) {
|
|
|
|
return FALSE; // don't have a clear shot
|
|
|
|
}
|
|
|
|
|
|
|
|
if(trace_inopen && trace_inwater) {
|
|
|
|
return FALSE; // sight line crossed contents
|
|
|
|
}
|
|
|
|
|
|
|
|
if(enemy_range == RANGE_MELEE) {
|
|
|
|
// melee attack
|
|
|
|
if(self.th_melee) {
|
|
|
|
if(self.classname == "monster_knight") {
|
|
|
|
knight_attack();
|
|
|
|
} else {
|
|
|
|
self.th_melee();
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// missile attack
|
|
|
|
if(!self.th_missile) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(time < self.attack_finished) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(enemy_range == RANGE_FAR) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(enemy_range == RANGE_MELEE) {
|
|
|
|
chance = 0.9;
|
|
|
|
self.attack_finished = 0;
|
|
|
|
} else if(enemy_range == RANGE_NEAR) {
|
|
|
|
if(self.th_melee) {
|
|
|
|
chance = 0.2;
|
|
|
|
} else {
|
|
|
|
chance = 0.4;
|
|
|
|
}
|
|
|
|
} else if(enemy_range == RANGE_MID) {
|
|
|
|
if(self.th_melee) {
|
|
|
|
chance = 0.05;
|
|
|
|
} else {
|
|
|
|
chance = 0.1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
chance = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(random() < chance) {
|
|
|
|
self.th_missile();
|
2019-09-20 20:24:56 -07:00
|
|
|
sub_attack_finished(2 * random());
|
2019-09-11 11:47:16 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ai_face
|
|
|
|
|
|
|
|
Stay facing the enemy
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void() ai_face = {
|
2019-09-20 20:24:56 -07:00
|
|
|
self.ideal_yaw = vec_yaw(self.enemy.origin - self.origin);
|
|
|
|
change_yaw();
|
2019-09-11 11:47:16 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ai_charge
|
|
|
|
|
|
|
|
The monster is in a melee attack, so get as close as possible to .enemy
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void(float d) ai_charge = {
|
|
|
|
ai_face();
|
2019-09-20 20:24:56 -07:00
|
|
|
move_to_goal(d); // done in C code...
|
2019-09-11 11:47:16 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void() ai_charge_side = {
|
2019-09-17 08:26:44 -07:00
|
|
|
vector dtemp;
|
|
|
|
float heading;
|
2019-09-11 11:47:16 -07:00
|
|
|
|
|
|
|
// aim to the left of the enemy for a flyby
|
|
|
|
|
2019-09-20 20:24:56 -07:00
|
|
|
self.ideal_yaw = vec_yaw(self.enemy.origin - self.origin);
|
|
|
|
change_yaw();
|
2019-09-11 11:47:16 -07:00
|
|
|
|
2019-09-20 20:24:56 -07:00
|
|
|
make_vectors(self.angles);
|
2019-09-11 11:47:16 -07:00
|
|
|
dtemp = self.enemy.origin - 30 * v_right;
|
2019-09-20 20:24:56 -07:00
|
|
|
heading = vec_yaw(dtemp - self.origin);
|
2019-09-11 11:47:16 -07:00
|
|
|
|
2019-09-20 20:24:56 -07:00
|
|
|
walk_move(heading, 20);
|
2019-09-11 11:47:16 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ai_melee
|
|
|
|
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void() ai_melee = {
|
2019-09-17 08:26:44 -07:00
|
|
|
vector delta;
|
|
|
|
float ldmg;
|
2019-09-11 11:47:16 -07:00
|
|
|
|
|
|
|
if(!self.enemy) {
|
|
|
|
return; // removed before stroke
|
|
|
|
}
|
|
|
|
|
|
|
|
delta = self.enemy.origin - self.origin;
|
|
|
|
|
2019-09-20 20:24:56 -07:00
|
|
|
if(vec_len(delta) > 60) {
|
2019-09-11 11:47:16 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ldmg = (random() + random() + random()) * 3;
|
2019-09-20 20:24:56 -07:00
|
|
|
ent_damage(self.enemy, self, self, ldmg);
|
2019-09-11 11:47:16 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void() ai_melee_side = {
|
2019-09-17 08:26:44 -07:00
|
|
|
vector delta;
|
|
|
|
float ldmg;
|
2019-09-11 11:47:16 -07:00
|
|
|
|
|
|
|
if(!self.enemy) {
|
|
|
|
return; // removed before stroke
|
|
|
|
}
|
|
|
|
|
|
|
|
ai_charge_side();
|
|
|
|
|
|
|
|
delta = self.enemy.origin - self.origin;
|
|
|
|
|
2019-09-20 20:24:56 -07:00
|
|
|
if(vec_len(delta) > 60) {
|
2019-09-11 11:47:16 -07:00
|
|
|
return;
|
|
|
|
}
|
2019-09-21 12:29:42 -07:00
|
|
|
if(!ent_can_damage(self.enemy, self)) {
|
2019-09-11 11:47:16 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ldmg = (random() + random() + random()) * 3;
|
2019-09-20 20:24:56 -07:00
|
|
|
ent_damage(self.enemy, self, self, ldmg);
|
2019-09-11 11:47:16 -07:00
|
|
|
};
|
|
|
|
|