void Process_wheel_motor(ModuleWheelMotor motor)
		{
			foreach (ModuleResource res in motor.resHandler.inputResources)
			{
				Resource(res.name).Consume(res.rate, "wheel");
			}
		}
 public ModuleWheelBaseAdaptor(Part part)
 {
     _moduleWheelBase          = part.FindModuleImplementing <ModuleWheelBase>();
     _moduleWheelMotor         = part.FindModuleImplementing <ModuleWheelMotor>();
     _moduleWheelMotorSteering = part.FindModuleImplementing <ModuleWheelMotorSteering>();
     _moduleWheelDamage        = part.FindModuleImplementing <ModuleWheelDamage>();
 }
 public ModuleWheelBaseAdaptor(Part part)
 {
     _moduleWheelBase = part.FindModuleImplementing<ModuleWheelBase>();
     _moduleWheelMotor = part.FindModuleImplementing<ModuleWheelMotor>();
     _moduleWheelMotorSteering = part.FindModuleImplementing<ModuleWheelMotorSteering>();
     _moduleWheelDamage = part.FindModuleImplementing<ModuleWheelDamage>();
 }
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     this.wheelBase     = base.part.FindModuleImplementing <ModuleWheelBase>();
     this.wheelSteering = base.part.FindModuleImplementing <ModuleWheelSteering>();
     this.wheelBrakes   = base.part.FindModuleImplementing <ModuleWheelBrakes>();
     this.wheelMotor    = base.part.FindModuleImplementing <ModuleWheelMotor>();
 }
        public override void OnStart(StartState state)
        {
            if (state == StartState.Editor || state == StartState.None)
            {
                return;
            }

            string partParentName = part.name + "_" + this.moduleName;

            audioParent = part.gameObject.GetChild(partParentName);
            if (audioParent == null)
            {
                audioParent = new GameObject(partParentName);
                audioParent.transform.rotation = part.transform.rotation;
                audioParent.transform.position = part.transform.position;
                audioParent.transform.parent   = part.transform;
            }

            moduleWheel  = part.GetComponent <ModuleWheelBase>();
            moduleMotor  = part.GetComponent <ModuleWheelMotor>();
            moduleDeploy = part.GetComponent <ModuleWheelDeployment>();

            var configNode = AudioUtility.GetConfigNode(part.partInfo.name, this.moduleName);

            SoundLayerGroups.Clear();
            spools.Clear();
            foreach (var node in configNode.GetNodes())
            {
                string _wheelState = node.name;

                var soundLayers = AudioUtility.CreateSoundLayerGroup(node.GetNodes("SOUNDLAYER"));
                if (soundLayers.Count > 0)
                {
                    if (SoundLayerGroups.ContainsKey(_wheelState))
                    {
                        SoundLayerGroups[_wheelState].AddRange(soundLayers);
                    }
                    else
                    {
                        SoundLayerGroups.Add(_wheelState, soundLayers);
                    }
                }
            }

            GameEvents.onGamePause.Add(onGamePause);
            GameEvents.onGameUnpause.Add(onGameUnpause);

            initialized = true;
        }
Beispiel #6
0
        public void FixedUpdate()
        {
            if (Input.GetKeyDown(KeyCode.Keypad5))
            {
                ModuleWheelMotor motorModule = part.Modules.GetModule <ModuleWheelMotor>();
                foreach (Keyframe kf in motorModule.torqueCurve.Curve.keys)
                {
                    Debug.Log($"Debug Reductor: {kf.time} -> {kf.value}");
                }

                Debug.Log(
                    $"Debug Max Speed: {motorModule.wheelSpeedMax}, Reductor Ratio: {reductorRatio}, " +
                    $"Max Torque: {motorModule.maxTorque}, Drive Output: {motorModule.driveOutput}");
                Debug.Log($"Reductor: gui={guiReductorRatio}, reductor={reductorRatio}");
            }
        }
