]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/breakable.qc
Bot AI: reduce powerup rating value
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / breakable.qc
index 6763701d31fa91d52468af4e71f657d0986313e7..d09ccd5e00a8cede8584138723c607d37637ea9c 100644 (file)
@@ -1,8 +1,9 @@
+#include "breakable.qh"
 #ifdef SVQC
 
 #include <server/g_subs.qh>
 #include <server/g_damage.qh>
-#include <server/bot/bot.qh>
+#include <server/bot/api.qh>
 #include <common/csqcmodel_settings.qh>
 #include <lib/csqcmodel/sv_model.qh>
 #include <server/weapons/common.qh>
 //   target = targets to trigger when broken
 //   health = amount of damage it can take
 //   spawnflags:
-//     1 = start disabled (needs to be triggered to activate)
-//     2 = indicate damage
-//     4 = don't take direct damage (needs to be triggered to 'explode', then triggered again to restore)
+//     START_DISABLED: needs to be triggered to activate
+//     BREAKABLE_INDICATE_DAMAGE: indicate damage
+//     BREAKABLE_NODAMAGE: don't take direct damage (needs to be triggered to 'explode', then triggered again to restore)
+//     NOSPLASH: don't take splash damage
 // notes:
 //   for mdl_dead to work, origin must be set (using a common/origin brush).
 //   Otherwise mdl_dead will be displayed at the map origin, and nobody would
 //   want that!
 
-void func_breakable_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force);
+void func_breakable_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force);
 
 //
 // func_breakable
@@ -66,7 +68,8 @@ void LaunchDebris (entity this, string debrisname, vector force)
        dbr.velocity_x = this.debrisvelocity.x + this.debrisvelocityjitter.x * crandom();
        dbr.velocity_y = this.debrisvelocity.y + this.debrisvelocityjitter.y * crandom();
        dbr.velocity_z = this.debrisvelocity.z + this.debrisvelocityjitter.z * crandom();
-       this.velocity = this.velocity + force * this.debrisdamageforcescale;
+       dbr.velocity = dbr.velocity + force * this.debrisdamageforcescale;
+       dbr.angles = this.angles;
        dbr.avelocity_x = random()*this.debrisavelocityjitter.x;
        dbr.avelocity_y = random()*this.debrisavelocityjitter.y;
        dbr.avelocity_z = random()*this.debrisavelocityjitter.z;
@@ -79,7 +82,7 @@ void LaunchDebris (entity this, string debrisname, vector force)
 void func_breakable_colormod(entity this)
 {
        float h;
-       if (!(this.spawnflags & 2))
+       if (!(this.spawnflags & BREAKABLE_INDICATE_DAMAGE))
                return;
        h = this.health / this.max_health;
        if(h < 0.25)
@@ -88,8 +91,6 @@ void func_breakable_colormod(entity this)
                this.colormod = '1 0 0' + '0 1 0' * (2 * h - 0.5);
        else
                this.colormod = '1 1 1';
-
-       CSQCMODEL_AUTOUPDATE(this);
 }
 
 void func_breakable_look_destroyed(entity this)
@@ -108,24 +109,22 @@ void func_breakable_look_destroyed(entity this)
                        this.origin_z = floorZ;
                }
                _setmodel(this, this.mdl_dead);
+               ApplyMinMaxScaleAngles(this);
                this.effects &= ~EF_NODRAW;
        }
 
-       CSQCMODEL_AUTOUPDATE(this);
-
        this.solid = SOLID_NOT;
 }
 
 void func_breakable_look_restore(entity this)
 {
        _setmodel(this, this.mdl);
+       ApplyMinMaxScaleAngles(this);
        this.effects &= ~EF_NODRAW;
 
        if(this.mdl_dead != "") // only do this if we use mdl_dead, to behave better with misc_follow
                setorigin(this, this.dropped_origin);
 
-       CSQCMODEL_AUTOUPDATE(this);
-
        this.solid = SOLID_BSP;
 }
 
@@ -133,16 +132,25 @@ void func_breakable_behave_destroyed(entity this)
 {
        this.health = this.max_health;
        this.takedamage = DAMAGE_NO;
+       if(this.bot_attack)
+               IL_REMOVE(g_bot_targets, this);
        this.bot_attack = false;
        this.event_damage = func_null;
-       this.state = 1;
-       if(this.spawnflags & 4)
+       this.state = STATE_BROKEN;
+       if(this.spawnflags & BREAKABLE_NODAMAGE)
                this.use = func_null;
        func_breakable_colormod(this);
        if (this.noise1)
                stopsound (this, CH_TRIGGER_SINGLE);
 }
 
+void func_breakable_think(entity this)
+{
+       this.nextthink = time;
+       CSQCMODEL_AUTOUPDATE(this);
+}
+
+void func_breakable_destroy(entity this, entity actor, entity trigger);
 void func_breakable_behave_restore(entity this)
 {
        this.health = this.max_health;
@@ -151,14 +159,20 @@ void func_breakable_behave_restore(entity this)
                WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
                WaypointSprite_UpdateHealth(this.sprite, this.health);
        }
-       if(!(this.spawnflags & 4))
+       if(!(this.spawnflags & BREAKABLE_NODAMAGE))
        {
                this.takedamage = DAMAGE_AIM;
+               if(!this.bot_attack)
+                       IL_PUSH(g_bot_targets, this);
                this.bot_attack = true;
                this.event_damage = func_breakable_damage;
        }
