Sinus32

ProcessDrillsLights() method with white lights

Sep 17th, 2015
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. private void ProcessDrillsLights()
  2. {
  3.     if (!ENABLE_DISTRIBUTING_ORE_IN_DRILLS)
  4.     {
  5.         _output.AppendLine("Setting color of drills payload indicators is disabled.");
  6.         return;
  7.     }
  8.  
  9.     if (_drillsPayloadLights.Count == 0)
  10.     {
  11.         _output.AppendLine("Setting color of drills payload indicators. Not enough lights found. Nothing to do.");
  12.         return;
  13.     }
  14.  
  15.     _output.AppendLine("Setting color of drills payload indicators.");
  16.  
  17.     Color color;
  18.  
  19.     if (_notConnectedDrillsFound)
  20.     {
  21.         _output.AppendLine("Not all drills are connected.");
  22.  
  23.         if (Storage == null || Storage.Length == 0 || Storage[0] == '0')
  24.         {
  25.             color = new Color(0, 128, 128);
  26.             Storage = "1";
  27.         }
  28.         else
  29.         {
  30.             color = new Color(0, 64, 128);
  31.             Storage = "0";
  32.         }
  33.     }
  34.     else
  35.     {
  36.         float p;
  37.         if (_drillsMaxVolume > 0)
  38.         {
  39.             p = (float)_drillsCurrentVolume * 1000.0f;
  40.             p /= (float)_drillsMaxVolume;
  41.  
  42.             _output.Append("Drills space usage: ");
  43.             _output.Append((p / 10.0f).ToString("F1"));
  44.             _output.AppendLine("%");
  45.  
  46.             if ((_drillsMaxVolume - _drillsCurrentVolume) < WARNING_LEVEL_IN_CUBIC_METERS_LEFT)
  47.             {
  48.                 if (Storage == null || Storage.Length == 0 || Storage[0] == '0')
  49.                 {
  50.                     color = new Color(128, 0, 128);
  51.                     Storage = "1";
  52.                 }
  53.                 else
  54.                 {
  55.                     color = new Color(128, 0, 64);
  56.                     Storage = "0";
  57.                 }
  58.             }
  59.             else
  60.             {
  61.                 float r, g, b;
  62.  
  63.                 if (p < 500.0f)
  64.                 {
  65.                     r = 255.0f;
  66.                     g = 255.0f;
  67.                     b = 255.0f * (500.0f - p) / 500.0f;
  68.                 }
  69.                 else
  70.                 {
  71.                     r = 255.0f;
  72.                     g = 255.0f * (900.0f - p) / 500.0f;
  73.                     b = 0.0f;
  74.                 }
  75.  
  76.                 if (r > 255.0f) r = 255.0f;
  77.                 else if (r < 0.0f) r = 0.0f;
  78.  
  79.                 if (g > 255.0f) g = 255.0f;
  80.                 else if (g < 0.0f) g = 0.0f;
  81.  
  82.                 if (b > 255.0f) b = 255.0f;
  83.                 else if (b < 0.0f) b = 0.0f;
  84.  
  85.                 color = new Color((int)r, (int)g, (int)b);
  86.                 Storage = "0";
  87.             }
  88.         }
  89.         else
  90.         {
  91.             color = new Color(255, 255, 255);
  92.         }
  93.     }
  94.  
  95.     _output.Append("Drills payload indicators lights color: ");
  96.     _output.Append(color);
  97.     _output.AppendLine();
  98.  
  99.     for (int i = 0; i < _drillsPayloadLights.Count; ++i)
  100.     {
  101.         IMyLightingBlock light = _drillsPayloadLights[i];
  102.         Color currentColor = light.GetValue<Color>("Color");
  103.         if (currentColor != color)
  104.         {
  105.             light.SetValue<Color>("Color", color);
  106.         }
  107.     }
  108.  
  109.     _output.Append("Color of ");
  110.     _output.Append(_drillsPayloadLights.Count);
  111.     _output.AppendLine(" drills payload indicators has been set.");
  112. }
Advertisement
Add Comment
Please, Sign In to add comment