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