Beispiel #7
0
        public void SetupReductor()
        {
            Debug.Log("Reductor: Setup called");

            Part             prefab      = part.partInfo.partPrefab;
            ModuleWheelMotor prefabMotor = prefab.Modules.GetModule <ModuleWheelMotor>();

            if (prefabMotor == null)
            {
                return;
            }
            guiReductorRatio = reductorRatio;
            checkTweakScale();

            float maxTorque = 0;
            // Get curve from prefab
            FloatCurve newCurve = new FloatCurve();

            ModuleWheelMotor motor = part.Modules.GetModule <ModuleWheelMotor>();

            foreach (Keyframe kf in prefabMotor.torqueCurve.Curve.keys)
            {
                Debug.Log($"Reductor: Prefab Curve: {kf.time} -> {kf.value}");
                newCurve.Add(
                    kf.time / reductorRatio, kf.value * tweakScaleRatio * reductorRatio);
                maxTorque = kf.value > maxTorque ? kf.value : maxTorque;
            }
            foreach (Keyframe kf in newCurve.Curve.keys)
            {
                Debug.Log(String.Format("Reductor: New Curve: {0} -> {1}", kf.time, kf.value));
//                newCurve.Add(kf.time * effectiveReductorRatio, kf.value / effectiveReductorRatio);
//                maxTorque = kf.value > maxTorque ? kf.value : maxTorque;
            }

            motor.torqueCurve   = newCurve;
            motor.wheelSpeedMax = prefabMotor.wheelSpeedMax * tweakScaleRatio / reductorRatio;
            motor.maxTorque     = maxTorque * tweakScaleRatio * reductorRatio;
            Debug.Log($"MaxTorque={motor.maxTorque}, MaxSpeed={motor.wheelSpeedMax}");
        }
