public UnitConfiguration(SerializationInputStream Stream)
        {
            UniqueKey = Stream.ReadString();
            Name      = Stream.ReadString();
            UnitClass = (UnitClass)Stream.ReadByte();

            PrimaryWeapon   = new Weapon(Stream);
            SecondaryWeapon = new Weapon(Stream);
            Defense         = Stream.ReadByte();
            Movement        = Stream.ReadByte();

            CanDirectFire            = Stream.ReadBoolean();
            CanIndirectFire          = Stream.ReadBoolean();
            CanOverrun               = Stream.ReadBoolean();
            CanCloseAssault          = Stream.ReadBoolean();
            CanAirAttack             = Stream.ReadBoolean();
            CanAntiAircraft          = Stream.ReadBoolean();
            CanClearMines            = Stream.ReadBoolean();
            CanPlaceMines            = Stream.ReadBoolean();
            CanPlaceBridges          = Stream.ReadBoolean();
            InnatelyClearsMines      = Stream.ReadBoolean();
            ImmuneToMines            = Stream.ReadBoolean();
            MinimumIndirectFireRange = Stream.ReadByte();

            IsVehicle     = Stream.ReadBoolean();
            IsArmored     = Stream.ReadBoolean();
            WrecksAs      = Stream.ReadObject(i => new UnitConfiguration(i), true, true);
            UnitWeight    = (UnitWeight)Stream.ReadByte();
            IsEngineer    = Stream.ReadBoolean();
            IsParatroop   = Stream.ReadBoolean();
            IsCommando    = Stream.ReadBoolean();
            HasLowProfile = Stream.ReadBoolean();

            MovementRules = Stream.ReadObject(i => new UnitMovementRules(i), false, true);

            IsCarrier                  = Stream.ReadBoolean();
            UnloadsWhenDisrupted       = Stream.ReadBoolean();
            CanOnlyCarryInfantry       = Stream.ReadBoolean();
            CanOnlyCarryLight          = Stream.ReadBoolean();
            CanCarryInWater            = Stream.ReadBoolean();
            CanOnlyOverrunUnarmored    = Stream.ReadBoolean();
            CanOnlySupportCloseAssault = Stream.ReadBoolean();
            IsPassenger                = Stream.ReadBoolean();
            IsOversizedPassenger       = Stream.ReadBoolean();
            CannotUseRoadMovementWithOversizedPassenger = Stream.ReadBoolean();
            OversizedPassengerMovementMultiplier        = Stream.ReadFloat();
            WaterDieModifier = Stream.ReadInt32();

            CanReveal  = Stream.ReadBoolean();
            CanSpot    = Stream.ReadBoolean();
            SpotRange  = Stream.ReadByte();
            SightRange = Stream.ReadByte();

            DismountAs = Stream.ReadObject(i => new UnitConfiguration(i), true, true);
            CanRemount = Stream.ReadBoolean();

            CanSupportArmored   = Stream.ReadBoolean();
            CloseAssaultCapture = Stream.ReadBoolean();
            AreaControlCapture  = Stream.ReadBoolean();
        }
예제 #2
0
 public UnitConfigurationLink(SerializationInputStream Stream)
 {
     UniqueKey         = Stream.ReadString();
     Faction           = Stream.ReadObject(i => new Faction(i), false, true);
     UnitConfiguration = Stream.ReadObject(i => new UnitConfiguration(i), false, true);
     Constraints       = new UnitConstraints(Stream);
 }
예제 #3
0
        public UnitCount(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            UnitConfiguration = (UnitConfiguration)attributes[(int)Attribute.UNIT_CONFIGURATION];
            Count             = (int)attributes[(int)Attribute.COUNT];
        }
