/// <summary> /// this is really only used for initialization. Use Entity.Mass for the ship's mass as it pertains to the physics model /// </summary> /// <returns>the mass of all combined shipParts</returns> private float getTotalMass() { return(Reactors.Select(x => x.GetMass()).Sum() + Shields.Select(x => x.GetMass()).Sum() + Weapons.Select(x => x.GetMass()).Sum() + Engines.Select(x => x.GetMass()).Sum() + CrewDecks.Select(x => x.GetMass()).Sum()); }
private List <IShipPart> getDamageableParts() { return(new List <IShipPart>() .Concat(Reactors.Where(x => !x.IsDestroyed())) .Concat(Engines.Where(x => !x.IsDestroyed())) .Concat(Shields.Where(x => !x.IsDestroyed())) .Concat(Weapons.Where(x => !x.IsDestroyed())) .Concat(CrewDecks.Where(x => !x.IsDestroyed())).ToList()); }
/// <summary> /// repairs some part that is damaged. /// </summary> /// <param name="crewDeck">Use this crewdeck's repair rate.</param> private void repairARandomPartThatNeedsIt(CrewDeck crewDeck) { List <IShipPart> damagedParts = new List <IShipPart>(); damagedParts.AddRange(Reactors.Where(x => x.Health.Item1 < x.Health.Item2)); damagedParts.AddRange(Engines.Where(x => x.Health.Item1 < x.Health.Item2)); damagedParts.AddRange(Weapons.Where(x => x.Health.Item1 < x.Health.Item2)); damagedParts.AddRange(Shields.Where(x => x.Health.Item1 < x.Health.Item2)); damagedParts.AddRange(CrewDecks.Where(x => x.Health.Item1 < x.Health.Item2)); if (damagedParts.Count() == 0) { return; } crewDeck.PerformRepair(damagedParts[GameEngine.Random(damagedParts.Count)]); }
private void spendPower() { // currently the only thing that this does is regen the shields or not. // change to for loop so we have more control owver what gets power when and what happens if there isn't enough power. Power -= (Reactors.Select(x => x.GetUpkeepCost()).Sum() + Shields.Select(x => x.GetUpkeepCost()).Sum() + Weapons.Select(x => x.GetUpkeepCost()).Sum() + Engines.Select(x => x.GetUpkeepCost()).Sum() + CrewDecks.Select(x => x.GetUpkeepCost()).Sum()); if (Power < 0) { Power = 0; } foreach (var shield in Shields) { Power = shield.Regen(Power); } }
public override string ToString() { var result = "Ship:" + Name + " Crew:" + CrewDecks.Select(x => (int)x.GetCrew()).Sum() + " Mass: " + Mass + " Power:" + Power + " Position:[X:" + Position.X + " Y:" + Position.Y + " Heading:" + Orientation + "° Velocity: X:" + Velocity.X + " Y:" + Velocity.Y + " Mag:" + Velocity.Magnitude + "]\n"; result += string.Join(" ", Reactors.Select(x => x.ToString())) + "\n"; result += string.Join(" ", Shields.Select(x => x.ToString())) + "\n"; result += string.Join(" ", Weapons.Select(x => x.ToString())) + "\n"; result += string.Join(" ", Engines.Select(x => x.ToString())) + "Max :" + GetMaxAcceleration() + "\n"; result += string.Join(" ", CrewDecks.Select(x => x.ToString())) + "\n"; if (IsDestroyed()) { result += "(Destroyed)\n"; } return(result); }
public override bool IsDestroyed() { if (CrewDecks.Select(x => (int)x.GetCrew()).Sum() == 0) { return(true); // probably not exactly what we want. We will probably want a difference betweeen destroyed and derelict. } foreach (var part in Reactors) { if (!part.IsDestroyed()) { return(false); } } foreach (var part in Shields) { if (!part.IsDestroyed()) { return(false); } } foreach (var part in Weapons) { if (!part.IsDestroyed()) { return(false); } } foreach (var part in Engines) { if (!part.IsDestroyed()) { return(false); } } return(true); }