]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_damage.qc
Merge branch 'master' into mario/monsters
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_damage.qc
index ac7c3cd2a7ceb637b4a69d5f2529a110a454a456..efa6c0ad5c36d56e324e44054bf3be7d33161f82 100644 (file)
@@ -47,14 +47,13 @@ float checkrules_firstblood;
 float yoda;
 float damage_goodhits;
 float damage_gooddamage;
-float headshot;
-float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
 
 .float dmg_team;
 .float teamkill_complain;
 .float teamkill_soundtime;
 .entity teamkill_soundsource;
 .entity pusher;
+.float istypefrag;
 .float taunt_soundtime;
 
 
@@ -85,15 +84,6 @@ float IsFlying(entity a)
        return 1;
 }
 
-vector GetHeadshotMins(entity targ)
-{
-       return '-0.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
-}
-vector GetHeadshotMaxs(entity targ)
-{
-       return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_y + '0 0 1' * targ.maxs_z;
-}
-
 void UpdateFrags(entity player, float f)
 {
        PlayerTeamScore_AddScore(player, f);
@@ -218,11 +208,6 @@ void GiveFrags (entity attacker, entity targ, float f, float deathtype)
                        }
                        f = 0;
                }
-               else if(g_ctf)
-               {
-                       if(g_ctf_ignore_frags)
-                               f = 0;
-               }
        }
 
        attacker.totalfrags += f;
@@ -314,13 +299,13 @@ void LogDeath(string mode, float deathtype, entity killer, entity killed)
 
 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
 {
-       WriteByte(MSG_ALL, SVC_TEMPENTITY);
-       WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
-       WriteString(MSG_ALL, s1);
-       WriteString(MSG_ALL, s2);
-       WriteString(MSG_ALL, s3);
-       WriteShort(MSG_ALL, msg);
-       WriteByte(MSG_ALL, type);
+       WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
+       WriteByte(MSG_BROADCAST, TE_CSQC_KILLNOTIFY);
+       WriteString(MSG_BROADCAST, s1);
+       WriteString(MSG_BROADCAST, s2);
+       WriteString(MSG_BROADCAST, s3);
+       WriteShort(MSG_BROADCAST, msg);
+       WriteByte(MSG_BROADCAST, type);
 }
 
 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
@@ -343,7 +328,7 @@ void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float
 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
 {
        string  s, a, msg;
-       float w, type;
+       float type;
 
        if (targ.classname == "player")
        {
@@ -377,7 +362,7 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                        deathtype = KILL_TEAM_BLUE;
                        }
 
-                       Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
+                       Send_KillNotification(s, msg, "", deathtype, MSG_SUICIDE);
                }
                else if (attacker.classname == "player")
                {
@@ -420,7 +405,7 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                        PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
                                }
 
-                               if(targ.BUTTON_CHAT) {
+                               if(targ.istypefrag) {
                                        Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
                                        Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
                                } else {
@@ -442,14 +427,7 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
 
                                Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
 
-                               if(g_ctf && targ.flagcarried)
-                               {
-                                       UpdateFrags(attacker, ctf_score_value("score_kill"));
-                                       PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
-                                       GiveFrags(attacker, targ, 0, deathtype); // for logging
-                               }
-                               else
-                                       GiveFrags(attacker, targ, 1, deathtype);
+                               GiveFrags(attacker, targ, 1, deathtype);
 
                                if (targ.killcount > 2) {
                                        Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
@@ -457,10 +435,7 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
 
                                attacker.killcount = attacker.killcount + 1;
 
-                               if (attacker.killcount > 2) {
-                                       Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
-                               }
-                               else if (attacker.killcount == 3)
+                               if (attacker.killcount == 3)
                                {
                                        Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
                                        AnnounceTo(attacker, "03kills");
@@ -502,6 +477,9 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
                                        AnnounceTo(attacker, "30kills");
                                        PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
                                }
+                               else if (attacker.killcount > 2) {
+                                       Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
+                               }
                                LogDeath("frag", deathtype, attacker, targ);
                        }
                }
@@ -540,6 +518,67 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
        }
 }
 
+void Ice_Think()
+{
+       if(self.owner.health < 1)
+       {
+               remove(self);
+               return;
+       }
+       setorigin(self, self.owner.origin - '0 0 16');
+       self.nextthink = time;
+}
+
+void Freeze (entity targ, float freeze_time)
+{
+       float monster = (targ.flags & FL_MONSTER);
+       float player = (targ.flags & FL_CLIENT);
+       
+       if(!player && !monster) // only specified entities can be freezed
+               return;
+               
+       if(targ.frozen || targ.freezetag_frozen)
+               return;
+               
+       targ.frozen = 1;
+       targ.revive_progress = 0;
+       targ.health = 1;
+       targ.revive_speed = freeze_time;
+
+       entity ice;
+       ice = spawn();
+       ice.owner = targ;
+       ice.classname = "ice";
+       ice.scale = targ.scale;
+       ice.think = Ice_Think;
+       ice.nextthink = time;
+       ice.frame = floor(random() * 21); // ice model has 20 different looking frames
+       setmodel(ice, "models/ice/ice.md3");
+
+       entity oldself;
+       oldself = self;
+       self = ice;
+       Ice_Think();
+       self = oldself;
+
+       RemoveGrapplingHook(targ);
+}
+
+void Unfreeze (entity targ)
+{
+       targ.frozen = 0;
+       targ.revive_progress = 0;
+       targ.health = ((targ.classname == STR_PLAYER) ? autocvar_g_balance_health_start : targ.max_health);
+
+       // remove the ice block
+       entity ice;
+       for(ice = world; (ice = find(ice, classname, "ice")); ) if(ice.owner == targ)
+       {
+               remove(ice);
+               break;
+       }
+}
+
 // these are updated by each Damage call for use in button triggering and such
 entity damage_targ;
 entity damage_inflictor;
