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 {
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}
68
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}
94
95
96// Compatibility spawn functions
97
98// in Quake this is green armor, in Xonotic maps it is an armor shard
99SPAWNFUNC_ITEM(item_armor1, autocvar_sv_mapformat_is_quake3 ? ITEM_ArmorSmall : ITEM_ArmorMedium)
100SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega) // Nexuiz used item_armor25 to spawn a Mega Armor
101SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
102SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
103SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
104SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
105SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define SPAWNFUNC_ITEM(name, item)
Definition item.qh:106
@ ITEM_FLAG_NORMAL
Item is usable during normal gameplay.
Definition item.qh:120
#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:71
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_SET_LOOT(item, loot)
Sets the item loot status.
Definition spawning.qh:45
#define FOREACH_WORD(words, cond, body)
Definition iter.qh:33
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define LOG_FATALF(...)
Definition log.qh:54
#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, entity def)
Definition items.qc:1004
void weapon_defaultspawnfunc(entity this, Weapon e)
Definition spawning.qc:30
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:219
bool autocvar_sv_mapformat_is_quake3
Definition world.qh:32