Пример #1
0
        /// <summary>
        /// Gets the remaining distance and next "step" to the destination room
        /// </summary>
        /// <param name="destination">The room you're heading for</param>
        /// <returns>distance (in rooms) and the next path you'd have to use</returns>
        public Tuple <int, IPathway> GetDistanceAndNextStepDestination(ILocation destination)
        {
            int      distance = -1;
            IPathway nextStep = null;

            return(new Tuple <int, IPathway>(distance, nextStep));
        }
Пример #2
0
        static void DrawPathFencesOnMap(TerrainMap map, IPathway path)
        {
            float   xs       = map.XSize / map.Resolution;
            float   zs       = map.ZSize / map.Resolution;
            Vector3 alongRow = new Vector3(xs, 0, 0);
            Vector3 nextRow  = new Vector3(-map.XSize, 0, zs);
            Vector3 g        = new Vector3((map.XSize - xs) / -2, 0, (map.ZSize - zs) / -2);

            for (int j = 0; j < map.Resolution; j++)
            {
                for (int i = 0; i < map.Resolution; i++)
                {
                    float       outside        = path.HowFarOutsidePath(g);
                    const float WALL_THICKNESS = 1.0f;

                    // set map cells adjacent to the outside edge of the path
                    if ((outside > 0) && (outside < WALL_THICKNESS))
                    {
                        map.SetMapBit(i, j, true);
                    }

                    // clear all other off-path map cells
                    if (outside > WALL_THICKNESS)
                    {
                        map.SetMapBit(i, j, false);
                    }

                    g += alongRow;
                }
                g += nextRow;
            }
        }
Пример #3
0
        //This function pulls in the data from GREET that can be classified as user input, meaning it was a custom user value
        //In order to change the values in GREET you go into the data editor tab, and select either the pathway or resource
        //You want to change (in this case we are only looking at resources) and then change the values and hit apply
        //After you apply the changes, you can hit the pull user values button and it will allow you to update values in real time
        public void pullUserParameterValues()
        {
            IGDataDictionary <int, IResource> resources = ResultsAccess.controler.CurrentProject.Data.Resources;
            IGDataDictionary <int, IPathway>  pathways  = ResultsAccess.controler.CurrentProject.Data.Pathways;

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            IPathway myPathway = pathways.ValueForKey(CRUDE_PATHWAY_ID);
            // Grab the int id for the resource
            int       productID = myPathway.MainOutputResourceID;
            IResource resource  = resources.ValueForKey(productID);

            label11.Text = resource.Density.UserValue.ToString();

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            myPathway = pathways.ValueForKey(COAL_PATHWAY_ID);
            // Grab the int id for the resource
            productID    = myPathway.MainOutputResourceID;
            resource     = resources.ValueForKey(productID);
            label10.Text = resource.LowerHeatingValue.UserValue.ToString();

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            myPathway = pathways.ValueForKey(LSDIESEL_PATHWAY_ID);
            // Grab the int id for the resource
            productID   = myPathway.MainOutputResourceID;
            resource    = resources.ValueForKey(productID);
            label9.Text = resource.SulfurRatio.UserValue.ToString();
        }
Пример #4
0
        public void pullGREETParameterValues()
        {
            //You need to create these dictionaries in order to pull out the values you want
            IGDataDictionary <int, IResource> resources = ResultsAccess.controler.CurrentProject.Data.Resources;
            IGDataDictionary <int, IPathway>  pathways  = ResultsAccess.controler.CurrentProject.Data.Pathways;

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            IPathway myPathway = pathways.ValueForKey(CRUDE_PATHWAY_ID);
            // Grab the int id for the resource
            int       productID = myPathway.MainOutputResourceID;
            IResource resource  = resources.ValueForKey(productID);

            label4.Text = resource.Density.GreetValue.ToString();

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            myPathway = pathways.ValueForKey(COAL_PATHWAY_ID);
            // Grab the int id for the resource
            productID   = myPathway.MainOutputResourceID;
            resource    = resources.ValueForKey(productID);
            label5.Text = resource.LowerHeatingValue.GreetValue.ToString();

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            myPathway = pathways.ValueForKey(LSDIESEL_PATHWAY_ID);
            // Grab the int id for the resource
            productID   = myPathway.MainOutputResourceID;
            resource    = resources.ValueForKey(productID);
            label7.Text = resource.SulfurRatio.GreetValue.ToString();
        }
Пример #5
0
        /// <summary>
        /// is the given point inside the path tube?
        /// </summary>
        /// <param name="pathway"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static bool IsInsidePath(this IPathway pathway, Vector3 point)
        {
            float   outside;
            Vector3 tangent;

            pathway.MapPointToPath(point, out tangent, out outside);
            return(outside < 0);
        }
Пример #6
0
        /// <summary>
        /// how far outside path tube is the given point?  (negative is inside)
        /// </summary>
        /// <param name="pathway"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static float HowFarOutsidePath(this IPathway pathway, Vector3 point)
        {
            float   outside;
            Vector3 tangent;

            pathway.MapPointToPath(point, out tangent, out outside);
            return(outside);
        }
Пример #7
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var      sb         = new List <string>();
            IPathway targetPath = (IPathway)Subject;

            targetPath.FromLocation.MoveFrom((IMobile)Actor);
            targetPath.ToLocation.MoveInto((IMobile)Actor);

            targetPath.Enter.ExecuteMessaging(Actor, targetPath, null, targetPath.FromLocation, targetPath.ToLocation);
        }
Пример #8
0
        /// <summary>
        /// Executes this command
        /// </summary>
        internal override bool ExecutionBody()
        {
            IPathway targetPath = (IPathway)Subject;

            Actor.TryMoveTo(targetPath.Destination.GetContainerAsLocation());

            targetPath.Enter.ExecuteMessaging(Actor, targetPath, null, targetPath.Origin, targetPath.Destination);

            Actor.WriteTo(null);

            return(true);
        }
