예제 #1
0
파일: Region.cs 프로젝트: Basilid/Spheres
 /// <summary>
 /// Добавить смежный регион с взвешенным переходом
 /// </summary>
 /// <param name="reg">Регион</param>
 /// <param name="dist">Расcтояние</param>
 /// <param name="bandwidth">Пропускная способность</param>
 public void AddNeighbor(Region reg, double dist = 1, double bandwidth = 1)
 {
     var nei = Neighbors.FirstOrDefault(s => s.Region == reg);
     if (nei == null)
         Neighbors.Add(new Duct(reg, dist, bandwidth));
     else
         nei.Distance = dist;
 }
예제 #2
0
        void ActivateRegion()
        {
            //stop listen activationRegion
            if( activationRegion != null )
            {
                activationRegion.ObjectIn -= ActivationRegion_ObjectIn;
                activationRegion = null;
            }

            ActivateWayMovement();
        }
예제 #3
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary>
        protected override void OnPostCreate( bool loaded )
        {
            base.OnPostCreate( loaded );
            AddTimer();

            //get activationRegion
            TankGameExtendedProperties extendedProperties =
                ControlledObject.ExtendedProperties as TankGameExtendedProperties;
            if( extendedProperties != null )
                activationRegion = extendedProperties.ActivationRegion;

            //listen activationRegion
            if( activationRegion != null )
                activationRegion.ObjectIn += ActivationRegion_ObjectIn;
        }
예제 #4
0
 protected override void OnDestroy()
 {
     //stop listen activationRegion
     if( activationRegion != null )
     {
         activationRegion.ObjectIn -= ActivationRegion_ObjectIn;
         activationRegion = null;
     }
     base.OnDestroy();
 }
예제 #5
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary>
        protected override void OnPostCreate(bool loaded)
        {
            base.OnPostCreate(loaded);
            SubscribeToTickEvent();//AddTimer();

            //get activationRegion
            //TankGameExtendedProperties extendedProperties =
            //    ControlledObject.ExtendedProperties as TankGameExtendedProperties;
            //get activationRegion
            EntityComponent_ForTankDemo component = (EntityComponent_ForTankDemo)
                ControlledObject.Component_GetFirstWithType(typeof(EntityComponent_ForTankDemo));
            //if (extendedProperties != null)
            //    activationRegion = extendedProperties.ActivationRegion;
            if (component != null)
                activationRegion = component.ActivationRegion;

            //listen activationRegion
            if (activationRegion != null)
                activationRegion.ObjectIn += ActivationRegion_ObjectIn;

            if (this.RandomizeSkill == true)
                this.SkillLevel = (MechSkillLevel)(World.Instance.Random.NextFloat() * 5);

            //Unit_Ai_Skill_Label();

            FindUnitWeapons();
        }
예제 #6
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary>
        protected override void OnPostCreate( bool loaded )
        {
            base.OnPostCreate( loaded );
            SubscribeToTickEvent();

            //get activationRegion
            EntityComponent_ForTankDemo component = (EntityComponent_ForTankDemo)
                ControlledObject.Component_GetFirstWithType( typeof( EntityComponent_ForTankDemo ) );
            if( component != null )
                activationRegion = component.ActivationRegion;

            //listen activationRegion
            if( activationRegion != null )
                activationRegion.ObjectIn += ActivationRegion_ObjectIn;
        }
예제 #7
0
파일: Map.cs 프로젝트: Basilid/Spheres
 public static IEnumerable<Region> FindPath(Region start, Region finish)
 {
     if (start == null) throw new ArgumentNullException("start");
     if (finish == null) throw new ArgumentNullException("finish");
     var curNum = ++Region.NumPath;
     var dist = 0d;
     var minDist = double.MaxValue;
     HashSet<Region> curPath = new HashSet<Region>(), wave;
     var res = new Stack<Region>();
     start.CurrentPath = curNum;
     finish.DistFromStart = double.MaxValue;
     start.DistFromStart = 0;
     curPath.Add(start);
     while (curPath.Count > 0)
     {
         if (curPath.Contains(finish))
             minDist = finish.DistFromStart;
         wave = new HashSet<Region>();
         foreach (var old in curPath)
             foreach (var duct in old.Neighbors)
             {
                 dist = old.DistFromStart + duct.Distance;
                 if (dist < minDist)
                     if (duct.Region.CurrentPath == curNum)
                     {
                         if (dist < duct.Region.DistFromStart)
                         {
                             wave.Add(duct.Region);
                             duct.Region.DistFromStart = dist;
                         }
                     }
                     else
                     {
                         wave.Add(duct.Region);
                         duct.Region.CurrentPath = curNum;
                         duct.Region.DistFromStart = dist;
                     }
                 if (duct.Region == finish)
                     minDist = finish.DistFromStart;
             }
         curPath = wave;
     }
     if (finish.DistFromStart < double.MaxValue)
     {
         Region penult = finish, reg = null;
         res.Push(penult);
         while (penult != start)
         {
             dist = penult.DistFromStart;
             foreach (var duct in penult.Neighbors
                 .Where(s => s.Region.CurrentPath == curNum)
                 .Where(s => s.Region.DistFromStart + s.Distance <= dist))
             {
                 dist = duct.Region.DistFromStart + duct.Distance;
                 reg = duct.Region;
             }
             penult = reg;
             res.Push(penult);
         }
         return res;
     }
     return new Region[0];
 }
예제 #8
0
파일: Region.cs 프로젝트: Basilid/Spheres
 /// <summary>
 /// Добавить смежный регион с равновесным переходом
 /// </summary>
 /// <param name="reg"></param>
 /// <param name="dist"></param>
 public void AddSymetricNeighbor(Region reg, double dist = 1)
 {
     AddNeighbor(reg, dist);
     reg.AddNeighbor(this, dist);
 }