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