]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/compat/quake3.qc
target_give: support shield and strength powerups
[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 #include <common/weapons/_all.qh>
17
18 /***********************
19  * QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons
20  ***********************
21
22  * Map entities NOT handled in this file:
23  holdable_invulnerability       Q3TA    currently unsupported
24  holdable_kamikaze              Q3TA    currently unsupported
25  item_ammoregen                 Q3TA    handled by buffs mutator
26  item_doubler                   Q3TA    handled by buffs mutator
27  item_guard                     Q3TA    handled by buffs mutator
28  item_scout                     Q3TA    handled by buffs mutator
29  item_armor_jacket              CPMA    handled in quake2.qc
30  item_flight                    Q3A     handled by buffs mutator
31  item_haste                     Q3A     handled by buffs mutator
32  item_health                    Q3A     handled in quake.qc
33  item_health_large              Q3A     handled in items.qc
34  item_health_small              Q3A     handled in health.qh
35  item_health_mega               Q3A     handled in health.qh
36  item_invis                     Q3A     handled by buffs mutator
37  item_quad                      Q3A     handled in items.qc
38  item_regen                     Q3A     handled by buffs mutator
39  CTF spawnfuncs handled in sv_ctf.qc
40
41  NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG
42 */
43
44 // SG -> MG || SG
45 SPAWNFUNC_ITEM_COND(ammo_shells, (q3compat & Q3COMPAT_ARENA), ITEM_Bullets, ITEM_Shells)
46 SPAWNFUNC_WEAPON_COND(weapon_shotgun, (q3compat & Q3COMPAT_ARENA), WEP_MACHINEGUN, WEP_SHOTGUN)
47
48 // MG -> SG || MG
49 SPAWNFUNC_ITEM_COND(ammo_bullets, (q3compat & Q3COMPAT_ARENA), ITEM_Shells, ITEM_Bullets)
50
51 // GL -> Mortar
52 SPAWNFUNC_ITEM(ammo_grenades, ITEM_Rockets)
53
54 // Team Arena Proximity Launcher -> Mortar
55 // 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
56 SPAWNFUNC_WEAPON(weapon_prox_launcher, WEP_MORTAR)
57 SPAWNFUNC_ITEM(ammo_mines, ITEM_Rockets)
58
59 // Team Arena Chaingun -> HLAC
60 SPAWNFUNC_WEAPON(weapon_chaingun, WEP_HLAC)
61 SPAWNFUNC_ITEM(ammo_belt, ITEM_Cells)
62
63 // Quake Live Heavy Machine Gun -> HLAC
64 SPAWNFUNC_WEAPON(weapon_hmg, WEP_HLAC)
65 SPAWNFUNC_ITEM(ammo_hmg, ITEM_Cells)
66
67 // Team Arena Nailgun -> Crylink || Quake Nailgun -> Electro
68 SPAWNFUNC_WEAPON_COND(weapon_nailgun, cvar("sv_mapformat_is_quake3"), WEP_CRYLINK, WEP_ELECTRO)
69 SPAWNFUNC_ITEM(ammo_nails, ITEM_Cells)
70
71 // LG -> Electro
72 SPAWNFUNC_WEAPON(weapon_lightning, WEP_ELECTRO)
73 SPAWNFUNC_ITEM(ammo_lightning, ITEM_Cells)
74
75 // Plasma -> Hagar
76 SPAWNFUNC_WEAPON(weapon_plasmagun, WEP_HAGAR)
77 SPAWNFUNC_ITEM(ammo_cells, ITEM_Rockets)
78
79 // Rail -> Vortex
80 SPAWNFUNC_WEAPON(weapon_railgun, WEP_VORTEX)
81 SPAWNFUNC_ITEM(ammo_slugs, ITEM_Cells)
82
83 // BFG -> Crylink || Fireball
84 SPAWNFUNC_WEAPON_COND(weapon_bfg, cvar_string("g_mod_balance") == "XDF", WEP_CRYLINK, WEP_FIREBALL)
85 SPAWNFUNC_ITEM_COND(ammo_bfg, cvar_string("g_mod_balance") == "XDF", ITEM_Cells, ITEM_Rockets)
86
87 // grappling hook -> hook
88 SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
89
90 // RL -> RL
91 SPAWNFUNC_ITEM(ammo_rockets, ITEM_Rockets)
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 // Battle Suit
100 SPAWNFUNC_ITEM(item_enviro, ITEM_Shield)
101
102 // medkit -> armor (we have no holdables)
103 SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorBig)
104
105 .float wait;
106 .float delay;
107
108 // weapon remove ent from df
109 void target_init_verify(entity this)
110 {
111         entity trigger, targ;
112         for(trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); )
113                 for(targ = NULL; (targ = find(targ, targetname, trigger.target)); )
114                         if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items")
115                         {
116                                 trigger.wait = 0;
117                                 trigger.delay = 0;
118                                 targ.wait = 0;
119                                 targ.delay = 0;
120
121                                 //setsize(targ, trigger.mins, trigger.maxs);
122                                 //setorigin(targ, trigger.origin);
123                                 //remove(trigger);
124                         }
125 }
126
127 void target_init_use(entity this, entity actor, entity trigger)
128 {
129         if (!(this.spawnflags & 1))
130         {
131                 SetResource(actor, RES_ARMOR, start_armorvalue);
132                 actor.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot;
133         }
134
135         if (!(this.spawnflags & 2))
136         {
137                 SetResource(actor, RES_HEALTH, start_health);
138                 actor.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot;
139                 actor.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
140         }
141
142         if (!(this.spawnflags & 4))
143         {
144                 if(this.spawnflags & 32) // spawn with only melee
145                 {
146                         SetResource(actor, RES_SHELLS, 0);
147                         SetResource(actor, RES_BULLETS, 0);
148                         SetResource(actor, RES_ROCKETS, 0);
149                         SetResource(actor, RES_CELLS, 0);
150                         SetResource(actor, RES_PLASMA, 0);
151                         SetResource(actor, RES_FUEL, 0);
152
153                         STAT(WEAPONS, actor) = WEPSET(SHOTGUN);
154                 }
155                 else
156                 {
157                         SetResource(actor, RES_SHELLS, start_ammo_shells);
158                         SetResource(actor, RES_BULLETS, start_ammo_nails);
159                         SetResource(actor, RES_ROCKETS, start_ammo_rockets);
160                         SetResource(actor, RES_CELLS, start_ammo_cells);
161                         SetResource(actor, RES_PLASMA, start_ammo_plasma);
162                         SetResource(actor, RES_FUEL, start_ammo_fuel);
163
164                         STAT(WEAPONS, actor) = start_weapons;
165                 }
166         }
167
168         if (!(this.spawnflags & 8))
169         {
170                 STAT(STRENGTH_FINISHED, actor) = 0;
171                 STAT(INVINCIBLE_FINISHED, actor) = 0;
172                 if(STAT(BUFFS, actor)) // TODO: make a dropbuffs function to handle this
173                 {
174                         int buffid = buff_FirstFromFlags(STAT(BUFFS, actor)).m_id;
175                         Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid);
176                         sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
177                         if(!IS_INDEPENDENT_PLAYER(actor))
178                                 Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
179                         STAT(BUFFS, actor) = 0;
180                         STAT(BUFF_TIME, actor) = 0;
181                 }
182         }
183
184         if (!(this.spawnflags & 16))
185         {
186                 // We don't have holdables.
187         }
188
189         SUB_UseTargets(this, actor, trigger);
190 }
191
192 spawnfunc(target_init)
193 {
194         this.use = target_init_use;
195         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
196 }
197
198 // weapon give ent from Q3
199 void target_give_init(entity this)
200 {
201         IL_EACH(g_items, it.targetname == this.target,
202         {
203                 if (it.classname == "weapon_devastator") {
204                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(devastator, ammo)); // WEAPONTODO
205                         this.netname = cons(this.netname, "devastator");
206                 }
207                 else if (it.classname == "weapon_vortex") {
208                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(vortex, ammo)); // WEAPONTODO
209                         this.netname = cons(this.netname, "vortex");
210                 }
211                 else if (it.classname == "weapon_electro") {
212                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(electro, ammo)); // WEAPONTODO
213                         this.netname = cons(this.netname, "electro");
214                 }
215                 else if (it.classname == "weapon_hagar") {
216                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(hagar, ammo)); // WEAPONTODO
217                         this.netname = cons(this.netname, "hagar");
218                 }
219                 else if (it.classname == "weapon_crylink") {
220                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(crylink, ammo)); // WEAPONTODO
221                         this.netname = cons(this.netname, "crylink");
222                 }
223                 else if (it.classname == "weapon_mortar") {
224                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(mortar, ammo)); // WEAPONTODO
225                         this.netname = cons(this.netname, "mortar");
226                 }
227                 else if (it.classname == "weapon_shotgun") {
228                         SetResourceExplicit(this, RES_SHELLS, GetResource(this, RES_SHELLS) + it.count * WEP_CVAR_PRI(shotgun, ammo)); // WEAPONTODO
229                         this.netname = cons(this.netname, "shotgun");
230                 }
231                 else if (it.classname == "weapon_machinegun") {
232                         SetResourceExplicit(this, RES_BULLETS, GetResource(this, RES_BULLETS) + it.count * WEP_CVAR(machinegun, burst_ammo)); // WEAPONTODO
233                         this.netname = cons(this.netname, "machinegun");
234                 }
235                 else if (it.classname == "item_armor_mega")
236                         SetResourceExplicit(this, RES_ARMOR, 100);
237                 else if (it.classname == "item_health_mega")
238                         SetResourceExplicit(this, RES_HEALTH, 200);
239                 else if (it.classname == "item_buff") {
240                         entity buff = buff_FirstFromFlags(STAT(BUFFS, it));
241                         this.netname = cons(this.netname, buff.netname);
242                         STAT(BUFF_TIME, this) = it.count;
243                 }
244                 else if (it.classname == "item_shield") {
245                         this.invincible_finished = it.count;
246                         this.netname = cons(this.netname, "invincible");
247                 }
248                 else if (it.classname == "item_strength") {
249                         this.strength_finished = it.count;
250                         this.netname = cons(this.netname, "strength");
251                 }
252
253                 //remove(it); // removing ents in init functions causes havoc, workaround:
254                 setthink(it, SUB_Remove);
255                 it.nextthink = time;
256         });
257         this.spawnflags = 2;
258         this.spawnfunc_checked = true;
259         spawnfunc_target_items(this);
260         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
261 }
262
263 spawnfunc(target_give)
264 {
265         InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
266 }
267
268 void score_use(entity this, entity actor, entity trigger)
269 {
270         if(!IS_PLAYER(actor))
271                 return;
272         actor.fragsfilter_cnt += this.count;
273 }
274 spawnfunc(target_score)
275 {
276         if(!g_cts) { delete(this); return; }
277
278         if(!this.count)
279                 this.count = 1;
280         this.use = score_use;
281 }
282
283 void fragsfilter_use(entity this, entity actor, entity trigger)
284 {
285         if(!IS_PLAYER(actor))
286                 return;
287         if(actor.fragsfilter_cnt >= this.frags)
288                 SUB_UseTargets(this, actor, trigger);
289 }
290 spawnfunc(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 .bool notteam;
300 .bool notsingle;
301 .bool notfree;
302 .bool notta;
303 .bool notvq3;
304 .bool notcpm;
305 .string gametype;
306 bool DoesQ3ARemoveThisEntity(entity this)
307 {
308         // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
309
310         // DeFRaG mappers use "notcpm" or "notvq3" to disable an entity in CPM or VQ3 physics
311         // Xonotic is usually played with a CPM-based physics so we default to CPM mode
312         if(cvar_string("g_mod_physics") == "Q3")
313         {
314                 if(this.notvq3)
315                         return true;
316         }
317         else if(this.notcpm)
318                 return true;
319
320         // Q3 mappers use "notq3a" or "notta" to disable an entity in Q3A or Q3TA
321         // Xonotic has ~equivalent features to Team Arena
322         if(this.notta)
323                 return true;
324
325         if(this.notsingle)
326                 if(maxclients == 1)
327                         return true;
328
329         if(this.notteam)
330                 if(teamplay)
331                         return true;
332
333         if(this.notfree)
334                 if(!teamplay)
335                         return true;
336
337         if(this.gametype)
338         {
339                 string gametypename;
340                 // From ioq3 g_spawn.c: static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester"};
341                 gametypename = "ffa";
342                 if(teamplay)
343                         gametypename = "team";
344                 if(g_ctf)
345                         gametypename = "ctf";
346                 if(g_ctf && ctf_oneflag)
347                         gametypename = "oneflag";
348                 if(g_duel)
349                         gametypename = "tournament";
350                 if(maxclients == 1)
351                         gametypename = "single";
352                 // we do not have the other types (obelisk, harvester)
353                 if(strstrofs(this.gametype, gametypename, 0) < 0)
354                         return true;
355         }
356
357         return false;
358 }