Xonotic
sv_random_items.qh File Reference

Header file that describes the random items mutator. More...

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

Go to the source code of this file.

Macros

#define EV_RandomItems_GetRandomItemClassName(i, o)
 Called when random item classname is requested. More...
 

Enumerations

enum  {
  RANDOM_ITEM_TYPE_HEALTH = BIT(0), RANDOM_ITEM_TYPE_ARMOR = BIT(1), RANDOM_ITEM_TYPE_RESOURCE = BIT(2), RANDOM_ITEM_TYPE_WEAPON = BIT(3),
  RANDOM_ITEM_TYPE_POWERUP = BIT(4), RANDOM_ITEM_TYPE_ALL = BITS(5)
}
 

Functions

 MUTATOR_HOOKABLE (RandomItems_GetRandomItemClassName, EV_RandomItems_GetRandomItemClassName)
 
string RandomItems_GetRandomItemClassName (string prefix)
 Returns a random classname of the item. More...
 
string RandomItems_GetRandomVanillaItemClassName (string prefix, int types)
 Returns a random classname of the vanilla item. More...
 
 REGISTER_MUTATOR (random_items,(autocvar_g_random_items||autocvar_g_random_loot))
 

Variables

bool autocvar_g_random_items
 Whether to enable random items. More...
 
bool autocvar_g_random_loot
 Whether to enable random loot. More...
 

Detailed Description

Header file that describes the random items mutator.

Author
Lyberta

Definition in file sv_random_items.qh.

Macro Definition Documentation

◆ EV_RandomItems_GetRandomItemClassName

#define EV_RandomItems_GetRandomItemClassName (   i,
 
)
Value:
i(string, MUTATOR_ARGV_0_string) \ o(string, MUTATOR_ARGV_1_string) \

Called when random item classname is requested.

Definition at line 37 of file sv_random_items.qh.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RANDOM_ITEM_TYPE_HEALTH 
RANDOM_ITEM_TYPE_ARMOR 
RANDOM_ITEM_TYPE_RESOURCE 
RANDOM_ITEM_TYPE_WEAPON 
RANDOM_ITEM_TYPE_POWERUP 
RANDOM_ITEM_TYPE_ALL 

Definition at line 11 of file sv_random_items.qh.

Function Documentation

◆ MUTATOR_HOOKABLE()

◆ RandomItems_GetRandomItemClassName()

string RandomItems_GetRandomItemClassName ( string  prefix)

Returns a random classname of the item.

Parameters
[in]prefixPrefix of the cvars that hold probabilities.
Returns
Random classname of the item.
Note
This function will automatically detect gamemode and use cvars from that gamemode.

Definition at line 54 of file sv_random_items.qc.

References M_ARGV, MUTATOR_CALLHOOK, RANDOM_ITEM_TYPE_ALL, RandomItems_GetRandomItemClassName(), and RandomItems_GetRandomVanillaItemClassName().

Referenced by RandomItems_GetRandomItemClassName(), RandomItems_ReplaceMapItem(), and RandomItems_SpawnLootItem().

55 {
57  {
58  return M_ARGV(1, string);
59  }
62 }
string RandomItems_GetRandomVanillaItemClassName(string prefix, int types)
Returns a random classname of the vanilla item.
string RandomItems_GetRandomItemClassName(string prefix)
Returns a random classname of the item.
#define M_ARGV(x, type)
Definition: events.qh:17
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RandomItems_GetRandomVanillaItemClassName()

string RandomItems_GetRandomVanillaItemClassName ( string  prefix,
int  types 
)

Returns a random classname of the vanilla item.

Parameters
[in]prefixPrefix of the cvars that hold probabilities.
[in]typesBitmask of the types. See RANDOM_ITEM_TYPE constants.
Returns
Random classname of the vanilla item.
Note
This includes mutator items that don't change gameplay a lot such as jetpack and new toys.

Definition at line 64 of file sv_random_items.qc.

References cvar(), CVAR_TYPEFLAG_EXISTS, FOREACH, LOG_WARNF, RANDOM_ITEM_TYPE_ARMOR, RANDOM_ITEM_TYPE_HEALTH, RANDOM_ITEM_TYPE_POWERUP, RANDOM_ITEM_TYPE_RESOURCE, RANDOM_ITEM_TYPE_WEAPON, RandomItems_GetRandomItemClassNameWithProperty(), RandomSelection_AddFloat, RandomSelection_AddString, RandomSelection_chosen_float, RandomSelection_chosen_string, RandomSelection_Init(), and WEP_FLAG_MUTATORBLOCKED.

Referenced by RandomItems_GetRandomItemClassName().

65 {
66  if (types == 0)
67  {
68  return "";
69  }
70  while (types != 0)
71  {
72  string cvar_name;
74  if (types & RANDOM_ITEM_TYPE_HEALTH)
75  {
76  cvar_name = sprintf("g_%s_health_probability", prefix);
77  if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
78  {
79  LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
80  }
81  else
82  {
83  RandomSelection_AddFloat(RANDOM_ITEM_TYPE_HEALTH,
84  cvar(cvar_name), 1);
85  }
86  }
87  if (types & RANDOM_ITEM_TYPE_ARMOR)
88  {
89  cvar_name = sprintf("g_%s_armor_probability", prefix);
90  if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
91  {
92  LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
93  }
94  else
95  {
96  RandomSelection_AddFloat(RANDOM_ITEM_TYPE_ARMOR,
97  cvar(cvar_name), 1);
98  }
99  }
100  if (types & RANDOM_ITEM_TYPE_RESOURCE)
101  {
102  cvar_name = sprintf("g_%s_resource_probability", prefix);
103  if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
104  {
105  LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
106  }
107  else
108  {
109  RandomSelection_AddFloat(RANDOM_ITEM_TYPE_RESOURCE,
110  cvar(cvar_name), 1);
111  }
112  }
113  if (types & RANDOM_ITEM_TYPE_WEAPON)
114  {
115  cvar_name = sprintf("g_%s_weapon_probability", prefix);
116  if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
117  {
118  LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
119  }
120  else
121  {
122  RandomSelection_AddFloat(RANDOM_ITEM_TYPE_WEAPON, cvar(cvar_name), 1);
123  }
124  }
125  if (types & RANDOM_ITEM_TYPE_POWERUP)
126  {
127  cvar_name = sprintf("g_%s_powerup_probability", prefix);
128  if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
129  {
130  LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
131  }
132  else
133  {
134  RandomSelection_AddFloat(RANDOM_ITEM_TYPE_POWERUP, cvar(cvar_name), 1);
135  }
136  }
137  int item_type = RandomSelection_chosen_float;
138  string class_name = "";
139  switch (item_type)
140  {
142  {
144  prefix, instanceOfHealth);
145  break;
146  }
148  {
150  prefix, instanceOfArmor);
151  break;
152  }
154  {
156  prefix, instanceOfAmmo);
157  break;
158  }
160  {
162  FOREACH(Weapons, it != WEP_Null &&
163  !(it.spawnflags & WEP_FLAG_MUTATORBLOCKED),
164  {
165  cvar_name = sprintf("g_%s_%s_probability", prefix,
166  it.m_canonical_spawnfunc);
167  if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
168  {
169  LOG_WARNF("Random items: cvar %s doesn't exist.",
170  cvar_name);
171  continue;
172  }
173  RandomSelection_AddString(it.m_canonical_spawnfunc,
174  cvar(cvar_name), 1);
175  });
176  class_name = RandomSelection_chosen_string;
177  break;
178  }
180  {
182  prefix, instanceOfPowerup);
183  break;
184  }
185  }
186  if (class_name != "")
187  {
188  return class_name;
189  }
190  types &= ~item_type;
191  }
192  return "";
193 }
string RandomSelection_chosen_string
Definition: random.qh:7
ERASEABLE void RandomSelection_Init()
Definition: random.qc:4
float CVAR_TYPEFLAG_EXISTS
#define RandomSelection_AddString(s, weight, priority)
Definition: random.qh:16
float RandomSelection_chosen_float
Definition: random.qh:6
#define LOG_WARNF(...)
Definition: log.qh:67
string RandomItems_GetRandomItemClassNameWithProperty(string prefix,.bool item_property)
Returns a random classname of the item with specific property.
#define RandomSelection_AddFloat(f, weight, priority)
Definition: random.qh:15
const int WEP_FLAG_MUTATORBLOCKED
Definition: weapon.qh:203
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( random_items  ,
(autocvar_g_random_items||autocvar_g_random_loot  
)

Variable Documentation

◆ autocvar_g_random_items

bool autocvar_g_random_items

Whether to enable random items.

Definition at line 8 of file sv_random_items.qh.

Referenced by MUTATOR_HOOKFUNCTION().

◆ autocvar_g_random_loot

bool autocvar_g_random_loot

Whether to enable random loot.

Definition at line 9 of file sv_random_items.qh.

Referenced by MUTATOR_HOOKFUNCTION().