This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 9595 for ps


Ignore:
Timestamp:
06/07/11 00:08:26 (14 years ago)
Author:
Badmadblacksad
Message:

Ranged units always face their targets when attacking. fixes #831

Location:
ps/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js

    r9532 r9595  
    620620                    // TODO: if .prepare is short, players can cheat by cycling attack/stop/attack
    621621                    // to beat the .repeat time; should enforce a minimum time
     622
     623                    this.FaceTowardsTarget(this.order.data.target);
    622624                },
    623625
     
    633635                        if (this.CheckTargetRange(this.order.data.target, IID_Attack, this.attackType))
    634636                        {
     637                            this.FaceTowardsTarget(this.order.data.target);
    635638                            var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
    636639                            cmpAttack.PerformAttack(this.attackType, this.order.data.target);
     
    18131816};
    18141817
     1818UnitAI.prototype.FaceTowardsTarget = function(target)
     1819{
     1820    var cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
     1821    if (!cmpPosition || !cmpPosition.IsInWorld())
     1822            return;
     1823    var cmpTargetPosition = Engine.QueryInterface(target, IID_Position);
     1824    if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld())
     1825            return;
     1826    var pos = cmpPosition.GetPosition();
     1827    var targetpos = cmpTargetPosition.GetPosition();
     1828    var angle = Math.atan2(targetpos.x - pos.x, targetpos.z - pos.z);
     1829    var rot = cmpPosition.GetRotation();
     1830    var delta = (rot.y - angle + Math.PI) % (2 * Math.PI) - Math.PI;
     1831    if (Math.abs(delta) > 0.2)
     1832    {
     1833        var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
     1834        if (cmpUnitMotion)
     1835        {
     1836            cmpPosition.TurnTo(angle);
     1837        }
     1838    }
     1839}
     1840
    18151841UnitAI.prototype.GetBestAttack = function()
    18161842{
  • ps/trunk/source/simulation2/components/ICmpPosition.cpp

    r8866 r9595  
    3232DEFINE_INTERFACE_METHOD_0("GetPosition", CFixedVector3D, ICmpPosition, GetPosition)
    3333DEFINE_INTERFACE_METHOD_0("GetPosition2D", CFixedVector2D, ICmpPosition, GetPosition2D)
     34DEFINE_INTERFACE_METHOD_1("TurnTo", void, ICmpPosition, TurnTo, entity_angle_t)
    3435DEFINE_INTERFACE_METHOD_1("SetYRotation", void, ICmpPosition, SetYRotation, entity_angle_t)
    3536DEFINE_INTERFACE_METHOD_2("SetXZRotation", void, ICmpPosition, SetXZRotation, entity_angle_t, entity_angle_t)
Note: See TracChangeset for help on using the changeset viewer.