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