WIP fix placement on same tile
This commit is contained in:
parent
56b5dd3361
commit
37568663fb
@ -10,19 +10,40 @@ public class ObjectPlaceholder : UnitPlaceholder
|
||||
}
|
||||
public override bool CanBePlacedHere()
|
||||
{
|
||||
//bool isTileEmpty = !LevelManager.Instance.Has<ILevelObject>(obj => obj.Position.IsContainedIn(transform.position));
|
||||
bool isHarvesterAndAllowed = IsHarvesterAndAllowed();
|
||||
|
||||
var objsOnPosition = LevelManager.Instance.GetAll<ILevelObject>(obj => obj.Position.IsContainedIn(transform.position));
|
||||
var positionIsCollidable = objsOnPosition.Exists(obj => obj.IsCollidable);
|
||||
|
||||
// Look if tile is already used by an ally
|
||||
var isTileBusy = false;
|
||||
Transform[] children = LevelManager.Instance.LevelTransform.GetComponentsInChildren<Transform>();
|
||||
foreach (Transform tr in children)
|
||||
{
|
||||
Debug.Log(tr);
|
||||
if (tr == null || tr.tag != "Ally") break;
|
||||
float distance = Vector2.Distance(transform.position, tr.position);
|
||||
Debug.Log("distance : " + distance);
|
||||
if (distance <= 0.5f)
|
||||
{
|
||||
Debug.Log("distance ahah: " + distance);
|
||||
isTileBusy = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var defaultUnitCost = GlobalConfig.Instance.Current.populationCostPerUnit;
|
||||
return !positionIsCollidable
|
||||
return !positionIsCollidable
|
||||
&& LevelBoundCache.Contains(transform.position)
|
||||
&& ResourceManager.Instance.EnoughFor(Rock, Wood, Food)
|
||||
&& (Prefab.GetComponent<Building>()
|
||||
|| ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost))
|
||||
&& IsFarmerAndAllowed();
|
||||
|| ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost))
|
||||
&& isHarvesterAndAllowed
|
||||
&& !isTileBusy;
|
||||
}
|
||||
|
||||
private bool IsFarmerAndAllowed()
|
||||
private bool IsHarvesterAndAllowed()
|
||||
{
|
||||
Ally unit = Prefab.GetComponent<Ally>();
|
||||
|
||||
@ -30,7 +51,6 @@ public class ObjectPlaceholder : UnitPlaceholder
|
||||
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)
|
||||
|
||||
@ -11,10 +11,12 @@ public abstract class UnitPlaceholder : DraggablePlaceholder
|
||||
WasPlaced?.Invoke(this);
|
||||
}
|
||||
|
||||
// This isn't ever used?
|
||||
public override bool CanBePlacedHere()
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -102,7 +102,8 @@ public static class Extensions
|
||||
/// <returns></returns>
|
||||
public static bool IsContainedIn(this Vector3 vect, Vector3 tilePosition)
|
||||
{
|
||||
return Vector2.Distance(vect, tilePosition) < 0.5f;
|
||||
float distance = Vector2.Distance(vect, tilePosition);
|
||||
return distance < 0.5f;
|
||||
}
|
||||
public static Vector2 RandomInRectangle(float x, float y)
|
||||
{
|
||||
|
||||
@ -50,6 +50,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