/// <summary>
        /// marks the path from origin to destination - only marks short path by astar algorithem
        /// </summary>
        /// <param name="mapPoint">origin</param>
        /// <param name="mpTownAccessPoint">destination</param>
        private void MarkRoadInZone(MapPoint mpOrigin, MapPoint mpDestination, int iRoadIndexNumber, int iZoneIndex)
        {
            //signal i've already been here
            barrAStarVisit[mpOrigin.x, mpOrigin.y] = true;

            //mark point as road
            iarrMap[(int)MapLayer.Terrain, mpOrigin.x, mpOrigin.y] = iRoadIndexNumber;

            //stop condition
            if (!mpOrigin.Equals(mpDestination))
            {
                int       iMinDirectionValue = int.MaxValue;
                ArrayList mparrRoundPoints   = new ArrayList();
                //examine all around blocks and choose a random minimal then go there
                for (int i = 0; i < mpRoundTrip.Length; i++)
                {
                    MapPoint mpDirection      = mpRoundTrip[i];
                    MapPoint mpPointToExamine = mpOrigin + mpDirection;
                    //if its not null that means there's a way in this direction
                    if (IsInsideMapLimit(mpPointToExamine.x, mpPointToExamine.y))
                    {
                        mparrRoundPoints.Add(mpPointToExamine);
                        if (iarrMap[(int)MapLayer.AStarDistance, mpPointToExamine.x, mpPointToExamine.y] != null &&
                            (int)iarrMap[(int)MapLayer.Zones, mpPointToExamine.x, mpPointToExamine.y] == iZoneIndex)
                        {
                            //this is condition to prevent going on the same road again and again and again
                            if (!barrAStarVisit[mpPointToExamine.x, mpPointToExamine.y])
                            {
                                //the minimum will be in the direction we want to go
                                if ((int)iarrMap[(int)MapLayer.AStarDistance, mpPointToExamine.x, mpPointToExamine.y] < iMinDirectionValue)
                                {
                                    iMinDirectionValue = (int)iarrMap[(int)MapLayer.AStarDistance, mpPointToExamine.x, mpPointToExamine.y];
                                }
                            }
                        }
                    }
                }



                for (int i = 0; i < mparrRoundPoints.Count; i++)
                {
                    if (iarrMap[(int)MapLayer.AStarDistance, ((MapPoint)mparrRoundPoints[i]).x, ((MapPoint)mparrRoundPoints[i]).y] != null)
                    {
                        if ((int)iarrMap[(int)MapLayer.AStarDistance, ((MapPoint)mparrRoundPoints[i]).x, ((MapPoint)mparrRoundPoints[i]).y] != iMinDirectionValue ||
                            (int)iarrMap[(int)MapLayer.Zones, ((MapPoint)mparrRoundPoints[i]).x, ((MapPoint)mparrRoundPoints[i]).y] != iZoneIndex)
                        {
                            mparrRoundPoints.RemoveAt(i);
                            i--;
                        }
                    }
                    else
                    {
                        mparrRoundPoints.RemoveAt(i);
                        i--;
                    }
                }


                //out of the minimums any random direction is ok
                //pick some random direction point and continue algorithem
                int iRandomIndex = Randomizer.rnd.Next(mparrRoundPoints.Count);

                if (mparrRoundPoints.Count == 0)
                {
                    return;
                }

                MarkRoadInZone((MapPoint)mparrRoundPoints[iRandomIndex], mpDestination, iRoadIndexNumber, iZoneIndex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// converts an xml node to a map object
        /// pathways was an old idea that currently is not needed
        /// </summary>
        /// <param name="xndMapObject">the xml to convert</param>
        /// <returns>object as a map object</returns>
        public MapObject ConvertXMLNodeToMapObject(XmlNode xndMapObject)
        {
            eObjectType ObjectType = eObjectType.General;

            try
            {
                ObjectType = (eObjectType)Enum.Parse(typeof(eObjectType), xndMapObject.Attributes["Type"].Value);
            }
            catch (Exception)
            {
            }


            string strRotation = ObjectsWriter.strDirections[(int)ObjectDirection.Down];

            try
            {
                strRotation = xndMapObject.Attributes["InitialRotation"].Value;
            }
            catch (Exception)
            {
            }


            bool bShouldBeGuarded = true;

            try
            {
                bShouldBeGuarded = bool.Parse(xndMapObject.Attributes["ShouldBeGuarded"].Value);
            }
            catch (Exception)
            {
            }

            MapPoint mpDummy = new MapPoint(-1, -1);

            MapPoint[] mpArea;
            ArrayList  arrArea;

            string strAreaValues;

            string[] strPointValues;
            //dwp добавлена вероятность
            string strValue, strMaxNumber, strProbability;

            try
            {
                strValue = int.Parse(xndMapObject.Attributes["Value"].Value).ToString();
            }
            catch (Exception)
            {
                strValue = "0";
            }

            try
            {
                strMaxNumber = int.Parse(xndMapObject.Attributes["MaxNumber"].Value).ToString();
            }
            catch (Exception)
            {
                strMaxNumber = "0";
            }

            //dwp добавлена вероятность
            try
            {
                strProbability = double.Parse(xndMapObject.Attributes["Chance"].Value).ToString();
            }
            catch (Exception)
            {
                strProbability = "0";
            }

            try
            {
                strAreaValues  = xndMapObject.Attributes["Area"].Value;
                strPointValues = strAreaValues.Split(';');
                arrArea        = new ArrayList();
            }
            catch (Exception)
            {
                // mpArea = null;
                strPointValues = null;
                arrArea        = null;
            }

            if (strPointValues != null)
            {
                //int iAreaIndex = 0;

                foreach (string strPoint in strPointValues)
                {
                    string[] strarrPoint = strPoint.Split(',');

                    arrArea.Add(new MapPoint(Convert.ToInt32(strarrPoint[0]), Convert.ToInt32(strarrPoint[1])));
                }
            }

            MapPoint[] mpPathWays;

            //convert from arraylist to array
            if (arrArea != null)
            {
                mpArea = new MapPoint[arrArea.Count];

                for (int i = 0; i < arrArea.Count; i++)
                {
                    mpArea[i] = (MapPoint)arrArea[i];
                }
            }
            else
            {
                mpArea = null;
            }


            //convert from arraylist to array
            //if (arraylistPathWays.Count > 0)
            //{
            //    mpPathWays = new MapPoint[arraylistPathWays.Count];

            //    for (int i = 0; i < arraylistPathWays.Count; i++)
            //    {
            //        mpPathWays[i] = (MapPoint)arraylistPathWays[i];
            //    }

            //}
            //else
            //    if (ObjectType != eObjectType.Barrier )
            //        mpPathWays = mpDirections;
            //    else
            mpPathWays = null;


            string strAccessPoint = string.Empty;

            try
            {
                strAccessPoint = xndMapObject.Attributes["AccessPoint"].Value;
            }
            catch
            {
            }

            MapPoint mpAccessPoint = null;

            if (strAccessPoint != string.Empty)
            {
                mpAccessPoint = new MapPoint(int.Parse(strAccessPoint.Split(',')[0]), int.Parse(strAccessPoint.Split(',')[1]));
            }
            else
            {
                mpAccessPoint = new MapPoint(0, -1);
            }

            //dwp добавлена вероятность
            return(new MapObject(mpDummy, mpArea, xndMapObject.Attributes["Name"].Value, ObjectType, mpPathWays, int.Parse(strValue), mpAccessPoint, strRotation, ObjectDirection.Down, bShouldBeGuarded, int.Parse(strMaxNumber), double.Parse(strProbability)));
        }
        /// <summary>
        /// goes over each zone and create roads
        /// </summary>
        /// <param name="iZoneIndex"></param>
        private void CreateRoadsInZone(int iZoneIndex, int iRoadStatus)
        {
            //get road for zone
            int iRoadIndexNumber = GetRoadIndexNumberForZone(iZoneIndex);

            //first check is this zone has a starting town
            if (AccessPoints[iZoneIndex, (int)ePointLayer.StartingTownsPoints].Count == 1)
            {
                MapPoint mpStartingTown = (MapPoint)AccessPoints[iZoneIndex, (int)ePointLayer.StartingTownsPoints][0];
                //first need to set the origin as 0 distance (will be minimum)
                iarrMap[(int)MapLayer.AStarDistance, mpStartingTown.x, mpStartingTown.y] = 0;
                //if so compute a star from this point
                ComputeAStarForRoads(mpStartingTown, 0, iZoneIndex + 1);
#if (DEBUG)
                dumpAStarToFile();
#endif
                //now mark road at terrain layer from the town point to all other points

                //mark from town point to all other town points
                foreach (MapPoint mpTownAccessPoint in AccessPoints[iZoneIndex, (int)ePointLayer.OtherTownsPoints])
                {
                    ReturnSignalArrayDefaults();
                    MarkRoadInZone(mpTownAccessPoint, mpStartingTown, iRoadIndexNumber, iZoneIndex + 1);
                }

                //mark from town to all openings
                foreach (MapPoint mpOpeningPoint in AccessPoints[iZoneIndex, (int)ePointLayer.OpenningPoints])
                {
                    ReturnSignalArrayDefaults();
                    MarkRoadInZone(mpOpeningPoint, mpStartingTown, iRoadIndexNumber, iZoneIndex + 1);
                }


                if (iRoadStatus == (int)eRoadStatus.Roads_To_Towns_And_Mines)
                {
                    //mark from town to all Mines
                    foreach (MapPoint mpMinePoint in AccessPoints[iZoneIndex, (int)ePointLayer.MinePoints])
                    {
                        ReturnSignalArrayDefaults();
                        MarkRoadInZone(mpMinePoint, mpStartingTown, iRoadIndexNumber, iZoneIndex + 1);
                    }
                }
            }
            else//each zone must have an access point
            {
                MapPoint mpOriginPoint = (MapPoint)AccessPoints[iZoneIndex, (int)ePointLayer.OpenningPoints][0];
                //first need to set the origin as 0 distance (will be minimum)
                iarrMap[(int)MapLayer.AStarDistance, mpOriginPoint.x, mpOriginPoint.y] = 0;
                //compute a star from first access point
                ComputeAStarForRoads(mpOriginPoint, 0, iZoneIndex + 1);

                //now mark road at terrain layer from the access point to all other points

                //mark from Access point to all other town points
                foreach (MapPoint mpTownAccessPoint in AccessPoints[iZoneIndex, (int)ePointLayer.OtherTownsPoints])
                {
                    ReturnSignalArrayDefaults();
                    MarkRoadInZone(mpTownAccessPoint, mpOriginPoint, iRoadIndexNumber, iZoneIndex + 1);
                }

                //mark from Access point to all openings
                foreach (MapPoint mpOpeningPoint in AccessPoints[iZoneIndex, (int)ePointLayer.OpenningPoints])
                {
                    ReturnSignalArrayDefaults();
                    if (mpOriginPoint != mpOpeningPoint)
                    {
                        MarkRoadInZone(mpOpeningPoint, mpOriginPoint, iRoadIndexNumber, iZoneIndex + 1);
                    }
                }

                if (iRoadStatus == (int)eRoadStatus.Roads_To_Towns_And_Mines)
                {
                    //mark from town to all Mines
                    foreach (MapPoint mpMinePoint in AccessPoints[iZoneIndex, (int)ePointLayer.MinePoints])
                    {
                        ReturnSignalArrayDefaults();
                        MarkRoadInZone(mpMinePoint, mpOriginPoint, iRoadIndexNumber, iZoneIndex + 1);
                    }
                }
            }
        }
Esempio n. 4
0
 public double Distance(MapPoint mpSource, VoronoiPoint vpDest)
 {
     return(mpSource - vpDest);
 }
Esempio n. 5
0
 //dwp добавлена вероятность
 public MapObject(MapPoint pBasePoint, MapPoint[] pArea, string strObjectName, eObjectType eType, MapPoint[] pPathWays, int iObjectValue, MapPoint mpAccessPoint, string strRotation, ObjectDirection objDir, bool bShouldGuarded, int max_number, double probability)
 {
     PathWays  = pPathWays;
     BasePoint = pBasePoint;
     Area      = pArea;
     strName   = strObjectName;
     ObjectSpacificProperties = new Dictionary <string, string>();
     this.Type            = eType;
     iValue               = iObjectValue;
     AccessPoint          = mpAccessPoint;
     Rotation             = strRotation;
     this.objdirDirection = objDir;
     bShouldBeGuarded     = bShouldGuarded;
     max_number_          = max_number;
     //dwp инициализация вероятности и текущего количества.
     probability_   = probability;
     current_number = 0;
 }
Esempio n. 6
0
 public MapObject(MapPoint pBasePoint, MapPoint[] pArea, string strObjectName, eObjectType eType, MapPoint[] pPathWays, int iObjectValue, MapPoint mpAccessPoint, string strRotation, ObjectDirection objDir, bool bShouldGuarded)
 {
     PathWays  = pPathWays;
     BasePoint = pBasePoint;
     Area      = pArea;
     strName   = strObjectName;
     ObjectSpacificProperties = new Dictionary <string, string>();
     this.Type            = eType;
     iValue               = iObjectValue;
     AccessPoint          = mpAccessPoint;
     Rotation             = strRotation;
     this.objdirDirection = objDir;
     bShouldBeGuarded     = bShouldGuarded;
 }
Esempio n. 7
0
 public MapObject(MapPoint pBasePoint, MapPoint[] pArea, string strObjectName, eObjectType eType, MapPoint[] pPathWays, int iObjectValue, MapPoint mpAccessPoint)
 {
     PathWays  = pPathWays;
     BasePoint = pBasePoint;
     Area      = pArea;
     strName   = strObjectName;
     ObjectSpacificProperties = new Dictionary <string, string>();
     this.Type   = eType;
     iValue      = iObjectValue;
     AccessPoint = mpAccessPoint;
 }