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
7
10#include <common/weapons/all.qh>
11#include <server/items/items.qh>
14#include <server/world.qh>
15
16
18{
19 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
20}
21
22// An optimised and generic way to initialise items (loot or permanent)
23// required field: itemdef (faster, preferred) OR classname
24// optional fields: origin, velocity, lifetime, noalign
25// lifetime < 0 means permanent (not loot), lifetime > 0 overrides the default
26// permanent items only: noalign means the item is suspended (won't drop to floor)
28{
29 if (item.lifetime >= 0)
30 ITEM_SET_LOOT(item, true);
31 if (ITEM_IS_LOOT(item))
32 item.pickup_anyway = true; // these are ALWAYS pickable
33
34 if (item.itemdef) // no search required
35 StartItem(item);
36 else // fall back to classname search
37 {
38 FOREACH(Weapons, it.m_canonical_spawnfunc == item.classname,
39 {
40 item.itemdef = it;
41 goto classname_found;
42 });
43 FOREACH(Items, it.m_canonical_spawnfunc == item.classname,
44 {
45 item.itemdef = it;
46 goto classname_found;
47 });
48 LOG_WARNF("Item_Initialise: invalid item classname \"%s\"", item.classname);
49 return false;
50
51 LABEL(classname_found)
52 StartItem(item);
53 }
54
55 if (wasfreed(item))
56 return false;
57
58 // StartItem sets the default .wait expiry time which is respected by Item_Think()
59 if (item.lifetime > 0)
60 item.wait = time + item.lifetime;
61
62 item.spawnfunc_checked = true;
63 return true;
64}
65
69{
70 if(itemlist == "")
71 return NULL;
72
74 FOREACH_WORD(itemlist, true,
75 {
76 string item = it;
77
78 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & WEP_FLAG_MUTATORBLOCKED),
79 {
80 if(it.netname == item || (item == "random" && (it.spawnflags & WEP_FLAG_NORMAL) && !(it.spawnflags & WEP_FLAG_HIDDEN) && !(it.spawnflags & WEP_FLAG_SUPERWEAPON)))
81 RandomSelection_AddEnt(it, 1, 1);
82 });
84 {
85 if(it.netname == item || (item == "random" && (it.spawnflags & ITEM_FLAG_NORMAL) && !it.instanceOfPowerup))
86 RandomSelection_AddEnt(it, 1, 1);
87 });
88 });
90}
91
92
93// Compatibility spawn functions
94
95// in Quake this is green armor, in Xonotic maps it is an armor shard
96SPAWNFUNC_ITEM(item_armor1, autocvar_sv_mapformat_is_quake3 ? ITEM_ArmorSmall : ITEM_ArmorMedium)
97SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega) // Nexuiz used item_armor25 to spawn a Mega Armor
98SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
99SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
100SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
101SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
102SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
#define MUTATOR_CALLHOOK(name,...)
Definition base.qh:186
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define SPAWNFUNC_ITEM(name, item)
Definition item.qh:107
@ ITEM_FLAG_NORMAL
Item is usable during normal gameplay.
Definition item.qh:121
#define LABEL(id)
Definition compiler.qh:34
float time
Weapons
Definition guide.qh:113
entity Item_RandomFromList(string itemlist)
Takes a space-separated list of netnames, returns the itemdef of one of them (or NULL if none are ava...
Definition spawning.qc:68
bool Item_Initialise(entity item)
An optimised and generic way to initialise items (loot or permanent).
Definition spawning.qc:27
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:37
#define ITEM_SET_LOOT(item, loot)
Sets the item loot status.
Definition spawning.qh:43
#define FOREACH_WORD(words, cond, body)
Definition iter.qh:33
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define LOG_WARNF(...)
Definition log.qh:59
#define NULL
Definition post.qh:14
ERASEABLE void RandomSelection_Init()
Definition random.qc:4
#define RandomSelection_AddEnt(e, weight, priority)
Definition random.qh:14
entity RandomSelection_chosen_ent
Definition random.qh:5
void StartItem(entity this)
Definition items.qc:1008
const int WEP_FLAG_MUTATORBLOCKED
hides from impulse 99 etc. (mutators are allowed to clear this flag)
Definition weapon.qh:255
bool autocvar_sv_mapformat_is_quake3
Definition world.qh:32