using System.Collections.Generic;
using UnityEngine;
namespace GrassCutter
{
///
/// A garage you build yourself: sells and calls machines like the one at the base, and whatever a machine unloads on the pad
/// in front goes into its silo. Two ports at the back turn the silo into bundles for the belts.
///
public class Garage : SiloPiece
{
public static readonly List All = new List();
// the garage stands at 0.6 times the pack model (half what it was: it towered over the base): its front is 1.9 m out,
// its back wall 1.9 m back. The pad is still sized for the machines.
const float PadFront = 2.4f, PadLong = 11f, PadWide = 6.5f, PortBack = 2.24f;
public override string Prompt => Loc.F("Garage — buy, call & upgrade machines (silo {0})", GameDefs.Kilos(Silo.Value));
public override void Interact()
{
Sfx.Play("ui_open");
UIRoot.I?.OpenGarage(this);
}
public override void OnNetworkSpawn() { All.Add(this); base.OnNetworkSpawn(); }
public override void OnNetworkDespawn() { All.Remove(this); base.OnNetworkDespawn(); }
public override string PadName => Loc.T("Garage pad");
public override void OnDestroy()
{
All.Remove(this);
base.OnDestroy();
}
public override void Ports(List into)
{
var back = -transform.forward;
var at = transform.position + transform.up * GameDefs.BeltLowest + back * PortBack;
into.Add(new Port { at = at - transform.right * 0.8f, dir = back });
into.Add(new Port { at = at + transform.right * 0.8f, dir = back });
}
/// Where a called machine appears: the middle of the pad.
public override Vector3 PadSpot => transform.position + transform.forward * (PadFront + PadLong * 0.5f) + transform.up * 0.6f;
public override bool OnPad(Vector3 p)
{
var l = transform.InverseTransformPoint(p);
return Mathf.Abs(l.x) < PadWide && l.z > PadFront - 1f && l.z < PadFront + PadLong && Mathf.Abs(l.y) < 4f;
}
public static Garage Under(Vector3 p)
{
foreach (var g in All) if (g && g.OnPad(p)) return g;
return null;
}
}
}