Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_weaponarena_random.qc
Go to the documentation of this file.
2
3// WEAPONTODO: rename the cvars
4REGISTER_MUTATOR(weaponarena_random, true);
5
6MUTATOR_HOOKFUNCTION(weaponarena_random, SetStartItems)
7{
9 g_weaponarena_random = cvar("g_weaponarena_random");
10 else
12
13 g_weaponarena_random_with_blaster = cvar("g_weaponarena_random_with_blaster");
14}
15
16MUTATOR_HOOKFUNCTION(weaponarena_random, PlayerSpawn)
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}
25
26MUTATOR_HOOKFUNCTION(weaponarena_random, GiveFragsForKill)
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}
#define REGISTER_MUTATOR(...)
Definition base.qh:295
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:44
bool warmup_stage
Definition main.qh:120
#define M_ARGV(x, type)
Definition events.qh:17
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition selection.qc:246
#define DEATH_WEAPONOF(t)
Definition all.qh:45
#define STAT(...)
Definition stats.qh:82
float cvar(string name)
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67
#define w_getbestweapon(ent, wepent)
Definition selection.qh:23
float g_weaponarena_random_with_blaster
WepSet W_RandomWeapons(entity e, WepSet remaining, int n)
Definition all.qc:172
#define WEPSET(id)
Definition all.qh:45
#define WepSet_FromWeapon(it)
Definition all.qh:46
WepSet start_weapons
Definition world.qh:80
#define WARMUP_START_WEAPONS
Definition world.qh:101
float g_weaponarena
Definition world.qh:75
float g_weaponarena_random
Definition world.qh:77