Merge pull request #45 from BjossiAlfreds/fixbot-stuck

Fix for fixbots getting permanently stuck until angered
This commit is contained in:
Yamagi 2020-01-15 15:14:56 +01:00 committed by GitHub
commit 02531143e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 45 deletions

View file

@ -3167,8 +3167,6 @@ SP_object_repair(edict_t *ent)
ent->movetype = MOVETYPE_NONE; ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX; ent->solid = SOLID_BBOX;
ent->classname = "object_repair"; ent->classname = "object_repair";
VectorSet(ent->mins, -8, -8, 8);
VectorSet(ent->maxs, 8, 8, 8);
ent->think = object_repair_sparks; ent->think = object_repair_sparks;
ent->nextthink = level.time + 1.0; ent->nextthink = level.time + 1.0;
ent->health = 100; ent->health = 100;
@ -3177,5 +3175,7 @@ SP_object_repair(edict_t *ent)
{ {
ent->delay = 1.0; ent->delay = 1.0;
} }
gi.linkentity(ent);
} }

View file

@ -1031,10 +1031,11 @@ struct edict_s
void (*die)(edict_t *self, edict_t *inflictor, edict_t *attacker, void (*die)(edict_t *self, edict_t *inflictor, edict_t *attacker,
int damage, vec3_t point); int damage, vec3_t point);
float touch_debounce_time; float touch_debounce_time; /* now also used by fixbots for timeouts when getting stuck */
float pain_debounce_time; float pain_debounce_time;
float damage_debounce_time; float damage_debounce_time;
float fly_sound_debounce_time; /* now also used by insane marines to store pain sound timeout */ float fly_sound_debounce_time; /* now also used by insane marines to store pain sound timeout */
/* and by fixbots for storing object_repair timeout when getting stuck */
float last_move_time; float last_move_time;
int health; int health;

View file

@ -350,23 +350,33 @@ void
use_scanner(edict_t *self) use_scanner(edict_t *self)
{ {
edict_t *ent = NULL; edict_t *ent = NULL;
float radius = 1024;
vec3_t vec; vec3_t vec;
int len;
if (!self) if (!self)
{ {
return; return;
} }
while ((ent = findradius(ent, self->s.origin, radius)) != NULL) if (self->fly_sound_debounce_time < level.time &&
strcmp(self->goalentity->classname, "object_repair") != 0)
{ {
if (ent->health >= 100) while ((ent = findradius(ent, self->s.origin, 1024)) != NULL)
{ {
if (strcmp(ent->classname, "object_repair") == 0) if (strcmp(ent->classname, "object_repair") != 0)
{ {
if (visible(self, ent)) continue;
}
if (ent->health < 100)
{ {
continue;
}
if (!visible(self, ent))
{
continue;
}
/* remove the old one */ /* remove the old one */
if (strcmp(self->goalentity->classname, "bot_goal") == 0) if (strcmp(self->goalentity->classname, "bot_goal") == 0)
{ {
@ -376,31 +386,27 @@ use_scanner(edict_t *self)
self->goalentity = self->enemy = ent; self->goalentity = self->enemy = ent;
VectorSubtract(self->s.origin, self->goalentity->s.origin, vec); break;
len = VectorNormalize(vec);
if (len < 32)
{
self->monsterinfo.currentmove = &fixbot_move_weld_start;
return;
}
return;
}
}
} }
} }
VectorSubtract(self->s.origin, self->goalentity->s.origin, vec);
len = VectorLength(vec);
if (len < 32)
{
if (strcmp(self->goalentity->classname, "object_repair") == 0) if (strcmp(self->goalentity->classname, "object_repair") == 0)
{
VectorSubtract(self->s.origin, self->goalentity->s.origin, vec);
if (VectorLength(vec) < 56)
{ {
self->monsterinfo.currentmove = &fixbot_move_weld_start; self->monsterinfo.currentmove = &fixbot_move_weld_start;
} }
else
return;
}
if (strcmp(self->goalentity->classname, "bot_goal") == 0)
{
VectorSubtract(self->s.origin, self->goalentity->s.origin, vec);
if (VectorLength(vec) < 32)
{ {
self->goalentity->nextthink = level.time + 0.1; self->goalentity->nextthink = level.time + 0.1;
self->goalentity->think = G_FreeEdict; self->goalentity->think = G_FreeEdict;
@ -412,22 +418,29 @@ use_scanner(edict_t *self)
} }
VectorSubtract(self->s.origin, self->s.old_origin, vec); VectorSubtract(self->s.origin, self->s.old_origin, vec);
len = VectorLength(vec);
/* bot is stuck get new goalentity */ if (VectorLength(vec) > 0)
if (len == 0)
{ {
if (strcmp(self->goalentity->classname, "object_repair") == 0) self->touch_debounce_time = level.time + 1;
{
self->monsterinfo.currentmove = &fixbot_move_stand;
} }
else
if (self->touch_debounce_time < level.time)
{
/* bot is stuck, get new goalentity */
if (strcmp(self->goalentity->classname, "bot_goal") == 0)
{ {
self->goalentity->nextthink = level.time + 0.1; self->goalentity->nextthink = level.time + 0.1;
self->goalentity->think = G_FreeEdict; self->goalentity->think = G_FreeEdict;
self->goalentity = self->enemy = NULL; self->goalentity = self->enemy = NULL;
self->monsterinfo.currentmove = &fixbot_move_stand;
} }
else if (strcmp(self->goalentity->classname, "object_repair") == 0)
{
/* don't try to go for welding targets again for a while */
self->fly_sound_debounce_time = level.time + 10;
}
self->monsterinfo.currentmove = &fixbot_move_stand;
} }
} }