Fix placing multiple units on the same tile (#2)
Reviewed-on: #2 Reviewed-by: Ader_Alisma <ader.alisma.1@ens.etsmtl.ca>
This commit is contained in:
parent
e5c9e327e4
commit
3fdbbee765
@ -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<ILevelObject>(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<Building>()
|
||||
|| ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost))
|
||||
&& IsFarmerAndAllowed();
|
||||
&& IsHarvesterAndAllowed();
|
||||
}
|
||||
|
||||
private bool IsFarmerAndAllowed()
|
||||
private bool IsHarvesterAndAllowed()
|
||||
{
|
||||
Ally unit = Prefab.GetComponent<Ally>();
|
||||
|
||||
//Obtiens info correctement.
|
||||
// Get info
|
||||
LevelTile pointedTile = LevelManager.Instance.Get<LevelTile>(obj => obj.Position.IsContainedIn(transform.position));
|
||||
|
||||
return unit is not Harvester || (unit is Harvester && IsAllowedTile(pointedTile));
|
||||
//return true;
|
||||
}
|
||||
|
||||
private bool IsAllowedTile(LevelTile pointedTile)
|
||||
|
||||
@ -16,5 +16,6 @@ public abstract class UnitPlaceholder : DraggablePlaceholder
|
||||
return base.CanBePlacedHere() && ResourceManager.Instance.EnoughFor(Rock, Wood, Food)
|
||||
&& !LevelManager.Instance.Has<ILevelObject>(obj => obj.Position.IsContainedIn(transform.position));
|
||||
}
|
||||
|
||||
public event System.Action<UnitPlaceholder> WasPlaced;
|
||||
}
|
||||
@ -59,6 +59,7 @@ public class LevelManagerScript : SingletonBehaviour<LevelManagerScript>
|
||||
{
|
||||
//only when the level is loaded do we start updating
|
||||
updateAction = LevelManager.Instance.UpdateLevel;
|
||||
LevelManager.Instance.LevelTransform = transform;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user