protected BlockInstructions(IMyTerminalBlock block) { m_logger = new Logger("BlockInstructions", block as IMyCubeBlock); m_block = block as IMyCubeBlock; block.CustomNameChanged += BlockChange; }
public ShipControllerBlock(IMyCubeBlock block) { m_logger = new Logger(GetType().Name, block); Controller = block as MyShipController; CubeBlock = block; Terminal = block as IMyTerminalBlock; Pseudo = new PseudoBlock(block); }
public void PrintActions(IMyTerminalBlock block) { List<ITerminalAction> results = new List<ITerminalAction>(); block.GetActions(results); for (int i=0; i<results.Count; i++) Println(results[i].Name.ToString()); }
public void PrintProperties(IMyTerminalBlock block) { List<ITerminalProperty> results = new List<ITerminalProperty>(); block.GetProperties(results); for (int i=0; i<results.Count; i++) Println(results[i].Id); }
public Elevator(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) { GridTerminalSystem = grid; Echo = echo; ElapsedTime = elapsedTime; Me = me; }
public BlockInstructions(IMyTerminalBlock block, Func<string, bool> onInstruction) { m_logger = new Logger("BlockInstructions", block as IMyCubeBlock); m_block = block; m_onInstruction = onInstruction; m_block.CustomNameChanged += BlockChange; }
public Autopilot_CustomInfo(IMyCubeBlock block) { this.m_logger = new Logger("Autopilot_CustomInfo", block); this.m_block = block as IMyTerminalBlock; m_block.AppendingCustomInfo += AppendingCustomInfo; Registrar.Add(block, this); m_logger.debugLog("Initialized", "Autopilot_CustomInfo()", Logger.severity.INFO); }
private bool DoorFilter(IMyTerminalBlock arg) { var door = (IMyDoor)arg; if (MY_GRID_ONLY && door.CubeGrid != Me.CubeGrid) return false; var def = door.BlockDefinition.ToString(); if (!def.StartsWith("MyObjectBuilder_Door/")) return false; return door.Enabled && door.IsFunctional && door.Open && door.OpenRatio >= 0.99f; }
public AutopilotTerminal(IMyCubeBlock block) { this.m_logger = new Logger("AutopilotTerminal", block); this.m_block = block as IMyTerminalBlock; byte index = 0; this.m_autopilotControl = new EntityValue<bool>(block, index++, Static.autopilotControl.UpdateVisual, Saver.Instance.LoadOldVersion(69) && ((MyShipController)block).ControlThrusters); this.m_autopilotCommands = new EntityStringBuilder(block, index++, Static.autopilotCommands.UpdateVisual); m_block.AppendingCustomInfo += AppendingCustomInfo; Registrar.Add(block, this); m_logger.debugLog("Initialized", Logger.severity.INFO); }
public static void CustomHandler(IMyTerminalBlock block, List<IMyTerminalControl> controlList) { ManualMessage instance; if (!Registrar.TryGetValue(block.EntityId, out instance)) return; if (instance.m_sending) { controlList.Clear(); controlList.Add(Static.AbortMessageButton); controlList.Add(Static.TargetShipName); controlList.Add(Static.TargetBlockName); controlList.Add(Static.Message); controlList.Add(Static.SendMessageButton); } else { controlList.Add(Static.SendMessageButton); } }
public void set_oriented_gyros(IMyGyro[] gyros, IMyTerminalBlock pivot, Vector3D tar){ Matrix orientation; pivot.Orientation.GetMatrix(out orientation); MatrixD invMatrix = MatrixD.Invert(orientation); Vector3D localTar = Vector3D.Transform(tar, MatrixD.Invert(MatrixD.CreateFromDir(pivot.WorldMatrix.Forward, pivot.WorldMatrix.Up)) * orientation); Vector3D angsin = Vector3D.Cross(orientation.Forward, localTar); Vector3D ang = new Vector3D(Math.Sin(angsin.GetDim(0)), Math.Sin(angsin.GetDim(1)), Math.Sin(angsin.GetDim(2))); for (int i = 0; i < gyros.Length; i++) { Matrix gyro_or; gyros[i].Orientation.GetMatrix(out gyro_or); MatrixD invGyroMatrix = invMatrix*MatrixD.Invert(gyro_or); Vector3D angle = Vector3D.Transform(ang,invGyroMatrix); gyros[i].SetValueFloat("Pitch", (float)angle.GetDim(0)); gyros[i].SetValueFloat("Yaw", (float)angle.GetDim(1)); gyros[i].SetValueFloat("Roll", (float)angle.GetDim(2)); } }
/// <summary> /// gets the message that was sent from player / ingame programming /// </summary> public static List<Message> getFromName(IMyTerminalBlock sender) { string name = sender.DisplayNameText; int start = name.IndexOf(startOfSend) + startOfSend.Length; int length = name.LastIndexOf(endOfSend) - start; if (start <= startOfSend.Length || length < 1) // nothing to send { myLogger.debugLog("nothing to send for " + name, "getFromName()", Logger.severity.TRACE); return null; } // clear message from name string NameNew = name.Remove(start - startOfSend.Length); sender.SetCustomName(NameNew); string[] sent = name.Substring(start, length).Split(separator); string message; if (sent.Length < 3) // not possible to send { myLogger.debugLog("cannot send while split has length " + sent.Length + ", for " + name, "getFromName()", Logger.severity.DEBUG); return null; } else if (sent.Length == 3) message = sent[2]; else // sent.Length > 3 { StringBuilder messageSB = new StringBuilder(); for (int index = 2; index < sent.Length; index++) { if (index != 2) messageSB.Append(separator); messageSB.Append(sent[index]); } message = messageSB.ToString(); } return Message.buildMessages(message, sent[0], sent[1], sender as IMyCubeBlock, NameNew); }
private void printPropertiesAndActions(IMyTerminalBlock block) { List<ITerminalProperty> prop = new List<ITerminalProperty>(); block.GetProperties(prop); Echo("Properties:"); foreach (ITerminalProperty p in prop) { Echo("ID: " + p.Id); Echo("Type: " + p.TypeName); } List<ITerminalAction> acts = new List<ITerminalAction>(); block.GetActions(acts); Echo("Actions:"); foreach (ITerminalAction a in acts) { //Echo("Icon: " + a.Icon); Echo("ID: " + a.Id); Echo("Name: " + a.Name); } }
private static void SetOffset(IMyTerminalBlock block, int dim, float value) { Projector proj; if (!Registrar.TryGetValue(block, out proj)) return; Vector3 offset = proj.m_offset_ev.Value;//.SetDim(dim, value); offset.SetDim(dim, value); proj.m_offset_ev.Value = offset; }
private static void SetRangeDetection(IMyTerminalBlock block, float value) { Projector proj; if (!Registrar.TryGetValue(block, out proj)) return; proj.m_rangeDetection.Value = value; }
public virtual bool hyperVisible(IMyTerminalBlock hyper_block) { return(hyper_block.BlockDefinition.TypeId == hyperDefinition.TypeId && hyper_block.BlockDefinition.SubtypeId == hyperDefinition.SubtypeId); }
void Main() { // Get blocks var blocks = new List <IMyTerminalBlock>(); // Get the antenna GridTerminalSystem.GetBlocksOfType <IMyRadioAntenna>(blocks); if (blocks.Count > 0) { IMyTerminalBlock Block = blocks[0]; // Get time now var Time1 = System.DateTime.Now; long OldTime = 0; // We pull this here to prevent conversions being *too* weird long CurrentTime = Time1.ToBinary(); // Store the current name String CurrentName = Block.CustomName; // Get the fragments (or get one fragment) String[] Fragments = CurrentName.Split('|'); // Get coordinates (VRageMath.Vector3D, so pull it in the ugly way) double x = Math.Round(Block.GetPosition().GetDim(0), 4); double y = Math.Round(Block.GetPosition().GetDim(1), 4); double z = Math.Round(Block.GetPosition().GetDim(2), 4); // Allocate this here double X = 0; double Y = 0; double Z = 0; // Start with "the unknown" speed, stored in m/s double Speed = 0.0; // Total distance moved double Distance = 0; // Do we actually have fragments? if (Fragments.Length == 3) { // Yes? Excellent. OldTime = Convert.ToInt64(Fragments[1]); // Vomit a bit here because this is how we have to store variables at the moment ... string[] Coords = Fragments[2].Split(','); X = Math.Round(Convert.ToDouble(Coords[0]), 4); Y = Math.Round(Convert.ToDouble(Coords[1]), 4); Z = Math.Round(Convert.ToDouble(Coords[2]), 4); // Nothing fancy here Distance = System.Math.Sqrt( ((x - X) * (x - X)) + ((y - Y) * (y - Y)) + ((z - Z) * (z - Z)) ); } // If the base coordinates if (Distance != 0 && X != 0 && Y != 0 && Z != 0 && OldTime != 0) { // Update time var Time0 = System.DateTime.FromBinary(OldTime); // We have 's' for m/s. var TimeDelta = (Time1 - Time0).TotalSeconds; // We have our distance Speed = Distance / TimeDelta; Speed = Math.Round(Convert.ToDouble(Speed), 4); } // Speed|Time|X,Y,Z String NewName = Speed.ToString() + "|" + CurrentTime.ToString() + "|" + x.ToString() + "," + y.ToString() + "," + z.ToString(); // Store it Block.CustomName = NewName; // Show it on the HUD so we can check it Block.ShowOnHUD = true; } }
private static StringBuilder GetAutopilotCommands(IMyTerminalBlock block) { AutopilotTerminal autopilot; if (!Registrar.TryGetValue(block, out autopilot)) { Static.s_logger.alwaysLog("Failed lookup of block: " + block.getBestName(), Logger.severity.WARNING); return new StringBuilder(); ; } return autopilot.m_autopilotCommands.Value; }
public void SetOrientation(IMyTerminalBlock relativeTo, Quaternion orientation) { target.SetOrientation(relativeTo, orientation); }
public void OverLoadShield(IMyTerminalBlock block) => _overLoad?.Invoke(block);
/// <summary> /// Checks if block can be type. /// </summary> /// <param name="TypeIdString"></param> /// <returns>Delegate type checker</returns> public static bool IsType <Type>(IMyTerminalBlock Block) { return(Block is Type); }
public void SetShieldHeat(IMyTerminalBlock block, int value) => _setShieldHeat?.Invoke(block, value);
public void SetSkipLos(IMyTerminalBlock block) => _setSkipLos?.Invoke(block);
public float?PointAttackShieldExt(IMyTerminalBlock block, Vector3D pos, long attackerId, float damage, bool energy, bool drawParticle, bool posMustBeInside = false) => _pointAttackShieldExt?.Invoke(block, pos, attackerId, damage, energy, drawParticle, posMustBeInside) ?? null;
public Vector3D?LineAttackShield(IMyTerminalBlock block, LineD line, long attackerId, float damage, bool energy, bool drawParticle) => _lineAttackShield?.Invoke(block, line, attackerId, damage, energy, drawParticle) ?? null;
public Vector3D?RayAttackShield(IMyTerminalBlock block, RayD ray, long attackerId, float damage, bool energy, bool drawParticle) => _rayAttackShield?.Invoke(block, ray, attackerId, damage, energy, drawParticle) ?? null;
private static void WriterMetres(Func<IMyTerminalBlock, float> Getter, IMyTerminalBlock block, StringBuilder stringBuilder) { stringBuilder.Append(PrettySI.makePretty(Getter(block))); stringBuilder.Append("m"); }
public void SetCharge(IMyTerminalBlock block, float value) => _setCharge.Invoke(block, value);
public virtual void hyperWriter(IMyTerminalBlock hyper_block, StringBuilder builder) { }
public Vector3D?RayIntersectShield(IMyTerminalBlock block, RayD ray) => _rayIntersectShield?.Invoke(block, ray) ?? null;
private void ExitLadder(bool setFreeFallAnimation = true) { if(grabOnLoad) grabOnLoad = false; if(usingLadder == null) return; SendLadderData(LadderAction.LET_GO); usingLadder = null; alignedToGravity = false; skipRetryGravity = GRAVITY_UPDATERATE; if(MyAPIGateway.Session.ControlledObject is IMyCharacter && setFreeFallAnimation && character != null && lastLadderAnim != LadderAnimation.NONE) { LadderAnim(character, LadderAnimation.JUMP_OFF); } lastLadderAnim = LadderAnimation.NONE; }
public Vector3D?LineIntersectShield(IMyTerminalBlock block, LineD line) => _lineIntersectShield?.Invoke(block, line) ?? null;
private void AppendingCustomInfo(IMyTerminalBlock arg1, StringBuilder arg2) { arg2.Append(m_customInfo); }
public bool PointInShield(IMyTerminalBlock block, Vector3D pos) => _pointInShield?.Invoke(block, pos) ?? false;
bool TransferItem(IMyTerminalBlock blockFrom, IMyTerminalBlock blockTo, string itemType, ref float amount) { return(true); }
public float GetShieldPercent(IMyTerminalBlock block) => _getShieldPercent?.Invoke(block) ?? -1;
public virtual void OnhyperAction(IMyTerminalBlock hyper_block) { }
public int GetShieldHeat(IMyTerminalBlock block) => _getShieldHeat?.Invoke(block) ?? -1;
private static float Normalizer(float min, float max, IMyTerminalBlock block, float value) { return (value - min) / (max - min); }
public float HpToChargeRatio(IMyTerminalBlock block) => _hpToChargeRatio?.Invoke(block) ?? -1;
private static void SetOptionTerminal(IMyTerminalBlock block, Option opt, bool value) { Projector proj; if (!Registrar.TryGetValue(block, out proj)) return; if (value) proj.m_options.Value |= opt; else proj.m_options.Value &= ~opt; if (opt == Option.OnOff || opt == Option.ShowOffset || opt == Option.IntegrityColours) MyGuiScreenTerminal.SwitchToControlPanelBlock((MyTerminalBlock)block); }
public NaniteAreaBeaconConstruct(IMyTerminalBlock beaconBlock) : base(beaconBlock) { }
private static void SetSizeScale(IMyTerminalBlock block, float value) { Projector proj; if (!Registrar.TryGetValue(block, out proj)) return; proj.m_sizeDistScale.Value = value; }
// ----------------------------------------------------------------------------------- bool DoorFilterMethod(IMyTerminalBlock block) { IMyDoor door = block as IMyDoor; return door != null; }
private void BlockChange(IMyTerminalBlock obj) { m_displayNameDirty = true; }
// ----------------------------------------------------------------------------------- bool LightFilterMethod(IMyTerminalBlock block) { IMyInteriorLight light = block as IMyInteriorLight; return light != null; }
public float GetCharge(IMyTerminalBlock block) => _getCharge?.Invoke(block) ?? -1;
private static string[] GetConfigLines(IMyTerminalBlock block) => block.CustomData.Split(_configLineSeparators, StringSplitOptions.RemoveEmptyEntries);
public static void SetCustomName( IMyTerminalBlock terminalBlock, string text ) { try { StringBuilder newCustomName = new StringBuilder( text ); InvokeStaticMethod( terminalBlock.GetType( ), TerminalBlockBroadcastCustomNameMethod, new object[ ] { terminalBlock, newCustomName } ); } catch ( Exception ex ) { ApplicationLog.BaseLog.Error( string.Format( "SetCustomName(): {0}", ex ) ); } }
public float GetPowerUsed(IMyTerminalBlock block) => _getPowerUsed?.Invoke(block) ?? -1;
// ----------------------------------------------------------------------------------- bool AirVentsFilterMethod(IMyTerminalBlock block) { IMyAirVent airvent = block as IMyAirVent; return airvent != null; }
// Check inventory/gather count. checkOre = check for ore, if false, check for ignots void CheckInventoryOfBlock(IMyTerminalBlock block, bool checkOre) { MaterialStatus currentStatus = _ignotStatus; string typeId = "MyObjectBuilder_Ignot"; if (checkOre) { currentStatus = _oreStatus; typeId = "MyObjectBuilder_Ore"; } var inventory = block.GetInventory(); foreach (var item in inventory.GetItems()) { if (item.Content.TypeId.ToString() == typeId) { switch (item.Content.SubtypeId.ToString()) { case "Iron": currentStatus.SetMaterial(ItemType.Iron); currentStatus.AddAmount(ItemType.Iron, (float)item.Amount.RawValue / 1000000); break; case "Nickel": currentStatus.SetMaterial(ItemType.Nickel); currentStatus.AddAmount(ItemType.Nickel, (float)item.Amount.RawValue / 1000000); break; case "Cobalt": currentStatus.SetMaterial(ItemType.Cobalt); currentStatus.AddAmount(ItemType.Cobalt, (float)item.Amount.RawValue / 1000000); break; case "Magnesium": currentStatus.SetMaterial(ItemType.Magnesium); currentStatus.AddAmount(ItemType.Magnesium, (float)item.Amount.RawValue / 1000000); break; case "Silicon": currentStatus.SetMaterial(ItemType.Silicon); currentStatus.AddAmount(ItemType.Silicon, (float)item.Amount.RawValue / 1000000); break; case "Silver": currentStatus.SetMaterial(ItemType.Silver); currentStatus.AddAmount(ItemType.Silver, (float)item.Amount.RawValue / 1000000); break; case "Gold": currentStatus.SetMaterial(ItemType.Gold); currentStatus.AddAmount(ItemType.Gold, (float)item.Amount.RawValue / 1000000); break; case "Platinum": currentStatus.SetMaterial(ItemType.Platinum); currentStatus.AddAmount(ItemType.Platinum, (float)item.Amount.RawValue / 1000000); break; case "Uranium": currentStatus.SetMaterial(ItemType.Uranium); currentStatus.AddAmount(ItemType.Uranium, (float)item.Amount.RawValue / 1000000); break; default: break; } } } }
// ----------------------------------------------------------------------------------- bool O2TankFilterMethod(IMyTerminalBlock block) { IMyOxygenTank tank = block as IMyOxygenTank; return tank != null; }
public bool IsShieldUp(IMyTerminalBlock block) => _isShieldUp?.Invoke(block) ?? false;
private void PlayerUpdate() { var playerControlled = MyAPIGateway.Session.ControlledObject; if(playerControlled != null) { if(playerControlled.Entity is IMyCharacter) { SetCharacterReference(playerControlled.Entity); } else if(playerControlled.Entity is IMyCockpit) // in a seat, certainly not gonna climb ladders { SetCharacterReference(null); } // other cases depend on having the character controlled for a bit to get the reference else if(character != null && character.Closed) { SetCharacterReference(null); } } else { character = null; } if(character != null) { var cb = MyCubeBuilder.Static; // Dynamically enable/disable UseModelIntersection on ladder blocks that you hold to have the useful effect // of being able the block when another entity is blocking the grid space but not the blocks's physical shape. // This will still have the side effect issue if you aim at a ladder block with the same ladder block. if(cb.IsActivated && cb.CubeBuilderState != null && cb.CubeBuilderState.CurrentBlockDefinition != null && LadderLogic.ladderIds.Contains(cb.CubeBuilderState.CurrentBlockDefinition.Id.SubtypeName)) { if(prevCubeBuilderDefinition == null || prevCubeBuilderDefinition.Id != cb.CubeBuilderState.CurrentBlockDefinition.Id) { if(prevCubeBuilderDefinition != null) prevCubeBuilderDefinition.UseModelIntersection = false; prevCubeBuilderDefinition = cb.CubeBuilderState.CurrentBlockDefinition; cb.CubeBuilderState.CurrentBlockDefinition.UseModelIntersection = true; } } else if(prevCubeBuilderDefinition != null) { prevCubeBuilderDefinition.UseModelIntersection = false; prevCubeBuilderDefinition = null; } var charCtrl = character as IMyControllableEntity; bool controllingCharacter = (playerControlled != null && playerControlled.Entity is IMyCharacter); IMyTerminalBlock ladder = null; MyCubeBlock ladderInternal = null; MatrixD ladderMatrix = character.WorldMatrix; // temporarily using it for character matrix, then used for ladder matrix var charPos = ladderMatrix.Translation + ladderMatrix.Up * 0.05; var charPos2 = ladderMatrix.Translation + ladderMatrix.Up * RAY_HEIGHT; var charRay = new RayD(charPos, ladderMatrix.Up); if(dismounting <= 1) // relative top dismount sequence { if(usingLadder == null) { dismounting = 2; return; } ladder = usingLadder; ladderInternal = ladder as MyCubeBlock; dismounting *= ALIGN_MUL; if(settings.clientPrediction) { ladderMatrix = ladder.WorldMatrix; var charOnLadder = ladderMatrix.Translation + ladderMatrix.Forward * (ladderInternal.BlockDefinition.ModelOffset.Z + EXTRA_OFFSET_Z); if(ladder.CubeGrid.GridSizeEnum == MyCubeSize.Large) charOnLadder += ladderMatrix.Backward; var topDir = Vector3D.Dot(character.WorldMatrix.Up, ladderMatrix.Up); var matrix = character.WorldMatrix; var halfY = ((ladderInternal.BlockDefinition.Size.Y * ladder.CubeGrid.GridSize) / 2); matrix.Translation = charOnLadder + (topDir > 0 ? ladderMatrix.Up : ladderMatrix.Down) * (halfY + 0.1f) + ladderMatrix.Backward * 0.75; character.SetWorldMatrix(MatrixD.SlerpScale(character.WorldMatrix, matrix, MathHelper.Clamp(dismounting, 0.0f, 1.0f))); character.Physics.LinearVelocity = ladder.CubeGrid.Physics.GetVelocityAtPoint(character.WorldMatrix.Translation); // sync velocity with the ladder } SetLadderStatus("Dismounting ladder...", MyFontEnum.White); if(dismounting > 1f) ExitLadder(false); return; } // UNDONE DEBUG //{ // var c = Color.Blue.ToVector4(); // MySimpleObjectDraw.DrawLine(charPos, charPos2, "WeaponLaserIgnoreDepth", ref c, 0.5f); //} // find a ladder foreach(var l in ladders.Values) { if(l.Closed || l.MarkedForClose || !l.IsFunctional) continue; if(Vector3D.DistanceSquared(l.WorldMatrix.Translation, charPos) <= UPDATE_RADIUS) { ladderInternal = l as MyCubeBlock; ladderMatrix = l.WorldMatrix; // update ladder oriented box to find character in it accurately Quaternion.CreateFromRotationMatrix(ref ladderMatrix, out ladderBox.Orientation); if(l is MyAdvancedDoor && !(l as MyAdvancedDoor).FullyOpen) { ladderBox.HalfExtent = (ladderInternal.BlockDefinition.Size * l.CubeGrid.GridSize) / 2; var offset = ladderInternal.BlockDefinition.ModelOffset; ladderBox.Center = ladderMatrix.Translation + ladderMatrix.Up * 1.125f + ladderMatrix.Forward * (offset.Z + EXTRA_OFFSET_Z); ladderBox.HalfExtent.Y = 0.25 + 0.06; // 6mm offset to avoid some inaccuracies ladderBox.HalfExtent.Z = 0.5; if(l.CubeGrid.GridSizeEnum == MyCubeSize.Large) ladderBox.Center += ladderMatrix.Backward; } else { ladderBox.HalfExtent = (ladderInternal.BlockDefinition.Size * l.CubeGrid.GridSize) / 2; ladderBox.HalfExtent.Y += 0.06; // 6mm offset to avoid some inaccuracies ladderBox.HalfExtent.Z = 0.5; var offset = ladderInternal.BlockDefinition.ModelOffset; ladderBox.Center = ladderMatrix.Translation + ladderMatrix.Forward * (offset.Z + EXTRA_OFFSET_Z); if(l.CubeGrid.GridSizeEnum == MyCubeSize.Large) ladderBox.Center += ladderMatrix.Backward; } if(!ladderBox.Contains(ref charPos) && !ladderBox.Contains(ref charPos2)) { var intersect = ladderBox.Intersects(ref charRay); if(!intersect.HasValue || intersect.Value < 0 || intersect.Value > RAY_HEIGHT) continue; } // UNDONE DEBUG //{ // { // var c = Color.Red.ToVector4(); // MySimpleObjectDraw.DrawLine(ladderBox.Center + ladderMatrix.Down * ladderBox.HalfExtent.Y, ladderBox.Center + ladderMatrix.Up * ladderBox.HalfExtent.Y, "WeaponLaserIgnoreDepth", ref c, 0.01f); // } // // if(debugBox == null) // { // debugBox = new MyEntity(); // debugBox.Init(null, @"Models\Debug\Error.mwm", null, null, null); // debugBox.PositionComp.LocalMatrix = Matrix.Identity; // debugBox.Flags = EntityFlags.Visible | EntityFlags.NeedsDraw | EntityFlags.NeedsDrawFromParent | EntityFlags.InvalidateOnMove; // debugBox.OnAddedToScene(null); // debugBox.Render.Transparency = 0.5f; // debugBox.Render.RemoveRenderObjects(); // debugBox.Render.AddRenderObjects(); // } // var matrix = MatrixD.CreateWorld(ladderBox.Center, ladderMatrix.Forward, ladderMatrix.Up); // var scale = ladderBox.HalfExtent * 2; // MatrixD.Rescale(ref matrix, ref scale); // debugBox.PositionComp.SetWorldMatrix(matrix); //} ladder = l; ladderInternal = l as MyCubeBlock; break; } } if(ladder != null) { var offset = ladderInternal.BlockDefinition.ModelOffset; var charOnLadder = ladderMatrix.Translation + ladderMatrix.Forward * (offset.Z + EXTRA_OFFSET_Z); if(ladder.CubeGrid.GridSizeEnum == MyCubeSize.Large) charOnLadder += ladderMatrix.Backward; if(++skipRetryGravity >= GRAVITY_UPDATERATE) { skipRetryGravity = 0; alignedToGravity = true; var gravity = MyParticlesManager.CalculateGravityInPoint(character.WorldMatrix.Translation); var gravityLength = gravity.Normalize(); if(gravityLength > 0) { float gravDot = Vector3.Dot(gravity, ladderMatrix.Down); if(!(gravDot >= 0.9f || gravDot <= -0.9f)) { alignedToGravity = false; } } } //bool readInput = InputHandler.IsInputReadable(); // HACK use before GetPressedOr() once ActiveGameplayScreen's NRE is resolved if(!alignedToGravity) { bool pressed = InputHandler.GetPressedOr(settings.useLadder1, settings.useLadder2, false, false) && InputHandler.IsInputReadable(); // needs to support hold-press, so don't set JustPressed to true! if(pressed) SetLadderStatus("Gravity not parallel to ladder!", MyFontEnum.Red, 1000); if(usingLadder != null) ExitLadder(false); return; } if(usingLadder == null) // first ladder interaction { //var controlUse = MyAPIGateway.Input.GetGameControl(MyControlsSpace.USE); // //if(!controlUse.IsPressed()) //{ // string assigned = (controlUse.GetKeyboardControl() != MyKeys.None ? MyAPIGateway.Input.GetKeyName(controlUse.GetKeyboardControl()) : (controlUse.GetMouseControl() != MyMouseButtonsEnum.None ? MyAPIGateway.Input.GetName(controlUse.GetMouseControl()) : "(NONE)")) + (controlUse.GetSecondKeyboardControl() != MyKeys.None ? " or " + MyAPIGateway.Input.GetKeyName(controlUse.GetSecondKeyboardControl()) : null); // SetLadderStatus("Press "+assigned+" to use the ladder.", MyFontEnum.White); // return; //} if(grabOnLoad) { grabOnLoad = false; } else { aimingAtLadder = true; if(settings.useLadder1 == null && settings.useLadder2 == null) { SetLadderStatus("Ladder interaction is unassigned, edit the settings.cfg file!\nFor now you can use the USE key.", MyFontEnum.Red); if(!MyAPIGateway.Input.IsGameControlPressed(MyControlsSpace.USE)) return; } else { bool pressed = InputHandler.GetPressedOr(settings.useLadder1, settings.useLadder2, false, false) && InputHandler.IsInputReadable(); // needs to support hold-press, so don't set JustPressed to true! if(!pressed) { #if !STABLE // STABLE CONDITION if(!highlightedLadders.Contains(ladder.EntityId)) { if(highlightedLadders.Count > 0) { foreach(var id in highlightedLadders) { MyVisualScriptLogicProvider.SetHighlight(LADDER_NAME_PREFIX + id, false); } highlightedLadders.Clear(); } var envDef = MyDefinitionManager.Static.EnvironmentDefinition; var color = envDef.ContourHighlightColor; var thick = (int)envDef.ContourHighlightThickness; highlightedLadders.Add(ladder.EntityId); MyVisualScriptLogicProvider.SetHighlight(ladder.Name, true, thick, LADDER_HIGHLIGHT_PULSE, color); var ladderGrid = ladder.CubeGrid; for(int i = 1; i <= 10; i++) { var slim = ladderGrid.GetCubeBlock(ladderGrid.WorldToGridInteger(ladderMatrix.Translation + ladderMatrix.Up * i * ladderGrid.GridSize)); if(slim?.FatBlock?.GameLogic?.GetAs<LadderLogic>() == null) break; var id = slim.FatBlock.EntityId; highlightedLadders.Add(id); MyVisualScriptLogicProvider.SetHighlight(LADDER_NAME_PREFIX + id, true, thick, LADDER_HIGHLIGHT_PULSE, color); } for(int i = 1; i <= 10; i++) { var slim = ladderGrid.GetCubeBlock(ladderGrid.WorldToGridInteger(ladderMatrix.Translation + ladderMatrix.Down * i * ladderGrid.GridSize)); if(slim?.FatBlock?.GameLogic?.GetAs<LadderLogic>() == null) break; var id = slim.FatBlock.EntityId; highlightedLadders.Add(id); MyVisualScriptLogicProvider.SetHighlight(LADDER_NAME_PREFIX + id, true, thick, LADDER_HIGHLIGHT_PULSE, color); } } #endif SetLadderStatus("Press " + InputHandler.GetFriendlyStringOr(settings.useLadder1, settings.useLadder2) + " to use the ladder.", MyFontEnum.White); return; } } } skipRefreshAnim = 60; mounting = (controllingCharacter ? ALIGN_STEP : 2); usingLadder = ladder; SendLadderData(LadderAction.MOUNT, entId: ladder.EntityId); LadderAnim(character, LadderAnimation.MOUNTING); } if(usingLadder != ladder) { usingLadder = ladder; SendLadderData(LadderAction.CHANGE_LADDER, entId: ladder.EntityId); } if(charCtrl.Entity.Physics == null) { ExitLadder(false); return; } if(settings.clientPrediction) character.Physics.LinearVelocity = ladder.CubeGrid.Physics.GetVelocityAtPoint(character.WorldMatrix.Translation); // sync velocity with the ladder if(skipRefreshAnim > 0 && --skipRefreshAnim == 0) // force refresh animation after mounting due to an issue { var anim = lastLadderAnim; lastLadderAnim = LadderAnimation.NONE; LadderAnim(character, anim); } if(mounting <= 1) // mounting on ladder sequence { mounting *= ALIGN_MUL; if(settings.clientPrediction) { float align = Vector3.Dot(ladderMatrix.Up, character.WorldMatrix.Up); var matrix = MatrixD.CreateFromDir(ladderMatrix.Backward, (align > 0 ? ladderMatrix.Up : ladderMatrix.Down)); var halfY = ((ladderInternal.BlockDefinition.Size.Y * ladder.CubeGrid.GridSize) / 2); var diff = Vector3D.Dot(character.WorldMatrix.Translation, ladderMatrix.Up) - Vector3D.Dot(charOnLadder, ladderMatrix.Up); matrix.Translation = charOnLadder + ladderMatrix.Up * MathHelper.Clamp(diff, -halfY, halfY); character.SetWorldMatrix(MatrixD.SlerpScale(character.WorldMatrix, matrix, MathHelper.Clamp(mounting, 0.0f, 1.0f))); } if(mounting >= 0.75f && charCtrl.EnabledThrusts) // delayed turning off thrusts because gravity aligns you faster and can make you fail to attach to the ladder charCtrl.SwitchThrusts(); SetLadderStatus("Mounting ladder...", MyFontEnum.White); return; } // TODO jetpack assited climb/descend ? / gravity assisted descend ? if(charCtrl.EnabledThrusts) { if(!learned[4]) learned[4] = true; ExitLadder(false); // leave ladder if jetpack is turned on return; } // HACK use once input reading NRE is fixed //if(!controllingCharacter) // disable ladder control if not controlling character // readInput = false; bool movingSideways = false; var analogInput = MyAPIGateway.Input.GetPositionDelta(); // HACK use in-line once NRE is fixed if(!controllingCharacter) analogInput = Vector3.Zero; else if(analogInput.LengthSquared() > 0 && !InputHandler.IsInputReadable()) analogInput = Vector3.Zero; if(analogInput.Y < 0) // crouch { if(!learned[4]) learned[4] = true; ExitLadder(false); return; } float move = MathHelper.Clamp((float)Math.Round(-analogInput.Z, 1), -1, 1); // forward/backward float side = MathHelper.Clamp((float)Math.Round(analogInput.X, 1), -1, 1); // left/right //float move = readInput ? MathHelper.Clamp(MyAPIGateway.Input.GetGameControlAnalogState(MyControlsSpace.FORWARD) - MyAPIGateway.Input.GetGameControlAnalogState(MyControlsSpace.BACKWARD), -1, 1) : 0; //float side = readInput ? MathHelper.Clamp(MyAPIGateway.Input.GetGameControlAnalogState(MyControlsSpace.STRAFE_RIGHT) - MyAPIGateway.Input.GetGameControlAnalogState(MyControlsSpace.STRAFE_LEFT), -1, 1) : 0; var alignVertical = ladderMatrix.Up.Dot(character.WorldMatrix.Up); if(!loadedAllLearned) { bool allLearned = (learned[0] && learned[1] && learned[2] && learned[3] && learned[4]); for(int i = 0; i < learned.Length; i++) { if(learnNotify[i] == null) learnNotify[i] = MyAPIGateway.Utilities.CreateNotification(""); learnNotify[i].Text = (learned[i] ? LEARN_CHECK : LEARN_UNCHECK) + learnText[i]; learnNotify[i].Font = (learned[i] ? MyFontEnum.White : MyFontEnum.DarkBlue); learnNotify[i].AliveTime = (allLearned ? 1000 : 100); learnNotify[i].Show(); } if(allLearned) { SaveLearn(); loadedAllLearned = true; } } var view = MyAPIGateway.Session.ControlledObject.GetHeadMatrix(false, true); float lookVertical = Vector3.Dot(character.WorldMatrix.Up, view.Forward); if(settings.relativeControls) // climbing relative to camera { float verticalModifier = MathHelper.Clamp((lookVertical + 0.65f) / 0.5f, -0.5f, 1.0f); if(verticalModifier < 0) verticalModifier *= 2; move = (float)Math.Round(move * verticalModifier, 1); } if(analogInput.Y > 0) // jump { if(characterMovementState == MyCharacterMovementEnum.Jump) // this is still fine for avoiding jump as the character still is able to jump without needing feet on the ground { ExitLadder(false); // only release if on the floor as the character will jump regardless return; } if(settings.clientPrediction) character.Physics.LinearVelocity += view.Forward * (characterDefinition == null ? VEL_JUMP : 200 * characterDefinition.JumpForce) * TICKRATE; SendLadderData(LadderAction.JUMP_OFF, vec: view.Forward); LadderAnim(character, LadderAnimation.JUMP_OFF); if(!learned[3]) learned[3] = true; ExitLadder(false); return; } bool sprint = (characterDefinition != null && characterDefinition.Jetpack != null && MyAPIGateway.Input.IsGameControlPressed(MyControlsSpace.SPRINT)); if(Math.Abs(side) > 0.0001f) { if(settings.relativeControls) // side dismounting relative to camera { var alignForward = ladderMatrix.Backward.Dot(character.WorldMatrix.Forward); if(alignForward < 0) side = -side; } float speed = (characterDefinition == null ? (sprint ? VEL_SIDE : VEL_CLIMB) : CHAR_SPEED_MUL * (sprint ? characterDefinition.MaxSprintSpeed : characterDefinition.MaxRunStrafingSpeed)); if(settings.clientPrediction) character.Physics.LinearVelocity += side * (alignVertical > 0 ? ladderMatrix.Left : ladderMatrix.Right) * speed * TICKRATE; LadderAnim(character, (side > 0 ? LadderAnimation.DISMOUNT_LEFT : LadderAnimation.DISMOUNT_RIGHT)); movingSideways = true; if(!learned[2]) learned[2] = true; } else { // aligning player to ladder if(settings.clientPrediction) { Vector3 dir = charOnLadder - charPos; Vector3 vel = dir - (ladderMatrix.Up * Vector3D.Dot(dir, ladderMatrix.Up)); // projecting up/down direction to ignore it float len = vel.Normalize(); if(len >= ALIGN_ACCURACY) { float speed = (characterDefinition == null ? (sprint ? VEL_SIDE : VEL_CLIMB) : CHAR_SPEED_MUL * (sprint ? characterDefinition.MaxRunStrafingSpeed : characterDefinition.MaxWalkStrafingSpeed)); len = MathHelper.Clamp(len, 0.1f, 1); character.Physics.LinearVelocity += vel * len * speed * TICKRATE; } } } // TODO find a way to control view { //var ctrl2 = (Sandbox.Game.Entities.IMyControllableEntity)character; // //ctrl2.HeadLocalYAngle = 0; //ctrl2.HeadLocalXAngle = 0; // // or MoveAndRotate() ? // or... angularvelocity ? // or I dunno! } if(Math.Abs(move) > 0.0001f) { if(!learned[0]) learned[0] = true; var halfY = ((ladderInternal.BlockDefinition.Size.Y * ladder.CubeGrid.GridSize) / 2); var edge = charOnLadder + ((alignVertical > 0 ? ladderMatrix.Up : ladderMatrix.Down) * halfY); // climb over at the end when climbing up if(move > 0 && Vector3D.DistanceSquared(charPos, edge) <= 0.0625) // 0.25 squared { var nextBlockWorldPos = ladderMatrix.Translation + ladderMatrix.Forward * offset.Z + ((alignVertical > 0 ? ladderMatrix.Up : ladderMatrix.Down) * (halfY + 0.1f)); var nextBlockPos = ladder.CubeGrid.WorldToGridInteger(nextBlockWorldPos); var slim = ladder.CubeGrid.GetCubeBlock(nextBlockPos); // if the next block is not a ladder, dismount if(slim == null || !(slim.FatBlock is IMyTerminalBlock) || !LadderLogic.ladderIds.Contains(slim.FatBlock.BlockDefinition.SubtypeId)) { dismounting = ALIGN_STEP; SendLadderData(LadderAction.DISMOUNT); return; } } // on the floor and moving backwards makes you dismount if(move < 0) { var feetStart = character.WorldMatrix.Translation + character.WorldMatrix.Up * 0.2; // a bit higher because the floor might clip through the character var feetTarget = feetStart + character.WorldMatrix.Down * 0.3; IHitInfo hit; if(MyAPIGateway.Physics.CastRay(feetStart, feetTarget, out hit, COLLISSIONLAYER_NOCHARACTER)) { // need to check the block under the ladder if it's anything but a ladder because "standing" stance occurs when character rests on its chest-sphere collision mesh too var prevBlockWorldPos = ladderMatrix.Translation + ladderMatrix.Forward * offset.Z + (alignVertical > 0 ? ladderMatrix.Down : ladderMatrix.Up) * (halfY + 0.1f); var prevBlockPos = ladder.CubeGrid.WorldToGridInteger(prevBlockWorldPos); var slim = ladder.CubeGrid.GetCubeBlock(prevBlockPos); // if it's not a ladder, check the distance and confirm your feet are close to its edge if(slim == null || !(slim.FatBlock is IMyTerminalBlock) || !LadderLogic.ladderIds.Contains(slim.FatBlock.BlockDefinition.SubtypeId)) { // get the block's edge and the character feet position only along the ladder's up/down axis var blockPosProjectedUp = ladderMatrix.Up * Vector3D.Dot(prevBlockWorldPos, ladderMatrix.Up); var charPosProjectedUp = ladderMatrix.Up * Vector3D.Dot(character.WorldMatrix.Translation, ladderMatrix.Up); if(Vector3D.DistanceSquared(blockPosProjectedUp, charPosProjectedUp) <= 0.04) // 0.2 squared { ExitLadder(false); // to recap: if you're moving char-relative down and in "standing" stance and the block below is not a ladder and you're closer than 0.1m to its edge, then let go of the ladder. return; } } } } // climbing on the ladder if(!learned[1] && sprint) learned[1] = true; float speed = (characterDefinition == null ? (sprint ? VEL_SPRINT : VEL_CLIMB) : CHAR_SPEED_MUL * (sprint ? characterDefinition.MaxSprintSpeed : characterDefinition.MaxRunSpeed)); if(settings.clientPrediction) character.Physics.LinearVelocity += (alignVertical > 0 ? ladderMatrix.Up : ladderMatrix.Down) * move * speed * TICKRATE; if(!movingSideways) LadderAnim(character, (move > 0 ? LadderAnimation.UP : LadderAnimation.DOWN)); } else if(!movingSideways) { LadderAnim(character, LadderAnimation.IDLE); } SendLadderData(LadderAction.CLIMB, climb: (alignVertical > 0 ? move : -move), side: (alignVertical > 0 ? side : -side), sprint: sprint); return; } } ExitLadder(); }
public string ShieldStatus(IMyTerminalBlock block) => _shieldStatus?.Invoke(block) ?? string.Empty;
private static void SetAutopilotControl(IMyTerminalBlock block, bool value) { AutopilotTerminal autopilot; if (!Registrar.TryGetValue(block, out autopilot)) { Static.s_logger.alwaysLog("Failed lookup of block: " + block.getBestName(), Logger.severity.WARNING); return; } autopilot.m_autopilotControl.Value = value; }
public bool EntityBypass(IMyTerminalBlock block, IMyEntity entity, bool remove = false) => _entityBypass?.Invoke(block, entity, remove) ?? false;
public float GetMaxHpCap(IMyTerminalBlock block) => _getMaxHpCap?.Invoke(block) ?? -1;
public EasyBlock(IMyTerminalBlock Block) { this.Block = Block; this.slim = null; }