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); }