@@ -549,7 +588,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
 {
        float mirrordamage;
        float mirrorforce;
-       float teamdamage0;
+       float complainteamdamage = 0; 
        entity attacker_save;
        mirrordamage = 0;
        mirrorforce = 0;
@@ -629,10 +668,10 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                        {
                                                if(targ.classname == "player" && targ.deadflag == DEAD_NO)
                                                {
-                                                       teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
                                                        attacker.dmg_team = attacker.dmg_team + damage;
-                                                       if(attacker.dmg_team > teamdamage0 && !g_ca)
-                                                               mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
+                                                       complainteamdamage = attacker.dmg_team - autocvar_g_teamdamage_threshold;
+                                                       if(complainteamdamage > 0 && !g_ca) // FIXME why is g_ca ruled out here? Why not just g_mirrordamage 0 on CA servers?
+                                                               mirrordamage = autocvar_g_mirrordamage * complainteamdamage;
                                                        mirrorforce = autocvar_g_mirrordamage * vlen(force);
                                                        if(g_minstagib)
                                                        {
@@ -647,11 +686,11 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
 
                                                        if(autocvar_g_mirrordamage_virtual)
                                                        {
-                                                               vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
+                                                               vector v  = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
                                                                attacker.dmg_take += v_x;
                                                                attacker.dmg_save += v_y;
                                                                attacker.dmg_inflictor = inflictor;
-                                                               mirrordamage = 0;
+                                                               mirrordamage = v_z; // = 0, to make fteqcc stfu
                                                                mirrorforce = 0;
                                                        }
 
@@ -707,6 +746,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                        {
                                damage = 0;
                                mirrordamage = 0;
+                               complainteamdamage = 0;
                                if (targ != attacker)
                                {
                                        if ((targ.health >= 1) && (targ.classname == "player"))
@@ -722,10 +762,17 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                {
                        damage *= g_weapondamagefactor;
                        mirrordamage *= g_weapondamagefactor;
+                       complainteamdamage *= g_weapondamagefactor;
                        force = force * g_weaponforcefactor;
                        mirrorforce *= g_weaponforcefactor;
                }
                
+               if(targ.frozen && attacker.classname != "monster_spider")
+               {
+                       damage = 0;
+                       force *= 0.2;
+               }
+               
                // should this be changed at all? If so, in what way?
                frag_attacker = attacker;
                frag_target = targ;
@@ -763,15 +810,6 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
                }
 
-               // CTF: reduce damage/force
-               if(g_ctf)
-               if(targ == attacker)
-               if(targ.flagcarried)
-               {
-                       damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
-                       force = force * autocvar_g_ctf_flagcarrier_selfforce;
-               }
-
                if(g_runematch)
                {
                        // apply strength rune
@@ -812,38 +850,13 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                if(targ.takedamage == DAMAGE_AIM)
                if(targ != attacker)
                {
-                       if(damage_headshotbonus)
-                       {
-                               if(targ.classname == "player")
-                               {
-                                       // HEAD SHOT:
-                                       // find height of hit on player axis
-                                       // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
-                                       vector headmins, headmaxs, org;
-                                       org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
-                                       headmins = org + GetHeadshotMins(targ);
-                                       headmaxs = org + GetHeadshotMaxs(targ);
-                                       if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
-                                       {
-                                               deathtype |= HITTYPE_HEADSHOT;
-                                       }
-                               }
-                               else if(targ.classname == "turret_head")
-                               {
-                                       deathtype |= HITTYPE_HEADSHOT;
-                               }
-                               if(deathtype & HITTYPE_HEADSHOT)
-                                       if(damage_headshotbonus > 0)
-                                               damage *= 1 + damage_headshotbonus;
-                       }
-
                        entity victim;
                        if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
                                victim = targ.owner;
                        else
                                victim = targ;
 
-                       if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
+                       if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET || victim.flags & FL_MONSTER)
                        {
                                if(IsDifferentTeam(victim, attacker))
                                {
@@ -870,12 +883,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                                        if(g_minstagib)
                                                        if(victim.items & IT_STRENGTH)
                                                                yoda = 1;
-
-                                                       if(deathtype & HITTYPE_HEADSHOT)
-                                                               headshot = 1;
                                                }
-                                               if(g_ca)
-                                                       PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
                                        }
                                }
                                else
@@ -884,7 +892,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                        {
                                                attacker.typehitsound += 1;
                                        }
-                                       if(mirrordamage > 0)
+                                       if(complainteamdamage > 0)
                                                if(time > attacker.teamkill_complain)
                                                {
                                                        attacker.teamkill_complain = time + 5;
@@ -1068,10 +1076,7 @@ float RadiusDamage (entity inflictor, entity attacker, float coredamage, float e
                                                myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
 
                                                // if it's a player, use the view origin as reference
-                                               if (targ.classname == "player")
-                                                       center = targ.origin + targ.view_ofs;
-                                               else
-                                                       center = targ.origin + (targ.mins + targ.maxs) * 0.5;
+                                               center = CENTER_OR_VIEWOFS(targ);
 
                                                force = normalize(center - myblastorigin);
                                                force = force * (finaldmg / coredamage) * forceintensity;
@@ -1372,7 +1377,7 @@ void Fire_ApplyDamage(entity e)
                e.fire_endtime = 0;
 
        // ice stops fire
-       if(e.freezetag_frozen)
+       if(e.freezetag_frozen || e.frozen)
                e.fire_endtime = 0;
 
        t = min(frametime, e.fire_endtime - time);