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