Ticket #3685: rebased_clearance.patch

File rebased_clearance.patch, 14.4 KB (added by wraitii, 7 years ago)
  • binaries/data/mods/public/simulation/components/BuildRestrictions.js

    diff --git a/binaries/data/mods/public/simulation/components/BuildRestrictions.js b/binaries/data/mods/public/simulation/components/BuildRestrictions.js
    index 75c0c48..a998302 100644
    a b BuildRestrictions.prototype.CheckPlacement = function()  
    133133    if (!cmpObstruction)
    134134        return result; // Fail
    135135
    136 
    137     if (this.template.Category == "Wall")
    138     {
    139         // for walls, only test the center point
    140         var ret = cmpObstruction.CheckFoundation(passClassName, true);
    141     }
    142     else
    143     {
    144         var ret = cmpObstruction.CheckFoundation(passClassName, false);
    145     }
     136    var ret = cmpObstruction.CheckFoundation(passClassName);
    146137
    147138    if (ret != "success")
    148139    {
  • binaries/data/mods/public/simulation/templates/other/bridge_hele.xml

    diff --git a/binaries/data/mods/public/simulation/templates/other/bridge_hele.xml b/binaries/data/mods/public/simulation/templates/other/bridge_hele.xml
    index dbe722f..f70f030 100644
    a b  
    2020  </Identity>
    2121  <Minimap disable=""/>
    2222  <Obstruction>
     23    <Static disable=""/>
    2324    <Obstructions>
    2425      <Edge width="59" depth="4" x="0" z="5"/>
    2526    </Obstructions>
  • binaries/data/mods/public/simulation/templates/other/bridge_wooden.xml

    diff --git a/binaries/data/mods/public/simulation/templates/other/bridge_wooden.xml b/binaries/data/mods/public/simulation/templates/other/bridge_wooden.xml
    index 89b4e7e..6b1a5cd 100644
    a b  
    2020  </Identity>
    2121  <Minimap disable=""/>
    2222  <Obstruction>
     23    <Static disable=""/>
    2324    <Obstructions>
    2425      <Edge width="59" depth="4" x="0" z="5"/>
    2526    </Obstructions>
  • binaries/data/mods/public/simulation/templates/other/palisades_rocks_tower.xml

    diff --git a/binaries/data/mods/public/simulation/templates/other/palisades_rocks_tower.xml b/binaries/data/mods/public/simulation/templates/other/palisades_rocks_tower.xml
    index 2dc8899..d1a55cb 100644
    a b  
    3030    <RequiredTechnology>phase_village</RequiredTechnology>
    3131  </Identity>
    3232  <Obstruction>
    33     <Static width="4.0" depth="4.0"/>
     33    <Static width="4.0" depth="4.0" clearance="-1"/>
    3434    <ControlPersist/>
    3535  </Obstruction>
    3636  <StatusBars>
  • binaries/data/mods/public/simulation/templates/template_structure.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_structure.xml b/binaries/data/mods/public/simulation/templates/template_structure.xml
    index dd05092..728b825 100644
    a b  
    6666    <Type>structure</Type>
    6767  </Minimap>
    6868  <Obstruction>
     69    <Static width="2" depth="2" clearance="4"/>
    6970    <Active>true</Active>
    7071    <BlockMovement>true</BlockMovement>
    7172    <BlockPathfinding>true</BlockPathfinding>
  • binaries/data/mods/public/simulation/templates/template_structure_defense_wall.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_structure_defense_wall.xml b/binaries/data/mods/public/simulation/templates/template_structure_defense_wall.xml
    index 36146e1..af51812 100644
    a b  
    3131    <stone>15</stone>
    3232  </Loot>
    3333  <Obstruction>
    34     <Static width="6.0" depth="6.0"/>
     34    <Static width="6.0" depth="6.0" clearance="0"/>
    3535  </Obstruction>
    3636  <ProductionQueue disable=""/>
    3737  <RallyPoint disable=""/>
  • binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml b/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml
    index 12a9438..570b7aa 100644
    a b  
    5858    <stone>15</stone>
    5959  </Loot>
    6060  <Obstruction>
    61     <Static width="6.0" depth="6.0"/>
     61    <Static width="6.0" depth="6.0" clearance="-1"/>
    6262    <ControlPersist/>
    6363  </Obstruction>
    6464  <ProductionQueue>
  • source/simulation2/components/CCmpObstruction.cpp

    diff --git a/source/simulation2/components/CCmpObstruction.cpp b/source/simulation2/components/CCmpObstruction.cpp
    index a45b1e4..5c0cd23 100644
    a b public:  
    122122                            "<param name='minInclusive'>1.5</param>"
    123123                        "</data>"
    124124                    "</attribute>"
     125                    "<optional>"
     126                        "<attribute name='clearance' a:help='Extra clearance to be applied when placing the entity, ensures there is passable space around it (can be negative to allow for overlap, if the overlap is small enough to not cause problems).'>"
     127                            "<data type='decimal'/>"
     128                        "</attribute>"
     129                    "</optional>"
    125130                "</element>"
    126131                "<element name='Unit'>"
    127132                    "<empty/>"
    public:  
    216221            m_Type = STATIC;
    217222            m_Size0 = paramNode.GetChild("Static").GetChild("@width").ToFixed();
    218223            m_Size1 = paramNode.GetChild("Static").GetChild("@depth").ToFixed();
     224            m_Clearance = paramNode.GetChild("Static").GetChild("@clearance").ToFixed();
    219225            ENSURE(m_Size0 > minObstruction);
    220226            ENSURE(m_Size1 > minObstruction);
    221227        }
    public:  
    244250            }
    245251            m_Size0 = fixed::FromInt(2).Multiply(MAX(max.X, -min.X));
    246252            m_Size1 = fixed::FromInt(2).Multiply(MAX(max.Y, -min.Y));
     253            // TODO perhaps support clearance per obstruction
     254            m_Clearance = entity_pos_t::Zero();
    247255        }
    248256
    249257        m_Active = paramNode.GetChild("Active").ToBool();
    public:  
    525533   
    526534    virtual EFoundationCheck CheckFoundation(std::string className)
    527535    {
    528         return  CheckFoundation(className, false);
    529     }
    530 
    531     virtual EFoundationCheck CheckFoundation(std::string className, bool onlyCenterPoint)
    532     {
    533536        CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle());
    534537        if (!cmpPosition)
    535538            return FOUNDATION_CHECK_FAIL_ERROR; // error
    public:  
    560563            ICmpObstructionManager::FLAG_BLOCK_FOUNDATION);
    561564
    562565        if (m_Type == UNIT)
    563             return cmpPathfinder->CheckUnitPlacement(filter, pos.X, pos.Y, m_Clearance, passClass, onlyCenterPoint);
     566            return cmpPathfinder->CheckUnitPlacement(filter, pos.X, pos.Y, m_Clearance, passClass);
    564567        else
    565             return cmpPathfinder->CheckBuildingPlacement(filter, pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1, GetEntityId(), passClass, onlyCenterPoint);
     568            return cmpPathfinder->CheckBuildingPlacement(filter, pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1, GetEntityId(), passClass, m_Clearance * 2);
    566569    }
    567570
    568571    virtual bool CheckDuplicateFoundation()
  • source/simulation2/components/CCmpPathfinder.cpp

    diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp
    index e0e725f..ce13db4 100644
    a b bool CCmpPathfinder::CheckMovement(const IObstructionTestFilter& filter,  
    810810}
    811811
    812812ICmpObstruction::EFoundationCheck CCmpPathfinder::CheckUnitPlacement(const IObstructionTestFilter& filter,
    813     entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass, bool UNUSED(onlyCenterPoint))
     813    entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass)
    814814{
    815815    // Check unit obstruction
    816816    CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity());
    ICmpObstruction::EFoundationCheck CCmpPathfinder::CheckBuildingPlacement(const I  
    838838    entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w,
    839839    entity_pos_t h, entity_id_t id, pass_class_t passClass)
    840840{
    841     return CCmpPathfinder::CheckBuildingPlacement(filter, x, z, a, w, h, id, passClass, false);
     841    return CCmpPathfinder::CheckBuildingPlacement(filter, x, z, a, w, h, id, passClass, entity_pos_t::Zero());
    842842}
    843843
    844844
    845845ICmpObstruction::EFoundationCheck CCmpPathfinder::CheckBuildingPlacement(const IObstructionTestFilter& filter,
    846846    entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w,
    847     entity_pos_t h, entity_id_t id, pass_class_t passClass, bool UNUSED(onlyCenterPoint))
     847    entity_pos_t h, entity_id_t id, pass_class_t passClass, entity_pos_t clearance)
    848848{
    849849    // Check unit obstruction
    850850    CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity());
    851851    if (!cmpObstructionManager)
    852852        return ICmpObstruction::FOUNDATION_CHECK_FAIL_ERROR;
    853853
    854     if (cmpObstructionManager->TestStaticShape(filter, x, z, a, w, h, NULL))
     854    if (cmpObstructionManager->TestStaticShape(filter, x, z, a, w + clearance, h + clearance, NULL))
    855855        return ICmpObstruction::FOUNDATION_CHECK_FAIL_OBSTRUCTS_FOUNDATION;
    856856
    857857    // Test against terrain:
  • source/simulation2/components/CCmpPathfinder_Common.h

    diff --git a/source/simulation2/components/CCmpPathfinder_Common.h b/source/simulation2/components/CCmpPathfinder_Common.h
    index 7fc9789..32de276 100644
    a b public:  
    273273
    274274    virtual bool CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, pass_class_t passClass);
    275275
    276     virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass, bool onlyCenterPoint);
     276    virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass);
    277277
    278278    virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass);
    279279
    280     virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass, bool onlyCenterPoint);
     280    virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass, entity_pos_t clearance);
    281281
    282282    virtual void FinishAsyncRequests();
    283283
  • source/simulation2/components/ICmpObstruction.cpp

    diff --git a/source/simulation2/components/ICmpObstruction.cpp b/source/simulation2/components/ICmpObstruction.cpp
    index 3216ae9..c6b967e 100644
    a b  
    2323
    2424#include "simulation2/system/SimContext.h"
    2525
    26 std::string ICmpObstruction::CheckFoundation_wrapper(const std::string& className, bool onlyCenterPoint)
     26std::string ICmpObstruction::CheckFoundation_wrapper(const std::string& className)
    2727{
    28     EFoundationCheck check = CheckFoundation(className, onlyCenterPoint);
     28    EFoundationCheck check = CheckFoundation(className);
    2929
    3030    switch (check)
    3131    {
    std::string ICmpObstruction::CheckFoundation_wrapper(const std::string& classNam  
    4747
    4848BEGIN_INTERFACE_WRAPPER(Obstruction)
    4949DEFINE_INTERFACE_METHOD_0("GetUnitRadius", entity_pos_t, ICmpObstruction, GetUnitRadius)
    50 DEFINE_INTERFACE_METHOD_2("CheckFoundation", std::string, ICmpObstruction, CheckFoundation_wrapper, std::string, bool)
     50DEFINE_INTERFACE_METHOD_1("CheckFoundation", std::string, ICmpObstruction, CheckFoundation_wrapper, std::string)
    5151DEFINE_INTERFACE_METHOD_0("CheckDuplicateFoundation", bool, ICmpObstruction, CheckDuplicateFoundation)
    5252DEFINE_INTERFACE_METHOD_0("GetUnitCollisions", std::vector<entity_id_t>, ICmpObstruction, GetUnitCollisions)
    5353DEFINE_INTERFACE_METHOD_1("SetActive", void, ICmpObstruction, SetActive, bool)
  • source/simulation2/components/ICmpObstruction.h

    diff --git a/source/simulation2/components/ICmpObstruction.h b/source/simulation2/components/ICmpObstruction.h
    index a337502..eb5bfc3 100644
    a b public:  
    6868     *  value describing the type of failure.
    6969     */
    7070    virtual EFoundationCheck CheckFoundation(std::string className) = 0;
    71     virtual EFoundationCheck CheckFoundation(std::string className, bool onlyCenterPoint) = 0;
    7271
    7372    /**
    7473     * CheckFoundation wrapper for script calls, to return friendly strings instead of an EFoundationCheck.
    7574     * @return "success" if check passes, else a string describing the type of failure.
    7675     */
    77     virtual std::string CheckFoundation_wrapper(const std::string& className, bool onlyCenterPoint);
     76    virtual std::string CheckFoundation_wrapper(const std::string& className);
    7877
    7978    /**
    8079     * Test whether this entity is colliding with any obstructions that share its
  • source/simulation2/components/ICmpPathfinder.h

    diff --git a/source/simulation2/components/ICmpPathfinder.h b/source/simulation2/components/ICmpPathfinder.h
    index 80b590b..35b55b8 100644
    a b public:  
    134134    /**
    135135     * Check whether a unit placed here is valid and doesn't hit any obstructions
    136136     * or impassable terrain.
    137      * When onlyCenterPoint = true, only check the center tile of the unit
    138137     * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
    139138     *  a value describing the type of failure.
    140139     */
    141     virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass, bool onlyCenterPoint = false) = 0;
     140    virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass) = 0;
    142141
    143142    /**
    144143     * Check whether a building placed here is valid and doesn't hit any obstructions
    public:  
    151150    /**
    152151     * Check whether a building placed here is valid and doesn't hit any obstructions
    153152     * or impassable terrain.
    154      * when onlyCenterPoint = true, only check the center tile of the building
    155153     * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
    156154     *  a value describing the type of failure.
    157155     */
    158     virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass, bool onlyCenterPoint) = 0;
     156    virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass, entity_pos_t clearance) = 0;
    159157
    160158
    161159    /**