]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/compat/quake3.qc
GetResourceAmount --> GetResource, SetResourceAmount --> SetResource
[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/weapons/_all.qh>
11
12 //***********************
13 //QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons
14 //***********************
15
16 // NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG
17
18 // SG -> SG
19 SPAWNFUNC_ITEM(ammo_shells, ITEM_Shells)
20
21 // MG -> MG
22 SPAWNFUNC_ITEM(ammo_bullets, ITEM_Bullets)
23
24 // GL -> Mortar
25 SPAWNFUNC_ITEM(ammo_grenades, ITEM_Rockets)
26
27 // Mines -> Rockets
28 SPAWNFUNC_WEAPON(weapon_prox_launcher, WEP_MINE_LAYER)
29 SPAWNFUNC_ITEM(ammo_mines, ITEM_Rockets)
30
31 // LG -> Lightning
32 SPAWNFUNC_WEAPON(weapon_lightning, WEP_ELECTRO)
33 SPAWNFUNC_ITEM(ammo_lightning, ITEM_Cells)
34
35 // Plasma -> Hagar
36 SPAWNFUNC_WEAPON(weapon_plasmagun, WEP_HAGAR)
37 SPAWNFUNC_ITEM(ammo_cells, ITEM_Rockets)
38
39 // Rail -> Vortex
40 SPAWNFUNC_WEAPON(weapon_railgun, WEP_VORTEX)
41 SPAWNFUNC_ITEM(ammo_slugs, ITEM_Cells)
42
43 // BFG -> Crylink
44 SPAWNFUNC_WEAPON(weapon_bfg, WEP_CRYLINK)
45 SPAWNFUNC_ITEM(ammo_bfg, ITEM_Cells)
46
47 // grappling hook -> hook
48 SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
49
50 // RL -> RL
51 SPAWNFUNC_ITEM(ammo_rockets, ITEM_Rockets)
52
53 // Armor
54 SPAWNFUNC_ITEM(item_armor_body, ITEM_ArmorMega)
55 SPAWNFUNC_ITEM(item_armor_combat, ITEM_ArmorBig)
56 SPAWNFUNC_ITEM(item_armor_shard, ITEM_ArmorSmall)
57 SPAWNFUNC_ITEM(item_enviro, ITEM_Shield)
58
59 // medkit -> armor (we have no holdables)
60 SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorMega)
61
62 // doubler -> strength
63 SPAWNFUNC_ITEM(item_doubler, ITEM_Strength)
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                 SetResource(actor, RES_SHELLS, start_ammo_shells);
105                 SetResource(actor, RES_BULLETS, start_ammo_nails);
106                 SetResource(actor, RES_ROCKETS, start_ammo_rockets);
107                 SetResource(actor, RES_CELLS, start_ammo_cells);
108                 SetResource(actor, RES_PLASMA, start_ammo_plasma);
109                 SetResource(actor, RES_FUEL, start_ammo_fuel);
110
111                 STAT(WEAPONS, actor) = start_weapons;
112                 if (this.spawnflags & 32)
113                 {
114                         // TODO
115                 }
116         }
117
118         if (!(this.spawnflags & 8))
119         {
120                 actor.strength_finished = 0;
121                 actor.invincible_finished = 0;
122                 STAT(BUFFS, actor) = 0;
123         }
124
125         if (!(this.spawnflags & 16))
126         {
127                 // We don't have holdables.
128         }
129
130         SUB_UseTargets(this, actor, trigger);
131 }
132
133 spawnfunc(target_init)
134 {
135         this.use = target_init_use;
136         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
137 }
138
139 // weapon give ent from defrag
140 void target_give_init(entity this)
141 {
142         IL_EACH(g_items, it.targetname == this.target,
143         {
144                 if (it.classname == "weapon_devastator") {
145                         SetResource(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(devastator, ammo)); // WEAPONTODO
146                         this.netname = cons(this.netname, "devastator");
147                 }
148                 else if (it.classname == "weapon_vortex") {
149                         SetResource(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(vortex, ammo)); // WEAPONTODO
150                         this.netname = cons(this.netname, "vortex");
151                 }
152                 else if (it.classname == "weapon_electro") {
153                         SetResource(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(electro, ammo)); // WEAPONTODO
154                         this.netname = cons(this.netname, "electro");
155                 }
156                 else if (it.classname == "weapon_hagar") {
157                         SetResource(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(hagar, ammo)); // WEAPONTODO
158                         this.netname = cons(this.netname, "hagar");
159                 }
160                 else if (it.classname == "weapon_crylink") {
161                         SetResource(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(crylink, ammo)); // WEAPONTODO
162                         this.netname = cons(this.netname, "crylink");
163                 }
164                 else if (it.classname == "weapon_mortar") {
165                         SetResource(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(mortar, ammo)); // WEAPONTODO
166                         this.netname = cons(this.netname, "mortar");
167                 }
168                 else if (it.classname == "item_armor_mega")
169                         SetResource(this, RES_ARMOR, 100);
170                 else if (it.classname == "item_health_mega")
171                         SetResource(this, RES_HEALTH, 200);
172                 //remove(it); // removing ents in init functions causes havoc, workaround:
173         setthink(it, SUB_Remove);
174         it.nextthink = time;
175         });
176         this.spawnflags = 2;
177         this.spawnfunc_checked = true;
178         spawnfunc_target_items(this);
179         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
180 }
181
182 spawnfunc(target_give)
183 {
184         InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
185 }
186
187 void score_use(entity this, entity actor, entity trigger)
188 {
189         if(!IS_PLAYER(actor))
190                 return;
191         actor.fragsfilter_cnt += this.count;
192 }
193 spawnfunc(target_score)
194 {
195         if(!g_cts) { delete(this); return; }
196
197         if(!this.count)
198                 this.count = 1;
199         this.use = score_use;
200 }
201
202 void fragsfilter_use(entity this, entity actor, entity trigger)
203 {
204         if(!IS_PLAYER(actor))
205                 return;
206         if(actor.fragsfilter_cnt >= this.frags)
207                 SUB_UseTargets(this, actor, trigger);
208 }
209 spawnfunc(target_fragsFilter)
210 {
211         if(!g_cts) { delete(this); return; }
212
213         if(!this.frags)
214                 this.frags = 1;
215         this.use = fragsfilter_use;
216 }
217
218 //spawnfunc(item_flight)       /* handled by buffs mutator */
219 //spawnfunc(item_haste)        /* handled by buffs mutator */
220 //spawnfunc(item_health)       /* handled in t_quake.qc */
221 //spawnfunc(item_health_large) /* handled in t_items.qc */
222 //spawnfunc(item_health_small) /* handled in t_items.qc */
223 //spawnfunc(item_health_mega)  /* handled in t_items.qc */
224 //spawnfunc(item_invis)        /* handled by buffs mutator */
225 //spawnfunc(item_regen)        /* handled by buffs mutator */
226
227 // CTF spawnfuncs handled in mutators/gamemode_ctf.qc now
228
229 .float notteam;
230 .float notsingle;
231 .float notfree;
232 .float notq3a;
233 .float notta;
234 .string gametype;
235 bool DoesQ3ARemoveThisEntity(entity this)
236 {
237         // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
238
239         if(this.notq3a)
240                 if(!teamplay || g_tdm || g_ctf)
241                         return true;
242
243         if(this.notta)
244                 if (!(!teamplay || g_tdm || g_ctf))
245                         return true;
246
247         if(this.notsingle)
248                 if(maxclients == 1)
249                         return true;
250
251         if(this.notteam)
252                 if(teamplay)
253                         return true;
254
255         if(this.notfree)
256                 if(!teamplay)
257                         return true;
258
259         if(this.gametype)
260         {
261                 string gametypename;
262                 // static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester", "teamtournament"}
263                 gametypename = "ffa";
264                 if(teamplay)
265                         gametypename = "team";
266                 if(g_ctf)
267                         gametypename = "ctf";
268                 if(g_duel)
269                         gametypename = "tournament";
270                 if(maxclients == 1)
271                         gametypename = "single";
272                 // we do not have the other types (oneflag, obelisk, harvester, teamtournament)
273                 if(strstrofs(this.gametype, gametypename, 0) < 0)
274                         return true;
275         }
276
277         return false;
278 }