Ejemplo n.º 1
0
 /// <summary>Adds the provided node type to the world.</summary>
 /// <param name="nodeType">The node type to add.</param>
 public void addNodeType(NodeType nodeType)
 {
     if (nodeType.ID == null)
         nodeType.ID = getNextNodeTypeID();
     NodeTypes.Add(nodeType);
     NodeTypeByID.Add(nodeType.ID, nodeType);
 }
Ejemplo n.º 2
0
        /// <summary>Called when btnNodeTypeAddNew is clicked.</summary>
        private void btnNodeTypeAddNew_MouseLeftUp(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtNodeTypeName.Text))
            {
                showMsg("Name cannot be blank.");
                return;
            }

            for (int i = 0; i < world.NodeTypes.Count; i++)
            {
                if (world.NodeTypes[i].Name == txtNodeTypeName.Text)
                {
                    showMsg("A node type with that name already exists.");
                    return;
                }
            }

            NodeType nt = new NodeType();
            nt.Name = txtNodeTypeName.Text;
            nt.IsParent = btnNodeTypeIsParent.Pressed;
            nt.NumSegments = int.Parse(txtNodeTypeNumSegs.Text);
            nt.Radius = (FInt)double.Parse(txtNodeTypeRadius.Text);
            nt.Spacing = (FInt)double.Parse(txtNodeTypeSpacing.Text);
            nt.GenSpacing = (FInt)double.Parse(txtNodeTypeGenSpacing.Text);
            nt.SightDistance = (FInt)double.Parse(txtNodeTypeSightDistance.Text);
            nt.BuildRangeMin = (FInt)double.Parse(txtNodeTypeBuildRangeMin.Text);

            world.NodeTypes.Add(nt);
            cmbNodeTypes.Menu.addItem(nt.Name);
            cmbNodeTypes.SelectedIndex = cmbNodeTypes.Menu.Count - 1;

            // update other lists
            cmbEditorAddNodeType.Menu.addItem(nt.Name);
            cmbEditorNodeType.Menu.addItem(nt.Name);
        }
Ejemplo n.º 3
0
 /// <summary>Removes the specified node type from the world.</summary>
 /// <param name="nodeType">The node type to remove.</param>
 private void removeNodeType(NodeType nodeType)
 {
     removeNodeType(NodeTypes.IndexOf(nodeType));
 }
Ejemplo n.º 4
0
 /// <summary>Changes the settings of this node to match the provided node type.</summary>
 /// <param name="type">The type of node.</param>
 public void setNodeType(NodeType type)
 {
     NType = type;
     IsParent = type.IsParent;
     initSegArrays(type.NumSegments);
     GenSpacing = type.GenSpacing;
     Radius = type.Radius;
     SightDistance = type.SightDistance;
     Spacing = type.Spacing;
 }
Ejemplo n.º 5
0
 /// <summary>Creates a new instance of Node.</summary>
 /// <param name="inWorld">The world that contains this node.</param>
 /// <param name="nodeType">The type of node.</param>
 public Node(World inWorld, NodeType nodeType)
     : this(inWorld)
 {
     setNodeType(nodeType);
 }