예제 #4
0
        public UnitConfigurationLink(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            UniqueKey         = Block.Name;
            Faction           = (Faction)attributes[(int)Attribute.FACTION];
            UnitConfiguration = (UnitConfiguration)attributes[(int)Attribute.UNIT_CONFIGURATION];
            Constraints       = (UnitConstraints)(attributes[(int)Attribute.CONSTRAINTS] ?? new UnitConstraints());
        }
 public OrderInvalidReason CanLoad(UnitConfiguration UnitConfiguration)
 {
     if (!IsCarrier ||
         !UnitConfiguration.IsPassenger ||
         (CanOnlyCarryInfantry && UnitConfiguration.UnitClass != UnitClass.INFANTRY) ||
         (CanOnlyCarryLight && UnitConfiguration.UnitWeight > UnitWeight.LIGHT))
     {
         return(OrderInvalidReason.UNIT_NO_CARRY);
     }
     return(OrderInvalidReason.NONE);
 }
        public GroupedUnitSelectionOption(
            string ClassName, string OverlayClassName, IEnumerable <Unit> Units, UnitConfigurationRenderer Renderer)
            : base(ClassName)
        {
            UnitConfiguration = Units.First().Configuration;

            _StackView = new HomogenousStackView(
                Units, Renderer, Class.GetAttributeWithDefault("unit-scale", 0), OverlayClassName);
            _StackView.Position = Size / 2;
            _StackView.Parent   = this;
            Value = _StackView;
        }
예제 #7
0
 public Unit(Army Army, UnitConfiguration UnitConfiguration, IdGenerator IdGenerator)
 {
     this.Army          = Army;
     _BaseConfiguration = UnitConfiguration;
     if (UnitConfiguration.PrimaryWeapon.Ammunition > 0)
     {
         _PrimaryAmmunition = UnitConfiguration.PrimaryWeapon.Ammunition;
     }
     if (UnitConfiguration.SecondaryWeapon.Ammunition > 0)
     {
         _SecondaryAmmunition = UnitConfiguration.SecondaryWeapon.Ammunition;
     }
     Id = IdGenerator.GenerateId();
 }
 public UnitConfigurationStackView(
     UnitConfiguration UnitConfiguration,
     Faction Faction,
     UnitConfigurationRenderer Renderer,
     int UnitScale,
     string OverlayClassName,
     bool DisplayCount)
 {
     _DisplayCount          = DisplayCount;
     _UnitConfigurationView = new UnitConfigurationView(UnitConfiguration, Faction, Renderer, UnitScale);
     if (_DisplayCount)
     {
         _Text          = new Button(OverlayClassName);
         _Text.Position = -.5f * new Vector2f(UnitScale, _Text.Size.Y);
         _Text.Parent   = this;
     }
 }
예제 #9
0
        protected UnitInfoPaneBase(
            UnitConfiguration UnitConfiguration, Faction Faction, UnitConfigurationRenderer Renderer)
            : base("unit-info-pane")
        {
            _UnitConfiguration = UnitConfiguration;
            _Faction           = Faction;

            _CloseButton.Position = new Vector2f(Size.X - _CloseButton.Size.X - LeftPadding.X * 2, 0);
            _CloseButton.OnClick += HandleClose;

            _UnitConfigurationView          = new UnitConfigurationView(UnitConfiguration, Faction, Renderer, 192);
            _UnitConfigurationView.Position = new Vector2f(144, 96);

            Add(_CloseButton);
            Add(_UnitConfigurationView);
            Add(_Info);
        }
예제 #10
0
        public UnitConfigurationInfoPane(
            UnitConfiguration UnitConfiguration, Faction Faction, UnitConfigurationRenderer Renderer)
            : base(UnitConfiguration, Faction, Renderer)
        {
            _Info.Add(new Button("unit-info-header")
            {
                DisplayedString = ObjectDescriber.Describe(UnitConfiguration)
            });

            AddBasicAttributes();
            AddComposition();
            AddCombatCapabilities();
            AddSightCapabilities();
            AddTransportCapabilities();
            AddMovementAttributes();
            AddMountedInfantryAttributes();
        }
예제 #11
0
 public bool Covers(UnitConfiguration Configuration)
 {
     return(UnitClass == UnitClass.FORT &&
            Configuration.UnitClass != UnitClass.FIGHTER_BOMBER &&
            Defense > Configuration.Defense);
 }
