Xonotic
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

entity Item_Create (string class_name, vector position, bool no_align)
 Creates a new item. More...
 
entity Item_CreateLoot (string class_name, vector position, vector vel, float time_to_live)
 Creates a loot item. More...
 
entity Item_DefinitionFromInternalName (string item_name)
 Returns the item definition corresponding to the given internal name. More...
 
entity Item_FindDefinition (string class_name)
 Returns the item definition corresponding to the given class name. More...
 
void Item_Initialize (entity item, string class_name)
 Initializes the item according to class name. More...
 
bool Item_InitializeLoot (entity item, string class_name, vector position, vector vel, float time_to_live)
 Initializes the loot item. More...
 
bool Item_IsAllowed (string class_name)
 Checks whether the items with the specified class name are allowed to spawn. More...
 
bool Item_IsDefinitionAllowed (entity definition)
 Checks whether the items with the specified definition are allowed to spawn. More...
 
bool Item_IsExpiring (entity item)
 Returns whether the item is expiring (i.e. More...
 
bool Item_IsLoot (entity item)
 Returns whether the item is loot. More...
 
void Item_SetExpiring (entity item, bool expiring)
 Sets the item expiring status (i.e. More...
 
void Item_SetLoot (entity item, bool loot)
 Sets the item loot status. More...
 
bool Item_ShouldKeepPosition (entity item)
 Returns whether item should keep its position or be dropped to the ground. More...
 

Variables

bool m_isexpiring
 Holds whether strength, shield or superweapon timers expire while this item is on the ground. More...
 
bool m_isloot
 Holds whether item is loot. More...
 

Detailed Description

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

Definition in file spawning.qc.

Function Documentation

◆ Item_Create()

entity Item_Create ( string  class_name,
vector  position,
bool  no_align 
)

Creates a new item.

Parameters
[in]class_nameClass name of the item.
[in]positionPosition of the item.
[in]no_alignTrue if item should be placed directly at specified position, false to let it drop to the ground.
Returns
Item on success, NULL otherwise.

Definition at line 60 of file spawning.qc.

References entity(), Item_Initialize(), NULL, setorigin(), and spawn().

Referenced by RandomItems_ReplaceMapItem().

61 {
62  entity item = spawn();
63  item.classname = class_name;
64  item.spawnfunc_checked = true;
65  setorigin(item, position);
66  item.noalign = no_align;
67  Item_Initialize(item, class_name);
68  if (wasfreed(item))
69  {
70  return NULL;
71  }
72  return item;
73 }
void Item_Initialize(entity item, string class_name)
Initializes the item according to class name.
Definition: spawning.qc:75
entity() spawn
#define NULL
Definition: post.qh:17
setorigin(ent, v)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Item_CreateLoot()

entity Item_CreateLoot ( string  class_name,
vector  position,
vector  vel,
float  time_to_live 
)

Creates a loot item.

Parameters
[in]class_nameClass name of the item.
[in]positionPosition of the item.
[in]velocityof the item.
[in]time_to_liveAmount of time after which the item will disappear.
Returns
Item on success, NULL otherwise.

Definition at line 90 of file spawning.qc.

References entity(), Item_InitializeLoot(), NULL, and spawn().

Referenced by RandomItems_SpawnLootItem().

92 {
93  entity item = spawn();
94  if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
95  {
96  return NULL;
97  }
98  return item;
99 }
bool Item_InitializeLoot(entity item, string class_name, vector position, vector vel, float time_to_live)
Initializes the loot item.
Definition: spawning.qc:101
entity() spawn
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Item_DefinitionFromInternalName()

entity Item_DefinitionFromInternalName ( string  item_name)

Returns the item definition corresponding to the given internal name.

Parameters
[in]item_nameInternal netname to search for.
Returns
Item definition corresponding to the given internal name or NULL is not found.

Definition at line 32 of file spawning.qc.

References FOREACH, and NULL.

Referenced by powerups_DropItem().

33 {
34  FOREACH(Items, it.netname == item_name,
35  {
36  return it;
37  });
38  FOREACH(Weapons, it.netname == item_name,
39  {
40  return it.m_pickup;
41  });
42  return NULL;
43 }
#define NULL
Definition: post.qh:17
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ Item_FindDefinition()

entity Item_FindDefinition ( string  class_name)

Returns the item definition corresponding to the given class name.

Parameters
[in]class_nameClass name to search for.
Returns
Item definition corresponding to the given class name or NULL is not found.

Definition at line 19 of file spawning.qc.

References FOREACH, and NULL.

Referenced by Item_IsAllowed().

20 {
21  FOREACH(Items, it.m_canonical_spawnfunc == class_name,
22  {
23  return it;
24  });
25  FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
26  {
27  return it.m_pickup;
28  });
29  return NULL;
30 }
#define NULL
Definition: post.qh:17
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ Item_Initialize()

void Item_Initialize ( entity  item,
string  class_name 
)

Initializes the item according to class name.

Parameters
[in,out]itemItem to initialize.
[in]class_nameClass name to use.
Returns
No return. This function is useful if you want to set some item properties before initialization.

Definition at line 75 of file spawning.qc.

References FOREACH, and LOG_FATALF.

Referenced by Item_Create(), Item_InitializeLoot(), MUTATOR_HOOKFUNCTION(), and RandomItems_ReplaceMapItem().

76 {
77  FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
78  {
79  weapon_defaultspawnfunc(item, it);
80  return;
81  });
82  FOREACH(Items, it.m_canonical_spawnfunc == class_name,
83  {
84  StartItem(item, it);
85  return;
86  });
87  LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
88 }
#define LOG_FATALF(...)
Definition: log.qh:59
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ Item_InitializeLoot()