Пример #9
0
        /// <summary>
        /// Invoked when the user click on an item in the tree list view
        /// Retrieve the IPathway or IMix object stored in the tag and sends it to the ResultsControl
        /// for displaying the results associated with that pathway or mix main output
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            treeView1.SelectedNode = treeView1.GetNodeAt(e.Location);

            if (this.treeView1.SelectedNode != null)
            {
                Object   tag       = this.treeView1.SelectedNode.Tag;
                IResults result    = null;
                int      productID = -1;
                string   name      = "";

                //if the retrieved object is a pathway
                if (tag is IPathway)
                {
                    IPathway path = tag as IPathway;
                    //We ask the pathway what is the product defined as the main product for this pathway
                    //then store an integer that corresponds to an IResource.ID
                    productID = path.MainOutputResourceID;
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    Dictionary <int, IResults> availableResults = path.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);
                    if (availableResults.ContainsKey(productID))
                    {
                        result = availableResults[productID];
                    }
                    //We set the string variable as the name of the pathway
                    name = path.Name;
                }
                //if the retrieved object is a pathway
                else if (tag is IMix)
                {
                    IMix mix = tag as IMix;
                    //We ask the mix what is the product defined as the main product for this mix
                    //then store an integer that corresponds to an IResource.ID
                    productID = mix.MainOutputResourceID;
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    Dictionary <int, IResults> availableResults = mix.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);
                    if (availableResults.ContainsKey(productID))
                    {
                        result = availableResults[productID];
                    }
                    //We set the string variable as the name of the pathway
                    name = mix.Name;
                }

                //if we found a pathway or a mix and we have all the necessary parameters
                //we Invoke the SetResults method of our user control in charge of displaying the life cycle upstream results
                if (result != null && productID != -1 && !String.IsNullOrEmpty(name))
                {
                    this.resultsControl1.SetResults(name, result, productID);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Creates a new pathway with a few processes, then inserts that pathway in the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonNewPathway_Click(object sender, EventArgs e)
        {
            //Hardcoded crude oil resource ID, could be fetched from the IData class instead
            int CRUDE_RES_ID = 23;
            //Hardcoded process model id
            int PROC_ID_REC = 200, PROC_ID_TRA = 1000, PROC_ID_STO = 201;

            //Creates an instance of a pathway
            IPathway path = _dataHelper.CreateNewPathway("Example4 Pathway");

            //Retrieves process models from the current dataset
            IProcess procr = _controller.CurrentProject.Data.Processes.ValueForKey(PROC_ID_REC);
            IProcess proct = _controller.CurrentProject.Data.Processes.ValueForKey(PROC_ID_TRA);
            IProcess procs = _controller.CurrentProject.Data.Processes.ValueForKey(PROC_ID_STO);

            //Add processes models to the pathway, vertices will be created for each process model added to the pathway
            IVertex vertexR = _dataHelper.PathwayAddModel(path, procr);
            IVertex vertexT = _dataHelper.PathwayAddModel(path, proct);
            IVertex vertexS = _dataHelper.PathwayAddModel(path, procs);

            //finds input and outputs ID from the model, then add a connector in the pathway
            IInput inpT    = proct.FlattenInputList.First();
            IIO    outR    = procr.FlattenAllocatedOutputList.First();
            bool   success = _dataHelper.PathwayAddConnector(path, vertexR.ID, outR.Id, vertexT.ID, inpT.Id);

            //finds input and outputs ID from the model, then add a connector in the pathway
            IInput inpS = procs.FlattenInputList.First();
            IIO    outT = proct.FlattenAllocatedOutputList.First();

            success &= _dataHelper.PathwayAddConnector(path, vertexT.ID, outT.Id, vertexS.ID, inpS.Id);

            //creates a pathway output then connect the last process in the pathway to that output
            IIO pathOut = _dataHelper.PathwayCreateOutput(path, CRUDE_RES_ID);

            success &= _dataHelper.PathwaySetMainOutput(path, pathOut.Id);
            IIO outS = procs.FlattenAllocatedOutputList.First();

            success &= _dataHelper.PathwayAddConnector(path, vertexS.ID, outS.Id, pathOut.Id);

            //inserts the pathway to the current dataset
            success &= _dataHelper.DataInsertOrUpdatePathway(path);

            if (success)
            {
                MessageBox.Show("Pathway named : '" + path.Name + "' inserted in dataset");
            }
            else
            {
                MessageBox.Show("Failure");
            }
        }
Пример #11
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            List <string> sb         = new List <string>();
            IPathway      targetPath = (IPathway)Subject;

            Actor.TryMoveTo(targetPath.Destination.GetContainerAsLocation());

            targetPath.Enter.ExecuteMessaging(Actor, targetPath, null, targetPath.Origin, targetPath.Destination);

            //Render the next room to them
            Look lookCommand = new Look()
            {
                Actor = Actor, Subject = null, OriginLocation = Actor.CurrentLocation
            };

            lookCommand.Execute();
        }
Пример #12
0
        /// <summary>
        /// This function is pulling the BTUPerGal for Conventional Diesel so it can be used to calculate the gallons per trip. (This is ultimately recalculated in the Results code)
        /// </summary>
        /// <returns> The total BTUs per Gallon of conventional diesel </returns>
        public double getApproxBTUperGAL()
        {
            IGDataDictionary <int, IResource> resources = ResultsAccess.controler.CurrentProject.Data.Resources;
            IGDataDictionary <int, IPathway>  pathways  = ResultsAccess.controler.CurrentProject.Data.Pathways;
            IGDataDictionary <int, IMix>      mixes     = ResultsAccess.controler.CurrentProject.Data.Mixes;
            IPathway myPathway = pathways.ValueForKey(CD_PATH_ID);
            int      productID = myPathway.MainOutputResourceID;

            productID = myPathway.MainOutputResourceID;
            IResource ConvDiesel = resources.ValueForKey(productID);

            if (ConvDiesel.LowerHeatingValue.UserValue == 0)
            {
                return((ConvDiesel.LowerHeatingValue.GreetValue) * (1 / GALLONS_PER_CUBIC_METER) * (1 / JOULES_PER_BTU));
            }
            else
            {
                return((ConvDiesel.LowerHeatingValue.UserValue) * (1 / GALLONS_PER_CUBIC_METER) * (1 / JOULES_PER_BTU));
            }
        }
Пример #13
0
        //We have to render our pathway out, an empty space for the potential pathway back and the destination room
        private static string[,,] AddDirectionToMap(string[,,] dataMap, MovementDirectionType transversalDirection, IRoom origin, int diameter, int centerX, int centerY, int centerZ, HashSet <IRoom> roomPool)
        {
            IEnumerable <IPathway> pathways         = origin.GetPathways(true);
            Tuple <int, int, int>  directionalSteps = Utilities.GetDirectionStep(transversalDirection);

            int xStepped = centerX + directionalSteps.Item1;
            int yStepped = centerY + directionalSteps.Item2;
            int zStepped = centerZ + directionalSteps.Item3;

            //If we're not over diameter budget and there is nothing there already (we might have already rendered the path and room) then render it
            //When the next room tries to render backwards it'll run into the existant path it came from and stop the chain here
            if (xStepped > 0 && xStepped <= diameter &&
                yStepped > 0 && yStepped <= diameter &&
                zStepped > 0 && zStepped <= diameter &&
                string.IsNullOrWhiteSpace(dataMap[xStepped - 1, yStepped - 1, zStepped - 1]))
            {
                IPathway thisPath = pathways.FirstOrDefault(path =>
                                                            (path.DirectionType == transversalDirection && path.Origin.Equals(origin) && path.Destination.GetType().GetInterfaces().Contains(typeof(IRoom))) ||
                                                            (path.DirectionType == Utilities.ReverseDirection(transversalDirection) && path.Destination.Equals(origin) && path.Origin.GetType().GetInterfaces().Contains(typeof(IRoom)))
                                                            );
                if (thisPath != null)
                {
                    string locId = thisPath.Destination.BirthMark;

                    if (thisPath.Destination.BirthMark.Equals(origin.BirthMark))
                    {
                        locId = thisPath.Origin.BirthMark;
                    }

                    IRoom passdownOrigin = LiveCache.Get <IRoom>(new LiveCacheKey(typeof(IRoom), locId));

                    if (passdownOrigin != null)
                    {
                        dataMap[xStepped - 1, yStepped - 1, zStepped - 1] = passdownOrigin.BirthMark;
                        dataMap = AddFullRoomToMap(dataMap, passdownOrigin, diameter, xStepped, yStepped, zStepped, roomPool);
                    }
                }
            }

            return(dataMap);
        }
Пример #14
0
        /// <summary>
        /// Creates a new mix with a few pathways and mixes references, then inserts that mix in the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonNewMix_Click(object sender, EventArgs e)
        {
            //Hardcoded crude oil resource ID, could be fetched from the IData class instead
            int CRUDE_RES_ID = 23;
            //Hardcoded pathway IDs
            int CONV_CRD = 34, OILS_CRD = 36;
            //Hardcoded mix ID (for the fun of it)
            int MIX_CRD = 0;

            //Creating a new instance of a mix
            IMix mix = _dataHelper.CreateNewMix("Example4 Mix");

            //Set the resource ID produced by this mix
            _dataHelper.MixSetResource(mix, CRUDE_RES_ID);

            //Retriving pathways to be added to the mix
            IPathway path1 = _controller.CurrentProject.Data.Pathways.ValueForKey(CONV_CRD);
            IPathway path2 = _controller.CurrentProject.Data.Pathways.ValueForKey(OILS_CRD);
            IMix     mix1  = _controller.CurrentProject.Data.Mixes.ValueForKey(MIX_CRD);

            //Adding the different production items to the mix and define their shares
            bool success = _dataHelper.MixAddFeed(mix, path1, 0.3);

            success &= _dataHelper.MixAddFeed(mix, path2, 0.6);
            success &= _dataHelper.MixAddFeed(mix, mix1, 0.1);

            //Inserting the newly created mix to the database
            success &= _dataHelper.DataInsertOrUpdateMix(mix);

            if (success)
            {
                MessageBox.Show("Mix named : '" + mix.Name + "' inserted in dataset");
            }
            else
            {
                MessageBox.Show("Failure");
            }
        }
