Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_new_toys.qc
Go to the documentation of this file.
1#include "sv_new_toys.qh"
2
3#include "new_toys.qh"
4
7
8/*
9
10CORE laser vortex lg rl cry gl elec hagar fireb hook
11 vaporizer porto
12 tuba
13
14NEW rifle hlac minel seeker
15IDEAS OPEN flak OPEN FUN FUN FUN FUN
16
17
18
19How this mutator works:
20 =======================
21
22When a gun tries to spawn, this mutator is called. It will provide alternate
23weaponreplace lists.
24
25Entity:
26
27{
28"classname" "weapon_vortex"
29"new_toys" "rifle"
30}
31-> This will spawn as Rifle in this mutator ONLY, and as Vortex otherwise.
32
33{
34"classname" "weapon_vortex"
35"new_toys" "vortex rifle"
36}
37-> This will spawn as either Vortex or Rifle in this mutator ONLY, and as Vortex otherwise.
38
39{
40"classname" "weapon_vortex"
41"new_toys" "vortex"
42}
43-> This is always a Vortex.
44
45If the map specifies no "new_toys" argument
46
47There will be two default replacements selectable: "replace all" and "replace random".
48In "replace all" mode, e.g. Vortex will have the default replacement "rifle".
49In "replace random" mode, Vortex will have the default replacement "vortex rifle".
50
51This mutator's replacements run BEFORE regular weaponreplace!
52
53The New Toys guns do NOT get a spawn function, so they can only ever be spawned
54when this mutator is active.
55
56Likewise, warmup, give all, give ALL and impulse 99 will not give them unless
57this mutator is active.
58
59Outside this mutator, they still can be spawned by:
60- setting their start weapon cvar to 1
61- give weaponname
62- weaponreplace
63- weaponarena (but all and most weapons arena again won't include them)
64
65This mutator performs the default replacements on the DEFAULTS of the
66start weapon selection.
67
68These weapons appear in the menu's priority list, BUT get a suffix
69"(Mutator weapon)".
70
71Picking up a "new toys" weapon will not play standard weapon pickup sound, but
72roflsound "New toys, new toys!" sound.
73
74*/
75
76//string autocvar_g_new_toys;
77
78REGISTER_MUTATOR(nt, expr_evaluate(cvar_string("g_new_toys")) && !MUTATOR_IS_ENABLED(mutator_instagib) && !MUTATOR_IS_ENABLED(ok))
79{
81 {
82 if(time > 1) // game loads at time 1
83 error("This cannot be added at runtime\n");
84
85 // mark the guns as ok to use by e.g. impulse 99
86 FOREACH(Weapons, it != WEP_Null, {
87 if(nt_IsNewToy(it.m_id))
88 it.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
89 });
90 }
91
93 {
94 FOREACH(Weapons, it != WEP_Null, {
95 if(nt_IsNewToy(it.m_id))
96 it.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
97 });
98 }
99
101 {
102 LOG_INFO("This cannot be removed at runtime");
103 return -1;
104 }
105
106 return 0;
107}
108
109.string new_toys;
110
113const float NT_AUTOREPLACE_NEVER = 0;
114const float NT_AUTOREPLACE_ALWAYS = 1;
115const float NT_AUTOREPLACE_RANDOM = 2;
116
117string nt_GetFullReplacement(string w)
118{
119 switch(w)
120 {
121 case "hagar": return "seeker";
122 case "devastator": return "minelayer";
123 case "machinegun": return "hlac";
124 case "vortex": return "rifle";
125 default: return string_null;
126 }
127}
128
129string nt_GetReplacement(string w, float m)
130{
131 if(m == NT_AUTOREPLACE_NEVER)
132 return w;
133 string s = nt_GetFullReplacement(w);
134 if (!s)
135 return w;
136 if(m == NT_AUTOREPLACE_RANDOM)
137 s = strcat(w, " ", s);
138 return s;
139}
140
141MUTATOR_HOOKFUNCTION(nt, SetStartItems)
142{
143 // rearrange start_weapon_default
144 // apply those bits that are set by start_weapon_defaultmask
145 // same for warmup
146
147 float j, n;
148
149 WepSet newdefault;
150 WepSet warmup_newdefault;
151
152 newdefault = '0 0 0';
153 warmup_newdefault = '0 0 0';
154
155 WepSet seti = '0 0 0';
156
157 FOREACH(Weapons, it != WEP_Null, {
158 seti = it.m_wepset;
160
161 for(j = 0; j < n; ++j)
162 FOREACH(Weapons, it != WEP_Null, {
163 if(it.netname == argv(j))
164 {
165 WepSet setk = it.m_wepset;
166 if(start_weapons & seti) newdefault |= setk;
167 if(warmup_start_weapons & seti) warmup_newdefault |= setk;
168 }
169 });
170 });
171
172 newdefault &= start_weapons_defaultmask;
174 start_weapons |= newdefault;
175
176 warmup_newdefault &= warmup_start_weapons_defaultmask;
178 warmup_start_weapons |= warmup_newdefault;
179}
180
181MUTATOR_HOOKFUNCTION(nt, SetWeaponreplace)
182{
183 if (MUTATOR_IS_ENABLED(random_items))
184 {
185 // Do not replace weapons when random items are enabled.
186 return;
187 }
188 entity wep = M_ARGV(0, entity);
189 entity wepinfo = M_ARGV(1, entity);
190 string ret_string = M_ARGV(2, string);
191
192 // otherwise, we do replace
193 if(wep.new_toys)
194 {
195 // map defined replacement:
196 ret_string = wep.new_toys;
197 }
198 else
199 {
200 // auto replacement:
201 ret_string = nt_GetReplacement(wepinfo.netname, autocvar_g_new_toys_autoreplace);
202 }
203
204 // apply regular weaponreplace
205 ret_string = W_Apply_Weaponreplace(ret_string);
206
207 M_ARGV(2, string) = ret_string;
208}
209
210MUTATOR_HOOKFUNCTION(nt, FilterItem)
211{
212 entity item = M_ARGV(0, entity);
213
215 item.item_pickupsound = string_null;
216 item.item_pickupsound_ent = SND_WEAPONPICKUP_NEW_TOYS;
217 }
218}
#define MUTATOR_ONADD
Definition base.qh:309
#define MUTATOR_ONROLLBACK_OR_REMOVE
Definition base.qh:311
#define MUTATOR_IS_ENABLED(this)
Definition base.qh:193
#define REGISTER_MUTATOR(...)
Definition base.qh:295
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
#define MUTATOR_ONREMOVE
Definition base.qh:310
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define M_ARGV(x, type)
Definition events.qh:17
float time
ERASEABLE bool expr_evaluate(string s)
Evaluate an expression of the form: [+ | -]?
Definition cvar.qh:48
#define tokenize_console
Weapons
Definition guide.qh:113
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define LOG_INFO(...)
Definition log.qh:65
const string cvar_string(string name)
string argv(float n)
bool nt_IsNewToy(int w)
Definition new_toys.qc:6
string string_null
Definition nil.qh:9
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define error
Definition pre.qh:6
string nt_GetFullReplacement(string w)
const float NT_AUTOREPLACE_ALWAYS
float autocvar_g_new_toys_autoreplace
string new_toys
string nt_GetReplacement(string w, float m)
const float NT_AUTOREPLACE_NEVER
bool autocvar_g_new_toys_use_pickupsound
const float NT_AUTOREPLACE_RANDOM
Header file that describes the random items mutator.
string W_Apply_Weaponreplace(string in)
Definition spawning.qc:13
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:219
vector WepSet
Definition weapon.qh:14
WepSet start_weapons
Definition world.qh:80
WepSet start_weapons_defaultmask
Definition world.qh:82
WepSet warmup_start_weapons_defaultmask
Definition world.qh:100
WepSet warmup_start_weapons
Definition world.qh:98