Beispiel #8
0
  public static ec_data analyze_ec(List<Part> parts, environment_data env, crew_data crew, food_data food, oxygen_data oxygen, signal_data signal)
  {
    // store data
    ec_data ec = new ec_data();

    // calculate climate cost
    ec.consumed = (double)crew.count * env.temp_diff * Settings.ElectricChargePerSecond;

    // scan the parts
    foreach(Part p in parts)
    {
      // accumulate EC storage
      ec.storage += Lib.GetResourceAmount(p, "ElectricCharge");

      // remember if we already considered a resource converter module
      // rationale: we assume only the first module in a converter is active
      bool first_converter = true;

      // for each module
      foreach(PartModule m in p.Modules)
      {
        // command
        if (m.moduleName == "ModuleCommand")
        {
          ModuleCommand mm = (ModuleCommand)m;
          foreach(ModuleResource res in mm.inputResources)
          {
            if (res.name == "ElectricCharge")
            {
              ec.consumed += res.rate;
            }
          }
        }
        // solar panel
        else if (m.moduleName == "ModuleDeployableSolarPanel")
        {
          ModuleDeployableSolarPanel mm = (ModuleDeployableSolarPanel)m;
          double solar_k = (mm.useCurve ? mm.powerCurve.Evaluate((float)env.sun_dist) : env.sun_flux / Sim.SolarFluxAtHome());
          double generated = mm.chargeRate * solar_k * env.atmo_factor;
          ec.generated_sunlight += generated;
          ec.best_ec_generator = Math.Max(ec.best_ec_generator, generated);
        }
        // generator
        else if (m.moduleName == "ModuleGenerator")
        {
          // skip launch clamps, that include a generator
          if (p.partInfo.name == "launchClamp1") continue;

          ModuleGenerator mm = (ModuleGenerator)m;
          foreach(ModuleResource res in mm.inputList)
          {
            if (res.name == "ElectricCharge")
            {
              ec.consumed += res.rate;
            }
          }
          foreach(ModuleResource res in mm.outputList)
          {
            if (res.name == "ElectricCharge")
            {
              ec.generated_shadow += res.rate;
              ec.generated_sunlight += res.rate;
              ec.best_ec_generator = Math.Max(ec.best_ec_generator, res.rate);
            }
          }
        }
        // converter
        // note: only electric charge is considered for resource converters
        // note: we only consider the first resource converter in a part, and ignore the rest
        else if (m.moduleName == "ModuleResourceConverter" && first_converter)
        {
          ModuleResourceConverter mm = (ModuleResourceConverter)m;
          foreach(ResourceRatio rr in mm.inputList)
          {
            if (rr.ResourceName == "ElectricCharge")
            {
              ec.consumed += rr.Ratio;
            }
          }
          foreach(ResourceRatio rr in mm.outputList)
          {
            if (rr.ResourceName == "ElectricCharge")
            {
              ec.generated_shadow += rr.Ratio;
              ec.generated_sunlight += rr.Ratio;
              ec.best_ec_generator = Math.Max(ec.best_ec_generator, rr.Ratio);
            }
          }
          first_converter = false;
        }
        // harvester
        // note: only electric charge is considered for resource harvesters
        else if (m.moduleName == "ModuleResourceHarvester")
        {
          ModuleResourceHarvester mm = (ModuleResourceHarvester)m;
          foreach(ResourceRatio rr in mm.inputList)
          {
            if (rr.ResourceName == "ElectricCharge")
            {
              ec.consumed += rr.Ratio;
            }
          }
        }
        // active radiators
        else if (m.moduleName == "ModuleActiveRadiator")
        {
          ModuleActiveRadiator mm = (ModuleActiveRadiator)m;
          if (mm.IsCooling)
          {
            foreach(var rr in mm.inputResources)
            {
              if (rr.name == "ElectricCharge")
              {
                ec.consumed += rr.rate;
              }
            }
          }
        }
        // wheels
        else if (m.moduleName == "ModuleWheelMotor")
        {
          ModuleWheelMotor mm = (ModuleWheelMotor)m;
          if (mm.motorEnabled && mm.inputResource.name == "ElectricCharge")
          {
            ec.consumed += mm.inputResource.rate;
          }
        }
        else if (m.moduleName == "ModuleWheelMotorSteering")
        {
          ModuleWheelMotorSteering mm = (ModuleWheelMotorSteering)m;
          if (mm.motorEnabled && mm.inputResource.name == "ElectricCharge")
          {
            ec.consumed += mm.inputResource.rate;
          }
        }
        // SCANsat support
        else if (m.moduleName == "SCANsat" || m.moduleName == "ModuleSCANresourceScanner")
        {
          // include it in ec consumption, if deployed
          if (SCANsat.isDeployed(p, m)) ec.consumed += Lib.ReflectionValue<float>(m, "power");
        }
        // NearFutureSolar support
        // note: assume half the components are in sunlight, and average inclination is half
        else if (m.moduleName == "ModuleCurvedSolarPanel")
        {
          // get total rate
          double tot_rate = Lib.ReflectionValue<float>(m, "TotalEnergyRate");

          // get number of components
          int components = p.FindModelTransforms(Lib.ReflectionValue<string>(m, "PanelTransformName")).Length;

          // approximate output
          // 0.7071: average clamped cosine
          ec.generated_sunlight += 0.7071 * tot_rate;
        }
      }
    }

    // include cost from greenhouses artificial lighting
    ec.consumed += food.greenhouse_cost;

    // include cost from scrubbers
    ec.consumed += oxygen.scrubber_cost;

    // include relay cost for the best relay antenna
    ec.consumed += signal.relay_cost;

    // finally, calculate life expectancy of ec
    ec.life_expectancy_sunlight = ec.storage / Math.Max(ec.consumed - ec.generated_sunlight, 0.0);
    ec.life_expectancy_shadow = ec.storage / Math.Max(ec.consumed - ec.generated_shadow, 0.0);

    // return data
    return ec;
  }