Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_buffs.qc File Reference
Include dependency graph for sv_buffs.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

float buff_Available (entity buff)
bool buff_Customize (entity this, entity client)
void buff_Delete (entity this)
void buff_Effect (entity player, string eff)
entity buff_FirstFromFlags (entity actor)
void buff_Init (entity this)
void buff_Init_Compat (entity ent, entity replacement)
void buff_NewType (entity ent)
void buff_RemoveAll (entity actor, int removal_type)
void buff_Reset (entity this)
void buff_Respawn (entity this)
void buff_SetCooldown (entity this, float cd)
void buff_SpawnReplacement (entity ent, entity old)
void buff_Think (entity this)
void buff_Touch (entity this, entity toucher)
void buff_Waypoint_Spawn (entity e)
bool buff_Waypoint_visible_for_player (entity this, entity player, entity view)
bool buffs_BuffModel_Customize (entity this, entity client)
void buffs_BuffModel_Remove (entity player)
void buffs_BuffModel_Spawn (entity player)
void buffs_BuffModel_Think (entity this)
void buffs_BuffModel_Update (entity this)
void buffs_DelayedInit (entity this)
void buffs_Initialize ()
bool buffs_RemovePlayer (entity player)
 MUTATOR_HOOKFUNCTION (buffs, BuildMutatorsPrettyString)
 MUTATOR_HOOKFUNCTION (buffs, BuildMutatorsString)
 MUTATOR_HOOKFUNCTION (buffs, ClientDisconnect)
 MUTATOR_HOOKFUNCTION (buffs, Damage_Calculate)
 MUTATOR_HOOKFUNCTION (buffs, FilterItem)
 MUTATOR_HOOKFUNCTION (buffs, MakePlayerObserver)
 MUTATOR_HOOKFUNCTION (buffs, PlayerPreThink)
 MUTATOR_HOOKFUNCTION (buffs, PlayerUseKey, CBC_ORDER_FIRST)

Variables

int buff_seencount

Function Documentation

◆ buff_Available()

float buff_Available ( entity buff)

Definition at line 254 of file sv_buffs.qc.

255{
256 if (!buff)
257 return false;
258 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_AMMO) || cvar("g_melee_only")))
259 return false;
260 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
261 return false;
262 return cvar(strcat("g_buffs_", buff.netname));
263}
const int IT_UNLIMITED_AMMO
Definition item.qh:23
float cvar(string name)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
int start_items
Definition world.qh:83

References cvar(), entity(), IT_UNLIMITED_AMMO, start_items, and strcat().

Referenced by buff_Init(), buff_NewType(), and GiveItems().

◆ buff_Customize()

bool buff_Customize ( entity this,
entity client )

Definition at line 404 of file sv_buffs.qc.

405{
406 entity player = WaypointSprite_getviewentity(client);
407 if ((!this.buff_active || !this.buffdef) || (this.team_forced && player.team != this.team_forced))
408 {
409 this.alpha = 0.3;
410 if (this.effects & EF_FULLBRIGHT)
411 this.effects &= ~EF_FULLBRIGHT;
412 this.pflags = 0;
413 }
414 else
415 {
416 this.alpha = 1;
417 if (!(this.effects & EF_FULLBRIGHT))
418 this.effects |= EF_FULLBRIGHT;
419 this.light_lev = 220 + 36 * sin(time);
421 }
422 return true;
423}
int team_forced
Definition buffs.qh:61
entity buffdef
Definition buffs.qh:60
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float alpha
Definition items.qc:13
const float EF_FULLBRIGHT
float effects
float time
const float PFLAGS_FULLDYNAMIC
float pflags
float light_lev
Definition dynlight.qc:13
float sin(float f)
bool buff_active
Definition sv_buffs.qh:39
entity WaypointSprite_getviewentity(entity e)

References alpha, buff_active, buffdef, EF_FULLBRIGHT, effects, entity(), light_lev, pflags, PFLAGS_FULLDYNAMIC, sin(), team_forced, time, and WaypointSprite_getviewentity().

Referenced by buff_Init().

◆ buff_Delete()

void buff_Delete ( entity this)

Definition at line 425 of file sv_buffs.qc.

426{
428 delete_fn(this);
429}
entity buff_waypoint
Definition sv_buffs.qh:42
var void delete_fn(entity e)
void WaypointSprite_Kill(entity wp)

References buff_waypoint, delete_fn(), entity(), and WaypointSprite_Kill().

Referenced by buff_Init().

◆ buff_Effect()

void buff_Effect ( entity player,
string eff )

Definition at line 103 of file sv_buffs.qc.

104{
106 return;
107
108 if (time >= player.buff_effect_delay)
109 {
110 Send_Effect_(eff, player.origin + (player.mins + player.maxs) * 0.5, '0 0 0', 1);
111 player.buff_effect_delay = time + 0.05; // prevent spam
112 }
113}
void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt)
Definition all.qc:129
bool autocvar_g_buffs_effects
Definition sv_buffs.qh:19

References autocvar_g_buffs_effects, entity(), Send_Effect_(), and time.

◆ buff_FirstFromFlags()

entity buff_FirstFromFlags ( entity actor)

Definition at line 291 of file sv_buffs.qc.

292{
293 if (!actor.statuseffects)
294 return NULL;
295 FOREACH(StatusEffects, it.instanceOfBuff && it.m_active(it, actor), {
296 return it;
297 });
298 return NULL;
299}
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define NULL
Definition post.qh:14

References entity(), FOREACH, and NULL.

