Xonotic
sv_weaponarena_random.qc File Reference
+ Include dependency graph for sv_weaponarena_random.qc:

Go to the source code of this file.

Functions

 MUTATOR_HOOKFUNCTION (weaponarena_random, SetStartItems)
 
 MUTATOR_HOOKFUNCTION (weaponarena_random, PlayerSpawn)
 
 MUTATOR_HOOKFUNCTION (weaponarena_random, GiveFragsForKill)
 
 REGISTER_MUTATOR (weaponarena_random, true)
 

Function Documentation

◆ MUTATOR_HOOKFUNCTION() [1/3]

MUTATOR_HOOKFUNCTION ( weaponarena_random  ,
SetStartItems   
)

Definition at line 6 of file sv_weaponarena_random.qc.

References cvar(), g_weaponarena, g_weaponarena_random, and g_weaponarena_random_with_blaster.

7 {
8  if(g_weaponarena)
9  g_weaponarena_random = cvar("g_weaponarena_random");
10  else
12 
13  g_weaponarena_random_with_blaster = cvar("g_weaponarena_random_with_blaster");
14 }
float g_weaponarena_random
Definition: world.qh:78
float g_weaponarena_random_with_blaster
float g_weaponarena
Definition: world.qh:76
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [2/3]

MUTATOR_HOOKFUNCTION ( weaponarena_random  ,
PlayerSpawn   
)

Definition at line 16 of file sv_weaponarena_random.qc.

References entity(), g_weaponarena_random, g_weaponarena_random_with_blaster, M_ARGV, W_RandomWeapons(), and WEPSET.

17 {
18  if (!g_weaponarena_random) return;
19  entity player = M_ARGV(0, entity);
20 
21  if (g_weaponarena_random_with_blaster) STAT(WEAPONS, player) &= ~WEPSET(BLASTER);
22  STAT(WEAPONS, player) = W_RandomWeapons(player, STAT(WEAPONS, player), g_weaponarena_random);
23  if (g_weaponarena_random_with_blaster) STAT(WEAPONS, player) |= WEPSET(BLASTER);
24 }
#define WEPSET(id)
Definition: all.qh:37
WepSet W_RandomWeapons(entity e, WepSet remaining, int n)
Definition: all.qc:188
entity() spawn
float g_weaponarena_random
Definition: world.qh:78
float g_weaponarena_random_with_blaster
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [3/3]

MUTATOR_HOOKFUNCTION ( weaponarena_random  ,
GiveFragsForKill   
)

Definition at line 26 of file sv_weaponarena_random.qc.

References DEATH_WEAPONOF, entity(), g_weaponarena_random, g_weaponarena_random_with_blaster, M_ARGV, new_pure, start_weapons, w_getbestweapon, W_RandomWeapons(), W_SwitchWeapon_Force(), warmup_stage, WARMUP_START_WEAPONS, and WepSet_FromWeapon.

27 {
28  if(!g_weaponarena_random) return;
29  entity attacker = M_ARGV(0, entity);
30  entity targ = M_ARGV(1, entity);
31  float deathtype = M_ARGV(3, float);
32  entity wep_ent = M_ARGV(4, entity);
33  .entity weaponentity = wep_ent.weaponentity_fld;
34 
35  if(targ == attacker) return; // not for suicides
36 
37  // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
38  Weapon culprit = DEATH_WEAPONOF(deathtype);
39  if(!culprit) culprit = wep_ent.m_weapon;
40  else if(!(STAT(WEAPONS, attacker) & (culprit.m_wepset))) culprit = wep_ent.m_weapon;
41 
42  if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER)
43  {
44  // no exchange
45  }
46  else
47  {
48 
49  static entity GiveFrags_randomweapons;
50  if(!GiveFrags_randomweapons)
51  {
52  GiveFrags_randomweapons = new_pure(GiveFrags_randomweapons);
53  }
54 
55  if(warmup_stage)
56  STAT(WEAPONS, GiveFrags_randomweapons) = WARMUP_START_WEAPONS;
57  else
58  STAT(WEAPONS, GiveFrags_randomweapons) = start_weapons;
59 
60  // all others (including the culprit): remove
61  STAT(WEAPONS, GiveFrags_randomweapons) &= ~STAT(WEAPONS, attacker);
62  STAT(WEAPONS, GiveFrags_randomweapons) &= ~(culprit.m_wepset);
63 
64  // among the remaining ones, choose one by random
65  STAT(WEAPONS, GiveFrags_randomweapons) = W_RandomWeapons(GiveFrags_randomweapons, STAT(WEAPONS, GiveFrags_randomweapons), 1);
66 
67  if(STAT(WEAPONS, GiveFrags_randomweapons))
68  {
69  STAT(WEAPONS, attacker) |= STAT(WEAPONS, GiveFrags_randomweapons);
70  STAT(WEAPONS, attacker) &= ~(culprit.m_wepset);
71  }
72  }
73 
74  // after a frag, choose another random weapon set
75  if (!(STAT(WEAPONS, attacker) & WepSet_FromWeapon(wep_ent.m_weapon)))
76  W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker, weaponentity), weaponentity);
77 }
WepSet W_RandomWeapons(entity e, WepSet remaining, int n)
Definition: all.qc:188
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition: selection.qc:243
WepSet start_weapons
Definition: world.qh:81
#define w_getbestweapon(ent, wepent)
Definition: selection.qh:23
entity() spawn
bool warmup_stage
Definition: main.qh:103
float g_weaponarena_random
Definition: world.qh:78
#define DEATH_WEAPONOF(t)
Definition: all.qh:41
float g_weaponarena_random_with_blaster
#define WARMUP_START_WEAPONS
Definition: world.qh:103
#define M_ARGV(x, type)
Definition: events.qh:17
#define new_pure(class)
purely logical entities (.origin doesn't work)
Definition: oo.qh:62
#define WepSet_FromWeapon(it)
Definition: all.qh:38
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
+ Here is the call graph for this function:

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( weaponarena_random  ,
true   
)