Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_tmayhem.qc
Go to the documentation of this file.
1#include "sv_tmayhem.qh"
3
6
10
19
27
29
30// code from here on is just to support maps that don't have team entities
31void tmayhem_SpawnTeam (string teamname, int teamcolor)
32{
33 entity this = new_pure(tmayhem_team);
34 this.netname = teamname;
35 this.cnt = teamcolor - 1;
36 this.team = teamcolor;
37 this.spawnfunc_checked = true;
38 //spawnfunc_tmayhem_team(this);
39}
40
42{
43 // if no teams are found, spawn defaults
44 if (find(NULL, classname, "tmayhem_team") == NULL)
45 {
46 LOG_TRACE("No \"tmayhem_team\" entities found on this map, creating them anyway.");
47
49 if(numteams < 2) { numteams = autocvar_g_tmayhem_teams; }
50
51 int teams = BITS(bound(2, numteams, 4));
52 if(teams & BIT(0))
54 if(teams & BIT(1))
56 if(teams & BIT(2))
58 if(teams & BIT(3))
60 }
61}
62
73// code up to here is just to support maps that don't have team entities
74
79
80/*
81MUTATOR_HOOKFUNCTION(tmayhem, Scores_CountFragsRemaining)
82{
83 // do not announce remaining frags, upscaled score count doesn't match well with this
84 // when scorelimit is set to 1000 it would announce 997, 998 and 999 score counts
85 // usually a single shot which deals ~40-80 dmg gives 2 or 3 score
86 // this usually would cause a "2 fra..." announcement to be played as the match ends
87 // without leaving anyone time to even process the announcement
88 return false;
89}
90*/
91
106
108{
110 M_ARGV(2, float) = 0;
112 M_ARGV(3, float) = 0;
114}
115
116MUTATOR_HOOKFUNCTION(tmayhem, ForbidThrowCurrentWeapon)
117{
118 return true;
119}
120
122{
123 if (M_ARGV(0, string) == "0" || M_ARGV(0, string) == "")
125}
126
128{
129 entity item = M_ARGV(0, entity);
130
131 // enable powerups if forced globally or global accepts gametypes to have powerups according to their own settings
133 if (item.itemdef.instanceOfPowerup){
134 return false;
135 }
136 }
137 // disabled powerups if forced off globally or in this gametype
139 if (item.itemdef.instanceOfPowerup){
140 return true;
141 }
142 }
143 // remove all items if items are forced off globally
144 if (autocvar_g_pickup_items == 0){
145 return true;
146 }
147 // if items are switched on in this gametype allow the removal of weapons and ammo still
149 if (item.itemdef.instanceOfAmmo || item.itemdef.instanceOfWeaponPickup){
150 return true;
151 }
152 }
153 // remove items if not globally set to follow mode's settings and locally set off
155 return true;
156 }
157 return false;
158}
159
161{
162 entity frag_attacker = M_ARGV(1, entity);
164 float frag_deathtype = M_ARGV(3, float);
165 float frag_damage = M_ARGV(4, float);
166 float frag_mirrordamage = M_ARGV(5, float);
167
168 if (IS_PLAYER(frag_target)) // nullify self-damage if self-damage is disabled and always nullify splat
169 if (!IS_DEAD(frag_target)) // but enable anyone to gib corpses, even their own corpses with delayed damage
170 if ((autocvar_g_tmayhem_selfdamage == 0 && frag_target == frag_attacker) || frag_deathtype == DEATH_FALL.m_id)
171 frag_damage = 0;
172
173 frag_mirrordamage = 0; // no mirror damaging
174
175 M_ARGV(4, float) = frag_damage;
176 M_ARGV(5, float) = frag_mirrordamage;
177}
178
179MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor)
180{
182
184
185 if (StatusEffects_active(STATUSEFFECT_SpawnShield, frag_target) && autocvar_g_spawnshield_blockdamage >= 1) return;
186
187 entity frag_attacker = M_ARGV(1, entity);
188 float frag_deathtype = M_ARGV(6, float);
189 float frag_damage = M_ARGV(7, float);
190 float damage_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH));
191 float damage_save = bound(0, M_ARGV(5, float), GetResource(frag_target, RES_ARMOR));
192 float excess = max(0, frag_damage - damage_take - damage_save);
193 float total = frag_damage - excess;
194
195 if (total == 0) return;
196
199
200 entity scorer = NULL; // entity which needs their score to be updated
201
202 if (IS_PLAYER(frag_attacker))
203 {
204 // non-friendly fire
205 if (!SAME_TEAM(frag_target, frag_attacker))
206 frag_attacker.total_damage_dealt += total;
207
208 // friendly fire aka self damage
209 if (SAME_TEAM(frag_target, frag_attacker) || (frag_target == frag_attacker && !autocvar_g_tmayhem_scoring_disable_selfdamage2score))
210 frag_attacker.total_damage_dealt -= total;
211
212 scorer = frag_attacker;
213 }
214 else
215 {
216 // handle (environmental hazard) suiciding, check first if the player
217 // has a registered attacker who most likely pushed them there to
218 // avoid punishing pushed players as pushers are already rewarded
219 // deathtypes:
220 // kill = suicide, drown = drown in water/liquid, hurttrigger = out of the map void or hurt triggers inside maps like electric sparks
221 // camp = campcheck, lava = lava, slime = slime
222 // team change / rebalance suicides are currently not included
224 frag_deathtype == DEATH_KILL.m_id ||
225 frag_deathtype == DEATH_DROWN.m_id ||
226 frag_deathtype == DEATH_HURTTRIGGER.m_id ||
227 frag_deathtype == DEATH_CAMP.m_id ||
228 frag_deathtype == DEATH_LAVA.m_id ||
229 frag_deathtype == DEATH_SLIME.m_id ||
230 frag_deathtype == DEATH_SWAMP.m_id))
231 frag_target.total_damage_dealt -= total;
232
233 scorer = frag_target;
234 }
235
237}
238
240{
241 entity frag_attacker = M_ARGV(0, entity);
242 M_ARGV(2, float) = 0; // score to give for the frag directly
243
244 if (IS_PLAYER(frag_attacker)) MayhemCalculatePlayerScore(frag_attacker);
245
246 return true;
247}
248
249MUTATOR_HOOKFUNCTION(tmayhem, reset_map_players)
250{
251 // reset damage dealt on reset
252 FOREACH_CLIENT(true, {
253 it.total_damage_dealt = 0;
254 });
255 return false;
256}
257
const int CBC_ORDER_FIRST
Definition base.qh:10
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
const int CBC_ORDER_EXCLUSIVE
Definition base.qh:12
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
#define BITS(n)
Definition bits.qh:9
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
string netname
Definition powerups.qc:20
float cnt
Definition powerups.qc:24
int team
Definition main.qh:188
entity teams
Definition main.qh:58
const int IT_UNLIMITED_AMMO
Definition item.qh:23
const int IT_UNLIMITED_SUPERWEAPONS
Definition item.qh:24
#define M_ARGV(x, type)
Definition events.qh:17
#define IS_DEAD(s)
Definition player.qh:245
#define IS_PLAYER(s)
Definition player.qh:243
const int INITPRIO_GAMETYPE
Definition constants.qh:94
string classname
RES_ARMOR
Definition ent_cs.qc:130
#define LOG_TRACE(...)
Definition log.qh:76
float bound(float min, float value, float max)
float cvar(string name)
entity find(entity start,.string field, string match)
float max(float f,...)
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67
#define NULL
Definition post.qh:14
int autocvar_g_pickup_items
Definition items.qh:10
float autocvar_g_spawnshield_blockdamage
Definition player.qh:4
bool spawnfunc_checked
Definition spawnfunc.qh:8
bool StatusEffects_active(StatusEffect this, entity actor)
float frag_damage
Definition sv_ctf.qc:2322
entity frag_target
Definition sv_ctf.qc:2321
void MayhemCalculatePlayerScore(entity scorer)
Definition sv_mayhem.qc:145
float total_damage_dealt
Definition sv_mayhem.qc:31
int autocvar_g_powerups
Definition sv_powerups.qh:7
void GameRules_limit_score(int limit)
Definition sv_rules.qc:23
void GameRules_teams(bool value)
Definition sv_rules.qc:3
void GameRules_limit_lead(int limit)
Definition sv_rules.qc:33
#define GameRules_spawning_teams(value)
Used to disable team spawns in team modes.
Definition sv_rules.qh:35
int autocvar_g_tmayhem_teams_override
Definition sv_tmayhem.qc:8
float autocvar_g_tmayhem_start_ammo_nails
Definition sv_tmayhem.qc:23
float autocvar_g_tmayhem_start_health
Definition sv_tmayhem.qc:20
bool autocvar_g_tmayhem_unlimited_ammo
Definition sv_tmayhem.qc:18
int autocvar_g_tmayhem_teams
Definition sv_tmayhem.qc:7
bool autocvar_g_tmayhem_rot
Definition sv_tmayhem.qc:12
bool autocvar_g_tmayhem_pickup_items
Definition sv_tmayhem.qc:16
bool autocvar_g_tmayhem_pickup_items_remove_weapons_and_ammo
Definition sv_tmayhem.qc:17
bool autocvar_g_tmayhem_powerups
Definition sv_tmayhem.qc:14
float autocvar_g_tmayhem_start_ammo_shells
Definition sv_tmayhem.qc:22
void tmayhem_SpawnTeam(string teamname, int teamcolor)
Definition sv_tmayhem.qc:31
float autocvar_g_tmayhem_start_armor
Definition sv_tmayhem.qc:21
float autocvar_g_tmayhem_point_leadlimit
Definition sv_tmayhem.qc:5
bool autocvar_g_tmayhem_selfdamage
Definition sv_tmayhem.qc:15
float autocvar_g_tmayhem_start_ammo_fuel
Definition sv_tmayhem.qc:26
float autocvar_g_tmayhem_start_ammo_rockets
Definition sv_tmayhem.qc:24
void tmayhem_Initialize()
Definition sv_tmayhem.qc:63
void tmayhem_DelayedInit(entity this)
Definition sv_tmayhem.qc:41
bool autocvar_g_tmayhem_team_spawns
Definition sv_tmayhem.qc:9
float autocvar_g_tmayhem_start_ammo_cells
Definition sv_tmayhem.qc:25
string autocvar_g_tmayhem_weaponarena
Definition sv_tmayhem.qc:13
bool autocvar_g_tmayhem_regenerate
Definition sv_tmayhem.qc:11
float autocvar_g_tmayhem_point_limit
Definition sv_tmayhem.qc:4
float autocvar_g_tmayhem_scoring_damage_weight
Definition sv_tmayhem.qh:8
bool autocvar_g_tmayhem_scoring_disable_selfdamage2score
Definition sv_tmayhem.qh:9
entity TeamBalance_CheckAllowedTeams(entity for_whom)
Checks whether the player can join teams according to global configuration and mutator settings.
Definition teamplay.qc:459
#define SAME_TEAM(a, b)
Definition teams.qh:241
const int NUM_TEAM_2
Definition teams.qh:14
const int NUM_TEAM_4
Definition teams.qh:16
const int NUM_TEAM_3
Definition teams.qh:15
const int NUM_TEAM_1
Definition teams.qh:13
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:50
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2209
float warmup_start_ammo_cells
Definition world.qh:105
float start_ammo_shells
Definition world.qh:84
float warmup_start_ammo_rockets
Definition world.qh:104
float warmup_start_ammo_shells
Definition world.qh:102
float start_ammo_fuel
Definition world.qh:88
int start_items
Definition world.qh:83
float warmup_start_ammo_nails
Definition world.qh:103
float start_ammo_cells
Definition world.qh:87
float warmup_start_health
Definition world.qh:107
float start_ammo_rockets
Definition world.qh:86
float start_armorvalue
Definition world.qh:97
float warmup_start_ammo_fuel
Definition world.qh:106
float start_health
Definition world.qh:96
float warmup_start_armorvalue
Definition world.qh:108
float start_ammo_nails
Definition world.qh:85