Server: Minor scripted_sequence pathfinding improvements, add support

for m_flChaseSpeed for CBaseMonster...
This commit is contained in:
Marco Cawthorne 2020-11-23 21:39:40 +01:00
parent 9245ae809b
commit a9d87aa590
12 changed files with 72 additions and 159 deletions

View file

@ -119,6 +119,9 @@ CBaseMonster::SeeThink(void)
void
CBaseMonster::AttackThink(void)
{
if (m_iSequenceState != SEQUENCESTATE_NONE)
return;
if (m_flAttackThink > time) {
return;
}
@ -262,9 +265,23 @@ CBaseMonster::CheckRoute(void)
flDist = floor(vlen(evenpos - origin));
if (flDist < 8) {
dprint(sprintf("^2CBaseMonster::^3CheckRoute^7: %s reached node\n", this.targetname));
dprint(sprintf("^2CBaseMonster::^3CheckRoute^7: " \
"%s reached node\n", this.targetname));
m_iCurNode--;
velocity = [0,0,0]; /* clamp friction */
/* we've still traveling and from this node we may be able to walk
* directly to our end-destination */
if (m_iCurNode > -1) {
tracebox(origin, mins, maxs, m_vecLastNode, MOVE_NORMAL, this);
/* can we walk directly to our target destination? */
if (trace_fraction == 1.0) {
dprint("^2CBaseMonster::^3CheckRoute^7: " \
"Walking directly to last node\n");
m_iCurNode = -1;
}
}
}
if (m_iCurNode < -1) {
@ -326,7 +343,7 @@ CBaseMonster::WalkRoute(void)
} else if (m_iMState == MONSTER_CHASING) {
/* we've got 'em in our sights, just need to walk closer */
endangles = vectoangles(m_eEnemy.origin - origin);
input_movevalues = [140, 0, 0];
input_movevalues = [m_flChaseSpeed, 0, 0];
m_vecTurnAngle[1] = endangles[1];
} else {
return;
@ -335,6 +352,7 @@ CBaseMonster::WalkRoute(void)
/* functional */
input_angles[1] = v_angle[1] = m_vecTurnAngle[1];
#if 1
/* cosmetic */
vector new_ang;
vector old_ang;
@ -342,12 +360,13 @@ CBaseMonster::WalkRoute(void)
makevectors(m_vecTurnAngle);
new_ang = v_forward;
makevectors(angles);
old_ang = v_forward;
old_ang = v_forward;
tmp[0] = Math_Lerp(old_ang[0], new_ang[0], frametime * 5);
tmp[1] = Math_Lerp(old_ang[1], new_ang[1], frametime * 5);
tmp[2] = Math_Lerp(old_ang[2], new_ang[2], frametime * 5);
angles = vectoangles(tmp);
#endif
}
void
@ -429,8 +448,11 @@ CBaseMonster::Physics(void)
input_angles = v_angle = angles = m_vecSequenceAngle;
SetFrame(m_flSequenceEnd);
} else if (movetype == MOVETYPE_WALK) {
SeeThink();
AttackThink();
if (m_iSequenceState == SEQUENCESTATE_NONE) {
SeeThink();
AttackThink();
}
CheckRoute();
WalkRoute();
runstandardplayerphysics(this);
@ -568,4 +590,5 @@ CBaseMonster::CBaseMonster(void)
/* give us a 65 degree view cone */
m_flFOV = 1.0 / 65;
m_flChaseSpeed = 140;
}

View file

@ -76,6 +76,8 @@ class CBaseMonster:CBaseEntity
vector base_maxs;
int base_health;
float m_flChaseSpeed;
/* sequences */
string m_strRouteEnded;
int m_iSequenceRemove;

View file

