Ticket #3997: terrainbonus.diff

File terrainbonus.diff, 8.0 KB (added by sanderd17, 8 years ago)
  • binaries/data/mods/public/art/terrains/biome-alpine/alpine_grass.xml

     
    66        <texture name="specTex" file="types/medit_grass_field_spec.png"/>
    77    </textures>
    88    <material>terrain_norm_spec.xml</material>
    9 </terrain>
    10  No newline at end of file
     9    <props classes="test1, test2"/>
     10</terrain>
  • binaries/data/mods/public/art/terrains/terrain_texture.rnc

     
    1919    }? &
    2020    element props {
    2121        attribute groups { text }? & # comma-separated list of groups
     22        attribute classes { text }? & # comma-separated list of classes
    2223        attribute mmap {
    2324            list {
    2425                xsd:integer { minInclusive = "0" }, # R
  • binaries/data/mods/public/art/terrains/terrain_texture.rng

     
    3434            <attribute name="groups"/>
    3535          </optional>
    3636          <optional>
     37            <attribute name="classes"/>
     38          </optional>
     39          <optional>
    3740            <!-- comma-separated list of groups -->
    3841            <attribute name="mmap">
    3942              <list>
  • binaries/data/mods/public/simulation/components/BuildRestrictions.js

     
    314314        }
    315315    }
    316316
     317    var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain);
     318    if (cmpTerrain.GetTerrainClasses(pos.x, pos.y).indexOf("test1") != -1)
     319    {
     320        result.message = "Get a terrain bonus here";
     321        result.success = true;
     322        result.bonus = 0.4;
     323    }
    317324    // Success
    318325    result.success = true;
    319326    result.message = "";
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    10411041
    10421042            if (!result.success)
    10431043                cmpVisual.SetShadingColor(1.4, 0.4, 0.4, 1);
     1044            else if (result.bonus)
     1045                cmpVisual.SetShadingColor(1 - result.bonus, 1 + result.bonus, 1, 1);
    10441046            else
    10451047                cmpVisual.SetShadingColor(1, 1, 1, 1);
    10461048        }
  • source/graphics/Terrain.cpp

     
    112112    return "default";
    113113}
    114114
     115std::vector<std::string> CTerrain::GetClasses(fixed x, fixed z) const
     116{
     117    const ssize_t i = clamp((ssize_t)(x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2);
     118    const ssize_t j = clamp((ssize_t)(z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2);
     119    CMiniPatch* tile = GetTile(i, j);
     120    if (tile && tile->GetTextureEntry())
     121        return tile->GetTextureEntry()->GetProperties().GetClasses();
     122    return std::vector<std::string>();
     123}
     124
    115125///////////////////////////////////////////////////////////////////////////////
    116126// CalcPosition: calculate the world space position of the vertex at (i,j)
    117127// If i,j is off the map, it acts as if the edges of the terrain are extended
  • source/graphics/Terrain.h

     
    8181
    8282    CStr8 GetMovementClass(ssize_t i, ssize_t j) const;
    8383
     84    std::vector<std::string> GetClasses(fixed x, fixed z) const;
     85
    8486    float GetVertexGroundLevel(ssize_t i, ssize_t j) const;
    8587    fixed GetVertexGroundLevelFixed(ssize_t i, ssize_t j) const;
    8688    float GetExactGroundLevel(float x, float z) const;
  • source/graphics/TerrainProperties.cpp

     
    9696    // Terrain Attribs
    9797    ATTR(mmap);
    9898    ATTR(groups);
     99    ATTR(classes);
    99100    ATTR(movementclass);
    100101    ATTR(angle);
    101102    ATTR(size);
     
    115116            for(tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
    116117                m_Groups.push_back(g_TexMan.FindGroup(*it));
    117118        }
     119        else if (attr.Name == attr_classes)
     120        {
     121            // Parse a comma-separated list of groups, add the new entry to
     122            // each of them
     123            m_Classes.clear();
     124            boost::char_separator<char> sep(", ");
     125            typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
     126            tokenizer tok(attr.Value, sep);
     127            for (const CStr& cl : tok)
     128                m_Classes.push_back(cl);
     129        }
    118130        else if (attr.Name == attr_mmap)
    119131        {
    120132            CColor col;
  • source/graphics/TerrainProperties.h

     
    6666    // All terrain type groups we're a member of
    6767    GroupVector m_Groups;
    6868
     69    // Classes of this terrain
     70    std::vector<std::string> m_Classes;
     71
    6972public:
    7073    CTerrainProperties(CTerrainPropertiesPtr parent);
    7174
     
    112115    {
    113116        return m_Groups;
    114117    }
     118
     119    std::vector<std::string> GetClasses() const
     120    {
     121        return m_Classes;
     122    }
    115123};
    116124
    117125#endif
  • source/simulation2/components/CCmpTerrain.cpp

     
    109109        return (u16)vertices;
    110110    }
    111111
     112    virtual std::vector<std::string> GetTerrainClasses(entity_pos_t x, entity_pos_t z)
     113    {
     114        return m_Terrain->GetClasses(x, z);
     115    }
     116
    112117    virtual CTerrain* GetCTerrain()
    113118    {
    114119        return m_Terrain;
  • source/simulation2/components/ICmpTerrain.cpp

     
    2424BEGIN_INTERFACE_WRAPPER(Terrain)
    2525DEFINE_INTERFACE_METHOD_2("GetGroundLevel", entity_pos_t, ICmpTerrain, GetGroundLevel, entity_pos_t, entity_pos_t)
    2626DEFINE_INTERFACE_METHOD_2("CalcNormal", CFixedVector3D, ICmpTerrain, CalcNormal, entity_pos_t, entity_pos_t)
     27DEFINE_INTERFACE_METHOD_2("GetTerrainClasses", std::vector<std::string>, ICmpTerrain, GetTerrainClasses, entity_pos_t, entity_pos_t)
    2728DEFINE_INTERFACE_METHOD_0("GetTilesPerSide", u16, ICmpTerrain, GetTilesPerSide)
    2829END_INTERFACE_WRAPPER(Terrain)
  • source/simulation2/components/ICmpTerrain.h

     
    4041
    4142    virtual float GetExactGroundLevel(float x, float z) = 0;
    4243
     44    virtual std::vector<std::string> GetTerrainClasses(entity_pos_t x, entity_pos_t z) = 0;
     45
    4346    /**
    4447     * Returns number of tiles per side on the terrain.
    4548     * Return value is always non-zero.
  • source/simulation2/system/ComponentTest.h

     
    207207        return 50.f;
    208208    }
    209209
     210    virtual std::vector<std::string> GetTerrainClasses(entity_pos_t UNUSED(x), entity_pos_t UNUSED(z))
     211    {
     212        return std::vector<std::string>();
     213    }
     214
    210215    virtual u16 GetTilesPerSide()
    211216    {
    212217        return 16;