Ticket #3685: clearance.diff

File clearance.diff, 15.2 KB (added by sanderd17, 3 years ago)
  • binaries/data/mods/public/simulation/components/BuildRestrictions.js

     
    133133    if (!cmpObstruction)
    134134        return result; // Fail
    135135
     136    var ret = cmpObstruction.CheckFoundation(passClassName);
    136137
    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     }
    146 
    147138    if (ret != "success")
    148139    {
    149140        switch (ret)
  • binaries/data/mods/public/simulation/templates/other/palisades_rocks_tower.xml

     
    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_gaia_flora.xml

     
    88    <GenericName>Generic Flora</GenericName>
    99  </Identity>
    1010  <Obstruction>
    11     <Static width="3.0" depth="3.0"/>
     11    <Static width="3.0" depth="3.0" clearance="0"/>
    1212  </Obstruction>
    1313</Entity>
  • binaries/data/mods/public/simulation/templates/template_gaia_geo.xml

     
    88    <GenericName>Generic Geology</GenericName>
    99  </Identity>
    1010  <Obstruction>
    11     <Static width="7.0" depth="7.0"/>
     11    <Static width="7.0" depth="7.0" clearance="0"/>
    1212  </Obstruction>
    1313  <Position>
    1414    <Anchor>pitch-roll</Anchor>
  • binaries/data/mods/public/simulation/templates/template_gaia_treasure.xml

     
    1515    <Color r="250" g="250" b="250"/>
    1616  </Minimap>
    1717  <Obstruction>
    18     <Static width="1.5" depth="1.5"/>
     18    <Static width="1.5" depth="1.5" clearance="0"/>
    1919  </Obstruction>
    2020  <ResourceSupply>
    2121    <KillBeforeGather>false</KillBeforeGather>
  • binaries/data/mods/public/simulation/templates/template_structure.xml

     
    6262    <Type>structure</Type>
    6363  </Minimap>
    6464  <Obstruction>
     65    <Static width="2" depth="2" clearance="4"/>
    6566    <Active>true</Active>
    6667    <BlockMovement>true</BlockMovement>
    6768    <BlockPathfinding>true</BlockPathfinding>
  • binaries/data/mods/public/simulation/templates/template_structure_defense_wall.xml

     
    3737    <metal>0</metal>
    3838  </Loot>
    3939  <Obstruction>
    40     <Static width="6.0" depth="6.0"/>
     40    <Static width="6.0" depth="6.0" clearance="0"/>
    4141  </Obstruction>
    4242  <RallyPoint disable=""/>
    4343  <Sound>
  • binaries/data/mods/public/simulation/templates/template_structure_defense_wall_gate.xml

     
    3939    <metal>0</metal>
    4040  </Loot>
    4141  <Obstruction>
     42    <Static disable=""/>
    4243    <Obstructions>
    4344      <Right width="5" depth="5" x="10" z="0"/>
    4445      <Left width="5" depth="5" x="-10" z="0"/>
  • binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml

     
    6464    <metal>0</metal>
    6565  </Loot>
    6666  <Obstruction>
    67     <Static width="6.0" depth="6.0"/>
     67    <Static width="6.0" depth="6.0" clearance="-1"/>
    6868    <ControlPersist/>
    6969  </Obstruction>
    7070  <ProductionQueue>
  • source/simulation2/components/CCmpObstruction.cpp

     
    122122                            "<param name='minInclusive'>1.5</param>"
    123123                        "</data>"
    124124                    "</attribute>"
     125                    "<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).'>"
     126                        "<data type='decimal'/>"
     127                    "</attribute>"
    125128                "</element>"
    126129                "<element name='Unit'>"
    127130                    "<empty/>"
     
    216219            m_Type = STATIC;
    217220            m_Size0 = paramNode.GetChild("Static").GetChild("@width").ToFixed();
    218221            m_Size1 = paramNode.GetChild("Static").GetChild("@depth").ToFixed();
     222            m_Clearance = paramNode.GetChild("Static").GetChild("@clearance").ToFixed();
    219223            ENSURE(m_Size0 > minObstruction);
    220224            ENSURE(m_Size1 > minObstruction);
    221225        }
     
    244248            }
    245249            m_Size0 = fixed::FromInt(2).Multiply(MAX(max.X, -min.X));
    246250            m_Size1 = fixed::FromInt(2).Multiply(MAX(max.Y, -min.Y));
     251            // TODO perhaps support clearance per obstruction
     252            m_Clearance = entity_pos_t::Zero();
    247253        }
    248254
    249255        m_Active = paramNode.GetChild("Active").ToBool();
     
    525531   
    526532    virtual EFoundationCheck CheckFoundation(std::string className)
    527533    {
    528         return  CheckFoundation(className, false);
    529     }
    530 
    531     virtual EFoundationCheck CheckFoundation(std::string className, bool onlyCenterPoint)
    532     {
    533534        CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle());
    534535        if (!cmpPosition)
    535536            return FOUNDATION_CHECK_FAIL_ERROR; // error
     
    560561            ICmpObstructionManager::FLAG_BLOCK_FOUNDATION);
    561562
    562563        if (m_Type == UNIT)
    563             return cmpPathfinder->CheckUnitPlacement(filter, pos.X, pos.Y, m_Clearance, passClass, onlyCenterPoint);
     564            return cmpPathfinder->CheckUnitPlacement(filter, pos.X, pos.Y, m_Clearance, passClass);
    564565        else
    565             return cmpPathfinder->CheckBuildingPlacement(filter, pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1, GetEntityId(), passClass, onlyCenterPoint);
     566            return cmpPathfinder->CheckBuildingPlacement(filter, pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1, GetEntityId(), passClass, m_Clearance * 2);
    566567    }
    567568
    568569    virtual bool CheckDuplicateFoundation()
  • source/simulation2/components/CCmpPathfinder.cpp

     
    801801}
    802802
    803803ICmpObstruction::EFoundationCheck CCmpPathfinder::CheckUnitPlacement(const IObstructionTestFilter& filter,
    804     entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass, bool UNUSED(onlyCenterPoint))
     804    entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass)
    805805{
    806806    // Check unit obstruction
    807807    CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity());
     
    829829    entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w,
    830830    entity_pos_t h, entity_id_t id, pass_class_t passClass)
    831831{
    832     return CCmpPathfinder::CheckBuildingPlacement(filter, x, z, a, w, h, id, passClass, false);
     832    return CCmpPathfinder::CheckBuildingPlacement(filter, x, z, a, w, h, id, passClass, entity_pos_t::Zero());
    833833}
    834834
    835835
    836836ICmpObstruction::EFoundationCheck CCmpPathfinder::CheckBuildingPlacement(const IObstructionTestFilter& filter,
    837837    entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w,
    838     entity_pos_t h, entity_id_t id, pass_class_t passClass, bool UNUSED(onlyCenterPoint))
     838    entity_pos_t h, entity_id_t id, pass_class_t passClass, entity_pos_t clearance)
    839839{
    840840    // Check unit obstruction
    841841    CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity());
     
    842842    if (!cmpObstructionManager)
    843843        return ICmpObstruction::FOUNDATION_CHECK_FAIL_ERROR;
    844844
    845     if (cmpObstructionManager->TestStaticShape(filter, x, z, a, w, h, NULL))
     845    if (cmpObstructionManager->TestStaticShape(filter, x, z, a, w + clearance, h + clearance, NULL))
    846846        return ICmpObstruction::FOUNDATION_CHECK_FAIL_OBSTRUCTS_FOUNDATION;
    847847
    848848    // Test against terrain:
  • source/simulation2/components/CCmpPathfinder_Common.h

     
    212212
    213213    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);
    214214
    215     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);
     215    virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass);
    216216
    217217    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);
    218218
    219     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);
     219    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);
    220220
    221221    virtual void FinishAsyncRequests();
    222222
  • source/simulation2/components/ICmpObstruction.cpp

     
    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    {
     
    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

     
    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

     
    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
     
    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    /**