Xonotic
sv_new_toys.qc File Reference
+ Include dependency graph for sv_new_toys.qc:

Go to the source code of this file.

Functions

 MUTATOR_HOOKFUNCTION (nt, SetStartItems)
 
 MUTATOR_HOOKFUNCTION (nt, SetWeaponreplace)
 
 MUTATOR_HOOKFUNCTION (nt, FilterItem)
 
string nt_GetFullReplacement (string w)
 
string nt_GetReplacement (string w, float m)
 
bool nt_IsNewToy (int w)
 
 REGISTER_MUTATOR (nt, expr_evaluate(cvar_string("g_new_toys")) &&!MUTATOR_IS_ENABLED(mutator_instagib) &&!MUTATOR_IS_ENABLED(ok))
 

Variables

float autocvar_g_new_toys_autoreplace
 
bool autocvar_g_new_toys_use_pickupsound = false
 
string new_toys
 
const float NT_AUTOREPLACE_ALWAYS = 1
 
const float NT_AUTOREPLACE_NEVER = 0
 
const float NT_AUTOREPLACE_RANDOM = 2
 

Function Documentation

◆ MUTATOR_HOOKFUNCTION() [1/3]

MUTATOR_HOOKFUNCTION ( nt  ,
SetStartItems   
)

Definition at line 157 of file sv_new_toys.qc.

References argv(), FOREACH, nt_GetReplacement(), start_weapons, start_weapons_defaultmask, tokenize_console, warmup_start_weapons, and warmup_start_weapons_defaultmask.

158 {
159  // rearrange start_weapon_default
160  // apply those bits that are set by start_weapon_defaultmask
161  // same for warmup
162 
163  float j, n;
164 
165  WepSet newdefault;
166  WepSet warmup_newdefault;
167 
168  newdefault = '0 0 0';
169  warmup_newdefault = '0 0 0';
170 
171  WepSet seti = '0 0 0';
172 
173  FOREACH(Weapons, it != WEP_Null, {
174  seti = it.m_wepset;
176 
177  for(j = 0; j < n; ++j)
178  FOREACH(Weapons, it != WEP_Null, {
179  if(it.netname == argv(j))
180  {
181  WepSet setk = it.m_wepset;
182  if(start_weapons & seti) newdefault |= setk;
183  if(warmup_start_weapons & seti) warmup_newdefault |= setk;
184  }
185  });
186  });
187 
188  newdefault &= start_weapons_defaultmask;
190  start_weapons |= newdefault;
191 
192  warmup_newdefault &= warmup_start_weapons_defaultmask;
194  warmup_start_weapons |= warmup_newdefault;
195 }
string nt_GetReplacement(string w, float m)
Definition: sv_new_toys.qc:145
vector WepSet
Definition: weapon.qh:11
WepSet warmup_start_weapons
Definition: world.qh:100
WepSet start_weapons
Definition: world.qh:81
WepSet warmup_start_weapons_defaultmask
Definition: world.qh:102
float autocvar_g_new_toys_autoreplace
Definition: sv_new_toys.qc:111
#define tokenize_console
Definition: dpextensions.qh:24
WepSet start_weapons_defaultmask
Definition: world.qh:83
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [2/3]

MUTATOR_HOOKFUNCTION ( nt  ,
SetWeaponreplace   
)

Definition at line 197 of file sv_new_toys.qc.

References entity(), M_ARGV, MUTATOR_IS_ENABLED, nt_GetReplacement(), and W_Apply_Weaponreplace().

198 {
199  if (MUTATOR_IS_ENABLED(random_items))
200  {
201  // Do not replace weapons when random items are enabled.
202  return;
203  }
204  entity wep = M_ARGV(0, entity);
205  entity wepinfo = M_ARGV(1, entity);
206  string ret_string = M_ARGV(2, string);
207 
208  // otherwise, we do replace
209  if(wep.new_toys)
210  {
211  // map defined replacement:
212  ret_string = wep.new_toys;
213  }
214  else
215  {
216  // auto replacement:
217  ret_string = nt_GetReplacement(wepinfo.netname, autocvar_g_new_toys_autoreplace);
218  }
219 
220  // apply regular weaponreplace
221  ret_string = W_Apply_Weaponreplace(ret_string);
222 
223  M_ARGV(2, string) = ret_string;
224 }
string nt_GetReplacement(string w, float m)
Definition: sv_new_toys.qc:145
string W_Apply_Weaponreplace(string in)
Definition: spawning.qc:13
entity() spawn
#define MUTATOR_IS_ENABLED(this)
Definition: base.qh:176
float autocvar_g_new_toys_autoreplace
Definition: sv_new_toys.qc:111
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [3/3]

MUTATOR_HOOKFUNCTION ( nt  ,
FilterItem   
)

Definition at line 226 of file sv_new_toys.qc.

References entity(), M_ARGV, nt_IsNewToy(), and string_null.