Referenced by buff_Think(), buff_Touch(), buff_Waypoint_visible_for_player(), buffs_BuffModel_Customize(), buffs_BuffModel_Think(), MUTATOR_HOOKFUNCTION(), and Obituary().

◆ buff_Init()

void buff_Init ( entity this)

Definition at line 431 of file sv_buffs.qc.

432{
433 if (!autocvar_g_buffs)
434 {
435 delete(this);
436 return;
437 }
438
439 entity buff = this.buffdef;
440
441 // item_buff_random provides a null type so force randomization in that case
442 // otherwise replace the buff type if it's unavailable and the option is enabled
443 if (!buff || (autocvar_g_buffs_replace_available && !buff_Available(buff)))
444 {
445 buff_NewType(this);
446 buff = this.buffdef;
447 }
448
449 // the buff type is still invalid or unavailable, simply delete the item
450 if (!buff || !buff_Available(buff))
451 {
452 delete(this);
453 return;
454 }
455
456 this.classname = "item_buff";
457 this.solid = SOLID_TRIGGER;
458 this.flags = FL_ITEM;
459 this.bot_pickup = true;
460 this.bot_pickupevalfunc = generic_pickupevalfunc;
461 this.bot_pickupbasevalue = 1000;
462 IL_PUSH(g_items, this);
463 setthink(this, buff_Think);
464 settouch(this, buff_Touch);
465 setmodel(this, MDL_BUFF);
466 setsize(this, ITEM_D_MINS, ITEM_L_MAXS);
467 this.reset = buff_Reset;
468 this.nextthink = time + 0.1;
469 this.gravity = 1;
471 this.scale = 1;
472 this.skin = buff.m_skin;
475 setcefc(this, buff_Customize);
476 //this.gravity = 100;
477 this.color = buff.m_color;
478 this.glowmod = buff.m_color;
480 this.buff_active = !this.buff_activetime;
482 this.dtor = buff_Delete;
483
484 if (!this.buffs_finished)
485 this.buffs_finished = this.count; // legacy support
486
487 if (this.spawnflags & 1)
488 this.noalign = true;
489 if (this.noalign)
490 set_movetype(this, MOVETYPE_NONE); // reset by random location
491
492 buff_Reset(this);
493}
float bot_pickup
Definition api.qh:43
float bot_pickupbasevalue
Definition bot.qh:68
float count
Definition powerups.qc:22
float gravity
Definition items.qh:17
int spawnflags
Definition ammo.qh:15
float buffs_finished
Definition item.qh:95
const vector ITEM_L_MAXS
Definition item.qh:84
const vector ITEM_D_MINS
Definition item.qh:82
#define setmodel(this, m)
Definition model.qh:26
float game_starttime
Definition stats.qh:82
const int FL_ITEM
Definition constants.qh:77
string classname
float flags
const float EF_STARDUST
const float SOLID_TRIGGER
float DPCONTENTS_SOLID
float DPCONTENTS_BODY
float skin
float nextthink
const float EF_NOSHADOW
float dphitcontentsmask
vector glowmod
vector color
Definition dynlight.qc:15
solid
Definition ent_cs.qc:165
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
float max(float f,...)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:129
const int MOVETYPE_TOSS
Definition movetypes.qh:135
float scale
Definition projectile.qc:14
#define setthink(e, f)
#define setcefc(e, f)
#define settouch(e, f)
Definition self.qh:73
float generic_pickupevalfunc(entity player, entity item)
Definition items.qc:885
IntrusiveList g_items
Definition items.qh:119
bool noalign
Definition items.qh:37
void buff_Think(entity this)
Definition sv_buffs.qc:301
void buff_Delete(entity this)
Definition sv_buffs.qc:425
void buff_NewType(entity ent)
Definition sv_buffs.qc:267
float buff_Available(entity buff)
Definition sv_buffs.qc:254
void buff_SetCooldown(entity this, float cd)
Definition sv_buffs.qc:140
void buff_Reset(entity this)
Definition sv_buffs.qc:377
bool buff_Customize(entity this, entity client)
Definition sv_buffs.qc:404
void buff_Touch(entity this, entity toucher)
Definition sv_buffs.qc:189
float autocvar_g_buffs_cooldown_activate
Definition sv_buffs.qh:32
float buff_activetime
Definition sv_buffs.qh:40
bool autocvar_g_buffs_replace_available
Definition sv_buffs.qh:30

References autocvar_g_buffs_cooldown_activate, autocvar_g_buffs_replace_available, bot_pickup, bot_pickupbasevalue, buff_active, buff_activetime, buff_Available(), buff_Customize(), buff_Delete(), buff_NewType(), buff_Reset(), buff_SetCooldown(), buff_Think(), buff_Touch(), buffdef, buffs_finished, classname, color, count, DPCONTENTS_BODY, DPCONTENTS_SOLID, dphitcontentsmask, EF_FULLBRIGHT, EF_NOSHADOW, EF_STARDUST, effects, entity(), FL_ITEM, flags, g_items, game_starttime, generic_pickupevalfunc(), glowmod, gravity, IL_PUSH(), ITEM_D_MINS, ITEM_L_MAXS, max(), MOVETYPE_NONE, MOVETYPE_TOSS, nextthink, noalign, pflags, PFLAGS_FULLDYNAMIC, scale, set_movetype(), setcefc, setmodel, setthink, settouch, skin, solid, SOLID_TRIGGER, spawnflags, and time.

Referenced by buff_Init_Compat(), buff_SpawnReplacement(), and buffs_DelayedInit().

◆ buff_Init_Compat()

void buff_Init_Compat ( entity ent,
entity replacement )

