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