split PrimaryBuilding from Production
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -230,6 +230,7 @@
|
|||||||
<Compile Include="ActorInitializer.cs" />
|
<Compile Include="ActorInitializer.cs" />
|
||||||
<Compile Include="ActorReference.cs" />
|
<Compile Include="ActorReference.cs" />
|
||||||
<Compile Include="Map.cs" />
|
<Compile Include="Map.cs" />
|
||||||
|
<Compile Include="Traits\PrimaryBuilding.cs" />
|
||||||
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
|
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -260,7 +261,4 @@
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Traits\" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -82,7 +82,7 @@ namespace OpenRA.Traits
|
|||||||
var producers = self.World.Queries.OwnedBy[ self.Owner ].WithTrait<Production>()
|
var producers = self.World.Queries.OwnedBy[ self.Owner ].WithTrait<Production>()
|
||||||
.Where( x => x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains( unit.Category ) )
|
.Where( x => x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains( unit.Category ) )
|
||||||
.ToList();
|
.ToList();
|
||||||
var producer = producers.Where( x => x.Trait.IsPrimary ).Concat( producers )
|
var producer = producers.Where( x => x.Actor.IsPrimaryBuilding() ).Concat( producers )
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if( producer.Actor != null )
|
if( producer.Actor != null )
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ namespace OpenRA.Traits
|
|||||||
var producers = self.World.Queries.OwnedBy[self.Owner]
|
var producers = self.World.Queries.OwnedBy[self.Owner]
|
||||||
.WithTrait<Production>()
|
.WithTrait<Production>()
|
||||||
.Where(x => producerTypes.Contains(x.Actor.Info))
|
.Where(x => producerTypes.Contains(x.Actor.Info))
|
||||||
.OrderByDescending(x => x.Trait.IsPrimary ? 1 : 0) // prioritize the primary.
|
.OrderByDescending(x => x.Actor.IsPrimaryBuilding() ? 1 : 0 ) // prioritize the primary.
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
if (producers.Length == 0)
|
if (producers.Length == 0)
|
||||||
|
|||||||
77
OpenRA.Game/Traits/PrimaryBuilding.cs
Normal file
77
OpenRA.Game/Traits/PrimaryBuilding.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#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.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace OpenRA.Traits
|
||||||
|
{
|
||||||
|
class PrimaryBuildingInfo : TraitInfo<PrimaryBuilding> { }
|
||||||
|
|
||||||
|
class PrimaryBuilding : IIssueOrder, IResolveOrder, IOrderCursor, ITags
|
||||||
|
{
|
||||||
|
bool isPrimary = false;
|
||||||
|
public bool IsPrimary { get { return isPrimary; } }
|
||||||
|
|
||||||
|
public IEnumerable<TagType> GetTags()
|
||||||
|
{
|
||||||
|
yield return (isPrimary) ? TagType.Primary : TagType.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||||
|
{
|
||||||
|
if (mi.Button == MouseButton.Right && underCursor == self)
|
||||||
|
return new Order("PrimaryProducer", self);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CursorForOrder(Actor self, Order order)
|
||||||
|
{
|
||||||
|
return (order.OrderString == "PrimaryProducer") ? "deploy" : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResolveOrder(Actor self, Order order)
|
||||||
|
{
|
||||||
|
if (order.OrderString == "PrimaryProducer")
|
||||||
|
SetPrimaryProducer(self, !isPrimary);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPrimaryProducer(Actor self, bool state)
|
||||||
|
{
|
||||||
|
if (state == false)
|
||||||
|
{
|
||||||
|
isPrimary = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel existing primaries
|
||||||
|
foreach (var p in self.Info.Traits.Get<ProductionInfo>().Produces)
|
||||||
|
foreach (var b in self.World.Queries.OwnedBy[self.Owner]
|
||||||
|
.WithTrait<PrimaryBuilding>()
|
||||||
|
.Where(x => x.Trait.IsPrimary
|
||||||
|
&& (x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains(p))))
|
||||||
|
b.Trait.SetPrimaryProducer(b.Actor, false);
|
||||||
|
|
||||||
|
isPrimary = true;
|
||||||
|
|
||||||
|
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
||||||
|
Sound.PlayToPlayer(self.Owner, eva.PrimaryBuildingSelected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class PrimaryExts
|
||||||
|
{
|
||||||
|
public static bool IsPrimaryBuilding(this Actor a)
|
||||||
|
{
|
||||||
|
var pb = a.traits.Get<PrimaryBuilding>();
|
||||||
|
return pb != null && pb.IsPrimary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,13 +20,12 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public readonly float[] SpawnOffsets; // in px relative to CenterLocation
|
public readonly float[] SpawnOffsets; // in px relative to CenterLocation
|
||||||
public readonly int[] ExitCells; // in cells relative to TopLeft, supports a list for multiple exits
|
public readonly int[] ExitCells; // in cells relative to TopLeft, supports a list for multiple exits
|
||||||
public readonly bool EnablePrimary = true;
|
|
||||||
public readonly string[] Produces = { };
|
public readonly string[] Produces = { };
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init) { return new Production(this); }
|
public virtual object Create(ActorInitializer init) { return new Production(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Production : IIssueOrder, IResolveOrder, ITags, IOrderCursor
|
public class Production
|
||||||
{
|
{
|
||||||
public readonly List<Pair<float2, int2>> Spawns = new List<Pair<float2, int2>>();
|
public readonly List<Pair<float2, int2>> Spawns = new List<Pair<float2, int2>>();
|
||||||
public Production(ProductionInfo info)
|
public Production(ProductionInfo info)
|
||||||
@@ -111,56 +110,6 @@ namespace OpenRA.Traits
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// "primary building" crap - perhaps this should be split?
|
|
||||||
bool isPrimary = false;
|
|
||||||
public bool IsPrimary { get { return isPrimary; } }
|
|
||||||
|
|
||||||
public IEnumerable<TagType> GetTags()
|
|
||||||
{
|
|
||||||
yield return (isPrimary) ? TagType.Primary : TagType.None;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
|
||||||
{
|
|
||||||
if (mi.Button == MouseButton.Right && underCursor == self && self.Info.Traits.Get<ProductionInfo>().EnablePrimary)
|
|
||||||
return new Order("PrimaryProducer", self);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string CursorForOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
return (order.OrderString == "PrimaryProducer") ? "deploy" : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
if (order.OrderString == "PrimaryProducer")
|
|
||||||
SetPrimaryProducer(self, !isPrimary);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetPrimaryProducer(Actor self, bool state)
|
|
||||||
{
|
|
||||||
if (state == false)
|
|
||||||
{
|
|
||||||
isPrimary = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel existing primaries
|
|
||||||
foreach (var p in self.Info.Traits.Get<ProductionInfo>().Produces)
|
|
||||||
{
|
|
||||||
foreach (var b in self.World.Queries.OwnedBy[self.Owner]
|
|
||||||
.WithTrait<Production>()
|
|
||||||
.Where(x => x.Trait.IsPrimary
|
|
||||||
&& (x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains(p))))
|
|
||||||
{
|
|
||||||
b.Trait.SetPrimaryProducer(b.Actor, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isPrimary = true;
|
|
||||||
|
|
||||||
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
|
||||||
Sound.PlayToPlayer(self.Owner,eva.PrimaryBuildingSelected);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ FACT:
|
|||||||
AllowsBuildingRepair:
|
AllowsBuildingRepair:
|
||||||
Production:
|
Production:
|
||||||
Produces: Building,Defense
|
Produces: Building,Defense
|
||||||
EnablePrimary: false
|
|
||||||
Transforms:
|
Transforms:
|
||||||
IntoActor: mcv
|
IntoActor: mcv
|
||||||
Offset:1,1
|
Offset:1,1
|
||||||
@@ -160,6 +159,7 @@ PYLE:
|
|||||||
Produces: Infantry
|
Produces: Infantry
|
||||||
SpawnOffsets: -10,2, 7,7
|
SpawnOffsets: -10,2, 7,7
|
||||||
ExitCells: 0,1, 1,1
|
ExitCells: 0,1, 1,1
|
||||||
|
PrimaryBuilding:
|
||||||
|
|
||||||
HAND:
|
HAND:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
@@ -188,6 +188,7 @@ HAND:
|
|||||||
Produces: Infantry
|
Produces: Infantry
|
||||||
SpawnOffsets: 12,24
|
SpawnOffsets: 12,24
|
||||||
ExitCells:1,2
|
ExitCells:1,2
|
||||||
|
PrimaryBuilding:
|
||||||
|
|
||||||
AFLD:
|
AFLD:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
@@ -218,6 +219,8 @@ AFLD:
|
|||||||
Produces: Vehicle
|
Produces: Vehicle
|
||||||
SpawnOffsets: -24,0
|
SpawnOffsets: -24,0
|
||||||
ExitCells:3,1
|
ExitCells:3,1
|
||||||
|
PrimaryBuilding:
|
||||||
|
|
||||||
WEAP:
|
WEAP:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
Buildable:
|
Buildable:
|
||||||
@@ -247,6 +250,8 @@ WEAP:
|
|||||||
Produces: Vehicle
|
Produces: Vehicle
|
||||||
SpawnOffsets: -8,-8
|
SpawnOffsets: -8,-8
|
||||||
ExitCells: 0,2
|
ExitCells: 0,2
|
||||||
|
PrimaryBuilding:
|
||||||
|
|
||||||
HQ:
|
HQ:
|
||||||
RequiresPower:
|
RequiresPower:
|
||||||
CanPowerDown:
|
CanPowerDown:
|
||||||
@@ -346,6 +351,7 @@ HPAD:
|
|||||||
SpawnOffsets: 0,-6
|
SpawnOffsets: 0,-6
|
||||||
ExitCells: 0,0
|
ExitCells: 0,0
|
||||||
Produces: Plane
|
Produces: Plane
|
||||||
|
PrimaryBuilding:
|
||||||
BelowUnits:
|
BelowUnits:
|
||||||
Reservable:
|
Reservable:
|
||||||
RepairsUnits:
|
RepairsUnits:
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ SPEN:
|
|||||||
SpawnOffsets: 0,-5, 0,-5, 0,0, 0,0
|
SpawnOffsets: 0,-5, 0,-5, 0,0, 0,0
|
||||||
ExitCells: -1,2, 3,2, 0,0, 2,0
|
ExitCells: -1,2, 3,2, 0,0, 2,0
|
||||||
Produces: Ship
|
Produces: Ship
|
||||||
|
PrimaryBuilding:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
-EmitInfantryOnSell:
|
-EmitInfantryOnSell:
|
||||||
RepairsUnits:
|
RepairsUnits:
|
||||||
@@ -115,6 +116,7 @@ SYRD:
|
|||||||
Produces: Ship
|
Produces: Ship
|
||||||
SpawnOffsets: -25,23, 26,23, -22,-25, 23,-25
|
SpawnOffsets: -25,23, 26,23, -22,-25, 23,-25
|
||||||
ExitCells: 0,2, 2,2, 0,0, 2,0
|
ExitCells: 0,2, 2,2, 0,0, 2,0
|
||||||
|
PrimaryBuilding:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
-EmitInfantryOnSell:
|
-EmitInfantryOnSell:
|
||||||
RepairsUnits:
|
RepairsUnits:
|
||||||
@@ -451,6 +453,7 @@ WEAP:
|
|||||||
SpawnOffsets: 5,0
|
SpawnOffsets: 5,0
|
||||||
ExitCells: 1,1
|
ExitCells: 1,1
|
||||||
Produces: Vehicle
|
Produces: Vehicle
|
||||||
|
PrimaryBuilding:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
|
|
||||||
FACT:
|
FACT:
|
||||||
@@ -468,7 +471,6 @@ FACT:
|
|||||||
Bib:
|
Bib:
|
||||||
Production:
|
Production:
|
||||||
Produces: Building,Defense
|
Produces: Building,Defense
|
||||||
EnablePrimary: false
|
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
Valued:
|
Valued:
|
||||||
Cost: 2500
|
Cost: 2500
|
||||||
@@ -567,6 +569,7 @@ HPAD:
|
|||||||
SpawnOffsets: 0,-6
|
SpawnOffsets: 0,-6
|
||||||
ExitCells: 0,0
|
ExitCells: 0,0
|
||||||
Produces: Plane
|
Produces: Plane
|
||||||
|
PrimaryBuilding:
|
||||||
BelowUnits:
|
BelowUnits:
|
||||||
Reservable:
|
Reservable:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
@@ -595,6 +598,7 @@ AFLD:
|
|||||||
Produces: Plane
|
Produces: Plane
|
||||||
SpawnOffsets: 0,4
|
SpawnOffsets: 0,4
|
||||||
ExitCells: 1,1
|
ExitCells: 1,1
|
||||||
|
PrimaryBuilding:
|
||||||
BelowUnits:
|
BelowUnits:
|
||||||
Reservable:
|
Reservable:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
@@ -697,6 +701,7 @@ BARR:
|
|||||||
SpawnOffsets: -4,19, -17,15
|
SpawnOffsets: -4,19, -17,15
|
||||||
ExitCells: 0,2, 0,2
|
ExitCells: 0,2, 0,2
|
||||||
Produces: Infantry
|
Produces: Infantry
|
||||||
|
PrimaryBuilding:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
|
|
||||||
TENT:
|
TENT:
|
||||||
@@ -726,6 +731,7 @@ TENT:
|
|||||||
Produces: Infantry
|
Produces: Infantry
|
||||||
SpawnOffsets: -1,19, -17,15
|
SpawnOffsets: -1,19, -17,15
|
||||||
ExitCells: 0,2, 0,2
|
ExitCells: 0,2, 0,2
|
||||||
|
PrimaryBuilding:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
|
|
||||||
KENN:
|
KENN:
|
||||||
@@ -750,6 +756,7 @@ KENN:
|
|||||||
SpawnOffsets: 0,0
|
SpawnOffsets: 0,0
|
||||||
ExitCells: 0,0
|
ExitCells: 0,0
|
||||||
Produces: Infantry
|
Produces: Infantry
|
||||||
|
PrimaryBuilding:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
-EmitInfantryOnSell:
|
-EmitInfantryOnSell:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user