Пример #15
0
 protected Vector3 SteerToStayOnPath(float predictionTime, IPathway path)
 {
     return(this.SteerToStayOnPath(predictionTime, path, MaxSpeed, annotation));
 }
Пример #16
0
        /// <summary>
        /// Invoked when the user click on an item in the tree list view
        /// Retrieve the IPathway or IMix object stored in the tag and sends it to the ResultsControl
        /// for displaying the results associated with that pathway or mix main output
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            treeView1.SelectedNode = treeView1.GetNodeAt(e.Location);

            if (this.treeView1.SelectedNode != null)
            {
                Object   tag       = this.treeView1.SelectedNode.Tag;
                IResults result    = null;
                int      productID = -1;
                string   name      = "";

                if (tag is IPathway)
                {//if the retrieved object is a pathway
                    IPathway path = tag as IPathway;
                    //We ask the pathway what is the product defined as the main product for this pathway
                    //then store an integer that corresponds to an IResource.ID
                    productID = ResultsAccess.controler.CurrentProject.Data.Helper.PathwayMainOutputResouce(path.Id);
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    Dictionary <IIO, IResults> availableResults = path.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);
                    Guid desiredOutput = new Guid();
                    if (null == availableResults.Keys.SingleOrDefault(item => item.ResourceId == productID))
                    {
                        MessageBox.Show("Selected pathway does not produce the fuel selected. Please remove it from the Fule Types list");
                        return;
                    }
                    else
                    {
                        foreach (IIO io in availableResults.Keys.Where(item => item.ResourceId == productID))
                        {
                            desiredOutput = io.Id;
                            if (io.Id == path.MainOutput)
                            {
                                desiredOutput = io.Id;
                                break;
                            }
                        }
                    }
                    result = availableResults.SingleOrDefault(item => item.Key.Id == desiredOutput).Value;
                    //We set the string variable as the name of the pathway
                    name = path.Name;
                }
                else if (tag is IMix)
                {//if the retrieved object is a mix
                    IMix mix = tag as IMix;
                    //We ask the mix what is the product defined as the main product for this mix
                    //then store an integer that corresponds to an IResource.ID
                    productID = mix.MainOutputResourceID;
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    var upstream = mix.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);

                    if (null == upstream.Keys.SingleOrDefault(item => item.ResourceId == productID))
                    {
                        MessageBox.Show("Selected mix does not produce the fuel selected. Please remove it from the Fule Types list");
                        return;
                    }

                    //a mix has a single output so we can safely do the folowing
                    result = upstream.SingleOrDefault(item => item.Key.ResourceId == productID).Value;

                    //We set the string variable as the name of the pathway
                    name = mix.Name;
                }

                //if we found a pathway or a mix and we have all the necessary parameters
                //we Invoke the SetResults method of our user control in charge of displaying the life cycle upstream results
                if (result != null && productID != -1 && !String.IsNullOrEmpty(name))
                {
                    this.resultsControl1.SetResults(name, result, productID);
                }
            }
        }
 /// <summary>
 /// Pulls the main product resource from using a specific pathway
 /// </summary>
 /// <param name="path">The specific pathway you are getting the resource for</param>
 /// <returns>The product of the pathway it was passed</returns>
 public IResource getResourceUsed(IPathway path) { return ResultsAccess.controler.CurrentProject.Data.Resources.ValueForKey(path.MainOutputResourceID); }
Пример #18
0
 /// <summary>
 /// Pulls the main product resource from using a specific pathway
 /// </summary>
 /// <param name="path">The specific pathway you are getting the resource for</param>
 /// <returns>The product of the pathway it was passed</returns>
 public IResource getResourceUsed(IPathway path)
 {
     return(ResultsAccess.controler.CurrentProject.Data.Resources.ValueForKey(path.MainOutputResourceID));
 }
