mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-06 13:16:52 +02:00
#14 cowboy AI
This commit is contained in:
93
src/enemy.h
93
src/enemy.h
@@ -226,7 +226,7 @@ struct Enemy : Character {
|
|||||||
animation.overrideMask &= ~(1 << chest);
|
animation.overrideMask &= ~(1 << chest);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getTargetInfo(int height, vec3 *pos, float *angleX, float *angleY, float *dist) {
|
void getTargetInfo(int height, vec3 *pos, float *angleX, float *angleY, float *dist) {
|
||||||
vec3 p = waypoint;
|
vec3 p = waypoint;
|
||||||
p.y -= height;
|
p.y -= height;
|
||||||
if (pos) *pos = p;
|
if (pos) *pos = p;
|
||||||
@@ -240,7 +240,6 @@ struct Enemy : Character {
|
|||||||
if (angleX) *angleX = 0.0f;
|
if (angleX) *angleX = 0.0f;
|
||||||
if (angleY) *angleY = atan2f(b.cross(a).dot(n), a.dot(b));
|
if (angleY) *angleY = atan2f(b.cross(a).dot(n), a.dot(b));
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool targetIsVisible(float maxDist) {
|
bool targetIsVisible(float maxDist) {
|
||||||
@@ -307,7 +306,7 @@ struct Enemy : Character {
|
|||||||
void bite(int joint, const vec3 &offset, float damage) {
|
void bite(int joint, const vec3 &offset, float damage) {
|
||||||
ASSERT(target);
|
ASSERT(target);
|
||||||
target->hit(damage, this);
|
target->hit(damage, this);
|
||||||
game->addEntity(TR::Entity::BLOOD, target->getRoomIndex(), getJoint(joint) * offset);
|
game->addEntity(TR::Entity::BLOOD, target->getRoomIndex(), target->getJoint(joint) * offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mood getMoodFixed() {
|
Mood getMoodFixed() {
|
||||||
@@ -722,9 +721,6 @@ struct Lion : Enemy {
|
|||||||
if (!think(true))
|
if (!think(true))
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
float angle;
|
|
||||||
getTargetInfo(0, NULL, NULL, &angle, NULL);
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
|
|
||||||
@@ -1091,9 +1087,6 @@ struct Rat : Enemy {
|
|||||||
if (!think(false))
|
if (!think(false))
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
float angle;
|
|
||||||
getTargetInfo(0, NULL, NULL, &angle, NULL);
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
|
|
||||||
@@ -1134,9 +1127,6 @@ struct Rat : Enemy {
|
|||||||
if (!think(false))
|
if (!think(false))
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
float angle;
|
|
||||||
getTargetInfo(0, NULL, NULL, &angle, NULL);
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
|
|
||||||
@@ -1281,9 +1271,6 @@ struct Crocodile : Enemy {
|
|||||||
if (!think(true))
|
if (!think(true))
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
float angle;
|
|
||||||
getTargetInfo(0, NULL, NULL, &angle, NULL);
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
|
|
||||||
@@ -1333,9 +1320,6 @@ struct Crocodile : Enemy {
|
|||||||
if (!think(false))
|
if (!think(false))
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
float angle;
|
|
||||||
getTargetInfo(0, NULL, NULL, &angle, NULL);
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
|
|
||||||
@@ -2498,7 +2482,7 @@ struct Human : Enemy {
|
|||||||
STATE_RUN,
|
STATE_RUN,
|
||||||
STATE_AIM,
|
STATE_AIM,
|
||||||
STATE_DEATH,
|
STATE_DEATH,
|
||||||
STATE_WAIT, // == STATE_FIRE for MrT
|
STATE_WAIT, // == STATE_FIRE for MrT and Cowboy
|
||||||
STATE_FIRE
|
STATE_FIRE
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2573,9 +2557,6 @@ struct Larson : Human {
|
|||||||
if (!think(false))
|
if (!think(false))
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
float angle;
|
|
||||||
getTargetInfo(0, NULL, NULL, &angle, NULL);
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
|
|
||||||
@@ -2667,6 +2648,9 @@ struct SkaterBoy : Human {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define COWBOY_DIST_WALK (3 * 1024)
|
||||||
|
#define COWBOY_DAMAGE 70
|
||||||
|
|
||||||
struct Cowboy : Human {
|
struct Cowboy : Human {
|
||||||
|
|
||||||
Cowboy(IGame *game, int entity) : Human(game, entity, 150) {
|
Cowboy(IGame *game, int entity) : Human(game, entity, 150) {
|
||||||
@@ -2676,10 +2660,70 @@ struct Cowboy : Human {
|
|||||||
virtual void onDead() {
|
virtual void onDead() {
|
||||||
game->addEntity(TR::Entity::MAGNUMS, getRoomIndex(), pos, 0);
|
game->addEntity(TR::Entity::MAGNUMS, getRoomIndex(), pos, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int getStateGround() {
|
||||||
|
if (!think(false))
|
||||||
|
return state;
|
||||||
|
|
||||||
|
if (nextState == state)
|
||||||
|
nextState = STATE_NONE;
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
// same as Mr. T
|
||||||
|
case STATE_STOP :
|
||||||
|
if (nextState != STATE_NONE)
|
||||||
|
return nextState;
|
||||||
|
if (targetIsVisible(HUMAN_DIST_SHOT))
|
||||||
|
return STATE_AIM;
|
||||||
|
if (mood == MOOD_SLEEP)
|
||||||
|
return STATE_WALK;
|
||||||
|
return STATE_RUN;
|
||||||
|
case STATE_WALK :
|
||||||
|
if (mood == MOOD_ESCAPE || !targetInView)
|
||||||
|
nextState = STATE_RUN;
|
||||||
|
else if (targetIsVisible(HUMAN_DIST_SHOT))
|
||||||
|
nextState = STATE_AIM;
|
||||||
|
else if (targetDist > COWBOY_DIST_WALK)
|
||||||
|
nextState = STATE_RUN;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
return STATE_STOP;
|
||||||
|
case STATE_RUN :
|
||||||
|
if (mood == MOOD_ESCAPE || !targetInView)
|
||||||
|
break;
|
||||||
|
if (targetIsVisible(HUMAN_DIST_SHOT))
|
||||||
|
nextState = STATE_AIM;
|
||||||
|
else if (targetDist < COWBOY_DIST_WALK && targetInView)
|
||||||
|
nextState = STATE_WALK;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
return STATE_STOP;
|
||||||
|
case STATE_AIM :
|
||||||
|
flags.unused = 7;
|
||||||
|
if (nextState != STATE_NONE)
|
||||||
|
return STATE_STOP;
|
||||||
|
if (targetIsVisible(HUMAN_DIST_SHOT))
|
||||||
|
return STATE_WAIT; // STATE_FIRE
|
||||||
|
return STATE_STOP;
|
||||||
|
// ----
|
||||||
|
case STATE_WAIT : // STATE_FIRE
|
||||||
|
if (animation.frameIndex != flags.unused && (animation.frameIndex == 0 || animation.frameIndex == 4)) {
|
||||||
|
jointGun = (flags.unused == 7) ? 8 : 5;
|
||||||
|
doShot(COWBOY_DAMAGE, vec3(0, -40, 40));
|
||||||
|
flags.unused = animation.frameIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mood == MOOD_ESCAPE)
|
||||||
|
nextState = STATE_RUN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define MRT_DIST_WALK 4096
|
#define MRT_DIST_WALK (4 * 1024)
|
||||||
#define MRT_DAMAGE 150
|
#define MRT_DAMAGE 150
|
||||||
|
|
||||||
struct MrT : Human {
|
struct MrT : Human {
|
||||||
@@ -2700,9 +2744,6 @@ struct MrT : Human {
|
|||||||
if (!think(false))
|
if (!think(false))
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
float angle;
|
|
||||||
getTargetInfo(0, NULL, NULL, &angle, NULL);
|
|
||||||
|
|
||||||
if (nextState == state)
|
if (nextState == state)
|
||||||
nextState = STATE_NONE;
|
nextState = STATE_NONE;
|
||||||
|
|
||||||
|
@@ -1378,7 +1378,7 @@ namespace TR {
|
|||||||
return sectors + sx * zSectors + sz;
|
return sectors + sx * zSectors + sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addDynLight(int32 id, const vec4 &pos, const vec4 &color) {
|
void addDynLight(int32 id, const vec4 &pos, const vec4 &color, bool priority = false) {
|
||||||
DynLight *light = NULL;
|
DynLight *light = NULL;
|
||||||
for (int i = 0; i < dynLightsCount; i++)
|
for (int i = 0; i < dynLightsCount; i++)
|
||||||
if (dynLights[i].id == id) {
|
if (dynLights[i].id == id) {
|
||||||
@@ -1399,6 +1399,9 @@ namespace TR {
|
|||||||
light->id = id;
|
light->id = id;
|
||||||
light->pos = pos;
|
light->pos = pos;
|
||||||
light->color = color;
|
light->color = color;
|
||||||
|
|
||||||
|
if (priority && dynLights[0].id != id)
|
||||||
|
swap(dynLights[0], dynLights[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeDynLight(int32 id) {
|
void removeDynLight(int32 id) {
|
||||||
|
@@ -232,7 +232,7 @@ struct MuzzleFlash : Controller {
|
|||||||
Core::lightPos[lightIndex] = lightPos;
|
Core::lightPos[lightIndex] = lightPos;
|
||||||
Core::lightColor[lightIndex] = lightColor;
|
Core::lightColor[lightIndex] = lightColor;
|
||||||
} else
|
} else
|
||||||
getRoom().addDynLight(owner->entity, lightPos, lightColor);
|
getRoom().addDynLight(owner->entity, lightPos, lightColor, true);
|
||||||
} else {
|
} else {
|
||||||
if (lightIndex > -1) {
|
if (lightIndex > -1) {
|
||||||
ASSERT(lightIndex < MAX_LIGHTS);
|
ASSERT(lightIndex < MAX_LIGHTS);
|
||||||
|
Reference in New Issue
Block a user