-       this.state = 0;
-       this.nextthink = 0; // cancel auto respawn
+       if(this.spawnflags & BREAKABLE_NODAMAGE)
+               this.use = func_breakable_destroy; // don't need to set it usually, as .use isn't reset
+       this.state = STATE_ALIVE;
+       //this.nextthink = 0; // cancel auto respawn
+       setthink(this, func_breakable_think);
+       this.nextthink = time + 0.1;
        func_breakable_colormod(this);
        if (this.noise1)
                _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM);
@@ -166,7 +180,7 @@ void func_breakable_behave_restore(entity this)
 
 void func_breakable_init_for_player(entity this, entity player)
 {
-       if (this.noise1 && this.state == 0 && clienttype(player) == CLIENTTYPE_REAL)
+       if (this.noise1 && this.state == STATE_ALIVE && IS_REAL_CLIENT(player))
        {
                msg_entity = player;
                soundto (MSG_ONE, this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM);
@@ -177,16 +191,12 @@ void func_breakable_destroyed(entity this)
 {
        func_breakable_look_destroyed(this);
        func_breakable_behave_destroyed(this);
-
-       CSQCMODEL_AUTOUPDATE(this);
 }
 
 void func_breakable_restore(entity this, entity actor, entity trigger)
 {
        func_breakable_look_restore(this);
        func_breakable_behave_restore(this);
-
-       CSQCMODEL_AUTOUPDATE(this);
 }
 
 void func_breakable_restore_self(entity this)
@@ -214,13 +224,14 @@ void func_breakable_destroy(entity this, entity actor, entity trigger)
                _sound (this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
 
        if(this.dmg)
-               RadiusDamage(this, act, this.dmg, this.dmg_edge, this.dmg_radius, this, NULL, this.dmg_force, DEATH_HURTTRIGGER.m_id, NULL);
+               RadiusDamage(this, act, this.dmg, this.dmg_edge, this.dmg_radius, this, NULL, this.dmg_force, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, NULL);
 
        if(this.cnt) // TODO
                __pointparticles(this.cnt, this.absmin * 0.5 + this.absmax * 0.5, '0 0 0', this.count);
 
        if(this.respawntime)
        {
+               CSQCMODEL_AUTOUPDATE(this);
                setthink(this, func_breakable_restore_self);
                this.nextthink = time + this.respawntime + crandom() * this.respawntimejitter;
        }
@@ -236,11 +247,11 @@ void func_breakable_destroy_self(entity this)
        func_breakable_destroy(this, NULL, NULL);
 }
 
-void func_breakable_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+void func_breakable_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
 {
-       if(this.state == 1)
+       if(this.state == STATE_BROKEN)
                return;
-       if(this.spawnflags & DOOR_NOSPLASH)
+       if(this.spawnflags & NOSPLASH)
                if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
                        return;
        if(this.team)
@@ -262,7 +273,7 @@ void func_breakable_damage(entity this, entity inflictor, entity attacker, float
                this.takedamage = DAMAGE_NO;
                this.event_damage = func_null;
 
-               if(IS_CLIENT(attacker) && this.classname == "func_assault_destructible")
+               if(IS_CLIENT(attacker)) //&& this.classname == "func_assault_destructible")
                {
                        this.owner = attacker;
                        this.realowner = attacker;
@@ -271,6 +282,7 @@ void func_breakable_damage(entity this, entity inflictor, entity attacker, float
                // do not explode NOW but in the NEXT FRAME!
                // because recursive calls to RadiusDamage are not allowed
                this.nextthink = time;
+               CSQCMODEL_AUTOUPDATE(this);
                setthink(this, func_breakable_destroy_self);
        }
 }
@@ -279,12 +291,10 @@ void func_breakable_reset(entity this)
 {
        this.team = this.team_saved;
        func_breakable_look_restore(this);
-       if(this.spawnflags & 1)
+       if(this.spawnflags & START_DISABLED)
                func_breakable_behave_destroyed(this);
        else
                func_breakable_behave_restore(this);
-
-       CSQCMODEL_AUTOUPDATE(this);
 }
 
 // destructible walls that can be used to trigger target_objective_decrease
@@ -321,12 +331,12 @@ spawnfunc(func_breakable)
        this.mdl = this.model;
        SetBrushEntityModel(this);
 
-       if(this.spawnflags & 4)
+       if(this.spawnflags & BREAKABLE_NODAMAGE)
                this.use = func_breakable_destroy;
        else
                this.use = func_breakable_restore;
 
-       if(this.spawnflags & 4)
+       if(this.spawnflags & BREAKABLE_NODAMAGE)
        {
                this.takedamage = DAMAGE_NO;
                this.event_damage = func_null;
@@ -345,12 +355,13 @@ spawnfunc(func_breakable)
                precache_sound(this.noise1);
 
        this.team_saved = this.team;
+       IL_PUSH(g_saved_team, this);
        this.dropped_origin = this.origin;
 
        this.reset = func_breakable_reset;
        this.reset(this);
 
-       this.init_for_player_needed = 1;
+       IL_PUSH(g_initforplayer, this);
        this.init_for_player = func_breakable_init_for_player;
 
        CSQCMODEL_AUTOINIT(this);