Example #1
0
 public Command(Hex3D sh, Hex3D th, Action a, ShipType s)
 {
     start = new Tuple<int, int, int>(sh.hexgrid.index, sh.x, sh.y);
     target = new Tuple<int, int, int>(th.hexgrid.index, th.x, th.y);
     action = a;
     shiptype = s;
     //if (shiptype.IsSubclassOf(Ship)
 }
Example #2
0
 //For moves-before-bording only
 public QueuedCommand(Ship s, Hex3D h, int offset)
 {
     agent = s;
     targetHex = h;
     order = Command.Action.Move;
     shiptype = null;
     priority = 50 + offset;
 }
Example #3
0
 public Planet(String n, Hex3D loc)
 {
     this.SetHex(loc);
     this.name = n;
     loc.defaultcolor = Color.Black;
     buildQueue = new List<Unit>();
     buildTimes = new List<int>();
     //loc.passable = false;
 }
Example #4
0
 public QueuedCommand(Command C, Galaxy g, int offset)
 {
     agent = (Unit)g.GetHex(C.start).GetGameObject();
     try
     {
         targetHex = g.GetHex(C.target);
     }
     catch (NullReferenceException) {
         targetHex = null;
     }
     order = C.action;
     shiptype = C.shiptype;
     priority = 10*(int)order+offset;
 }
Example #5
0
        public Sun(Hex3D h)
        {
            color = defaultcolor;
            SetHex(h);
            h.passable = false;
            h.defaultcolor = Color.Black;

            foreach (Hex3D n in h.getNeighbors())
            {
                n.passable = false;
                n.defaultcolor = Color.Black;

            }
        }
Example #6
0
        private List<Hex3D> Pathfinder(Hex3D s, Hex3D d)
        {
            Console.WriteLine(s.ToString() + ", " + d.ToString());
            //Assume d is occupable.
            if (s == d) {
                List<Hex3D> ret = new List<Hex3D>();
                ret.Add(d);
                return ret;
            }
            List<Hex3D> path = new List<Hex3D>();
            HashSet<Hex3D> HexFrontier = new HashSet<Hex3D>();
            HashSet<Hex3D> ExploredHexes = new HashSet<Hex3D>();
            HashSet<Hex3D> OldHexFrontier = new HashSet<Hex3D>();
            ExploredHexes.Add(d);
            OldHexFrontier.Add(d);
            d.distance = 0;
            while (true) {
                foreach (Hex3D h1 in OldHexFrontier) {
                    //Console.WriteLine("h1 is " + h1.ToString());
                    //Console.WriteLine("h1 dist is " + h1.distance);
                    foreach(Hex3D h2 in h1.getNeighbors()) {
                        //Console.WriteLine("h2 is " + h2.ToString());
                        //Console.WriteLine("h2 dist is " + h2.distance);
                        if (h2 == s)
                        {
                            Console.WriteLine("Victory!\n"+h2.distance + " vs. " + h1.distance);
                        }
                        if ((h2.distance < 0 || h2.distance > h1.distance + 1) && (h2.GetGameObject() == null || s == h2)) {
                            h2.distance = h1.distance+1;
                            h2.prev = h1;
                            HexFrontier.Add(h2);
                            ExploredHexes.Add(h2);
                        }

                    }
                }
                if (HexFrontier.Contains(s))
                    break;
                if (HexFrontier.Count == 0) {
                    foreach (Hex3D h in ExploredHexes)
                    {
                        h.distance = -1;
                        h.prev = null;
                    }
                    return null;
                }
                OldHexFrontier = HexFrontier;
                HexFrontier = new HashSet<Hex3D>();
            }
            path.Add(s);
            Hex3D cursor = s;
            while (cursor != d) {
                cursor = cursor.prev;
                path.Add(cursor);
            }
            if (d.GetGameObject() != null) {
                path.Remove(d);
            }
            foreach (Hex3D h in ExploredHexes) {
                h.distance = -1;
                h.prev = null;
            }
            return path;
        }
Example #7
0
 public Asteroid(Hex3D loc)
 {
     this.SetHex(loc);
     loc.defaultcolor = Color.Black;
     //loc.passable = false;
 }
