skyscraper8/skyscraper8/Skyscraper/Equipment/SatellitePositionEntity.cs
2026-01-20 17:01:31 +01:00

109 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace skyscraper5.Skyscraper
{
public class SatellitePositionEntity
{
public SatellitePositionEntity()
{
}
public SatellitePositionEntity(float angle, string name)
{
this.angle = angle;
this.name = name;
}
public float angle;
public string name;
public int Checksum => GetChecksum(angle);
public static int GetChecksum(float angle)
{
int result = (int)(angle * 10.0f);
return result;
}
public override string ToString()
{
if (angle > 0)
{
return String.Format("{0}°E {1}", angle, name);
}
else
{
float tmpAngle = angle;
tmpAngle *= -1;
return String.Format("{0}°W {1}", tmpAngle, name);
}
}
public static SatellitePositionEntity FromChecksum(int checksum)
{
float newAngle = checksum;
newAngle /= 10.0f;
return new SatellitePositionEntity(newAngle, "???");
}
protected bool Equals(SatellitePositionEntity other)
{
return angle.Equals(other.angle);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((SatellitePositionEntity)obj);
}
public override int GetHashCode()
{
return HashCode.Combine(angle);
}
/// <summary>
/// Returns an integer value for the cardinal direction.
/// </summary>
/// <returns>Returns 0 for east, 1 for west, 2 if satellite is at 0.0</returns>
public int GetCardinalDirectionAsInt()
{
if (angle > 0)
return 0;
else if (angle < 0)
return 1;
else
return 2;
}
/// <summary>
/// Get the letter matching the cardinal direction of the satellite.
/// </summary>
/// <returns>Returns either 'E' or 'W' depending on the angle.</returns>
public char GetCardinalDirectionAsChar()
{
int cardinalDirectionAsInt = GetCardinalDirectionAsInt();
return cardinalDirectionAsInt == 0 ? 'E' : 'W';
}
/// <summary>
/// Get a filename-safe number of the angle. Meaning the angle stripped of its sign and decimal separator.
/// </summary>
/// <returns>For example: For 19.2°E, this will return 192, For 34.5°W, this will return 345</returns>
public int GetCleanAngle()
{
int cleanAngle = (int)(angle * 10.0f);
if (cleanAngle < 0)
cleanAngle /= -1;
return cleanAngle;
}
}
}