diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 8618e38daf..439272e60c 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -119,8 +119,8 @@ namespace OpenRA return null; var underCursor = World.FindUnitsAtMouse(mi.Location) - .Where(a => a.Info.Traits.Contains()) - .OrderByDescending(a => a.Info.Traits.Get().Priority) + //.Where(a => a.Info.Traits.Contains()) + .OrderByDescending(a => a.Info.Traits.Contains() ? a.Info.Traits.Get().Priority : int.MinValue) .FirstOrDefault(); return traits.WithInterface() diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 99b8cead12..9bffd05e4f 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -228,6 +228,7 @@ + diff --git a/OpenRA.Game/Traits/Building.cs b/OpenRA.Game/Traits/Building.cs index bf134dc379..0907ca00eb 100644 --- a/OpenRA.Game/Traits/Building.cs +++ b/OpenRA.Game/Traits/Building.cs @@ -22,7 +22,6 @@ namespace OpenRA.Traits { public readonly int HP = 0; public readonly ArmorType Armor = ArmorType.none; - public readonly string[] TargetType = {"Ground"}; } public class BuildingInfo : OwnedActorInfo, ITraitInfo diff --git a/OpenRA.Game/Traits/Targetable.cs b/OpenRA.Game/Traits/Targetable.cs new file mode 100644 index 0000000000..c70d08949e --- /dev/null +++ b/OpenRA.Game/Traits/Targetable.cs @@ -0,0 +1,26 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System.Drawing; +using OpenRA.Graphics; +using System.Linq; + +namespace OpenRA.Traits +{ + public class TargetableInfo : TraitInfo + { + public readonly string[] TargetTypes = {}; + } + + public class Targetable + { + + } +} diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 8ac2f3e93e..26f90b97fe 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -14,6 +14,7 @@ using System.Linq; using OpenRA.FileFormats; using OpenRA.Orders; using OpenRA.Traits; +using System.Collections.Generic; namespace OpenRA.Widgets { @@ -36,7 +37,7 @@ namespace OpenRA.Widgets Game.Renderer.LineRenderer.DrawLine(a + b + c, a + c, Color.White, Color.White); Game.Renderer.LineRenderer.DrawLine(a, a + c, Color.White, Color.White); - foreach (var u in world.SelectActorsInBox(selbox.Value.First, selbox.Value.Second)) + foreach (var u in SelectActorsInBox(world, selbox.Value.First, selbox.Value.Second)) world.WorldRenderer.DrawSelectionBox(u, Color.Yellow); Game.Renderer.LineRenderer.Flush(); @@ -60,7 +61,7 @@ namespace OpenRA.Widgets { if (world.OrderGenerator is UnitOrderGenerator) { - var newSelection = Game.world.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy); + var newSelection = SelectActorsInBox(world, Game.CellSize * dragStart, Game.CellSize * xy); world.Selection.Combine(world, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy); } @@ -170,6 +171,17 @@ namespace OpenRA.Widgets Game.viewport.Center(world.Selection.Actors); } + IEnumerable SelectActorsInBox(World world, float2 a, float2 b) + { + return world.FindUnits(a, b) + .Where( x => x.traits.Contains() && x.IsVisible() ) + .GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get().Priority : 0) + .OrderByDescending(g => g.Key) + .Select( g => g.AsEnumerable() ) + .DefaultIfEmpty( new Actor[] {} ) + .FirstOrDefault(); + } + public override Widget Clone() { return new WorldInteractionControllerWidget(this); } } } \ No newline at end of file diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index e947ce8ea7..558f49623d 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -81,17 +81,6 @@ namespace OpenRA if (r * r >= (new int2(i, j) - a).LengthSquared) yield return new int2(i, j); } - - public static IEnumerable SelectActorsInBox(this World world, float2 a, float2 b) - { - return world.FindUnits(a, b) - .Where( x => x.traits.Contains() && x.IsVisible() ) - .GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get().Priority : 0) - .OrderByDescending(g => g.Key) - .Select( g => g.AsEnumerable() ) - .DefaultIfEmpty( new Actor[] {} ) - .FirstOrDefault(); - } public static string GetTerrainType(this World world, int2 cell) { diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index 0737506aeb..5c54bf0cc1 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -150,7 +150,7 @@ namespace OpenRA.Mods.RA if (!WeaponValidForTarget(args.weapon, Target.FromActor(target))) return 0f; var selectable = target.Info.Traits.GetOrDefault(); - var radius = selectable != null ? selectable.Radius : 0; + var radius = selectable != null ? selectable.Radius : 0; var distance = (int)Math.Max(0, (target.CenterLocation - args.dest).Length - radius); var falloff = (float)GetDamageFalloff(distance / warhead.Spread); var rawDamage = (float)(warhead.Damage * modifier * falloff); @@ -167,13 +167,11 @@ namespace OpenRA.Mods.RA || (weapon.ValidTargets.Contains("Water") && Game.world.GetTerrainType(Util.CellContaining(target.CenterLocation)) == "Water"); // even bigger hack! - var ownedInfo = target.Actor.Info.Traits.GetOrDefault(); - - - - if (!weapon.ValidTargets.Intersect(ownedInfo.TargetType).Any()) + var targetable = target.Actor.Info.Traits.GetOrDefault(); + if (targetable == null || !weapon.ValidTargets.Intersect(targetable.TargetTypes).Any()) return false; - + + var ownedInfo = target.Actor.Info.Traits.GetOrDefault(); if (weapon.Warheads.All( w => w.EffectivenessAgainst(ownedInfo.Armor) <= 0)) return false; diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index d102ccf806..2027d498e5 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -104,9 +104,9 @@ namespace OpenRA.Mods.RA yield break; } - var underCursor = world.FindUnitsAtMouse(mi.Location) - .Where(a => a.Info.Traits.Contains()) - .OrderByDescending(a => a.Info.Traits.Get().Priority) + var underCursor = world.FindUnitsAtMouse(mi.Location) + //.Where(a => a.Info.Traits.Contains()) + .OrderByDescending(a => a.Info.Traits.Contains() ? a.Info.Traits.Get().Priority : int.MinValue) .FirstOrDefault(); if (mi.Button == MouseButton.Right && underCursor == null) diff --git a/mods/cnc/civilian.yaml b/mods/cnc/civilian.yaml index d40f65e2fa..99e5e71be4 100644 --- a/mods/cnc/civilian.yaml +++ b/mods/cnc/civilian.yaml @@ -165,8 +165,6 @@ BRIDGE1: Building: Footprint: ____ ____ ____ ____ Dimensions: 4,4 -# Selectable: -# Bounds: 96,96 BRIDGE2: Inherits: ^Bridge @@ -176,8 +174,6 @@ BRIDGE2: Building: Footprint: _____ _____ _____ _____ _____ Dimensions: 5,5 -# Selectable: -# Bounds: 120,120 BRIDGE3: Inherits: ^Bridge @@ -187,8 +183,6 @@ BRIDGE3: Building: Footprint: ______ ______ ______ ______ ______ Dimensions: 6,5 -# Selectable: -# Bounds: 144,120 BRIDGE4: Inherits: ^Bridge @@ -198,5 +192,3 @@ BRIDGE4: Building: Footprint: ______ ______ ______ ______ Dimensions: 6,4 -# Selectable: -# Bounds: 144,96 \ No newline at end of file diff --git a/mods/cnc/defaults.yaml b/mods/cnc/defaults.yaml index 711bc01c7b..a154f8d657 100644 --- a/mods/cnc/defaults.yaml +++ b/mods/cnc/defaults.yaml @@ -7,6 +7,8 @@ TerrainSpeeds: 60%, 40%, 100%, 0%, 0%, 0%, 0%, 50%, 40%, 0% Selectable: Voice: VehicleVoice + Targetable: + TargetTypes: Ground Repairable: Chronoshiftable: Passenger: @@ -26,6 +28,8 @@ TerrainSpeeds: 80%, 70%, 100%, 0%, 0%, 0%, 0%, 70%, 70%, 0% Selectable: Voice: VehicleVoice + Targetable: + TargetTypes: Ground Repairable: Chronoshiftable: Passenger: @@ -38,7 +42,8 @@ ^Helicopter: Category: Plane Unit: - TargetType: Air + Targetable: + TargetTypes: Air Selectable: Voice: VehicleVoice HiddenUnderFog: @@ -60,6 +65,8 @@ TerrainSpeeds: 90%, 80%, 100%, 0%, 0%, 0%, 0%, 90%, 80%, 0% Selectable: Voice: GenericVoice + Targetable: + TargetTypes: Ground RenderInfantry: AutoTarget: Passenger: @@ -73,9 +80,10 @@ ^Plane: Category: Plane Unit: - TargetType: Air Selectable: Voice: GenericVoice + Targetable: + TargetTypes: Air HiddenUnderFog: GainsExperience: GivesExperience: @@ -85,6 +93,8 @@ Category: Building Selectable: Priority: 3 + Targetable: + TargetTypes: Ground Building: Dimensions: 1,1 Footprint: x @@ -186,11 +196,10 @@ Category: Building Valued: Description: Bridge - Selectable: - Bounds: 96,96 + Targetable: + TargetTypes: Ground, Water BelowUnits: Building: - TargetType: Ground, Water DamagedSound: xplos.aud DestroyedSound: xplobig4.aud Footprint: ______ ______ ______ ______ diff --git a/mods/cnc/vehicles.yaml b/mods/cnc/vehicles.yaml index eb3ee4329e..ab677488da 100644 --- a/mods/cnc/vehicles.yaml +++ b/mods/cnc/vehicles.yaml @@ -463,7 +463,6 @@ C17: LZRange: 1 Inherits: ^Plane Unit: - TargetType: Special HP: 25 Armor: light ROT: 5 @@ -475,6 +474,7 @@ C17: Passengers: 10 Invulnerable: -Selectable: + -Targetable: -GainsExperience: A10: diff --git a/mods/ra/civilian.yaml b/mods/ra/civilian.yaml index 01498599e3..ebd0a44ffd 100644 --- a/mods/ra/civilian.yaml +++ b/mods/ra/civilian.yaml @@ -164,8 +164,7 @@ BRIDGE1: Building: Footprint: _____ _____ _____ Dimensions: 5,3 -# Selectable: -# Bounds: 120,48 + BRIDGE2: Inherits: ^Bridge Bridge: @@ -175,5 +174,3 @@ BRIDGE2: Building: Footprint: _____ _____ Dimensions: 5,2 -# Selectable: -# Bounds: 120,48 \ No newline at end of file diff --git a/mods/ra/defaults.yaml b/mods/ra/defaults.yaml index fea61d91b7..7c0b8be043 100644 --- a/mods/ra/defaults.yaml +++ b/mods/ra/defaults.yaml @@ -8,6 +8,8 @@ TerrainSpeeds: 60%, 40%, 100%, 0%, 0%, 0%, 0%, 90%, 40%, 0% Selectable: Voice: VehicleVoice + Targetable: + TargetTypes: Ground Repairable: Chronoshiftable: Passenger: @@ -27,6 +29,8 @@ TerrainSpeeds: 80%, 70%, 100%, 0%, 0%, 0%, 0%, 90%, 70%, 0% Selectable: Voice: VehicleVoice + Targetable: + TargetTypes: Ground Repairable: Chronoshiftable: Passenger: @@ -48,6 +52,8 @@ TerrainSpeeds: 90%, 80%, 100%, 0%, 0%, 0%, 0%, 100%, 80%, 0% Selectable: Voice: GenericVoice + Targetable: + TargetTypes: Ground RenderInfantry: AutoTarget: Passenger: @@ -60,12 +66,13 @@ ^Ship: Category: Ship Unit: - TargetType: Ground, Water Mobile: TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River TerrainSpeeds: 0%, 0%, 0%, 0%, 100%, 0%, 0%, 0%, 0%, 0% Selectable: Voice: ShipVoice + Targetable: + TargetTypes: Ground, Water HiddenUnderFog: GainsExperience: GivesExperience: @@ -74,9 +81,10 @@ ^Plane: Category: Plane Unit: - TargetType: Air Selectable: Voice: GenericVoice + Targetable: + TargetTypes: Air HiddenUnderFog: GainsExperience: GivesExperience: @@ -86,6 +94,8 @@ Category: Building Selectable: Priority: 3 + Targetable: + TargetTypes: Ground Building: Dimensions: 1,1 Footprint: x @@ -114,6 +124,8 @@ Range: 8 Selectable: Priority: 1 + Targetable: + TargetTypes: Ground RenderBuildingWall: HasMakeAnimation: false Palette: terrain @@ -154,7 +166,6 @@ Speed: 0 HP: 140 Armor: Heavy - TargetType: Special Husk: Selectable: Priority: -1 @@ -165,11 +176,10 @@ Category: Building Valued: Description: Bridge -# Selectable: -# Bounds: 96,48 BelowUnits: + Targetable: + TargetTypes: Ground, Water Building: - TargetType: Ground, Water Footprint: ____ ____ Dimensions: 4,2 HP: 1000 diff --git a/mods/ra/structures.yaml b/mods/ra/structures.yaml index c69dc7542d..8a3a72ddec 100644 --- a/mods/ra/structures.yaml +++ b/mods/ra/structures.yaml @@ -59,8 +59,9 @@ SPEN: Description: Sub Pen LongDesc: Produces and repairs submarines and \ntransports Hotkey: s + Targetable: + TargetTypes: Ground, Water Building: - TargetType: Ground, Water Power: -30 Footprint: xxx xxx xxx Dimensions: 3,3 @@ -89,8 +90,9 @@ SYRD: Description: Shipyard LongDesc: Produces and repairs ships Hotkey: s + Targetable: + TargetTypes: Ground, Water Building: - TargetType: Ground, Water Power: -30 Footprint: xxx xxx xxx Dimensions: 3,3 @@ -794,8 +796,9 @@ SYRF: # Description: Fake Shipyard # LongDesc: Looks like a Shipyard # Hotkey: z + Targetable: + TargetTypes: Ground, Water Building: - TargetType: Ground, Water Power: -2 Footprint: xxx xxx xxx Dimensions: 3,3 @@ -813,8 +816,9 @@ SYRF: SPEF: Inherits: ^Building + Targetable: + TargetTypes: Ground, Water Building: - TargetType: Ground, Water Power: -2 Footprint: xxx xxx xxx Dimensions: 3,3 diff --git a/mods/ra/system.yaml b/mods/ra/system.yaml index 1167f229a1..2e9591243a 100644 --- a/mods/ra/system.yaml +++ b/mods/ra/system.yaml @@ -185,7 +185,6 @@ MINP: AvoidFriendly: yes Unit: HP: 1 - TargetType: special RenderUnit: BelowUnits: InvisibleToOthers: @@ -198,7 +197,6 @@ MINV: AvoidFriendly: yes Unit: HP: 1 - TargetType: special RenderUnit: BelowUnits: InvisibleToOthers: @@ -252,14 +250,12 @@ CAMERA: Aircraft: Unit: HP:1000 - TargetType: special RevealsShroud: Range: 10 FLARE: Unit: HP:1000 - TargetType: special RevealsShroud: Range: 3 RenderFlare: