Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
spawning.qc
Go to the documentation of this file.
1#include "spawning.qh"
2
9#include <server/world.qh>
10
12
13string W_Apply_Weaponreplace(string in)
14{
15 string out = "";
16 FOREACH_WORD(in, true, {
17 string replacement = "";
19 if (w)
20 {
21 replacement = w.weaponreplace;
22 if (replacement == "") replacement = it;
23 }
24 if (replacement == "0") continue;
25 out = cons(out, replacement);
26 });
27 return out;
28}
29
31{
32 wpn = wpn.m_spawnfunc_hookreplace(wpn, this);
33 this.classname = wpn.m_canonical_spawnfunc;
34 if (!ITEM_IS_LOOT(this) && !this.m_isreplaced)
35 {
37 {
38 //LOG_WARNF("Attempted to spawn a mutator-blocked weapon rejected: prvm_edict server %i", this);
39 startitem_failed = true;
40 return;
41 }
42
43 string s = W_Apply_Weaponreplace(wpn.netname);
44 MUTATOR_CALLHOOK(SetWeaponreplace, this, wpn, s);
45 s = M_ARGV(2, string);
46 if (s == "")
47 {
48 delete(this);
49 startitem_failed = true;
50 return;
51 }
52 int t = tokenize_console(s);
53 if (t >= 2)
54 {
55 this.team = --internalteam;
56 for (int i = 1; i < t; ++i)
57 {
58 s = argv(i);
59 Weapon wep = Weapon_from_name(s);
60 if(wep != WEP_Null)
61 {
62 entity replacement = spawn();
63 Item_CopyFields(this, replacement);
64 replacement.m_isreplaced = true;
65 weapon_defaultspawnfunc(replacement, wep);
66 }
67 }
68 }
69 if (t >= 1) // always the case!
70 {
71 s = argv(0);
72 wpn = Weapon_from_name(s);
73 }
74 if (wpn == WEP_Null)
75 {
76 delete(this);
77 startitem_failed = true;
78 return;
79 }
80 }
81
82 if(!ITEM_IS_LOOT(this))
84
85 if (!Item_IsDefinitionAllowed(wpn.m_pickup))
86 {
87 delete(this);
88 startitem_failed = true;
89 return;
90 }
91
92 if (!this.respawntime)
93 {
95 {
98 }
99 else
100 {
103 }
104 }
105
107 if (!this.superweapons_finished)
109
110 // if we don't already have ammo, give us some ammo
111 // WEAPONTODO: magazines of MG, rifle and OK weapons are unaccounted for
112 if ((wpn.ammo_type != RES_NONE) && !GetResource(this, wpn.ammo_type))
113 SetResource(this, wpn.ammo_type,
114 this.count > 0 ? rint(this.count * GetAmmoConsumption(wpn)) : WEP_CVAR(wpn, pickup_ammo));
115
116 #if 0 // WEAPONTODO
117 if (wpn.items)
118 {
119 for (int i = 0, j = 1; i < 24; ++i, j <<= 1)
120 {
121 if (wpn.items & j)
122 {
123 ammotype = Item_CounterField(j);
124 if (!this.ammotype)
125 this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
126 }
127 }
128 }
129 #endif
130
131 // pickup anyway
133 this.pickup_anyway = true;
134
135 if(!this.owner)
136 this.glowmod = wpn.m_color;
137 else
138 this.glowmod = colormapPaletteColor(this.owner.clientcolors & 0x0F, true);
139
140 StartItem(this, wpn.m_pickup);
141
142 #if 0 // WEAPONTODO
143 if (this.modelindex) { // don't precache if this was removed
144 wpn.wr_init(wpn);
145 }
146 #endif
147}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void SetResource(entity e, Resource res_type, float amount)
Sets the current amount of resource the given entity will have.
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:44
virtual void m_spawnfunc_hookreplace()
control what happens when this weapon is spawned
Definition weapon.qh:49
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:51
vector m_color
M: color : waypointsprite color.
Definition weapon.qh:59
string netname
M: refname : reference name name.
Definition weapon.qh:79
int spawnflags
M: flags : WEPSPAWNFLAG_... combined.
Definition weapon.qh:55
virtual void wr_init()
(BOTH) precaches models/sounds used by this weapon, also sets up weapon properties
Definition weapon.qh:98
float count
Definition powerups.qc:22
entity owner
Definition main.qh:87
int team
Definition main.qh:188
#define colormapPaletteColor(c, isPants)
Definition color.qh:5
#define M_ARGV(x, type)
Definition events.qh:17
vector weaponsInMapAll
all the weapons placed by the mapper (weaponreplace applied), ignores most filters
Definition stats.qh:55
string classname
float modelindex
#define spawn
vector glowmod
#define tokenize_console
bool Item_IsDefinitionAllowed(entity definition)
Checks whether the items with the specified definition are allowed to spawn.
Definition spawning.qc:17
Header file that describes the functions related to game items.
#define ITEM_IS_LOOT(item)
Returns whether the item is loot.
Definition spawning.qh:39
bool startitem_failed
Definition spawning.qh:7
#define FOREACH_WORD(words, cond, body)
Definition iter.qh:33
float cvar(string name)
float rint(float f)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
void Item_CopyFields(entity this, entity to)
Definition items.qc:850
void StartItem(entity this, entity def)
Definition items.qc:1004
float autocvar_g_balance_superweapons_time
Definition items.qh:6
float respawntimejitter
Definition items.qh:31
float superweapons_finished
Definition items.qh:38
float pickup_anyway
Definition items.qh:26
float respawntime
Definition items.qh:30
ERASEABLE string cons(string a, string b)
Definition string.qh:276
int GetAmmoConsumption(entity wpn)
Returns ammo consumed per shot by the primary/default fire mode.
Header file that describes the resource system.
Weapon Weapon_from_name(string s)
Definition all.qh:144
#define WEP_CVAR(wep, name)
Definition all.qh:321
#define WepSet_FromWeapon(it)
Definition all.qh:46
bool m_isreplaced
Holds whether the weapon has been replaced.
Definition spawning.qc:11
string W_Apply_Weaponreplace(string in)
Definition spawning.qc:13
float autocvar_g_pickup_respawntimejitter_weapon
Definition spawning.qh:10
bool autocvar_g_pickup_weapons_anyway
Definition spawning.qh:6
float autocvar_g_pickup_respawntimejitter_superweapon
Definition spawning.qh:8
float autocvar_g_pickup_respawntime_weapon
Definition spawning.qh:9
float autocvar_g_pickup_respawntime_superweapon
Definition spawning.qh:7
void weapon_defaultspawnfunc(entity this, Weapon e)
Definition spawning.qc:30
const int WEP_FLAG_SUPERWEAPON
Definition weapon.qh:218
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:219
float internalteam