Exemplo n.º 1
0
        public void RenderGame(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.ScaleTransform(Graphx.Scale, Graphx.Scale);
            g.TranslateTransform(Graphx.DeltaX, Graphx.DeltaY);

            Graphx.RenderCells(g, world);
            Graphx.RenderGameWorld(g, world, btms.Get("grass"));
            Graphx.ShowHoveredCell(g, Graphx.GetBrushByState(loop.gameState));
            Graphx.ShowWorldCoords(g);
        }
Exemplo n.º 2
0
        public void AddActions(InputController <Form1> input)
        {
            input.AddAction(Keys.Right, () => Graphx.DeltaX -= Graphx.CameraSpeed);
            input.AddAction(Keys.Left, () => Graphx.DeltaX  += Graphx.CameraSpeed);
            input.AddAction(Keys.Up, () => Graphx.DeltaY    += Graphx.CameraSpeed);
            input.AddAction(Keys.Down, () => Graphx.DeltaY  -= Graphx.CameraSpeed);

            input.AddAction(Keys.Escape, () => loop.ProcessEsc());
            input.AddAction("build", () => {
                var c = Graphx.CursorToWorldCoords();

                if (world.playerData[world.playerCompanyName].money > 0)
                {
                    world.Build(world.playerCompanyName, Graphx.CursorToWorldCoords(), loop.infraBuilder.Invoke());
                    world.playerData[world.playerCompanyName].money -= loop.infraBuilder.Invoke().price;
                    UpdateMoney();
                }
            });
        }
Exemplo n.º 3
0
        public Structure[] webService_GetStructures(Graphx graph, long[] ids)
        {
            if (ids.Length == 0)
                return new Structure[0];

            // connect to the structure webservice
            Structure[] FoundStructures = GetStructuresByIDs(ids, true);

            List<long> ListMissingChildrenIDs = new List<long>();

            //Add the root structure to nodelist if it not already added
            foreach (Structure structure in FoundStructures)
            {
                if (!graph.NodeList.ContainsKey(structure.ID))
                {
                    graph.NodeList.Add(structure.ID, structure);
                }
            }

            return FoundStructures;
        }
Exemplo n.º 4
0
        public Graphx getGraph(int cellID, int numHops)
        {
            // Create a new graph
            Graphx graph = new Graphx();

            // Get all the missing nodes
            List<long> MissingNodes = new List<long>(new long[] { cellID });

            // Get the nodes and build graph for numHops
            for (int i = 0; i < numHops; i++)
            {
                MissingNodes = webService_GetHop(graph, MissingNodes.ToArray());
            }

            //Tell the graph which cells are not fully populated
            graph.FrontierNodes = MissingNodes;

            var structLocations = db.ApproximateStructureLocations();

            foreach (ApproximateStructureLocationsResult result in structLocations)
            {
                if (result == null)
                    continue;

                if (graph.NodeList.ContainsKey(result.ParentID))
                {
                    Structure structure = graph.NodeList[result.ParentID];

                    if (structure.ParentID.HasValue)
                        graph.zLocationForSynapses.Add(result.ParentID, (long)Math.Round((double)result.Z));
                    else
                    {
                        graph.locationInfo.Add(result.ParentID, new LocationInfo((double)result.X, (double)result.Y, (double)result.Z, (double)result.Radius));
                        graph.InvolvedCells.Add(result.ParentID);
                    }
                }

                if (graph.FrontierNodes.Contains(result.ParentID))
                {
                    graph.locationInfo.Add(result.ParentID, new LocationInfo((double)result.X, (double)result.Y, (double)result.Z, (double)result.Radius));
                }
            }

            return graph;
        }
Exemplo n.º 5
0
        public List<long> webService_GetHop(Graphx graph, long[] cellids)
        {
            if (cellids.Length == 0)
            {
                return new List<long>();
            }

            // Store all them missing structure ids and call webservice
            List<long> MissingRootStructureIds = new List<long>();

            foreach (long id in cellids)
            {
                // Test to see if the RootStructure is already in the nodelist
                if (!graph.NodeList.ContainsKey(id))
                {
                    MissingRootStructureIds.Add(id);
                }
            }

            Structure[] MissingStructures = webService_GetStructures(graph, MissingRootStructureIds.ToArray());

            List<long> ListMissingChildrenIDs = new List<long>();

            foreach (Structure structure in MissingStructures)
            {
                foreach (long childID in structure.ChildIDs)
                {
                    if (graph.NodeList.ContainsKey(childID) == false)
                    {
                        ListMissingChildrenIDs.Add(childID);
                    }
                }
            }

            //Find all synapses and gap junctions
            Structure[] ChildStructObjs = webService_GetStructures(graph, ListMissingChildrenIDs.ToArray());

            List<long> ListAbsentSiblings = new List<long>();

            //Find missing structures and populate the list
            foreach (Structure child in ChildStructObjs)
            {
                //Temp Hack to skip desmosomes
                if (child.TypeID == 85)
                    continue;

                foreach (StructureLink link in child.Links)
                {

                    if (!graph.NodeList.ContainsKey(link.SourceID))
                    {
                        ListAbsentSiblings.Add(link.SourceID);

                    }

                    if (!graph.NodeList.ContainsKey(link.TargetID))
                    {
                        ListAbsentSiblings.Add(link.TargetID);

                    }
                }
            }

            Structure[] SiblingStructures = webService_GetStructures(graph, ListAbsentSiblings.ToArray());

            //Find missing structures and populate the list
            foreach (Structure child in ChildStructObjs)
            {
                foreach (StructureLink link in child.Links)
                {
                    if (!graph.NodeList.ContainsKey(link.SourceID))
                    {
                        continue;
                    }

                    if (!graph.NodeList.ContainsKey(link.TargetID))
                    {
                        continue;
                    }

                    //After this point both nodes are already in the graph and we can create an edge
                    Structure SourceCell = graph.NodeList[link.SourceID];
                    Structure TargetCell = graph.NodeList[link.TargetID];

                    if (TargetCell.ParentID != null && SourceCell.ParentID != null)
                    {
                        string SourceTypeName = "";
                        if (StructureTypesDictionary.ContainsKey(SourceCell.TypeID))
                        {
                            SourceTypeName = StructureTypesDictionary[SourceCell.TypeID].Name;
                        }

                        Edgex E = new Edgex(SourceCell.ParentID.Value, TargetCell.ParentID.Value, link, SourceTypeName);
                        graph.EdgeList.Add(E);
                    }
                }
            }

            List<long> ListAbsentParents = new List<long>(SiblingStructures.Length);

            //Find a list of the parentIDs we are missing, and add them to the graph, and return them
            //so we can easily make another hop later
            foreach (Structure sibling in SiblingStructures)
            {
                if (sibling.ParentID.HasValue == false)
                    continue;

                if (graph.NodeList.ContainsKey(sibling.ParentID.Value))
                    continue;

                if (ListAbsentParents.Contains(sibling.ParentID.Value) == false)
                    ListAbsentParents.Add(sibling.ParentID.Value);
            }

            return ListAbsentParents;
        }