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


Ignore:
Timestamp:
08/15/11 01:36:13 (13 years ago)
Author:
ben
Message:

Changes shore definition to distance on land (all water included) for better dock placement.
Updates build passability classes.
Fixes tile expansion in CheckBuildingPlacement (don't use FromFloat).
Changes dock rotation snapping to search outward.

Location:
ps/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/gui/session/input.js

    r9991 r10007  
    564564            });
    565565            if (snapData)
     566            {
    566567                placementAngle = snapData.angle;
     568                placementPosition.x = snapData.x;
     569                placementPosition.z = snapData.z;
     570            }
    567571           
    568572            updateBuildingPlacementPreview();
     
    826830            });
    827831            if (snapData)
     832            {
    828833                placementAngle = snapData.angle;
     834                placementPosition.x = snapData.x;
     835                placementPosition.z = snapData.z;
     836            }
    829837           
    830838            updateBuildingPlacementPreview();
  • ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js

    r9991 r10007  
    526526        }
    527527       
    528         // Find direction of most open water, algorithm:
    529         //  1. Pick points in a circle around dock
    530         //  2. If point is in water, add to array
    531         //  3. Scan array looking for consective points
    532         //  4. Find longest sequence of conseuctive points
    533         //  5. Calculate angle using average of sequence
     528        /* Find direction of most open water, algorithm:
     529         *  1. Pick points in a circle around dock
     530         *  2. If point is in water, add to array
     531         *  3. Scan array looking for consective points
     532         *  4. Find longest sequence of conseuctive points
     533         *  5. If sequence equals all points, no direction can be determined,
     534         *      expand search outward and try (1) again
     535         *  6. Calculate angle using average of sequence
     536         */
    534537        const numPoints = 16;
    535         var waterPoints = [];
    536         for (var i = 0; i < numPoints; ++i)
    537         {
    538             var angle = (i/numPoints)*2*Math.PI;
    539             var nx = data.x - halfSize*Math.sin(angle);
    540             var nz = data.z + halfSize*Math.cos(angle);
    541            
    542             if (cmpTerrain.GetGroundLevel(nx, nz) < cmpWaterManager.GetWaterLevel(nx, nz))
     538        for (var dist = 0; dist < 4; ++dist)
     539        {
     540            var waterPoints = [];
     541            for (var i = 0; i < numPoints; ++i)
    543542            {
    544                 waterPoints.push(i);
    545             }
    546         }
    547         var consec = [];
    548         var length = waterPoints.length;
    549         for (var i = 0; i < length; ++i)
    550         {
    551             var count = 0;
    552             for (var j = 0; j < (length-1); ++j)
    553             {
    554                 if (((waterPoints[(i + j) % length]+1) % numPoints) == waterPoints[(i + j + 1) % length])
     543                var angle = (i/numPoints)*2*Math.PI;
     544                var d = halfSize*(dist+1);
     545                var nx = data.x - d*Math.sin(angle);
     546                var nz = data.z + d*Math.cos(angle);
     547               
     548                if (cmpTerrain.GetGroundLevel(nx, nz) < cmpWaterManager.GetWaterLevel(nx, nz))
    555549                {
    556                     ++count;
    557                 }
    558                 else
    559                 {
    560                     break;
     550                    waterPoints.push(i);
    561551                }
    562552            }
    563             consec[i] = count;
    564         }
    565         var start = 0;
    566         var count = 0;
    567         for (var c in consec)
    568         {
    569             if (consec[c] > count)
     553            var consec = [];
     554            var length = waterPoints.length;
     555            for (var i = 0; i < length; ++i)
    570556            {
    571                 start = c;
    572                 count = consec[c];
     557                var count = 0;
     558                for (var j = 0; j < (length-1); ++j)
     559                {
     560                    if (((waterPoints[(i + j) % length]+1) % numPoints) == waterPoints[(i + j + 1) % length])
     561                    {
     562                        ++count;
     563                    }
     564                    else
     565                    {
     566                        break;
     567                    }
     568                }
     569                consec[i] = count;
    573570            }
    574         }
    575 
    576         return {"x": data.x, "z": data.z, "angle": -(((waterPoints[start] + consec[start]/2) % numPoints)/numPoints*2*Math.PI) };
     571            var start = 0;
     572            var count = 0;
     573            for (var c in consec)
     574            {
     575                if (consec[c] > count)
     576                {
     577                    start = c;
     578                    count = consec[c];
     579                }
     580            }
     581           
     582            // If we've found a shoreline, stop searching
     583            if (count != numPoints-1)
     584            {
     585                return {"x": data.x, "z": data.z, "angle": -(((waterPoints[start] + consec[start]/2) % numPoints)/numPoints*2*Math.PI)};
     586            }
     587        }
    577588    }
    578589
  • ps/trunk/binaries/data/mods/public/simulation/data/pathfinder.xml

    r9970 r10007  
    2424    <building-land>
    2525      <MaxWaterDepth>0</MaxWaterDepth>
    26       <MinShoreDistance>2.0</MinShoreDistance>
     26      <MinShoreDistance>1.0</MinShoreDistance>
    2727      <MaxTerrainSlope>1.0</MaxTerrainSlope>
    2828    </building-land>
    2929    <building-shore>
    30       <MaxShoreDistance>3.0</MaxShoreDistance>
    31       <MaxTerrainSlope>1.5</MaxTerrainSlope>
     30      <MaxShoreDistance>2.0</MaxShoreDistance>
     31      <MaxTerrainSlope>1.25</MaxTerrainSlope>
    3232    </building-shore>
    3333
  • ps/trunk/source/simulation2/components/CCmpPathfinder.cpp

    r9970 r10007  
    400400            {
    401401                // Find a land tile
    402                 if (!waterGrid.get(i, j) && (
    403                     (i > 0 && waterGrid.get(i-1, j)) || (i > 0 && j < m_MapSize-1 && waterGrid.get(i-1, j+1)) || (i > 0 && j > 0 && waterGrid.get(i-1, j-1)) ||
    404                     (i < m_MapSize-1 && waterGrid.get(i+1, j)) || (i < m_MapSize-1 && j < m_MapSize-1 && waterGrid.get(i+1, j+1)) || (i < m_MapSize-1 && j > 0 && waterGrid.get(i+1, j-1)) ||
    405                     (j > 0 && waterGrid.get(i, j-1)) || (j < m_MapSize-1 && waterGrid.get(i, j+1))
    406                     ))
     402                if (!waterGrid.get(i, j))
    407403                {
    408                     shoreGrid.set(i, j, 0);
     404                    if ((i > 0 && waterGrid.get(i-1, j)) || (i > 0 && j < m_MapSize-1 && waterGrid.get(i-1, j+1)) || (i > 0 && j > 0 && waterGrid.get(i-1, j-1))
     405                        || (i < m_MapSize-1 && waterGrid.get(i+1, j)) || (i < m_MapSize-1 && j < m_MapSize-1 && waterGrid.get(i+1, j+1)) || (i < m_MapSize-1 && j > 0 && waterGrid.get(i+1, j-1))
     406                        || (j > 0 && waterGrid.get(i, j-1)) || (j < m_MapSize-1 && waterGrid.get(i, j+1))
     407                        )
     408                    {   // If it's bordered by water, it's a shore tile
     409                        shoreGrid.set(i, j, 0);
     410                    }
     411                    else
     412                    {
     413                        shoreGrid.set(i, j, shoreMax);
     414                    }
    409415                }
    410                 else
    411                 {
    412                     shoreGrid.set(i, j, shoreMax);
    413                 }
    414             }
    415         }
    416 
    417         // Expand influences to find shore distance
     416            }
     417        }
     418
     419        // Expand influences on land to find shore distance
    418420        for (size_t y = 0; y < m_MapSize; ++y)
    419421        {
     
    421423            for (size_t x = 0; x < m_MapSize; ++x)
    422424            {
    423                 u16 g = shoreGrid.get(x, y);
    424                 if (g > min)
    425                     shoreGrid.set(x, y, min);
    426                 else if (g < min)
    427                     min = g;
    428 
    429                 ++min;
     425                if (!waterGrid.get(x, y))
     426                {
     427                    u16 g = shoreGrid.get(x, y);
     428                    if (g > min)
     429                        shoreGrid.set(x, y, min);
     430                    else if (g < min)
     431                        min = g;
     432
     433                    ++min;
     434                }
    430435            }
    431436            for (size_t x = m_MapSize; x > 0; --x)
    432437            {
    433                 u16 g = shoreGrid.get(x-1, y);
    434                 if (g > min)
    435                     shoreGrid.set(x-1, y, min);
    436                 else if (g < min)
    437                     min = g;
    438 
    439                 ++min;
     438                if (!waterGrid.get(x-1, y))
     439                {
     440                    u16 g = shoreGrid.get(x-1, y);
     441                    if (g > min)
     442                        shoreGrid.set(x-1, y, min);
     443                    else if (g < min)
     444                        min = g;
     445
     446                    ++min;
     447                }
    440448            }
    441449        }
     
    445453            for (size_t y = 0; y < m_MapSize; ++y)
    446454            {
    447                 u16 g = shoreGrid.get(x, y);
    448                 if (g > min)
    449                     shoreGrid.set(x, y, min);
    450                 else if (g < min)
    451                     min = g;
    452 
    453                 ++min;
     455                if (!waterGrid.get(x, y))
     456                {
     457                    u16 g = shoreGrid.get(x, y);
     458                    if (g > min)
     459                        shoreGrid.set(x, y, min);
     460                    else if (g < min)
     461                        min = g;
     462
     463                    ++min;
     464                }
    454465            }
    455466            for (size_t y = m_MapSize; y > 0; --y)
    456467            {
    457                 u16 g = shoreGrid.get(x, y-1);
    458                 if (g > min)
    459                     shoreGrid.set(x, y-1, min);
    460                 else if (g < min)
    461                     min = g;
    462 
    463                 ++min;
     468                if (!waterGrid.get(x, y-1))
     469                {
     470                    u16 g = shoreGrid.get(x, y-1);
     471                    if (g > min)
     472                        shoreGrid.set(x, y-1, min);
     473                    else if (g < min)
     474                        min = g;
     475
     476                    ++min;
     477                }
    464478            }
    465479        }
     
    699713        return false;
    700714
    701     CFixedVector2D halfSize(square.hw, square.hh);
    702     halfSize = halfSize * 1.41421f;
     715    // Expand bounds by 1/sqrt(2) tile (multiply by CELL_SIZE since we want world coordinates)
     716    entity_pos_t expand = entity_pos_t::FromInt(2).Sqrt().Multiply(entity_pos_t::FromInt(CELL_SIZE / 2));
     717    CFixedVector2D halfSize(square.hw + expand, square.hh + expand);
    703718    CFixedVector2D halfBound = Geometry::GetHalfBoundingBox(square.u, square.v, halfSize);
    704719
Note: See TracChangeset for help on using the changeset viewer.