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


Ignore:
Timestamp:
08/11/11 01:57:54 (13 years ago)
Author:
ben
Message:

Fixes incorrect distance calculation.
Improves dock foundation snapping.

Location:
ps/trunk/binaries/data/mods/public
Files:
3 edited

Legend:

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

    r9970 r9991  
    563563                "z": placementPosition.z
    564564            });
    565             if (snapData.snapped)
     565            if (snapData)
    566566                placementAngle = snapData.angle;
    567567           
     
    825825                "z": placementPosition.z
    826826            });
    827             if (snapData.snapped)
     827            if (snapData)
    828828                placementAngle = snapData.angle;
    829829           
  • ps/trunk/binaries/data/mods/public/simulation/components/BuildRestrictions.js

    r9970 r9991  
    140140    if (this.template.Category == "Dock")
    141141    {
    142         // Dock must be oriented from land facing into water
     142        // TODO: Probably should check unit passability classes here, to determine if:
     143        //      1. ships can be spawned "nearby"
     144        //      2. builders can pass the terrain where the dock is placed (don't worry about paths)
     145        //  so it's correct even if the criteria changes for these units
    143146        var cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint);
    144147        if (!cmpFootprint)
     
    158161            halfSize = shape.radius;
    159162        }
    160 
     163       
    161164        var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain);
    162165        var cmpWaterManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_WaterManager);
     
    169172        var sz = halfSize * Math.sin(ang);
    170173        var cz = halfSize * Math.cos(ang);
    171         if ((cmpTerrain.GetGroundLevel(pos.x + sz, pos.y + cz) > cmpWaterManager.GetWaterLevel(pos.x + sz, pos.y + cz)) || // front
    172             (cmpTerrain.GetGroundLevel(pos.x - sz, pos.y - cz) <= cmpWaterManager.GetWaterLevel(pos.x - sz, pos.y - cz)))   // back
     174        if ((cmpWaterManager.GetWaterLevel(pos.x + sz, pos.y + cz) - cmpTerrain.GetGroundLevel(pos.x + sz, pos.y + cz)) < 1.0 // front
     175            || (cmpWaterManager.GetWaterLevel(pos.x - sz, pos.y - cz) - cmpTerrain.GetGroundLevel(pos.x - sz, pos.y - cz)) > 2.0)   // back
    173176        {
    174177            return false;   // Fail
     
    179182    if (this.template.Distance)
    180183    {
    181         var minDist = 65535;
    182         var maxDist = 0;
     184        var nearest = 65535;
    183185        var ents = Engine.GetEntitiesWithInterface(IID_BuildRestrictions);
    184186        for each (var ent in ents)
     
    186188            var cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions);
    187189            if (cmpBuildRestrictions.GetCategory() == this.template.Distance.FromCategory && IsOwnedByPlayer(player, ent))
    188             {
     190            {   // Find nearest building matching this category
    189191                var cmpEntPosition = Engine.QueryInterface(ent, IID_Position);
    190192                if (cmpEntPosition && cmpEntPosition.IsInWorld())
     
    192194                    var entPos = cmpEntPosition.GetPosition2D();
    193195                    var dist = Math.sqrt((pos.x-entPos.x)*(pos.x-entPos.x) + (pos.y-entPos.y)*(pos.y-entPos.y));
    194                     if (dist < minDist)
     196                    if (dist < nearest)
    195197                    {
    196                         minDist = dist;
    197                     }
    198                     if (dist > maxDist)
    199                     {
    200                         maxDist = dist;
     198                        nearest = dist;
    201199                    }
    202200                }
     
    204202        }
    205203       
    206         if (this.template.Distance.MinDistance !== undefined && minDist < this.template.Distance.MinDistance
    207             || this.template.Distance.MaxDistance !== undefined && maxDist > this.template.Distance.MaxDistance)
     204        if ((this.template.Distance.MinDistance && nearest < this.template.Distance.MinDistance)
     205            || (this.template.Distance.MaxDistance && nearest > this.template.Distance.MaxDistance))
    208206        {
    209207            return false;   // Fail
  • ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js

    r9970 r9991  
    510510        var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain);
    511511        var cmpWaterManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_WaterManager);
     512        if (!cmpTerrain || !cmpWaterManager)
     513        {
     514            return false;
     515        }
     516       
     517        // Get footprint size
     518        var halfSize = 0;
     519        if (template.Footprint.Square)
     520        {
     521            halfSize = Math.max(template.Footprint.Square["@depth"], template.Footprint.Square["@width"])/2;
     522        }
     523        else if (template.Footprint.Circle)
     524        {
     525            halfSize = template.Footprint.Circle["@radius"];
     526        }
    512527       
    513528        // Find direction of most open water, algorithm:
     
    518533        //  5. Calculate angle using average of sequence
    519534        const numPoints = 16;
    520         const dist = 20.0;
    521535        var waterPoints = [];
    522536        for (var i = 0; i < numPoints; ++i)
    523537        {
    524538            var angle = (i/numPoints)*2*Math.PI;
    525             var nx = data.x - dist*Math.sin(angle);
    526             var nz = data.z + dist*Math.cos(angle);
     539            var nx = data.x - halfSize*Math.sin(angle);
     540            var nz = data.z + halfSize*Math.cos(angle);
    527541           
    528542            if (cmpTerrain.GetGroundLevel(nx, nz) < cmpWaterManager.GetWaterLevel(nx, nz))
     
    560574        }
    561575
    562         return { "snapped": true, "x": data.x, "z": data.z, "angle": -(((waterPoints[start] + consec[start]/2) % numPoints)/numPoints*2*Math.PI) };
    563     }
    564 
    565     return {"snapped": false};
     576        return {"x": data.x, "z": data.z, "angle": -(((waterPoints[start] + consec[start]/2) % numPoints)/numPoints*2*Math.PI) };
     577    }
     578
     579    return false;
    566580};
    567581
Note: See TracChangeset for help on using the changeset viewer.