mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-08 06:06:51 +02:00
fixed AI
This commit is contained in:
95
src/enemy.h
95
src/enemy.h
@@ -60,7 +60,6 @@ struct Enemy : Character {
|
|||||||
uint16 targetBox;
|
uint16 targetBox;
|
||||||
vec3 waypoint;
|
vec3 waypoint;
|
||||||
|
|
||||||
float thinkTime;
|
|
||||||
float length; // dist from center to head (jaws)
|
float length; // dist from center to head (jaws)
|
||||||
float aggression;
|
float aggression;
|
||||||
int radius;
|
int radius;
|
||||||
@@ -76,7 +75,7 @@ struct Enemy : Character {
|
|||||||
bool targetFromView; // enemy in target view zone
|
bool targetFromView; // enemy in target view zone
|
||||||
bool targetCanAttack;
|
bool targetCanAttack;
|
||||||
|
|
||||||
Enemy(IGame *game, int entity, float health, int radius, float length, float aggression) : Character(game, entity, health), ai(AI_RANDOM), mood(MOOD_SLEEP), wound(false), nextState(0), targetBox(TR::NO_BOX), thinkTime(1.0f / 30.0f), length(length), aggression(aggression), radius(radius), hitSound(-1), target(NULL), path(NULL) {
|
Enemy(IGame *game, int entity, float health, int radius, float length, float aggression) : Character(game, entity, health), ai(AI_RANDOM), mood(MOOD_SLEEP), wound(false), nextState(0), targetBox(TR::NO_BOX), length(length), aggression(aggression), radius(radius), hitSound(-1), target(NULL), path(NULL) {
|
||||||
targetDist = +INF;
|
targetDist = +INF;
|
||||||
targetInView = targetFromView = targetCanAttack = false;
|
targetInView = targetFromView = targetCanAttack = false;
|
||||||
waypoint = pos;
|
waypoint = pos;
|
||||||
@@ -329,12 +328,7 @@ struct Enemy : Character {
|
|||||||
return brave ? MOOD_STALK : mood;
|
return brave ? MOOD_STALK : mood;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool think(bool fixedLogic) {
|
void think(bool fixedLogic) {
|
||||||
thinkTime += Core::deltaTime;
|
|
||||||
if (thinkTime < 1.0f / 30.0f)
|
|
||||||
return false;
|
|
||||||
thinkTime -= 1.0f / 30.0f;
|
|
||||||
|
|
||||||
int zoneOld = zone;
|
int zoneOld = zone;
|
||||||
updateZone();
|
updateZone();
|
||||||
|
|
||||||
@@ -426,8 +420,6 @@ struct Enemy : Character {
|
|||||||
if (fabsf(d.x) < 512 && fabsf(d.y) < 512 && fabsf(d.z) < 512)
|
if (fabsf(d.x) < 512 && fabsf(d.y) < 512 && fabsf(d.z) < 512)
|
||||||
nextWaypoint();
|
nextWaypoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void nextWaypoint() {
|
void nextWaypoint() {
|
||||||
@@ -585,8 +577,7 @@ struct Wolf : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -731,8 +722,7 @@ struct Lion : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -844,9 +834,8 @@ struct Gorilla : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
|
|
||||||
@@ -1097,8 +1086,7 @@ struct Rat : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -1137,8 +1125,7 @@ struct Rat : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateOnwater() {
|
virtual int getStateOnwater() {
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -1281,8 +1268,7 @@ struct Crocodile : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -1330,8 +1316,7 @@ struct Crocodile : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateUnderwater() {
|
virtual int getStateUnderwater() {
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -1439,8 +1424,7 @@ struct Bear : Enemy {
|
|||||||
if (!flags.active)
|
if (!flags.active)
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -1574,8 +1558,7 @@ struct Bat : Enemy {
|
|||||||
return STATE_AWAKE;
|
return STATE_AWAKE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case STATE_AWAKE : return STATE_FLY;
|
case STATE_AWAKE : return STATE_FLY;
|
||||||
@@ -1661,8 +1644,7 @@ struct Rex : Enemy {
|
|||||||
if (!flags.active)
|
if (!flags.active)
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -1776,8 +1758,7 @@ struct Raptor : Enemy {
|
|||||||
if (!flags.active)
|
if (!flags.active)
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -1935,8 +1916,7 @@ struct Mutant : Enemy {
|
|||||||
stepHeight = 256;
|
stepHeight = 256;
|
||||||
dropHeight = -stepHeight;
|
dropHeight = -stepHeight;
|
||||||
|
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -2057,8 +2037,7 @@ struct Mutant : Enemy {
|
|||||||
stepHeight = 30 * 1024;
|
stepHeight = 30 * 1024;
|
||||||
dropHeight = -stepHeight;
|
dropHeight = -stepHeight;
|
||||||
|
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if ((flags.unused & FLAG_FLY) && mood != MOOD_ESCAPE && zone == target->zone)
|
if ((flags.unused & FLAG_FLY) && mood != MOOD_ESCAPE && zone == target->zone)
|
||||||
flags.unused &= ~FLAG_FLY;
|
flags.unused &= ~FLAG_FLY;
|
||||||
@@ -2168,8 +2147,7 @@ struct GiantMutant : Enemy {
|
|||||||
if (health <= 0)
|
if (health <= 0)
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (!target || target->health <= 0.0f)
|
if (!target || target->health <= 0.0f)
|
||||||
return STATE_STOP;
|
return STATE_STOP;
|
||||||
@@ -2305,8 +2283,7 @@ struct Centaur : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -2412,8 +2389,7 @@ struct Mummy : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2486,8 +2462,7 @@ struct Doppelganger : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2568,8 +2543,7 @@ struct Human : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2614,8 +2588,7 @@ struct Larson : Human {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
fullChestRotation = state == STATE_FIRE || state == STATE_AIM;
|
fullChestRotation = state == STATE_FIRE || state == STATE_AIM;
|
||||||
|
|
||||||
@@ -2698,8 +2671,7 @@ struct Pierre : Human {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (!flags.once && health <= PIERRE_MIN_HEALTH) {
|
if (!flags.once && health <= PIERRE_MIN_HEALTH) {
|
||||||
health = PIERRE_MIN_HEALTH;
|
health = PIERRE_MIN_HEALTH;
|
||||||
@@ -2823,8 +2795,7 @@ struct SkaterBoy : Human {
|
|||||||
};
|
};
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
fullChestRotation = state == STATE_STAND_FIRE || state == STATE_MOVE_FIRE;
|
fullChestRotation = state == STATE_STAND_FIRE || state == STATE_MOVE_FIRE;
|
||||||
|
|
||||||
@@ -2894,8 +2865,7 @@ struct Cowboy : Human {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
fullChestRotation = state == STATE_WAIT || state == STATE_AIM;
|
fullChestRotation = state == STATE_WAIT || state == STATE_AIM;
|
||||||
|
|
||||||
@@ -2973,8 +2943,7 @@ struct MrT : Human {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
fullChestRotation = state == STATE_WAIT || state == STATE_AIM;
|
fullChestRotation = state == STATE_WAIT || state == STATE_AIM;
|
||||||
|
|
||||||
@@ -3072,8 +3041,7 @@ struct Natla : Human {
|
|||||||
dropHeight *= 80;
|
dropHeight *= 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
timer += Core::deltaTime;
|
timer += Core::deltaTime;
|
||||||
bool canShot = target && target->health > 0.0f && targetIsVisible(HUMAN_DIST_SHOT);
|
bool canShot = target && target->health > 0.0f && targetIsVisible(HUMAN_DIST_SHOT);
|
||||||
@@ -3135,8 +3103,7 @@ struct Natla : Human {
|
|||||||
dropHeight = -256;
|
dropHeight = -256;
|
||||||
flying = false;
|
flying = false;
|
||||||
|
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
timer += Core::deltaTime;
|
timer += Core::deltaTime;
|
||||||
bool canShot = target && target->health > 0.0f && fabsf(targetAngle) < NATLA_FIRE_ANGLE && targetIsVisible(HUMAN_DIST_SHOT);
|
bool canShot = target && target->health > 0.0f && fabsf(targetAngle) < NATLA_FIRE_ANGLE && targetIsVisible(HUMAN_DIST_SHOT);
|
||||||
@@ -3287,8 +3254,7 @@ struct Tiger : Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual int getStateGround() {
|
virtual int getStateGround() {
|
||||||
if (!think(true))
|
think(true);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
@@ -3430,8 +3396,7 @@ struct Winston : Enemy {
|
|||||||
return STATE_STOP;
|
return STATE_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!think(false))
|
think(false);
|
||||||
return state;
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
|
Reference in New Issue
Block a user