3 #include <common/gamemodes/_mod.qh>
4 #include <common/gamemodes/gamemode/ctf/sv_ctf.qh>
5 #include <common/mapobjects/trigger/counter.qh>
6 #include <common/mapobjects/triggers.qh>
7 #include <common/mutators/mutator/buffs/buffs.qh>
8 #include <common/mutators/mutator/buffs/sv_buffs.qh>
9 #include <common/mutators/mutator/powerups/_mod.qh>
10 #include <common/mutators/mutator/status_effects/_mod.qh>
11 #include <common/notifications/all.qh>
12 #include <common/resources/sv_resources.qh>
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>
21 /***********************
22 * QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons
23 ***********************
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
45 NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG
49 SPAWNFUNC_Q3_COND(weapon_shotgun, ammo_shells, (q3compat & Q3COMPAT_ARENA), WEP_MACHINEGUN, WEP_SHOTGUN)
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)
56 SPAWNFUNC_Q3AMMO(ammo_grenades, WEP_MORTAR)
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)
62 // Team Arena Chaingun -> HLAC
63 SPAWNFUNC_Q3(weapon_chaingun, ammo_belt, WEP_HLAC)
65 // Quake Live Heavy Machine Gun -> HLAC
66 SPAWNFUNC_Q3(weapon_hmg, ammo_hmg, WEP_HLAC)
68 // Team Arena Nailgun -> Crylink || Quake Nailgun -> Electro
69 SPAWNFUNC_Q3_COND(weapon_nailgun, ammo_nails, autocvar_sv_mapformat_is_quake3, WEP_CRYLINK, WEP_ELECTRO)
72 SPAWNFUNC_Q3(weapon_lightning, ammo_lightning, WEP_ELECTRO)
75 SPAWNFUNC_Q3(weapon_plasmagun, ammo_cells, WEP_HAGAR)
78 SPAWNFUNC_Q3(weapon_railgun, ammo_slugs, WEP_VORTEX)
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
84 // grappling hook -> hook
85 SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
88 SPAWNFUNC_Q3AMMO(ammo_rockets, WEP_DEVASTATOR)
91 SPAWNFUNC_ITEM(weapon_gauntlet, WEP_TUBA)
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
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)
105 // medkit -> armor (we have no holdables)
106 SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorBig)
111 // weapon remove ent from df
112 void target_init_verify(entity this)
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")
124 //setsize(targ, trigger.mins, trigger.maxs);
125 //setorigin(targ, trigger.origin);
130 void target_init_use(entity this, entity actor, entity trigger)
132 if (!(this.spawnflags & 1))
134 SetResource(actor, RES_ARMOR, start_armorvalue);
135 actor.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot;
138 if (!(this.spawnflags & 2))
140 SetResource(actor, RES_HEALTH, start_health);
141 actor.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot;
142 actor.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
145 if (!(this.spawnflags & 4))
147 if(this.spawnflags & 32) // spawn with only melee
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);
156 STAT(WEAPONS, actor) = WEPSET(SHOTGUN);
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);
167 STAT(WEAPONS, actor) = start_weapons;
171 if (!(this.spawnflags & 8))
173 FOREACH(StatusEffect, it.instanceOfPowerups,
175 it.m_remove(it, actor, STATUSEFFECT_REMOVE_NORMAL);
177 entity heldbuff = buff_FirstFromFlags(actor);
178 if(heldbuff) // TODO: make a dropbuffs function to handle this
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);
185 buff_RemoveAll(actor, STATUSEFFECT_REMOVE_NORMAL);
189 if (!(this.spawnflags & 16))
191 // We don't have holdables.
194 SUB_UseTargets(this, actor, trigger);
197 spawnfunc(target_init)
199 this.use = target_init_use;
200 InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
203 // weapon give ent from Q3
204 void target_give_init(entity this)
206 IL_EACH(g_items, it.targetname == this.target,
208 if (it.classname == "item_buff")
210 this.netname = cons(this.netname, it.buffdef.netname);
211 this.buffs_finished += it.buffs_finished;
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;
226 this.netname = cons(this.netname, (it.itemdef.m_weapon) ? it.itemdef.m_weapon.netname : it.itemdef.netname);
229 //remove(it); // removing ents in init functions causes havoc, workaround:
230 setthink(it, SUB_Remove);
234 this.spawnfunc_checked = true;
235 spawnfunc_target_items(this);
236 InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
239 spawnfunc(target_give)
241 InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
244 void score_use(entity this, entity actor, entity trigger)
246 if(!IS_PLAYER(actor))
248 actor.fragsfilter_cnt += this.count;
250 spawnfunc(target_score)
252 if(!g_cts) { delete(this); return; }
256 this.use = score_use;
259 void fragsfilter_use(entity this, entity actor, entity trigger)
261 if(!IS_PLAYER(actor))
263 if(actor.fragsfilter_cnt >= this.frags)
264 SUB_UseTargets(this, actor, trigger);
266 spawnfunc(target_fragsFilter)
268 if(!g_cts) { delete(this); return; }
272 this.use = fragsfilter_use;
275 #define PRINT_REDTEAM BIT(0) // Q3 only, not used in Q3DF
276 #define PRINT_BLUETEAM BIT(1) // Q3 only, not used in Q3DF
277 #define PRINT_PRIVATE BIT(2) // Q3 only, not used in Q3DF
278 #define PRINT_BROADCAST BIT(3) // Q3DF only, default behavior in Q3
280 void target_print_message(entity this, entity actor)
282 centerprint(actor, this.message);
283 play2(actor, SND(TALK));
286 void target_print_use(entity this, entity actor, entity trigger)
288 if(!IS_PLAYER(actor))
291 if(this.message == "")
294 bool priv, red, blue;
295 if(!(q3compat & Q3COMPAT_DEFI)) // Q3 spawnflags
297 priv = boolean(this.spawnflags & PRINT_PRIVATE);
298 red = boolean(this.spawnflags & PRINT_REDTEAM);
299 blue = boolean(this.spawnflags & PRINT_BLUETEAM);
301 else // Q3DF spawnflags
303 priv = !boolean(this.spawnflags & PRINT_BROADCAST);
309 target_print_message(this, actor);
313 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));
320 * message: text string to print on screen.
321 * targetname: the activating trigger points to this.
323 spawnfunc(target_print)
325 this.use = target_print_use;
328 // target_smallprint, Q3DF only
329 spawnfunc(target_smallprint)
331 spawnfunc_target_print(this);
341 bool DoesQ3ARemoveThisEntity(entity this)
343 // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
345 // DeFRaG mappers use "notcpm" or "notvq3" to disable an entity in CPM or VQ3 physics
346 // Xonotic is usually played with a CPM-based physics so we default to CPM mode
347 if(cvar_string("g_mod_physics") == "Q3")
355 // Q3 mappers use "notq3a" or "notta" to disable an entity in Q3A or Q3TA
356 // Xonotic has ~equivalent features to Team Arena
360 // FIXME: singleplayer does not use maxclients 1 as that would prevent bots
376 // From ioq3 g_spawn.c: static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester"};
377 gametypename = "ffa";
379 gametypename = "team";
381 gametypename = "ctf";
382 if(g_ctf && ctf_oneflag)
383 gametypename = "oneflag";
385 gametypename = "tournament";
387 gametypename = "single";
388 // we do not have the other types (obelisk, harvester)
389 if(strstrofs(this.gametype, gametypename, 0) < 0)
396 int GetAmmoConsumptionQ3(string netname)
397 // Returns ammo consumed per shot by the primary/default fire mode
398 // Returns 0 if the netname has no ammo cvar
402 case "arc": return autocvar_g_balance_arc_beam_ammo;
403 case "devastator": return autocvar_g_balance_devastator_ammo;
404 case "machinegun": return autocvar_g_balance_machinegun_sustained_ammo;
405 case "minelayer": return autocvar_g_balance_minelayer_ammo;
406 case "seeker": return autocvar_g_balance_seeker_tag_ammo;
407 default: return cvar(strcat("g_balance_", netname, "_primary_ammo"));