Definition at line 495 of file sv_buffs.qc.

496{
497 if (teamplay)
498 {
499 if (ent.spawnflags & 2)
500 ent.team_forced = NUM_TEAM_1;
501 else if (ent.spawnflags & 4)
502 ent.team_forced = NUM_TEAM_2;
503 }
504
505 ent.buffdef = replacement;
506
507 buff_Init(ent);
508}
void buff_Init(entity this)
Definition sv_buffs.qc:431
const int NUM_TEAM_2
Definition teams.qh:14
bool teamplay
Definition teams.qh:59
const int NUM_TEAM_1
Definition teams.qh:13

References buff_Init(), entity(), NUM_TEAM_1, NUM_TEAM_2, and teamplay.

◆ buff_NewType()

void buff_NewType ( entity ent)

Definition at line 267 of file sv_buffs.qc.

268{
270 FOREACH(StatusEffects, it.instanceOfBuff && buff_Available(it), {
271 // if it's already been chosen, give it a lower priority
272 float myseencount = (it.buff_seencount > 0) ? it.buff_seencount : 1; // no division by zero please!
273 RandomSelection_AddEnt(it, max(0.2, 1 / myseencount), 1);
274 });
276 if (!newbuff)
277 return;
278 ++newbuff.buff_seencount; // lower chances of seeing this buff again soon
279 ent.buffdef = newbuff;
280}
ERASEABLE void RandomSelection_Init()
Definition random.qc:4
#define RandomSelection_AddEnt(e, weight, priority)
Definition random.qh:14
entity RandomSelection_chosen_ent
Definition random.qh:5

References buff_Available(), entity(), FOREACH, max(), RandomSelection_AddEnt, RandomSelection_chosen_ent, and RandomSelection_Init().

Referenced by buff_Init(), buff_Reset(), and buff_Think().

◆ buff_RemoveAll()

void buff_RemoveAll ( entity actor,
int removal_type )

Definition at line 282 of file sv_buffs.qc.

283{
284 if (!actor.statuseffects)
285 return;
286 FOREACH(StatusEffects, it.instanceOfBuff, {
287 it.m_remove(it, actor, removal_type);
288 });
289}

References entity(), and FOREACH.

Referenced by buff_Touch(), GiveBuff(), MUTATOR_HOOKFUNCTION(), and MUTATOR_HOOKFUNCTION().

◆ buff_Reset()

void buff_Reset ( entity this)

Definition at line 377 of file sv_buffs.qc.

378{
379 if (this.targetname != "" && !(this.spawnflags & 16)) // q3compat
380 {
381 // buffs have no equivalent of Item_Show(this, -1)
382 this.effects = EF_NODRAW;
383 this.solid = SOLID_NOT; // u can't touch this
384 setorigin(this, this.origin); // unlink from the area grid
385 this.nextthink = 0;
386 if (this.buff_waypoint)
388 return;
389 }
390
392 buff_NewType(this);
393 this.owner = NULL;
396 if (this.buff_activetime)
398 this.buff_activetime_updated = false;
399
401 buff_Respawn(this);
402}
entity owner
Definition main.qh:87
const float SOLID_NOT
vector origin
const float EF_NODRAW
void buff_Respawn(entity this)
Definition sv_buffs.qc:153
void buff_Waypoint_Spawn(entity e)
Definition sv_buffs.qc:128
bool buff_activetime_updated
Definition sv_buffs.qh:41
bool autocvar_g_buffs_randomize
Definition sv_buffs.qh:23
bool autocvar_g_buffs_random_location
Definition sv_buffs.qh:26
bool autocvar_g_buffs_randomize_teamplay
Definition sv_buffs.qh:24
string targetname
Definition triggers.qh:56

References autocvar_g_buffs_cooldown_activate, autocvar_g_buffs_random_location, autocvar_g_buffs_randomize, autocvar_g_buffs_randomize_teamplay, buff_activetime, buff_activetime_updated, buff_NewType(), buff_Respawn(), buff_SetCooldown(), buff_waypoint, buff_Waypoint_Spawn(), EF_NODRAW, effects, entity(), nextthink, NULL, origin, owner, solid, SOLID_NOT, spawnflags, targetname, teamplay, and WaypointSprite_Kill().

Referenced by buff_Init().

◆ buff_Respawn()

void buff_Respawn ( entity this)

Definition at line 153 of file sv_buffs.qc.

154{
155 if (game_stopped)
156 return;
157
158 vector oldbufforigin = this.origin;
159 this.velocity = '0 0 200';
160
163 {
164 entity spot = SelectSpawnPoint(this, true);
165 setorigin(this, spot.origin);
166 this.velocity = (randomvec() * 100) + '0 0 200';
167 this.angles = spot.angles;
168 }
169
170 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
171
172 setorigin(this, trace_endpos); // attempt to unstick
173
175
176 makevectors(this.angles);
177 this.angles = '0 0 0';
180
181 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
182 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
183
185
186 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
187}
float lifetime
Definition powerups.qc:23
float game_stopped
Definition stats.qh:81
float Q3SURFACEFLAG_SKY
float DPCONTENTS_SKY
const float MOVE_NOMONSTERS
float DPCONTENTS_DONOTENTER
float DPCONTENTS_CORPSE
vector mins
vector velocity
float DPCONTENTS_PLAYERCLIP
float DPCONTENTS_SLIME
vector trace_endpos
vector maxs
float DPCONTENTS_LAVA
void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
Definition all.qc:124
ent angles
Definition ent_cs.qc:121
vector randomvec(void)
#define makevectors
Definition post.qh:21
vector
Definition self.qh:92
entity SelectSpawnPoint(entity this, bool anypoint)
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASE
Definition sound.qh:36
const float ATTEN_NONE
Definition sound.qh:27
#define sound(e, c, s, v, a)
Definition sound.qh:52
int autocvar_g_buffs_random_location_attempts
Definition sv_buffs.qh:27
float autocvar_g_buffs_random_lifetime
Definition sv_buffs.qh:25
#define CENTER_OR_VIEWOFS(ent)
Definition utils.qh:31
void WaypointSprite_Ping(entity e)
float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
Definition world.qc:1247

