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