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