Пример #19
0
        /// <summary>
        /// Restores live entity backup from Current
        /// </summary>
        /// <returns>Success state</returns>
        public bool RestoreLiveBackup()
        {
            LiveData liveDataAccessor = new LiveData();

            string currentBackupDirectory = liveDataAccessor.BaseDirectory + liveDataAccessor.CurrentDirectoryName;

            //No backup directory? No live data.
            if (!Directory.Exists(currentBackupDirectory))
            {
                return(false);
            }

            LoggingUtility.Log("World restored from current live INITIATED.", LogChannels.Backup, false);

            try
            {
                //dont load players here
                List <IEntity>     entitiesToLoad   = new List <IEntity>();
                IEnumerable <Type> implimentedTypes = typeof(EntityPartial).Assembly.GetTypes().Where(ty => ty.GetInterfaces().Contains(typeof(IEntity)) &&
                                                                                                      ty.IsClass &&
                                                                                                      !ty.IsAbstract &&
                                                                                                      !ty.GetCustomAttributes <IgnoreAutomatedBackupAttribute>().Any());

                foreach (Type type in implimentedTypes.OrderByDescending(type => type == typeof(Gaia) ? 6 :
                                                                         type == typeof(Zone) ? 5 :
                                                                         type == typeof(Locale) ? 3 :
                                                                         type == typeof(Room) ? 3 :
                                                                         type == typeof(Pathway) ? 2 : 0))
                {
                    if (!Directory.Exists(currentBackupDirectory + type.Name))
                    {
                        continue;
                    }

                    DirectoryInfo entityFilesDirectory = new DirectoryInfo(currentBackupDirectory + type.Name);

                    foreach (FileInfo file in entityFilesDirectory.EnumerateFiles())
                    {
                        entitiesToLoad.Add(liveDataAccessor.ReadEntity(file, type));
                    }
                }

                //Check we found actual data
                if (!entitiesToLoad.Any(ent => ent.GetType() == typeof(Gaia)))
                {
                    throw new Exception("No Worlds found, failover.");
                }

                if (!entitiesToLoad.Any(ent => ent.GetType() == typeof(Zone)))
                {
                    throw new Exception("No zones found, failover.");
                }

                //Shove them all into the live system first
                foreach (IEntity entity in entitiesToLoad.OrderBy(ent => ent.Birthdate))
                {
                    entity.UpsertToLiveWorldCache();
                    entity.KickoffProcesses();
                }

                //We need to pick up any places that aren't already live from the file system incase someone added them during the last session\
                foreach (IGaiaTemplate thing in TemplateCache.GetAll <IGaiaTemplate>().Where(dt => !entitiesToLoad.Any(ent => ent.TemplateId.Equals(dt.Id) && ent.Birthdate >= dt.LastRevised)))
                {
                    IGaia entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as IGaia;

                    entityThing.SpawnNewInWorld();
                }

                foreach (IZoneTemplate thing in TemplateCache.GetAll <IZoneTemplate>().Where(dt => !entitiesToLoad.Any(ent => ent.TemplateId.Equals(dt.Id) && ent.Birthdate >= dt.LastRevised)))
                {
                    IZone entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as IZone;

                    entityThing.SpawnNewInWorld();
                }

                foreach (ILocaleTemplate thing in TemplateCache.GetAll <ILocaleTemplate>().Where(dt => !entitiesToLoad.Any(ent => ent.TemplateId.Equals(dt.Id) && ent.Birthdate >= dt.LastRevised)))
                {
                    ILocale entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as ILocale;

                    entityThing.ParentLocation = entityThing.ParentLocation.GetLiveInstance();
                    entityThing.SpawnNewInWorld();
                }

                foreach (IRoomTemplate thing in TemplateCache.GetAll <IRoomTemplate>().Where(dt => !entitiesToLoad.Any(ent => ent.TemplateId.Equals(dt.Id) && ent.Birthdate >= dt.LastRevised)))
                {
                    IRoom entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as IRoom;

                    entityThing.ParentLocation = entityThing.Template <IRoomTemplate>().ParentLocation.GetLiveInstance();
                    entityThing.SpawnNewInWorld();
                }

                foreach (IPathwayTemplate thing in TemplateCache.GetAll <IPathwayTemplate>().Where(dt => !entitiesToLoad.Any(ent => ent.TemplateId.Equals(dt.Id) && ent.Birthdate >= dt.LastRevised)))
                {
                    IPathway entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as IPathway;

                    entityThing.SpawnNewInWorld();
                }

                //We have the containers contents and the birthmarks from the deserial
                //I don't know how we can even begin to do this type agnostically since the collections are held on type specific objects without some super ugly reflection
                foreach (Room entity in entitiesToLoad.Where(ent => ent.GetType() == typeof(Room)))
                {
                    foreach (IInanimate obj in entity.Contents.EntitiesContained())
                    {
                        IInanimate fullObj = LiveCache.Get <IInanimate>(new LiveCacheKey(obj));
                        entity.MoveFrom(obj);
                        entity.MoveInto(fullObj);
                    }

                    foreach (INonPlayerCharacter obj in entity.MobilesInside.EntitiesContained())
                    {
                        INonPlayerCharacter fullObj = LiveCache.Get <INonPlayerCharacter>(new LiveCacheKey(obj));
                        entity.MoveFrom(obj);
                        entity.MoveInto(fullObj);
                    }
                }

                foreach (NonPlayerCharacter entity in entitiesToLoad.Where(ent => ent.GetType() == typeof(NonPlayerCharacter)))
                {
                    foreach (IInanimate obj in entity.Inventory.EntitiesContained())
                    {
                        IInanimate fullObj = LiveCache.Get <IInanimate>(new LiveCacheKey(obj));
                        entity.MoveFrom(obj);
                        entity.MoveInto(fullObj);
                    }
                }

                foreach (Inanimate entity in entitiesToLoad.Where(ent => ent.GetType() == typeof(Inanimate)))
                {
                    foreach (Tuple <string, IInanimate> obj in entity.Contents.EntitiesContainedByName())
                    {
                        IInanimate fullObj = LiveCache.Get <IInanimate>(new LiveCacheKey(obj.Item2));
                        entity.MoveFrom(obj.Item2);
                        entity.MoveInto(fullObj, obj.Item1);
                    }

                    foreach (Tuple <string, IInanimate> obj in entity.Contents.EntitiesContainedByName())
                    {
                        INonPlayerCharacter fullObj = LiveCache.Get <INonPlayerCharacter>(new LiveCacheKey(obj.Item2));
                        entity.MoveFrom((INonPlayerCharacter)obj.Item2);
                        entity.MoveInto(fullObj, obj.Item1);
                    }
                }

                //We need to poll the WorldMaps here and give all the rooms their coordinates as well as the zones their sub-maps
                ParseDimension();

                LoggingUtility.Log("World restored from current live.", LogChannels.Backup, false);
                return(true);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return(false);
        }
Пример #20
0
        static void DrawPathFencesOnMap(TerrainMap map, IPathway path)
		{
			float xs = map.XSize / map.Resolution;
			float zs = map.ZSize / map.Resolution;
			Vector3 alongRow = new Vector3(xs, 0, 0);
			Vector3 nextRow = new Vector3(-map.XSize, 0, zs);
			Vector3 g = new Vector3((map.XSize - xs) / -2, 0, (map.ZSize - zs) / -2);
			for (int j = 0; j < map.Resolution; j++)
			{
				for (int i = 0; i < map.Resolution; i++)
				{
					float outside = path.HowFarOutsidePath(g);
					const float WALL_THICKNESS = 1.0f;

					// set map cells adjacent to the outside edge of the path
					if ((outside > 0) && (outside < WALL_THICKNESS))
						map.SetMapBit(i, j, true);

					// clear all other off-path map cells 
					if (outside > WALL_THICKNESS) map.SetMapBit(i, j, false);

					g += alongRow;
				}
				g += nextRow;
			}
		}
Пример #21
0
        /// <summary>
        /// Pulls the needed GREET data, and makes final results calculations
        /// </summary>
        #region Final results calculation
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            Object tag = tree_Main_Fuel_Pathways.SelectedNode.Tag;

            if (tag is IPathway)
            {
                IData data = APIcontroller.getData();

                IPathway  path         = tag as IPathway;
                IResource resourceUsed = APIcontroller.getResourceUsed(path);

                // Grabs the fuel used in the main engine to display to the user.
                MainfuelUsed = APIcontroller.getFuelUsed(path);

                IResults pathwayResults = APIcontroller.getPathwayResults(data, path);

                teams_sheet.GALLONperTrip = APIcontroller.getGallonsPerMMBTU(resourceUsed) * teams_sheet.MMBTUinperTrip;

                //These numbers will be used in calculations below, and are based on whether or not the user has edited GREET resource variables
                double resourceDensity           = APIcontroller.getResourceDensity(resourceUsed);
                double resourceSulfurRatio       = APIcontroller.getResourceSulfurRatio(resourceUsed);
                double resourceLowerHeatingValue = APIcontroller.getResourceLowerHeatingValue(resourceUsed);
                double resourceCarbonRatio       = APIcontroller.getResourceCarbonRatio(resourceUsed);


                double[] main_fuel_type = new double[7];

                if (MainfuelUsed.Equals("Conventional Diesel"))
                {
                    Array.Copy(teams_sheet.Diesel, main_fuel_type, teams_sheet.Diesel.Length);
                }
                else if (MainfuelUsed.Equals("Residual Oil"))
                {
                    Array.Copy(teams_sheet.Residual_Oil, main_fuel_type, teams_sheet.Residual_Oil.Length);
                }
                else if (MainfuelUsed.Equals("Low-Sulfur Diesel"))
                {
                    Array.Copy(teams_sheet.Ult_Low_Sulf, main_fuel_type, teams_sheet.Ult_Low_Sulf.Length);
                }
                else if (MainfuelUsed.Equals("Liquefied Natural Gas"))
                {
                    Array.Copy(teams_sheet.Natural_Gas, main_fuel_type, teams_sheet.Natural_Gas.Length);
                }
                else if (MainfuelUsed.Equals("Biodiesel"))
                {
                    Array.Copy(teams_sheet.Biodiesel, main_fuel_type, teams_sheet.Biodiesel.Length);
                }
                else
                {
                    Array.Copy(teams_sheet.Fischer, main_fuel_type, teams_sheet.Fischer.Length);
                }

                //These should be relatively accurate no matter what, since it's a total energy and not the different engines
                //Total Energy Well To Pump = mmbtu of fuel put into the engine * all sections of energy for what it took to create 1 mmbtu of fuel - the 1 mmbtu of fuel

                TE_WTP = teams_sheet.MMBTUinperTrip * APIcontroller.getSumAllLifeCycleResources(pathwayResults) - 1 - teams_sheet.MMBTUinperTrip;
                //TE_WTP = teams_sheet.MMBTUinperTrip * APIcontroller.getSumAllLifeCycleResources(pathwayResults);

                //Total Energy Vessel Operation = mmbtu needed to put into the ship
                TE_VO = teams_sheet.MMBTUinperTrip;
                //Total Energy = Vessel Operation + Well to pump + aux vessel operation + aux well to pump
                TE_Total = TE_WTP + TE_VO + AUX_TE_WTP + AUX_TE_VO;

                // TODO: Implement Fossil Fuels and Petroleum Fuels
                // Fossil Fuels in WTP =  mmbtuin * a greet energy WTP value
                //FF_WTP = teams_sheet.MMBTUinperTrip * pathwayResults.LifeCycleResourcesGroups(data).ElementAt(0).Value.Value;
                //FF_Total = FF_WTP + FF_VO + AUX_FF_WTP + AUX_FF_VO;
                FF_WTP   = 0;
                FF_Total = 0;

                // Petroleum Fuel in WTP =  mmbtuin * a greet energy WTP value
                //PF_WTP = teams_sheet.MMBTUinperTrip * pathwayResults.LifeCycleResourcesGroups(data).ElementAt(2).Value.Value;
                //PF_Total = PF_WTP + PF_VO + AUX_PF_WTP + AUX_PF_VO;
                PF_WTP   = 0;
                PF_Total = 0;

                // Volatile Organic Compounds
                VOC_WTP   = APIcontroller.getResourceWTPEmissions(pathwayResults, 0) * teams_sheet.MMBTUinperTrip;
                VOC_VO    = main_fuel_type[0] * (1 / KWHRS_PER_HPHR) * teams_sheet.KWHOutperTrip;
                VOC_Total = VOC_WTP + VOC_VO + AUX_VOC_WTP + AUX_VOC_VO;

                // Carbon Monoxide
                CO_WTP   = APIcontroller.getResourceWTPEmissions(pathwayResults, 1) * teams_sheet.MMBTUinperTrip;
                CO_VO    = (main_fuel_type[1] * (1 / KWHRS_PER_HPHR) * teams_sheet.KWHOutperTrip);
                CO_Total = CO_WTP + CO_VO + AUX_CO_WTP + AUX_CO_VO;

                // Nitrogen Dioxide
                NOx_WTP   = APIcontroller.getResourceWTPEmissions(pathwayResults, 2) * teams_sheet.MMBTUinperTrip;
                NOx_VO    = main_fuel_type[2] * (1 / KWHRS_PER_HPHR) * teams_sheet.KWHOutperTrip;
                NOx_Total = NOx_WTP + NOx_VO + AUX_NOx_WTP + AUX_NOx_VO;

                // Particulate Matter 10
                PM10_WTP   = APIcontroller.getResourceWTPEmissions(pathwayResults, 3) * teams_sheet.MMBTUinperTrip;
                PM10_VO    = main_fuel_type[3] * (1 / KWHRS_PER_HPHR) * teams_sheet.KWHOutperTrip;
                PM10_Total = PM10_WTP + PM10_VO + AUX_PM10_WTP + AUX_PM10_VO;

                // Particulate Matter 25
                PM25_WTP   = APIcontroller.getResourceWTPEmissions(pathwayResults, 4) * teams_sheet.MMBTUinperTrip;
                PM25_VO    = main_fuel_type[4] * (1 / KWHRS_PER_HPHR) * teams_sheet.KWHOutperTrip;
                PM25_Total = PM25_WTP + PM25_VO + AUX_PM25_WTP + AUX_PM25_VO;

                // Sulfur Oxides
                SOx_WTP   = APIcontroller.getResourceWTPEmissions(pathwayResults, 5) * teams_sheet.MMBTUinperTrip;
                SOx_VO    = resourceDensity * resourceSulfurRatio * GRAMS_PER_KILOGRAM * (1 / GALLONS_PER_CUBIC_METER) * GRAMS_SOX_PER_GRAMS_S * teams_sheet.GALLONperTrip;
                SOx_Total = SOx_WTP + SOx_VO + AUX_SOx_WTP + AUX_SOx_VO;

                // Methane
                CH4_WTP   = APIcontroller.getResourceWTPEmissions(pathwayResults, 6) * teams_sheet.MMBTUinperTrip;
                CH4_VO    = main_fuel_type[5] * (1 / KWHRS_PER_HPHR) * teams_sheet.KWHOutperTrip;
                CH4_Total = CH4_WTP + CH4_VO + AUX_CH4_WTP + AUX_CH4_VO;

                // Carbon Dioxide
                double gramsOfFuel = (1 / resourceLowerHeatingValue) * resourceDensity * JOULES_PER_MMBTU * GRAMS_PER_KILOGRAM * teams_sheet.MMBTUinperTrip;
                CO2_WTP   = APIcontroller.getResourceWTPEmissions(pathwayResults, 8) * teams_sheet.MMBTUinperTrip;
                CO2_VO    = gramsOfFuel * resourceCarbonRatio * (44 / 12);
                CO2_Total = CO2_WTP + CO2_VO + AUX_CO2_WTP + AUX_CO2_VO;

                //Nitrous Oxide
                N2O_WTP   = APIcontroller.getResourceWTPEmissions(pathwayResults, 7) * teams_sheet.MMBTUinperTrip;
                N2O_VO    = main_fuel_type[6] * (1 / KWHRS_PER_HPHR) * teams_sheet.KWHOutperTrip;
                N2O_Total = N2O_WTP + N2O_VO + AUX_N2O_WTP + AUX_N2O_VO;
            }
            setLabels();
        }
