public override void UpdateBeforeSimulation100() { try { MyAPIGateway.Parallel.Start(() => { if (m_gasGenerator != null) { m_gasGenerator.UseConveyorSystem = false; } if (m_terminalBlock != null) { m_terminalBlock.ShowInInventory = false; } m_cosTheta = 0; m_speed = 0; m_amountAdded = 0; if (m_functionalBlock != null && m_functionalBlock.IsWorking && m_functionalBlock.IsFunctional) { m_state = RamscoopState.Idle; if (m_inventory != null && m_inventory.GetItemsCount() == 0) { DoWork(); } } else { m_state = RamscoopState.Disabled; } if (m_terminalBlock != null) { m_terminalBlock.RefreshCustomInfo(); } }); } catch (Exception e) { Debug.HandleException(e); } }
private void DoWork() { try { Vector3D velocity = Vector3D.Zero; var grid = (Container.Entity as IMyCubeBlock).CubeGrid; var entity = (Container.Entity as IMyFunctionalBlock); MyFixedPoint amount = 0; m_speed = 0; if (grid != null && entity != null && grid.Physics != null) { velocity = grid.Physics.LinearVelocity; var rotation = entity.WorldMatrix.GetDirectionVector(Base6Directions.Direction.Forward); var start = entity.GetPosition() + (entity.WorldAABB.Size.Z / 2 * rotation); var end = start + (100 * rotation); if ((Container.Entity as IMyCubeBlock).CubeGrid.RayCastBlocks(start, end).HasValue) { m_state = RamscoopState.Blocked; } else if (!Vector3D.IsZero(velocity)) { m_state = RamscoopState.Collecting; m_speed = velocity.Length(); var rotdot = Vector3D.Dot(velocity, rotation); var lens = velocity.Length() * rotation.Length(); var cos_theta = (rotdot / lens); cos_theta += 1.0f; // positive offset, facing reverse will be 0. m_cosTheta = cos_theta / 2.0d; m_amountAdded = amount = m_amount * (MyFixedPoint)m_cosTheta * (MyFixedPoint)m_speed * (MyFixedPoint)m_sizeFactor; } } if (Sync.IsServer && m_inventory.CanItemsBeAdded(amount, m_definitionId)) { var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(m_definitionId); if (content != null) { MyAPIGateway.Utilities.InvokeOnGameThread(() => { try { if (content != null) { m_inventory.AddItems(amount, content); } } catch (Exception e) { Debug.HandleException(e); } }); } } } catch (Exception e) { Debug.HandleException(e); } }