2020-07-19 21:36:57 -04:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Auger : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float amount;
|
|
|
|
|
public int speed = 1;
|
|
|
|
|
public int power;
|
|
|
|
|
public bool hasHeatExchanger;
|
|
|
|
|
public int heat;
|
|
|
|
|
public int cooling;
|
|
|
|
|
public GameObject outputObject;
|
|
|
|
|
public GameObject powerObject;
|
2020-09-09 20:01:45 -04:00
|
|
|
|
public ConduitItem conduitItem;
|
2020-09-07 16:47:47 -04:00
|
|
|
|
public PowerReceiver powerReceiver;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
public Material lineMat;
|
|
|
|
|
public string ID = "unassigned";
|
|
|
|
|
public string creationMethod;
|
|
|
|
|
public int address;
|
|
|
|
|
public bool powerON;
|
2020-09-07 16:47:47 -04:00
|
|
|
|
private LineRenderer connectionLine;
|
2020-09-19 20:29:43 -05:00
|
|
|
|
private StateManager stateManager;
|
2020-09-07 16:47:47 -04:00
|
|
|
|
private float updateTick;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
private int machineTimer;
|
2020-09-19 20:29:43 -05:00
|
|
|
|
private int warmup;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
|
2020-09-16 21:40:25 -05:00
|
|
|
|
//! Called by unity engine on start up to initialize variables.
|
2020-08-31 04:00:45 -04:00
|
|
|
|
public void Start()
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-08-08 23:45:20 -04:00
|
|
|
|
powerReceiver = gameObject.AddComponent<PowerReceiver>();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
connectionLine = gameObject.AddComponent<LineRenderer>();
|
2020-09-09 20:01:45 -04:00
|
|
|
|
conduitItem = GetComponentInChildren<ConduitItem>(true);
|
2020-09-19 20:29:43 -05:00
|
|
|
|
stateManager = FindObjectOfType<StateManager>();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
connectionLine.startWidth = 0.2f;
|
|
|
|
|
connectionLine.endWidth = 0.2f;
|
|
|
|
|
connectionLine.material = lineMat;
|
|
|
|
|
connectionLine.loop = true;
|
|
|
|
|
connectionLine.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 21:40:25 -05:00
|
|
|
|
//! Called once per frame by unity engine.
|
2020-08-31 04:00:45 -04:00
|
|
|
|
public void Update()
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
|
|
|
|
updateTick += 1 * Time.deltaTime;
|
|
|
|
|
if (updateTick > 0.5f + (address * 0.001f))
|
|
|
|
|
{
|
2020-09-19 20:29:43 -05:00
|
|
|
|
if (stateManager.Busy())
|
|
|
|
|
{
|
|
|
|
|
updateTick = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-19 21:36:57 -04:00
|
|
|
|
GetComponent<PhysicsHandler>().UpdatePhysics();
|
2020-08-08 23:45:20 -04:00
|
|
|
|
UpdatePowerReceiver();
|
|
|
|
|
|
2020-07-19 21:36:57 -04:00
|
|
|
|
updateTick = 0;
|
2020-09-19 20:29:43 -05:00
|
|
|
|
if (warmup < 10)
|
|
|
|
|
{
|
|
|
|
|
warmup++;
|
|
|
|
|
}
|
|
|
|
|
else if (speed > power)
|
2020-09-05 18:39:40 -04:00
|
|
|
|
{
|
2020-09-15 04:00:33 -04:00
|
|
|
|
speed = power > 0 ? power : 1;
|
2020-09-05 18:39:40 -04:00
|
|
|
|
}
|
2020-07-19 21:36:57 -04:00
|
|
|
|
if (speed > 1)
|
|
|
|
|
{
|
|
|
|
|
heat = speed - 1 - cooling;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
heat = 0;
|
|
|
|
|
}
|
|
|
|
|
if (heat < 0)
|
|
|
|
|
{
|
|
|
|
|
heat = 0;
|
|
|
|
|
}
|
2020-09-05 18:39:40 -04:00
|
|
|
|
|
2020-07-19 21:36:57 -04:00
|
|
|
|
if (outputObject != null)
|
|
|
|
|
{
|
|
|
|
|
connectionLine.SetPosition(0, transform.position);
|
|
|
|
|
connectionLine.SetPosition(1, outputObject.transform.position);
|
|
|
|
|
connectionLine.enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
connectionLine.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (powerON == true && speed > 0)
|
|
|
|
|
{
|
2020-09-09 20:01:45 -04:00
|
|
|
|
conduitItem.active = true;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
machineTimer += 1;
|
|
|
|
|
if (machineTimer > 5 - (address * 0.01f))
|
|
|
|
|
{
|
|
|
|
|
amount += speed - heat;
|
|
|
|
|
machineTimer = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
machineTimer = 0;
|
2020-09-09 20:01:45 -04:00
|
|
|
|
conduitItem.active = false;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-31 04:00:45 -04:00
|
|
|
|
|
2020-09-16 21:40:25 -05:00
|
|
|
|
//! Gets power values from power receiver.
|
2020-08-31 04:00:45 -04:00
|
|
|
|
private void UpdatePowerReceiver()
|
|
|
|
|
{
|
|
|
|
|
powerReceiver.ID = ID;
|
|
|
|
|
power = powerReceiver.power;
|
|
|
|
|
powerON = powerReceiver.powerON;
|
|
|
|
|
powerObject = powerReceiver.powerObject;
|
|
|
|
|
}
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|