bool Item_InitializeLoot ( entity  item,
string  class_name,
vector  position,
vector  vel,
float  time_to_live 
)

Initializes the loot item.

Parameters
[in]class_nameClass name of the item.
[in]positionPosition of the item.
[in]velocityof the item.
[in]time_to_liveAmount of time after which the item will disappear.
Returns
True on success, false otherwise. This function is useful if you want to set some item properties before initialization.

Definition at line 101 of file spawning.qc.

References Item_Initialize(), Item_SetLoot(), setorigin(), SUB_SetFade(), and time.

Referenced by Item_CreateLoot(), ok_DropItem(), powerups_DropItem(), and RandomItems_SpawnLootItem().

103 {
104  item.classname = class_name;
105  Item_SetLoot(item, true);
106  item.noalign = true;
107  setorigin(item, position);
108  item.pickup_anyway = true;
109  item.spawnfunc_checked = true;
110  Item_Initialize(item, class_name);
111  if (wasfreed(item))
112  {
113  return false;
114  }
115  item.gravity = 1;
116  item.velocity = vel;
117  SUB_SetFade(item, time + time_to_live, 1);
118  return true;
119 }
void Item_Initialize(entity item, string class_name)
Initializes the item according to class name.
Definition: spawning.qc:75
setorigin(ent, v)
void SUB_SetFade(entity ent, float vanish_time, float fading_time)
Definition: subs.qc:77
float time
Definition: csprogsdefs.qc:16
void Item_SetLoot(entity item, bool loot)
Sets the item loot status.
Definition: spawning.qc:126
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Item_IsAllowed()

bool Item_IsAllowed ( string  class_name)

Checks whether the items with the specified class name are allowed to spawn.

Parameters
[in]class_nameItem class name to check.
Returns
True items with the specified class name are allowed to spawn, false otherwise.

Definition at line 45 of file spawning.qc.

References entity(), Item_FindDefinition(), Item_IsDefinitionAllowed(), and NULL.

46 {
47  entity definition = Item_FindDefinition(class_name);
48  if (definition == NULL)
49  {
50  return false;
51  }
52  return Item_IsDefinitionAllowed(definition);
53 }
bool Item_IsDefinitionAllowed(entity definition)
Checks whether the items with the specified definition are allowed to spawn.
Definition: spawning.qc:55
entity Item_FindDefinition(string class_name)
Returns the item definition corresponding to the given class name.
Definition: spawning.qc:19
entity() spawn
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:

◆ 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 55 of file spawning.qc.

References MUTATOR_CALLHOOK.

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

56 {
57  return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
58 }
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
+ Here is the caller graph for this function:

◆ Item_IsExpiring()

bool Item_IsExpiring ( entity  item)

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 136 of file spawning.qc.

Referenced by _StartItem(), and Item_Touch().

137 {
138  return item.m_isexpiring;
139 }
+ Here is the caller graph for this function:

◆ Item_IsLoot()

bool Item_IsLoot ( entity  item)

Returns whether the item is loot.

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

Definition at line 121 of file spawning.qc.

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

122 {
123  return item.m_isloot || item.classname == "droppedweapon";
124 }
+ Here is the caller graph for this function:

◆ Item_SetExpiring()

void Item_SetExpiring ( entity  item,
bool  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 141 of file spawning.qc.

References cvar(), and SPAWNFUNC_ITEM().

Referenced by powerups_DropItem(), and W_ThrowNewWeapon().

142 {
143  item.m_isexpiring = expiring;
144 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Item_SetLoot()

void Item_SetLoot ( entity  item,
bool  loot 
)

Sets the item loot status.

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

Definition at line 126 of file spawning.qc.

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

127 {
128  item.m_isloot = loot;
129 }
+ Here is the caller graph for this function:

◆ Item_ShouldKeepPosition()

bool Item_ShouldKeepPosition ( entity  item)

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 131 of file spawning.qc.

Referenced by buff_SpawnReplacement(), MUTATOR_HOOKFUNCTION(), RandomItems_ReplaceMapItem(), and replace_with_insta_cells().

132 {
133  return item.noalign || (item.spawnflags & 1);
134 }
+ Here is the caller graph for this function:

Variable Documentation

◆ m_isexpiring

bool m_isexpiring

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

Definition at line 17 of file spawning.qc.

◆ m_isloot

bool m_isloot

Holds whether item is loot.

Definition at line 14 of file spawning.qc.