Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
spawning.qc File Reference

Source file that contains implementation of the functions related to creation of game items. More...

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

bool Item_Initialise (entity item)
 An optimised and generic way to initialise items (loot or permanent)
bool Item_IsDefinitionAllowed (entity definition)
 Checks whether the items with the specified definition are allowed to spawn.
entity Item_RandomFromList (string itemlist)
 Takes a space-separated list of netnames, returns the itemdef of one of them (or NULL if none are available).

Detailed Description

Source file that contains implementation of the functions related to creation of game items.

Definition in file spawning.qc.

Function Documentation

◆ Item_Initialise()

bool Item_Initialise ( entity item)

An optimised and generic way to initialise items (loot or permanent)

Parameters
[in]itemThe item entity to initialise
Returns
True on success, false otherwise. \nore required field: itemdef (faster, preferred) OR classname optional fields: origin, velocity, lifetime, noalign lifetime < 0 means permanent (not loot), lifetime > 0 overrides the default permanent items only: noalign means the item is suspended (won't drop to floor)

Definition at line 27 of file spawning.qc.

28{
29 if (item.lifetime >= 0)
30 {
31 ITEM_SET_LOOT(item, true);
32 item.pickup_anyway = true; // these are ALWAYS pickable
33 }
34
35 if (item.itemdef) // no search required
36 {
37 if (item.itemdef.instanceOfWeapon)
38 weapon_defaultspawnfunc(item, item.itemdef);
39 else
40 StartItem(item, item.itemdef);
41 }
42 else // fall back to classname search
43 {
44 FOREACH(Weapons, it.m_canonical_spawnfunc == item.classname,
45 {
46 weapon_defaultspawnfunc(item, it);
47 goto classname_found;
48 });
49 FOREACH(Items, it.m_canonical_spawnfunc == item.classname,
50 {
51 StartItem(item, it);
52 goto classname_found;
53 });
54 LOG_FATALF("Invalid classname: %s", item.classname);
55 LABEL(classname_found)
56 }
57
58 if (wasfreed(item))
59 return false;
60
61 // StartItem sets the default .wait expiry time which is respected by Item_Think()
62 if (item.lifetime > 0)
63 item.wait = time + item.lifetime;
64
65 item.spawnfunc_checked = true;
66 return true;
67}
#define LABEL(id)
Definition compiler.qh:34
float time
Weapons
Definition guide.qh:113
#define ITEM_SET_LOOT(item, loot)
Sets the item loot status.
Definition spawning.qh:45
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define LOG_FATALF(...)
Definition log.qh:54
void StartItem(entity this, entity def)
Definition items.qc:1004
void weapon_defaultspawnfunc(entity this, Weapon e)
Definition spawning.qc:30

References entity(), FOREACH, ITEM_SET_LOOT, LABEL, LOG_FATALF, StartItem(), time, weapon_defaultspawnfunc(), and Weapons.

Referenced by monster_dropitem(), MUTATOR_HOOKFUNCTION(), ok_DropItem(), powerups_DropItem(), RandomItems_ReplaceMapItem(), and RandomItems_SpawnLootItem().

◆ Item_IsDefinitionAllowed()

bool Item_IsDefinitionAllowed ( entity definition)

Checks whether the items with the specified definition are allowed to spawn.

Parameters
[in]definitionItem definition to check.
Returns
True items with the specified definition are allowed to spawn, false otherwise.

Definition at line 17 of file spawning.qc.

18{
19 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
20}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143

References entity(), and MUTATOR_CALLHOOK.

Referenced by Item_RandomFromList(), RandomItems_GetRandomInstagibItemClassName(), RandomItems_GetRandomItemClassNameWithProperty(), RandomItems_GetRandomOverkillItemClassName(), and weapon_defaultspawnfunc().

◆ Item_RandomFromList()

entity Item_RandomFromList ( string itemlist)

Takes a space-separated list of netnames, returns the itemdef of one of them (or NULL if none are available).

Definition at line 71 of file spawning.qc.

72{
73 if(itemlist == "")
74 return NULL;
75
77 FOREACH_WORD(itemlist, true,
78 {
79 string item = it;
80
81 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & WEP_FLAG_MUTATORBLOCKED),
82 {
83 if(it.netname == item || (item == "random" && (it.spawnflags & WEP_FLAG_NORMAL) && !(it.spawnflags & WEP_FLAG_HIDDEN) && !(it.spawnflags & WEP_FLAG_SUPERWEAPON)))
84 RandomSelection_AddEnt(it, 1, 1);
85 });
87 {
88 if(it.netname == item || (item == "random" && (it.spawnflags & ITEM_FLAG_NORMAL) && !it.instanceOfPowerup))
89 RandomSelection_AddEnt(it, 1, 1);
90 });
91 });
93}
@ ITEM_FLAG_NORMAL
Item is usable during normal gameplay.
Definition item.qh:120
bool Item_IsDefinitionAllowed(entity definition)
Checks whether the items with the specified definition are allowed to spawn.
Definition spawning.qc:17
#define FOREACH_WORD(words, cond, body)
Definition iter.qh:33
#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
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:219

References entity(), FOREACH, FOREACH_WORD, ITEM_FLAG_NORMAL, Item_IsDefinitionAllowed(), NULL, RandomSelection_AddEnt, RandomSelection_chosen_ent, RandomSelection_Init(), Weapons, and WEP_FLAG_MUTATORBLOCKED.

Referenced by monster_dropitem(), and ok_DropItem().