Xonotic
quake3.qc
Go to the documentation of this file.
1 #include "quake3.qh"
2 
13 #include <common/stats.qh>
14 #include <common/weapons/_all.qh>
15 #include <common/weapons/_all.qh>
16 #include <server/client.qh>
17 #include <server/items/items.qh>
18 #include <server/items/spawning.qh>
19 #include <server/world.qh>
20 
21 /***********************
22  * QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons
23  ***********************
24 
25  * Map entities NOT handled in this file:
26  holdable_invulnerability Q3TA buffs/all.inc
27  holdable_kamikaze Q3TA buffs/all.inc
28  holdable_teleporter Q3A buffs/all.inc
29  item_ammoregen Q3TA buffs/all.inc
30  item_doubler Q3TA buffs/all.inc
31  item_guard Q3TA buffs/all.inc
32  item_scout Q3TA buffs/all.inc
33  item_armor_jacket CPMA quake2.qc
34  item_flight Q3A buffs/all.inc
35  item_health Q3A quake.qc
36  item_health_large Q3A items/spawning.qc
37  item_health_small Q3A health.qh
38  item_health_mega Q3A health.qh
39  item_regen Q3A buffs/all.inc
40  weapon_machinegun Q3A machinegun.qh
41  weapon_grenadelauncher Q3A mortar.qh
42  weapon_rocketlauncher Q3A devastator.qh
43  * CTF spawnfuncs in sv_ctf.qc
44 
45  NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG
46 */
47 
48 // SG -> MG || SG
49 SPAWNFUNC_Q3_COND(weapon_shotgun, ammo_shells, (q3compat & Q3COMPAT_ARENA), WEP_MACHINEGUN, WEP_SHOTGUN)
50 
51 // MG -> SG || MG
52 // Technically we should replace weapon_machinegun with WEP_SHOTGUN if Q3COMPAT_ARENA, but it almost never occurs on Q3 maps
53 SPAWNFUNC_Q3AMMO_COND(ammo_bullets, (q3compat & Q3COMPAT_ARENA), WEP_SHOTGUN, WEP_MACHINEGUN)
54 
55 // GL -> Mortar
56 SPAWNFUNC_Q3AMMO(ammo_grenades, WEP_MORTAR)
57 
58 // Team Arena Proximity Launcher -> Mortar
59 // It's more accurate to spawn Mine Layer but players prefer Mortar, and weapon_grenadelauncher is usually disabled by "notta" and weapon_prox_launcher placed at the same origin
60 SPAWNFUNC_Q3(weapon_prox_launcher, ammo_mines, WEP_MORTAR)
61 
62 // Team Arena Chaingun -> HLAC
63 SPAWNFUNC_Q3(weapon_chaingun, ammo_belt, WEP_HLAC)
64 
65 // Quake Live Heavy Machine Gun -> HLAC
66 SPAWNFUNC_Q3(weapon_hmg, ammo_hmg, WEP_HLAC)
67 
68 // Team Arena Nailgun -> Crylink || Quake Nailgun -> Electro
69 SPAWNFUNC_Q3_COND(weapon_nailgun, ammo_nails, cvar("sv_mapformat_is_quake3"), WEP_CRYLINK, WEP_ELECTRO)
70 
71 // LG -> Electro
72 SPAWNFUNC_Q3(weapon_lightning, ammo_lightning, WEP_ELECTRO)
73 
74 // Plasma -> Hagar
75 SPAWNFUNC_Q3(weapon_plasmagun, ammo_cells, WEP_HAGAR)
76 
77 // Rail -> Vortex
78 SPAWNFUNC_Q3(weapon_railgun, ammo_slugs, WEP_VORTEX)
79 
80 // BFG -> Crylink || Fireball
81 SPAWNFUNC_Q3_COND(weapon_bfg, ammo_bfg, cvar_string("g_mod_balance") == "XDF", WEP_CRYLINK, WEP_FIREBALL)
82  // FIXME: WEP_FIREBALL has no ammo_type field so ammo_bfg is deleted by SPAWNFUNC_BODY
83 
84 // grappling hook -> hook
85 SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
86 
87 // RL -> RL
88 SPAWNFUNC_Q3AMMO(ammo_rockets, WEP_DEVASTATOR)
89 
90 // Gauntlet -> Tuba
91 SPAWNFUNC_ITEM(weapon_gauntlet, WEP_TUBA)
92 
93 // Armor
94 SPAWNFUNC_ITEM(item_armor_body, ITEM_ArmorMega)
95 SPAWNFUNC_ITEM(item_armor_combat, ITEM_ArmorBig)
96 SPAWNFUNC_ITEM(item_armor_shard, ITEM_ArmorSmall)
97 SPAWNFUNC_ITEM(item_armor_green, ITEM_ArmorMedium) // CCTF
98 
99 // Powerups
100 SPAWNFUNC_ITEM(item_quad, ITEM_Strength)
101 SPAWNFUNC_ITEM(item_enviro, ITEM_Shield)
102 SPAWNFUNC_ITEM(item_haste, ITEM_Speed)
103 SPAWNFUNC_ITEM(item_invis, ITEM_Invisibility)
104 
105 // medkit -> armor (we have no holdables)
106 SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorBig)
107 
108 .float wait;
109 .float delay;
110 
111 // weapon remove ent from df
113 {
114  entity trigger, targ;
115  for(trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); )
116  for(targ = NULL; (targ = find(targ, targetname, trigger.target)); )
117  if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items")
118  {
119  trigger.wait = 0;
120  trigger.delay = 0;
121  targ.wait = 0;
122  targ.delay = 0;
123 
124  //setsize(targ, trigger.mins, trigger.maxs);
125  //setorigin(targ, trigger.origin);
126  //remove(trigger);
127  }
128 }
129 
130 void target_init_use(entity this, entity actor, entity trigger)
131 {
132  if (!(this.spawnflags & 1))
133  {
134  SetResource(actor, RES_ARMOR, start_armorvalue);
135  actor.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot;
136  }
137 
138  if (!(this.spawnflags & 2))
139  {
141  actor.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot;
142  actor.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
143  }
144 
145  if (!(this.spawnflags & 4))
146  {
147  if(this.spawnflags & 32) // spawn with only melee
148  {
149  SetResource(actor, RES_SHELLS, 0);
150  SetResource(actor, RES_BULLETS, 0);
151  SetResource(actor, RES_ROCKETS, 0);
152  SetResource(actor, RES_CELLS, 0);
153  SetResource(actor, RES_PLASMA, 0);
154  SetResource(actor, RES_FUEL, 0);
155 
156  STAT(WEAPONS, actor) = WEPSET(SHOTGUN);
157  }
158  else
159  {
160  SetResource(actor, RES_SHELLS, start_ammo_shells);
161  SetResource(actor, RES_BULLETS, start_ammo_nails);
162  SetResource(actor, RES_ROCKETS, start_ammo_rockets);
163  SetResource(actor, RES_CELLS, start_ammo_cells);
164  SetResource(actor, RES_PLASMA, start_ammo_plasma);
165  SetResource(actor, RES_FUEL, start_ammo_fuel);
166 
167  STAT(WEAPONS, actor) = start_weapons;
168  }
169  }
170 
171  if (!(this.spawnflags & 8))
172  {
173  FOREACH(StatusEffect, it.instanceOfPowerups,
174  {
175  it.m_remove(it, actor, STATUSEFFECT_REMOVE_NORMAL);
176  });
177  entity heldbuff = buff_FirstFromFlags(actor);
178  if(heldbuff) // TODO: make a dropbuffs function to handle this
179  {
180  int buffid = heldbuff.m_id;
181  Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid);
182  sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
183  if(!IS_INDEPENDENT_PLAYER(actor))
184  Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
186  }
187  }
188 
189  if (!(this.spawnflags & 16))
190  {
191  // We don't have holdables.
192  }
193 
194  SUB_UseTargets(this, actor, trigger);
195 }
196 
197 spawnfunc(target_init)
198 {
199  this.use = target_init_use;
200  InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
201 }
202 
203 // weapon give ent from Q3
205 {
206  IL_EACH(g_items, it.targetname == this.target,
207  {
208  if (it.classname == "item_buff")
209  {
210  this.netname = cons(this.netname, it.buffdef.netname);
211  this.buffs_finished += it.buffs_finished;
212  }
213  else
214  {
215  this.ammo_rockets += it.ammo_rockets;
216  this.ammo_cells += it.ammo_cells;
217  this.ammo_shells += it.ammo_shells;
218  this.ammo_nails += it.ammo_nails;
219  this.invincible_finished += it.invincible_finished;
220  this.strength_finished += it.strength_finished;
221  this.speed_finished += it.speed_finished;
222  this.invisibility_finished += it.invisibility_finished;
223  this.health += it.health;
224  this.armorvalue += it.armorvalue;
225 
226  this.netname = cons(this.netname, (it.itemdef.m_weapon) ? it.itemdef.m_weapon.netname : it.itemdef.netname);
227  }
228 
229  //remove(it); // removing ents in init functions causes havoc, workaround:
230  setthink(it, SUB_Remove);
231  it.nextthink = time;
232  });
233  this.spawnflags = 2;
234  this.spawnfunc_checked = true;
235  spawnfunc_target_items(this);
236  InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
237 }
238 
239 spawnfunc(target_give)
240 {
241  InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
242 }
243 
244 void score_use(entity this, entity actor, entity trigger)
245 {
246  if(!IS_PLAYER(actor))
247  return;
248  actor.fragsfilter_cnt += this.count;
249 }
250 spawnfunc(target_score)
251 {
252  if(!g_cts) { delete(this); return; }
253 
254  if(!this.count)
255  this.count = 1;
256  this.use = score_use;
257 }
258 
259 void fragsfilter_use(entity this, entity actor, entity trigger)
260 {
261  if(!IS_PLAYER(actor))
262  return;
263  if(actor.fragsfilter_cnt >= this.frags)
264  SUB_UseTargets(this, actor, trigger);
265 }
266 spawnfunc(target_fragsFilter)
267 {
268  if(!g_cts) { delete(this); return; }
269 
270  if(!this.frags)
271  this.frags = 1;
272  this.use = fragsfilter_use;
273 }
274 
275 .bool notteam;
276 .bool notsingle;
277 .bool notfree;
278 .bool notta;
279 .bool notvq3;
280 .bool notcpm;
281 .string gametype;
283 {
284  // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
285 
286  // DeFRaG mappers use "notcpm" or "notvq3" to disable an entity in CPM or VQ3 physics
287  // Xonotic is usually played with a CPM-based physics so we default to CPM mode
288  if(cvar_string("g_mod_physics") == "Q3")
289  {
290  if(this.notvq3)
291  return true;
292  }
293  else if(this.notcpm)
294  return true;
295 
296  // Q3 mappers use "notq3a" or "notta" to disable an entity in Q3A or Q3TA
297  // Xonotic has ~equivalent features to Team Arena
298  if(this.notta)
299  return true;
300 
301  // FIXME: singleplayer does not use maxclients 1 as that would prevent bots
302  if(this.notsingle)
303  if(maxclients == 1)
304  return true;
305 
306  if(this.notteam)
307  if(teamplay)
308  return true;
309 
310  if(this.notfree)
311  if(!teamplay)
312  return true;
313 
314  if(this.gametype)
315  {
316  string gametypename;
317  // From ioq3 g_spawn.c: static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester"};
318  gametypename = "ffa";
319  if(teamplay)
320  gametypename = "team";
321  if(g_ctf)
322  gametypename = "ctf";
323  if(g_ctf && ctf_oneflag)
324  gametypename = "oneflag";
325  if(g_duel)
326  gametypename = "tournament";
327  if(maxclients == 1)
328  gametypename = "single";
329  // we do not have the other types (obelisk, harvester)
330  if(strstrofs(this.gametype, gametypename, 0) < 0)
331  return true;
332  }
333 
334  return false;
335 }
336 
338 // Returns ammo consumed per shot by the primary/default fire mode
339 // Returns 0 if the netname has no ammo cvar
340 {
341  switch (netname)
342  {
343  case "arc": return autocvar_g_balance_arc_beam_ammo;
344  case "devastator": return autocvar_g_balance_devastator_ammo;
345  case "machinegun": return autocvar_g_balance_machinegun_sustained_ammo;
346  case "minelayer": return autocvar_g_balance_minelayer_ammo;
347  case "seeker": return autocvar_g_balance_seeker_tag_ammo;
348  default: return cvar(strcat("g_balance_", netname, "_primary_ammo"));
349  }
350 }
351 
void buff_RemoveAll(entity actor, int removal_type)
Definition: sv_buffs.qc:286
float delay
Definition: quake3.qc:109
void target_init_verify(entity this)
Definition: quake3.qc:112
#define WEPSET(id)
Definition: all.qh:37
float autocvar_g_balance_pause_armor_rot
Definition: sv_resources.qh:32
#define IL_EACH(this, cond, body)
float start_ammo_rockets
Definition: world.qh:87
bool notteam
Definition: quake3.qc:275
int ammo_rockets
Definition: resources.qh:17
#define g_ctf
Definition: ctf.qh:39
float autocvar_g_balance_pause_health_regen
Definition: sv_resources.qh:35
float start_ammo_fuel
Definition: world.qh:90
SPAWNFUNC_ITEM(item_armor_green, ITEM_ArmorMedium) .float wait
Header file that describes the resource system.
bool notvq3
Definition: quake3.qc:279
WepSet start_weapons
Definition: world.qh:81
#define SPAWNFUNC_Q3AMMO_COND(ammo_classname, cond, xonwep1, xonwep0)
Definition: quake3.qh:28
#define IS_INDEPENDENT_PLAYER(e)
Definition: client.qh:314
entity() spawn
int ammo_shells
Definition: resources.qh:15
int ammo_nails
Definition: resources.qh:16
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition: triggers.qc:366
string netname
Definition: powerups.qc:20
Effect is being removed by a function, calls regular removal mechanics.
Definition: all.qh:25
float maxclients
Definition: csprogsdefs.qc:21
int ammo_cells
Definition: resources.qh:18
float start_ammo_shells
Definition: world.qh:85
string classname
Definition: csprogsdefs.qc:107
entity buff_FirstFromFlags(entity actor)
Definition: sv_buffs.qc:296
float spawnflags
Definition: progsdefs.qc:191
#define Q3COMPAT_ARENA
Definition: quake3.qh:4
void target_give_init(entity this)
Definition: quake3.qc:204
const float ATTN_NORM
Definition: csprogsdefs.qc:226
RES_HEALTH
Definition: ent_cs.qc:126
int q3compat
Definition: quake3.qh:3
#define g_cts
Definition: cts.qh:36
string gametype
Definition: quake3.qc:281
void SetResource(entity e, Resource res_type, float amount)
Sets the current amount of resource the given entity will have.
Definition: cl_resources.qc:26
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"))
bool notsingle
Definition: quake3.qc:276
const int CH_TRIGGER
Definition: sound.qh:12
float start_ammo_cells
Definition: world.qh:88
IntrusiveList g_items
Definition: items.qh:126
float wait
Definition: subs.qh:39
#define NULL
Definition: post.qh:17
bool notta
Definition: quake3.qc:278
const float VOL_BASE
Definition: sound.qh:36
frags
Definition: ent_cs.qc:151
int GetAmmoConsumptionQ3(string netname)
Definition: quake3.qc:337
#define strstrofs
Definition: dpextensions.qh:42
float teamplay
Definition: progsdefs.qc:31
bool DoesQ3ARemoveThisEntity(entity this)
Definition: quake3.qc:282
float autocvar_g_balance_pause_health_rot
Definition: sv_resources.qh:36
bool notfree
Definition: quake3.qc:277
spawnfunc(target_init)
Definition: quake3.qc:197
float start_health
Definition: world.qh:98
void InitializeEntity(entity e, void(entity this) func, int order)
Definition: world.qc:2146
float count
Definition: powerups.qc:22
void score_use(entity this, entity actor, entity trigger)
Definition: quake3.qc:244
#define SPAWNFUNC_WEAPON(name, weapon)
Definition: weapon.qh:143
#define SPAWNFUNC_Q3(weapon_classname, ammo_classname, xonwep)
Definition: quake3.qh:32
string targetname
Definition: progsdefs.qc:194
float start_ammo_nails
Definition: world.qh:86
#define SPAWNFUNC_Q3_COND(weapon_classname, ammo_classname, cond, xonwep1, xonwep0)
Definition: quake3.qh:37
void target_init_use(entity this, entity actor, entity trigger)
Definition: quake3.qc:130
#define setthink(e, f)
#define use
Definition: csprogsdefs.qh:50
#define sound(e, c, s, v, a)
Definition: sound.qh:52
Header file that describes the functions related to game items.
void fragsfilter_use(entity this, entity actor, entity trigger)
Definition: quake3.qc:259
float time
Definition: csprogsdefs.qc:16
float start_armorvalue
Definition: world.qh:99
float start_ammo_plasma
Definition: world.qh:89
#define FOREACH(list, cond, body)
Definition: iter.qh:19
bool ctf_oneflag
Definition: sv_ctf.qh:160
#define IS_PLAYER(v)
Definition: utils.qh:9
#define g_duel
Definition: duel.qh:28
#define SPAWNFUNC_Q3AMMO(ammo_classname, xonwep)
Definition: quake3.qh:19
bool notcpm
Definition: quake3.qc:280