示例#1
0
        //Called whenever the ship is forced to process its Order list.
        public void ProcessOrders()
        {
            //While the ship still has movement points and Orders remain in the list...
            while (remainingMovementPoints > 0 && orderList.Count > 0)
            {
                //Check if the Order at the front of the list is a movement Order.
                if ((orderList[0].orderType == "MovementOrder"))
                {
                    //If it is, grab a pathfinder, and clarify the Order at the front of the list as MovementOrder.
                    StellarPathfinder pathfinder = StellarPathfinderList.AssignStellarPathfinder();
                    MovementOrder     toExecute  = (MovementOrder)orderList[0];

                    //Sets the ship as moving until otherwise noted.
                    moving = true;

                    //While we're moving...
                    while (moving)
                    {
                        //Path towards the target and decrement the ship's movement points.
                        pathfinder.Path(this, toExecute.targetSystem, toExecute.targetPos);
                        remainingMovementPoints--;

                        //Check if the ship is out of movement points.
                        if (remainingMovementPoints == 0)
                        {
                            //If it has, stop moving.
                            moving = false;

                            //Then check if the target has been reached. If it has, removing the Order from the list.
                            if (toExecute.targetPos.x == currentPosInSys.x - Settings.systemRadius && toExecute.targetPos.y == currentPosInSys.y - Settings.systemRadius)
                            {
                                orderList.RemoveAt(0);
                            }
                        }
                        else
                        {
                            //Otherwise, check if the target has been reached. If it has, remove the Order from the list and stop moving.
                            //This accounts for the ship reaching the target with movement points left over.
                            if (toExecute.targetPos.x == currentPosInSys.x - Settings.systemRadius && toExecute.targetPos.y == currentPosInSys.y - Settings.systemRadius)
                            {
                                orderList.RemoveAt(0);
                                moving = false;
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        //Adds an Order to the list of Orders that the ship has.
        public void AddOrder(Order order)
        {
            //First check if the list is null.
            if (orderList == null)
            {
                //If it is, initialize it and add the Order.
                orderList = new List <Order>();
                orderList.Add(order);
            }
            else
            {
                //Otherwise just add the Order.
                orderList.Add(order);
            }

            //If the Order list has exactly one order in it, the ship was just given order, so...
            if (orderList.Count == 1)
            {
                //...check if the Order is a movement Order and that the ship can still move.
                if ((orderList[0].orderType == "MovementOrder") && remainingMovementPoints > 0)
                {
                    //Grab a pathfinder and clarify the Order as a MovementOrder.
                    StellarPathfinder pathfinder = StellarPathfinderList.AssignStellarPathfinder();
                    MovementOrder     toExecute  = (MovementOrder)orderList[0];

                    //Set the ship as moving until otherwise noted.
                    moving = true;

                    //While we're moving...
                    while (moving)
                    {
                        //Path towards the target and decrement the ship's remaining movement points.
                        pathfinder.Path(this, toExecute.targetSystem, toExecute.targetPos);
                        remainingMovementPoints--;

                        //Check if the ship has any movement points left.
                        if (remainingMovementPoints == 0)
                        {
                            //If it does not, stop moving.
                            moving = false;

                            //Check if the ship has reached the target position. If it has, remove the MovementOrder from the list of Orders.
                            if (toExecute.targetPos.x == currentPosInSys.x - Settings.systemRadius && toExecute.targetPos.y == currentPosInSys.y - Settings.systemRadius)
                            {
                                orderList.RemoveAt(0);
                            }
                        }
                        else
                        {
                            //Otherwise, check if the ship has reached the target position. If it has, remove the MovementOrder from the list of Orders and stop moving.
                            //This accounts for the possibility of the ship reaching the target with leftover movement points.
                            if (toExecute.targetPos.x == currentPosInSys.x - Settings.systemRadius && toExecute.targetPos.y == currentPosInSys.y - Settings.systemRadius)
                            {
                                orderList.RemoveAt(0);
                                moving = false;
                            }
                        }
                    }
                }
            }
        }