References angles, ATTEN_NONE, autocvar_g_buffs_random_lifetime, autocvar_g_buffs_random_location_attempts, buff_waypoint, CENTER_OR_VIEWOFS, CH_TRIGGER, DPCONTENTS_BODY, DPCONTENTS_CORPSE, DPCONTENTS_DONOTENTER, DPCONTENTS_LAVA, DPCONTENTS_PLAYERCLIP, DPCONTENTS_SKY, DPCONTENTS_SLIME, DPCONTENTS_SOLID, entity(), game_stopped, lifetime, makevectors, maxs, mins, MOVE_NOMONSTERS, MoveToRandomMapLocation(), MOVETYPE_TOSS, origin, Q3SURFACEFLAG_SKY, randomvec(), SelectSpawnPoint(), Send_Effect(), set_movetype(), sound, time, trace_endpos, vector, velocity, VOL_BASE, and WaypointSprite_Ping().

Referenced by buff_Reset(), buff_Think(), and buff_Touch().

◆ buff_SetCooldown()

void buff_SetCooldown ( entity this,
float cd )

Definition at line 140 of file sv_buffs.qc.

141{
142 cd = max(0, cd);
143
144 if (!this.buff_waypoint)
146 if (this.buff_waypoint)
148
149 this.buff_activetime = cd;
150 this.buff_active = !cd;
151}
void WaypointSprite_UpdateBuildFinished(entity e, float f)

References buff_active, buff_activetime, buff_waypoint, buff_Waypoint_Spawn(), entity(), max(), time, and WaypointSprite_UpdateBuildFinished().

Referenced by buff_Init(), buff_Reset(), and buff_Think().

◆ buff_SpawnReplacement()

void buff_SpawnReplacement ( entity ent,
entity old )

Definition at line 510 of file sv_buffs.qc.

511{
512 setorigin(ent, old.origin);
513 ent.angles = old.angles;
514 ent.noalign = ITEM_SHOULD_KEEP_POSITION(old);
515
516 buff_Init(ent);
517}
#define ITEM_SHOULD_KEEP_POSITION(item)
Returns whether item should keep its position or be dropped to the ground.
Definition spawning.qh:52

References buff_Init(), entity(), and ITEM_SHOULD_KEEP_POSITION.

Referenced by MUTATOR_HOOKFUNCTION().

◆ buff_Think()

void buff_Think ( entity this)

Definition at line 301 of file sv_buffs.qc.

302{
305
306 if (this.buffdef != this.oldbuffs)
307 {
308 entity buff = this.buffdef;
309 this.color = buff.m_color;
310 this.glowmod = buff.m_color;
311 this.skin = buff.m_skin;
312
313 setmodel(this, MDL_BUFF);
314 setsize(this, ITEM_D_MINS, ITEM_L_MAXS);
315
316 if (this.buff_waypoint)
317 {
318 //WaypointSprite_Disown(this.buff_waypoint, 1);
321 if (this.buff_activetime)
323 }
324
325 this.oldbuffs = this.buffdef;
326 }
327
328 if (!game_stopped)
330 if (!this.buff_activetime_updated)
331 {
333 this.buff_activetime_updated = true;
334 }
335
336 if (!this.buff_active && !this.buff_activetime)
337 if (!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle
338 || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway)
339 || this.buffdef != buff_FirstFromFlags(this.owner))
340 {
342 this.owner = NULL;
344 buff_NewType(this);
345
347 buff_Respawn(this);
348 }
349
350 if (this.buff_activetime)
351 if (!game_stopped)
353 {
355
356 if (!this.buff_activetime)
357 {
358 this.buff_active = true;
359 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
360 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
361 }
362 }
363
364 if (this.buff_active)
365 {
366 if (this.team_forced && !this.buff_waypoint)
368
369 if (this.lifetime && time >= this.lifetime)
370 buff_Respawn(this);
371 }
372
373 this.nextthink = time;
374 //this.angles_y = time * 110.1;
375}
#define IS_DEAD(s)
Definition player.qh:244
float frametime
const float ATTN_NORM
#define STAT(...)
Definition stats.qh:82
#define round_handler_IsActive()
#define round_handler_IsRoundStarted()
entity buff_FirstFromFlags(entity actor)
Definition sv_buffs.qc:291
entity oldbuffs
Definition sv_buffs.qh:43
bool autocvar_g_buffs_pickup_anyway
Definition sv_buffs.qh:21
float autocvar_g_buffs_cooldown_respawn
Definition sv_buffs.qh:33
float autocvar_g_buffs_waypoint_distance
Definition sv_buffs.qh:20

