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