game: support of item_invisibility

This commit is contained in:
Denis Pauk 2024-10-15 23:58:51 +03:00
parent d9de3ea0df
commit 4f1e668eb7
6 changed files with 99 additions and 0 deletions

View file

@ -434,6 +434,18 @@ visible(edict_t *self, edict_t *other)
return false;
}
/*
* [Paril-KEX] bit of a hack, but we'll tweak monster-player visibility
* if they have the invisibility powerup.
*/
if (other->client)
{
if (other->client->invisible_framenum > level.framenum)
{
return false;
}
}
VectorCopy(self->s.origin, spot1);
spot1[2] += self->viewheight;
VectorCopy(other->s.origin, spot2);
@ -761,6 +773,13 @@ FindTarget(edict_t *self)
return false;
}
}
if ((self->enemy->client) &&
(self->enemy->client->invisible_framenum > level.framenum))
{
self->enemy = NULL;
return false;
}
}
}
else /* heardit */
@ -870,6 +889,14 @@ M_CheckAttack(edict_t *self)
if (self->enemy->health > 0)
{
if (self->enemy->client)
{
if (self->enemy->client->invisible_framenum > level.framenum)
{
return false;
}
}
/* see if any entities are in the way of the shot */
VectorCopy(self->s.origin, spot1);
spot1[2] += self->viewheight;

View file

@ -1059,6 +1059,28 @@ Use_Invulnerability(edict_t *ent, gitem_t *item)
"items/protect.wav"), 1, ATTN_NORM, 0);
}
void
Use_Invisibility(edict_t *ent, gitem_t *item)
{
if (!ent || !item)
{
return;
}
ent->client->pers.inventory[ITEM_INDEX(item)]--;
if (ent->client->invisible_framenum > level.framenum)
{
ent->client->invisible_framenum += 300;
}
else
{
ent->client->invisible_framenum = level.framenum + 300;
}
gi.sound(ent, CHAN_ITEM, gi.soundindex("items/protect.wav"), 1, ATTN_NORM, 0);
}
/* ====================================================================== */
void
@ -3304,6 +3326,31 @@ static const gitem_t gameitemlist[] = {
"items/protect.wav items/protect2.wav items/protect4.wav"
},
/*
* QUAKED item_invisibility (.3 .3 1) (-16 -16 -16) (16 16 16)
*/
{
"item_invisibility",
Pickup_Powerup,
Use_Invisibility,
Drop_General,
NULL,
"items/pkup.wav",
"models/items/cloaker/tris.md2",
EF_ROTATE,
NULL,
"p_cloaker",
"Invisibility",
2,
300,
NULL,
IT_POWERUP,
0,
NULL,
0,
NULL,
},
/*
* QUAKED item_silencer (.3 .3 1) (-16 -16 -16) (16 16 16) TRIGGER_SPAWN
*/

View file

@ -1259,6 +1259,7 @@ struct gclient_s
/* powerup timers */
float quad_framenum;
float invincible_framenum;
float invisible_framenum;
float breather_framenum;
float enviro_framenum;

View file

@ -1125,6 +1125,7 @@ player_die(edict_t *self, edict_t *inflictor, edict_t *attacker,
/* remove powerups */
self->client->quad_framenum = 0;
self->client->invincible_framenum = 0;
self->client->invisible_framenum = 0;
self->client->breather_framenum = 0;
self->client->enviro_framenum = 0;
self->flags &= ~FL_POWER_ARMOR;

View file

@ -61,6 +61,7 @@ MoveClientToIntermission(edict_t *ent)
/* clean up powerup info */
ent->client->quad_framenum = 0;
ent->client->invincible_framenum = 0;
ent->client->invisible_framenum = 0;
ent->client->breather_framenum = 0;
ent->client->enviro_framenum = 0;
ent->client->grenade_blew_up = false;
@ -557,6 +558,13 @@ G_SetStats(edict_t *ent)
ent->client->ps.stats[STAT_TIMER] =
(ent->client->invincible_framenum - level.framenum) / 10;
}
else if (ent->client->invisible_framenum > level.framenum)
{
ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex(
"p_cloaker");
ent->client->ps.stats[STAT_TIMER] =
(ent->client->invisible_framenum - level.framenum) / 10;
}
else if (ent->client->enviro_framenum > level.framenum)
{
ent->client->ps.stats[STAT_TIMER_ICON] = gi.imageindex("p_envirosuit");

View file

@ -665,6 +665,21 @@ SV_CalcBlend(edict_t *ent)
SV_AddBlend(1, 1, 0, 0.08, ent->client->ps.blend);
}
}
else if (ent->client->invisible_framenum > level.framenum)
{
remaining = ent->client->invisible_framenum - level.framenum;
if (remaining == 30) /* beginning to fade */
{
gi.sound(ent, CHAN_ITEM, gi.soundindex(
"items/protect2.wav"), 1, ATTN_NORM, 0);
}
if ((remaining > 30) || (remaining & 4))
{
SV_AddBlend(0.8f, 0.8f, 0.8f, 0.08f, ent->client->ps.blend);
}
}
else if (ent->client->enviro_framenum > level.framenum)
{
remaining = ent->client->enviro_framenum - level.framenum;