]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/new_toys/new_toys.qc
236bb136f762c21ff573d940c73928db129d10b9
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / new_toys / new_toys.qc
1 #ifdef IMPLEMENTATION
2 /*
3
4 CORE    laser   vortex     lg      rl      cry     gl      elec    hagar   fireb   hook
5                                                                         vaporizer  porto
6                                                                         tuba
7
8 NEW             rifle   hlac    minel                           seeker
9 IDEAS                                   OPEN    flak    OPEN            FUN FUN FUN FUN
10
11
12
13 How this mutator works:
14  =======================
15
16 When a gun tries to spawn, this mutator is called. It will provide alternate
17 weaponreplace lists.
18
19 Entity:
20
21 {
22 "classname" "weapon_vortex"
23 "new_toys" "rifle"
24 }
25 -> This will spawn as Rifle in this mutator ONLY, and as Vortex otherwise.
26
27 {
28 "classname" "weapon_vortext"
29 "new_toys" "vortex rifle"
30 }
31 -> This will spawn as either Vortex or Rifle in this mutator ONLY, and as Vortex otherwise.
32
33 {
34 "classname" "weapon_vortex"
35 "new_toys" "vortex"
36 }
37 -> This is always a Vortex.
38
39 If the map specifies no "new_toys" argument
40
41 There will be two default replacements selectable: "replace all" and "replace random".
42 In "replace all" mode, e.g. Vortex will have the default replacement "rifle".
43 In "replace random" mode, Vortex will have the default replacement "vortex rifle".
44
45 This mutator's replacements run BEFORE regular weaponreplace!
46
47 The New Toys guns do NOT get a spawn function, so they can only ever be spawned
48 when this mutator is active.
49
50 Likewise, warmup, give all, give ALL and impulse 99 will not give them unless
51 this mutator is active.
52
53 Outside this mutator, they still can be spawned by:
54 - setting their start weapon cvar to 1
55 - give weaponname
56 - weaponreplace
57 - weaponarena (but all and most weapons arena again won't include them)
58
59 This mutator performs the default replacements on the DEFAULTS of the
60 start weapon selection.
61
62 These weapons appear in the menu's priority list, BUT get a suffix
63 "(Mutator weapon)".
64
65 Picking up a "new toys" weapon will not play standard weapon pickup sound, but
66 roflsound "New toys, new toys!" sound.
67
68 */
69
70 bool nt_IsNewToy(int w);
71
72 REGISTER_MUTATOR(nt, cvar("g_new_toys") && !cvar("g_instagib") && !cvar("g_overkill"))
73 {
74         MUTATOR_ONADD
75         {
76                 if(time > 1) // game loads at time 1
77                         error("This cannot be added at runtime\n");
78
79                 // mark the guns as ok to use by e.g. impulse 99
80                 FOREACH(Weapons, it != WEP_Null, LAMBDA(
81                         if(nt_IsNewToy(it.m_id))
82                                 it.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
83                 ));
84         }
85
86         MUTATOR_ONROLLBACK_OR_REMOVE
87         {
88                 FOREACH(Weapons, it != WEP_Null, LAMBDA(
89                         if(nt_IsNewToy(it.m_id))
90                                 it.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
91                 ));
92         }
93
94         MUTATOR_ONREMOVE
95         {
96                 LOG_INFO("This cannot be removed at runtime\n");
97                 return -1;
98         }
99
100         return 0;
101 }
102
103 .string new_toys;
104
105 float autocvar_g_new_toys_autoreplace;
106 bool autocvar_g_new_toys_use_pickupsound = true;
107 const float NT_AUTOREPLACE_NEVER = 0;
108 const float NT_AUTOREPLACE_ALWAYS = 1;
109 const float NT_AUTOREPLACE_RANDOM = 2;
110
111 MUTATOR_HOOKFUNCTION(nt, SetModname)
112 {
113         modname = "NewToys";
114         return 0;
115 }
116
117 bool nt_IsNewToy(int w)
118 {
119         switch(w)
120         {
121                 case WEP_SEEKER.m_id:
122                 case WEP_MINE_LAYER.m_id:
123                 case WEP_HLAC.m_id:
124                 case WEP_RIFLE.m_id:
125                         return true;
126                 default:
127                         return false;
128         }
129 }
130
131 string nt_GetFullReplacement(string w)
132 {
133         switch(w)
134         {
135                 case "hagar": return "seeker";
136                 case "devastator": return "minelayer";
137                 case "machinegun": return "hlac";
138                 case "vortex": return "rifle";
139                 //case "shotgun": return "shockwave";
140                 default: return string_null;
141         }
142 }
143
144 string nt_GetReplacement(string w, float m)
145 {
146         if(m == NT_AUTOREPLACE_NEVER)
147                 return w;
148         string s = nt_GetFullReplacement(w);
149         if (!s)
150                 return w;
151         if(m == NT_AUTOREPLACE_RANDOM)
152                 s = strcat(w, " ", s);
153         return s;
154 }
155
156 MUTATOR_HOOKFUNCTION(nt, SetStartItems)
157 {
158         // rearrange start_weapon_default
159         // apply those bits that are set by start_weapon_defaultmask
160         // same for warmup
161
162         float j, n;
163
164         WepSet newdefault;
165         WepSet warmup_newdefault;
166
167         newdefault = '0 0 0';
168         warmup_newdefault = '0 0 0';
169
170         WepSet seti = '0 0 0';
171
172         FOREACH(Weapons, it != WEP_Null, LAMBDA(
173                 seti = it.m_wepset;
174                 n = tokenize_console(nt_GetReplacement(it.netname, autocvar_g_new_toys_autoreplace));
175
176                 for(j = 0; j < n; ++j)
177                         FOREACH(Weapons, it != WEP_Null, LAMBDA(
178                                 if(it.netname == argv(j))
179                                 {
180                                         WepSet setk = it.m_wepset;
181                                         if(start_weapons & seti) newdefault |= setk;
182                                         if(warmup_start_weapons & seti) warmup_newdefault |= setk;
183                                 }
184                         ));
185         ));
186
187         newdefault &= start_weapons_defaultmask;
188         start_weapons &= ~start_weapons_defaultmask;
189         start_weapons |= newdefault;
190
191         warmup_newdefault &= warmup_start_weapons_defaultmask;
192         warmup_start_weapons &= ~warmup_start_weapons_defaultmask;
193         warmup_start_weapons |= warmup_newdefault;
194
195         return 0;
196 }
197
198 MUTATOR_HOOKFUNCTION(nt, SetWeaponreplace)
199 {SELFPARAM();
200         // otherwise, we do replace
201         if(self.new_toys)
202         {
203                 // map defined replacement:
204                 ret_string = self.new_toys;
205         }
206         else
207         {
208                 // auto replacement:
209                 ret_string = nt_GetReplacement(other.netname, autocvar_g_new_toys_autoreplace);
210         }
211
212         // apply regular weaponreplace
213         ret_string = W_Apply_Weaponreplace(ret_string);
214
215         return 0;
216 }
217
218 MUTATOR_HOOKFUNCTION(nt, FilterItem)
219 {
220         entity item = M_ARGV(0, entity);
221
222         if(nt_IsNewToy(item.weapon) && autocvar_g_new_toys_use_pickupsound) {
223                 item.item_pickupsound = string_null;
224                 item.item_pickupsound_ent = SND_WEAPONPICKUP_NEW_TOYS;
225         }
226         return false;
227 }
228 #endif