diff --git a/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs b/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs index 781c2fe..bf95cb7 100644 --- a/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs +++ b/Assets/Scripts/Drag&Drop/ObjectPlaceholder.cs @@ -3,34 +3,44 @@ public class ObjectPlaceholder : UnitPlaceholder { public GameObject Prefab { get; set; } + public override void Place() { base.Place(); Prefab.Create(transform.position, parent : LevelManager.Instance.LevelTransform); } + public override bool CanBePlacedHere() { var objsOnPosition = LevelManager.Instance.GetAll(obj => obj.Position.IsContainedIn(transform.position)); var positionIsCollidable = objsOnPosition.Exists(obj => obj.IsCollidable); + // If an ally is on the tile, we can't place anything here + foreach (var item in objsOnPosition) + { + if (item is Ally) + { + return false; + } + } + var defaultUnitCost = GlobalConfig.Instance.Current.populationCostPerUnit; return !positionIsCollidable && LevelBoundCache.Contains(transform.position) && ResourceManager.Instance.EnoughFor(Rock, Wood, Food) && (Prefab.GetComponent() || ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost)) - && IsFarmerAndAllowed(); + && IsHarvesterAndAllowed(); } - private bool IsFarmerAndAllowed() + private bool IsHarvesterAndAllowed() { Ally unit = Prefab.GetComponent(); - //Obtiens info correctement. + // Get info LevelTile pointedTile = LevelManager.Instance.Get(obj => obj.Position.IsContainedIn(transform.position)); return unit is not Harvester || (unit is Harvester && IsAllowedTile(pointedTile)); - //return true; } private bool IsAllowedTile(LevelTile pointedTile) diff --git a/Assets/Scripts/Drag&Drop/UnitPlaceholder.cs b/Assets/Scripts/Drag&Drop/UnitPlaceholder.cs index b553a1f..d397059 100644 --- a/Assets/Scripts/Drag&Drop/UnitPlaceholder.cs +++ b/Assets/Scripts/Drag&Drop/UnitPlaceholder.cs @@ -11,10 +11,12 @@ public abstract class UnitPlaceholder : DraggablePlaceholder WasPlaced?.Invoke(this); } + // Not actually used because overriden. public override bool CanBePlacedHere() { return base.CanBePlacedHere() && ResourceManager.Instance.EnoughFor(Rock, Wood, Food) && !LevelManager.Instance.Has(obj => obj.Position.IsContainedIn(transform.position)); } + public event System.Action WasPlaced; } \ No newline at end of file diff --git a/Assets/Scripts/LevelManager/LevelManagerScript.cs b/Assets/Scripts/LevelManager/LevelManagerScript.cs index e3f1139..e022c45 100644 --- a/Assets/Scripts/LevelManager/LevelManagerScript.cs +++ b/Assets/Scripts/LevelManager/LevelManagerScript.cs @@ -59,6 +59,7 @@ public class LevelManagerScript : SingletonBehaviour { //only when the level is loaded do we start updating updateAction = LevelManager.Instance.UpdateLevel; + LevelManager.Instance.LevelTransform = transform; } ///