void Connections() { //ExpencesCommunications = 0; float plumbingLen = 0; float heatingLen = 0; float ventsLen = 0; // HOT WATER // looking for closest boiler foreach (LogicRiser l in LCache.Risers) { LogicBoiler b = LCache.FindClosest <LogicBoiler>(LCache.Boilers, l.Center); if (b != null) { plumbingLen += Vector3.Distance(b.Center, l.Center); l.HasHotWater = true; } else { l.HasHotWater = Conditions.HotWater; } } //looking for risers foreach (IHotWaterConsumer lh in LCache.HotWaterConsumers) { ILogicObject l = lh as ILogicObject; LogicRiser r = LCache.FindClosest <LogicRiser>(LCache.Risers, l.Center); if (r != null) { plumbingLen += Vector3.Distance(r.Center, l.Center); lh.HasHotWater = r.HasHotWater; } } // HEATING foreach (LogicHeatingPipe h in LCache.HeatingPipes) { h.HasHotWater = Conditions.HotWater; } foreach (LogicHeater h in LCache.Heaters) { LogicHeatingPipe pipe = LCache.FindClosest <LogicHeatingPipe>(LCache.HeatingPipes, h.Center); if (pipe != null) { heatingLen += Vector3.Distance(h.Center, pipe.Center); h.Operates = pipe.HasHotWater; } } if (LCache.Vents.Count > 0) { // Vents foreach (Room r in Rooms) { if (r.TypeOfRoom != RoomType.Kitchen && r.TypeOfRoom != RoomType.Garage && r.TypeOfRoom != RoomType.Dining && r.TypeOfRoom != RoomType.Bathroom && r.TypeOfRoom != RoomType.Toilet && r.TypeOfRoom != RoomType.ToiletBathroom) { continue; } float distance = -1; LogicVentshaft closest = null; foreach (LogicVentshaft v in LCache.Vents) { float d = r.CalcDistance(v.Center); if (closest == null || distance > d) { closest = v; distance = d; } } ventsLen += distance; r.Ventilated = true; } } Debug.Log(string.Format("pipes len {0}, heating len {1}, vents len {2}", plumbingLen, heatingLen, ventsLen)); M.Statistic.CommunicationsCost = (int)(plumbingLen * Conditions.PlumbingCost + heatingLen * Conditions.HeatingCost + ventsLen * Conditions.VentsCost); }