Exemplo n.º 1
0
 /// <summary>Creates a new <see cref="Route"/> instance, based on another <see cref="Route"/>.
 /// The <see cref="Province"/> is added on to the end of the new <see cref="Route"/>.
 /// </summary>
 /// <param name="route">Route.</param>
 /// <param name="province">Province.</param>
 public Route(Route route, Province province)
     : this(route)
 {
     this.route.Add(province);
 }
Exemplo n.º 2
0
        private void PopulateMoveByConvoyOrders(Unit unit, Dictionary<Unit, List<UnitOrderMetaData>> allOrders)
        {
            List<UnitOrderMetaData> orders = allOrders[unit];

            if( unit.UnitType != UnitType.Army
                || !unit.Province.IsCoastal )
            {
                return;
            }

            //We've found an army that is placed in a coastal territory!

            //Find all sea-provinces that have fleets in them
            Route route = new Route(unit.Province);
            Queue<Route> routesToSearch = new Queue<Route>();
            foreach( Province province in unit.Location.AdjacentProvinces )
            {
                routesToSearch.Enqueue(new Route(route, province));
            }

            while( routesToSearch.Count > 0 )
            {
                Route aRoute = (Route)routesToSearch.Dequeue();
                if( aRoute.End.IsSea	//It's a sea province
                    && aRoute.End.Unit != null )	//There's a fleet there
                {
                    foreach( Province adjacentProvince in aRoute.End.AdjacentProvinces )
                    {
                        //Make sure that we do not end up in a never-ending loop.
                        if( !aRoute.Provinces.Contains(adjacentProvince) )
                        {
                            routesToSearch.Enqueue(new Route(aRoute, adjacentProvince));
                        }
                    }
                }
                else if( aRoute.End.IsCoastal	//A coastal territory
                    && aRoute.Provinces.Count >= 3 )	//We've gone at least one step on water!
                {
                    UnitOrderMetaData orderMeta = new UnitOrderMetaData(
                        new MoveByConvoyOrder(unit, aRoute));
                    Route via = aRoute.Via;

                    List<UnitOrderMetaData> conveyOrders = new List<UnitOrderMetaData>();
                    for( int index = 0; index < via.Provinces.Count; ++index )
                    {
                        Unit convoyingUnit = via.Provinces[index].Unit;

                        UnitOrderMetaData conveyMeta = new UnitOrderMetaData(
                            new ConveyOrder(convoyingUnit, unit, aRoute.End));

                        //Schedule the convoy order for updates regarding it's dependent orders.
                        conveyOrders.Add(conveyMeta);

                        //Add the convoy order to the conveying unit.
                        //This means that we do not have to look at fleet to add their
                        //convoy orders, since they've been added for all convoyed armies!
                        List<UnitOrderMetaData> convoyUnitOrders = allOrders[convoyingUnit];
                        convoyUnitOrders.Add(conveyMeta);

                        orderMeta.RequiredOrders.Add(conveyMeta);
                    }

                    //Finalize the convey orders.
                    foreach( UnitOrderMetaData conveyOrder in conveyOrders )
                    {
                        conveyOrder.RequiredOrders.Add(orderMeta);
                        conveyOrder.RequiredOrders.AddRange(conveyOrders);
                        conveyOrder.RequiredOrders.Remove(conveyOrder);	//Remove yourself from the list!
                    }

                    orders.Add(orderMeta);
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>Creates a new <see cref="Route"/> instance, based on another <see cref="Route"/>.
 /// </summary>
 /// <param name="route">Route.</param>
 public Route(Route route)
 {
     Robustness.ValidateArgumentNotNull("route", route);
     this.route = new ProvinceCollection(route.route);
 }