Пример #22
0
        private static string RenderPathwayToAsciiForModals(IPathway path, string originId, MovementDirectionType directionType, bool forAdmin = false)
        {
            string      returnValue     = string.Empty;
            string      asciiCharacter  = Utilities.TranslateDirectionToAsciiCharacter(directionType);
            string      destinationId   = "";
            string      destinationName = string.Empty;
            PathwayType pathType        = PathwayType.None;

            if (path != null && path.Destination != null)
            {
                destinationName = path.Destination.TemplateName;
                destinationId   = path.Destination.BirthMark;
                pathType        = path.Type;
            }

            if (forAdmin)
            {
                if (path != null)
                {
                    if (pathType == PathwayType.Rooms)
                    {
                        returnValue = string.Format("<a href='#' class='editData pathway AdminEditPathway' pathwayId='{0}' fromRoom='{3}' toRoom='{4}' title='Edit - {5} path to {1}' data-id='{0}'>{2}</a>",
                                                    path.BirthMark, destinationName, asciiCharacter, originId, destinationId, directionType.ToString());
                    }
                    else
                    {
                        string classString = "zone";

                        if (pathType == PathwayType.Locale)
                        {
                            classString = "locale";
                        }

                        returnValue = string.Format("<a class='pathway {4}' title='{5}: {3} to {1}' data-id='{0}'>{2}</a>",
                                                    path.BirthMark, destinationName, asciiCharacter, directionType.ToString(), classString, path.TemplateName);
                    }
                }
                else
                {
                    string roomString = string.Format("Add - {0} path and room", directionType.ToString());

                    if (!string.IsNullOrWhiteSpace(destinationName))
                    {
                        roomString = string.Format("Add {0} path to {1}", directionType.ToString(), destinationName);
                    }

                    returnValue = string.Format("<a href='#' class='addData pathway AdminAddPathway' pathwayId='-1' fromRoom='{0}' toRoom='{4}' data-direction='{1}' data-incline='{2}' title='{3}'>+</a>",
                                                originId, Utilities.TranslateDirectionToDegrees(directionType).Item1, Utilities.GetBaseInclineGrade(directionType), roomString, destinationId);
                }
            }
            else if (path != null)
            {
                if (pathType == PathwayType.Rooms)
                {
                    returnValue = string.Format("<a href='#' class='pathway nonAdminPathway' title='{3}: {1}{4} to {2}{5}' data-id='{6}'>{0}</a>",
                                                asciiCharacter, directionType, destinationName, path.TemplateName, originId, destinationId, path.BirthMark);
                }
                else
                {
                    string classString = "zone";

                    if (pathType == PathwayType.Locale)
                    {
                        classString = "locale";
                    }

                    returnValue = string.Format("<a class='pathway {4}' title='{5}: {3} to {1}' data-id='{0}'>{2}</a>",
                                                path.BirthMark, destinationName, asciiCharacter, directionType.ToString(), classString, path.TemplateName);
                }
            }

            return(returnValue);
        }
