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