Created
May 20, 2014 23:23
-
-
Save phrohdoh/928c9dd77c2c3f05c349 to your computer and use it in GitHub Desktop.
Requesting help for stashing Plug/PlugActor in BuildingUtil/Util.cs ~11-12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore) | |
{ | |
if (building.AllowInvalidPlacement) | |
return true; | |
var existing = world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(topLeft); | |
var toPlace = Rules.Info[name.ToLowerInvariant()]; | |
if (CanPlacePlug(existing, toPlace, topLeft)) | |
{ | |
foreach (var pluggable in existing.TraitsImplementing<Pluggable>()) | |
pluggable.Plug = toPlace.Traits.Get<Plug>(); | |
Game.Debug("Placing plug on {0} at {1}.".F(existing.Info.Name, existing.Location.TopLeft.ToCPos() - topLeft)); | |
return true; | |
} | |
var res = world.WorldActor.Trait<ResourceLayer>(); | |
return FootprintUtils.Tiles(name, building, topLeft).All( | |
t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null && | |
world.IsCellBuildable(t, building, toIgnore)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PlugInfo : ITraitInfo | |
{ | |
[Desc("This is a plug of type...")] | |
public readonly string Type = null; | |
public virtual object Create(ActorInitializer init) { return new Plug(init.self, this); } | |
} | |
public class Plug | |
{ | |
public Actor PlugActor; | |
public Plug(Actor self, PlugInfo info) | |
{ | |
PlugActor = self; | |
} | |
} | |
public class PlugInit : IActorInit<Plug> | |
{ | |
[FieldFromYamlKey] public readonly Plug value = null; | |
public PlugInit() { } | |
public PlugInit(Plug init) { value = init; } | |
public Plug Value(World world) { return value; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PluggableInfo : ITraitInfo | |
{ | |
[Desc("Which cell does this plug belong in? Relative to the top left cell of the pluggable structure.")] | |
public readonly CVec CellOffset = new CVec(); | |
[Desc("Plug types supported for this cell.")] | |
public readonly string[] PlugTypes = { }; | |
public virtual object Create(ActorInitializer init) { return new Pluggable(init, this); } | |
} | |
public class Pluggable | |
{ | |
public Plug Plug; | |
public Pluggable(ActorInitializer init, PluggableInfo info) | |
{ | |
if (init.Contains<PlugInit>()) | |
Plug = init.Get<PlugInit, Plug>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment