Exemplo n.º 1
0
    private float CalcDistance(VectorLand pos1, VectorLand pos2)
    {
        List <Vector3> brPositions = new List <Vector3>();

        var firstPos = ReturnInZonePos(pos1, pos2, Bridges[0]);
        var secPos   = ReturnInZonePos(pos1, pos2, Bridges[Bridges.Count - 1]);

        float dist = 0;

        for (int i = 0; i < Bridges.Count; i++)
        {
            var pos = Bridges[i].Pos;
            brPositions.Add(pos);

            if (i > 0)
            {
                var prevPos = Bridges[i - 1].Pos;

                dist += Vector3.Distance(prevPos, pos);
            }
        }

        //distance from 1st pos to first bridge
        dist += Vector3.Distance(firstPos, brPositions[0]);

        //distance from pos2 to last brdige
        dist += Vector3.Distance(secPos, brPositions[brPositions.Count - 1]);

        return(dist);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Will Create VectorLand with Building and will added to legs.
    /// </summary>
    /// <param name="pos"></param>
    /// <param name="buildId"></param>
    /// <param name="add">If is false will not added to legs</param>
    /// <returns>The new Vector Land</returns>
    private VectorLand CreateAndAddToLegs(Vector3 pos, string buildId, bool add = true, bool isBridgeLeg = false)
    {
        var build = Brain.GetBuildingFromKey(buildId);

        ////todo
        //is the _fin or _ini being a dummy
        if (build == null && buildId.Contains("Dummy"))
        {
            build = ReturnIniOrFinAsIDPass(buildId);
            Debug.Log("build :" + build.MyId);
            //throw new Exception("Fix");
        }

        //bz the Leg falls insiede the Bridge anchors
        pos = MoveItAwayABitIfBridgeRoad(build, pos, isBridgeLeg);

        VectorLand newVectorLand = new VectorLand();

        newVectorLand = new VectorLand("", pos, build);
        if (add)
        {
            _legs = AddIfsNotContain(_legs, newVectorLand);
        }

        return(newVectorLand);
    }
Exemplo n.º 3
0
 private List <VectorLand> AddIfsNotContain(List <VectorLand> lis, VectorLand newV)
 {
     if (!lis.Contains(newV))
     {
         lis.Add(newV);
     }
     return(lis);
 }
Exemplo n.º 4
0
    /// <summary>
    /// Will return the closest combitnation of bridges to reach from pos1 to pos2
    ///
    /// Before the method will evalute all the posibilities
    /// </summary>
    /// <returns></returns>
    public BridgePsuedoPath ReturnBestPath(VectorLand one, VectorLand two)
    {
        var conn = new Connection(one.LandZone, two.LandZone);

        conn = ReturnOrderedConn(conn);

        var sameEndsLis = FindAllConnWithSameEnds(conn);

        return(ShorterPath(sameEndsLis, one, two));
    }
Exemplo n.º 5
0
    /// <summary>
    /// Will init the individual routes in the ground
    /// </summary>
    private void InitIndividualRoutes()
    {
        for (int i = 0; i < _legs.Count; i += 2)
        {
            VectorLand uno = _legs[i];
            VectorLand dos = _legs[i + 1];

            _myRoutes.Add(new CryRoute(uno, dos, _person));
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Always the one on the land of the 'posVectorLand' will be returned first
    /// </summary>
    public List <Vector3> ReturnTopsBasedOnVectorLand(VectorLand posVectorLand)
    {
        //bz need to get the VectorLand on the Bridge
        posVectorLand = ReturnMyVectorLandOnThatZone(posVectorLand);
        List <Vector3> res = new List <Vector3>();

        var tops = ReturnTwoOrderedByDistance(posVectorLand.Position, H.Top);

        res.AddRange(tops);

        return(res);
    }
Exemplo n.º 7
0
    /// <summary>
    /// Will find the point in the bridge from that zone. ordered from that zone point on brdige
    /// </summary>
    /// <param name="from"></param>
    /// <param name="which"></param>
    /// <returns></returns>
    private List <Vector3> FindPointInBridge(VectorLand from, H which)
    {
        var bridge = FindBridgeOnVectorLand(from);

        if (which == H.Bottom)
        {
            return(bridge.ReturnBottonsBasedOnVectorLand(from));
        }
        else
        {
            return(bridge.ReturnTopsBasedOnVectorLand(from));
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Always the one on the land of the 'posVectorLand' will be returned first
    /// </summary>
    /// <param name="posVectorLand"></param>
    /// <returns></returns>
    public List <Vector3> ReturnBottonsBasedOnVectorLand(VectorLand posVectorLand)
    {
        //bz need to get the VectorLand on the Bridge
        posVectorLand = ReturnMyVectorLandOnThatZone(posVectorLand);
        List <Vector3> res = new List <Vector3>();

        var bots = ReturnTwoOrderedByDistance(posVectorLand.Position, H.Bottom);

        res.Insert(0, bots[0]); //insert 1st one
        res.Add(bots[1]);       //add last

        return(res);
    }
Exemplo n.º 9
0
 /// <summary>
 /// Will find the bridge tht is on that LandZone
 /// </summary>
 /// <param name="land"></param>
 /// <returns></returns>
 private Bridge FindBridgeOnVectorLand(VectorLand land)
 {
     for (int i = 0; i < _bridgePsuedoPath.Bridges.Count; i++)
     {
         var link = _bridgePsuedoPath.Bridges[i];
         //if has 1 with the same leg. then this is the brdige im looking for
         if (link.Has1OfSameType(land.LandZone))
         {
             var key = _bridgePsuedoPath.Bridges[i].BuildMyId;
             return(FromKeyToBridge(key));
         }
     }
     return(null);
 }
Exemplo n.º 10
0
    public BridgePsuedoPath(List <LandZoneLinker> bridges, VectorLand pos1, VectorLand pos2)
    {
        _bridges = bridges;

        //more thn 1 bridge
        if (bridges.Count > 1)
        {
            Distance = CalcDistance(pos1, pos2);
        }
        else if (bridges.Count == 1)
        {
            Distance = CalcDistance(pos1, pos2, bridges[0].Pos);
        }
    }
Exemplo n.º 11
0
    /// <summary>
    /// Because when is more tht 1 brdige I need to know wich VectorLand is the one in land with the bridge
    /// so Distance is calculated properly
    /// </summary>
    /// <param name="pos1"></param>
    /// <param name="pos2"></param>
    /// <param name="bridge"></param>
    /// <returns></returns>
    private Vector3 ReturnInZonePos(VectorLand pos1, VectorLand pos2, LandZoneLinker bridge)
    {
        List <string> temp = new List <string>()
        {
            pos1.LandZone, pos2.LandZone, bridge.Zone1, bridge.Zone2
        };
        var common = UString.ReturnMostCommonName(temp);

        //if the common is the one is pos1.LandZone
        if (pos1.LandZone == common)
        {
            return(pos1.Position);
        }
        return(pos2.Position);
    }
Exemplo n.º 12
0
    public CryBridgeRoute(Structure ini, Structure fin, Person person, string destinyKey, HPers routeType)
    {
        _origenKey  = ini.MyId;
        _destinyKey = destinyKey;
        _person     = person;
        _one        = ini.LandZone1[0];
        _two        = fin.LandZone1[0];

        _ini = ini;
        _fin = fin;

        RouteType = routeType;

        Init();
    }
Exemplo n.º 13
0
 /// <summary>
 /// Will find the VectorLand the bridge has in that zone
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 private VectorLand ReturnMyVectorLandOnThatZone(VectorLand other)
 {
     if (other.LandZone == LandZone1[0].LandZone)
     {
         return(LandZone1[0]);
     }
     else if (other.LandZone == LandZone1[1].LandZone)
     {
         return(LandZone1[1]);
     }
     else
     {
         throw new Exception("Must have always one tht is the same" +
                             " other wise problem on BrideManager.ThereAreMoreNewConnections()");
     }
 }
Exemplo n.º 14
0
    /// <summary>
    /// Will create path for each connection and will return the shorterst
    /// </summary>
    /// <param name="sameEndsLis"></param>
    /// <returns></returns>
    private BridgePsuedoPath ShorterPath(List <Connection> sameEndsLis, VectorLand one, VectorLand two)
    {
        List <BridgePsuedoPath> list = new List <BridgePsuedoPath>();

        for (int i = 0; i < sameEndsLis.Count; i++)
        {
            var conn = sameEndsLis[i];

            list.Add(new BridgePsuedoPath(conn.ThruBridge, one, two));
        }

        list = list.OrderBy(a => a.Distance).ToList();

        if (list.Count == 0)
        {
            return(null);
        }

        return(list[0]);
    }
Exemplo n.º 15
0
    void DefineOneAndTwo(Structure ini, Structure fin)
    {
        if (ini != null && ini.LandZone1.Count > 0)
        {
            _one = ini.LandZone1[0];
        }
        else
        {
            _one = new VectorLand("", ini.transform.position);
        }

        if (fin != null && fin.LandZone1.Count > 0)
        {
            _two = fin.LandZone1[0];
        }
        else
        {
            _two = new VectorLand("", fin.transform.position);
        }
    }
Exemplo n.º 16
0
    public CryRoute(VectorLand uno, VectorLand dos, Person person, bool iniDoor = true, bool finDoor = true,
                    HPers routeType = HPers.None)
    {
        _origenKey  = uno.MyBuild().MyId;
        _destinyKey = dos.MyBuild().MyId;

        _iniDoor = iniDoor;
        _finDoor = finDoor;

        _person = person;
        _one    = uno;
        _two    = dos;

        _ini = uno.MyBuild();
        _fin = dos.MyBuild();

        RouteType = routeType;

        ClearOldVars();
        Init();
    }
Exemplo n.º 17
0
    public CryRoute(Structure ini, Structure fin, Person person, string destinyKey, bool iniDoor = true, bool finDoor = true,
                    HPers routetype = HPers.None)
    {
        _origenKey  = ini.MyId;
        _destinyKey = destinyKey;

        _iniDoor = iniDoor;
        _finDoor = finDoor;

        _person = person;
        _one    = ini.LandZone1[0];
        _two    = fin.LandZone1[0];

        _ini = ini;
        _fin = fin;

        RouteType = routetype;

        ClearOldVars();
        Init();
    }
Exemplo n.º 18
0
 /// <summary>
 /// If is only one bridge
 /// </summary>
 /// <param name="pos1"></param>
 /// <param name="pos2"></param>
 /// <param name="theBridgePos"></param>
 /// <returns></returns>
 private float CalcDistance(VectorLand pos1, VectorLand pos2, Vector3 theBridgePos)
 {
     return(Vector3.Distance(pos1.Position, theBridgePos) + Vector3.Distance(pos2.Position, theBridgePos));
 }