Xonotic
sv_overkill.qc
Go to the documentation of this file.
1 #include "sv_overkill.qh"
2 
3 #include "okshotgun.qh"
4 #include "okhmg.qh"
5 #include "okrpc.qh"
6 
8 
10 
12 
17 {
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  }
50 }
51 
52 
54 {
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 
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) ||
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 
181 {
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 
197 {
198  entity item = M_ARGV(0, entity);
199  return ok_HandleItemWaypoints(item);
200 }
201 
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  }
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 
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  start_items |= IT_UNLIMITED_AMMO;
266 
267  start_weapons = warmup_start_weapons = ok_start_items;
268 }
269 
270 MUTATOR_HOOKFUNCTION(ok, SetWeaponArena)
271 {
272  // turn weapon arena off
273  M_ARGV(0, string) = "off";
274 }
275 
276 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
277 {
278  M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
279 }
280 
281 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
282 {
283  M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
284 }
285 
286 MUTATOR_HOOKFUNCTION(ok, SetModname)
287 {
288  M_ARGV(0, string) = "Overkill";
289  return true;
290 }
291 
vector WepSet
Definition: weapon.qh:11
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition: player.qh:148
#define WEPSET(id)
Definition: all.qh:37
#define round_handler_IsActive()
#define IL_EACH(this, cond, body)
string RandomSelection_chosen_string
Definition: random.qh:7
bool Item_IsDefinitionAllowed(entity definition)
Checks whether the items with the specified definition are allowed to spawn.
Definition: spawning.qc:55
WepSet warmup_start_weapons
Definition: world.qh:100
bool autocvar_g_overkill_powerups_replace
Definition: sv_overkill.qc:7
WepSet start_weapons
Definition: world.qh:81
void Item_Initialize(entity item, string class_name)
Initializes the item according to class name.
Definition: spawning.qc:75
ERASEABLE void RandomSelection_Init()
Definition: random.qc:4
bool Item_InitializeLoot(entity item, string class_name, vector position, vector vel, float time_to_live)
Initializes the loot item.
Definition: spawning.qc:101
float CVAR_TYPEFLAG_EXISTS
entity() spawn
MUTATOR_HOOKFUNCTION(ok, RandomItems_GetRandomItemClassName)
Definition: sv_overkill.qc:53
int start_items
Definition: world.qh:84
#define RandomSelection_AddString(s, weight, priority)
Definition: random.qh:16
origin
Definition: ent_cs.qc:114
int autocvar_g_powerups
Definition: sv_powerups.qh:7
#define round_handler_IsRoundStarted()
void PlayerPreThink(entity this)
Definition: client.qc:2402
bool autocvar_g_overkill_filter_healthmega
Definition: sv_overkill.qh:4
#define IS_TURRET(v)
Definition: utils.qh:23
#define LOG_WARNF(...)
Definition: log.qh:67
bool autocvar_g_overkill_filter_armorbig
Definition: sv_overkill.qh:6
const int CBC_ORDER_LAST
Definition: base.qh:8
string RandomItems_GetRandomOverkillItemClassName(string prefix)
Returns a random classname of the overkill item.
Definition: sv_overkill.qc:16
bool weaponLocked(entity player)
bool autocvar_g_overkill_filter_armormedium
Definition: sv_overkill.qh:5
float weapon
Definition: progsdefs.qc:139
IntrusiveList g_overkill_items
Definition: sv_overkill.qh:10
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
const int MAX_WEAPONSLOTS
Definition: weapon.qh:13
string RandomItems_GetRandomItemClassName(string prefix)
Returns a random classname of the item.
#define NULL
Definition: post.qh:17
bool autocvar_g_overkill_itemwaypoints
Definition: sv_overkill.qc:9
#define M_ARGV(x, type)
Definition: events.qh:17
#define IS_DEAD(s)
Definition: utils.qh:26
bool autocvar_g_overkill_filter_armormega
Definition: sv_overkill.qh:7
bool ok_HandleItemWaypoints(entity e)
Definition: sv_overkill.qc:180
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define IS_VEHICLE(v)
Definition: utils.qh:22
Weapon ok_lastwep[MAX_WEAPONSLOTS]
Definition: sv_overkill.qc:11
bool Item_ShouldKeepPosition(entity item)
Returns whether item should keep its position or be dropped to the ground.
Definition: spawning.qc:131
void Item_RespawnCountdown(entity this)
Definition: items.qc:218
void ok_DropItem(entity this, entity targ)
Definition: sv_overkill.qc:80
entity weaponentities[MAX_WEAPONSLOTS]
Definition: weapon.qh:14
setorigin(ent, v)
#define DEATH_ISWEAPON(t, w)
Definition: all.qh:42
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
void Item_ScheduleRespawn(entity e)
Definition: items.qc:351
#define IS_PLAYER(v)
Definition: utils.qh:9