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 9605 for ps


Ignore:
Timestamp:
06/09/11 21:44:40 (14 years ago)
Author:
philip
Message:

# Add experimental fighter planes.

Location:
ps/trunk
Files:
4 added
15 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/_test.sim/simulation/templates/unit.xml

    r9080 r9605  
    1111        <Anchor>upright</Anchor>
    1212        <Floating>false</Floating>
     13        <TurnRate>6.0</TurnRate>
    1314    </Position>
    1415    <UnitAI/>
  • ps/trunk/binaries/data/mods/_test.sim/simulation/templates/unitobstruct.xml

    r9080 r9605  
    1111        <Anchor>upright</Anchor>
    1212        <Floating>false</Floating>
     13        <TurnRate>6.0</TurnRate>
    1314    </Position>
    1415    <UnitAI/>
  • ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js

    r9602 r9605  
    18301830        var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
    18311831        if (cmpUnitMotion)
    1832         {
    1833             cmpPosition.TurnTo(angle);
    1834         }
     1832            cmpUnitMotion.FaceTowardsPoint(pos.x, pos.z);
    18351833    }
    18361834}
  • ps/trunk/binaries/data/mods/public/simulation/templates/special/actor.xml

    r9515 r9605  
    55    <Anchor>upright</Anchor>
    66    <Floating>false</Floating>
     7    <TurnRate>6.0</TurnRate>
    78  </Position>
    89  <VisualActor>
  • ps/trunk/binaries/data/mods/public/simulation/templates/special/formation.xml

    r9010 r9605  
    55    <Anchor>upright</Anchor>
    66    <Floating>false</Floating>
     7    <TurnRate>6.0</TurnRate>
    78  </Position>
    89  <Formation/>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_entity_full.xml

    r8865 r9605  
    77    <Anchor>upright</Anchor>
    88    <Floating>false</Floating>
     9    <TurnRate>6.0</TurnRate>
    910  </Position>
    1011  <Selectable/>
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_entity_quasi.xml

    r8865 r9605  
    77    <Anchor>upright</Anchor>
    88    <Floating>false</Floating>
     9    <TurnRate>6.0</TurnRate>
    910  </Position>
    1011</Entity>
  • ps/trunk/source/simulation2/TypeList.h

    r9443 r9605  
    128128INTERFACE(UnitMotion)
    129129COMPONENT(UnitMotion) // must be after Obstruction
     130COMPONENT(UnitMotionScripted)
    130131
    131132INTERFACE(Vision)
  • ps/trunk/source/simulation2/components/CCmpPosition.cpp

    r8867 r9605  
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    6969    entity_pos_t m_X, m_Z, m_LastX, m_LastZ; // these values contain undefined junk if !InWorld
    7070    entity_pos_t m_YOffset;
     71    bool m_RelativeToGround; // whether m_YOffset is relative to terrain/water plane, or an absolute height
    7172
    7273    entity_angle_t m_RotX, m_RotY, m_RotZ;
     
    8182                "<Altitude>0.0</Altitude>"
    8283                "<Floating>false</Floating>"
     84                "<TurnRate>6.0</TurnRate>"
    8385            "</a:example>"
    8486            "<element name='Anchor' a:help='Automatic rotation to follow the slope of terrain'>"
     
    9496            "<element name='Floating' a:help='Whether the entity floats on water'>"
    9597                "<data type='boolean'/>"
     98            "</element>"
     99            "<element name='TurnRate' a:help='Maximum graphical rotation speed around Y axis, in radians per second'>"
     100                "<ref name='positiveDecimal'/>"
    96101            "</element>";
    97102    }
     
    110115
    111116        m_YOffset = paramNode.GetChild("Altitude").ToFixed();
     117        m_RelativeToGround = true;
    112118        m_Floating = paramNode.GetChild("Floating").ToBool();
    113119
    114         m_RotYSpeed = 6.f; // TODO: should get from template
     120        m_RotYSpeed = paramNode.GetChild("TurnRate").ToFixed().ToFloat();
    115121
    116122        m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0);
     
    138144        serialize.NumberFixed_Unbounded("rot z", m_RotZ);
    139145        serialize.NumberFixed_Unbounded("altitude", m_YOffset);
     146        serialize.Bool("relative", m_RelativeToGround);
    140147
    141148        if (serialize.IsDebug())
     
    169176        deserialize.NumberFixed_Unbounded("rot z", m_RotZ);
    170177        deserialize.NumberFixed_Unbounded("altitude", m_YOffset);
     178        deserialize.Bool("relative", m_RelativeToGround);
    171179        // TODO: should there be range checks on all these values?
    172180
     
    213221    {
    214222        m_YOffset = dy;
     223        m_RelativeToGround = true;
    215224
    216225        AdvertisePositionChanges();
     
    220229    {
    221230        return m_YOffset;
     231    }
     232
     233    virtual void SetHeightFixed(entity_pos_t y)
     234    {
     235        m_YOffset = y;
     236        m_RelativeToGround = false;
    222237    }
    223238
     
    236251
    237252        entity_pos_t baseY;
    238         CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
    239         if (!cmpTerrain.null())
    240             baseY = cmpTerrain->GetGroundLevel(m_X, m_Z);
    241 
    242         if (m_Floating)
    243         {
    244             CmpPtr<ICmpWaterManager> cmpWaterMan(GetSimContext(), SYSTEM_ENTITY);
    245             if (!cmpWaterMan.null())
    246                 baseY = std::max(baseY, cmpWaterMan->GetWaterLevel(m_X, m_Z));
     253        if (m_RelativeToGround)
     254        {
     255            CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
     256            if (!cmpTerrain.null())
     257                baseY = cmpTerrain->GetGroundLevel(m_X, m_Z);
     258
     259            if (m_Floating)
     260            {
     261                CmpPtr<ICmpWaterManager> cmpWaterMan(GetSimContext(), SYSTEM_ENTITY);
     262                if (!cmpWaterMan.null())
     263                    baseY = std::max(baseY, cmpWaterMan->GetWaterLevel(m_X, m_Z));
     264            }
    247265        }
    248266
     
    328346
    329347        float baseY = 0;
    330         CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
    331         if (!cmpTerrain.null())
    332             baseY = cmpTerrain->GetExactGroundLevel(x, z);
    333 
    334         if (m_Floating || forceFloating)
    335         {
    336             CmpPtr<ICmpWaterManager> cmpWaterMan(GetSimContext(), SYSTEM_ENTITY);
    337             if (!cmpWaterMan.null())
    338                 baseY = std::max(baseY, cmpWaterMan->GetExactWaterLevel(x, z));
     348        if (m_RelativeToGround)
     349        {
     350            CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
     351            if (!cmpTerrain.null())
     352                baseY = cmpTerrain->GetExactGroundLevel(x, z);
     353
     354            if (m_Floating || forceFloating)
     355            {
     356                CmpPtr<ICmpWaterManager> cmpWaterMan(GetSimContext(), SYSTEM_ENTITY);
     357                if (!cmpWaterMan.null())
     358                    baseY = std::max(baseY, cmpWaterMan->GetExactWaterLevel(x, z));
     359            }
    339360        }
    340361
  • ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp

    r9465 r9605  
    414414    virtual void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z);
    415415
     416    virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z);
     417
    416418    virtual void StopMoving()
    417419    {
     
    523525     * Rotate to face towards the target point, given the current pos
    524526     */
    525     void FaceTowardsPoint(CFixedVector2D pos, entity_pos_t x, entity_pos_t z);
     527    void FaceTowardsPointFromPos(CFixedVector2D pos, entity_pos_t x, entity_pos_t z);
    526528
    527529    /**
     
    902904                            StopMoving();
    903905
    904                             FaceTowardsPoint(pos, m_FinalGoal.x, m_FinalGoal.z);
     906                            FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z);
    905907                            // TODO: if the goal was a square building, we ought to point towards the
    906908                            // nearest point on the square, not towards its center
     
    10341036}
    10351037
    1036 void CCmpUnitMotion::FaceTowardsPoint(CFixedVector2D pos, entity_pos_t x, entity_pos_t z)
     1038void CCmpUnitMotion::FaceTowardsPoint(entity_pos_t x, entity_pos_t z)
     1039{
     1040    CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
     1041    if (cmpPosition.null() || !cmpPosition->IsInWorld())
     1042        return;
     1043
     1044    CFixedVector2D pos = cmpPosition->GetPosition2D();
     1045    FaceTowardsPointFromPos(pos, x, z);
     1046}
     1047
     1048void CCmpUnitMotion::FaceTowardsPointFromPos(CFixedVector2D pos, entity_pos_t x, entity_pos_t z)
    10371049{
    10381050    CFixedVector2D target(x, z);
     
    12241236        {
    12251237            // We're already in range - no need to move anywhere
    1226             FaceTowardsPoint(pos, x, z);
     1238            FaceTowardsPointFromPos(pos, x, z);
    12271239            return false;
    12281240        }
     
    13351347        {
    13361348            // We're already in range - no need to move anywhere
    1337             FaceTowardsPoint(pos, goal.x, goal.z);
     1349            FaceTowardsPointFromPos(pos, goal.x, goal.z);
    13381350            return false;
    13391351        }
     
    13571369                {
    13581370                    // We're already in range - no need to move anywhere
    1359                     FaceTowardsPoint(pos, goal.x, goal.z);
     1371                    FaceTowardsPointFromPos(pos, goal.x, goal.z);
    13601372                    return false;
    13611373                }
  • ps/trunk/source/simulation2/components/ICmpPosition.cpp

    r9595 r9605  
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    2929DEFINE_INTERFACE_METHOD_1("SetHeightOffset", void, ICmpPosition, SetHeightOffset, entity_pos_t)
    3030DEFINE_INTERFACE_METHOD_0("GetHeightOffset", entity_pos_t, ICmpPosition, GetHeightOffset)
     31DEFINE_INTERFACE_METHOD_1("SetHeightFixed", void, ICmpPosition, SetHeightFixed, entity_pos_t)
    3132DEFINE_INTERFACE_METHOD_0("IsFloating", bool, ICmpPosition, IsFloating)
    3233DEFINE_INTERFACE_METHOD_0("GetPosition", CFixedVector3D, ICmpPosition, GetPosition)
  • ps/trunk/source/simulation2/components/ICmpPosition.h

    r8058 r9605  
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    8686
    8787    /**
     88     * Set the vertical position as a fixed, absolute value.
     89     * Will stay at this height until the next call to SetHeightFixed or SetHeightOffset.
     90     */
     91    virtual void SetHeightFixed(entity_pos_t y) = 0;
     92
     93    /**
    8894     * Returns whether the entity floats on water.
    8995     */
  • ps/trunk/source/simulation2/components/ICmpUnitMotion.cpp

    r8751 r9605  
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    2121
    2222#include "simulation2/system/InterfaceScripted.h"
     23#include "simulation2/scripting/ScriptComponent.h"
    2324
    2425BEGIN_INTERFACE_WRAPPER(UnitMotion)
     
    2728DEFINE_INTERFACE_METHOD_3("MoveToTargetRange", bool, ICmpUnitMotion, MoveToTargetRange, entity_id_t, entity_pos_t, entity_pos_t)
    2829DEFINE_INTERFACE_METHOD_3("MoveToFormationOffset", void, ICmpUnitMotion, MoveToFormationOffset, entity_id_t, entity_pos_t, entity_pos_t)
     30DEFINE_INTERFACE_METHOD_2("FaceTowardsPoint", void, ICmpUnitMotion, FaceTowardsPoint, entity_pos_t, entity_pos_t)
    2931DEFINE_INTERFACE_METHOD_0("StopMoving", void, ICmpUnitMotion, StopMoving)
    3032DEFINE_INTERFACE_METHOD_1("SetSpeed", void, ICmpUnitMotion, SetSpeed, fixed)
     
    3436DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpUnitMotion, SetDebugOverlay, bool)
    3537END_INTERFACE_WRAPPER(UnitMotion)
     38
     39class CCmpUnitMotionScripted : public ICmpUnitMotion
     40{
     41public:
     42    DEFAULT_SCRIPT_WRAPPER(UnitMotionScripted)
     43
     44    virtual bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange)
     45    {
     46        return m_Script.Call<bool>("MoveToPointRange", x, z, minRange, maxRange);
     47    }
     48
     49    virtual bool IsInTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)
     50    {
     51        return m_Script.Call<bool>("IsInTargetRange", target, minRange, maxRange);
     52    }
     53
     54    virtual bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)
     55    {
     56        return m_Script.Call<bool>("MoveToTargetRange", target, minRange, maxRange);
     57    }
     58
     59    virtual void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z)
     60    {
     61        m_Script.CallVoid("MoveToFormationOffset", target, x, z);
     62    }
     63
     64    virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z)
     65    {
     66        m_Script.CallVoid("FaceTowardsPoint", x, z);
     67    }
     68
     69    virtual void StopMoving()
     70    {
     71        m_Script.CallVoid("StopMoving");
     72    }
     73
     74    virtual void SetSpeed(fixed speed)
     75    {
     76        m_Script.CallVoid("SetSpeed", speed);
     77    }
     78
     79    virtual fixed GetWalkSpeed()
     80    {
     81        return m_Script.Call<fixed>("GetWalkSpeed");
     82    }
     83
     84    virtual fixed GetRunSpeed()
     85    {
     86        return m_Script.Call<fixed>("GetRunSpeed");
     87    }
     88
     89    virtual void SetUnitRadius(fixed radius)
     90    {
     91        m_Script.CallVoid("SetUnitRadius", radius);
     92    }
     93
     94    virtual void SetDebugOverlay(bool enabled)
     95    {
     96        m_Script.CallVoid("SetDebugOverlay", enabled);
     97    }
     98
     99};
     100
     101REGISTER_COMPONENT_SCRIPT_WRAPPER(UnitMotionScripted)
  • ps/trunk/source/simulation2/components/ICmpUnitMotion.h

    r9010 r9605  
    6969
    7070    /**
     71     * Turn to look towards the given point.
     72     */
     73    virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z) = 0;
     74
     75    /**
    7176     * Stop moving immediately.
    7277     */
  • ps/trunk/source/simulation2/tests/test_CmpTemplateManager.h

    r9462 r9605  
    8484        TS_ASSERT(preview != NULL);
    8585        TS_ASSERT_WSTR_EQUALS(preview->ToXML(),
    86                 L"<Position><Altitude>0</Altitude><Anchor>upright</Anchor><Floating>false</Floating></Position>"
     86                L"<Position><Altitude>0</Altitude><Anchor>upright</Anchor><Floating>false</Floating><TurnRate>6.0</TurnRate></Position>"
    8787                L"<Vision><AlwaysVisible>true</AlwaysVisible><Range>0</Range><RetainInFog>false</RetainInFog></Vision>"
    8888                L"<VisualActor><Actor>example</Actor><SilhouetteDisplay>false</SilhouetteDisplay><SilhouetteOccluder>false</SilhouetteOccluder></VisualActor>");
     
    9898                    L"<Unit radius=\"4\"></Unit>"
    9999                L"</Obstruction>"
    100                 L"<Position><Altitude>0</Altitude><Anchor>upright</Anchor><Floating>false</Floating></Position>"
     100                L"<Position><Altitude>0</Altitude><Anchor>upright</Anchor><Floating>false</Floating><TurnRate>6.0</TurnRate></Position>"
    101101                L"<Vision><AlwaysVisible>true</AlwaysVisible><Range>0</Range><RetainInFog>false</RetainInFog></Vision>"
    102102                L"<VisualActor><Actor>example</Actor><SilhouetteDisplay>false</SilhouetteDisplay><SilhouetteOccluder>false</SilhouetteOccluder></VisualActor>");
Note: See TracChangeset for help on using the changeset viewer.