References ATTN_NORM, autocvar_g_buffs_cooldown_respawn, autocvar_g_buffs_pickup_anyway, autocvar_g_buffs_random_location, autocvar_g_buffs_randomize, autocvar_g_buffs_randomize_teamplay, autocvar_g_buffs_waypoint_distance, buff_active, buff_activetime, buff_activetime_updated, buff_FirstFromFlags(), buff_NewType(), buff_Respawn(), buff_SetCooldown(), buff_waypoint, buff_Waypoint_Spawn(), buffdef, CENTER_OR_VIEWOFS, CH_TRIGGER, color, entity(), frametime, game_starttime, game_stopped, glowmod, IS_DEAD, ITEM_D_MINS, ITEM_L_MAXS, lifetime, max(), nextthink, NULL, oldbuffs, owner, round_handler_IsActive, round_handler_IsRoundStarted, Send_Effect(), setmodel, skin, sound, spawnflags, STAT, team_forced, teamplay, time, VOL_BASE, WaypointSprite_Kill(), and WaypointSprite_UpdateBuildFinished().

Referenced by buff_Init().

◆ buff_Touch()

void buff_Touch ( entity this,
entity toucher )

Definition at line 189 of file sv_buffs.qc.

190{
191 if (game_stopped)
192 return;
193
195 {
196 buff_Respawn(this);
197 return;
198 }
199
200 if (!this.buff_active)
201 return;
202
203 if (MUTATOR_CALLHOOK(BuffTouch, this, toucher))
204 return;
205 toucher = M_ARGV(1, entity);
206
207 if (!IS_PLAYER(toucher))
208 return; // incase mutator changed toucher
209
210 if ((this.team_forced && toucher.team != this.team_forced)
211 || toucher.vehicle
212 || !this.buffdef // TODO: error out or maybe reset type if this occurs?
213 || time < toucher.buff_shield)
214 {
215 // can't touch this
216 return;
217 }
218
220 entity thebuff = this.buffdef;
221
222 if (heldbuff)
223 {
224 if (CS_CVAR(toucher).cvar_cl_buffs_autoreplace && heldbuff != thebuff)
225 {
226 // TODO: lost-gained notification for this case
227 int buffid = heldbuff.m_id;
228 Send_Notification(NOTIF_ONE, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
230 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
231 //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
232 }
233 else
234 return; // do nothing
235 }
236
237 this.owner = toucher;
238 this.buff_active = false;
239 this.lifetime = 0;
240 Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, thebuff.m_id);
242 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, thebuff.m_id);
243
244 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
245 sound(toucher, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
246 float bufftime = (this.buffs_finished) ? this.buffs_finished : thebuff.m_time(thebuff);
247
248 buff_RemoveAll(toucher, STATUSEFFECT_REMOVE_NORMAL); // remove previous buffs so that a new one may be added
249 if (!bufftime)
250 bufftime = 999;
251 StatusEffects_apply(thebuff, toucher, time + bufftime, 0);
252}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
#define M_ARGV(x, type)
Definition events.qh:17
#define IS_PLAYER(s)
Definition player.qh:242
@ STATUSEFFECT_REMOVE_NORMAL
Effect is being removed by a function, calls regular removal mechanics.
Definition all.qh:28
void Send_Notification(NOTIF broadcast, entity client, MSG net_type, Notification net_name,...count)
Definition all.qc:1573
entity entity toucher
Definition self.qh:72
#define IS_INDEPENDENT_PLAYER(e)
Definition client.qh:312
#define ITEM_TOUCH_NEEDKILL()
Definition items.qh:122
#define CS_CVAR(this)
Definition state.qh:51
void StatusEffects_apply(StatusEffect this, entity actor, float eff_time, int eff_flags)
void buff_RemoveAll(entity actor, int removal_type)
Definition sv_buffs.qc:282

References ATTN_NORM, buff_active, buff_FirstFromFlags(), buff_RemoveAll(), buff_Respawn(), buffdef, buffs_finished, CENTER_OR_VIEWOFS, CH_TRIGGER, CS_CVAR, entity(), game_stopped, IS_INDEPENDENT_PLAYER, IS_PLAYER, ITEM_TOUCH_NEEDKILL, lifetime, M_ARGV, MUTATOR_CALLHOOK, owner, Send_Effect(), Send_Notification(), sound, STATUSEFFECT_REMOVE_NORMAL, StatusEffects_apply(), team_forced, time, toucher, and VOL_BASE.

Referenced by buff_Init().

◆ buff_Waypoint_Spawn()

void buff_Waypoint_Spawn ( entity e)

Definition at line 128 of file sv_buffs.qc.

129{
131 return;
132
133 entity buff = e.buffdef;
134 entity wp = WaypointSprite_Spawn(WP_Buff, 0, autocvar_g_buffs_waypoint_distance, e, '0 0 1' * e.maxs.z, NULL, e.team_forced, e, buff_waypoint, true, RADARICON_Buff);
135 wp.wp_extra = buff.m_id;
136 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
137 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
138}
bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
Definition sv_buffs.qc:116
void WaypointSprite_UpdateTeamRadar(entity e, entity icon, vector col)
entity WaypointSprite_Spawn(entity spr, float _lifetime, float maxdistance, entity ref, vector ofs, entity showto, float t, entity own,.entity ownfield, float hideable, entity icon)

References autocvar_g_buffs_waypoint_distance, buff_waypoint, buff_Waypoint_visible_for_player(), entity(), NULL, WaypointSprite_Spawn(), and WaypointSprite_UpdateTeamRadar().

Referenced by buff_Reset(), buff_SetCooldown(), and buff_Think().

◆ buff_Waypoint_visible_for_player()

bool buff_Waypoint_visible_for_player ( entity this,
entity player,
entity view )

Definition at line 116 of file sv_buffs.qc.

