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

Header file that describes the functions related to game items. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ITEM_IS_EXPIRING(item)
 Returns whether the item is expiring (i.e.
#define ITEM_IS_LOOT(item)
 Returns whether the item is loot.
#define ITEM_SET_EXPIRING(item, expiring)
 Sets the item expiring status (i.e.
#define ITEM_SET_LOOT(item, loot)
 Sets the item loot status.
#define ITEM_SHOULD_KEEP_POSITION(item)
 Returns whether item should keep its position or be dropped to the ground.

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).

Variables

float lifetime
 lifetime < 0 means permanent (not loot), lifetime > 0 overrides the default
bool m_isexpiring
 Holds whether strength, shield or superweapon timers expire while this item is on the ground.
bool m_isloot
 Holds whether item is loot.
bool startitem_failed

Detailed Description

Header file that describes the functions related to game items.

Definition in file spawning.qh.

Macro Definition Documentation

◆ ITEM_IS_EXPIRING

#define ITEM_IS_EXPIRING ( item)
Value:
(item.m_isexpiring)

Returns whether the item is expiring (i.e.

its strength, shield and superweapon timers expire while it is on the ground).

Parameters
[in]itemItem to check.
Returns
True if the item is expiring, false otherwise.

Definition at line 58 of file spawning.qh.

Referenced by Item_Touch(), and StartItem().

◆ ITEM_IS_LOOT

#define ITEM_IS_LOOT ( item)
Value:
(item.m_isloot || item.classname == "droppedweapon")

Returns whether the item is loot.

Parameters
[in]itemItem to check.
Returns
True if the item is loot, false otherwise.

Definition at line 39 of file spawning.qh.

Referenced by havocbot_goalrating_items(), havocbot_movetogoal(), isPushable(), Item_Reset(), Item_Think(), Item_Touch(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), setItemGroup(), StartItem(), target_items_use(), and weapon_defaultspawnfunc().

◆ ITEM_SET_EXPIRING

#define ITEM_SET_EXPIRING ( item,
expiring )
Value:
(item.m_isexpiring = expiring)

Sets the item expiring status (i.e.

whether its strength, shield and superweapon timers expire while it is on the ground).

Parameters
[in,out]itemItem to adjust.
[in]expiringWhether item is expiring.
Returns
No return.

Definition at line 65 of file spawning.qh.

Referenced by powerups_DropItem(), and W_ThrowNewWeapon().

◆ ITEM_SET_LOOT

#define ITEM_SET_LOOT ( item,
loot )
Value:
(item.m_isloot = loot)

Sets the item loot status.

Parameters
[in,out]itemItem to adjust.
[in]lootWhether item is loot.
Returns
No return.

Definition at line 45 of file spawning.qh.

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

◆ ITEM_SHOULD_KEEP_POSITION

#define ITEM_SHOULD_KEEP_POSITION ( item)
Value:
(item.noalign || (item.spawnflags & 1))

Returns whether item should keep its position or be dropped to the ground.

Parameters
[in]itemItem to check.
Returns
True if item should keep its position or false if it should be dropped to the ground.

Definition at line 52 of file spawning.qh.

Referenced by buff_SpawnReplacement(), and Item_CopyFields().

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().

Variable Documentation

◆ lifetime

float lifetime

lifetime < 0 means permanent (not loot), lifetime > 0 overrides the default

Definition at line 10 of file spawning.qh.

◆ m_isexpiring

bool m_isexpiring

Holds whether strength, shield or superweapon timers expire while this item is on the ground.

Definition at line 14 of file spawning.qh.

◆ m_isloot

bool m_isloot

Holds whether item is loot.

Definition at line 12 of file spawning.qh.

◆ startitem_failed

bool startitem_failed

Definition at line 7 of file spawning.qh.

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