227 {
228  entity item = M_ARGV(0, entity);
229 
231  item.item_pickupsound = string_null;
232  item.item_pickupsound_ent = SND_WEAPONPICKUP_NEW_TOYS;
233  }
234 }
bool autocvar_g_new_toys_use_pickupsound
Definition: sv_new_toys.qc:112
string string_null
Definition: nil.qh:9
entity() spawn
bool nt_IsNewToy(int w)
Definition: sv_new_toys.qc:117
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ nt_GetFullReplacement()

string nt_GetFullReplacement ( string  w)

Definition at line 132 of file sv_new_toys.qc.

References string_null.

Referenced by nt_GetReplacement().

133 {
134  switch(w)
135  {
136  case "hagar": return "seeker";
137  case "devastator": return "minelayer";
138  case "machinegun": return "hlac";
139  case "vortex": return "rifle";
140  //case "shotgun": return "shockwave";
141  default: return string_null;
142  }
143 }
string string_null
Definition: nil.qh:9
+ Here is the caller graph for this function:

◆ nt_GetReplacement()

string nt_GetReplacement ( string  w,
float  m 
)

Definition at line 145 of file sv_new_toys.qc.

References nt_GetFullReplacement(), and strcat().

Referenced by MUTATOR_HOOKFUNCTION().

146 {
147  if(m == NT_AUTOREPLACE_NEVER)
148  return w;
149  string s = nt_GetFullReplacement(w);
150  if (!s)
151  return w;
152  if(m == NT_AUTOREPLACE_RANDOM)
153  s = strcat(w, " ", s);
154  return s;
155 }
const float NT_AUTOREPLACE_NEVER
Definition: sv_new_toys.qc:113
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
string nt_GetFullReplacement(string w)
Definition: sv_new_toys.qc:132
const float NT_AUTOREPLACE_RANDOM
Definition: sv_new_toys.qc:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nt_IsNewToy()

bool nt_IsNewToy ( int  w)

Definition at line 117 of file sv_new_toys.qc.

Referenced by MUTATOR_HOOKFUNCTION(), and REGISTER_MUTATOR().

118 {
119  switch(w)
120  {
121  case WEP_SEEKER.m_id:
122  case WEP_MINE_LAYER.m_id:
123  case WEP_HLAC.m_id:
124  case WEP_RIFLE.m_id:
125  case WEP_SHOCKWAVE.m_id:
126  return true;
127  default:
128  return false;
129  }
130 }
+ Here is the caller graph for this function:

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( nt  ,
expr_evaluate(cvar_string("g_new_toys")) &&!MUTATOR_IS_ENABLED(mutator_instagib) &&!MUTATOR_IS_ENABLED(ok)   
)

Definition at line 78 of file sv_new_toys.qc.

References error(), FOREACH, LOG_INFO, MUTATOR_ONADD, MUTATOR_ONREMOVE, MUTATOR_ONROLLBACK_OR_REMOVE, nt_IsNewToy(), time, and WEP_FLAG_MUTATORBLOCKED.

79 {
81  {
82  if(time > 1) // game loads at time 1
83  error("This cannot be added at runtime\n");
84 
85  // mark the guns as ok to use by e.g. impulse 99
86  FOREACH(Weapons, it != WEP_Null, {
87  if(nt_IsNewToy(it.m_id))
88  it.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
89  });
90  }
91 
93  {
94  FOREACH(Weapons, it != WEP_Null, {
95  if(nt_IsNewToy(it.m_id))
96  it.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
97  });
98  }
99 
101  {
102  LOG_INFO("This cannot be removed at runtime");
103  return -1;
104  }
105 
106  return 0;
107 }
#define MUTATOR_ONROLLBACK_OR_REMOVE
Definition: base.qh:286
bool nt_IsNewToy(int w)
Definition: sv_new_toys.qc:117
#define LOG_INFO(...)
Definition: log.qh:70
#define MUTATOR_ONREMOVE
Definition: base.qh:285
const int WEP_FLAG_MUTATORBLOCKED
Definition: weapon.qh:203
#define MUTATOR_ONADD
Definition: base.qh:284
float time
Definition: csprogsdefs.qc:16
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:

Variable Documentation

◆ autocvar_g_new_toys_autoreplace

float autocvar_g_new_toys_autoreplace

Definition at line 111 of file sv_new_toys.qc.

◆ autocvar_g_new_toys_use_pickupsound

bool autocvar_g_new_toys_use_pickupsound = false

Definition at line 112 of file sv_new_toys.qc.

◆ new_toys

string new_toys

Definition at line 109 of file sv_new_toys.qc.

◆ NT_AUTOREPLACE_ALWAYS

const float NT_AUTOREPLACE_ALWAYS = 1

Definition at line 114 of file sv_new_toys.qc.

◆ NT_AUTOREPLACE_NEVER

const float NT_AUTOREPLACE_NEVER = 0

Definition at line 113 of file sv_new_toys.qc.

◆ NT_AUTOREPLACE_RANDOM

const float NT_AUTOREPLACE_RANDOM = 2

Definition at line 115 of file sv_new_toys.qc.