]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_new_toys.qc
more new toys related stuff
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_new_toys.qc
1 /*
2
3 CORE    laser   nex     lg      rl      cry     gl      elec    hagar   fireb   hook
4                                                                         minsta  porto
5                                                                         tuba
6
7 NEW             rifle   hlac    minel                           seeker   
8 IDEAS                                   OPEN    flak    OPEN            FUN FUN FUN FUN
9
10
11
12 How this mutator works:
13  =======================
14
15 When a gun tries to spawn, this mutator is called. It will provide alternate
16 weaponreplace lists.
17
18 Entity:
19
20 {
21 "classname" "weapon_nex"
22 "new_toys" "rifle"
23 }
24 -> This will spawn as Rifle in this mutator ONLY, and as Nex otherwise.
25
26 {
27 "classname" "weapon_nex"
28 "new_toys" "nex rifle"
29 }
30 -> This will spawn as either Nex or Rifle in this mutator ONLY, and as Nex otherwise.
31
32 {
33 "classname" "weapon_nex"
34 "new_toys" "nex"
35 }
36 -> This is always a Nex.
37
38 If the map specifies no "new_toys" argument
39
40 There will be two default replacements selectable: "replace all" and "replace random".
41 In "replace all" mode, e.g. Nex will have the default replacement "rifle".
42 In "replace random" mode, Nex will have the default replacement "nex rifle".
43
44 This mutator's replacements run BEFORE regular weaponreplace!
45
46         The New Toys guns do NOT get a spawn function, so they can only ever be spawned
47         when this mutator is active.
48
49 Likewise, warmup, give all, give ALL and impulse 99 will not give them unless
50 this mutator is active.
51
52 Outside this mutator, they still can be spawned by:
53 - setting their start weapon cvar to 1
54 - give weaponname
55 - weaponreplace
56 - weaponarena (but all and most weapons arena again won't include them)
57
58 This mutator performs the default replacements on the DEFAULTS of the
59 start weapon selection.
60
61         These weapons appear in the menu's priority list, BUT get a suffix
62         "(Mutator weapon)".
63
64         Picking up a "new toys" weapon will not play standard weapon pickup sound, but
65         roflsound "New toys, new toys!" sound.
66
67 */
68
69 float autocvar_g_new_toys_autoreplace = 2; // 0 = never, 1 = always, 2 = random
70
71 MUTATOR_HOOKFUNCTION(nt_SetModname)
72 {
73         modname = "NewToys";
74         return 0;
75 }
76
77 string nt_GetFullReplacement(string w)
78 {
79         switch(w)
80         {
81                 case "hagar": return "seeker";
82                 case "rocketlauncher": return "minelayer";
83                 case "uzi": return "hlac";
84                 case "nex": return "rifle";
85                 default: return string_null;
86         }
87 }
88
89 string nt_GetReplacement(string w, float m)
90 {
91         if(m == 0)
92                 return w;
93         string s = nt_GetFullReplacement(w);
94         if not(s)
95                 return w;
96         if(m == 2)
97                 s = strcat(w, " ", s);
98         return s;
99 }
100
101 MUTATOR_HOOKFUNCTION(nt_SetStartItems)
102 {
103         // rearrange start_weapon_default
104         // apply those bits that are set by start_weapon_defaultmask
105         // same for warmup
106
107         float i, j, k, n;
108
109         WEPSET_DECLARE_A(newdefault);
110         WEPSET_DECLARE_A(warmup_newdefault);
111         
112         WEPSET_CLEAR_A(newdefault);
113         WEPSET_CLEAR_A(warmup_newdefault);
114
115         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
116         {
117                 entity e = get_weaponinfo(i);
118                 if(!e.weapon)
119                         continue;
120
121                 n = tokenize_console(nt_GetReplacement(e.netname, autocvar_g_new_toys_autoreplace));
122
123                 for(j = 0; j < n; ++j)
124                         for(k = WEP_FIRST; k <= WEP_LAST; ++k)
125                                 if(get_weaponinfo(k).netname == argv(j))
126                                 {
127                                         if(WEPSET_CONTAINS_AW(start_weapons, i))
128                                                 WEPSET_OR_AW(newdefault, k);
129                                         if(WEPSET_CONTAINS_AW(warmup_start_weapons, i))
130                                                 WEPSET_OR_AW(warmup_newdefault, k);
131                                 }
132         }
133
134         WEPSET_AND_AA(newdefault, start_weapons_defaultmask);
135         WEPSET_ANDNOT_AA(start_weapons, start_weapons_defaultmask);
136         WEPSET_OR_AA(start_weapons, newdefault);
137
138         WEPSET_AND_AA(warmup_newdefault, warmup_start_weapons_defaultmask);
139         WEPSET_ANDNOT_AA(warmup_start_weapons, warmup_start_weapons_defaultmask);
140         WEPSET_OR_AA(warmup_start_weapons, warmup_newdefault);
141
142         return 0;
143 }
144
145 MUTATOR_HOOKFUNCTION(nt_SetWeaponreplace)
146 {
147         // otherwise, we do replace
148         if(self.new_toys)
149         {
150                 // map defined replacement:
151                 ret_string = self.new_toys;
152         }
153         else if(autocvar_g_new_toys_autoreplace)
154         {
155                 // auto replacement:
156                 ret_string = nt_GetReplacement(other.netname, autocvar_g_new_toys_autoreplace);
157         }
158         else
159         {
160                 ret_string = other.netname;
161         }
162
163         // apply regular weaponreplace
164         ret_string = W_Apply_Weaponreplace(ret_string);
165
166         return 0;
167 }
168
169 MUTATOR_DEFINITION(mutator_new_toys)
170 {
171         MUTATOR_HOOK(SetModname, nt_SetModname, CBC_ORDER_ANY);
172         MUTATOR_HOOK(SetStartItems, nt_SetStartItems, CBC_ORDER_ANY);
173         MUTATOR_HOOK(SetWeaponreplace, nt_SetWeaponreplace, CBC_ORDER_LAST);
174
175         MUTATOR_ONADD
176         {
177                 if(time > 1) // game loads at time 1
178                         error("This cannot be added at runtime\n");
179
180                 // mark all guns as ok to use by e.g. impulse 99
181                 float i;
182                 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
183                 {
184                         entity e = get_weaponinfo(i);
185                         if(e.weapon)
186                                 e.spawnflags &~= WEP_FLAG_MUTATORBLOCKED;
187                 }
188         }
189         MUTATOR_ONREMOVE
190         {
191                 error("This cannot be removed at runtime\n");
192         }
193
194         return 0;
195 }