]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/weaponarena_random/sv_weaponarena_random.qc
Merge branch 'master' into martin-t/defaults
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / weaponarena_random / sv_weaponarena_random.qc
1 #include "sv_weaponarena_random.qh"
2
3 // WEAPONTODO: rename the cvars
4 REGISTER_MUTATOR(weaponarena_random, true);
5
6 MUTATOR_HOOKFUNCTION(weaponarena_random, SetStartItems)
7 {
8         if(g_weaponarena)
9                 g_weaponarena_random = cvar("g_weaponarena_random");
10         else
11                 g_weaponarena_random = 0;
12         
13         g_weaponarena_random_with_blaster = cvar("g_weaponarena_random_with_blaster");
14 }
15
16 MUTATOR_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
26 MUTATOR_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                 if(!GiveFrags_randomweapons)
49                 {
50                         GiveFrags_randomweapons = new(GiveFrags_randomweapons);
51                 }
52
53                 if(warmup_stage)
54                         STAT(WEAPONS, GiveFrags_randomweapons) = WARMUP_START_WEAPONS;
55                 else
56                         STAT(WEAPONS, GiveFrags_randomweapons) = start_weapons;
57
58                 // all others (including the culprit): remove
59                 STAT(WEAPONS, GiveFrags_randomweapons) &= ~STAT(WEAPONS, attacker);
60                 STAT(WEAPONS, GiveFrags_randomweapons) &= ~(culprit.m_wepset);
61
62                 // among the remaining ones, choose one by random
63                 STAT(WEAPONS, GiveFrags_randomweapons) = W_RandomWeapons(GiveFrags_randomweapons, STAT(WEAPONS, GiveFrags_randomweapons), 1);
64
65                 if(STAT(WEAPONS, GiveFrags_randomweapons))
66                 {
67                         STAT(WEAPONS, attacker) |= STAT(WEAPONS, GiveFrags_randomweapons);
68                         STAT(WEAPONS, attacker) &= ~(culprit.m_wepset);
69                 }
70         }
71
72         // after a frag, choose another random weapon set
73         if (!(STAT(WEAPONS, attacker) & WepSet_FromWeapon(wep_ent.m_weapon)))
74                 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker, weaponentity), weaponentity);
75 }