public void AddNanites(int _iNanites) { int iNumSilos = m_NaniteSilos.Count; int evenDistribution = _iNanites / iNumSilos; foreach (GameObject silo in m_NaniteSilos) { CNaniteStorageBehaviour siloBehaviour = silo.GetComponent <CNaniteStorageBehaviour>(); float newNaniteAmount = siloBehaviour.StoredNanites + evenDistribution; if (newNaniteAmount > siloBehaviour.NaniteCapacity) { int chargeAddition = siloBehaviour.AvailableNaniteCapacity; siloBehaviour.StoredNanites = siloBehaviour.NaniteCapacity; evenDistribution -= chargeAddition; } } foreach (GameObject silo in m_NaniteSilos) { CNaniteStorageBehaviour siloBehaviour = silo.GetComponent <CNaniteStorageBehaviour>(); if (siloBehaviour.StoredNanites != siloBehaviour.NaniteCapacity) { siloBehaviour.StoredNanites += evenDistribution; } } }
public void DeductNanites(int _iNanites) { int iOriginalDebt = _iNanites; if (_iNanites < m_ShipCurrentNanites) { // Take nanites from non-full silos first foreach (GameObject silo in m_NaniteSilos) { CNaniteStorageBehaviour siloBehaviour = silo.GetComponent <CNaniteStorageBehaviour> (); if (siloBehaviour.IsStorageAvailable && siloBehaviour.StoredNanites < siloBehaviour.NaniteCapacity) { if (siloBehaviour.StoredNanites > _iNanites) { siloBehaviour.DeductNanites(_iNanites); _iNanites = 0; break; } else { int availableAmount = siloBehaviour.StoredNanites; siloBehaviour.DeductNanites(availableAmount); _iNanites -= availableAmount; } } } //If there is a remaining debt, start removing nanites from full silos if (_iNanites > 0) { foreach (GameObject silo in m_NaniteSilos) { CNaniteStorageBehaviour siloBehaviour = silo.GetComponent <CNaniteStorageBehaviour> (); if (siloBehaviour.IsStorageAvailable) { if (siloBehaviour.StoredNanites > _iNanites) { siloBehaviour.DeductNanites(_iNanites); _iNanites = 0; break; } else { int availableAmount = siloBehaviour.StoredNanites; siloBehaviour.DeductNanites(availableAmount); _iNanites -= availableAmount; } } } } } else { Debug.LogError("Insufficient nanites - always check available nanites before deducting"); } }
private void UpdateStorageVariables() { m_ShipNanitesPotential = 0; m_ShipCurrentNanites = 0; foreach (GameObject ns in m_NaniteSilos) { CNaniteStorageBehaviour nsb = ns.GetComponent <CNaniteStorageBehaviour>(); if (nsb.IsStorageAvailable) { m_ShipCurrentNanites += nsb.StoredNanites; m_ShipNanitesPotential += nsb.NaniteCapacity; } } }
// Member Properties // Member Methods public void RegisterNaniteCapsule(GameObject _NaniteCapacitor) { m_NaniteCapsule = _NaniteCapacitor; m_CachedNaniteStorageBehaviour = m_NaniteCapsule.GetComponent<CNaniteStorageBehaviour>(); m_CachedNaniteCapsule = m_NaniteCapsule.GetComponent<CTestNaniteCapsule>(); // Register charge/capacity state chages m_CachedNaniteStorageBehaviour.EventNaniteStorageChanged += HandleCapsuleStateChange; m_CachedNaniteStorageBehaviour.EventNaniteCapacityChanged += HandleCapsuleStateChange; // Register for when the circuitry breaks/fixes m_CachedNaniteCapsule.m_CircuitryComp.EventComponentBreak += HandleComponentStateChange; m_CachedNaniteCapsule.m_CircuitryComp.EventComponentFix += HandleComponentStateChange; m_CachedNaniteCapsule.m_CalibratorComp.EventComponentBreak += HandleComponentStateChange; m_CachedNaniteCapsule.m_CalibratorComp.EventComponentFix += HandleComponentStateChange; // Update initial values UpdateDUI(); }
// Member Properties // Member Methods public void RegisterNaniteCapsule(GameObject _NaniteCapacitor) { m_NaniteCapsule = _NaniteCapacitor; m_CachedNaniteStorageBehaviour = m_NaniteCapsule.GetComponent <CNaniteStorageBehaviour>(); m_CachedNaniteCapsule = m_NaniteCapsule.GetComponent <CTestNaniteCapsule>(); // Register charge/capacity state chages m_CachedNaniteStorageBehaviour.EventNaniteStorageChanged += HandleCapsuleStateChange; m_CachedNaniteStorageBehaviour.EventNaniteCapacityChanged += HandleCapsuleStateChange; // Register for when the circuitry breaks/fixes m_CachedNaniteCapsule.m_CircuitryComp.EventComponentBreak += HandleComponentStateChange; m_CachedNaniteCapsule.m_CircuitryComp.EventComponentFix += HandleComponentStateChange; m_CachedNaniteCapsule.m_CalibratorComp.EventComponentBreak += HandleComponentStateChange; m_CachedNaniteCapsule.m_CalibratorComp.EventComponentFix += HandleComponentStateChange; // Update initial values UpdateDUI(); }
// Member Methods public void Start() { m_NaniteStorage = gameObject.GetComponent <CNaniteStorageBehaviour>(); // Register for when the circuitry breaks/fixes m_CircuitryComp.EventComponentBreak += HandleComponentStateChange; m_CircuitryComp.EventComponentFix += HandleComponentStateChange; m_CalibratorComp.EventComponentBreak += HandleComponentStateChange; m_CalibratorComp.EventComponentFix += HandleComponentStateChange; // Get the DUI of the power generator m_DUINaniteCapsule = m_DUIConsole.DUI.GetComponent <CDUINaniteCapsuleRoot>(); m_DUINaniteCapsule.RegisterNaniteCapsule(gameObject); if (CNetwork.IsServer) { m_NaniteStorage.NaniteCapacity = m_MaxNaniteCapacity; m_NaniteStorage.StoredNanites = 0; } }
// Member Methods public void Start() { m_NaniteStorage = gameObject.GetComponent<CNaniteStorageBehaviour>(); // Register for when the circuitry breaks/fixes m_CircuitryComp.EventComponentBreak += HandleComponentStateChange; m_CircuitryComp.EventComponentFix += HandleComponentStateChange; m_CalibratorComp.EventComponentBreak += HandleComponentStateChange; m_CalibratorComp.EventComponentFix += HandleComponentStateChange; // Get the DUI of the power generator m_DUINaniteCapsule = m_DUIConsole.DUI.GetComponent<CDUINaniteCapsuleRoot>(); m_DUINaniteCapsule.RegisterNaniteCapsule(gameObject); if(CNetwork.IsServer) { m_NaniteStorage.NaniteCapacity = m_MaxNaniteCapacity; m_NaniteStorage.StoredNanites = 0; } }
private void HandleCapsuleStateChange(CNaniteStorageBehaviour _Capsule) { UpdateDUI(); }