Example #8
0
        public GameScreen(bool h, String ipstring, int numclients, Map m)
        {
            host = h;
            selectedhex = nullhex;
            if (m == null)
            {
                if (h) { map = new Map(2, 0, "test galaxy", (long)CommonRNG.rand.NextDouble()); }
                //else { map = new Map(2, numclients, "test galaxy", (long)1); }
            }
            else { map = m; }

            driver = new SlaveDriver(this); //dont use until middleman created

            if (host)
            {
                middleman = new Host(map, driver, numclients, this);
                //((Host)middleman).SendMap();
            }
            else middleman = new Client(ipstring, driver, this);

            //test for failure here

            map = driver.GetMap();

            if (map == null) { MenuManager.screen = new TitleScreen(MenuManager.batch, MenuManager.font); return; }
            Player temp = map.GetInstancePlayer();
            int num = map.players.IndexOf(temp);
            map.players[num] = map.players[0];
            map.players[0] = temp;

            if (!host) map.SetPlayer(numclients);

            galaxy = map.galaxy;
            player = map.GetInstancePlayer();
            space = map.GetHomeSystem();

            int x = Game1.device.Viewport.Width;
            int y = Game1.device.Viewport.Height;
            galaxybutton = new IconButton(new Rectangle(40, y-40, 120, 40), "GalaxyButton.png", "SystemButton.png", GalaxyClick);
            components.Add(galaxybutton);

            shipmenu = new CommandMenu(new Rectangle(x-200, y-200, 200, 200),this);
            shipmenu.AddShipStuff();
            components.Add(shipmenu);

            planetmenu = new CommandMenu(new Rectangle(x-200, y-200, 200, 200),this);

            components.Add(planetmenu);
            planetmenu.AddShipCommand(0, 0, "StarCruiserButton.png", StarCruiser.creator);
            planetmenu.AddShipCommand(2, 0, "FighterButton.png", FighterShip.creator);
            planetmenu.AddShipCommand(0, 1, "MinerButton.png", MiningShip.creator);
            planetmenu.AddShipCommand(1, 0, "ColonistButton.png", ColonyShip.creator);
            planetmenu.AddShipCommand(1, 1, "TransportButton.png", Transport.creator);
            planetmenu.AddShipCommand(1, 2, "TelescopeButton.png", Telescope.creator);
            planetmenu.AddNewCommand(0, 2, "ShieldButton.png", UpgradeClick);

            waitingmessage = new TextLine(new Rectangle(0, 20, 400, 20), "Waiting for other players.");

            //planetmenu.showbackround = false;
            //shipmenu.showbackround = false;

            statusmenu = new StatusMenu(new Rectangle(0, y - 150, 300, 150));
            statusmenu.visible = false;
            telescopemenu = new TelescopeMenu(new Rectangle(0, y - 150, 300, 150), player);
            telescopemenu.visible = false;

            topmenu = new TopMenu(new Rectangle(0, 0, x, 40), this);
            components.Add(topmenu);
        }
