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