public Commander(Hashtable hash) : base(hash) { _cash = (int)GetValueFromHash(hash, "_cash", _cash); _debt = (int)GetValueFromHash(hash, "_debt", _debt); _killsPirate = (int)GetValueFromHash(hash, "_killsPirate", _killsPirate); _killsPolice = (int)GetValueFromHash(hash, "_killsPolice", _killsPolice); _killsTrader = (int)GetValueFromHash(hash, "_killsTrader", _killsTrader); _policeRecordScore = (int)GetValueFromHash(hash, "_policeRecordScore", _policeRecordScore); _reputationScore = (int)GetValueFromHash(hash, "_reputationScore", _reputationScore); _days = (int)GetValueFromHash(hash, "_days", _days); _insurance = (bool)GetValueFromHash(hash, "_insurance", _insurance); _noclaim = (int)GetValueFromHash(hash, "_noclaim", _noclaim); _ship = new Ship((Hashtable)GetValueFromHash(hash, "_ship", _ship)); _priceCargo = (int[])GetValueFromHash(hash, "_priceCargo", _priceCargo); Game.CurrentGame.Mercenaries[(int)CrewMemberId.Commander] = this; Strings.CrewMemberNames[(int)CrewMemberId.Commander] = (string)GetValueFromHash(hash, "_name", Strings.CrewMemberNames[(int)CrewMemberId.Commander]); }
public static void PaintShipImage(Ship ship, Graphics g, Color backgroundColor) { int x = Consts.ShipImageOffsets[(int)ship.Type].X; int width = Consts.ShipImageOffsets[(int)ship.Type].Width; int startDamage = x + width - ship.Hull * width / ship.HullStrength; int startShield = x + width + 2 - (ship.ShieldStrength > 0 ? ship.ShieldCharge * (width + 4) / ship.ShieldStrength : 0); g.Clear(backgroundColor); if (startDamage > x) { if (startShield > x) DrawPartialImage(g, ship.ImageDamaged, x, Math.Min(startDamage, startShield)); if (startShield < startDamage) DrawPartialImage(g, ship.ImageDamagedWithShields, startShield, startDamage); } if (startShield > startDamage) DrawPartialImage(g, ship.Image, startDamage, startShield); if (startShield < x + width + 2) DrawPartialImage(g, ship.ImageWithShields, startShield, x + width + 2); }
private void GenerateOpponent(OpponentType oppType) { Opponent = new Ship(oppType); }
public Game(Hashtable hash, SpaceTrader parentWin) : base(hash) { _game = this; ParentWindow = parentWin; string version = (string)GetValueFromHash(hash, "_version"); if (version.CompareTo(Consts.CurrentVersion) > 0) throw new FutureVersionException(); _universe = (StarSystem[])ArrayListToArray((ArrayList)GetValueFromHash(hash, "_universe"), "StarSystem"); _wormholes = (int[])GetValueFromHash(hash, "_wormholes", _wormholes); _mercenaries = (CrewMember[])ArrayListToArray((ArrayList)GetValueFromHash(hash, "_mercenaries"), "CrewMember"); _commander = new Commander((Hashtable)GetValueFromHash(hash, "_commander")); _dragonfly = new Ship((Hashtable)GetValueFromHash(hash, "_dragonfly", _dragonfly.Serialize())); _scarab = new Ship((Hashtable)GetValueFromHash(hash, "_scarab", _scarab.Serialize())); _scorpion = new Ship((Hashtable)GetValueFromHash(hash, "_scorpion", _scorpion.Serialize())); _spaceMonster = new Ship((Hashtable)GetValueFromHash(hash, "_spaceMonster", _spaceMonster.Serialize())); _opponent = new Ship((Hashtable)GetValueFromHash(hash, "_opponent", _opponent.Serialize())); _chanceOfTradeInOrbit = (int)GetValueFromHash(hash, "_chanceOfTradeInOrbit", _chanceOfTradeInOrbit); _clicks = (int)GetValueFromHash(hash, "_clicks", _clicks); _raided = (bool)GetValueFromHash(hash, "_raided", _raided); _inspected = (bool)GetValueFromHash(hash, "_inspected", _inspected); _tribbleMessage = (bool)GetValueFromHash(hash, "_tribbleMessage", _tribbleMessage); _arrivedViaWormhole = (bool)GetValueFromHash(hash, "_arrivedViaWormhole", _arrivedViaWormhole); _paidForNewspaper = (bool)GetValueFromHash(hash, "_paidForNewspaper", _paidForNewspaper); _litterWarning = (bool)GetValueFromHash(hash, "_litterWarning", _litterWarning); _newsEvents = new ArrayList((int[])GetValueFromHash(hash, "_newsEvents", _newsEvents.ToArray(System.Type.GetType("System.Int32")))); _difficulty = (Difficulty)GetValueFromHash(hash, "_difficulty", _difficulty); _cheatEnabled = (bool)GetValueFromHash(hash, "_cheatEnabled", _cheatEnabled); _autoSave = (bool)GetValueFromHash(hash, "_autoSave", _autoSave); _easyEncounters = (bool)GetValueFromHash(hash, "_easyEncounters", _easyEncounters); _endStatus = (GameEndType)GetValueFromHash(hash, "_endStatus", _endStatus); _encounterType = (EncounterType)GetValueFromHash(hash, "_encounterType", _encounterType); _selectedSystemId = (StarSystemId)GetValueFromHash(hash, "_selectedSystemId", _selectedSystemId); _warpSystemId = (StarSystemId)GetValueFromHash(hash, "_warpSystemId", _warpSystemId); _trackedSystemId = (StarSystemId)GetValueFromHash(hash, "_trackedSystemId", _trackedSystemId); _targetWormhole = (bool)GetValueFromHash(hash, "_targetWormhole", _targetWormhole); _priceCargoBuy = (int[])GetValueFromHash(hash, "_priceCargoBuy", _priceCargoBuy); _priceCargoSell = (int[])GetValueFromHash(hash, "_priceCargoSell", _priceCargoSell); _questStatusArtifact = (int)GetValueFromHash(hash, "_questStatusArtifact", _questStatusArtifact); _questStatusDragonfly = (int)GetValueFromHash(hash, "_questStatusDragonfly", _questStatusDragonfly); _questStatusExperiment = (int)GetValueFromHash(hash, "_questStatusExperiment", _questStatusExperiment); _questStatusGemulon = (int)GetValueFromHash(hash, "_questStatusGemulon", _questStatusGemulon); _questStatusJapori = (int)GetValueFromHash(hash, "_questStatusJapori", _questStatusJapori); _questStatusJarek = (int)GetValueFromHash(hash, "_questStatusJarek", _questStatusJarek); _questStatusMoon = (int)GetValueFromHash(hash, "_questStatusMoon", _questStatusMoon); _questStatusPrincess = (int)GetValueFromHash(hash, "_questStatusPrincess", _questStatusPrincess); _questStatusReactor = (int)GetValueFromHash(hash, "_questStatusReactor", _questStatusReactor); _questStatusScarab = (int)GetValueFromHash(hash, "_questStatusScarab", _questStatusScarab); _questStatusSculpture = (int)GetValueFromHash(hash, "_questStatusSculpture", _questStatusSculpture); _questStatusSpaceMonster = (int)GetValueFromHash(hash, "_questStatusSpaceMonster", _questStatusSpaceMonster); _questStatusWild = (int)GetValueFromHash(hash, "_questStatusWild", _questStatusWild); _fabricRipProbability = (int)GetValueFromHash(hash, "_fabricRipProbability", _fabricRipProbability); _justLootedMarie = (bool)GetValueFromHash(hash, "_justLootedMarie", _justLootedMarie); _canSuperWarp = (bool)GetValueFromHash(hash, "_canSuperWarp", _canSuperWarp); _chanceOfVeryRareEncounter = (int)GetValueFromHash(hash, "_chanceOfVeryRareEncounter", _chanceOfVeryRareEncounter); _veryRareEncounters = new ArrayList((int[])GetValueFromHash(hash, "_veryRareEncounters", _veryRareEncounters.ToArray(System.Type.GetType("System.Int32")))); _options = new GameOptions((Hashtable)GetValueFromHash(hash, "_options", _options.Serialize())); }
private bool EncounterExecuteAttack(Ship attacker, Ship defender, bool fleeing) { bool hit = false; // On beginner level, if you flee, you will escape unharmed. // Otherwise, Fighter skill attacker is pitted against pilot skill defender; if defender // is fleeing the attacker has a free shot, but the chance to hit is smaller // JAF - if the opponent is disabled and attacker has targeting system, they WILL be hit. if (!(Difficulty == Difficulty.Beginner && defender.CommandersShip && fleeing) && (attacker.CommandersShip && OpponentDisabled && attacker.HasGadget(GadgetType.TargetingSystem) || Functions.GetRandom(attacker.Fighter + (int)defender.Size) >= (fleeing ? 2 : 1) * Functions.GetRandom(5 + defender.Pilot / 2))) { // If the defender is disabled, it only takes one shot to destroy it completely. if (attacker.CommandersShip && OpponentDisabled) defender.Hull = 0; else { int attackerLasers = attacker.WeaponStrength(WeaponType.PulseLaser, WeaponType.MorgansLaser); int attackerDisruptors = attacker.WeaponStrength(WeaponType.PhotonDisruptor, WeaponType.QuantumDistruptor); if (defender.Type == ShipType.Scarab) { attackerLasers -= attacker.WeaponStrength(WeaponType.BeamLaser, WeaponType.MilitaryLaser); attackerDisruptors -= attacker.WeaponStrength(WeaponType.PhotonDisruptor, WeaponType.PhotonDisruptor); } int attackerWeapons = attackerLasers + attackerDisruptors; int disrupt = 0; // Attempt to disable the opponent if they're not already disabled, their shields are down, // we have disabling weapons, and the option is checked. if (defender.Disableable && defender.ShieldCharge == 0 && !OpponentDisabled && Options.DisableOpponents && attackerDisruptors > 0) { disrupt = Functions.GetRandom(attackerDisruptors * (100 + 2 * attacker.Fighter) / 100); } else { int damage = attackerWeapons == 0 ? 0 : Functions.GetRandom(attackerWeapons * (100 + 2 * attacker.Fighter) / 100); if (damage > 0) { hit = true; // Reactor on board -- damage is boosted! if (defender.ReactorOnBoard) damage *= (int)(1 + ((int)Difficulty + 1) * (Difficulty < Difficulty.Normal ? 0.25 : 0.33)); // First, shields are depleted for (int i = 0; i < defender.Shields.Length && defender.Shields[i] != null && damage > 0; i++) { int applied = Math.Min(defender.Shields[i].Charge, damage); defender.Shields[i].Charge -= applied; damage -= applied; } // If there still is damage after the shields have been depleted, // this is subtracted from the hull, modified by the engineering skill // of the defender. // JAF - If the player only has disabling weapons, no damage will be done to the hull. if (damage > 0) { damage = Math.Max(1, damage - Functions.GetRandom(defender.Engineer)); disrupt = damage * attackerDisruptors / attackerWeapons; // Only that damage coming from Lasers will deplete the hull. damage -= disrupt; // At least 2 shots on Normal level are needed to destroy the hull // (3 on Easy, 4 on Beginner, 1 on Hard or Impossible). For opponents, // it is always 2. damage = Math.Min(damage, defender.HullStrength / (defender.CommandersShip ? Math.Max(1, Difficulty.Impossible - Difficulty) : 2)); // If the hull is hardened, damage is halved. if (QuestStatusScarab == SpecialEvent.StatusScarabDone) damage /= 2; defender.Hull = Math.Max(0, defender.Hull - damage); } } } // Did the opponent get disabled? (Disruptors are 3 times more effective against the ship's // systems than they are against the shields). if (defender.Hull > 0 && defender.Disableable && Functions.GetRandom(100) < disrupt * Consts.DisruptorSystemsMultiplier * 100 / defender.Hull) OpponentDisabled = true; // Make sure the Scorpion doesn't get destroyed. if (defender.Type == ShipType.Scorpion && defender.Hull == 0) { defender.Hull = 1; OpponentDisabled = true; } } } return hit; }
public bool TradeShip(ShipSpec specToBuy, int netPrice, string newShipName, IWin32Window owner) { bool traded = false; if (netPrice > 0 && Debt > 0) FormAlert.Alert(AlertType.DebtNoBuy, owner); else if (netPrice > CashToSpend) FormAlert.Alert(AlertType.ShipBuyIf, owner); else if (specToBuy.CrewQuarters < Ship.SpecialCrew.Length) { string passengers = Ship.SpecialCrew[1].Name; if (Ship.SpecialCrew.Length > 2) passengers += " and " + Ship.SpecialCrew[2].Name; FormAlert.Alert(AlertType.ShipBuyPassengerQuarters, owner, passengers); } else if (specToBuy.CrewQuarters < Ship.CrewCount) FormAlert.Alert(AlertType.ShipBuyCrewQuarters, owner); else if (Ship.ReactorOnBoard) FormAlert.Alert(AlertType.ShipBuyReactor, owner); else { Equipment[] special = new Equipment[] { Consts.Weapons[(int)WeaponType.MorgansLaser], Consts.Weapons[(int)WeaponType.QuantumDistruptor], Consts.Shields[(int)ShieldType.Lightning], Consts.Gadgets[(int)GadgetType.FuelCompactor], Consts.Gadgets[(int)GadgetType.HiddenCargoBays] }; bool[] add = new bool[special.Length]; bool addPod = false; int extraCost = 0; for (int i = 0; i < special.Length; i++) { if (!Ship.HasEquipment(special[i])) continue; if (specToBuy.Slots(special[i].EquipmentType) == 0) FormAlert.Alert(AlertType.ShipBuyNoSlots, owner, newShipName, special[i].Name, Strings.EquipmentTypes[(int)special[i].EquipmentType]); else { extraCost += special[i].TransferPrice; add[i] = true; } } if (Ship.EscapePod) { addPod = true; extraCost += Consts.PodTransferCost; } if (netPrice + extraCost > CashToSpend) FormAlert.Alert(AlertType.ShipBuyIfTransfer, owner); extraCost = 0; for (int i = 0; i < special.Length; i++) { if (!add[i]) continue; if (netPrice + extraCost + special[i].TransferPrice > CashToSpend) FormAlert.Alert(AlertType.ShipBuyNoTransfer, owner, special[i].Name); else if (FormAlert.Alert(AlertType.ShipBuyTransfer, owner, special[i].Name, special[i].Name.ToLower(), Functions.FormatNumber(special[i].TransferPrice)) == DialogResult.Yes) extraCost += special[i].TransferPrice; else add[i] = false; } if (addPod) { if (netPrice + extraCost + Consts.PodTransferCost > CashToSpend) FormAlert.Alert(AlertType.ShipBuyNoTransfer, owner, Strings.ShipInfoEscapePod); else if (FormAlert.Alert(AlertType.ShipBuyTransfer, owner, Strings.ShipInfoEscapePod, Strings.ShipInfoEscapePod.ToLower(), Functions.FormatNumber(Consts.PodTransferCost)) == DialogResult.Yes) extraCost += Consts.PodTransferCost; else addPod = false; } if (FormAlert.Alert(AlertType.ShipBuyConfirm, owner, Ship.Name, newShipName, (add[0] || add[1] || add[2] || addPod ? Strings.ShipBuyTransfer : "")) == DialogResult.Yes) { CrewMember[] oldCrew = Ship.Crew; Ship = new Ship(specToBuy.Type); Cash -= (netPrice + extraCost); for (int i = 0; i < Math.Min(oldCrew.Length, Ship.Crew.Length); i++) Ship.Crew[i] = oldCrew[i]; for (int i = 0; i < special.Length; i++) { if (add[i]) Ship.AddEquipment(special[i]); } if (addPod) Ship.EscapePod = true; else if (Insurance) { Insurance = false; NoClaim = 0; } traded = true; } } return traded; }