Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
quake3.qc
Go to the documentation of this file.
1#include "quake3.qh"
2
12#include <common/stats.qh>
15#include <server/client.qh>
16#include <server/items/items.qh>
18#include <server/world.qh>
19
20/***********************
21 * QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons
22 ***********************
23
24 * Map entities NOT handled in this file:
25 holdable_invulnerability Q3TA buffs/all.inc
26 holdable_kamikaze Q3TA buffs/all.inc
27 holdable_teleporter Q3A buffs/all.inc
28 item_ammoregen Q3TA buffs/all.inc
29 item_doubler Q3TA buffs/all.inc
30 item_guard Q3TA buffs/all.inc
31 item_scout Q3TA buffs/all.inc
32 item_armor_jacket CPMA quake2.qc
33 item_flight Q3A buffs/all.inc
34 item_health Q3A quake.qc
35 item_health_large Q3A items/spawning.qc
36 item_health_small Q3A health.qh
37 item_health_mega Q3A health.qh
38 item_regen Q3A buffs/all.inc
39 item_key_gold QL keys.qc
40 item_key_silver QL keys.qc
41 item_key_master QL keys.qc
42 weapon_machinegun Q3A machinegun.qh
43 weapon_grenadelauncher Q3A mortar.qh
44 weapon_rocketlauncher Q3A devastator.qh
45 * CTF spawnfuncs in sv_ctf.qc
46
47 NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG
48 Guns that are very different may need .count scaling beyond that of GetAmmoConsumption().
49*/
50
51// Shotgun <-> Machine Gun
52// We don't want the swap on defrag maps (some of which have a valid .arena file as well as the .defi).
53// In Q3 defaults SG has 10 shells and MG has 100 bullets, Xonotic's GetAmmoConsumption() will return 1 for both
54// so .count will be out by 10x, however Xonotic has a stronger MG than Q3 so using 8x for SG->MG.
55SPAWNFUNC_Q3(weapon_shotgun, ammo_shells,
56 q3compat == Q3COMPAT_ARENA ? WEP_MACHINEGUN : WEP_SHOTGUN,
57 q3compat == Q3COMPAT_ARENA ? 8 : 1)
58SPAWNFUNC_Q3(weapon_machinegun, ammo_bullets,
59 q3compat == Q3COMPAT_ARENA ? WEP_SHOTGUN : WEP_MACHINEGUN,
60 q3compat == Q3COMPAT_ARENA ? 0.1 : 1)
61
62// Grenade Launcher -> Mortar
63SPAWNFUNC_Q3(weapon_grenadelauncher, ammo_grenades, WEP_MORTAR)
64
65// Team Arena Proximity Launcher -> Mine Layer
66SPAWNFUNC_Q3(weapon_prox_launcher, ammo_mines, WEP_MINE_LAYER)
67
68// Team Arena Chain Gun -> HLAC
69SPAWNFUNC_Q3(weapon_chaingun, ammo_belt, WEP_HLAC)
70
71// Quake Live Heavy MachineGun -> HLAC
72SPAWNFUNC_Q3(weapon_hmg, ammo_hmg, WEP_HLAC)
73
74// Team Arena Nail Gun -> Crylink || Quake Nail Gun -> Electro
75SPAWNFUNC_Q3(weapon_nailgun, ammo_nails, autocvar_sv_mapformat_is_quake3 ? WEP_CRYLINK : WEP_ELECTRO)
76
77// Lightning Gun -> Electro
78// Damage potential of 100 LG bolts (varies between Q3 derivatives) is roughly half that of 100 electro cells,
79// Xonotic's GetAmmoConsumption() will return 4 so we need a 1/8 .count scale here.
80SPAWNFUNC_Q3(weapon_lightning, ammo_lightning, WEP_ELECTRO, 0.125)
81
82// Plasma Gun -> Hagar
83SPAWNFUNC_Q3(weapon_plasmagun, ammo_cells, WEP_HAGAR)
84
85// Rail Gun -> Vortex
86SPAWNFUNC_Q3(weapon_railgun, ammo_slugs, WEP_VORTEX)
87
88// BFG -> Crylink || Fireball
89SPAWNFUNC_Q3(weapon_bfg, ammo_bfg, cvar_string("g_mod_balance") == "XDF" ? WEP_CRYLINK : WEP_FIREBALL)
90 // NB: WEP_FIREBALL has no ammo_type field so ammo_bfg is deleted by SPAWNFUNC_BODY
91
92// Grappling Hook
93SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
94 // NB: in Q3 this doesn't use ammo
95
96// Rocket Launcher -> Devastator
97SPAWNFUNC_Q3(weapon_rocketlauncher, ammo_rockets, WEP_DEVASTATOR)
98
99// Gauntlet -> Tuba
100SPAWNFUNC_ITEM(weapon_gauntlet, WEP_TUBA)
101
102// Armor
103SPAWNFUNC_ITEM(item_armor_body, ITEM_ArmorMega)
104SPAWNFUNC_ITEM(item_armor_combat, ITEM_ArmorBig)
105SPAWNFUNC_ITEM(item_armor_shard, ITEM_ArmorSmall)
106SPAWNFUNC_ITEM(item_armor_green, ITEM_ArmorMedium) // CCTF
107
108// Powerups
109SPAWNFUNC_ITEM(item_quad, ITEM_Strength)
110SPAWNFUNC_ITEM(item_enviro, ITEM_Shield)
111SPAWNFUNC_ITEM(item_haste, ITEM_Speed)
112SPAWNFUNC_ITEM(item_invis, ITEM_Invisibility)
113
114// medkit -> armor (we have no holdables)
115SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorBig)
116
117.float wait;
118.float delay;
119
120// weapon remove ent from df
122{
123 entity trigger, targ;
124 for(trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); )
125 for(targ = NULL; (targ = find(targ, targetname, trigger.target)); )
126 if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items")
127 {
128 trigger.wait = 0;
129 trigger.delay = 0;
130 targ.wait = 0;
131 targ.delay = 0;
132
133 //setsize(targ, trigger.mins, trigger.maxs);
134 //setorigin(targ, trigger.origin);
135 //remove(trigger);
136 }
137}
138
139void target_init_use(entity this, entity actor, entity trigger)
140{
141 if (!(this.spawnflags & 1))
142 {
144 actor.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot;
145 }
146
147 if (!(this.spawnflags & 2))
148 {
149 SetResource(actor, RES_HEALTH, start_health);
150 actor.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot;
151 actor.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
152 }
153
154 if (!(this.spawnflags & 4))
155 {
156 if(this.spawnflags & 32) // spawn with only melee
157 {
158 SetResource(actor, RES_SHELLS, 0);
159 SetResource(actor, RES_BULLETS, 0);
160 SetResource(actor, RES_ROCKETS, 0);
161 SetResource(actor, RES_CELLS, 0);
162 SetResource(actor, RES_FUEL, 0);
163
164 STAT(WEAPONS, actor) = WEPSET(SHOTGUN);
165 }
166 else
167 {
168 SetResource(actor, RES_SHELLS, start_ammo_shells);
169 SetResource(actor, RES_BULLETS, start_ammo_nails);
170 SetResource(actor, RES_ROCKETS, start_ammo_rockets);
171 SetResource(actor, RES_CELLS, start_ammo_cells);
172 SetResource(actor, RES_FUEL, start_ammo_fuel);
173
174 STAT(WEAPONS, actor) = start_weapons;
175 }
176 }
177
178 if (!(this.spawnflags & 8))
179 {
180 FOREACH(StatusEffects, it.instanceOfPowerupStatusEffect,
181 {
182 it.m_remove(it, actor, STATUSEFFECT_REMOVE_NORMAL);
183 });
184 entity heldbuff = buff_FirstFromFlags(actor);
185 if(heldbuff) // TODO: make a dropbuffs function to handle this
186 {
187 int buffid = heldbuff.m_id;
188 Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid);
189 sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
190 if(!IS_INDEPENDENT_PLAYER(actor))
191 Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
193 }
194 }
195
196 if (!(this.spawnflags & 16))
197 {
198 // We don't have holdables.
199 }
200
201 SUB_UseTargets(this, actor, trigger);
202}
203
209
210// weapon give ent from Q3
212{
213 IL_EACH(g_items, it.targetname == this.target,
214 {
215 if (it.classname == "item_buff")
216 {
217 this.netname = cons(this.netname, it.buffdef.netname);
218 this.buffs_finished += it.buffs_finished;
219 }
220 else
221 {
222 this.ammo_rockets += it.ammo_rockets;
223 this.ammo_cells += it.ammo_cells;
224 this.ammo_shells += it.ammo_shells;
225 this.ammo_nails += it.ammo_nails;
226 this.invincible_finished += it.invincible_finished;
227 this.strength_finished += it.strength_finished;
228 this.speed_finished += it.speed_finished;
229 this.invisibility_finished += it.invisibility_finished;
230 this.health += it.health;
231 this.armorvalue += it.armorvalue;
232
233 this.netname = cons(this.netname, (it.itemdef.m_weapon) ? it.itemdef.m_weapon.netname : it.itemdef.netname);
234 }
235
236 //remove(it); // removing ents in init functions causes havoc, workaround:
237 setthink(it, SUB_Remove);
238 it.nextthink = time;
239 });
240 this.spawnflags = 2;
241 this.spawnfunc_checked = true;
242 spawnfunc_target_items(this);
244}
245
250
251void score_use(entity this, entity actor, entity trigger)
252{
253 if(!IS_PLAYER(actor))
254 return;
255 actor.fragsfilter_cnt += this.count;
256}
257spawnfunc(target_score)
258{
259 if(!g_cts) { delete(this); return; }
260
261 if(!this.count)
262 this.count = 1;
263 this.use = score_use;
264}
265
266#define FRAGSFILTER_REMOVER BIT(0)
267#define FRAGSFILTER_RUNONCE BIT(1) // introduced but now unused by q3df
268#define FRAGSFILTER_SILENT BIT(2)
269#define FRAGSFILTER_RESET BIT(3)
270
271void fragsfilter_use(entity this, entity actor, entity trigger)
272{
273 if(!IS_PLAYER(actor))
274 return;
275 if(actor.fragsfilter_cnt >= this.frags)
276 {
278 actor.fragsfilter_cnt = 0;
279 else if(this.spawnflags & FRAGSFILTER_REMOVER)
280 actor.fragsfilter_cnt -= this.frags;
281 SUB_UseTargets(this, actor, trigger);
282 }
283 else if(!(this.spawnflags & FRAGSFILTER_SILENT))
284 {
285 int req_frags = this.frags - actor.fragsfilter_cnt;
286 centerprint(actor, sprintf("%d more frag%s needed", req_frags, req_frags > 1 ? "s" : ""));
287 play2(actor, SND(TALK));
288 }
289}
290spawnfunc(target_fragsFilter)
291{
292 if(!g_cts) { delete(this); return; }
293
294 if(!this.frags)
295 this.frags = 1;
296 this.use = fragsfilter_use;
297}
298
299#define PRINT_REDTEAM BIT(0) // Q3 only, not used in Q3DF
300#define PRINT_BLUETEAM BIT(1) // Q3 only, not used in Q3DF
301#define PRINT_PRIVATE BIT(2) // Q3 only, not used in Q3DF
302#define PRINT_BROADCAST BIT(3) // Q3DF only, default behavior in Q3
303
305{
306 centerprint(actor, this.message);
307 play2(actor, SND(TALK));
308}
309
310void target_print_use(entity this, entity actor, entity trigger)
311{
312 if(!IS_PLAYER(actor))
313 return;
314
315 if(this.message == "")
316 return;
317
318 bool priv, red, blue;
319 if(!(q3compat & Q3COMPAT_DEFI)) // Q3 spawnflags
320 {
321 priv = boolean(this.spawnflags & PRINT_PRIVATE);
322 red = boolean(this.spawnflags & PRINT_REDTEAM);
323 blue = boolean(this.spawnflags & PRINT_BLUETEAM);
324 }
325 else // Q3DF spawnflags
326 {
327 priv = !boolean(this.spawnflags & PRINT_BROADCAST);
328 red = blue = false;
329 }
330
331 if(priv)
332 {
333 target_print_message(this, actor);
334 }
335 else
336 {
337 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && ((!red && !blue) || (red && it.team == NUM_TEAM_1) || (blue && it.team == NUM_TEAM_2)), target_print_message(this, it));
338 }
339}
340
341/*
342 * ENTITY PARAMETERS:
343 *
344 * message: text string to print on screen.
345 * targetname: the activating trigger points to this.
346 */
347spawnfunc(target_print)
348{
349 this.use = target_print_use;
350}
351
352// target_smallprint, Q3DF only
353spawnfunc(target_smallprint)
354{
355 spawnfunc_target_print(this);
356}
357
358.string gametype;
361{
362 // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
363
364 if (!this.classname)
365 return true;
366
367 // DeFRaG mappers use "notcpm" or "notvq3" to disable an entity in CPM or VQ3 physics
368 // Xonotic is usually played with a CPM-based physics so we default to CPM mode
369 if(cvar_string("g_mod_physics") == "Q3")
370 {
371 if(stof(GetField_fullspawndata(this, "notvq3", false)))
372 return true;
373 }
374 else if(stof(GetField_fullspawndata(this, "notcpm", false)))
375 return true;
376
377 // Q3 mappers use "notq3a" or "notta" to disable an entity in Q3A or Q3TA
378 // Xonotic has ~equivalent features to Team Arena
379 if(stof(GetField_fullspawndata(this, "notta", false)))
380 return true;
381
382 // FIXME: singleplayer does not use maxclients 1 as that would prevent bots,
383 // this is the case in Q3 also, it uses another method to block clients.
384 // Only accessible in VQ3, via the `spmap` command.
385 if(stof(GetField_fullspawndata(this, "notsingle", false)))
386 if(maxclients == 1 && IS_GAMETYPE(DEATHMATCH))
387 return true;
388
389 if(stof(GetField_fullspawndata(this, "notteam", false)))
390 if(teamplay)
391 return true;
392
393 if(stof(GetField_fullspawndata(this, "notfree", false)))
394 if(!teamplay)
395 return true;
396
397 if(this.gametype || this.not_gametype)
398 {
399 // Q3 checks these with strstr(): case-sensitive, no gametype can be a substring of another,
400 // any separator is allowed (conventions are: spaces, commas, or commas with spaces).
401 // QL's entities.def says they're space delineated.
402
403 // Q3 gametype entity fields: ffa tournament single team ctf oneflag obelisk harvester (game/g_spawn.c)
404 // Q3 arena file 'type' key: ffa tourney ctf oneflag overload harvester (ui/ui_gameinfo.c)
405
406 // QL gametype entity fields: ffa duel tdm ca ft rr ctf ad dom har 1f race ob
407 // QL arena file 'type' key: ffa duel tdm ca ft rr ctf ad dom har oneflag race
408
409 string gametypename_q3, gametypename_ql;
410
411 // One of these will apply if our gametype has no Q3/QL equivalent
412 if(teamplay)
413 {
414 gametypename_q3 = "team";
415 gametypename_ql = "tdm";
416 }
417 else
418 gametypename_q3 = gametypename_ql = "ffa";
419
420 if(g_ctf)
421 {
422 if (cvar("g_ctf_oneflag"))
423 {
424 gametypename_q3 = "oneflag";
425 gametypename_ql = "1f";
426 }
427 else
428 gametypename_q3 = gametypename_ql = "ctf";
429 }
430 else if(g_duel)
431 {
432 gametypename_q3 = "tournament";
433 gametypename_ql = "duel";
434 }
435 else if(IS_GAMETYPE(DEATHMATCH) && maxclients == 1)
436 gametypename_q3 = "single";
437 else if(g_ca)
438 gametypename_ql = "ql";
439 else if(IS_GAMETYPE(FREEZETAG))
440 gametypename_ql = "ft";
441 else if(IS_GAMETYPE(DOMINATION))
442 gametypename_ql = "dom";
443 else if(g_race || g_cts)
444 gametypename_ql = "race";
445
446 if(this.gametype)
447 if(strstrofs(this.gametype, gametypename_q3, 0) < 0
448 && strstrofs(this.gametype, gametypename_ql, 0) < 0)
449 return true;
450
451 // Only supported by QL
452 if(strstrofs(this.not_gametype, gametypename_ql, 0) >= 0)
453 return true;
454 }
455
456 return false;
457}
#define boolean(value)
Definition bool.qh:9
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void SetResource(entity e, Resource res_type, float amount)
Sets the current amount of resource the given entity will have.
#define g_ca
Definition clanarena.qh:51
string message
Definition powerups.qc:19
float count
Definition powerups.qc:22
float delay
Definition items.qc:17
float wait
Definition items.qc:17
entity gametype
Definition main.qh:43
#define g_race
Definition race.qh:48
int spawnflags
Definition ammo.qh:15
#define SPAWNFUNC_ITEM(name, item)
Definition item.qh:106
#define IS_PLAYER(s)
Definition player.qh:243
const int INITPRIO_FINDTARGET
Definition constants.qh:96
string classname
float maxclients
float time
const float ATTN_NORM
#define use
#define g_ctf
Definition ctf.qh:39
#define g_cts
Definition cts.qh:36
void SUB_Remove(entity this)
Remove entity.
Definition defer.qh:13
#define strstrofs
#define g_duel
Definition duel.qh:32
RES_ARMOR
Definition ent_cs.qc:130
int frags
Definition ent_cs.qh:71
#define IL_EACH(this, cond, body)
Header file that describes the functions related to game items.
#define FOREACH(list, cond, body)
Definition iter.qh:19
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition triggers.qc:344
#define STAT(...)
Definition stats.qh:82
float stof(string val,...)
float cvar(string name)
entity find(entity start,.string field, string match)
const string cvar_string(string name)
void centerprint(string text,...)
@ STATUSEFFECT_REMOVE_NORMAL
Effect is being removed by a function, calls regular removal mechanics.
Definition all.qh:28
void Send_Notification(NOTIF broadcast, entity client, MSG net_type, Notification net_name,...count)
Definition all.qc:1573
#define NULL
Definition post.qh:14
#define PRINT_BLUETEAM
Definition quake3.qc:300
void target_give_init(entity this)
Definition quake3.qc:211
void target_print_use(entity this, entity actor, entity trigger)
Definition quake3.qc:310
ammo_bullets
Definition quake3.qc:58
bool DoesQ3ARemoveThisEntity(entity this)
Definition quake3.qc:360
#define PRINT_PRIVATE
Definition quake3.qc:301
void target_init_verify(entity this)
Definition quake3.qc:121
#define FRAGSFILTER_SILENT
Definition quake3.qc:268
void target_print_message(entity this, entity actor)
Definition quake3.qc:304
void target_init_use(entity this, entity actor, entity trigger)
Definition quake3.qc:139
#define PRINT_BROADCAST
Definition quake3.qc:302
#define FRAGSFILTER_RESET
Definition quake3.qc:269
q3compat
Definition quake3.qc:59
#define FRAGSFILTER_REMOVER
Definition quake3.qc:266
void fragsfilter_use(entity this, entity actor, entity trigger)
Definition quake3.qc:271
#define PRINT_REDTEAM
Definition quake3.qc:299
void score_use(entity this, entity actor, entity trigger)
Definition quake3.qc:251
string not_gametype
Definition quake3.qc:359
#define Q3COMPAT_ARENA
Definition quake3.qh:4
#define Q3COMPAT_DEFI
Definition quake3.qh:5
#define SPAWNFUNC_Q3(weapon_classname, ammo_classname, xonwep,...)
Definition quake3.qh:36
int ammo_nails
Definition resources.qh:16
int ammo_cells
Definition resources.qh:18
int ammo_shells
Definition resources.qh:15
int ammo_rockets
Definition resources.qh:17
#define setthink(e, f)
entity this
Definition self.qh:72
#define IS_INDEPENDENT_PLAYER(e)
Definition client.qh:312
IntrusiveList g_items
Definition items.qh:125
string GetField_fullspawndata(entity e, string fieldname, bool vfspath)
Retrieves the value of a map entity field from fullspawndata.
Definition main.qc:451
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASE
Definition sound.qh:36
#define sound(e, c, s, v, a)
Definition sound.qh:52
void play2(entity e, string filename)
Definition all.qc:116
#define SND(id)
Definition all.qh:35
bool spawnfunc_checked
Definition spawnfunc.qh:8
#define spawnfunc(id)
Definition spawnfunc.qh:96
entity buff_FirstFromFlags(entity actor)
Definition sv_buffs.qc:293
void buff_RemoveAll(entity actor, int removal_type)
Definition sv_buffs.qc:284
Header file that describes the resource system.
float autocvar_g_balance_pause_armor_rot
float autocvar_g_balance_pause_health_rot
float autocvar_g_balance_pause_health_regen
const int NUM_TEAM_2
Definition teams.qh:14
bool teamplay
Definition teams.qh:59
const int NUM_TEAM_1
Definition teams.qh:13
string targetname
Definition triggers.qh:56
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:50
#define WEPSET(id)
Definition all.qh:45
#define SPAWNFUNC_WEAPON(name, weapon)
Definition weapon.qh:150
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2209
WepSet start_weapons
Definition world.qh:80
float start_ammo_shells
Definition world.qh:84
float start_ammo_fuel
Definition world.qh:88
bool autocvar_sv_mapformat_is_quake3
Definition world.qh:32
float start_ammo_cells
Definition world.qh:87
float start_ammo_rockets
Definition world.qh:86
float start_armorvalue
Definition world.qh:97
float start_health
Definition world.qh:96
float start_ammo_nails
Definition world.qh:85