117{
118 if (!this.owner.buff_active && !this.owner.buff_activetime || !this.owner.buffdef)
119 return false;
120
121 entity heldbuff = buff_FirstFromFlags(view); // TODO: cache this information so it isn't performing a loop every frame
122 if (heldbuff)
123 return CS_CVAR(view).cvar_cl_buffs_autoreplace == false || heldbuff != this.owner.buffdef;
124
125 return WaypointSprite_visible_for_player(this, player, view);
126}
bool WaypointSprite_visible_for_player(entity this, entity player, entity view)

References buff_FirstFromFlags(), CS_CVAR, entity(), owner, and WaypointSprite_visible_for_player().

Referenced by buff_Waypoint_Spawn().

◆ buffs_BuffModel_Customize()

bool buffs_BuffModel_Customize ( entity this,
entity client )

Definition at line 10 of file sv_buffs.qc.

11{
12 entity player = WaypointSprite_getviewentity(client);
13 entity myowner = this.owner;
14 entity heldbuff = buff_FirstFromFlags(myowner);
15
16 if (!heldbuff)
17 return false;
18
19 if (myowner.alpha <= 0.5 && myowner.alpha != 0 && DIFF_TEAM(player, myowner))
20 return false;
21
22 if (MUTATOR_CALLHOOK(BuffModel_Customize, this, player))
23 return false;
24
25 if (player == myowner)
26 {
27 // somewhat hide the model, but keep the glow
28 this.effects = 0;
29 this.alpha = -1;
30 }
31 else
32 {
34 this.alpha = myowner.alpha;
35 }
36 return true;
37}
float EF_LOWPRECISION
#define DIFF_TEAM(a, b)
Definition teams.qh:242

References alpha, buff_FirstFromFlags(), DIFF_TEAM, EF_FULLBRIGHT, EF_LOWPRECISION, effects, entity(), MUTATOR_CALLHOOK, owner, and WaypointSprite_getviewentity().

Referenced by buffs_BuffModel_Spawn().

◆ buffs_BuffModel_Remove()

void buffs_BuffModel_Remove ( entity player)

Definition at line 70 of file sv_buffs.qc.

71{
72 if (player.buff_model)
73 delete(player.buff_model);
74 player.buff_model = NULL;
75}

References entity(), and NULL.

Referenced by buffs_RemovePlayer().

◆ buffs_BuffModel_Spawn()

void buffs_BuffModel_Spawn ( entity player)

Definition at line 77 of file sv_buffs.qc.

78{
79 player.buff_model = new(buff_model);
80 setmodel(player.buff_model, MDL_BUFF);
81 setsize(player.buff_model, '0 0 -40', '0 0 40');
82 setattachment(player.buff_model, player, "");
83 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
84 player.buff_model.owner = player;
85 player.buff_model.exteriormodeltoclient = player;
86 player.buff_model.scale = 0.7;
87 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
88 player.buff_model.light_lev = 200;
89 setthink(player.buff_model, buffs_BuffModel_Think);
90 player.buff_model.nextthink = time;
91 setcefc(player.buff_model, buffs_BuffModel_Customize);
92}
void buffs_BuffModel_Think(entity this)
Definition sv_buffs.qc:39
bool buffs_BuffModel_Customize(entity this, entity client)
Definition sv_buffs.qc:10
entity buff_model
Definition sv_buffs.qh:45

References buff_model, buffs_BuffModel_Customize(), buffs_BuffModel_Think(), entity(), PFLAGS_FULLDYNAMIC, setcefc, setmodel, setthink, and time.

Referenced by buffs_BuffModel_Update().

◆ buffs_BuffModel_Think()

void buffs_BuffModel_Think ( entity this)

Definition at line 39 of file sv_buffs.qc.

40{
41 this.nextthink = time;
42 entity player = this.owner;
43 if (player.alpha < 0 || player.buff_model != this)
44 {
45 if (player) // remnant from ChatBubbleThink, same question... WHY?!
46 player.buff_model = NULL;
47 delete(this);
48 return;
49 }
50
51 entity heldbuff = buff_FirstFromFlags(player);
52
53 if (!heldbuff)
54 {
55 this.effects = EF_NODRAW;
56 return;
57 }
58
59 this.color = heldbuff.m_color;
60 this.glowmod = heldbuff.m_color;
61 this.skin = heldbuff.m_skin;
62
63 this.effects = player.effects;
65 this.effects = this.effects & EFMASK_CHEAP; // eat performance
66
67 this.alpha = player.alpha;
68}
#define EFMASK_CHEAP
Definition constants.qh:107

References alpha, buff_FirstFromFlags(), color, EF_LOWPRECISION, EF_NODRAW, effects, EFMASK_CHEAP, entity(), glowmod, nextthink, NULL, owner, skin, and time.

Referenced by buffs_BuffModel_Spawn().

◆ buffs_BuffModel_Update()

void buffs_BuffModel_Update ( entity this)

Definition at line 94 of file sv_buffs.qc.

95{
96 if (this.alpha < 0)
97 return;
98 // spawn a buff model entity if needed
99 if (!this.buff_model)
101}
void buffs_BuffModel_Spawn(entity player)
Definition sv_buffs.qc:77

References alpha, buff_model, buffs_BuffModel_Spawn(), and entity().

Referenced by MUTATOR_HOOKFUNCTION().

◆ buffs_DelayedInit()

void buffs_DelayedInit ( entity this)

Definition at line 706 of file sv_buffs.qc.

707{
709 if (find(NULL, classname, "item_buff") == NULL)
710 for (int i = 0; i < autocvar_g_buffs_spawn_count; ++i)
711 {
712 entity e = spawn();
713 e.spawnflags |= 64; // always randomize
714 e.velocity = randomvec() * 250; // this gets reset anyway if random location works
715 buff_Init(e);
716 }
717}
#define spawn
entity find(entity start,.string field, string match)
int autocvar_g_buffs_spawn_count
Definition sv_buffs.qh:28

