Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 36 additions & 27 deletions src/g_newdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern qboolean Pickup_Health(edict_t *ent, edict_t *other);
extern qboolean Pickup_Adrenaline(edict_t *ent, edict_t *other);
extern qboolean Pickup_Armor(edict_t *ent, edict_t *other);
extern qboolean Pickup_PowerArmor(edict_t *ent, edict_t *other);
extern qboolean Pickup_Sphere(edict_t *ent, edict_t *other);
extern edict_t *Sphere_Spawn(edict_t *owner, int spawnflags);
extern void ED_CallSpawn(edict_t *ent);
void fire_doppleganger(edict_t *ent, vec3_t start, vec3_t aimdir);
Expand Down Expand Up @@ -68,6 +69,39 @@ InitGameRules(void)
}
}

/*
* These dmflag filters decide which item may be substituted IN, so they test
* the candidate item. The original tested ent->classname, the item being
* replaced, which is loop invariant and the inverse of what the comment on the
* sphere filter says: a disabled sphere respawned as itself, while every other
* item could still be substituted into one. Both passes share this predicate
* so that the counting pass and the picking pass cannot disagree on which
* items are eligible.
*/
static qboolean
SubstituteItemAllowed(const gitem_t *it)
{
/* don't respawn spheres if they're dmflag disabled. */
if (((int)dmflags->value & DF_NO_SPHERES) && (it->pickup == Pickup_Sphere))
{
return false;
}

if (((int)dmflags->value & DF_NO_NUKES) &&
!strcmp(it->classname, "ammo_nuke"))
{
return false;
}

if (((int)dmflags->value & DF_NO_MINES) &&
(!strcmp(it->classname, "ammo_prox") || !strcmp(it->classname, "ammo_tesla")))
{
return false;
}

return true;
}

const char *
FindSubstituteItem(edict_t *ent)
{
Expand Down Expand Up @@ -168,25 +202,7 @@ FindSubstituteItem(edict_t *ent)
itflags = IT_AMMO;
}

/* don't respawn spheres if they're dmflag disabled. */
if ((int)dmflags->value & DF_NO_SPHERES)
{
if (!strcmp(ent->classname, "item_sphere_vengeance") ||
!strcmp(ent->classname, "item_sphere_hunter") ||
!strcmp(ent->classname, "item_spehre_defender"))
{
continue;
}
}

if (((int)dmflags->value & DF_NO_NUKES) &&
!strcmp(ent->classname, "ammo_nuke"))
{
continue;
}

if (((int)dmflags->value & DF_NO_MINES) &&
(!strcmp(ent->classname, "ammo_prox") || !strcmp(ent->classname, "ammo_tesla")))
if (!SubstituteItemAllowed(it))
{
continue;
}
Expand Down Expand Up @@ -223,14 +239,7 @@ FindSubstituteItem(edict_t *ent)
itflags = IT_AMMO;
}

if (((int)dmflags->value & DF_NO_NUKES) &&
!strcmp(ent->classname, "ammo_nuke"))
{
continue;
}

if (((int)dmflags->value & DF_NO_MINES) &&
(!strcmp(ent->classname, "ammo_prox") || !strcmp(ent->classname, "ammo_tesla")))
if (!SubstituteItemAllowed(it))
{
continue;
}
Expand Down
8 changes: 7 additions & 1 deletion src/monster/misc/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,14 @@ SV_movestep(edict_t *ent, vec3_t move, qboolean relink)
{
if (new_bad->owner && !strcmp(new_bad->owner->classname, "tesla"))
{
/* A monster that is already angry at a tesla is left alone.
The original guarded that case with a misspelled "telsa",
so the branch never ran and the monster was retargeted at
the blocking tesla instead, which is the behaviour this
condition inherited when the chain was collapsed. */
if (!ent->enemy || !ent->enemy->inuse ||
!ent->enemy->client || !visible(ent, ent->enemy))
(strcmp(ent->enemy->classname, "tesla") &&
(!ent->enemy->client || !visible(ent, ent->enemy))))
{
TargetTesla(ent, new_bad->owner);
ent->monsterinfo.aiflags |= AI_BLOCKED;
Expand Down
Loading