fix primary building & building fallback when busy
This commit is contained in:
@@ -156,47 +156,39 @@ namespace OpenRA.Traits
|
|||||||
production[group].Add(item);
|
production[group].Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool IsDisabledBuilding(Actor a)
|
||||||
|
{
|
||||||
|
var building = a.traits.GetOrDefault<Building>();
|
||||||
|
return building != null && building.Disabled;
|
||||||
|
}
|
||||||
|
|
||||||
void BuildUnit( string name )
|
void BuildUnit( string name )
|
||||||
{
|
{
|
||||||
var newUnitType = Rules.Info[ name ];
|
var newUnitType = Rules.Info[ name ];
|
||||||
var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType );
|
var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType );
|
||||||
Actor producer = null;
|
|
||||||
|
|
||||||
// Prioritise primary structure in build order
|
var producers = self.World.Queries.OwnedBy[self.Owner]
|
||||||
var primaryProducers = self.World.Queries.OwnedBy[self.Owner]
|
|
||||||
.WithTrait<Production>()
|
.WithTrait<Production>()
|
||||||
.Where(x => producerTypes.Contains(x.Actor.Info)
|
.Where(x => producerTypes.Contains(x.Actor.Info))
|
||||||
&& x.Trait.IsPrimary);
|
.OrderByDescending(x => x.Trait.IsPrimary ? 1 : 0) // prioritize the primary.
|
||||||
|
.ToArray();
|
||||||
foreach (var p in primaryProducers)
|
|
||||||
|
if (producers.Length == 0)
|
||||||
{
|
{
|
||||||
// Ignore buildings that are disabled
|
CancelProduction(name);
|
||||||
if (p.Actor.traits.Contains<Building>() && p.Actor.traits.Get<Building>().Disabled)
|
|
||||||
continue;
|
|
||||||
producer = p.Actor;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Be smart about disabled buildings. Units in progress should be paused(?)
|
|
||||||
// Ignore this for now
|
|
||||||
|
|
||||||
// Pick the first available producer
|
|
||||||
if (producer == null)
|
|
||||||
{
|
|
||||||
producer = self.World.Queries.OwnedBy[self.Owner]
|
|
||||||
.Where( x => producerTypes.Contains( x.Info ) )
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Something went wrong somewhere...
|
|
||||||
if( producer == null )
|
|
||||||
{
|
|
||||||
CancelProduction( name );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var p in producers)
|
||||||
|
{
|
||||||
|
if (IsDisabledBuilding(p.Actor)) continue;
|
||||||
|
|
||||||
if( producer.traits.WithInterface<Production>().Any( p => p.Produce( producer, newUnitType ) ) )
|
if (p.Trait.Produce(p.Actor, newUnitType))
|
||||||
FinishProduction( newUnitType.Category );
|
{
|
||||||
|
FinishProduction(newUnitType.Category);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user