References autocvar_g_buffs_spawn_count, buff_Init(), classname, entity(), find(), NULL, randomvec(), and spawn.

Referenced by buffs_Initialize().

◆ buffs_Initialize()

void buffs_Initialize ( )

Definition at line 719 of file sv_buffs.qc.

720{
721 // if buffs are above 0, allow random spawning
722 if (autocvar_g_buffs > 0 && autocvar_g_buffs_spawn_count > 0)
724}
const int INITPRIO_FINDTARGET
Definition constants.qh:96
void buffs_DelayedInit(entity this)
Definition sv_buffs.qc:706
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2225

References autocvar_g_buffs_spawn_count, buffs_DelayedInit(), InitializeEntity(), INITPRIO_FINDTARGET, and NULL.

Referenced by REGISTER_MUTATOR().

◆ buffs_RemovePlayer()

bool buffs_RemovePlayer ( entity player)

Definition at line 638 of file sv_buffs.qc.

639{
641 return false;
642}
void buffs_BuffModel_Remove(entity player)
Definition sv_buffs.qc:70

References buffs_BuffModel_Remove(), and entity().

Referenced by MUTATOR_HOOKFUNCTION(), and MUTATOR_HOOKFUNCTION().

◆ MUTATOR_HOOKFUNCTION() [1/8]

MUTATOR_HOOKFUNCTION ( buffs ,
BuildMutatorsPrettyString  )

Definition at line 700 of file sv_buffs.qc.

701{
702 if (autocvar_g_buffs > 0)
703 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
704}

References M_ARGV, and strcat().

◆ MUTATOR_HOOKFUNCTION() [2/8]

MUTATOR_HOOKFUNCTION ( buffs ,
BuildMutatorsString  )

Definition at line 694 of file sv_buffs.qc.

695{
696 if (autocvar_g_buffs > 0) // only report as a mutator if they're enabled
697 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
698}

References M_ARGV, and strcat().

◆ MUTATOR_HOOKFUNCTION() [3/8]

MUTATOR_HOOKFUNCTION ( buffs ,
ClientDisconnect  )

Definition at line 648 of file sv_buffs.qc.

649{
650 entity player = M_ARGV(0, entity);
651 return buffs_RemovePlayer(player);
652}
bool buffs_RemovePlayer(entity player)
Definition sv_buffs.qc:638

References buffs_RemovePlayer(), ClientDisconnect, entity(), and M_ARGV.

◆ MUTATOR_HOOKFUNCTION() [4/8]

MUTATOR_HOOKFUNCTION ( buffs ,
Damage_Calculate  )

Definition at line 547 of file sv_buffs.qc.