Example #9
0
        public void UpdateSolar()
        {
            selectedhex.color = selectedcolor;
            ((SolarSystem3D)space).sun.color = ((SolarSystem3D)space).sun.defaultcolor;

            ////////mouse stuff////////
            if (oldmousehex != null && !oldmousehex.Equals(selectedhex)) oldmousehex.color = oldmousehex.defaultcolor;

            mousehex = ((SolarSystem3D)space).GetMouseOverHex();

            if ((mousestate.LeftButton == ButtonState.Pressed) && (oldmousestate.LeftButton == ButtonState.Released) && !shipmenu.Contains(mousestate.X, mousestate.Y) && !planetmenu.Contains(mousestate.X, mousestate.Y) && !galaxybutton.Contains(mousestate.X, mousestate.Y) && mousehex != null)
            {
                //selecting a hex
                if (clickedaction == Command.Action.None)
                {
                    selectedhex = mousehex;
                }

                //selecting a target of a action
                if (clickedaction != Command.Action.None && !waiting)
                {
                    Console.WriteLine("a command");
                    if (selectedhex.GetGameObject() is Ship && clickedaction == Command.Action.Move)
                    {
                        if (!((Ship)(selectedhex.GetGameObject())).GetReachable().Contains(mousehex)) { return; }
                        ((Ship)(selectedhex.GetGameObject())).SetGhost(mousehex);
                    }
                    if (selectedhex.GetGameObject() is Warship && clickedaction == Command.Action.Fire)
                    {
                        if (!((Warship)(selectedhex.GetGameObject())).GetShootable().Contains(mousehex)) { return; }
                        //((Ship)(selectedhex.GetGameObject())).SetGhost(mousehex);
                    }

                    if (selectedhex.GetGameObject() is Warship && clickedaction == Command.Action.Colonize)
                    {
                        if (!((Warship)(selectedhex.GetGameObject())).GetReachable().Contains(mousehex)) { return; }
                        //((Ship)(selectedhex.GetGameObject())).SetGhost(mousehex);
                    }

                    if (selectedhex.GetGameObject() is Ship && clickedaction == Command.Action.Jump)
                    {
                        if (!((SolarSystem3D)(space)).GetWarpable().Contains(mousehex)) {}
                        else if (!selectedhex.GetGameObject().hex.hexgrid.neighbors.Contains((SolarSystem3D)(space))) {}
                        else
                        {
                            ((Ship)(selectedhex.GetGameObject())).SetGhost(mousehex);
                        }
                        Boolean vis = true;
                        int thresh = 0;
                        foreach (Hex3D h1 in ((SolarSystem3D)space).getHexes()) {
                            if (!h1.visible) {
                                vis = false;
                                break;
                            }
                            thresh ++;
                            if (thresh >= 10) {
                                break;
                            }
                        }
                        if (!vis) {
                            space = galaxy;
                            Console.WriteLine("BUMP");
                        }
                    }

                    middleman.AddCommand(new Command(selectedhex, mousehex, clickedaction));

                    clickedaction = Command.Action.None;
                    selectedhex = nullhex;
                }
            }

            /////stuff to do if a ship is selected/////
            GameObject selectedobject = selectedhex.GetGameObject();

            if (selectedobject != null && selectedobject is Unit) { statusmenu.Update((Unit)selectedobject); statusmenu.Show(); }
            else { statusmenu.Hide(); }

            if (selectedhex.GetGameObject() is Ship && clickedaction == Command.Action.Jump)
            {
                foreach (Hex3D h in ((SolarSystem3D)space).GetWarpable())
                {
                    h.color = Color.Blue;
                }
            }

            if (selectedobject != null && selectedobject is Ship && ((Ship)selectedobject).getAffiliation().Equals(player)) { shipmenu.Show(); }
            else { shipmenu.Hide(); }

            if (selectedobject != null && selectedobject is Warship)
            {

                foreach (Hex3D h in ((Warship)selectedobject).GetShootable())
                {
                    h.color = Color.Red;
                }
            }
            if (selectedobject != null && selectedobject is Ship)
            {
                Ship tmpShip = (Ship)selectedobject;
                if (oldShip != null && oldShip != tmpShip)
                {
                    tmpShip.shiptype.PlaySelectSound();
                }
                oldShip = tmpShip;
                foreach (Hex3D h in ((Ship)selectedobject).GetReachable())
                {
                    h.color = movecolor;
                }
            }

            ////VERY REDUNDANT, handles cases where range is smaller than speed
            if (selectedobject != null && selectedobject is Warship && ((Warship)selectedobject).GetRange() < ((Warship)selectedobject).getSpeed())
            {
                foreach (Hex3D h in ((Warship)selectedobject).GetShootable())
                {
                    h.color = Color.Red;
                }
            }

            //planetmenu
            if (selectedobject != null && selectedobject is Planet && ((Planet)selectedobject).getAffiliation() != null && ((Planet)selectedobject).getAffiliation().Equals(player)) { planetmenu.Show(); }
            else { planetmenu.Hide(); }

            //Color the mousedover hex
            if (mousehex != null && !mousehex.Equals(selectedhex) && !shipmenu.Contains(mousestate.X, mousestate.Y)) { mousehex.color = mousecolor; }

            telescopemenu.Hide();
        }