Пример #23
0
        private static string[,] RenderRoomAndPathwaysForMapNode(int x, int y, IRoom Room, IRoom centerRoom, string[,] expandedMap, bool currentRoom, bool forAdmin, MapRenderMode renderMode)
        {
            IEnumerable <IPathway> pathways = Room.GetPathways();
            int expandedRoomX = x * 3 + 1;
            int expandedRoomY = y * 3 + 1;

            switch (renderMode)
            {
            case MapRenderMode.Normal:
                IPathway ePath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.East);
                IPathway nPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.North);
                IPathway nePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.NorthEast);
                IPathway nwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.NorthWest);
                IPathway sPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.South);
                IPathway sePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.SouthEast);
                IPathway swPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.SouthWest);
                IPathway wPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.West);

                //The room
                expandedMap[expandedRoomX, expandedRoomY] = RenderRoomToAscii(Room, Room.GetZonePathways().Any(), Room.GetLocalePathways().Any()
                                                                              , !forAdmin && currentRoom, forAdmin);

                expandedMap[expandedRoomX - 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(nwPath, Room.BirthMark, MovementDirectionType.NorthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY + 1]     = RenderPathwayToAsciiForModals(nPath, Room.BirthMark, MovementDirectionType.North, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(nePath, Room.BirthMark, MovementDirectionType.NorthEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY]     = RenderPathwayToAsciiForModals(wPath, Room.BirthMark, MovementDirectionType.West, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY]     = RenderPathwayToAsciiForModals(ePath, Room.BirthMark, MovementDirectionType.East, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(swPath, Room.BirthMark, MovementDirectionType.SouthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY - 1]     = RenderPathwayToAsciiForModals(sPath, Room.BirthMark, MovementDirectionType.South, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(sePath, Room.BirthMark, MovementDirectionType.SouthEast, forAdmin);

                break;

            case MapRenderMode.Upwards:
                IPathway upPath   = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.Up);
                IPathway upePath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpEast);
                IPathway upnPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpNorth);
                IPathway upnePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpNorthEast);
                IPathway upnwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpNorthWest);
                IPathway upsPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpSouth);
                IPathway upsePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpSouthEast);
                IPathway upswPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpSouthWest);
                IPathway upwPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.UpWest);

                expandedMap[expandedRoomX, expandedRoomY]         = RenderPathwayToAsciiForModals(upPath, Room.BirthMark, MovementDirectionType.Up, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(upnwPath, Room.BirthMark, MovementDirectionType.UpNorthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY + 1]     = RenderPathwayToAsciiForModals(upnPath, Room.BirthMark, MovementDirectionType.UpNorth, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(upnePath, Room.BirthMark, MovementDirectionType.UpNorthEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY]     = RenderPathwayToAsciiForModals(upwPath, Room.BirthMark, MovementDirectionType.UpWest, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY]     = RenderPathwayToAsciiForModals(upePath, Room.BirthMark, MovementDirectionType.UpEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(upswPath, Room.BirthMark, MovementDirectionType.UpSouthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY - 1]     = RenderPathwayToAsciiForModals(upsPath, Room.BirthMark, MovementDirectionType.UpSouth, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(upsePath, Room.BirthMark, MovementDirectionType.UpSouthEast, forAdmin);

                break;

            case MapRenderMode.Downwards:
                IPathway downPath   = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.Down);
                IPathway downePath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownEast);
                IPathway downnPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownNorth);
                IPathway downnePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownNorthEast);
                IPathway downnwPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownNorthWest);
                IPathway downsPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownSouth);
                IPathway downsePath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownSouthEast);
                IPathway downswPath = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownSouthWest);
                IPathway downwPath  = pathways.FirstOrDefault(path => path.DirectionType == MovementDirectionType.DownWest);

                expandedMap[expandedRoomX, expandedRoomY]         = RenderPathwayToAsciiForModals(downPath, Room.BirthMark, MovementDirectionType.Down, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(downnwPath, Room.BirthMark, MovementDirectionType.DownNorthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY + 1]     = RenderPathwayToAsciiForModals(downnPath, Room.BirthMark, MovementDirectionType.DownNorth, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY + 1] = RenderPathwayToAsciiForModals(downnePath, Room.BirthMark, MovementDirectionType.DownNorthEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY]     = RenderPathwayToAsciiForModals(downwPath, Room.BirthMark, MovementDirectionType.DownWest, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY]     = RenderPathwayToAsciiForModals(downePath, Room.BirthMark, MovementDirectionType.DownEast, forAdmin);
                expandedMap[expandedRoomX - 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(downswPath, Room.BirthMark, MovementDirectionType.DownSouthWest, forAdmin);
                expandedMap[expandedRoomX, expandedRoomY - 1]     = RenderPathwayToAsciiForModals(downsPath, Room.BirthMark, MovementDirectionType.DownSouth, forAdmin);
                expandedMap[expandedRoomX + 1, expandedRoomY - 1] = RenderPathwayToAsciiForModals(downsePath, Room.BirthMark, MovementDirectionType.DownSouthEast, forAdmin);

                break;
            }

            return(expandedMap);
        }
Пример #24
0
        public static Vector3 SteerToFollowPath(this IVehicle vehicle, bool direction, float predictionTime, IPathway path, float maxSpeed, out float currentPathDistance, IAnnotationService annotation = null)
        {
            // our goal will be offset from our path distance by this amount
            float pathDistanceOffset = (direction ? 1 : -1) * predictionTime * vehicle.Speed;

            // predict our future position
            Vector3 futurePosition = vehicle.PredictFuturePosition(predictionTime);

            // measure distance along path of our current and predicted positions
            currentPathDistance = path.MapPointToPathDistance(vehicle.Position);
            float futurePathDistance = path.MapPointToPathDistance(futurePosition);

            // are we facing in the correction direction?
            bool rightway = ((pathDistanceOffset > 0) ?
                             (currentPathDistance < futurePathDistance) :
                             (currentPathDistance > futurePathDistance));

            // find the point on the path nearest the predicted future position
            Vector3 tangent;
            float   outside;
            Vector3 onPath = path.MapPointToPath(futurePosition, out tangent, out outside);

            // no steering is required if (a) our future position is inside
            // the path tube and (b) we are facing in the correct direction
            if ((outside <= 0) && rightway)
            {
                //We're going at max speed, in the right direction. don't need to do anything
                if (vehicle.Speed >= maxSpeed)
                {
                    return(Vector3.Zero);
                }

                //Predict vehicle position and sample multiple times, incresingly far along the path
                var seek = path.MapPointToPath(vehicle.PredictFuturePosition(predictionTime / 3), out tangent, out outside);
                for (int i = 0; i < 3; i++)
                {
                    var s = path.MapPointToPath(seek + tangent * vehicle.Speed / (i + 1), out tangent, out outside);

                    //terminate search if we wander outside the path
                    if (outside > 0)
                    {
                        break;
                    }
                    seek = s;

                    if (annotation != null)
                    {
                        annotation.Circle3D(0.3f, seek, Vector3.Up, Color.Green, 6);
                    }
                }

                //Steer towards future path point
                return(vehicle.SteerForSeek(seek, maxSpeed, annotation));
            }

            // otherwise we need to steer towards a target point obtained
            // by adding pathDistanceOffset to our current path position
            float   targetPathDistance = currentPathDistance + pathDistanceOffset;
            Vector3 target             = path.MapPathDistanceToPoint(targetPathDistance);

            if (annotation != null)
            {
                annotation.PathFollowing(futurePosition, onPath, target, outside);
            }

            // return steering to seek target on path
            return(SteerForSeek(vehicle, target, maxSpeed));
        }