Ejemplo n.º 6
0
        /// <summary>Updates all game variables in this mode.</summary>
        /// <param name="gameTime">The current game time.</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            FInt elapsed = (FInt)gameTime.ElapsedGameTime.TotalSeconds;
            hoveredNode = null;
            hoveredSeg = null;
            hoveredHotspot = null;
            Player hPlayer = null;
            Player cPlayer = null;

            foreach (Player p in map.Players)
            {
                if (p.Type == Player.PlayerType.Human)
                {
                    hPlayer = p;
                    break;
                }
            }

            foreach (Player p in map.Players)
            {
                if (p.Type == Player.PlayerType.Computer)
                {
                    cPlayer = p;
                    break;
                }
            }

            // prepare grid manager
            map.Grid.startNewUpdate(gameTime);

            // move camera
            if (Inp.Key.IsKeyDown(Keys.OemPlus))
                map.Cam.Zoom += map.Cam.Zoom * elapsed;

            if (Inp.Key.IsKeyDown(Keys.OemMinus))
                map.Cam.Zoom -= map.Cam.Zoom * elapsed;

            if (Inp.Key.IsKeyDown(Keys.A))
                map.Cam.CenterX -= (700 / map.Cam.Zoom) * elapsed;

            if (Inp.Key.IsKeyDown(Keys.D))
                map.Cam.CenterX += (700 / map.Cam.Zoom) * elapsed;

            if (Inp.Key.IsKeyDown(Keys.W))
                map.Cam.CenterY -= (700 / map.Cam.Zoom) * elapsed;

            if (Inp.Key.IsKeyDown(Keys.S))
                map.Cam.CenterY += (700 / map.Cam.Zoom) * elapsed;

            map.Cam.Zoom += (FInt)(Inp.Mse.ScrollWheelValue - Inp.OldMse.ScrollWheelValue) / (FInt)120 * (FInt).1d * map.Cam.Zoom;

            map.Cam.refreshCorners();

            // get cursor world coordinates
            VectorF cursorPos = map.Cam.screenToWorld(new Vector2((float)Inp.Mse.X, (float)Inp.Mse.Y));

            /*/ find path
            if (!tempBool)
            {
                Node fromNode = cPlayer.Nodes[cPlayer.Nodes.Count - 1];
                VectorF fromPos = fromNode.Pos;

                // find path
                VectorF nde = fromPos / cPlayer.Path.NodeSpacing;
                nde.X = (FInt)Math.Round((double)nde.X);
                nde.Y = (FInt)Math.Round((double)nde.Y);
                int srcNode = (int)nde.Y * cPlayer.Path.NumCols + (int)nde.X;

                nde = (hPlayer.Nodes[0].Pos + hPlayer.Nodes[1].Pos) / FInt.F2 / cPlayer.Path.NodeSpacing;
                nde.X = (FInt)Math.Round((double)nde.X);
                nde.Y = (FInt)Math.Round((double)nde.Y);
                int destNode = (int)nde.Y * cPlayer.Path.NumCols + (int)nde.X;

                shortest = cPlayer.Path.search(cPlayer.Path.Nodes[srcNode], cPlayer.Path.Nodes[destNode]);

                tempBool = true;
            }*/

            if (Inp.OldMse.Position != Inp.Mse.Position)
                desktop.mouseMove(Inp.Mse.Position);

            GUI.Desktop.Event evnt = Desktop.Event.MouseRightUp;
            bool evntHappened = true;
            if (Inp.OldMse.LeftButton == ButtonState.Pressed && Inp.Mse.LeftButton == ButtonState.Released)
                evnt = Desktop.Event.MouseLeftUp;
            else if (Inp.OldMse.LeftButton == ButtonState.Released && Inp.Mse.LeftButton == ButtonState.Pressed)
                evnt = Desktop.Event.MouseLeftDown;
            else if (Inp.OldMse.RightButton == ButtonState.Pressed && Inp.Mse.RightButton == ButtonState.Released)
                evnt = Desktop.Event.MouseRightUp;
            else if (Inp.OldMse.RightButton == ButtonState.Released && Inp.Mse.RightButton == ButtonState.Pressed)
                evnt = Desktop.Event.MouseRightUp;
            else
                evntHappened = false;

            if (selectedNode != null)
                hoveredHotspot = map.HotspotAtPoint(cursorPos);

            if (selectedNode == null && evntHappened && desktop.PerformMouseEvent(evnt, Inp.Mse.Position, Inp))
            {
                hoveredNode = null;
            }
            else
            {
                // check for hovered node and segment
                hoveredNode = map.NodeAtPoint(cursorPos, true);
                hoveredSeg = (hoveredNode == null) ? map.segmentAtPoint(cursorPos, hPlayer) : null;

                // if node is selected, determine which node type may be built at the selected distance
                selNodeType = (selectedNode == null) ? null : map.getNodeType(selectedNode.Pos, cursorPos);

                // if the user just released the left mouse button
                if (Inp.OldMse.LeftButton == ButtonState.Pressed && Inp.Mse.LeftButton == ButtonState.Released)
                {
                    if (selectedNode != null)
                    {
                        if (hoveredNode == null)
                        {
                            if (hoveredHotspot != null)
                                map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.BuildSeg, selectedNode.ID, true, hoveredHotspot.ID));
                            else if (selNodeType != null)
                                map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.BuildSeg, selectedNode.ID, false, cursorPos));
                        }
                        else if (hoveredNode != selectedNode)
                        {
                            map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.ClaimNode, selectedNode.ID, hoveredNode.ID));
                        }

                        selectedNode = null;
                    }
                }
                // user just pressed the left mouse button
                else if ((Inp.OldMse.LeftButton == ButtonState.Released && Inp.Mse.LeftButton == ButtonState.Pressed)
                    || (Inp.OldMse.RightButton == ButtonState.Released && Inp.Mse.RightButton == ButtonState.Pressed))
                {
                    if (hoveredNode != null && hoveredNode.Owner == hPlayer && (Inp.Mse.RightButton == ButtonState.Pressed || hoveredNode.NumSegments < hoveredNode.Segments.Length))
                        selectedNode = hoveredNode;
                }
                // if the left mouse button is still pressed
                else if (Inp.OldMse.LeftButton == ButtonState.Pressed && Inp.Mse.LeftButton == ButtonState.Pressed)
                {
                    if (selectedNode != null && cursorPos.Y >= FInt.F0 && cursorPos.X >= FInt.F0 && cursorPos.X < map.Width && cursorPos.Y < map.Height)
                    {
                        List<SegmentSkel> ignoreSeg = new List<SegmentSkel>(selectedNode.Segments.Length);
                        foreach (Segment seg in selectedNode.Segments)
                        {
                            if (seg != null)
                                ignoreSeg.Add(seg);
                        }

                        List<NodeSkel> ignoreNode = new List<NodeSkel>(1) { selectedNode };

                        SegmentSkel segColl;
                        NodeSkel nodeColl;
                        GeoSkel geoColl;

                        map.Collision.segCollisionIntPoint(selectedNode.Pos, cursorPos, ignoreSeg, ignoreNode, out segColl, out nodeColl, out geoColl, out intersectPoint);
                    }
                }
                // if the player just released the right mouse button
                else if (Inp.OldMse.RightButton == ButtonState.Pressed && Inp.Mse.RightButton == ButtonState.Released)
                {
                    if (selectedNode != null && hoveredNode == selectedNode)
                    {
                        map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.DestroyNode, selectedNode.ID));
                    }
                    else if (hoveredSeg != null)
                    {
                        map.PlayerActions.Add(new PlayerAction(hPlayer, PlayerAction.ActionType.SplitSeg, hoveredSeg.ID, cursorPos));
                        hoveredSeg = null;
                    }

                    selectedNode = null;
                }

                // if the player just pressed the spacebar
                else if (!Inp.OldKey.IsKeyDown(Keys.Space) && Inp.Key.IsKeyDown(Keys.Space))
                {
                    paused = !paused;
                }
            }

            // update world
            if (!paused && !cntMsgBox.Visible)
                map.update(gameTime);

            // execute action queue
            if (map.FrontEndActions.Count > 0 && !cntMsgBox.Visible)
            {
                FrontEndAction action = map.FrontEndActions.Dequeue();

                switch (action.Action)
                {
                    case FrontEndAction.ActionType.LoadMap:
                        loadWorld((string)action.Params[0]);
                        break;
                    case FrontEndAction.ActionType.Message:
                        showMsg((string)action.Params[0]);
                        break;
                }
            }
        }
