]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/sv_overkill.qc
Merge branch 'master' into terencehill/lms_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / sv_overkill.qc
1 #include "sv_overkill.qh"
2
3 #include "okshotgun.qh"
4 #include "okhmg.qh"
5 #include "okrpc.qh"
6
7 bool autocvar_g_overkill_powerups_replace;
8
9 bool autocvar_g_overkill_itemwaypoints = true;
10
11 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
12
13 /// \brief Returns a random classname of the overkill item.
14 /// \param[in] prefix Prefix of the cvars that hold probabilities.
15 /// \return Random classname of the overkill item.
16 string RandomItems_GetRandomOverkillItemClassName(string prefix)
17 {
18         RandomSelection_Init();
19         IL_EACH(g_overkill_items, !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) &&
20                 Item_IsDefinitionAllowed(it),
21         {
22                 string cvar_name = sprintf("g_%s_%s_probability", prefix,
23                         it.m_canonical_spawnfunc);
24                 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
25                 {
26                         LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
27                         continue;
28                 }
29                 RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
30         });
31         string cvar_name = sprintf("g_%s_weapon_okhmg_probability", prefix);
32         if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
33         {
34                 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
35         }
36         else
37         {
38                 RandomSelection_AddString("weapon_okhmg", cvar(cvar_name), 1);
39         }
40         cvar_name = sprintf("g_%s_weapon_okrpc_probability", prefix);
41         if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
42         {
43                 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
44         }
45         else
46         {
47                 RandomSelection_AddString("weapon_okrpc", cvar(cvar_name), 1);
48         }
49         return RandomSelection_chosen_string;
50 }
51
52
53 MUTATOR_HOOKFUNCTION(ok, RandomItems_GetRandomItemClassName)
54 {
55         M_ARGV(1, string) = RandomItems_GetRandomOverkillItemClassName(
56                 M_ARGV(0, string));
57         return true;
58 }
59
60 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
61 {
62         entity frag_attacker = M_ARGV(1, entity);
63         entity frag_target = M_ARGV(2, entity);
64         float frag_deathtype = M_ARGV(3, float);
65
66         if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
67         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
68         {
69                 if(frag_attacker != frag_target)
70                 if(!STAT(FROZEN, frag_target))
71                 if(!IS_DEAD(frag_target))
72                 {
73                         M_ARGV(6, vector) = '0 0 0'; // force
74                 }
75
76                 M_ARGV(4, float) = 0; // damage
77         }
78 }
79
80 void ok_DropItem(entity this, entity targ)
81 {
82         entity e = spawn();
83         e.ok_item = true;
84         Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32',
85                 '0 0 200' + normalize(targ.origin - this.origin) * 500, 5);
86 }
87
88 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
89 {
90         entity frag_attacker = M_ARGV(1, entity);
91         entity frag_target = M_ARGV(2, entity);
92
93         entity targ = ((IS_PLAYER(frag_attacker)) ? frag_attacker : frag_target);
94
95         ok_DropItem(frag_target, targ);
96
97         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
98         {
99                 .entity weaponentity = weaponentities[slot];
100
101                 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
102         }
103 }
104
105 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
106 {
107         entity mon = M_ARGV(0, entity);
108         entity olditem = M_ARGV(1, entity);
109         entity frag_attacker = M_ARGV(2, entity);
110
111         delete(olditem);
112
113         M_ARGV(1, entity) = NULL;
114
115         ok_DropItem(mon, frag_attacker);
116 }
117
118 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
119 {
120         return true;
121 }
122
123 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
124 {
125         if (game_stopped)
126         {
127                 return;
128         }
129         entity player = M_ARGV(0, entity);
130         if (!IS_PLAYER(player) || IS_DEAD(player) || STAT(FROZEN, player))
131         {
132                 return;
133         }
134         if (!PHYS_INPUT_BUTTON_ATCK2(player) || weaponLocked(player) ||
135                 !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
136         {
137                 return;
138         }
139         // Allow secondary blaster during countdown.
140         for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
141         {
142                 .entity weaponentity = weaponentities[slot];
143                 Weapon weapon = player.(weaponentity).m_weapon;
144                 if (weapon == WEP_Null && slot != 0)
145                 {
146                         continue;
147                 }
148                 weapon.wr_think(weapon, player, weaponentity, 2);
149         }
150         PHYS_INPUT_BUTTON_ATCK2(player) = false;
151 }
152
153 MUTATOR_HOOKFUNCTION(ok, ForbidRandomStartWeapons)
154 {
155         return true;
156 }
157
158 MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
159 {
160         entity player = M_ARGV(0, entity);
161
162         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
163         {
164                 .entity weaponentity = weaponentities[slot];
165                 entity thiswep = player.(weaponentity);
166
167                 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
168                 {
169                         Weapon newwep = player.ok_lastwep[slot];
170                         if(player.ok_lastwep[slot] == WEP_OVERKILL_HMG)
171                                 newwep = WEP_OVERKILL_MACHINEGUN;
172                         if(player.ok_lastwep[slot] == WEP_OVERKILL_RPC)
173                                 newwep = WEP_OVERKILL_NEX;
174                         thiswep.m_switchweapon = newwep;
175                         player.ok_lastwep[slot] = WEP_Null;
176                 }
177         }
178 }
179
180 bool ok_HandleItemWaypoints(entity e)
181 {
182         if(!autocvar_g_overkill_itemwaypoints)
183                 return false; // don't handle it
184
185         switch(e.itemdef)
186         {
187                 case ITEM_HealthMega: return true;
188                 case ITEM_ArmorMedium: return true;
189                 case ITEM_ArmorBig: return true;
190                 case ITEM_ArmorMega: return true;
191         }
192
193         return false;
194 }
195
196 MUTATOR_HOOKFUNCTION(ok, Item_RespawnCountdown)
197 {
198         entity item = M_ARGV(0, entity);
199         return ok_HandleItemWaypoints(item);
200 }
201
202 MUTATOR_HOOKFUNCTION(ok, Item_ScheduleRespawn)
203 {
204         entity item = M_ARGV(0, entity);
205         return ok_HandleItemWaypoints(item);
206 }
207
208 MUTATOR_HOOKFUNCTION(ok, FilterItem)
209 {
210         entity item = M_ARGV(0, entity);
211
212         if (item.ok_item)
213         {
214                 return false;
215         }
216         switch(item.itemdef)
217         {
218                 case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
219                 case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium;
220                 case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig;
221                 case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega;
222         }
223         if (!autocvar_g_powerups || !autocvar_g_overkill_powerups_replace)
224         {
225                 return true;
226         }
227         if (item.classname == "item_strength")
228         {
229                 entity wep = new(weapon_okhmg);
230                 setorigin(wep, item.origin);
231                 wep.ok_item = true;
232                 wep.noalign = Item_ShouldKeepPosition(item);
233                 wep.cnt = item.cnt;
234                 wep.team = item.team;
235                 wep.respawntime = g_pickup_respawntime_superweapon;
236                 wep.pickup_anyway = true;
237                 wep.spawnfunc_checked = true;
238                 Item_Initialize(wep, "weapon_okhmg"); // doesn't actually use spawnfunc
239                 return true;
240         }
241         else if (item.classname == "item_shield")
242         {
243                 entity wep = new(weapon_okrpc);
244                 setorigin(wep, item.origin);
245                 wep.ok_item = true;
246                 wep.noalign = Item_ShouldKeepPosition(item);
247                 wep.cnt = item.cnt;
248                 wep.team = item.team;
249                 wep.respawntime = g_pickup_respawntime_superweapon;
250                 wep.pickup_anyway = true;
251                 wep.spawnfunc_checked = true;
252                 Item_Initialize(wep, "weapon_okrpc"); // doesn't actually use spawnfunc
253                 return true;
254         }
255         return true;
256 }
257
258 MUTATOR_HOOKFUNCTION(ok, SetStartItems, CBC_ORDER_LAST)
259 {
260         WepSet ok_start_items = (WEPSET(OVERKILL_MACHINEGUN) | WEPSET(OVERKILL_NEX) | WEPSET(OVERKILL_SHOTGUN));
261
262         if(WEP_OVERKILL_RPC.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_RPC); }
263         if(WEP_OVERKILL_HMG.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_HMG); }
264
265         // this gives unlimited ammo (the 4 types) but not fuel
266         // using `g_use_ammunition` instead gives also fuel which is unnecessary and distracting in the HUD
267         start_items |= IT_UNLIMITED_AMMO;
268
269         start_weapons = warmup_start_weapons = ok_start_items;
270 }
271
272 MUTATOR_HOOKFUNCTION(ok, SetWeaponArena)
273 {
274         // turn weapon arena off
275         M_ARGV(0, string) = "off";
276 }
277
278 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
279 {
280         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
281 }
282
283 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
284 {
285         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
286 }
287
288 MUTATOR_HOOKFUNCTION(ok, SetModname)
289 {
290         M_ARGV(0, string) = "Overkill";
291         return true;
292 }
293