Example #10
0
        //void BuildClick(Object o, EventArgs e) { clickedaction = Command.Action.Build; }
        public void Update()
        {
            if (middleman.DriverReady()) { middleman.DriverReset(); driver.Execute(); waiting = false; }
            mousestate = Mouse.GetState();
            keystate = Keyboard.GetState();

            if (keystate.IsKeyDown(Keys.Escape) && oldkeystate.IsKeyUp(Keys.Escape)) { MenuManager.ClickTitle(this, EventArgs.Empty); middleman.Close(); }
            if (keystate.IsKeyDown(Keys.R) && oldkeystate.IsKeyUp(Keys.R)) { Save(); }

            if (keystate.IsKeyDown(Keys.Space) && oldkeystate.IsKeyUp(Keys.Space)) { waiting = true;  middleman.EndTurn(); }
            //////camera controls////
            if (keystate.IsKeyDown(Keys.Left)) { offset.X = offset.X + scrollspeed; }
            if (keystate.IsKeyDown(Keys.Right)) { offset.X = offset.X - scrollspeed; }
            if (keystate.IsKeyDown(Keys.Down)) { offset.Y = offset.Y + scrollspeed; }
            if (keystate.IsKeyDown(Keys.Up)) { offset.Y = offset.Y - scrollspeed; }

            //if (keystate.IsKeyDown(Keys.Z)) { xr += rotatespeed; }
            if (keystate.IsKeyDown(Keys.S)) { yr += rotatespeed; }
            if (keystate.IsKeyDown(Keys.D)) { zr += rotatespeed; }
            //if (keystate.IsKeyDown(Keys.A)) { xr -= rotatespeed; }
            if (keystate.IsKeyDown(Keys.W)) { yr -= rotatespeed; }
            if (keystate.IsKeyDown(Keys.A)) { zr -= rotatespeed; }

            if (keystate.IsKeyDown(Keys.Q)) { height += zoomspeed; }
            if (keystate.IsKeyDown(Keys.E)) { height -= zoomspeed; }

            if (yr > 0) { yr = 0; }
            if (yr < (-Math.PI / (float)2)) { yr = (float)(-Math.PI / (float)2); }

            space.Update(); //just resets the color of hexes
            if (space is SolarSystem3D) UpdateSolar();
            if (space is Galaxy) UpdateGalaxy();

            //update the 2d stuff
            foreach (MenuComponent c in components)
            {
                c.Update(mousestate, oldmousestate);
            }

            oldmousestate = mousestate;
            oldmousehex = mousehex;
            oldkeystate = keystate;
        }
Example #11
0
 private void Shootable(HashSet<Hex3D> hexes, Hex3D h, int r)
 {
     if (r <= 0) return;
     foreach (Hex3D n in h.getNeighbors())
     {
         hexes.Add(n);
         Shootable(hexes, n, r - 1);
     }
 }
Example #12
0
 public void SetHex(Hex3D h)
 {
     hex = h;
     h.AddObject(this);
 }
Example #13
0
 //public readonly Type shiptype;
 public Command(Hex3D sh, Hex3D th, Action a)
 {
     if( sh != null) start = new Tuple<int,int,int>(sh.hexgrid.index,sh.x,sh.y);
     if (th != null) target = new Tuple<int, int, int>(th.hexgrid.index, th.x, th.y);
     action = a;
 }
Example #14
0
        List<Hex3D> reachable(Hex3D startHex, int r)
        {
            startHex.distance = r;
            List<Hex3D> hexes = new List<Hex3D>();
            if (r <= 0)
            {
                return hexes;
            }
            foreach (Hex3D h in startHex.getNeighbors())
            {
                //if (!h.passable) continue;
                int dist = h.distance;
                if (dist == -1 || dist < r - 1)
                {
                    hexes.Add(h);
                    hexes.AddRange(reachable(h, r - 1));
                }
            }

            return hexes;
        }
Example #15
0
        public void SetGhost(Hex3D target)
        {
            //Console.WriteLine("setting ghost");

            double x = target.getCenter().X - hex.getCenter().X;
            double y = hex.getCenter().Y - target.getCenter().Y;
            targetangle = Math.Atan(x / y);
            //Console.WriteLine(" x  " + x);
            //Console.WriteLine(" y " + y);
            if (y < 0) targetangle = targetangle + Math.PI;
            //Console.WriteLine("angle -> " + targetangle);

            if (ghosthex != null) ghosthex.SetGhostObject(null);
            ghosthex = target;
            target.SetGhostObject(this);
            if (this.hex.hexgrid == ghosthex.hexgrid)
            {
                //Console.WriteLine("creating new linemodel");
                line = new LineModel(getCenter(), ghosthex.getCenter());
            }
        }
Example #16
0
        public void move(Hex3D target)
        {
            hex.RemoveObject();
            //oldposition = hex.getCenter();
            //percenttraveled = 0;

            if (ghosthex != null) ghosthex.ClearGhostObject();
            line = null;
            targetpositions.Enqueue(target.getCenter());

            double x = target.getCenter().X - hex.getCenter().X;
            double y = hex.getCenter().Y - target.getCenter().Y;
            double newangle = Math.Atan(x / y);
            //Console.WriteLine(" x  " + x);
            //Console.WriteLine(" y " + y);
            if (y < 0) newangle = newangle + Math.PI;
            //Console.WriteLine("angle -> " + newangle);
            targetangles.Enqueue(newangle);

            SetHex(target);
        }