예제 #12
0
        public UnitConfiguration(ParseBlock Block)
        {
            var attributes = Block.BreakToAttributes <object>(typeof(Attribute));

            UniqueKey = Block.Name;
            Name      = (string)attributes[(int)Attribute.NAME];
            UnitClass = (UnitClass)attributes[(int)Attribute.UNIT_CLASS];

            var weaponClass    = (WeaponClass)(attributes[(int)Attribute.WEAPON_CLASS] ?? WeaponClass.NA);
            var attack         = (byte)(attributes[(int)Attribute.ATTACK] ?? (byte)0);
            var range          = (byte)(attributes[(int)Attribute.RANGE] ?? (byte)0);
            var canDoubleRange = (bool)(attributes[(int)Attribute.CAN_DOUBLE_RANGE] ?? false);

            PrimaryWeapon = (Weapon)(
                attributes[(int)Attribute.PRIMARY_WEAPON] ?? new Weapon(weaponClass, attack, range, canDoubleRange, 0));
            SecondaryWeapon = (Weapon)(attributes[(int)Attribute.SECONDARY_WEAPON] ?? default(Weapon));
            Defense         = (byte)attributes[(int)Attribute.DEFENSE];
            Movement        = (byte)(attributes[(int)Attribute.MOVEMENT] ?? (byte)(IsAircraft() ? byte.MaxValue : 0));
            IsVehicle       = (bool)(
                attributes[(int)Attribute.IS_VEHICLE] ??
                (IsAircraft() ||
                 UnitClass == UnitClass.AMPHIBIOUS_VEHICLE ||
                 UnitClass == UnitClass.ASSAULT_GUN ||
                 UnitClass == UnitClass.ENGINEER_VEHICLE ||
                 UnitClass == UnitClass.FLAME_TANK ||
                 UnitClass == UnitClass.RECONNAISSANCE_VEHICLE ||
                 UnitClass == UnitClass.SELF_PROPELLED_ARTILLERY ||
                 UnitClass == UnitClass.TANK ||
                 UnitClass == UnitClass.TANK_DESTROYER ||
                 UnitClass == UnitClass.TRANSPORT ||
                 UnitClass == UnitClass.WRECKAGE));
            IsArmored = (bool)(
                attributes[(int)Attribute.IS_ARMORED] ??
                ((IsVehicle && UnitClass != UnitClass.TRANSPORT && !IsAircraft()) || UnitClass == UnitClass.FORT));
            var wrecksAs = (string)(attributes[(int)Attribute.WRECKS_AS] ?? GetDefaultWreck());

            WrecksAs      = wrecksAs == string.Empty ? null : Block.Get <UnitConfiguration>(wrecksAs);
            UnitWeight    = (UnitWeight)(attributes[(int)Attribute.UNIT_WEIGHT] ?? GetDefaultUnitWeight());
            IsParatroop   = (bool)(attributes[(int)Attribute.IS_PARATROOP] ?? false);
            IsCommando    = (bool)(attributes[(int)Attribute.IS_COMMANDO] ?? false);
            HasLowProfile = (bool)(
                attributes[(int)Attribute.HAS_LOW_PROFILE] ??
                (UnitClass == UnitClass.INFANTRY ||
                 UnitClass == UnitClass.COMMAND_POST ||
                 UnitClass == UnitClass.FORT));

            MovementRules = (UnitMovementRules)(attributes[(int)Attribute.MOVEMENT_RULES]
                                                ?? Block.Get <UnitMovementRules>(GetDefaultMovementRules()));

            IsCarrier = (bool)(attributes[(int)Attribute.IS_CARRIER]
                               ?? ((IsVehicle && !IsAircraft()) || UnitClass == UnitClass.TRANSPORT));
            CanOnlyCarryInfantry = (bool)(attributes[(int)Attribute.CAN_ONLY_CARRY_INFANTRY]
                                          ?? IsCarrier && UnitClass != UnitClass.TRANSPORT);
            UnloadsWhenDisrupted = (bool)(attributes[(int)Attribute.UNLOADS_WHEN_DISRUPTED] ?? CanOnlyCarryInfantry);
            CanOnlyCarryLight    = (bool)(attributes[(int)Attribute.CAN_ONLY_CARRY_LIGHT] ?? false);
            CanCarryInWater      = (bool)(attributes[(int)Attribute.CAN_CARRY_IN_WATER] ?? false);
            IsPassenger          = (bool)(attributes[(int)Attribute.IS_PASSENGER]
                                          ?? (UnitClass == UnitClass.INFANTRY ||
                                              UnitClass == UnitClass.COMMAND_POST ||
                                              UnitClass == UnitClass.TOWED_GUN));
            IsOversizedPassenger = (bool)(attributes[(int)Attribute.IS_OVERSIZED_PASSENGER] ?? false);
            CannotUseRoadMovementWithOversizedPassenger = (bool)(
                attributes[(int)Attribute.CANNOT_USE_ROAD_MOVEMENT_WITH_OVERSIZED_PASSENGER] ?? CanOnlyCarryInfantry);
            OversizedPassengerMovementMultiplier = (float)(
                attributes[(int)Attribute.OVERSIZED_PASSENGER_MOVEMENT_MULTIPLIER] ?? 1f);
            WaterDieModifier = (int)(attributes[(int)Attribute.WATER_DIE_MODIFIER] ?? 0);

            IsEngineer    = (bool)(attributes[(int)Attribute.IS_ENGINEER] ?? false);
            CanDirectFire = (bool)(attributes[(int)Attribute.CAN_DIRECT_FIRE]
                                   ?? (PrimaryWeapon.Attack > 0 && UnitClass != UnitClass.MINEFIELD && !IsAircraft()));
            CanIndirectFire = (bool)(attributes[(int)Attribute.CAN_INDIRECT_FIRE]
                                     ?? (UnitClass == UnitClass.SELF_PROPELLED_ARTILLERY ||
                                         PrimaryWeapon.WeaponClass == WeaponClass.MORTAR));
            CanOverrun = (bool)(attributes[(int)Attribute.CAN_OVERRUN]
                                ?? (IsVehicle &&
                                    IsArmored &&
                                    UnitClass != UnitClass.SELF_PROPELLED_ARTILLERY && CanDirectFire));
            CanOnlyOverrunUnarmored = (bool)(attributes[(int)Attribute.CAN_ONLY_OVERRUN_UNARMORED]
                                             ?? (CanOverrun && PrimaryWeapon.WeaponClass == WeaponClass.INFANTRY));
            CanCloseAssault = (bool)(attributes[(int)Attribute.CAN_CLOSE_ASSAULT]
                                     ?? (UnitClass == UnitClass.INFANTRY || UnitClass == UnitClass.CAVALRY));
            CanOnlySupportCloseAssault = (bool)(attributes[(int)Attribute.CAN_ONLY_SUPPORT_CLOSE_ASSAULT] ?? false);
            CanAirAttack             = (bool)(attributes[(int)Attribute.CAN_AIR_ATTACK] ?? UnitClass == UnitClass.FIGHTER_BOMBER);
            CanAntiAircraft          = (bool)(attributes[(int)Attribute.CAN_ANTI_AIRCRAFT] ?? false);
            CanClearMines            = (bool)(attributes[(int)Attribute.CAN_CLEAR_MINES] ?? IsEngineer);
            CanPlaceMines            = (bool)(attributes[(int)Attribute.CAN_PLACE_MINES] ?? IsEngineer);
            CanPlaceBridges          = (bool)(attributes[(int)Attribute.CAN_PLACE_BRIDGES] ?? IsEngineer);
            InnatelyClearsMines      = (bool)(attributes[(int)Attribute.INNATELY_CLEARS_MINES] ?? false);
            ImmuneToMines            = (bool)(attributes[(int)Attribute.IMMUNE_TO_MINES] ?? (InnatelyClearsMines || IsAircraft()));
            MinimumIndirectFireRange =
                (byte)(attributes[(int)Attribute.MINIMUM_INDIRECT_FIRE_RANGE]
                       ?? (UnitClass == UnitClass.TOWED_GUN || PrimaryWeapon.WeaponClass == WeaponClass.MORTAR
                                                   ? (byte)1
                                                   : (byte)((PrimaryWeapon.Range + 1) / 2)));

            CanSpot    = (bool)(attributes[(int)Attribute.CAN_SPOT] ?? GetDefaultCanSpot());
            CanReveal  = (bool)(attributes[(int)Attribute.CAN_REVEAL] ?? CanSpot && !IsAircraft());
            SpotRange  = (byte)(attributes[(int)Attribute.SPOT_RANGE] ?? GetDefaultSpotRange());
            SightRange = IsEmplaceable() ? (byte)0 : Math.Max((byte)20, SpotRange);

            DismountAs = (UnitConfiguration)attributes[(int)Attribute.DISMOUNT_AS];
            CanRemount = (bool)(attributes[(int)Attribute.CAN_REMOUNT] ?? DismountAs != null);

            CanSupportArmored   = (bool)(attributes[(int)Attribute.CAN_SUPPORT_ARMORED] ?? false);
            CloseAssaultCapture = (bool)(attributes[(int)Attribute.CLOSE_ASSAULT_CAPTURE]
                                         ?? UnitClass == UnitClass.COMMAND_POST);
            AreaControlCapture = (bool)(attributes[(int)Attribute.AREA_CONTROL_CAPTURE] ?? UnitClass == UnitClass.FORT);
        }
