mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-17 10:30:47 +02:00
fixed #53 check for enemy-enemy collisions, stalking mode if player is out of enemy zone
This commit is contained in:
30
src/enemy.h
30
src/enemy.h
@@ -155,12 +155,36 @@ struct Enemy : Character {
|
|||||||
if (pz != nz) pos.z = float(nz);
|
if (pz != nz) pos.z = float(nz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void collideEnemies() {
|
||||||
|
if (getEntity().isBigEnemy())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Controller *c = Controller::first;
|
||||||
|
while (c) {
|
||||||
|
if (c != this && c->getEntity().isEnemy()) {
|
||||||
|
Enemy *enemy = (Enemy*)c;
|
||||||
|
if (enemy->health > 0.0f) {
|
||||||
|
vec3 dir = vec3(enemy->pos.x - pos.x, 0.0f, enemy->pos.z - pos.z);
|
||||||
|
float D = dir.length2();
|
||||||
|
float R = enemy->radius + radius;
|
||||||
|
if (D < R * R) {
|
||||||
|
D = sqrt(D);
|
||||||
|
pos -= dir.normal() * (R - D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c = c->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void updatePosition() {
|
virtual void updatePosition() {
|
||||||
if (!flags.active) return;
|
if (!flags.active) return;
|
||||||
|
|
||||||
vec3 p = pos;
|
vec3 p = pos;
|
||||||
pos += velocity * (30.0f * Core::deltaTime);
|
pos += velocity * (30.0f * Core::deltaTime);
|
||||||
|
|
||||||
|
collideEnemies();
|
||||||
|
|
||||||
clipByBox(pos);
|
clipByBox(pos);
|
||||||
|
|
||||||
TR::Level::FloorInfo info;
|
TR::Level::FloorInfo info;
|
||||||
@@ -339,12 +363,12 @@ struct Enemy : Character {
|
|||||||
|
|
||||||
int targetBoxOld = targetBox;
|
int targetBoxOld = targetBox;
|
||||||
|
|
||||||
if (target->health <= 0.0f)
|
bool inZone = zone == target->zone;
|
||||||
|
|
||||||
|
if (target->health <= 0.0f || !inZone)
|
||||||
targetBox = -1;
|
targetBox = -1;
|
||||||
|
|
||||||
// update mood
|
// update mood
|
||||||
bool inZone = zone == target->zone;
|
|
||||||
|
|
||||||
if (mood != MOOD_ATTACK && targetBox > -1 && !checkBox(targetBox)) {
|
if (mood != MOOD_ATTACK && targetBox > -1 && !checkBox(targetBox)) {
|
||||||
if (!inZone)
|
if (!inZone)
|
||||||
mood = MOOD_SLEEP;
|
mood = MOOD_SLEEP;
|
||||||
|
Reference in New Issue
Block a user