Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
spawning.qc File Reference
Include dependency graph for spawning.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

string W_Apply_Weaponreplace (string in)
void weapon_defaultspawnfunc (entity this, Weapon wpn)

Variables

bool m_isreplaced
 Holds whether the weapon has been replaced.

Function Documentation

◆ W_Apply_Weaponreplace()

string W_Apply_Weaponreplace ( string in)

Definition at line 13 of file spawning.qc.

14{
15 string out = "";
16 FOREACH_WORD(in, true,
17 {
18 string replacement = "";
20 if (w)
21 replacement = (w.weaponreplace != "") ? w.weaponreplace : it;
22 if (replacement == "0")
23 continue;
24 out = cons(out, replacement);
25 });
26 return out;
27}
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:42
#define FOREACH_WORD(words, cond, body)
Definition iter.qh:33
ERASEABLE string cons(string a, string b)
Definition string.qh:276
Weapon Weapon_from_name(string s)
Definition all.qh:144

References cons(), FOREACH_WORD, and Weapon_from_name().

Referenced by MUTATOR_HOOKFUNCTION(), and weapon_defaultspawnfunc().

◆ weapon_defaultspawnfunc()

void weapon_defaultspawnfunc ( entity this,
Weapon wpn )

Definition at line 29 of file spawning.qc.

30{
31 wpn = wpn.m_spawnfunc_hookreplace(wpn, this);
32 this.classname = wpn.m_canonical_spawnfunc;
33 if (!ITEM_IS_LOOT(this) && !this.m_isreplaced)
34 {
36 {
37 //LOG_WARNF("Attempted to spawn a mutator-blocked weapon rejected: prvm_edict server %i", this);
38 startitem_failed = true;
39 return;
40 }
41
42 string s = W_Apply_Weaponreplace(wpn.netname);
43 MUTATOR_CALLHOOK(SetWeaponreplace, this, wpn, s);
44 s = M_ARGV(2, string);
45 if (s == "")
46 {
47 delete(this);
48 startitem_failed = true;
49 return;
50 }
51 int t = tokenize_console(s);
52 if (t >= 2)
53 {
54 this.team = --internalteam;
55 for (int i = 1; i < t; ++i)
56 {
57 s = argv(i);
58 Weapon wep = Weapon_from_name(s);
59 if (wep != WEP_Null)
60 {
61 entity replacement = spawn();
62 Item_CopyFields(this, replacement);
63 replacement.m_isreplaced = true;
64 weapon_defaultspawnfunc(replacement, wep);
65 }
66 }
67 }
68 if (t >= 1) // always the case!
69 {
70 s = argv(0);
71 wpn = Weapon_from_name(s);
72 }
73 if (wpn == WEP_Null)
74 {
75 delete(this);
76 startitem_failed = true;
77 return;
78 }
79 }
80
81 if (!ITEM_IS_LOOT(this))
83
84 if (!Item_IsDefinitionAllowed(wpn.m_pickup))
85 {
86 delete(this);
87 startitem_failed = true;
88 return;
89 }
90
91 if (!this.respawntime)
92 {
94 {
97 }
98 else
99 {
102 }
103 }
104
106 && !this.superweapons_finished)
108
109 // if we don't already have ammo, give us some ammo
110 // WEAPONTODO: magazines of MG, rifle and OK weapons are unaccounted for
111 if (wpn.ammo_type != RES_NONE && !GetResource(this, wpn.ammo_type))
112 SetResource(this, wpn.ammo_type,
113 this.count > 0 ? rint(this.count * GetAmmoConsumption(wpn)) : WEP_CVAR(wpn, pickup_ammo));
114
115 #if 0 // WEAPONTODO
116 if (wpn.items)
117 for (int i = 0, j = 1; i < 24; ++i, j <<= 1)
118 if (wpn.items & j)
119 {
120 ammotype = Item_CounterField(j);
121 if (!this.ammotype)
122 this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
123 }
124 #endif
125
126 // pickup anyway
128 this.pickup_anyway = true;
129
130 if (!this.owner)
131 this.glowmod = wpn.m_color;
132 else
133 this.glowmod = colormapPaletteColor(this.owner.clientcolors & 0x0F, true);
134
135 StartItem(this, wpn.m_pickup);
136
137 #if 0 // WEAPONTODO
138 if (this.modelindex) // don't precache if this was removed
139 wpn.wr_init(wpn);
140 #endif
141}
#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.
virtual void m_spawnfunc_hookreplace()
control what happens when this weapon is spawned
Definition weapon.qh:48
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:56
vector m_color
M: color : waypointsprite color.
Definition weapon.qh:62
string netname
M: refname : reference name name.
Definition weapon.qh:84
int spawnflags
M: flags : WEPSPAWNFLAG_... combined.
Definition weapon.qh:60
virtual void wr_init()
(BOTH) precaches models/sounds used by this weapon, also sets up weapon properties
Definition weapon.qh:114
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
#define ITEM_IS_LOOT(item)
Returns whether the item is loot.
Definition spawning.qh:39
bool startitem_failed
Definition spawning.qh:7
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:851
void StartItem(entity this, entity def)
Definition items.qc:1007
float autocvar_g_balance_superweapons_time
Definition items.qh:7
float respawntimejitter
Definition items.qh:32
float superweapons_finished
Definition items.qh:39
float pickup_anyway
Definition items.qh:27
float respawntime
Definition items.qh:31
int GetAmmoConsumption(entity wpn)
Returns ammo consumed per shot by the primary/default fire mode.
#define WEP_CVAR(wep, name)
Definition all.qh:337
#define WepSet_FromWeapon(it)
Definition all.qh:48
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:29
const int WEP_FLAG_SUPERWEAPON
Definition weapon.qh:260
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:261
float internalteam

References Weapon::ammo_type, argv(), autocvar_g_balance_superweapons_time, autocvar_g_pickup_respawntime_superweapon, autocvar_g_pickup_respawntime_weapon, autocvar_g_pickup_respawntimejitter_superweapon, autocvar_g_pickup_respawntimejitter_weapon, autocvar_g_pickup_weapons_anyway, classname, colormapPaletteColor, count, cvar(), entity(), GetAmmoConsumption(), GetResource(), glowmod, internalteam, Item_CopyFields(), ITEM_IS_LOOT, Item_IsDefinitionAllowed(), M_ARGV, Weapon::m_color, m_isreplaced, Weapon::m_spawnfunc_hookreplace(), modelindex, MUTATOR_CALLHOOK, Weapon::netname, owner, pickup_anyway, respawntime, respawntimejitter, rint(), SetResource(), spawn, Weapon::spawnflags, StartItem(), startitem_failed, strcat(), superweapons_finished, team, tokenize_console, W_Apply_Weaponreplace(), weapon_defaultspawnfunc(), Weapon_from_name(), weaponsInMapAll, WEP_CVAR, WEP_FLAG_MUTATORBLOCKED, WEP_FLAG_SUPERWEAPON, WepSet_FromWeapon, and Weapon::wr_init().

Referenced by Item_Initialise(), W_ThrowNewWeapon(), and weapon_defaultspawnfunc().

Variable Documentation

◆ m_isreplaced

bool m_isreplaced

Holds whether the weapon has been replaced.

Definition at line 11 of file spawning.qc.

Referenced by weapon_defaultspawnfunc().