Ticket #1833: faceTowardsPoint.diff

File faceTowardsPoint.diff, 5.2 KB (added by mimo, 11 years ago)
  • source/simulation2/components/ICmpUnitMotion.cpp

     
    3535DEFINE_INTERFACE_METHOD_0("IsMoving", bool, ICmpUnitMotion, IsMoving)
    3636DEFINE_INTERFACE_METHOD_0("GetWalkSpeed", fixed, ICmpUnitMotion, GetWalkSpeed)
    3737DEFINE_INTERFACE_METHOD_0("GetRunSpeed", fixed, ICmpUnitMotion, GetRunSpeed)
     38DEFINE_INTERFACE_METHOD_1("SetFacePointAfterMove", void, ICmpUnitMotion, SetFacePointAfterMove, bool)
    3839DEFINE_INTERFACE_METHOD_1("SetUnitRadius", void, ICmpUnitMotion, SetUnitRadius, fixed)
    3940DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpUnitMotion, SetDebugOverlay, bool)
    4041END_INTERFACE_WRAPPER(UnitMotion)
     
    104105        return m_Script.Call<fixed>("GetRunSpeed");
    105106    }
    106107
     108    virtual void SetFacePointAfterMove(bool facePointAfterMove)
     109    {
     110        m_Script.CallVoid("SetFacePointAfterMove", facePointAfterMove);
     111    }
     112
    107113    virtual ICmpPathfinder::pass_class_t GetPassabilityClass()
    108114    {
    109115        return m_Script.Call<ICmpPathfinder::pass_class_t>("GetPassabilityClass");
  • source/simulation2/components/CCmpUnitMotion.cpp

     
    129129
    130130    entity_pos_t m_Radius;
    131131    bool m_Moving;
     132    bool m_FacePointAfterMove;
    132133
    133134    enum State
    134135    {
     
    281282        m_FormationController = paramNode.GetChild("FormationController").ToBool();
    282283
    283284        m_Moving = false;
     285        m_FacePointAfterMove = true;
     286
    284287        m_WalkSpeed = paramNode.GetChild("WalkSpeed").ToFixed();
    285288        m_Speed = m_WalkSpeed;
    286289        m_CurSpeed = fixed::Zero();
     
    342345        serialize.NumberFixed_Unbounded("speed", m_Speed);
    343346
    344347        serialize.Bool("moving", m_Moving);
     348        serialize.Bool("facePointAfterMove", m_FacePointAfterMove);
    345349
    346350        SerializeVector<SerializeWaypoint>()(serialize, "long path", m_LongPath.m_Waypoints);
    347351        SerializeVector<SerializeWaypoint>()(serialize, "short path", m_ShortPath.m_Waypoints);
     
    428432        m_Speed = speed;
    429433    }
    430434
     435    virtual void SetFacePointAfterMove(bool facePointAfterMove)
     436    {
     437        m_FacePointAfterMove = facePointAfterMove;
     438    }
     439
    431440    virtual void SetDebugOverlay(bool enabled)
    432441    {
    433442        m_DebugOverlayEnabled = enabled;
     
    963972
    964973                            StopMoving();
    965974
    966                             FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z);
     975
     976                            if (m_FacePointAfterMove)
     977                                FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z);
    967978                            // TODO: if the goal was a square building, we ought to point towards the
    968979                            // nearest point on the square, not towards its center
    969980                        }
     
    13121323        else
    13131324        {
    13141325            // We're already in range - no need to move anywhere
    1315             FaceTowardsPointFromPos(pos, x, z);
     1326            if (m_FacePointAfterMove)
     1327                FaceTowardsPointFromPos(pos, x, z);
    13161328            return false;
    13171329        }
    13181330
     
    14741486        else if (maxRange < entity_pos_t::Zero() || distance < maxRange)
    14751487        {
    14761488            // We're already in range - no need to move anywhere
    1477             FaceTowardsPointFromPos(pos, goal.x, goal.z);
     1489            if (m_FacePointAfterMove)
     1490                FaceTowardsPointFromPos(pos, goal.x, goal.z);
    14781491            return false;
    14791492        }
    14801493        else
     
    14961509                if (circleDistance < maxRange)
    14971510                {
    14981511                    // We're already in range - no need to move anywhere
    1499                     FaceTowardsPointFromPos(pos, goal.x, goal.z);
     1512                    if (m_FacePointAfterMove)
     1513                        FaceTowardsPointFromPos(pos, goal.x, goal.z);
    15001514                    return false;
    15011515                }
    15021516
  • source/simulation2/components/ICmpUnitMotion.h

     
    110110    virtual fixed GetRunSpeed() = 0;
    111111
    112112    /**
     113     * Set the FaceTowardsPoint after the move
     114     */
     115    virtual void SetFacePointAfterMove(bool facePointAfterMove) = 0;
     116
     117    /**
    113118     * Get the unit's passability class.
    114119     */
    115120    virtual ICmpPathfinder::pass_class_t GetPassabilityClass() = 0;
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    24312431                this.MoveRandomly(+this.template.RoamDistance);
    24322432                // Set a random timer to switch to feeding state
    24332433                this.StartTimer(RandomInt(+this.template.RoamTimeMin, +this.template.RoamTimeMax));
     2434                this.SetFacePointAfterMove(false);
    24342435            },
    24352436
    24362437            "leave": function() {
    24372438                this.StopTimer();
     2439                this.SetFacePointAfterMove(true);
    24382440            },
    24392441
    24402442            "LosRangeUpdate": function(msg) {
     
    45834585    cmpMotion.MoveToPointRange(tx, tz, distance, distance);
    45844586};
    45854587
     4588UnitAI.prototype.SetFacePointAfterMove = function(val)
     4589{
     4590    var cmpMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
     4591    if (cmpMotion)
     4592        cmpMotion.SetFacePointAfterMove(val);
     4593};
     4594
    45864595UnitAI.prototype.AttackEntitiesByPreference = function(ents)
    45874596{
    45884597    var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);