```
void Main(string arguments){
}
Program(){
Runtime.UpdateFrequency = UpdateFrequency.Update1;
}
List<IMyTerminalBlock> GetBlocksByGroup(string group_name){
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
List<IMyBlockGroup> groups = new List<IMyBlockGroup>();
GridTerminalSystem.GetBlockGroups(groups, g=>g.Name == group_name);
groups.ForEach(delegate(IMyBlockGroup g){
List<IMyTerminalBlock> blocks_temp = new List<IMyTerminalBlock>();
g.GetBlocks(blocks_temp);
foreach(IMyTerminalBlock b in blocks_temp){
blocks.Add(b);
}
});
return blocks;
}
public class Caculate
{
// 计算类
// v1.0.0
// 依赖:无
// == 静态方法
//计算水平指向向量
//用于获得一个与垂直向量垂直的,且指向参考点方向的水平向量。常用于在星球下根据重力计算出一个切向球面的水平指向目标的方向
//传入 垂直向量、自己的坐标,目标坐标
public static Vector3D HorizontalVector(Vector3D gravity, Vector3D me_pos, Vector3D target_pos){
return Vector3D.Normalize(Vector3D.Cross(gravity.Cross(Vector3D.Normalize(target_pos - me_pos)), gravity));
}
//计算星球中心坐标 power by iron&wood
//传入第一次测量点的坐标(要求坐标点位于海平面)、第一次测量的重力矢量,第二次测量点的坐标(要求坐标点位于海平面),第二次测量的重力矢量
public static Vector3D PlanetCenter(Vector3D pos_1, Vector3D g_1, Vector3D pos_2, Vector3D g_2){
g_1 = Vector3D.Normalize(g_1);
g_2 = Vector3D.Normalize(g_2);
double x = ((pos_2.X - pos_1.X)/(g_1.X - g_2.X))*g_1.X + pos_1.X;
double y = ((pos_2.Y - pos_1.Y)/(g_1.Y - g_2.Y))*g_1.Y + pos_1.Y;
double z = ((pos_2.Z - pos_1.Z)/(g_1.Z - g_2.Z))*g_1.Z + pos_1.Z;
return new Vector3D(x, y, z);
}
//或传入 第一次测量点坐标(不要求海平面),第一次测量的重力矢量,第一次测量的水平海拔高度,第二次测量点的坐标(不要求海平面),第二次测量的重力矢量,第二次测量的水平海拔高度
public static Vector3D PlanetCenter(Vector3D pos_1, Vector3D g_1, double h_1, Vector3D pos_2, Vector3D g_2, double h_2){
g_1 = Vector3D.Normalize(g_1);
g_2 = Vector3D.Normalize(g_2);
pos_1 = pos_1 + (g_1 * h_1);
pos_2 = pos_2 + (g_2 * h_2);
return Caculate.PlanetCenter(pos_1, g_2, pos_2, g_2);
}
//计算星球上与某坐标的球面距(弧长)
//传入自己坐标,球心坐标,目标坐标,自己的海拔(可选传入,若传入则计算紧贴球表面的距离)
public static double PlanetDistance(Vector3D mepos, Vector3D center, Vector3D targetpos, double height = 0){
Vector3D v1 = mepos - center;
Vector3D v2 = targetpos - center;
double rad = Math.Acos((v1.X*v2.X + v1.Y*v2.Y + v1.Z*v2.Z)/(v1.Length() * v2.Length())); //夹角,是一个弧度
double half = Vector3D.Distance(mepos, center) - height; //半径
return rad*half;
}
//计算A向量在B向量方向上的投影长度
public static double VectorProjection(Vector3D a, Vector3D b){
return a.Dot(b)/b.Length();
}
//计算两个矢量的夹角
public static double AngleBetweenVector(Vector3D a, Vector3D b){
//计算投影
return Math.Acos(a.Dot(b)/(b.Length()*a.Length()))*180/Math.PI;
}
//计算目标坐标点相对自己的角度
//传入目标相当于自己坐标系的坐标,传入一个方向: Yaw、Pitch
//当传入Yaw返回目标相对自己左右的角度(左-右+),传入Pitch返回目标相对自己上下的角度(上-下+)
public static double TargetAngleToMe(Vector3D target_to_me, string direction){
target_to_me = Vector3D.Normalize(target_to_me);
Vector3D meForward = new Vector3D(0,0,-1);
if(direction == "Yaw"){
//把目标投影到xz平面
Vector3D targetYawVector = new Vector3D(target_to_me.X, 0, target_to_me.Z);
double pn = target_to_me.X >= 0 ? 1 : -1;
return Math.Acos(targetYawVector.Dot(meForward)/(targetYawVector.Length() * meForward.Length()))*180/Math.PI * pn;
}else if(direction == "Pitch"){
//把目标投影到yz平面
Vector3D targetPitchVector = new Vector3D(0, target_to_me.Y, target_to_me.Z);
double pn = target_to_me.Y <= 0 ? 1 : -1;
return Math.Acos(targetPitchVector.Dot(meForward)/(targetPitchVector.Length() * meForward.Length()))*180/Math.PI * pn;
}
return 0;
}
}
public class Block
{
// == 构造方法
public Block(IMyTerminalBlock b){
this._block = b;
}
// == 成员属性
public IMyTerminalBlock _block; //方块
public long Id{ //唯一ID
get { return this._block.EntityId; }
}
public bool IsOK{ //是否正确获取到方块
get { return this._block != null; }
}
public bool OnOff{
get { return this._block is IMyFunctionalBlock ? (this._block as IMyFunctionalBlock).Enabled : false; }
set { if(this._block is IMyFunctionalBlock){ (this._block as IMyFunctionalBlock).Enabled = value; } }
}
public bool IsBeingHacked{ //是否被黑了
get { return this._block.IsBeingHacked; }
}
public bool IsFunctional{ //是否可以工作
get { return this._block.IsFunctional; }
}
public bool IsWorking{ //是否在工作
get { return this._block.IsWorking; }
}
public int NumberInGrid{ //在网格中的顺序
get { return this._block.NumberInGrid; }
}
public IMyCubeGrid Grid{ //所属网格
get { return this._block.CubeGrid; }
}
public string Name{ //自定义名称(CustomName)
get { return this._block.CustomName; }
set { this._block.CustomName = value; }
}
public string Data{ //自定义数据 (CustomData)
get { return this._block.CustomData; }
set { this._block.CustomData = value; }
}
public long OwnerId{ //所有人ID
get { return this._block.OwnerId; }
}
public Vector3D Position{ //坐标(基于世界绝对坐标系的坐标)
get { return this._block.GetPosition(); }
}
public Matrix WorldMatrix{ //矩阵(描述方块世界坐标几方位的矩阵)
get { return this._block.WorldMatrix; }
}
public Vector3D Forward{ //前向矢量(归一化的,即矢量的长度恒等于1)
get { return this._block.WorldMatrix.Forward; }
}
public Vector3D Backward{ //后向矢量(归一化的,即矢量的长度恒等于1)
get { return this._block.WorldMatrix.Backward; }
}
public Vector3D Left{ //左向矢量(归一化的,即矢量的长度恒等于1)
get { return this._block.WorldMatrix.Left; }
}
public Vector3D Right{ //右向矢量(归一化的,即矢量的长度恒等于1)
get { return this._block.WorldMatrix.Right; }
}
public Vector3D Up{ //上向矢量(归一化的,即矢量的长度恒等于1)
get { return this._block.WorldMatrix.Up; }
}
public Vector3D Down{ //下向矢量(归一化的,即矢量的长度恒等于1)
get { return this._block.WorldMatrix.Down; }
}
public bool ShowInTerminal{ //是否在终端显示
get { return this._block.ShowInTerminal; }
set { this._block.ShowInTerminal = value; }
}
public bool ShowInInventory{ //是否在库存中显示
get { return this._block.ShowInInventory; }
set { this._block.ShowInInventory = value; }
}
}
public class Cockpit: Block
{
// v1.0.0
// 依赖:Block类
// == 构造方法
public Cockpit(IMyTerminalBlock b):base(b){
this._block = b;
this._cockpit = b as IMyShipController;
}
public Cockpit(IMyShipController b):base(b){
this._block = b;
this._cockpit = b as IMyShipController;
}
// == 成员属性
public IMyShipController _cockpit; //主控块
public bool CanControlShip{ //是否可以控制飞船
get { return this._cockpit.CanControlShip; }
}
public bool IsUnderControl{ //是否正在被玩家控制
get { return this._cockpit.IsUnderControl; }
}
public bool HasWheels{ //是否有轮子
get { return this._cockpit.HasWheels; }
}
public bool ControlWheels{ //是否勾选了可以控制轮子
get { return this._cockpit.ControlWheels; }
set { this._cockpit.ControlWheels = value; }
}
public bool ControlThrusters{ //是否勾选了可以控制推进器
get { return this._cockpit.ControlThrusters; }
set { this._cockpit.ControlThrusters = value; }
}
public bool HandBrake{ //是否勾选了手刹
get { return this._cockpit.HandBrake; }
set { this._cockpit.HandBrake = value; }
}
public bool DampenersOverride{ //是否勾选了惯性抑制
get { return this._cockpit.DampenersOverride; }
set { this._cockpit.DampenersOverride = value; }
}
public bool IsMainCockpit{ //是否是主控
get { return this._cockpit.IsMainCockpit; }
set { this._cockpit.IsMainCockpit = value; }
}
public bool ShowHorizonIndicator{ //是否勾选了显示地平线高度
get { return this._cockpit.ShowHorizonIndicator; }
set { this._cockpit.ShowHorizonIndicator = value; }
}
public Vector3D InputKey{ //按键输入,X表示AD,Y表示空格和C,Z表示SW
get {
Vector3D temp = new Vector3D();
Vector3D.TryParse(this._cockpit.MoveIndicator.ToString(), out temp);
return temp;
}
}
public double InputRoll{ //QE按键输入
get { return (double)this._cockpit.RollIndicator; }
}
public Vector2D InputMouse{ //鼠标输入,X表示左右,Y表示上下
get {
return new Vector2D((double)this._cockpit.RotationIndicator.X, (double)this._cockpit.RotationIndicator.Y);
}
}
public Vector3D CenterOfMass{ //质心(不考虑活塞转子等外挂部分)
get { return this._cockpit.CenterOfMass; }
}
public double BaseMass{ //飞船基础质量
get { return this._cockpit.CalculateShipMass().BaseMass; }
}
public double TotalMass{ //飞船总体质量
get { return this._cockpit.CalculateShipMass().TotalMass; }
}
public double PhysicalMass{ //飞船物理质量
get { return this._cockpit.CalculateShipMass().PhysicalMass; }
}
public Vector3D ArtificialGravity{ //人工重力
get { return this._cockpit.GetArtificialGravity(); }
}
public Vector3D NaturalGravity{ //自然重力
get { return this._cockpit.GetNaturalGravity(); }
}
public Vector3D Velocity{ //飞船线速度矢量
get { return this._cockpit.GetShipVelocities().LinearVelocity; }
}
public Vector3D AngleVelocity{ //飞船角速度矢量
get { return this._cockpit.GetShipVelocities().AngularVelocity; }
}
public MatrixD WorldMatrix{ //世界矩阵
get { return this._cockpit.WorldMatrix; }
}
public double YawVelocity{ //飞船偏航Yaw速度(基于自己的坐标系,单位角度)
get {
MatrixD refLookAtMatrix = MatrixD.CreateLookAt(new Vector3D(), this.WorldMatrix.Forward, this.WorldMatrix.Up);
//求出自己当前角速度相对自己的值,这是一套弧度值,其中最大值是0.45,最小值是0.0005,x表示俯仰Pitch(上+下-),y表示偏航Yaw(左+右-),z表示滚转(顺时针-逆时针+)
Vector3D MeAngleVelocityToMe = Vector3D.TransformNormal(this.AngleVelocity, refLookAtMatrix);
return MeAngleVelocityToMe.Y*180/Math.PI;
}
}
public double PitchVelocity{ //飞船俯仰Pitch速度(基于自己的坐标系,单位角度)
get {
MatrixD refLookAtMatrix = MatrixD.CreateLookAt(new Vector3D(), this.WorldMatrix.Forward, this.WorldMatrix.Up);
//求出自己当前角速度相对自己的值,这是一套弧度值,其中最大值是0.45,最小值是0.0005,x表示俯仰Pitch(上+下-),y表示偏航Yaw(左+右-),z表示滚转(顺时针-逆时针+)
Vector3D MeAngleVelocityToMe = Vector3D.TransformNormal(this.AngleVelocity, refLookAtMatrix);
return MeAngleVelocityToMe.X*180/Math.PI;
}
}
public double RollVelocity{ //飞船滚转Roll速度(基于自己的坐标系,单位角度)
get {
MatrixD refLookAtMatrix = MatrixD.CreateLookAt(new Vector3D(), this.WorldMatrix.Forward, this.WorldMatrix.Up);
//求出自己当前角速度相对自己的值,这是一套弧度值,其中最大值是0.45,最小值是0.0005,x表示俯仰Pitch(上+下-),y表示偏航Yaw(左+右-),z表示滚转(顺时针-逆时针+)
Vector3D MeAngleVelocityToMe = Vector3D.TransformNormal(this.AngleVelocity, refLookAtMatrix);
return MeAngleVelocityToMe.Z*180/Math.PI;
}
}
public bool IsInPlanet{ //是否在星球上
get {
Vector3D temp = new Vector3D();
return this._cockpit.TryGetPlanetPosition(out temp);
}
}
public Vector3D PlanetPosition{ //所处的星球坐标(处于星球状态中才能获取)
get {
Vector3D temp = new Vector3D();
this._cockpit.TryGetPlanetPosition(out temp);
return temp;
}
}
public double PlanetElevationSealevel{ //所处的星球海平面高度(处于星球状态中才能获取)
get{
double e = 0;
this._cockpit.TryGetPlanetElevation(MyPlanetElevation.Sealevel, out e);
return e;
}
}
public double PlanetElevationSurface{ //所处的星球地表高度(处于星球状态中才能获取)
get{
double e = 0;
this._cockpit.TryGetPlanetElevation(MyPlanetElevation.Surface, out e);
return e;
}
}
}
public class LCD: Block
{
// v1.0.0
// 依赖:Block类
// == 构造方法
public LCD(IMyTerminalBlock b):base(b){
this._block = b;
this._lcd = b as IMyTextPanel;
}
public LCD(IMyTextPanel b):base(b){
this._block = b;
this._lcd = b as IMyTextPanel;
}
// == 成员属性
public IMyTextPanel _lcd; //lcd方块
public string Title{
get { return this._lcd.GetPublicTitle(); }
set { this._lcd.WritePublicTitle(value); }
}
public string Text{
get { return this._lcd.GetPublicText(); }
set { this._lcd.WritePublicText(value); }
}
public bool ShowText{
get { return this._lcd.GetValueBool("ShowTextOnScreen"); }
set { this._lcd.SetValue("ShowTextOnScreen", value); }
}
public double FontSize{
get { return this._lcd.GetValueFloat("FontSize"); }
set { this._lcd.SetValueFloat("FontSize", (float)value); }
}
// == 成员方法
public void AppendText(string str){
this._lcd.WritePublicText(str, true);
}
}
public class LCD_Figure
{
// LCD 画布类
// v1.0
// 依赖:LCD、Figure
// 说明:当需要使用LCD方块绘图时,只需引入本类。考虑到LCD大多数时候不用于绘图,所以LCD类不依赖本类,而是反过来。
// 这样的好处是不需要绘图时也可以单独使用LCD类,坏处是需要渲染的时候,需要把LCD传进来。
public int BG_R; //背景色R值
public int BG_G; //背景色G值
public int BG_B; //背景色B值
public int Width; //画布宽度
public int Height; //画布高度
// == 构造方法
public LCD_Figure(int width = 177, int height = 177, Color bg = new Color()){
this.Width = width;
this.Height = height;
this.BG_R = bg.R;
this.BG_B = bg.B;
this.BG_G = bg.G;
}
// 重设背景色
public void SetBackground(int r, int g, int b){
this.BG_R = r;
this.BG_G = g;
this.BG_B = b;
}
// 渲染图像
public void Render(LCD lcd, List<Figure> figures){
lcd.ShowText = true;
lcd._lcd.SetValue("Font", 1147350002L);
lcd.FontSize = 0.1;
lcd.Text = this.GetStringFromPixs(figures);
}
public void Render(List<LCD> lcds, List<Figure> figures){
string info = this.GetStringFromPixs(figures);
foreach(LCD lcd in lcds){
lcd.ShowText = true;
lcd._lcd.SetValue("Font", 1147350002L);
lcd.FontSize = 0.1;
lcd.Text = info;
}
}
// 内部方法
public string GetStringFromPixs(List<Figure> figures){
char[][] pixs = new char[this.Height][];
for(int i = 0; i < pixs.Length; i ++){
pixs[i] = new string(LCD_Figure.GetColorFromRGB(this.BG_R, BG_G, BG_B), this.Width).ToCharArray();
}
foreach(Figure f in figures){
char color_char = LCD_Figure.GetColorFromRGB(f.R, f.G, f.B);
foreach(Vector2I xy in f.Pixs){
int x = xy.X + f.Dev_X;
int y = xy.Y + f.Dev_Y;
if(x > 0 && x <= this.Width - 1 && y > 0 && y <= this.Height - 1){
pixs[y][x] = color_char;
}
}
}
string info = "";
for(int y = 0; y < pixs.Count(); y ++){
info += new string(pixs[y]) + "\n";
}
return info;
}
public static char GetColorFromRGB(double R, double G, double B) //Large RGB Convertor(0 - 225)
{
R /= 32;
G /= 32;
B /= 32;
byte CR = (byte)(R > 255 ? 255 : (R < 0 ? 0 : R));
byte CG = (byte)(G > 255 ? 255 : (G < 0 ? 0 : G));
byte CB = (byte)(B > 255 ? 255 : (B < 0 ? 0 : B));
return (char)(0xE100 + (CR << 6) + (CG << 3) + CB);
}
}
public class Figure
{
// 图层类
// v1.0
// 依赖:无
public List<Vector2I> Pixs; //储存图层所有像素点集合的点集合
public int Dev_X; //x偏移
public int Dev_Y; //y偏移
public int R; //图层颜色R值
public int G; //图层颜色G值
public int B; //图层颜色B值
public Figure(){
this.Pixs = new List<Vector2I>();
}
public Figure(List<Vector2I> pixs){
this.Pixs = pixs;
}
public void SetColor(int r, int g, int b){
this.R = r;
this.G = g;
this.B = b;
}
public void SetDev(int x, int y){
this.Dev_X = x;
this.Dev_Y = y;
}
public Figure Add(List<Vector2I> pixs){
this.Pixs.AddList(pixs);
return this;
}
// == 静态方法 ==
// --------- 直线函数 ------------
// 起始点座标,终点座标
public static List<Vector2I> CreateLine(Vector2I StartPoint, Vector2I EndPoint){
List<Vector2I> returnPoint = new List<Vector2I>();
int X_dis = Math.Abs(StartPoint.X-EndPoint.X);
int Y_dis = Math.Abs(StartPoint.Y-EndPoint.Y);
if(X_dis == 0 && Y_dis == 0)
{
returnPoint.Add(new Vector2I(StartPoint.X,StartPoint.Y));
return returnPoint;
}
else if(X_dis == 0)//竖线
{
for(int i = (StartPoint.Y < EndPoint.Y ? StartPoint.Y : EndPoint.Y); i <= (StartPoint.Y > EndPoint.Y ? StartPoint.Y : EndPoint.Y); i ++)
{
returnPoint.Add(new Vector2I(StartPoint.X,i));
}
}
else if(Y_dis == 0)//横线
{
for(int i = (StartPoint.X < EndPoint.X ? StartPoint.X : EndPoint.X); i <= (StartPoint.X > EndPoint.X ? StartPoint.X : EndPoint.X); i ++)
{
returnPoint.Add(new Vector2I(i,StartPoint.Y));
}
}
else
{
double k = (double)(EndPoint.Y - StartPoint.Y)/(double)(EndPoint.X - StartPoint.X);
double b = (double)(EndPoint.X*StartPoint.Y - StartPoint.X*EndPoint.Y)/(double)(EndPoint.X - StartPoint.X);
if(X_dis > Y_dis)
{
for(int i = (StartPoint.X < EndPoint.X ? StartPoint.X : EndPoint.X); i <= (StartPoint.X > EndPoint.X ? StartPoint.X : EndPoint.X); i ++)
{
double y = k*i + b;
returnPoint.Add(new Vector2I(i,(int)Math.Round(y,0)));
}
}
else
{
for(int i = (StartPoint.Y < EndPoint.Y ? StartPoint.Y : EndPoint.Y); i <= (StartPoint.Y > EndPoint.Y ? StartPoint.Y : EndPoint.Y); i ++)
{
double x = (i - b)/k;
returnPoint.Add(new Vector2I((int)Math.Round(x,0),i));
}
}
}
return returnPoint;
}
// --------- 矩形函数 ------------
// 函数重载,有两种用法:
// 1、传入:左上角座标、宽、高 得到一个实心矩形
// 2、传入:左上角座标、宽、高、边框宽度 得到一个空心矩形
// 【注意】面积不宜太大
public static List<Vector2I> CreateRectangle(Vector2I Point, int Width, int Height){
List<Vector2I> returnPoint = new List<Vector2I>();
for(int x = Point.X; x < Point.X + Width; x++)
{
for(int y = Point.Y; y < Point.Y + Height; y ++)
{
returnPoint.Add(new Vector2I(x, y));//生成整个实心矩形
}
}
return returnPoint;
}
public static List<Vector2I> CreateRectangle(Vector2I Point, int Width, int Height, int Thickness){
List<Vector2I> returnPoint = CreateRectangle(Point, Width, Height);
//生成矩形2个对角点
Vector2I a_point = Point; //左上
Vector2I d_point = new Vector2I(Point.X+Width, Point.Y+Height); //右下
List<Vector2I> rightPoint = new List<Vector2I>();
for(int i = 0; i < returnPoint.Count; i ++)
{
if(returnPoint[i].X < a_point.X + Thickness || returnPoint[i].X >= d_point.X - Thickness)
{
rightPoint.Add(returnPoint[i]);
}
if(returnPoint[i].Y < a_point.Y + Thickness || returnPoint[i].Y >= d_point.Y - Thickness)
{
rightPoint.Add(returnPoint[i]);
}
}
return rightPoint;
}
// ---- 创造三角形
// 传入:
// 1、顶点坐标,宽度,高度 得到实心三角形
// 2、顶点坐标,宽度,高度,边框宽度,是否需要底边 得到一个空心三角形(或箭头)
public static List<Vector2I> CreateTriangle(Vector2I Point, int Width, int Height)
{
List<Vector2I> returnPoint = new List<Vector2I>();
for(int h = 0; h < Height; h++)
{
for(int l = 0; l < 0.5*h*Width/Height; l ++)
{
returnPoint.Add(new Vector2I(Point.X+l, Point.Y+h));
returnPoint.Add(new Vector2I(Point.X-l, Point.Y+h));
}
}
return returnPoint;
}
public static List<Vector2I> CreateTriangle(Vector2I Point, int Width, int Height, int Thickness, bool NeedBase)
{
List<Vector2I> returnPoint = new List<Vector2I>();
for(int h = 0; h < Height; h++)
{
for(int i = 0; i < Thickness; i ++)
{
returnPoint.Add(new Vector2I(Point.X+(int)Math.Round(0.5*h*Width/Height, 0)-i, Point.Y+h));
returnPoint.Add(new Vector2I(Point.X-(int)Math.Round(0.5*h*Width/Height, 0)+i, Point.Y+h));
if(NeedBase)
{
for(int x = 0; x < Width; x ++)
{
returnPoint.Add(new Vector2I(Point.X - (int)Math.Round(0.5*Width, 0) + x, Point.Y+Height-i));
}
}
}
}
return returnPoint;
}
// -------- string字符串转像素字符 ---------
public static List<Vector2I> CreateText(string Input_Text, int X1 = 0, int Y1 = 0) //这是一个很不耐烦的函数,碰到\n就会退出
{
int XShift = X1;
int YShift = Y1;
List<Vector2I> L_DotList = new List<Vector2I>();
for (int iText = 0; (iText < Input_Text.Length); iText++)
{
char CharStep = Input_Text[iText];
switch (CharStep)
{
case ' ':
XShift += 4;
break;
case '\n':
XShift = 0;
YShift += 6;
continue; //遇到\n直接退出
default:
short CharBitmap = Figure.T_GetBitmap(CharStep);
int i = 14;
do
{
if ((CharBitmap & 1) == 1)
{
L_DotList.Add(new Vector2I(XShift + i % 3, YShift - 4 + i / 3));
}
CharBitmap >>= 1;
i--;
}
while (CharBitmap > 0);
XShift += 4;
//Thanks to Blargmode, he taught me how to use it
break;
}
}
return L_DotList;
}
public static short T_GetBitmap(char Input_Char) //非静态
{
if (Input_Char > 127)
{
return CError[1]; //缺少错误提示&错误处理
}
return CChar[Input_Char - iCharOffset];
}
public const short iCharOffset = 0x21;
public static short[] CChar = //k社使我被迫删了const
{9346,23040,24445,15602,17057,10923,9216,5265,17556,21824,1488,20,448,2,672,31599,11415,25255,29326,23497,31118,10666,29330,10922,10954,1040,1044,5393,3640,17492,25218,15203,11245,27566,14627,27502,31143,31140,14827,23533,29847,12906,23469,18727,24557,27501,11114,27556,11131,27565,14478,29842,23403,23378,23549,23213,23186,29351,13459,2184,25750,10752,7,17408,239,18862,227,4843,1395,14756,1886,18861,8595,4302,18805,25745,509,429,170,1396,1369,228,1934,18851,363,362,383,341,2766,3671,5521,9234,17620,1920};
public static short[] CError = //k社使我被迫删了const
{
4095, //0全色填充
2047, //1非ASCII识别错误(1号NoBitmap错误)
3071, //2
3583, //3
3839, //4
3967, //5
4031, //6
4063, //7
4079, //8
4087, //9
4091, //10
4093, //11
4094 //12
};
}
public class Rotor: Block
{
// v1.0.0
// 依赖:Block类
// == 构造方法
public Rotor(IMyTerminalBlock b):base(b){
this._block = b;
this._rotor = b as IMyMotorStator;
}
public Rotor(IMyMotorStator b):base(b){
this._block = b;
this._rotor = b as IMyMotorStator;
}
// == 静态方法
// 角度转换
public static double AngleToRad(double angle){
return angle*Math.PI/180;
}
public static double RadToAngle(double rad){
return rad*180/Math.PI;
}
public static double NormalizeAngle(double angle){
if(angle > 360){
return angle%360;
}else if(angle < 0){
return 360 + (angle%360);
}else{
return angle;
}
}
// == 成员属性
public IMyMotorStator _rotor; //转子方块
public bool Lock{
get { return this._rotor.RotorLock; }
set { this._rotor.RotorLock = value; }
}
public double Angle{ //当前角度
get { return Rotor.RadToAngle(this._rotor.Angle); }
}
public double MaxAngle{ //最大角度
get { return Rotor.RadToAngle(this._rotor.UpperLimitRad); }
set { this._rotor.UpperLimitRad = (float)Rotor.AngleToRad(value); }
}
public double MinAngle{ //最小角度
get { return Rotor.RadToAngle(this._rotor.LowerLimitRad); }
set { this._rotor.LowerLimitRad = (float)Rotor.AngleToRad(value); }
}
public double AngleRad{ //当前弧度
get { return this._rotor.Angle; }
}
public double MaxRad{ //最大角(弧度)
get { return this._rotor.UpperLimitRad; }
set { this._rotor.UpperLimitRad = (float)value; }
}
public double MinRad{ //最小角(弧度)
get { return this._rotor.LowerLimitRad; }
set { this._rotor.LowerLimitRad = (float)value; }
}
public double Velocity{ //速度
get { return this._rotor.TargetVelocityRPM; }
set { this._rotor.TargetVelocityRPM = (float)value; }
}
public double VelocityRad{
get { return this._rotor.TargetVelocityRad; }
set { this._rotor.TargetVelocityRad = (float)value; }
}
public double VelocityAngle{
get { return Rotor.RadToAngle(this._rotor.TargetVelocityRad); }
set { this._rotor.TargetVelocityRad = (float)Rotor.AngleToRad(value); }
}
// == 成员方法
// 转到某个角度
// input angle 目标角度,使用角度而不是弧度
// input mode 运动方式,1顺时针,-1逆时针,0自动
// input velocity 指定速度,不指定默认用PID
public double TurnToAngleAccuracy = 0.2; //转动抵达判定角度
public double TurnToVelocityAccuracy = 0.01; //转动抵达判定速度
public double turn_pid_p = 20; //比例系数
public double turn_pid_i = 20; //积分系数(增加后降低动态误差,增加震荡)
public double turn_pid_d = 30; //微分系数(增加后降低震荡)
public double turn_pid_t = 30; //误差累加控制周期
private List<double> turn_pid_diff_data = new List<double>();
public bool TurnTo(double angle = 0, int mode = 0, double velocity = 0){
angle = Rotor.NormalizeAngle(angle);
if(mode == 0){
if(angle > this.Angle){
mode = angle - this.Angle > 180 ? -1 : 1;
}else{
mode = this.Angle - angle > 180 ? 1 : -1;
}
}
//指定速度方式
if(velocity != 0){
this.Velocity = mode * velocity;
return Math.Abs(angle - this.Angle) <= 0.5;
}
// diff是当前角度和目标角度的转动角度差,范围是0-1
double diff = 0;
if(mode == 1){
if(angle > this.Angle){
diff = angle - this.Angle;
}else{
diff = (360 - this.Angle) + angle;
}
}else if(mode == -1){
if(this.Angle > angle){
diff = this.Angle - angle;
}else{
diff = this.Angle + (360 - angle);
}
}
diff /= 360;
//对角度差进行逐帧累加,累加次数为 PID控制积分系数
double diff_i = 0; //积分求和项
if(this.turn_pid_diff_data.Count >= this.turn_pid_t){
this.turn_pid_diff_data.Remove(this.turn_pid_diff_data[0]);
}
this.turn_pid_diff_data.Add(diff);
foreach(double d in this.turn_pid_diff_data){
diff_i += d;
}
//输出结果是
this.Velocity = mode*this.turn_pid_p*(diff + diff_i*this.turn_pid_i/turn_pid_t + (diff - this.turn_pid_diff_data[this.turn_pid_diff_data.Count-1])*this.turn_pid_d);
return diff*360 <= this.TurnToAngleAccuracy && Math.Abs(this.Velocity) <= this.TurnToVelocityAccuracy;
}
}
public class Wheel: Block
{
// v1.0.0
// 依赖:Block类
// == 构造方法
public Wheel(IMyTerminalBlock b):base(b){
this._block = b;
this._wheel = b as IMyMotorSuspension;
}
public Wheel(IMyMotorSuspension b):base(b){
this._block = b;
this._wheel = b as IMyMotorSuspension;
}
// == 成员属性
public IMyMotorSuspension _wheel;
public bool SteeringOnOff{ //是否允许转向
get { return this._wheel.Steering; }
set { this._wheel.Steering = value; }
}
public bool PropulsionOnOff{ //是否允许加速
get { return this._wheel.Propulsion; }
set { this._wheel.Propulsion = value; }
}
public bool InvertSteerOnOff{ //是否反向转向
get { return this._wheel.InvertSteer; }
set { this._wheel.InvertSteer = value; }
}
public bool InvertPropulsionOnOff{ //是否反向加速
get { return this._wheel.InvertPropulsion; }
set { this._wheel.InvertPropulsion = value; }
}
public double Power{ //功率
get { return this._wheel.Power; }
set { this._wheel.Power = (float)value; }
}
public double Strength{ //强度
get { return this._wheel.Strength; }
set { this._wheel.Strength = (float)value; }
}
public double Friction{ //摩擦力
get { return this._wheel.Friction; }
set { this._wheel.Friction = (float)value; }
}
public double SpeedLimit{ //速度限制,0~360,其中360为无限制
get { return this._wheel.GetValueFloat("Speed Limit"); }
set { this._wheel.SetValueFloat("Speed Limit", (float)value); }
}
public double Speed{ //加速越级值
get { return this._wheel.GetValueFloat("Propulsion override"); }
set { this._wheel.SetValueFloat("Propulsion override", (float)value); }
}
public double Steer{ //转向越级值
get { return this._wheel.GetValueFloat("Steer override"); }
set { this._wheel.SetValueFloat("Steer override", (float)value); }
}
public double Height{ //悬架高度
get { return this._wheel.Height; }
set { this._wheel.Height = (float)value; }
}
}
public class Weapon: Block
{
// v1.0.0
// 依赖:Block类
// == 构造方法
public Weapon(IMyTerminalBlock b):base(b){
this._block = b;
this._weapon = b as IMyUserControllableGun;
}
public Weapon(IMyUserControllableGun b):base(b){
this._block = b;
this._weapon = b as IMyUserControllableGun;
}
// == 成员属性
public IMyUserControllableGun _weapon;
public bool IsShooting{ //是否在射击
get { return this._weapon.IsShooting; }
}
// ==== 成员方法
public void Shoot(){
this._weapon.ApplyAction("ShootOnce");
}
}
public class Camera: Block
{
// v1.0.0
// 依赖:Block类
// == 构造方法
public Camera(IMyTerminalBlock b):base(b){
this._block = b;
this._camera = b as IMyCameraBlock;
}
public Camera(IMyCameraBlock b):base(b){
this._block = b;
this._camera = b as IMyCameraBlock;
}
// == 成员属性
public IMyCameraBlock _camera;
public bool IsActive{ //是否可用
get { return this._camera.IsActive; }
}
public bool EnableRaycast{ //是否开启允许扫描
get { return this._camera.EnableRaycast; }
set { this._camera.EnableRaycast = value; }
}
public double CanScanRange{ //可扫描距离,储能
get { return this._camera.AvailableScanRange; }
}
// == 成员方法
public bool CanScan(double distance){
return this._camera.CanScan(distance);
}
public bool CanScan(Vector3D point){
return this._camera.CanScan(point);
}
public bool CanScan(double distance, Vector3D direction){
return this._camera.CanScan(distance, direction);
}
public Camera.Target Scan(Vector3D targetPos, int timestemp = 0){
return new Camera.Target(this._camera.Raycast(targetPos), timestemp);
}
public Camera.Target Scan(double distance, Vector3D targetDirection, int timestemp = 0){
return new Camera.Target(this._camera.Raycast(distance, targetDirection), timestemp);
}
public Camera.Target Scan(double distance, double pitch = 0, double yaw = 0, int timestemp = 0){
return new Camera.Target(this._camera.Raycast(distance, (float)pitch, (float)yaw), timestemp);
}
// == 成员类
public class Target
{
// == 构造方法
public Target(){}
public Target(MyDetectedEntityInfo entity, int create_time = 0){
this._target = entity;
this.CreateTime = create_time;
this.UpdateTime = create_time;
}
// == 成员属性
public MyDetectedEntityInfo _target;
public int CreateTime; //创建时间
public int UpdateTime; //更新时间
public bool IsEmpty{ //是否是空目标
get {
return this._target.EntityId == 0L;
}
}
public long Id { //实体ID
get { return this._target.EntityId; }
}
public string Name{ //名字
get { return this._target.Name; }
}
public Vector3D HitPosition{ //探测射线或探测场与实体的碰撞坐标
get {
Vector3D temp = new Vector3D();
Vector3D.TryParse(this._target.HitPosition.ToString(), out temp);
return temp;
}
}
public Vector3D Position{ //质心的空间坐标
get { return this._target.BoundingBox.Center; }
}
public Vector3D Velocity{ //速度矢量
get {
Vector3D temp = new Vector3D();
Vector3D.TryParse(this._target.Velocity.ToString(), out temp);
return temp;
}
}
public BoundingBoxD Box{ //空间体容器
get { return this._target.BoundingBox; }
}
public MyRelationsBetweenPlayerAndBlock Relationship{ //阵营关系
get { return this._target.Relationship; }
}
// == 成员方法
// 更新目标状态和时间戳
public bool Update(MyDetectedEntityInfo entity, int update_time = 0){
if(entity.EntityId == this.Id){
this._target = entity;
this.UpdateTime = update_time;
}
return false;
}
public bool Update(Camera.Target target, int update_time = 0){
return this.Update(target._target, update_time);
}
}
}
public class Cameras
{
// v1.0.0
// 依赖: Camera -> Block
// == 构造方法
// 传入一个主控块
public Cameras(Cockpit cockpit, List<Camera> cams){
this._cockpit = cockpit;
this._cameras = new List<Camera>();
foreach(Camera cm in cams){
if(cm.IsOK){
this._cameras.Add(cm);
}
}
}
public Cameras(Cockpit cockpit, List<IMyTerminalBlock> cams){
this._cockpit = cockpit;
this._cameras = new List<Camera>();
foreach(IMyTerminalBlock b in cams){
if(b is IMyCameraBlock){
this._cameras.Add(new Camera(b));
}
}
}
// == 成员属性
public Cockpit _cockpit; //主体方块
public List<Camera> _cameras; //主体
public int Count{
get { return this._cameras.Count; }
}
// == 成员方法
//开关可扫描
public void EnableScan(bool onoff){
foreach(Camera c in this._cameras){
c.EnableRaycast = onoff;
}
}
//扫描某个目标点
public int Scan_T;
public int Scan_Now_I;
public Camera.Target Scan(Vector3D position, int timestemp = 0){
this.Scan_T ++;
List<Camera> canScanCams = new List<Camera>();
foreach(Camera cm in this._cameras){
if(cm.IsFunctional && cm.CanScan(position)){
canScanCams.Add(cm);
}
}
Camera.Target FoundTarget = new Camera.Target();
if(this.Scan_Now_I >= canScanCams.Count) this.Scan_Now_I = 0;
double ScanSpeed = (canScanCams.Count*2000)/(Vector3D.Distance(position, this._cockpit.Position)*60);//每个循环可用于扫描的摄像头个数
if(ScanSpeed >= 1){
//每秒可扫描多个
FoundTarget = canScanCams[this.Scan_Now_I].Scan(position, timestemp);
this.Scan_Now_I += 1;
if(this.Scan_Now_I >= canScanCams.Count){this.Scan_Now_I=0;}
}else{
if(Scan_T%Math.Round(1/ScanSpeed,0)==0)
{
FoundTarget = canScanCams[this.Scan_Now_I].Scan(position, timestemp);
this.Scan_Now_I += 1;
}
}
return FoundTarget;
}
}
public class Gyro: Block
{
// v1.0.0
// 依赖:Block类
// == 构造方法
public Gyro(IMyTerminalBlock b):base(b){
this._block = b;
this._gyro = b as IMyGyro;
}
public Gyro(IMyGyro b):base(b){
this._block = b;
this._gyro = b as IMyGyro;
}
// == 成员属性
public IMyGyro _gyro; //陀螺仪方块本体
public double Pwoer{ //能量
get { return this._gyro.GyroPower; }
set { this._gyro.GyroPower = (float)value; }
}
public bool IsOverride{ //是否开启越级
get { return this._gyro.GyroOverride; }
set { this._gyro.GyroOverride = value; }
}
public int MotionRatio = 1; //正反系数
public double Yaw{ //偏航值,开启越级后有效
get { return this._gyro.Yaw*this.MotionRatio; }
set { this._gyro.Yaw = (float)value*this.MotionRatio; }
}
public double Pitch{ //俯仰值,开启越级后有效
get { return this._gyro.Pitch*this.MotionRatio; }
set { this._gyro.Pitch = (float)value*this.MotionRatio; }
}
public double Roll{ //滚转值,开启越级后有效
get { return this._gyro.Roll*this.MotionRatio; }
set { this._gyro.Roll = (float)value*this.MotionRatio; }
}
}
public class Gyros
{
// 陀螺仪组
// v1.0
// 依赖:Cockpit,Gyro
// 这是一个陀螺仪组类,构造方式是传入一个主控座椅和一组陀螺仪,这个类会自动处理陀螺仪与主控座椅的相对方向。
// 哪怕主控座椅和陀螺仪不在同一个主网格,只要大体上方向是对得上的,也能正确识别陀螺仪相对主控的安装方向。
// 使用这个类可以轻松的控制一组陀螺仪往基于主控的正确方向出力
public Cockpit _cockpit;
public List<Gyro> _gyros;
public List<string> _yawField;
public List<string> _pitchField;
public List<string> _rollField;
public List<float> _yawFactor;
public List<float> _pitchFactor;
public List<float> _rollFactor;
public int Count{
get { return this._gyros.Count; }
}
public double Yaw{ //Yaw值,set为每个陀螺仪的出力,get为所有陀螺仪的合出力
get {
double v = 0;
for (int i = 0; i < this._gyros.Count; i++){
v += (double)(this._gyros[i]._gyro.GetValueFloat(this._yawField[i]) * this._yawFactor[i]);
}
return v;
}
set {
for (int i = 0; i < this._gyros.Count; i++){
this._gyros[i]._gyro.SetValue(this._yawField[i], (float)value * this._yawFactor[i]);
}
}
}
public double Pitch{ //Pitch值,set为每个陀螺仪的出力,get为所有陀螺仪的合出力
get {
double v = 0;
for (int i = 0; i < this._gyros.Count; i++){
v += (double)(this._gyros[i]._gyro.GetValueFloat(this._pitchField[i]) * this._pitchFactor[i]);
}
return v;
}
set {
for (int i = 0; i < this._gyros.Count; i++){
this._gyros[i]._gyro.SetValue(this._pitchField[i], (float)value * this._pitchFactor[i]);
}
}
}
public double Roll{ //Roll值,set为每个陀螺仪的出力,get为所有陀螺仪的合出力
get {
double v = 0;
for (int i = 0; i < this._gyros.Count; i++){
v += (double)(this._gyros[i]._gyro.GetValueFloat(this._rollField[i]) * this._rollFactor[i]);
}
return v;
}
set {
for (int i = 0; i < this._gyros.Count; i++){
this._gyros[i]._gyro.SetValue(this._rollField[i], (float)value * this._rollFactor[i]);
}
}
}
public Gyros(Cockpit cockpit, List<Gyro> gyros){
this._cockpit = cockpit;
this._gyros = new List<Gyro>();
foreach(Gyro g in gyros){
if(g.IsOK){
this._gyros.Add(g);
}
}
this.init();
}
public Gyros(Cockpit cockpit, List<IMyTerminalBlock> gyros){
this._cockpit = cockpit;
this._gyros = new List<Gyro>();
foreach(IMyTerminalBlock b in gyros){
if(b is IMyGyro){
this._gyros.Add(new Gyro(b));
}
}
this.init();
}
private void init(){
this._yawField = new List<string>();
this._pitchField = new List<string>();
this._rollField = new List<string>();
this._yawFactor = new List<float>();
this._pitchFactor = new List<float>();
this._rollFactor = new List<float>();
for (int i = 0; i < this._gyros.Count; i++){
Base6Directions.Direction gyroUp = _gyros[i].WorldMatrix.GetClosestDirection(this._cockpit.WorldMatrix.Up);
Base6Directions.Direction gyroLeft = _gyros[i].WorldMatrix.GetClosestDirection(this._cockpit.WorldMatrix.Left);
Base6Directions.Direction gyroForward = _gyros[i].WorldMatrix.GetClosestDirection(this._cockpit.WorldMatrix.Forward);
switch (gyroUp)
{ case Base6Directions.Direction.Up: this._yawField.Add("Yaw"); this._yawFactor.Add(1f); break;
case Base6Directions.Direction.Down: this._yawField.Add("Yaw"); this._yawFactor.Add(-1f); break;
case Base6Directions.Direction.Left: this._yawField.Add("Pitch"); this._yawFactor.Add(1f); break;
case Base6Directions.Direction.Right: this._yawField.Add("Pitch"); this._yawFactor.Add(-1f); break;
case Base6Directions.Direction.Forward: this._yawField.Add("Roll"); this._yawFactor.Add(-1f); break;
case Base6Directions.Direction.Backward: this._yawField.Add("Roll"); this._yawFactor.Add(1f); break;
}
switch (gyroLeft)
{ case Base6Directions.Direction.Up: this._pitchField.Add("Yaw"); this._pitchFactor.Add(1f); break;
case Base6Directions.Direction.Down: this._pitchField.Add("Yaw"); this._pitchFactor.Add(-1f); break;
case Base6Directions.Direction.Left: this._pitchField.Add("Pitch"); this._pitchFactor.Add(1f); break;
case Base6Directions.Direction.Right: this._pitchField.Add("Pitch"); this._pitchFactor.Add(-1f); break;
case Base6Directions.Direction.Forward: this._pitchField.Add("Roll"); this._pitchFactor.Add(-1f); break;
case Base6Directions.Direction.Backward: this._pitchField.Add("Roll"); this._pitchFactor.Add(1f); break;
}
switch (gyroForward)
{ case Base6Directions.Direction.Up: this._rollField.Add("Yaw"); this._rollFactor.Add(1f); break;
case Base6Directions.Direction.Down: this._rollField.Add("Yaw"); this._rollFactor.Add(-1f); break;
case Base6Directions.Direction.Left: this._rollField.Add("Pitch"); this._rollFactor.Add(1f); break;
case Base6Directions.Direction.Right: this._rollField.Add("Pitch"); this._rollFactor.Add(-1f); break;
case Base6Directions.Direction.Forward: this._rollField.Add("Roll"); this._rollFactor.Add(-1f); break;
case Base6Directions.Direction.Backward: this._rollField.Add("Roll"); this._rollFactor.Add(1f); break;
}
}
}
// ==== 成员方法
// 设置越级值
public void SetValue(double yaw = 0, double pitch = 0, double roll = 0){
for (int i = 0; i < this._gyros.Count; i++){
this._gyros[i]._gyro.SetValue(this._yawField[i], (float)yaw * this._yawFactor[i]);
this._gyros[i]._gyro.SetValue(this._pitchField[i], (float)pitch * this._pitchFactor[i]);
this._gyros[i]._gyro.SetValue(this._rollField[i], (float)roll * this._rollFactor[i]);
}
}
//开关越级
public void SetOverride(bool onoff = true){
for (int i = 0; i < this._gyros.Count; i++){
this._gyros[i].IsOverride = onoff;
}
}
//开关方块
public void SetOnOff(bool onoff = true){
for (int i = 0; i < this._gyros.Count; i++){
this._gyros[i].OnOff = onoff;
}
}
}
public class Thrust: Block
{
// v1.0.0
// 依赖:Block类
// == 构造方法
public Thrust(IMyTerminalBlock b):base(b){
this._block = b;
this._thrust = b as IMyThrust;
}
public Thrust(IMyThrust b):base(b){
this._block = b;
this._thrust = b as IMyThrust;
}
// == 成员属性
public IMyThrust _thrust; //推进器方块本体
public double Power{ //越级出力值(单位:百分比)
get { return this._thrust.ThrustOverridePercentage; }
set { this._thrust.ThrustOverridePercentage = (float)value; }
}
public double PowerN{ //越级出力值(单位:牛顿)
get { return this._thrust.ThrustOverride; }
set { this._thrust.ThrustOverride = (float)value; }
}
public double MaxThrust{ //最大出力值(单位:牛顿)
get { return this._thrust.MaxThrust; }
}
public double MaxEffectiveThrust{ //最大实际出力值(单位:牛顿)
get { return this._thrust.MaxEffectiveThrust; }
}
public double CurrentThrust{ //当前出力值(单位:牛顿)
get { return this._thrust.CurrentThrust; }
}
public Vector3I GridThrustDirection{ //基于网格方向的相对方向,相当于安装方向
get { return this._thrust.GridThrustDirection; }
}
}
public class Thrusts
{
// 推进器组
// v1.0.0
// 依赖:Cockpit、Thrust
// 传入一个主控座椅和一组推进器构造本类
// 本类会在内部自动计算推进器基于主控座椅的安装方向,以便方便的控制Forward、Backward、Up、Down、Left、Right 6个方向的出力
// 允许跨网格安装,只要推进器指向大体对准主控的6个面之一,就能正确判断
// == 成员属性
public Cockpit _cockpit;
public List<Thrust> _thrusts;
public List<string> _fields;
public int Count{
get { return this._thrusts.Count; }
}
// == 构造方法
public Thrusts(Cockpit cockpit, List<Thrust> thrusts){
this._cockpit = cockpit;
this._thrusts = new List<Thrust>();
foreach(Thrust th in thrusts){
if(th.IsOK) this._thrusts.Add(th);
}
this.init();
}
public Thrusts(Cockpit cockpit, List<IMyTerminalBlock> thrusts){
this._cockpit = cockpit;
this._thrusts = new List<Thrust>();
foreach(IMyTerminalBlock b in thrusts){
if(b is IMyThrust){
this._thrusts.Add(new Thrust(b));
}
}
this.init();
}
// == 成员方法
private void init(){
this._fields = new List<string>();
for(int i = 0; i < this._thrusts.Count; i ++){
Base6Directions.Direction CockpitForward = this._thrusts[i].WorldMatrix.GetClosestDirection(this._cockpit.WorldMatrix.Forward);
Base6Directions.Direction CockpitUp = this._thrusts[i].WorldMatrix.GetClosestDirection(this._cockpit.WorldMatrix.Up);
Base6Directions.Direction CockpitLeft = this._thrusts[i].WorldMatrix.GetClosestDirection(this._cockpit.WorldMatrix.Left);
switch (CockpitForward)
{ case Base6Directions.Direction.Forward: this._fields.Add("Forward"); break; case Base6Directions.Direction.Backward: this._fields.Add("Backward"); break; }
switch (CockpitUp)
{ case Base6Directions.Direction.Forward: this._fields.Add("Up"); break; case Base6Directions.Direction.Backward: this._fields.Add("Down"); break; }
switch (CockpitLeft)
{ case Base6Directions.Direction.Forward: this._fields.Add("Left"); break; case Base6Directions.Direction.Backward: this._fields.Add("Right"); break; }
}
}
// 推进
// 方向(为All时设置所有),数值,是否是百分比
public void SetValue(string direction, double value, bool isPercent = true){
if(direction == "All"){
this.SetValue("Backward", value, isPercent);
this.SetValue("Forward", value, isPercent);
this.SetValue("Left", value, isPercent);
this.SetValue("Right", value, isPercent);
this.SetValue("Up", value, isPercent);
this.SetValue("Down", value, isPercent);
}else{
for(int i = 0; i < this._thrusts.Count; i ++){
if(this._fields[i] == direction){
if(isPercent){ this._thrusts[i].Power = value; }
else{ this._thrusts[i].PowerN = value; }
}
}
}
}
//开关方块
public void SetOnOff(bool onoff){
for (int i = 0; i < this._thrusts.Count; i++){
this._thrusts[i].OnOff = onoff;
}
}
}
public class Piston: Block
{
// v1.0.0
// 依赖:Block类
// == 构造方法
public Piston(IMyTerminalBlock b):base(b){
this._block = b;
this._piston = b as IMyPistonBase;
}
public Piston(IMyPistonBase b):base(b){
this._block = b;
this._piston = b as IMyPistonBase;
}
// == 成员属性
public IMyPistonBase _piston; //活塞方块本体
public double Velocity{ //速度
get { return this._piston.Velocity; }
set { this._piston.Velocity = (float)value; }
}
public double MaxVelocity{ //最大速度
get { return this._piston.MaxVelocity; }
}
public double MinLimit{ //最小限制
get { return this._piston.MinLimit; }
set { this._piston.MinLimit = (float)value; }
}
public double MaxLimit{ //最大限制
get { return this._piston.MaxLimit; }
set { this._piston.MaxLimit = (float)value; }
}
public double CurrentPosition{ //当前位置
get { return this._piston.CurrentPosition; }
}
public PistonStatus Status{ //当前状态
get { return this._piston.Status; }
}
}
```
- 序言
- 写在前面的话
- 太空工程师
- MEA小组
- 一、入门
- 1.1 基础概念
- 1.2 编程工具
- 1.3 变量
- 1.4 函数 Function
- 1.5 基本语法
- 1.5.1 运算符
- 1.5.2 if
- 1.5.3 for
- 1.5.4 其他语法
- 1.3 类 Class
- 二、编程块
- 2.1 方块的概念
- 2.2 List<T>结构
- 2.3 获取方块
- 2.4 方块的使用
- 三、Ship 类
- 3.1 简介
- Ship v0.5
- 代码
- 手册(待更新)
- 例子(待更新)
- Ship v1.0
- 代码
- 例子
- 文档
- 实例化
- 内置变量
- 内置方法
- Target类
- 四、运动控制算法在SE中的应用
- 4.1 运动控制介绍
- 4.2 过程控制
- 4.3 震荡和动态误差
- 4.4 误差累加方案
- 4.5 PID算法
- 4.6 对PID算法的一点点简化
- 4.7 一阶惯性系统的PID算法优化的研究
- 五、MEA方块类
- 5.0 核心代码目录
- v1.0核心代码
- v1.1 核心代码
- v2.0 核心代码
- 5.1 类的概念
- 5.2 MEA的方块类(Block)
- 5.3 方块类文档
- 5.4 方块类2.0 全教程
- 5.4.1 安装和使用
- 5.4.2 方块类(Block)
- 5.4.3 显示屏类(DisplayScreen)
- 5.4.4 LCD类(LCD)
- 5.4.5 主控座椅类(Cockpit)
- 六、疯猴的编程笔记
- 第一个程序
- 获取和控制其他块
- 物流与生产
- 界面与通信
- 运动与姿态
- 侦测与导航
- 七、SteamZhou的笔记
- 有趣而花里胡哨的IDEA
- 八、质子对撞炮的笔记
- 属性 Property
- 接口 interface