Skip to content

Commit

Permalink
SERVER: Improve accuracy and readability of damage and score componen…
Browse files Browse the repository at this point in the history
…ts (#77)
  • Loading branch information
MotoLegacy authored Jun 16, 2024
1 parent 4fcfa40 commit 4d27e89
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 58 deletions.
10 changes: 5 additions & 5 deletions source/server/ai/zombie_core.qc
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ void() Zombie_Think = //called every frame for zombies
Effect_Fire(self.origin);

if (self.ltime < time && self.onfire){
DamageHandler(self, self.firer, 300, S_FLAME);
DamageHandler(self, self.firer, 300, DMG_TYPE_FLAMETHROWER);
self.ltime = time + 2;

if (self.fire_timeout < time)
Expand All @@ -418,7 +418,7 @@ void() Zombie_Think = //called every frame for zombies
if (self.bleedingtime < time && !self.head.deadflag)
{
self.bleedingtime = time + 1;
DamageHandler (self, self.usedent, z_health * 0.2, S_HEADSHOT);
DamageHandler (self, self.usedent, z_health * 0.2, DMG_TYPE_HEADSHOT);
}

// If we're mid attack and our enemy has moved out of range
Expand Down Expand Up @@ -634,9 +634,9 @@ void() zombie_attack2 =
if(vlen(self.enemy.origin - self.origin) < 64)
{
if (self.classname == "ai_dog")
DamageHandler (self.enemy, self, 40, S_ZOMBIE);
DamageHandler (self.enemy, self, 40, DMG_TYPE_ZOMBIESWIPE);
else
DamageHandler (self.enemy, self, 50, S_ZOMBIE);
DamageHandler (self.enemy, self, 50, DMG_TYPE_ZOMBIESWIPE);
}
}
else return;
Expand Down Expand Up @@ -747,7 +747,7 @@ void() zombie_attack_through_window =
{
if(who.classname == "player")
{
DamageHandler (who, self, ZOMBIE_DAMAGE_THROUGH_WINDOW, S_ZOMBIE);
DamageHandler (who, self, ZOMBIE_DAMAGE_THROUGH_WINDOW, DMG_TYPE_ZOMBIESWIPE);
}
who = who.chain;
}
Expand Down
69 changes: 46 additions & 23 deletions source/server/damage.qc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
*/
void (float achievement_id, optional entity who) GiveAchievement;

#define DMG_SCORE_HEADSHOT 100 // Death by Headshot
#define DMG_SCORE_MELEE 130 // Death by Melee
#define DMG_SCORE_UPPERTORSO 60 // Death by gunshot, upper torso.
#define DMG_SCORE_LOWERTORSO 50 // Death by gunshot, lower torso.
#define DMG_SCORE_GRENADE 50 // Death by Grenade.
#define DMG_SCORE_EXPLOSIVE 60 // Death by Explosive Weapon.
#define DMG_SCORE_TESLA 50 // Death by Tesla.
#define DMG_SCORE_STDDAMAGE 10 // Standard Damage reward.

void() Barrel_Hit;
void() teddy_react;

Expand Down Expand Up @@ -430,46 +439,58 @@ void(entity attacker, float d_style) DieHandler =

float points_earned = 0;
switch(d_style) {
case S_HEADSHOT:
points_earned = 100;
case DMG_TYPE_HEADSHOT:
points_earned = DMG_SCORE_HEADSHOT;
attacker.headshots++;
break;
case S_KNIFE:
points_earned = 130;
case DMG_TYPE_MELEE:
points_earned = DMG_SCORE_MELEE;
break;
case S_TESLA:
points_earned = 50;
case DMG_TYPE_TESLA:
points_earned = DMG_SCORE_GRENADE;
break;
case S_FLAME:
points_earned = 50;
case DMG_TYPE_FLAMETHROWER:
points_earned = DMG_SCORE_GRENADE;

// override their death sound (FIXME: make a new sound..)
sound(self, CHAN_BODY, "sounds/pu/drop.wav", 1, ATTN_NORM);
break;
case DMG_TYPE_GRENADE:
points_earned = DMG_SCORE_GRENADE;
break;
case DMG_TYPE_EXPLOSIVE:
points_earned = DMG_SCORE_EXPLOSIVE;
break;
case DMG_TYPE_LOWERTORSO:
points_earned = DMG_SCORE_LOWERTORSO;
break;
case DMG_TYPE_UPPERTORSO:
points_earned = DMG_SCORE_UPPERTORSO;
break;
default:
points_earned = 60;
if (cvar("developer"))
bprint(PRINT_HIGH, "DieHandler: Received invalid style\n");
break;
}

Player_AddScore(attacker, points_earned, true);
}
}

