public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); m_thrustDefinition = (MyThrustDefinition)BlockDefinition; var builder = (MyObjectBuilder_Thrust)objectBuilder; m_thrustColor = m_thrustDefinition.FlameIdleColor; ThrustOverride = builder.ThrustOverride; LoadDummies(); m_light = MyLights.AddLight(); m_light.ReflectorDirection = WorldMatrix.Forward; m_light.ReflectorUp = WorldMatrix.Up; m_light.ReflectorRange = 1; m_light.Color = m_thrustColor; m_light.GlareMaterial = m_thrustDefinition.FlameGlareMaterial; m_light.GlareQuerySize = m_thrustDefinition.FlameGlareQuerySize; m_glareSize = m_thrustDefinition.FlameGlareSize; m_maxBillboardDistanceSquared = m_thrustDefinition.FlameVisibilityDistance * m_thrustDefinition.FlameVisibilityDistance; m_maxLightDistanceSquared = m_maxBillboardDistanceSquared / 100; m_light.Start(MyLight.LightTypeEnum.PointLight, 1); SyncObject = new MySyncThruster(this); }
void FlameHandler() { if (Entity == null) { return; } var thrust = block as MyThrust; if (thrust == null || thrust.CubeGrid.Physics == null) { return; } uint renderObjectID = Entity.Render.GetRenderObjectID(); if (renderObjectID == 4294967295u) { return; } MyThrustDefinition blockDefinition = thrust.BlockDefinition; //blockDefinition.FlameIdleColor = DefaultFlameIdleColor; blockDefinition.FlameFullColor = DefaultFlameFullColor; ((MyRenderComponentThrust)thrust.Render).UpdateFlameAnimatorData(); }
public ControllableThruster(IMyThrust thisThruster, ThrustDirection thisDirection) { _thisIThruster = thisThruster; ThrustDirection = thisDirection; _thisThruster = (MyThrust)thisThruster; _thisDefinition = _thisThruster.BlockDefinition; _thisThruster.OnClose += Close; }
internal void <OnParented> b__0_0(MyRotationAnimatorInitData d, MyThrust t) { MyThrustDefinition blockDefinition = t.BlockDefinition; float num = blockDefinition.PropellerFullSpeed * 6.283185f; d.SpinUpSpeed = num / blockDefinition.PropellerAcceleration; d.SpinDownSpeed = num / blockDefinition.PropellerDeceleration; d.RotationAxis = MyRotationAnimator.RotationAxis.AxisZ; }
public override void LoadData() { foreach (var def in MyDefinitionManager.Static.GetAllDefinitions()) { MyThrustDefinition thruster = def as MyThrustDefinition; if (thruster != null && thruster.Id.SubtypeName.ToLower().Contains("_Propeller")) { thruster.ForceMagnitude *= 1.5f; thruster.MaxPowerConsumption *= 1f; } } }
private void UpdateFlames() { if (Entity == null) { return; } var thrust = m_thruster as MyThrust; if (thrust == null || thrust.CubeGrid.Physics == null) { return; } uint renderObjectID = Entity.Render.GetRenderObjectID(); if (renderObjectID == 4294967295u) { return; } MyThrustDefinition blockDefinition = thrust.BlockDefinition; Vector4 flameIdleColor = blockDefinition.FlameIdleColor; Vector4 flameFullColor = blockDefinition.FlameFullColor; if (m_hideFlames) { blockDefinition.FlameIdleColor = Vector4D.Zero; blockDefinition.FlameFullColor = Vector4D.Zero; } else { if (m_renderMode == RenderMode.Separate) { var color = thrust.CurrentStrength > 0.001f ? m_flameFullColor : m_flameIdleColor; blockDefinition.FlameIdleColor = color; blockDefinition.FlameFullColor = color; } else { blockDefinition.FlameIdleColor = m_flameIdleColor; blockDefinition.FlameFullColor = m_flameFullColor; } } ((MyRenderComponentThrust)thrust.Render).UpdateFlameAnimatorData(); blockDefinition.FlameIdleColor = flameIdleColor; blockDefinition.FlameFullColor = flameFullColor; }
public override void OnParented() { base.OnParented(); MyThrust parent = (MyThrust)base.Entity.Parent; MyRenderProxy.UpdateRenderComponent <MyRotationAnimatorInitData, MyThrust>(base.GetRenderObjectID(), parent, delegate(MyRotationAnimatorInitData d, MyThrust t) { MyThrustDefinition blockDefinition = t.BlockDefinition; float num = blockDefinition.PropellerFullSpeed * 6.283185f; d.SpinUpSpeed = num / blockDefinition.PropellerAcceleration; d.SpinDownSpeed = num / blockDefinition.PropellerDeceleration; d.RotationAxis = MyRotationAnimator.RotationAxis.AxisZ; }); this.SendPropellerSpeed(parent.Render.m_propellerSpeed); }
public DetailedThruster(IMyEntity thruster) { Id = thruster.EntityId.ToString(); _thisEntity = (MyEntity)thruster; _thisIEntity = thruster; _thisThrust = (MyThrust)thruster; _thisIThrust = (IMyThrust)thruster; _thisTerminal = (IMyTerminalBlock)thruster; _thisBlock = (MyCubeBlock)thruster; _thisIBlock = (IMyCubeBlock)thruster; _thisIGrid = _thisBlock.CubeGrid; _thisGrid = _thisBlock.CubeGrid; _thisThrustDefinition = _thisThrust.BlockDefinition; _thisEntity.AddedToScene += OnAddedToScene; }
public static float CalculatedThrustScalar(MyThrust thruster, bool inAtmosphere, float planetaryInfluence) { float result = 1f; MyThrustDefinition definition = thruster.BlockDefinition; if (definition.NeedsAtmosphereForInfluence && !inAtmosphere) { result = definition.EffectivenessAtMinInfluence; } else if (Math.Abs(definition.MaxPlanetaryInfluence - definition.MinPlanetaryInfluence) > 0) { float value = (planetaryInfluence - definition.MinPlanetaryInfluence) * definition.InvDiffMinMaxPlanetaryInfluence; result = MathHelper.Lerp(definition.EffectivenessAtMinInfluence, definition.EffectivenessAtMaxInfluence, MathHelper.Clamp(value, 0f, 1f)); } return(result); }
private void SetThrustMountPoints(string subtypeId, params MyObjectBuilder_CubeBlockDefinition.MountPoint[] addMPObjects) { MyCubeBlockDefinition def; if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(new MyDefinitionId(typeof(MyObjectBuilder_Thrust), MyStringHash.GetOrCompute(subtypeId)), out def)) { // HACK since there's no way to edit the flame properly, this hides it and the mod draws its own MyThrustDefinition thrustDef = (MyThrustDefinition)def; thrustDef.FlameFullColor = Vector4.Zero; thrustDef.FlameIdleColor = Vector4.Zero; MyCubeBlockDefinition.MountPoint[] mp = def.MountPoints; def.MountPoints = new MyCubeBlockDefinition.MountPoint[mp.Length + addMPObjects.Length]; for (int i = 0; i < mp.Length; i++) { def.MountPoints[i] = mp[i]; } for (int i = 0; i < addMPObjects.Length; ++i) { MyObjectBuilder_CubeBlockDefinition.MountPoint mpObj = addMPObjects[i]; Vector3 start = new Vector3(Vector2.Min(mpObj.Start, mpObj.End) + 0.001f, 0.0004f); Vector3 end = new Vector3(Vector2.Max(mpObj.Start, mpObj.End) - 0.001f, -0.0004f); int side = (int)mpObj.Side; TransformMountPointPosition(ref start, side, def.Size, out start); TransformMountPointPosition(ref end, side, def.Size, out end); Vector3I forward = Vector3I.Forward; Vector3I.TransformNormal(ref forward, ref m_mountPointTransforms[side], out forward); def.MountPoints[mp.Length + i] = new MyCubeBlockDefinition.MountPoint() { Start = start, End = end, Normal = forward, ExclusionMask = mpObj.ExclusionMask, PropertiesMask = mpObj.PropertiesMask, Enabled = mpObj.Enabled, Default = mpObj.Default, }; } } }
public Progression() { IEnumerable <MyBlueprintDefinitionBase> blues = MyDefinitionManager.Static.GetBlueprintDefinitions(); //System.Collections.Generic.IEnumerable foreach (MyBlueprintDefinitionBase blue in blues) { //BlockInformation blockInfo = new BlockInformation(); //blockInfo.BlueprintId = blue.Id; //MyDefinitionId blockId = new MyDefinitionId(); //blockInfo.Results = new HashSet<SerializableDefinitionId>(); MyDefinitionId BlockId = new MyDefinitionId(); MyDefinitionId.TryParse("MyObjectBuilder_" + blue.Id.SubtypeId.String, out BlockId); if (BlockId.TypeId.IsNull) { continue; } MyCubeBlockDefinition cb = new MyCubeBlockDefinition(); MyDefinitionManager.Static.TryGetDefinition <MyCubeBlockDefinition>(BlockId, out cb); HashSet <SerializableDefinitionId> results = new HashSet <SerializableDefinitionId>(); String group = "Default"; float efficiency = 0; String cubeSize = cb.CubeSize.ToString(); String _Type = blue.Id.SubtypeId.String.Split('/')[0]; string PairName = cb.BlockPairName; MyThrustDefinition thrust = new MyThrustDefinition(); MyReactorDefinition reactor = new MyReactorDefinition(); MyCargoContainerDefinition cargo = new MyCargoContainerDefinition(); float Cost = 0; if (MyDefinitionManager.Static.TryGetDefinition <MyThrustDefinition>(BlockId, out thrust)) { if (thrust.FuelConverter.FuelId.IsNull()) { group = thrust.ThrusterType.String; } else { group = thrust.FuelConverter.FuelId.SubtypeName; } //Cost = thrust.ForceMagnitude; efficiency = thrust.ForceMagnitude;//thrust.MaxPowerConsumption; } else if (MyDefinitionManager.Static.TryGetDefinition <MyReactorDefinition>(BlockId, out reactor)) { group = reactor.FuelId.SubtypeId.String; } else if (MyDefinitionManager.Static.TryGetDefinition <MyCargoContainerDefinition>(BlockId, out cargo)) { efficiency = cargo.InventorySize.Sum; } string resultCount = blue.DisplayNameText; SerializableDefinitionId SerializedBlueprintId = blue.Id; List <MyBlueprintDefinitionBase.Item> recipe = new List <MyBlueprintDefinitionBase.Item>(); foreach (MyBlueprintDefinitionBase.Item item in blue.Results) { results.Add(item.Id); } SerializableDefinitionId smallLargeBlockId = new SerializableDefinitionId(); var dg = MyDefinitionManager.Static.TryGetDefinitionGroup(cb.BlockPairName); if (dg != null) { if (dg.Large != null) { smallLargeBlockId = dg.Large.Id; } if (dg.Small != null) { smallLargeBlockId = dg.Small.Id; } } //MyLog.Default.WriteLine($"Id {(SerializableDefinitionId)blue.Results[0].Id}"); foreach (var item in blue.Prerequisites) { Cost += item.Amount.RawValue; recipe.Add(item); } MyLog.Default.WriteLine($"Cost {Cost}"); if (BlockId != null) { SerializableDefinitionId SerializedBlockId = BlockId; ComponentsCosts.Add(BlockId, new BlockInformation(BlockId, SerializedBlockId, results, recipe, Cost, group, cubeSize, efficiency, _Type, smallLargeBlockId, PairName)); } } List <BlockInformation> existingKey = new List <BlockInformation>(); foreach (BlockInformation BI in ComponentsCosts.Values) { if (typeList.TryGetValue(BI.Type, out existingKey)) { existingKey.Add(BI); } else { // Create if not exists in dictionary List <BlockInformation> temp = new List <BlockInformation>(); temp.Add(BI); typeList.Add(BI.Type, temp); } } foreach (List <BlockInformation> BIList in typeList.Values) { BIList.Sort((pair1, pair2) => pair1.BlueprintCost.CompareTo(pair2.BlueprintCost)); } //Set Actual Positon on Each Block, so later we may get the current position out of the techtree PrepareCache(); SetTechPos(); CalculateLuck(); }
public override void Init(MyObjectBuilder_SessionComponent sessionComponent) { if (Instance == null) { Instance = this; } try { // This Variables are already loaded by this point, but unaccessible because we need Utilities. // Need to create the Utilities, as it isn't yet created by the game at this point. //MyModAPIHelper.OnSessionLoaded(); if (MyAPIGateway.Utilities == null) { MyAPIGateway.Utilities = MyAPIUtilities.Static; } // MyAPIGateway.Utilities = new MyAPIUtilities(); MyDefinitionId missileId = new MyDefinitionId(typeof(MyObjectBuilder_AmmoDefinition), "Missile"); MyMissileAmmoDefinition ammoDefinition = MyDefinitionManager.Static.GetAmmoDefinition(missileId) as MyMissileAmmoDefinition; DefaultDefinitionValues = new MidspaceEnvironmentComponent { LargeShipMaxSpeed = (decimal)MyDefinitionManager.Static.EnvironmentDefinition.LargeShipMaxSpeed, SmallShipMaxSpeed = (decimal)MyDefinitionManager.Static.EnvironmentDefinition.SmallShipMaxSpeed, MissileMinSpeed = (decimal)(ammoDefinition?.MissileInitialSpeed ?? 0), MissileMaxSpeed = (decimal)(ammoDefinition?.DesiredSpeed ?? 0), RemoteControlMaxSpeed = 100, // game hardcoded default in MyRemoteControl.CreateTerminalControls() ContainerDropDeployHeight = MessageConfig.DefaultContainerDropDeployHeight, RespawnShipDeployHeight = MessageConfig.DefaultRespawnShipDeployHeight }; // Load the speed on both server and client. string xmlValue; if (MyAPIGateway.Utilities.GetVariable("MidspaceEnvironmentComponent", out xmlValue)) { EnvironmentComponent = MyAPIGateway.Utilities.SerializeFromXML <MidspaceEnvironmentComponent>(xmlValue); if (EnvironmentComponent != null) { // Fix Defaults. if (EnvironmentComponent.Version == 0) { EnvironmentComponent.Version = SpeedConsts.ModCommunicationVersion; } if (EnvironmentComponent.ThrustRatio <= 0) { EnvironmentComponent.ThrustRatio = 1; } if (EnvironmentComponent.GyroPowerMod <= 0) { EnvironmentComponent.GyroPowerMod = 1; } if (EnvironmentComponent.IonAirEfficient < 0 || EnvironmentComponent.IonAirEfficient > 1) { EnvironmentComponent.IonAirEfficient = 0; } if (EnvironmentComponent.AtmosphereSpaceEfficient < 0 || EnvironmentComponent.AtmosphereSpaceEfficient > 1) { EnvironmentComponent.AtmosphereSpaceEfficient = 0; } if (EnvironmentComponent.MissileMinSpeed == 0) { EnvironmentComponent.MissileMinSpeed = DefaultDefinitionValues.MissileMinSpeed; } if (EnvironmentComponent.MissileMaxSpeed == 0) { EnvironmentComponent.MissileMaxSpeed = DefaultDefinitionValues.MissileMaxSpeed; } if (EnvironmentComponent.RemoteControlMaxSpeed == 0) { EnvironmentComponent.RemoteControlMaxSpeed = DefaultDefinitionValues.RemoteControlMaxSpeed; } if (EnvironmentComponent.ContainerDropDeployHeight == 0) { EnvironmentComponent.ContainerDropDeployHeight = MessageConfig.DefaultContainerDropDeployHeight; } if (EnvironmentComponent.RespawnShipDeployHeight == 0) { EnvironmentComponent.RespawnShipDeployHeight = MessageConfig.DefaultRespawnShipDeployHeight; } // Apply settings. if (EnvironmentComponent.LargeShipMaxSpeed > 0) { MyDefinitionManager.Static.EnvironmentDefinition.LargeShipMaxSpeed = (float)EnvironmentComponent.LargeShipMaxSpeed; } if (EnvironmentComponent.SmallShipMaxSpeed > 0) { MyDefinitionManager.Static.EnvironmentDefinition.SmallShipMaxSpeed = (float)EnvironmentComponent.SmallShipMaxSpeed; } if (EnvironmentComponent.EnableThrustRatio) { List <MyDefinitionBase> blocks = MyDefinitionManager.Static.GetAllDefinitions().Where(d => d is MyCubeBlockDefinition && (((MyCubeBlockDefinition)d).Id.TypeId == typeof(MyObjectBuilder_Thrust))).ToList(); foreach (var block in blocks) { MyThrustDefinition thrustBlock = (MyThrustDefinition)block; /* * // thrustBlock.ThrusterType == // this only affects the sound type. * * //thrustBlock.ResourceSinkGroup * * //if (thrustBlock.NeedsAtmosphereForInfluence) // ??? might be indicative of atmosphic thruster. * if (thrustBlock.PropellerUse) * { * // Is atmosphic thruster. * * // MinPlanetaryInfluence is the one to adjust. * // the default of 0.3 takes it down into the gravity well, somewhere below where Low Oxygen starts. * // at 0.0, it is at the cusp between Low Oxygen and No oxygen. * // at -0.3, it allows the atmosphic thruster to work in Space. * * //thrustBlock.MinPlanetaryInfluence = -0.3f; // 0.3 * //thrustBlock.MaxPlanetaryInfluence = 1f; // 1.0 * //thrustBlock.EffectivenessAtMinInfluence = 0f; // 0.0 * //thrustBlock.EffectivenessAtMaxInfluence = 1f; // 1.0 * //thrustBlock.NeedsAtmosphereForInfluence = true; // true * } * else * { * // Is Ion or Hydrogen thruster. * * //thrustBlock.FuelConverter != null // ??? Hydrogen or other fuel propellant. * * //thrustBlock.MinPlanetaryInfluence = 0.0f; // 0.0 * //thrustBlock.MaxPlanetaryInfluence = 0.3f; // 1.0 * //thrustBlock.EffectivenessAtMinInfluence = 1.0f; // 1.0 * //thrustBlock.EffectivenessAtMaxInfluence = 0.0f; // 0.3 * } */ thrustBlock.ForceMagnitude *= (float)EnvironmentComponent.ThrustRatio; } } /* * // if enabled Gyro boost. * { * List<MyDefinitionBase> blocks = MyDefinitionManager.Static.GetAllDefinitions().Where(d => d is MyCubeBlockDefinition && * (((MyCubeBlockDefinition) d).Id.TypeId == typeof (MyObjectBuilder_Gyro))).ToList(); * foreach (var block in blocks) * { * MyGyroDefinition gyroBlock = (MyGyroDefinition) block; * //gyroBlock.ForceMagnitude *= 100; // This works. * } * } */ if (ammoDefinition != null && EnvironmentComponent.MissileMinSpeed > 0) { ammoDefinition.MissileInitialSpeed = (float)EnvironmentComponent.MissileMinSpeed; } if (ammoDefinition != null && EnvironmentComponent.MissileMaxSpeed > 0) { ammoDefinition.DesiredSpeed = (float)EnvironmentComponent.MissileMaxSpeed; } #region ContainerDropDeployHeight // We're basically changing the ContainerDrop prefabs that are loaded in memory before any of them are spawned. // This is not my preferred approach, as these could be altered (by other mods) or reset (reload from disc by the game or mods). // The prefered approach is to modify the chute.DeployHeight after a container is spawned, but it is not whitelisted. DictionaryReader <string, MyDropContainerDefinition> dropContainers = MyDefinitionManager.Static.GetDropContainerDefinitions(); foreach (var kvp in dropContainers) { foreach (MyObjectBuilder_CubeGrid grid in kvp.Value.Prefab.CubeGrids) { foreach (MyObjectBuilder_CubeBlock block in grid.CubeBlocks) { MyObjectBuilder_Parachute chute = block as MyObjectBuilder_Parachute; if (chute != null) { if (chute.DeployHeight < (float)EnvironmentComponent.ContainerDropDeployHeight) { chute.DeployHeight = (float)EnvironmentComponent.ContainerDropDeployHeight; } } } } } #endregion #region RespawnShipDeployHeight DictionaryReader <string, MyRespawnShipDefinition> respawnShips = MyDefinitionManager.Static.GetRespawnShipDefinitions(); foreach (var kvp in respawnShips) { foreach (MyObjectBuilder_CubeGrid grid in kvp.Value.Prefab.CubeGrids) { foreach (MyObjectBuilder_CubeBlock block in grid.CubeBlocks) { MyObjectBuilder_Parachute chute = block as MyObjectBuilder_Parachute; if (chute != null) { if (chute.DeployHeight < (float)EnvironmentComponent.RespawnShipDeployHeight) { chute.DeployHeight = (float)EnvironmentComponent.RespawnShipDeployHeight; } } } } } #endregion OldEnvironmentComponent = EnvironmentComponent.Clone(); return; } } // creates a new EnvironmentComponent if one was not found in the game Variables. EnvironmentComponent = new MidspaceEnvironmentComponent { Version = SpeedConsts.ModCommunicationVersion, LargeShipMaxSpeed = (decimal)MyDefinitionManager.Static.EnvironmentDefinition.LargeShipMaxSpeed, SmallShipMaxSpeed = (decimal)MyDefinitionManager.Static.EnvironmentDefinition.SmallShipMaxSpeed, EnableThrustRatio = false, MissileMinSpeed = (decimal)(ammoDefinition?.MissileInitialSpeed ?? 0), MissileMaxSpeed = (decimal)(ammoDefinition?.DesiredSpeed ?? 0), ThrustRatio = 1, RemoteControlMaxSpeed = 100, ContainerDropDeployHeight = MessageConfig.DefaultContainerDropDeployHeight, RespawnShipDeployHeight = MessageConfig.DefaultRespawnShipDeployHeight }; OldEnvironmentComponent = EnvironmentComponent.Clone(); } catch (Exception ex) { VRage.Utils.MyLog.Default.WriteLine("##Mod## ERROR " + ex.Message); // The Loggers doesn't actually exist yet, as Init is called before UpdateBeforeSimulation. // TODO: should rework the code to change this. //ClientLogger.WriteException(ex); //ServerLogger.WriteException(ex); } }