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