void(entity victim, entity attacker, float damage, float d_style) DamageHandler = {
// don't do any attacking during nuke delay
if (d_style == S_ZOMBIE && nuke_powerup_active > time)
if (d_style == DMG_TYPE_ZOMBIESWIPE && nuke_powerup_active > time)
return;

entity old_self;
if (victim.classname == "ai_zombie" || victim.classname == "ai_dog") {

if (attacker.classname == "player" && (victim.health - damage) > 0) {
Player_AddScore(attacker, 10, true);
if (attacker.classname == "player" && (victim.health - damage) > 0 && d_style != DMG_TYPE_OTHER) {
Player_AddScore(attacker, DMG_SCORE_STDDAMAGE, true);
}

victim.health = victim.health - damage;

if (d_style == S_EXPLOSIVE && damage != 0) {
if (d_style == DMG_TYPE_EXPLOSIVE && damage != 0) {
if (victim.health > 0 && victim.crawling == 2) {
makeCrawler(victim);
GiveAchievement(3, attacker);
Expand Down Expand Up @@ -523,7 +544,7 @@ void(entity victim, entity attacker, float damage, float d_style) DamageHandler
victim.punchangle_y = distance_y;

// Play pain noise if this isn't done by an electric barrier.
if (d_style != S_ZAPPER)
if (d_style != DMG_TYPE_ELECTRICTRAP)
sound (victim, CHAN_AUTO, "sounds/player/pain4.wav", 1, ATTN_NORM);
else
sound (victim, CHAN_AUTO, "sounds/machines/elec_shock.wav", 1, ATTN_NORM);
Expand Down Expand Up @@ -608,6 +629,7 @@ float(float min, float max, vector org1, vector org2, float radius) calculate_pr
void(entity inflictor, entity attacker, float damage2, float mindamage, float radius) DamgageExplode =
{
float final_damage = 0;
float damage_style = 0;
entity ent;

float multi, r;
Expand Down Expand Up @@ -638,11 +660,11 @@ void(entity inflictor, entity attacker, float damage2, float mindamage, float ra

if (final_damage < other.health)
{
Player_AddScore(self, 10, false);
Player_AddScore(self, DMG_SCORE_STDDAMAGE, false);
}
else if (final_damage > other.health)
{
Player_AddScore(self, 10, false);
Player_AddScore(self, DMG_SCORE_STDDAMAGE, false);
}
else
{
Expand Down Expand Up @@ -698,11 +720,7 @@ void(entity inflictor, entity attacker, float damage2, float mindamage, float ra
self = oldself2;
}
else if (ent.takedamage && ent.classname != "ai_zombie_head" && ent.classname != "ai_zombie_larm" && ent.classname != "ai_zombie_rarm")
{
// verify we aren't doin anything with a bmodel
if (ent.solid == SOLID_BSP || ent.movetype == MOVETYPE_PUSH)
return;

{
if (mapname == "ndu" && ent.classname == "ai_zombie" && inflictor.classname == "explosive_barrel") {
ach_tracker_barr++;

Expand All @@ -719,23 +737,28 @@ void(entity inflictor, entity attacker, float damage2, float mindamage, float ra
// grenades follow the logic of (rounds + (rand 150-500))
// rounds is basically meaningless though.. wtf?
final_damage = rounds + rint(random() * 350) + 150;
damage_style = DMG_TYPE_GRENADE;
} else if (inflictor.classname == "projectile_grenade") {
// projectile-based grenades (mustang & sally) seem to do
// more damage than standard grenades.
// (rounds + (rand 1200-5000))
final_damage = rounds + rint(random() * 3800) + 1200;
damage_style = DMG_TYPE_EXPLOSIVE;
} else if (inflictor.classname == "rocket") {
// rockets were kinda tricky to figure out, this is as close
// as i can get and i'm not super confident..
// (rounds * (rand 0-100) * weapon_damage/500).
final_damage = (rounds * rint(random() * 100)) * damage2/500;
damage_style = DMG_TYPE_EXPLOSIVE;
} else if (inflictor.classname == "projectile_raybeam") {
//final_damage = calculate_proximity_value(mindamage, damage2, inflictor.origin, ent.origin, radius);
//bprint(PRINT_HIGH, strcat("damage: ", ftos(final_damage), "\n"));
final_damage = damage2;
damage_style = DMG_TYPE_GRENADE;
} else if (inflictor.classname == "player") {
// phd flopper.
final_damage = calculate_proximity_value(mindamage, damage2, inflictor.origin, ent.origin, radius);
damage_style = DMG_TYPE_GRENADE;
} else {
r = rounds;
multi = 1.07;
Expand Down Expand Up @@ -763,7 +786,7 @@ void(entity inflictor, entity attacker, float damage2, float mindamage, float ra

if (final_damage > 0) {
if (CanDamage (ent, inflictor))
DamageHandler (ent, attacker, final_damage, S_EXPLOSIVE);
DamageHandler (ent, attacker, final_damage, damage_style);
}
ent = ent.chain;
}
Expand Down
6 changes: 6 additions & 0 deletions source/server/defs/custom.qc
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,13 @@ float sounds_playing;
//.float OrgStuckCount;
.float crawling;

#define HIT_REGION_HEAD 1
#define HIT_REGION_ARM 2
#define HIT_REGION_TORSO_LOWER 3
#define HIT_REGION_TORSO_UPPER 4

.float washit;
.float hit_region;
.float hitamount;

.float laststep;
Expand Down
2 changes: 1 addition & 1 deletion source/server/entities/doors.qc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void() door_go_up;

void() door_blocked =
{
DamageHandler (other, self, self.dmg, S_NORMAL);
DamageHandler (other, self, self.dmg, DMG_TYPE_OTHER);

// if a door has a negative wait, it would never come back if blocked,
// so let it just squash the object to death real fast
Expand Down
4 changes: 2 additions & 2 deletions source/server/entities/func.qc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void () func_rotating_use =

void() rot_crush =
{
DamageHandler(self, other, 1, S_ZOMBIE);
DamageHandler(self, other, 1, DMG_TYPE_OTHER);
}

void () func_rotating =
Expand Down Expand Up @@ -159,7 +159,7 @@ void() train_blocked =

self.death_timer = time + 0.5;

DamageHandler(self, other, self.dmg, S_ZOMBIE);
DamageHandler(self, other, self.dmg, DMG_TYPE_OTHER);
};

void() train_use =
Expand Down
4 changes: 2 additions & 2 deletions source/server/entities/traps.qc
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ void() zapper_do_damage
// Inflict Damage
if (other.damage_timer < time) {
if (other.perks & P_JUG)
DamageHandler(other, self, 50, S_ZAPPER);
DamageHandler(other, self, 50, DMG_TYPE_ELECTRICTRAP);
else
DamageHandler(other, self, other.health, S_ZAPPER);
DamageHandler(other, self, other.health, DMG_TYPE_ELECTRICTRAP);
other.damage_timer = time + 1.25;
}
// Inflict Speed Penalty
Expand Down
2 changes: 1 addition & 1 deletion source/server/entities/triggers.qc
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void() hurt_touch =
(other.aistatus == "1" && !(self.spawnflags & HURT_SPAWNFLAG_NOAI)))
{
self.solid = SOLID_NOT;
DamageHandler(other, self, self.dmg, S_NORMAL);
DamageHandler(other, self, self.dmg, DMG_TYPE_OTHER);
self.think = hurt_on;
self.nextthink = time + 1;

Expand Down
2 changes: 1 addition & 1 deletion source/server/weapons/flamethrower.qc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void() Flame_Touch =
Effect_Fire(target.origin);

// Only do 1 damage to trigger insta-kill damage.
DamageHandler(target, target.firer, 1, S_FLAME);
DamageHandler(target, target.firer, 1, DMG_TYPE_FLAMETHROWER);
}

// Set the monster alight
Expand Down
7 changes: 2 additions & 5 deletions source/server/weapons/tesla.qc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void(entity hit_ent, entity arc_parent, entity arc_owner, float arc_num, float d
// 50 points for waffe kills
if(arc_owner.classname == "player") {
arc_owner.kills += 1;
Player_AddScore(arc_owner, 50, true);
Player_AddScore(arc_owner, DMG_SCORE_TESLA, true);
}
}

Expand Down Expand Up @@ -332,10 +332,7 @@ void() W_FireTesla =
float damage = lerp(0, 75, lerp_frac);
// print("Giving player ",ftos(damage), " damage.\n");

if (other.perks & P_JUG)
DamageHandler(ent, self, damage, S_ZAPPER);
else
DamageHandler(ent, self, damage, S_ZAPPER);
DamageHandler(ent, self, damage, DMG_TYPE_ELECTRICTRAP);
// ----------------------------------------
}

Expand Down
31 changes: 21 additions & 10 deletions source/server/weapons/weapon_core.qc
Original file line number Diff line number Diff line change
Expand Up @@ -752,13 +752,18 @@ void Parse_Damage () = // DO NOT TOUCH
}

if (head_hit)
DamageHandler(body_ent,self, total_dmg, S_HEADSHOT);
else
DamageHandler(body_ent,self, total_dmg, S_NORMAL);
DamageHandler(body_ent,self, total_dmg, DMG_TYPE_HEADSHOT);
else {
if (body_ent.hit_region == HIT_REGION_TORSO_LOWER)
DamageHandler(body_ent,self, total_dmg, DMG_TYPE_LOWERTORSO);
else
DamageHandler(body_ent,self, total_dmg, DMG_TYPE_UPPERTORSO);
}

if (body_ent != world) {
body_ent.washit = 0;
body_ent.hitamount = 0;
body_ent.hit_region = 0;
}
}
ent = findfloat (ent, washit, 1);
Expand Down Expand Up @@ -813,16 +818,22 @@ void(float damage, vector dir, vector org, vector plane, entity hit_ent, float s
switch(hit_ent.classname) {
case "ai_zombie_head":
f_damage = damage*getWeaponMultiplier(self.weapon, HEAD_X);
hit_ent.hit_region = HIT_REGION_HEAD;
break;
case "ai_zombie_larm":
case "ai_zombie_rarm":
f_damage = damage*getWeaponMultiplier(self.weapon, LIMBS_X);
hit_ent.hit_region = HIT_REGION_ARM;
break;
case "ai_zombie":
if (trace_endpos_z < hit_ent.origin_z)
if (trace_endpos_z < hit_ent.origin_z) {
f_damage = damage*getWeaponMultiplier(self.weapon, LOWER_TORSO_X);
else
hit_ent.hit_region = HIT_REGION_TORSO_LOWER;
}
else {
f_damage = damage*getWeaponMultiplier(self.weapon, UPPER_TORSO_X);
hit_ent.hit_region = HIT_REGION_TORSO_UPPER;
}
break;
default:
f_damage = damage;
Expand Down Expand Up @@ -1248,7 +1259,7 @@ void() WeaponCore_Melee =
// Apply damage to the entity.
if (trace_ent.takedamage) {
float melee_damage = WepDef_CalculateMeleeDamage(self.weapon, self.bowie);
DamageHandler (trace_ent, self, melee_damage, S_KNIFE);
DamageHandler (trace_ent, self, melee_damage, DMG_TYPE_MELEE);
}
}
}
Expand Down Expand Up @@ -1344,7 +1355,7 @@ void() Velocity_reduce =
{
// Do one (1) damage on monster contact, to kill when Insta-Kill is active.
if (other.flags & FL_MONSTER)
DamageHandler(other, self.owner, 1, S_NORMAL);
DamageHandler(other, self.owner, 1, DMG_TYPE_OTHER);

if (!other.solid || other.solid == SOLID_TRIGGER)
if (other != world)
Expand Down Expand Up @@ -1716,8 +1727,8 @@ void() CheckPlayer =
traceline(self.origin, self.origin + (v_up * -40), 0, self);

if (trace_ent.classname == "player") {
DamageHandler(self, trace_ent, 100000, S_NORMAL);
DamageHandler(trace_ent, self, 100000, S_NORMAL);
DamageHandler(self, trace_ent, 100000, DMG_TYPE_OTHER);
DamageHandler(trace_ent, self, 100000, DMG_TYPE_OTHER);
}
}

Expand Down Expand Up @@ -1749,7 +1760,7 @@ void() CheckPlayer =

if (damage > 98) damage = 98;

DamageHandler (self, other, damage, S_ZOMBIE);
DamageHandler (self, other, damage, DMG_TYPE_OTHER);

if (self.health <= 5)
GiveAchievement(7, self);
Expand Down
Loading

0 comments on commit 4d27e89

Please sign in to comment.