Ejemplo n.º 7
0
        private static void readNodeTypeVars(List<string[]> commands, World map, Dictionary<string, NodeType> nodeTypes, List<NodeType> nodeTypeNoID)
        {
            int tempInt = 0;
            double tempDbl = 0d;

            NodeType nodeType = new NodeType();

            for (int j = 1; j < commands.Count; j++)
            {
                string value = translateValue(commands[j][2], "[NodeType]", map);
                bool valueValid = true;
                switch (commands[j][0])
                {
                    case "ID":
                        nodeType.ID = value;
                        nodeTypes.Add(value, nodeType);
                        break;
                    case "IsParent":
                        valueValid = value == "true" || value == "false";
                        nodeType.IsParent = value == "true";
                        break;
                    case "NumSegments":
                        valueValid = int.TryParse(value, out tempInt);
                        nodeType.NumSegments = tempInt;
                        break;
                    case "Radius":
                        valueValid = double.TryParse(value, out tempDbl);
                        nodeType.Radius = (FInt)tempDbl;
                        break;
                    case "Spacing":
                        valueValid = double.TryParse(value, out tempDbl);
                        nodeType.Spacing = (FInt)tempDbl;
                        break;
                    case "GenSpacing":
                        valueValid = double.TryParse(value, out tempDbl);
                        nodeType.GenSpacing = (FInt)tempDbl;
                        break;
                    case "SightDistance":
                        valueValid = double.TryParse(value, out tempDbl);
                        nodeType.SightDistance = (FInt)tempDbl;
                        break;
                    case "BuildRangeMin":
                        valueValid = double.TryParse(value, out tempDbl);
                        nodeType.BuildRangeMin = (FInt)tempDbl;
                        break;
                    case "Name":
                        nodeType.Name = value;
                        break;
                    default:
                        throw new Exception("NodeType variable not recognized: " + commands[j][0]);
                }

                if (!valueValid)
                    throw new Exception("Value '" + commands[j][2] + "' not valid.");
            }

            if (nodeType.ID != null)
                map.addNodeType(nodeType);
            else
                nodeTypeNoID.Add(nodeType);
        }