@ -268,7 +268,7 @@ CBaseNPC::FollowPlayer(void)
if (vlen(m_eFollowingChain.origin - origin) > 1024) {
m_eFollowing = world;
} else if (vlen(m_eFollowingChain.origin - origin) > 64) {
input_movevalues[0] = 240;
input_movevalues[0] = m_flChaseSpeed;
other = world;
traceline(origin, m_eFollowingChain.origin, MOVE_OTHERONLY, this);
@ -363,7 +363,7 @@ CBaseNPC::Physics(void)
input_angles = v_angle;
if (m_iSequenceState != SEQUENCESTATE_NONE) {
m_eFollowing = __NULL__;
m_eEnemy = m_eFollowing = __NULL__;
}
/* override whatever we did above with this */
@ -372,21 +372,23 @@ CBaseNPC::Physics(void)
SetFrame(m_flSequenceEnd);
} else {
if (style != MONSTER_DEAD) {
SeeThink();
AttackThink();
TalkPlayerGreet();
FollowChain();
if (m_iSequenceState == SEQUENCESTATE_NONE) {
SeeThink();
AttackThink();
TalkPlayerGreet();
FollowChain();
if (m_eFollowing != world) {
FollowPlayer();
input_angles = angles = v_angle;
} else if (m_iFlags & MONSTER_FEAR) {
PanicFrame();
} else {
if (random() < 0.5) {
TalkPlayerAsk();
if (m_eFollowing != world) {
FollowPlayer();
input_angles = angles = v_angle;
} else if (m_iFlags & MONSTER_FEAR) {
PanicFrame();
} else {
TalkPlayerIdle();
if (random() < 0.5) {
TalkPlayerAsk();
} else {
TalkPlayerIdle();
}
}
}

View file

@ -272,22 +272,8 @@ CSGameRules::LevelNewParms(void)
void
CSGameRules::PlayerConnect(base_player pl)
{
entity a;
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
int playercount = 0;
for (a = world; (a = find(a, ::classname, "player"));) {
playercount++;
}
/* we're the first. respawn all entities? */
if (playercount == 0) {
for (a = world; (a = findfloat(a, ::identity, 1));) {
CBaseEntity caw = (CBaseEntity)a;
caw.Respawn();
}
Nodes_Init();
}
if (Plugin_PlayerConnect(pl) == FALSE)
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
}
void

View file

@ -32,12 +32,25 @@ void StartFrame(void)
void ClientConnect(float csqc_active)
{
int playercount = 0;
/* make sure you never change the classname. ever. */
if (self.classname != "player") {
spawnfunc_player();
}
g_grMode.PlayerConnect((base_player)self);
for (entity a = world; (a = find(a, ::classname, "player"));)
playercount++;
/* we're the only one. respawn all entities */
if (playercount == 1) {
for (entity a = world; (a = findfloat(a, ::identity, 1));) {
CBaseEntity caw = (CBaseEntity)a;
caw.Respawn();
}
Nodes_Init();
}
}
void ClientDisconnect(void)

View file

@ -234,22 +234,8 @@ HLGameRules::LevelChangeParms(base_player pp)
void
HLGameRules::PlayerConnect(base_player pl)
{
entity a;
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
int playercount = 0;
for (a = world; (a = find(a, ::classname, "player"));) {
playercount++;
}
/* we're the first. respawn all entities? */
if (playercount == 0) {
for (a = world; (a = findfloat(a, ::identity, 1));) {
CBaseEntity caw = (CBaseEntity)a;
caw.Respawn();
}
Nodes_Init();
}
if (Plugin_PlayerConnect(pl) == FALSE)
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
}
void

View file

@ -199,20 +199,6 @@ HLGameRules::PlayerConnect(base_player pl)
{
entity a;
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
int playercount = 0;
for (a = world; (a = find(a, ::classname, "player"));) {
playercount++;
}
/* we're the first. respawn all entities? */
if (playercount == 0) {
for (a = world; (a = findfloat(a, ::identity, 1));) {
CBaseEntity caw = (CBaseEntity)a;
caw.Respawn();
}
Nodes_Init();
}
}
void

View file

@ -212,22 +212,8 @@ HLGameRules::PlayerPostFrame(base_player pp)
void
HLGameRules::PlayerConnect(base_player pl)
{
entity a;
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
int playercount = 0;
for (a = world; (a = find(a, ::classname, "player"));) {
playercount++;
}
/* we're the first. respawn all entities? */
if (playercount == 0) {
for (a = world; (a = findfloat(a, ::identity, 1));) {
CBaseEntity caw = (CBaseEntity)a;
caw.Respawn();
}
Nodes_Init();
}
if (Plugin_PlayerConnect(pl) == FALSE)
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
}
void

View file

@ -335,22 +335,8 @@ SHMultiplayerRules::PlayerPostFrame(base_player pp)
void
SHMultiplayerRules::PlayerConnect(base_player pl)
{
entity a;
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
int playercount = 0;
for (a = world; (a = find(a, ::classname, "player"));) {
playercount++;
}
/* we're the first. respawn all entities? */
if (playercount == 0) {
for (a = world; (a = findfloat(a, ::identity, 1));) {
CBaseEntity caw = (CBaseEntity)a;
caw.Respawn();
}
Nodes_Init();
}
if (Plugin_PlayerConnect(pl) == FALSE)
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
}
void

View file

@ -318,7 +318,6 @@ class monster_scientist:CBaseNPC
virtual void(void) touch;
virtual void(void) Hide;
virtual void(void) Respawn;
virtual void(void) PlayerUse;
virtual void(void) Pain;
virtual void(void) Death;
virtual void(void) Physics;
@ -532,32 +531,6 @@ void monster_scientist::touch(void)
}
}
void monster_scientist::PlayerUse(void)
{
int r;
if (m_iFlags & SCIF_FEAR) {
return;
}
if ((m_eUser == world)) {
if (!(m_iFlags & SCIF_USED)) {
m_iFlags |= SCIF_USED;
}
r = floor(random(0,sci_snduse.length));
Speak(sci_snduse[r]);
m_eUser = eActivator;
m_eRescuer = m_eUser;
m_vecLastUserPos = m_eUser.origin;
} else {
r = floor(random(0,sci_snduseno.length));
Speak(sci_snduseno[r]);
m_eUser = world;
}
}
void monster_scientist::Pain(void)
{
if (style == MONSTER_DEAD) {
@ -653,7 +626,7 @@ void monster_scientist::Respawn(void)
style = MONSTER_IDLE;
health = 50;
velocity = [0,0,0];
m_iFlags = 0x0;
m_iFlags = MONSTER_CANFOLLOW;
m_eUser = world;
customphysics = Physics;
@ -700,7 +673,7 @@ void monster_scientist::monster_scientist(void)
}
model = "models/scientist.mdl";
CBaseEntity::CBaseEntity();
CBaseNPC::CBaseNPC();
precache_model(m_oldModel);
if (m_iBody == -1) {

View file

@ -130,22 +130,8 @@ TFCGameRules::LevelNewParms(void)
void
TFCGameRules::PlayerConnect(base_player pl)
{
entity a;
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
int playercount = 0;
for (a = world; (a = find(a, ::classname, "player"));) {
playercount++;
}
/* we're the first. respawn all entities? */
if (playercount == 0) {
for (a = world; (a = findfloat(a, ::identity, 1));) {
CBaseEntity caw = (CBaseEntity)a;
caw.Respawn();
}
Nodes_Init();
}
if (Plugin_PlayerConnect(pl) == FALSE)
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
}
void

View file

@ -211,24 +211,8 @@ HLGameRules::PlayerPostFrame(base_player pl)
void
HLGameRules::PlayerConnect(base_player pl)
{
entity a;
if (Plugin_PlayerConnect(pl) == FALSE)
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
int playercount = 0;
for (a = world; (a = find(a, ::classname, "player"));) {
playercount++;
}
/* we're the first. respawn all entities? */
if (playercount == 0) {
for (a = world; (a = findfloat(a, ::identity, 1));) {
CBaseEntity caw = (CBaseEntity)a;
caw.Respawn();
}
Nodes_Init();
}
}
void