Пример #25
0
        public static Vector3 SteerToFollowPath(this IVehicle vehicle, bool direction, float predictionTime, IPathway path, float maxSpeed, IAnnotationService annotation = null)
        {
            float pathDistance;

            return(SteerToFollowPath(vehicle, direction, predictionTime, path, maxSpeed, out pathDistance, annotation));
        }
Пример #26
0
        public static Vector3 SteerToStayOnPath(this IVehicle vehicle, float predictionTime, IPathway path, float maxSpeed, IAnnotationService annotation = null)
        {
            // predict our future position
            Vector3 futurePosition = vehicle.PredictFuturePosition(predictionTime);

            // find the point on the path nearest the predicted future position
            Vector3 tangent;
            float   outside;
            Vector3 onPath = path.MapPointToPath(futurePosition, out tangent, out outside);

            if (outside < 0)
            {
                return(Vector3.Zero);    // our predicted future position was in the path, return zero steering.
            }
            // our predicted future position was outside the path, need to
            // steer towards it.  Use onPath projection of futurePosition
            // as seek target
            if (annotation != null)
            {
                annotation.PathFollowing(futurePosition, onPath, onPath, outside);
            }

            return(vehicle.SteerForSeek(onPath, maxSpeed));
        }
Пример #27
0
 protected Vector3 SteerToFollowPath(bool direction, float predictionTime, IPathway path)
 {
     return(this.SteerToFollowPath(direction, predictionTime, path, MaxSpeed, annotation));
 }
Пример #28
0
 /// <summary>
 /// Gets the main, general fuel used after a specific pathway is selected. i.e. "Conventional Diesel"
 /// </summary>
 /// <param name="pathway">The specific pathway selected</param>
 /// <returns>A strong of the general fuel used</returns>
 public string getFuelUsed(IPathway pathway)
 {
     return(getResources().AllValues.Where(item => item.Id == pathway.MainOutputResourceID).ElementAt(0).Name);
 }
Пример #29
0
		// ----------------------------------------------------------------------------
		// Path Following behaviors

		public Vector3 steerToStayOnPath(float predictionTime, IPathway path)
		{
			// predict our future position
			Vector3 futurePosition = predictFuturePosition (predictionTime);

			// find the point on the path nearest the predicted future position
			PathRelativePosition tStruct = new PathRelativePosition();

			Vector3 onPath = path.MapPointToPath(futurePosition, ref tStruct);

			if (tStruct.outside < 0)
			{
				// our predicted future position was in the path,
				// return zero steering.
				return Vector3.zero;
			}
			else
			{
				// our predicted future position was outside the path, need to
				// steer towards it.  Use onPath projection of futurePosition
				// as seek target
				#if ANNOTATE_PATH
				annotatePathFollowing (futurePosition, onPath, onPath,tStruct.outside);
				#endif
				return steerForSeek (onPath);
			}
		}
Пример #30
0
 public PathWalker(IPathway path, IAnnotationService annotation, List<PathWalker> vehicles)
     :base(annotation)
 {
     Path = path;
     _vehicles = vehicles;
 }
Пример #31
0
        private void treeView2_AfterSelect(object sender, TreeViewEventArgs e)
        {
            Object tag = tree_Aux_Fuel_Pathways.SelectedNode.Tag;

            if (tag is IPathway)
            {
                IData     data         = APIcontroller.getData();
                IPathway  path         = tag as IPathway;
                IResource resourceUsed = APIcontroller.getResourceUsed(path);

                // Gets the fuel used in the auxiliary engine to display to the user.
                auxFuelUsed = APIcontroller.getFuelUsed(path);

                IResults pathwayResults = APIcontroller.getPathwayResults(data, path);

                // These numbers will be used in calculations below, and are based on whether or not the user has tried to edit GREET resource variables
                double resourceDensity           = APIcontroller.getResourceDensity(resourceUsed);
                double resourceSulfurRatio       = APIcontroller.getResourceSulfurRatio(resourceUsed);
                double resourceLowerHeatingValue = APIcontroller.getResourceLowerHeatingValue(resourceUsed);
                double resourceCarbonRatio       = APIcontroller.getResourceCarbonRatio(resourceUsed);

                double[] aux_fuel_type = new double[7];

                if (auxFuelUsed.Equals("Conventional Diesel"))
                {
                    Array.Copy(teams_sheet.Aux_Diesel, aux_fuel_type, teams_sheet.Aux_Diesel.Length);
                }
                else if (auxFuelUsed.Equals("Residual Oil"))
                {
                    Array.Copy(teams_sheet.Aux_Residual_Oil, aux_fuel_type, teams_sheet.Aux_Residual_Oil.Length);
                }
                else if (auxFuelUsed.Equals("Low-Sulfur Diesel"))
                {
                    Array.Copy(teams_sheet.Aux_Ult_Low_Sulf, aux_fuel_type, teams_sheet.Aux_Ult_Low_Sulf.Length);
                }
                else if (auxFuelUsed.Equals("Liquefied Natural Gas"))
                {
                    Array.Copy(teams_sheet.Aux_Natural_Gas, aux_fuel_type, teams_sheet.Aux_Natural_Gas.Length);
                }
                else if (auxFuelUsed.Equals("Biodiesel"))
                {
                    Array.Copy(teams_sheet.Aux_Biodiesel, aux_fuel_type, teams_sheet.Aux_Biodiesel.Length);
                }
                else
                {
                    Array.Copy(teams_sheet.Aux_Fischer, aux_fuel_type, teams_sheet.Aux_Fischer.Length);
                }

                teams_sheet.AuxEngineGALLONperTrip = (1 / resourceLowerHeatingValue) * GALLONS_PER_CUBIC_METER * JOULES_PER_MMBTU * teams_sheet.AuxEngineMMBTUinperTrip;

                AUX_TE_WTP = teams_sheet.AuxEngineMMBTUinperTrip * APIcontroller.getSumAllLifeCycleResources(pathwayResults) - 1 - teams_sheet.AuxEngineMMBTUinperTrip;

                AUX_TE_VO = teams_sheet.AuxEngineMMBTUinperTrip;
                TE_Total  = TE_WTP + TE_VO + AUX_TE_WTP + AUX_TE_VO;

                // TODO: Implement Fossil Fuels and Petroleum Fuels
                // Fossil Fuels in WTP =  mmbtuin * a greet energy WTP value
                //AUX_FF_WTP = teams_sheet.AuxEngineMMBTUinperTrip * pathwayResults.LifeCycleResourcesGroups(data).ElementAt(0).Value.Value;
                //FF_Total = FF_WTP + FF_VO + AUX_FF_WTP + AUX_FF_VO;
                AUX_FF_WTP = 0;
                FF_Total   = 0;

                // Petroleum Fuel in WTP =  mmbtuin * a greet energy WTP value
                //AUX_PF_WTP = teams_sheet.AuxEngineMMBTUinperTrip * pathwayResults.LifeCycleResourcesGroups(data).ElementAt(2).Value.Value;
                //PF_Total = PF_WTP + PF_VO + AUX_PF_WTP + AUX_PF_VO;
                AUX_PF_WTP = 0;
                PF_Total   = 0;

                AUX_VOC_WTP = APIcontroller.getResourceWTPEmissions(pathwayResults, 0) * teams_sheet.MMBTUinperTrip;
                AUX_VOC_VO  = aux_fuel_type[0] * (1 / KWHRS_PER_HPHR) * teams_sheet.AuxEngineKWHoutperTrip;
                VOC_Total   = VOC_WTP + VOC_VO + AUX_VOC_WTP + AUX_VOC_VO;

                AUX_CO_WTP = APIcontroller.getResourceWTPEmissions(pathwayResults, 1) * teams_sheet.MMBTUinperTrip;
                AUX_CO_VO  = aux_fuel_type[1] * (1 / KWHRS_PER_HPHR) * teams_sheet.AuxEngineKWHoutperTrip;
                CO_Total   = CO_WTP + CO_VO + AUX_CO_WTP + AUX_CO_VO;

                AUX_NOx_WTP = APIcontroller.getResourceWTPEmissions(pathwayResults, 2) * teams_sheet.MMBTUinperTrip;
                AUX_NOx_VO  = aux_fuel_type[2] * (1 / KWHRS_PER_HPHR) * teams_sheet.AuxEngineKWHoutperTrip;
                NOx_Total   = NOx_WTP + NOx_VO + AUX_NOx_WTP + AUX_NOx_VO;

                AUX_PM10_WTP = APIcontroller.getResourceWTPEmissions(pathwayResults, 3) * teams_sheet.MMBTUinperTrip;
                AUX_PM10_VO  = aux_fuel_type[3] * (1 / KWHRS_PER_HPHR) * teams_sheet.AuxEngineKWHoutperTrip;
                PM10_Total   = PM10_WTP + PM10_VO + AUX_PM10_WTP + AUX_PM10_VO;

                AUX_PM25_WTP = APIcontroller.getResourceWTPEmissions(pathwayResults, 4) * teams_sheet.MMBTUinperTrip;
                AUX_PM25_VO  = aux_fuel_type[4] * (1 / KWHRS_PER_HPHR) * teams_sheet.AuxEngineKWHoutperTrip;
                PM25_Total   = PM25_WTP + PM25_VO + AUX_PM25_WTP + AUX_PM25_VO;

                AUX_SOx_WTP = APIcontroller.getResourceWTPEmissions(pathwayResults, 5) * teams_sheet.MMBTUinperTrip;
                AUX_SOx_VO  = resourceDensity * resourceSulfurRatio * GRAMS_PER_KILOGRAM * (1 / GALLONS_PER_CUBIC_METER) * GRAMS_SOX_PER_GRAMS_S * teams_sheet.AuxEngineGALLONperTrip;
                SOx_Total   = SOx_WTP + SOx_VO + AUX_SOx_WTP + AUX_SOx_VO;

                AUX_CH4_WTP = APIcontroller.getResourceWTPEmissions(pathwayResults, 6) * teams_sheet.MMBTUinperTrip;
                AUX_CH4_VO  = aux_fuel_type[5] * (1 / KWHRS_PER_HPHR) * teams_sheet.AuxEngineKWHoutperTrip;
                CH4_Total   = CH4_WTP + CH4_VO + AUX_CH4_WTP + AUX_CH4_VO;

                double gramsOfFuel = (1 / resourceLowerHeatingValue) * resourceDensity * JOULES_PER_MMBTU * GRAMS_PER_KILOGRAM * teams_sheet.AuxEngineMMBTUinperTrip;
                AUX_CO2_WTP = APIcontroller.getResourceWTPEmissions(pathwayResults, 8) * teams_sheet.MMBTUinperTrip;
                AUX_CO2_VO  = gramsOfFuel * resourceCarbonRatio * (44 / 12);
                CO2_Total   = CO2_WTP + CO2_VO + AUX_CO2_WTP + AUX_CO2_VO;

                AUX_N2O_WTP = APIcontroller.getResourceWTPEmissions(pathwayResults, 7) * teams_sheet.MMBTUinperTrip;
                AUX_N2O_VO  = aux_fuel_type[6] * (1 / KWHRS_PER_HPHR) * teams_sheet.AuxEngineKWHoutperTrip;
                N2O_Total   = N2O_WTP + N2O_VO + AUX_N2O_WTP + AUX_N2O_VO;
            }
            setLabels();
        }
 /// <summary>
 /// Gets the main, general fuel used after a specific pathway is selected. i.e. "Conventional Diesel"
 /// </summary>
 /// <param name="pathway">The specific pathway selected</param>
 /// <returns>A strong of the general fuel used</returns>
 public string getFuelUsed(IPathway pathway)
 {
     return getResources().AllValues.Where(item => item.Id == pathway.MainOutputResourceID).ElementAt(0).Name;
 }