548{
549 entity frag_attacker = M_ARGV(1, entity);
551 float frag_deathtype = M_ARGV(3, float);
552 float frag_damage = M_ARGV(4, float);
554
555 if (frag_deathtype == DEATH_BUFF.m_id)
556 return;
557
558 if (StatusEffects_active(BUFF_RESISTANCE, frag_target))
560
561 if (StatusEffects_active(BUFF_MEDIC, frag_target))
562 if (GetResource(frag_target, RES_HEALTH) - frag_damage <= 0)
563 if (!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
564 if (frag_attacker)
566
567 if (StatusEffects_active(BUFF_JUMP, frag_target))
569
570 if (StatusEffects_active(BUFF_VENGEANCE, frag_target))
571 if (frag_attacker && frag_attacker != frag_target)
572 if (!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
573 {
574 entity dmgent = new_pure(dmgent);
575
577 dmgent.enemy = frag_attacker;
578 dmgent.owner = frag_target;
580 dmgent.nextthink = time + 0.1;
581 }
582
583 if (StatusEffects_active(BUFF_BASH, frag_target))
585
586 if (StatusEffects_active(BUFF_BASH, frag_attacker))
588
589 if (StatusEffects_active(BUFF_DISABILITY, frag_attacker))
591
592 if (StatusEffects_active(BUFF_INFERNO, frag_target))
593 {
594 if (frag_deathtype == DEATH_FIRE.m_id)
595 frag_damage = 0;
596 if (frag_deathtype == DEATH_LAVA.m_id)
597 frag_damage *= 0.5; // TODO: cvarize?
598 }
599
600 if (frag_attacker != frag_target)
601 {
602 if (StatusEffects_active(BUFF_LUCK, frag_attacker))
604
605 if (StatusEffects_active(BUFF_INFERNO, frag_attacker))
606 {
608 Fire_AddDamage(frag_target, frag_attacker, buff_Inferno_CalculateDamage(frag_damage), btime, DEATH_BUFF.m_id);
609 }
610 }
611
612 M_ARGV(4, float) = frag_damage;
614}
vector buff_Bash_AttackerCalculateForce(vector frag_force, entity frag_target, entity frag_attacker)
Definition bash.qc:10
vector buff_Bash_TargetCalculateForce(vector frag_force, entity frag_target, entity frag_attacker)
Definition bash.qc:4
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
Definition damage.qc:1002
void buff_Disability_ApplyStunned(entity frag_target, entity frag_attacker)
Definition disability.qc:4
float buff_Inferno_CalculateTime(float dmg)
Definition inferno.qc:4
float buff_Inferno_CalculateDamage(float frag_damage)
Definition inferno.qc:13
float buff_Jump_ChangeDamage(float frag_damage, float frag_deathtype)
Definition jump.qc:4
float buff_Luck_CalculateDamage(float frag_damage)
Definition luck.qc:4
float buff_Medic_CalculateSurviveDamage(float frag_damage, float health)
Definition medic.qc:16
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67
float buff_Resistance_CalculateDamage(float frag_damage)
Definition resistance.qc:4
#define ITEM_DAMAGE_NEEDKILL(dt)
Definition items.qh:123
bool StatusEffects_active(StatusEffect this, entity actor)
float frag_damage
Definition sv_ctf.qc:2322
vector frag_force
Definition sv_ctf.qc:2323
entity frag_target
Definition sv_ctf.qc:2321
void buff_Vengeance_DelayedDamage(entity this)
Definition vengeance.qc:4
float buff_Vengeance_CalculateDamage(float frag_damage)
Definition vengeance.qc:12

References buff_Bash_AttackerCalculateForce(), buff_Bash_TargetCalculateForce(), buff_Disability_ApplyStunned(), buff_Inferno_CalculateDamage(), buff_Inferno_CalculateTime(), buff_Jump_ChangeDamage(), buff_Luck_CalculateDamage(), buff_Medic_CalculateSurviveDamage(), buff_Resistance_CalculateDamage(), buff_Vengeance_CalculateDamage(), buff_Vengeance_DelayedDamage(), entity(), Fire_AddDamage(), frag_damage, frag_force, frag_target, GetResource(), ITEM_DAMAGE_NEEDKILL, M_ARGV, new_pure, setthink, StatusEffects_active(), time, and vector.

◆ MUTATOR_HOOKFUNCTION() [5/8]

MUTATOR_HOOKFUNCTION ( buffs ,
FilterItem  )

Definition at line 654 of file sv_buffs.qc.

655{
656 if (autocvar_g_buffs < 0)
657 return false; // no auto replacing of entities in this mode
658
659 entity item = M_ARGV(0, entity);
660
661 if (autocvar_g_buffs_replace_powerups && item.itemdef.instanceOfPowerup)
662 {
663 entity e = spawn();
664 buff_SpawnReplacement(e, item);
665 return true;
666 }
667
668 return false;
669}
void buff_SpawnReplacement(entity ent, entity old)
Definition sv_buffs.qc:510
bool autocvar_g_buffs_replace_powerups
Definition sv_buffs.qh:29

References autocvar_g_buffs_replace_powerups, buff_SpawnReplacement(), entity(), M_ARGV, and spawn.

◆ MUTATOR_HOOKFUNCTION() [6/8]

MUTATOR_HOOKFUNCTION ( buffs ,
MakePlayerObserver  )

Definition at line 643 of file sv_buffs.qc.

644{
645 entity player = M_ARGV(0, entity);
646 return buffs_RemovePlayer(player);
647}

References buffs_RemovePlayer(), entity(), and M_ARGV.

◆ MUTATOR_HOOKFUNCTION() [7/8]

MUTATOR_HOOKFUNCTION ( buffs ,
PlayerPreThink  )

Definition at line 671 of file sv_buffs.qc.

672{
673 entity player = M_ARGV(0, entity);
674
675 if (game_stopped || IS_DEAD(player) || !IS_PLAYER(player))
676 return;
677
678 // NOTE: this is kept here to ensure crouches are picked up each player movement frame
679 if (StatusEffects_active(BUFF_FLIGHT, player))
680 {
681 if (!PHYS_INPUT_BUTTON_CROUCH(player))
682 player.buff_flight_crouchheld = false;
683 else if (!player.buff_flight_crouchheld)
684 {
685 player.buff_flight_crouchheld = true;
686 player.gravity *= -1;
687 }
688 }
689
690 if (IS_PLAYER(player))
692}
#define PHYS_INPUT_BUTTON_CROUCH(s)
Definition player.qh:156
void buffs_BuffModel_Update(entity this)
Definition sv_buffs.qc:94

References buffs_BuffModel_Update(), entity(), game_stopped, IS_DEAD, IS_PLAYER, M_ARGV, PHYS_INPUT_BUTTON_CROUCH, PlayerPreThink, and StatusEffects_active().

◆ MUTATOR_HOOKFUNCTION() [8/8]

MUTATOR_HOOKFUNCTION ( buffs ,
PlayerUseKey ,
CBC_ORDER_FIRST  )

Definition at line 616 of file sv_buffs.qc.

617{
619 return;
620
621 entity player = M_ARGV(0, entity);
622
623 entity heldbuff = buff_FirstFromFlags(player);
624 if (heldbuff)
625 {
626 int buffid = heldbuff.m_id;
627 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
628 if (!IS_INDEPENDENT_PLAYER(player))
629 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
630
632 player.buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
633 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
634 return true;
635 }
636}
#define MUTATOR_RETURNVALUE
Definition base.qh:328
float autocvar_g_buffs_pickup_delay
Definition sv_buffs.qh:22
bool autocvar_g_buffs_drop
Definition sv_buffs.qh:31

References ATTN_NORM, autocvar_g_buffs_drop, autocvar_g_buffs_pickup_delay, buff_FirstFromFlags(), buff_RemoveAll(), CBC_ORDER_FIRST, CH_TRIGGER, entity(), game_stopped, IS_INDEPENDENT_PLAYER, M_ARGV, max(), MUTATOR_RETURNVALUE, PlayerUseKey(), Send_Notification(), sound, STATUSEFFECT_REMOVE_NORMAL, time, and VOL_BASE.

Variable Documentation

◆ buff_seencount

int buff_seencount

Definition at line 265 of file sv_buffs.qc.