Exemplo n.º 1
0
        public override bool OpenNearbyClosedPassages()
        {
            Vector3 v3 = GetSimPosition();
            byte    b  = PathStore.GetNodeQuality(v3, MoverPlaneZ);

            if (b < 200)
            {
                b += 100;
            }
            if (b > 254)
            {
                b = 254;
            }
            CollisionPlane MoverPlane = MoverPlaneZ;

            PathStore.SetNodeQuality(v3, b, MoverPlane);
            bool changed = base.OpenNearbyClosedPassages();

            if (changed)
            {
                MoverPlane.HeightMapNeedsUpdate = true;
                MoverPlane.MatrixNeedsUpdate    = true;
            }
            return(changed);
        }
 public float GetGroundLevel()
 {
     if (_GroundLevelCache > 0)
     {
         return(_GroundLevelCache);
     }
     _GroundLevelCache = PathStore.GetGroundLevel(_LocalPos.X, _LocalPos.Y);
     return(_GroundLevelCache);
 }
Exemplo n.º 3
0
        private void SeedPathStore(BreadingBreadDbContext context)
        {
            var pathStores = new PathStore[]
            {
                new PathStore
                {
                    IdPath  = 1,
                    IdStore = 1
                },
                new PathStore
                {
                    IdPath  = 1,
                    IdStore = 2
                },
                new PathStore
                {
                    IdPath  = 1,
                    IdStore = 3
                },
                new PathStore
                {
                    IdPath  = 1,
                    IdStore = 4
                },
                new PathStore
                {
                    IdPath  = 1,
                    IdStore = 5
                },
                new PathStore
                {
                    IdPath  = 2,
                    IdStore = 1
                },
                new PathStore
                {
                    IdPath  = 2,
                    IdStore = 2
                },
                new PathStore
                {
                    IdPath  = 3,
                    IdStore = 1
                },
            };

            foreach (var pathStore in pathStores)
            {
                context.PathStore.Add(pathStore);
                context.SaveChanges();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Make sure this the non-simplfied route
        /// </summary>
        /// <param name="route"></param>
        private void DepricateRoute(IEnumerable <Vector3d> route, double finalDist)
        {
            List <Vector3d>    reallyDepricate = new List <Vector3d>();
            List <ThreadStart> listUndo        = new List <ThreadStart>();
            const int          time            = 120;
            Vector3d           first           = default(Vector3d);

            foreach (Vector3d list in route)
            {
                if (first == default(Vector3d))
                {
                    first = list;
                    continue;
                }
                if (Vector3d.Distance(first, list) > finalDist)
                {
                    break;
                }
                reallyDepricate.Add(list);
            }
            Mover.IndicateRoute(reallyDepricate, Color.Orchid);
            foreach (Vector3d list in reallyDepricate)
            {
                PathStore.BlockPointTemp(SimPathStore.GlobalToLocal(list), listUndo, SimPathStore.BLOCKED);
            }

            if (listUndo.Count == 0)
            {
                return;
            }
            string tmp = string.Format("Blocking {0} points for {1} seconds", listUndo.Count, time);
            Thread thr = new Thread(() =>
            {
                Debug(tmp);
                Thread.Sleep(time * 1000);
                Debug("Un-{0}", tmp);
                foreach (ThreadStart undo in listUndo)
                {
                    undo();
                }
            })
            {
                Name = tmp
            };

            thr.Start();
        }
Exemplo n.º 5
0
        protected string PrivateGetFilename(string defaultExt, string filter, List <string> prefixes, string defaultName, bool autoSet, bool fileMustExist)
        {
            if (prefixes.Count == 0)
            {
                prefixes.Add(null);
            }

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.DefaultExt       = defaultExt;
            dialog.Filter           = filter;
            dialog.FilterIndex      = 1;
            dialog.InitialDirectory = PathStore.GetPath(MainForm.PackageName, dialog.DefaultExt);
            dialog.CheckFileExists  = fileMustExist;
            dialog.CheckPathExists  = true;

            string oldPath = dialog.InitialDirectory;

            string filename = null;

            foreach (string prefix in prefixes)
            {
                string name = defaultName;

                string path = oldPath;
                if (!string.IsNullOrEmpty(prefix))
                {
                    name = name.Replace(prefixes[0], prefix);

                    path += "\\" + prefix;
                }

                if (!Directory.Exists(path))
                {
                    path = oldPath;
                }
                else if (prefix == prefixes[0])
                {
                    dialog.InitialDirectory = path;
                }

                filename = path + "\\" + name;
                if (File.Exists(filename))
                {
                    break;
                }

                filename = null;
            }

            if ((filename == null) || (!autoSet))
            {
                dialog.FileName = defaultName;

                if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return(null);
                }

                filename = dialog.FileName;

                string directory = Path.GetDirectoryName(filename);

                foreach (string prefix in prefixes)
                {
                    if (prefix == null)
                    {
                        continue;
                    }

                    if (directory.Contains("\\" + prefix))
                    {
                        directory = directory.Replace("\\" + prefix, "");
                        break;
                    }
                }

                PathStore.SetPath(MainForm.PackageName, dialog.DefaultExt, directory);
            }

            return(filename);
        }
Exemplo n.º 6
0
        private bool Goto(SimPosition globalEnd, double distance)
        {
            bool OnlyStart = true;
            bool MadeIt    = true;

            int maxTryAgains            = 0;
            IList <Vector3d> route      = null;
            CollisionPlane   MoverPlane = MoverPlaneZ;
            bool             faked;
            bool             changePlanes = false;

            while (OnlyStart && MadeIt)
            {
                float    InitZ = Mover.SimPosition.Z;
                Vector3d v3d   = GetWorldPosition();
                if (Mover.Distance(FinalPosition) < distance)
                {
                    return(true);
                }
                float G = MoverPlane.GlobalBumpConstraint;
                if (G < 1f)
                {
                    Orig = G;
                }
                SimMoverState prev = STATE;
                STATE = SimMoverState.THINKING;
                route = SimPathStore.GetPath(MoverPlane, v3d, globalEnd.UsePosition.GlobalPosition, distance, out OnlyStart, out faked);
                // todo need to look at OnlyStart?
                PreXp = route.Count < 3 && G < MaxBigZ;
                while (route.Count < 3 && G < MaxBigZ && faked)
                {
                    if (G < 0.5)
                    {
                        G += 0.1f;
                    }
                    else
                    {
                        G += 0.5f;
                        if (Works > G)
                        {
                            G = Works;
                        }
                    }

                    MoverPlane.GlobalBumpConstraint = G;
                    route = SimPathStore.GetPath(MoverPlane, v3d, globalEnd.UsePosition.GlobalPosition, distance, out OnlyStart, out faked);
                }
                if (PreXp)
                {
                    Works = G;
                    UsedBigZ++;
                    Debug("BigG used {0} instead of {1} !!", G, Orig);
                    OnlyStart = true;
                }
                else
                {  // not PreXP
                    if (UsedBigZ > 0)
                    {
                        if (Works > 0.7f)
                        {
                            Works -= 0.5f;                // todo not as liberal the next time?
                        }
                        UsedBigZ = 0;
                        Debug("BigG RESTORE {0} instead of {1} !!", Orig, MoverPlane.GlobalBumpConstraint);
                        MoverPlane.GlobalBumpConstraint = Orig;
                    }
                }
                STATE = prev;
                STATE = FollowPathTo(route, globalEnd.UsePosition.GlobalPosition, distance);
                Vector3 newPos = GetSimPosition();
                switch (STATE)
                {
                case SimMoverState.TRYAGAIN:
                {
                    if (maxTryAgains-- > 0)
                    {
                        OnlyStart = true;
                        continue;
                    }
                    MadeIt = false;
                    continue;
                }

                case SimMoverState.COMPLETE:
                {
                    MadeIt = true;
                    continue;
                }

                case SimMoverState.BLOCKED:
                {
                    float globalEndUsePositionGlobalPositionZ = (float)globalEnd.UsePosition.GlobalPosition.Z;
                    if (faked)
                    {
                        if (Math.Abs(Mover.SimPosition.Z - InitZ) > 1)
                        {
                            MoverPlane = MoverPlanes[Mover] = PathStore.GetCollisionPlane(Mover.SimPosition.Z);
                        }
                        else
                        {
                            MoverPlane = MoverPlanes[Mover] = PathStore.GetCollisionPlane(globalEndUsePositionGlobalPositionZ);
                        }
                    }
                    OnlyStart = true;
                    MadeIt    = false;
                    continue;
                }

                case SimMoverState.PAUSED:
                case SimMoverState.MOVING:
                case SimMoverState.THINKING:
                default:
                {
                    //MadeIt = true;
                    OnlyStart = true;
                    continue;
                }
                }
            }
            if (!MadeIt && route != null)
            {
                SimMoverState prev = STATE;
                STATE = SimMoverState.THINKING;
                CollisionPlane CP = MoverPlane;
                if (CP.HeightMapNeedsUpdate)
                {
                    CP.MatrixNeedsUpdate = true;
                }
                if (!CP.MatrixNeedsUpdate || !CP.HeightMapNeedsUpdate)
                {
                    if (false)
                    {
                        CP.MatrixNeedsUpdate    = true;
                        CP.HeightMapNeedsUpdate = true;
                        Debug("Faking matrix needs update?");
                    }
                }
                else
                {
                    Debug("Matrix really needed update");
                }
                Vector3d v3d = GetWorldPosition();
                double   fd  = DistanceNoZ(v3d, globalEnd.GlobalPosition);
                if (fd < distance)
                {
                    STATE = SimMoverState.COMPLETE;
                    return(true);
                }
                CP.EnsureUpdated();
                int index = ClosetPointOnRoute(route, v3d);
                if (index > 0)
                {
                    var blockMe = new List <Vector3d>();
                    if (index + 2 < route.Count)
                    {
                        Vector3d firstBad = route[index + 1];
                        var      np       = v3d + ((firstBad - v3d) / 2);
                        blockMe.Add(np);
                        blockMe.Add(firstBad);
                        DepricateRoute(blockMe, fd);
                        STATE = prev;
                        return(MadeIt);
                    }
                }

                if (fd > distance && fd > 2)
                {
                    if (false)
                    {
                        DepricateRoute(route, fd);
                    }
                }
                Debug("Too far away " + fd + " wanted " + distance);
                STATE = prev;
            }
            return(MadeIt);
        }
 private CollisionPlane CollisionPlaneAt(float z)
 {
     return(PathStore.GetCollisionPlane(z));
 }