Пример #33
0
 public PathWalker(IPathway path, IAnnotationService annotation, List <PathWalker> vehicles)
     : base(annotation)
 {
     Path      = path;
     _vehicles = vehicles;
 }
 /// <summary>
 /// Gets the IResults of a specified pathway from a specified data set.
 /// </summary>
 /// <param name="data">A specific data set</param>
 /// <param name="pathway">The pathway to grab results from</param>
 /// <returns>IResults from the specified pathway</returns>
 public IResults getPathwayResults(IData data, IPathway pathway) { return pathway.GetUpstreamResults(data).ElementAt(0).Value; }
Пример #35
0
        /// <summary>
        /// Something went wrong with restoring the live backup, this loads all persistence singeltons from the database (rooms, paths, spawns)
        /// </summary>
        /// <returns>success state</returns>
        public bool NewWorldFallback()
        {
            LiveData liveDataAccessor = new LiveData();

            //This means we delete the entire Current livedata dir since we're falling back.
            string currentLiveDirectory = liveDataAccessor.BaseDirectory + liveDataAccessor.CurrentDirectoryName;

            //No backup directory? No live data.
            if (Directory.Exists(currentLiveDirectory))
            {
                DirectoryInfo currentDir = new DirectoryInfo(currentLiveDirectory);

                LoggingUtility.Log("Current Live directory deleted during New World Fallback Procedures.", LogChannels.Backup, true);

                try
                {
                    currentDir.Delete(true);
                }
                catch
                {
                    //occasionally will be pissy in an async situation
                }
            }

            //Only load in stuff that is static and spawns as singleton
            //We need to pick up any places that aren't already live from the file system incase someone added them during the last session\
            foreach (IGaiaTemplate thing in TemplateCache.GetAll <IGaiaTemplate>())
            {
                IGaia entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as IGaia;
            }

            foreach (IZoneTemplate thing in TemplateCache.GetAll <IZoneTemplate>())
            {
                IZone entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as IZone;
            }

            foreach (ILocaleTemplate thing in TemplateCache.GetAll <ILocaleTemplate>())
            {
                ILocale entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as ILocale;

                entityThing.ParentLocation = entityThing.Template <ILocaleTemplate>().ParentLocation.GetLiveInstance();
                entityThing.GetFromWorldOrSpawn();
            }

            foreach (IRoomTemplate thing in TemplateCache.GetAll <IRoomTemplate>())
            {
                IRoom entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as IRoom;

                entityThing.ParentLocation = entityThing.Template <IRoomTemplate>().ParentLocation.GetLiveInstance();
                entityThing.GetFromWorldOrSpawn();
            }

            foreach (IPathwayTemplate thing in TemplateCache.GetAll <IPathwayTemplate>())
            {
                IPathway entityThing = Activator.CreateInstance(thing.EntityClass, new object[] { thing }) as IPathway;
            }

            ParseDimension();

            LoggingUtility.Log("World restored from data fallback.", LogChannels.Backup, true);

            return(true);
        }
Пример #36
0
 /// <summary>
 /// Gets the IResults of a specified pathway from a specified data set.
 /// </summary>
 /// <param name="data">A specific data set</param>
 /// <param name="pathway">The pathway to grab results from</param>
 /// <returns>IResults from the specified pathway</returns>
 public IResults getPathwayResults(IData data, IPathway pathway)
 {
     return(pathway.GetUpstreamResults(data).ElementAt(0).Value);
 }