예제 #13
0
 public static string Describe(UnitConfiguration Configuration)
 {
     return(Configuration.Name);
 }
예제 #14
0
 public UnitCount(UnitConfiguration UnitConfiguration, int Count)
 {
     this.UnitConfiguration = UnitConfiguration;
     this.Count             = Count;
 }
 public UnitHasConfiguration(UnitConfiguration UnitConfiguration)
 {
     this.UnitConfiguration = UnitConfiguration;
 }
예제 #16
0
        public UnitConfigurationView(
            UnitConfiguration UnitConfiguration, Faction Faction, UnitConfigurationRenderer Renderer, float Scale)
        {
            this.Scale = Scale;
            Color[] colors = UnitConfiguration.UnitClass == UnitClass.BLOCK ||
                             UnitConfiguration.UnitClass == UnitClass.MINEFIELD
                                                                                          ? new Color[] { Color.White } : Faction.Colors;
            if (!UnitConfiguration.IsVehicle)
            {
                colors = colors.ToArray();
                for (int i = 0; i < colors.Length; ++i)
                {
                    var f = new FloatingColor(colors[i]);
                    f         = f.MakeHSL();
                    f.B       = Math.Min(1, f.B + .1f);
                    colors[i] = f.MakeRGB().ConvertToColor();
                }
            }

            _Vertices = new Vertex[colors.Length * 4];
            float barHeight            = 1f / colors.Length;
            var   backgroundRenderInfo = Renderer.GetRenderInfo(null);

            _BackgroundTexture = backgroundRenderInfo.Item1;
            var v = backgroundRenderInfo.Item2;

            for (int i = 0; i < colors.Length; ++i)
            {
                float yT = v[0].Y + ((float)i / colors.Length) * (v[0].Y + v[2].Y);
                float yB = v[0].Y + ((float)(i + 1) / colors.Length) * (v[0].Y + v[2].Y);
                _Vertices[i * 4] =
                    new Vertex(new Vector2f(-.5f, i * barHeight - .5f), colors[i], new Vector2f(v[0].X, yT));
                _Vertices[i * 4 + 1] =
                    new Vertex(new Vector2f(.5f, i * barHeight - .5f), colors[i], new Vector2f(v[2].X, yT));
                _Vertices[i * 4 + 2] =
                    new Vertex(new Vector2f(.5f, (i + 1) * barHeight - .5f), colors[i], new Vector2f(v[2].X, yB));
                _Vertices[i * 4 + 3] =
                    new Vertex(new Vector2f(-.5f, (i + 1) * barHeight - .5f), colors[i], new Vector2f(v[0].X, yB));
            }

            var renderInfo = Renderer.GetRenderInfo(UnitConfiguration);

            _Texture       = renderInfo.Item1;
            _ImageVertices = new Vertex[4];
            Color c = Renderer.RenderDetails[UnitConfiguration.UniqueKey].OverrideColor;

            if (c.R == 0 && c.G == 0 && c.B == 0)
            {
                c = colors.ArgMax(i => new FloatingColor(i).Luminosity());
            }

            var tl = new Vector2f(-.5f, -.5f);
            var tr = new Vector2f(.5f, -.5f);
            var br = new Vector2f(.5f, .5f);
            var bl = new Vector2f(-.5f, .5f);

            _ImageVertices[0] = new Vertex(tl, c, renderInfo.Item2[0]);
            _ImageVertices[1] = new Vertex(tr, c, renderInfo.Item2[1]);
            _ImageVertices[2] = new Vertex(br, c, renderInfo.Item2[2]);
            _ImageVertices[3] = new Vertex(bl, c, renderInfo.Item2[3]);

            _Bounds = new Rectangle(new Vector2f(-.5f, -.5f) * Scale, new Vector2f(1, 1) * Scale);
        }