Example #1
0
        /// <summary>
        /// Called when the game starts, providing all info.
        /// </summary>
        public void Setup(GameMap map, Player me, List<Player> players, List<Company> companies, List<Passenger> passengers, PlayerAIBase.PlayerOrdersEvent ordersEvent)
        {
            sendOrders = ordersEvent;

            XDocument doc = new XDocument();
            XElement elemRoot = new XElement("setup", new XAttribute("game-start", true), new XAttribute("my-guid", me.Guid));
            doc.Add(elemRoot);

            // the map
            XElement elemMap = new XElement("map", new XAttribute("width", map.Width), new XAttribute("height", map.Height), new XAttribute("units-tile", TileMovement.UNITS_PER_TILE));
            elemRoot.Add(elemMap);
            for (int x = 0; x < map.Width; x++ )
                for (int y = 0; y < map.Height; y++)
                {
                    MapSquare square = map.Squares[x][y];
                    XElement elemRow = new XElement("tile", new XAttribute("x", x), new XAttribute("y", y),
                                                    new XAttribute("type", square.Tile.Type));
                    if (square.Tile.IsDriveable)
                    {
                        elemRow.Add(new XAttribute("direction", square.Tile.Direction));
                        if (square.StopSigns != MapSquare.STOP_SIGNS.NONE)
                            elemRow.Add(new XAttribute("stop-sign", square.StopSigns));
                        if (square.SignalDirection != MapSquare.SIGNAL_DIRECTION.NONE)
                            elemRow.Add(new XAttribute("signal", true));
                    }
                    elemMap.Add(elemRow);
                }

            // all players (including me)
            XElement elemPlayers = new XElement("players");
            elemRoot.Add(elemPlayers);
            foreach (Player plyrOn in players)
                elemPlayers.Add(new XElement("player", new XAttribute("guid", plyrOn.Guid),
                                                   new XAttribute("name", plyrOn.Name),
                                                   new XAttribute("limo-x", plyrOn.Limo.Location.TilePosition.X),
                                                   new XAttribute("limo-y", plyrOn.Limo.Location.TilePosition.Y),
                                                   new XAttribute("limo-angle", plyrOn.Limo.Location.Angle)));

            // all companies
            XElement elemCompanies = new XElement("companies");
            elemRoot.Add(elemCompanies);
            foreach (Company cmpnyOn in companies)
                elemCompanies.Add(new XElement("company", new XAttribute("name", cmpnyOn.Name),
                            new XAttribute("bus-stop-x", cmpnyOn.BusStop.X), new XAttribute("bus-stop-y", cmpnyOn.BusStop.Y)));

            // all passengers
            XElement elemPassengers = new XElement("passengers");
            elemRoot.Add(elemPassengers);
            foreach (Passenger psngrOn in passengers)
            {
                XElement elemPassenger = new XElement("passenger", new XAttribute("name", psngrOn.Name), new XAttribute("points-delivered", psngrOn.PointsDelivered));
                // if due to a re-start, these can be null
                if (psngrOn.Lobby != null)
                    elemPassenger.Add(new XAttribute("lobby", psngrOn.Lobby.Name));
                if (psngrOn.Destination != null)
                    elemPassenger.Add(new XAttribute("destination", psngrOn.Destination.Name));
                foreach (Company route in psngrOn.Companies)
                    elemPassenger.Add(new XElement("route", route.Name));
                foreach (Passenger enemy in psngrOn.Enemies)
                    elemPassenger.Add(new XElement("enemy", enemy.Name));
                elemPassengers.Add(elemPassenger);
            }

            framework.tcpServer.SendMessage(TcpGuid, doc.ToString());
        }
Example #2
0
            public AiWorker(GameMap gameMap, string myPlayerGuid, List<Company> companies, PlayerAIBase.PlayerOrdersEvent sendOrders)
            {
                this.gameMap = gameMap;
                MyPlayerGuid = myPlayerGuid;
                Companies = companies;
                this.sendOrders = sendOrders;
                messages = new Queue<StatusMessage>();

                // get it ready to handle events.
                EventThread = new AutoResetEvent(false);
                ExitThread = false;
            }
Example #3
0
        /// <summary>
        /// Called at the start of the game.
        /// </summary>
        /// <param name="map">The game map.</param>
        /// <param name="me">You. This is also in the players list.</param>
        /// <param name="players">All players (including you).</param>
        /// <param name="companies">The companies on the map.</param>
        /// <param name="passengers">The passengers that need a lift.</param>
        /// <param name="ordersEvent">Method to call to send orders to the server.</param>
        public void Setup(Map map, Player me, List<Player> players, List<Company> companies, List<Passenger> passengers,
            PlayerAIBase.PlayerOrdersEvent ordersEvent)
        {
            try
            {
                pFinder = new PathFinder();
                GameMap = map;
                GameInfo = new GameStatusInfo();
                GameInfo.Setup(map, pFinder);
                Players = players;
                Me = me;
                Companies = companies;
                Passengers = passengers;
                sendOrders = ordersEvent;

                List<Passenger> pickup = AllPickups(me, passengers);
                pFinder.computeAllPaths(map);
                pFinder.generateAdjacencyMatrix();

                // get the path from where we are to the dest.
                List<Point> path = CalculatePathPlus1(me, pickup[0].Lobby.BusStop);
                sendOrders("ready", path, pickup);
            }
            catch (Exception ex)
            {
                log.Fatal(string.Format("Setup({0}, ...", me == null ? "{null}" : me.Name), ex);
            }
        }