public Ship Spawn(ShipDescription description) { GameObject obj; switch (description.Side) { case Side.Bluefor: obj = Instantiate(BlueforShipPrefab); break; case Side.Redfor: obj = Instantiate(RedforShipPrefab); break; default: throw new NotSupportedException(); } obj.transform.SetParent(ShipsParent); var ship = obj.GetComponent <Ship>(); ship.Initialize(description); _ships.Add(ship); if (description.Side == Side.Bluefor) { _playerShipControls.Add(CreatePlayerShipControl(ship, _playerShipControls.Count)); } UpdateShipPositions(); return(ship); }
private void FillShipDescription() { ShipDescription.DataTextField = "DESCRIPTION"; ShipDescription.DataValueField = "IDKEYS"; ShipDescription.DataSource = DatabaseConnection.CreateDataset("SELECT ID,DESCRIPTION FROM QUOTESHIPMENT"); ShipDescription.DataBind(); ShipDescription.Items.Insert(0, new ListItem(Root.rm.GetString("Choose"), "0")); }
public virtual void Initialize(ShipDescription description) { if (_initialized) { throw new InvalidOperationException("The ship is already initialized."); } _maxHealth = description.MaxHealth; _damage = description.Damage; _repairSpeed = description.RepairSpeed; _shipName = description.ShipName; _side = description.Side; _initialized = true; }
public void Load() { foreach (XElement element in _xml.Element(XName.Get("Ships")).Descendants(XName.Get("Ship"))) { ShipDescription description = new ShipDescription(); description.ID = element.Attribute(XName.Get("id")).Value.ToInt(); description.Name = element.Element(XName.Get("Name")).Value; description.Description = element.Element(XName.Get("Description")).Value; description.Damage = element.Element(XName.Get("Specs")).Element(XName.Get("Damage")).Value.ToInt(); description.Health = element.Element(XName.Get("Specs")).Element(XName.Get("Health")).Value.ToInt(); Descriptions.Add(description); } }
public void Load() { foreach (XElement element in _xml.Element(XName.Get("Ships")).Descendants(XName.Get("Ship"))) { ShipDescription description = new ShipDescription(); description.ID = element.Attribute(XName.Get("id")).Value.ToInt(); description.Name = element.Element(XName.Get("Name")).Value; description.Description = element.Element(XName.Get("Description")).Value; description.Damage = element.Element(XName.Get("Specs")).Element(XName.Get("Damage")).Value.ToInt(); description.Health = element.Element(XName.Get("Specs")).Element(XName.Get("Health")).Value.ToInt(); Descriptions.Add(description); } }
// ============================================================================================================== private void DoAddMoreModules(IReadOnlyCollection <int> ModuleTypeIDs) { Dictionary <int,uint> NewModules = new Dictionary <int,uint>(); foreach (int ModuleTypeID in ModuleTypeIDs) { if (NewModules.ContainsKey(ModuleTypeID)) { NewModules[ModuleTypeID]++; } else { NewModules[ModuleTypeID] = 1; } } foreach (KeyValuePair <int,uint> kvp in NewModules) { int ModuleTypeID = kvp.Key; uint ModuleCount = kvp.Value; int Index = -1; bool Ok = ModuleTypeIDToIndex.TryGetValue(ModuleTypeID,out Index); Debug.Assert(Ok && Index >= 0); ModuleDescription MD = ModuleDescriptions[Index]; if (m_Fit[MD.m_Slot].ContainsKey(ModuleTypeID)) { m_Fit[MD.m_Slot][ModuleTypeID] = Math.Max(m_Fit[MD.m_Slot][ModuleTypeID],ModuleCount); } else { m_Fit[MD.m_Slot][ModuleTypeID] = ModuleCount; } } if (m_ShipTypeID > 0) { int Index = -1; if (ShipTypeIDToIndex.TryGetValue(ShipTypeID,out Index)) { ShipDescription SD = ShipDescriptions[Index]; // recalc slot layout for t3 cruisers RecalcStategicCruiserSlotLayout(SD); } } }
private void SetShipTypeID(int ShipTypeID) { int Index = -1; if (ShipTypeIDToIndex.TryGetValue(ShipTypeID,out Index)) { Debug.Assert(Index >= 0); m_ShipTypeID = ShipTypeID; ShipDescription SD = ShipDescriptions[Index]; m_Slots[SLOT.HIGH] = SD.m_HighSlots; m_Slots[SLOT.MEDIUM] = SD.m_MedSlots; m_Slots[SLOT.LOW] = SD.m_LowSlots; m_Slots[SLOT.RIG] = SD.m_RigSlots; if (SD.m_SubsystemSlots > 0) { Debug.Assert(SD.m_SubsystemSlots == 4); m_Slots[SLOT.SUB_CORE] = 1; m_Slots[SLOT.SUB_DEFENSIVE] = 1; m_Slots[SLOT.SUB_OFFENSIVE] = 1; m_Slots[SLOT.SUB_PROPULSION] = 1; } else { m_Slots[SLOT.SUB_CORE] = 0; m_Slots[SLOT.SUB_DEFENSIVE] = 0; m_Slots[SLOT.SUB_OFFENSIVE] = 0; m_Slots[SLOT.SUB_PROPULSION] = 0; } RecalcStategicCruiserSlotLayout(SD); } else { m_ShipTypeID = -1; m_Slots[SLOT.HIGH] = 8; m_Slots[SLOT.MEDIUM] = 8; m_Slots[SLOT.LOW] = 8; m_Slots[SLOT.RIG] = 3; m_Slots[SLOT.SUB_CORE] = 1; m_Slots[SLOT.SUB_DEFENSIVE] = 1; m_Slots[SLOT.SUB_OFFENSIVE] = 1; m_Slots[SLOT.SUB_PROPULSION] = 1; } }
/// <summary> /// Draw the ship selection for the specified player at the specified position. /// </summary> /// <param name="selection">Current player selection.</param> /// <param name="drawInfo">Current player draw info.</param> /// <param name="y">The y position on the screen where the selection will be drawn.</param> void DrawPlayerSelection(ShipDescription selection, SelectionDrawInfo drawInfo, int y) { SpriteBatch.DrawString(_bigFont, selection.Name, new Vector2(Game.Window.ClientBounds.Width / 2, y), new Color(Color.White, _descriptionOpacity), HorizontalAlign.Center); int sideShips = Math.Min(_ships.Count, MaxVisibleShips) - 2; int width = (sideShips * 2 + 1) * _spacing; int x = (Game.Window.ClientBounds.Width - width) / 2 + _spacing / 2; var option = _ships.IndexOf(selection); for (int i = option - sideShips; i <= option + sideShips; i++, x += _spacing) { var ship = _ships[i.Mod(_ships.Count)]; SpriteBatch.Draw(ship.Texture, position: new Vector2(x + drawInfo.DrawShift, y + 110), scale: drawInfo.IconScales[ship], origin: new Vector2(ship.Texture.Width / 2, ship.Texture.Height / 2)); } #region Stats int statsY = y + 180; var leftStats = new Dictionary <string, object> { { "Special", selection.SpecialAttack.Name }, { "Speed", selection.MaxSpeed } }; var rightStats = new Dictionary <string, object> { { "Mass", selection.Mass }, { "Fuel Duration", selection.FuelDuration.ToString("%s") }, }; var leftStatsString = string.Join("\r\n", leftStats.Select(k => k.Key + ": " + k.Value)); var rightStatsString = string.Join("\r\n", rightStats.Select(k => k.Key + ": " + k.Value)); var statsColor = new Color(Color.Gray, 0.6f); SpriteBatch.DrawString(_smallFont, leftStatsString, new Vector2(_statsX + 40, statsY), statsColor); SpriteBatch.DrawString(_smallFont, rightStatsString, new Vector2(_statsX + 420, statsY), statsColor); #endregion }
// ============================================================================================================== private void RecalculateTank() { if (!m_ValidFit || m_ShipTypeID < 0) { TankForInvalidFit(); } else { int ShipIndex = -1; bool Ok = ShipTypeIDToIndex.TryGetValue(m_ShipTypeID, out ShipIndex); Debug.Assert(Ok && ShipIndex >= 0 && ShipIndex < ShipDescriptions.Count); ShipDescription SD = ShipDescriptions[ShipIndex]; Dictionary <int, uint> AllModuleIDs = new Dictionary <int, uint>(); foreach (SLOT Slot in Enum.GetValues(typeof(SLOT))) { foreach (KeyValuePair <int,uint> ModuleAndCount in m_Fit[Slot]) { AllModuleIDs[ModuleAndCount.Key] = ModuleAndCount.Value; } } bool isPolarized = false; List <Tuple <ModuleDescription,uint> > AllModules = new List <Tuple <ModuleDescription,uint> >(); foreach (KeyValuePair <int,uint> kvp in AllModuleIDs) { int Index = -1; Ok = ModuleTypeIDToIndex.TryGetValue(kvp.Key,out Index); Debug.Assert(Ok); isPolarized |= IsPolarized(ModuleDescriptions[Index]); AllModules.Add(new Tuple <ModuleDescription,uint>(ModuleDescriptions[Index],kvp.Value)); } m_Tank[LAYER.SHIELD] = GetLayerTank(SD.m_ShieldHP,SD.m_ShieldHPMultiplier,SD.m_ShieldResistEM,SD.m_ShieldResistThermal,SD.m_ShieldResistKinetic,SD.m_ShieldResistExplosive,isPolarized,LAYER.SHIELD,AllModules,SD.m_OverheatingBonus); m_Tank[LAYER.ARMOR] = GetLayerTank(SD.m_ArmorHP,SD.m_ArmorHPMultiplier,SD.m_ArmorResistEM,SD.m_ArmorResistThermal,SD.m_ArmorResistKinetic,SD.m_ArmorResistExplosive,isPolarized,LAYER.ARMOR,AllModules,SD.m_OverheatingBonus); m_Tank[LAYER.HULL] = GetLayerTank(SD.m_HullHP,SD.m_HullHPMultiplier,SD.m_HullResistEM,SD.m_HullResistThermal,SD.m_HullResistKinetic,SD.m_HullResistExplosive,isPolarized,LAYER.HULL,AllModules,SD.m_OverheatingBonus); } EventTankChanged(); }
private void CheckFitValid() { m_ValidFit = true; foreach (SLOT Slot in Enum.GetValues(typeof(SLOT))) { Debug.Assert(m_Fit.ContainsKey(Slot)); uint ModuleCount = 0; foreach (KeyValuePair <int,uint> M in m_Fit[Slot]) { ModuleCount += M.Value; } if (ModuleCount > m_Slots[Slot]) { m_ValidFit = false; break; } } if (m_ValidFit) { if (m_ShipTypeID > 0) { int Index = -1; if (ShipTypeIDToIndex.TryGetValue(ShipTypeID,out Index)) { ShipDescription SD = ShipDescriptions[Index]; if (SD.m_SubsystemSlots > 0) { foreach (SLOT Slot in new SLOT[] { SLOT.SUB_CORE,SLOT.SUB_DEFENSIVE,SLOT.SUB_OFFENSIVE,SLOT.SUB_PROPULSION }) { if (m_Fit[Slot].Count > 1) { m_ValidFit = false; break; } #region Check that all 4 subsystems are filled. Not required anymore, coz we can have partial t3c fits. //if (m_Fit[Slot].Count != 1) { // m_ValidFit = false; // break; //} #endregion // Check that subsystems belong to current t3 hull. foreach (KeyValuePair <int,uint> kvp in m_Fit[Slot]) { Index = -1; if (!ModuleTypeIDToIndex.TryGetValue(kvp.Key,out Index) || Index < 0) { m_ValidFit = false; break; } ModuleDescription md = ModuleDescriptions[Index]; if (md.m_ShipTypeID < 0 || md.m_ShipTypeID != m_ShipTypeID) { m_ValidFit = false; break; } if (kvp.Value != 1) { m_ValidFit = false; break; } break; } } } } } } CheckFullFit(); }
private void RecalcStategicCruiserSlotLayout(ShipDescription SD) { if (SD.m_SubsystemSlots > 0) { int nSubsystems = ((m_Fit[SLOT.SUB_CORE].Count > 0) ? 1 : 0) + ((m_Fit[SLOT.SUB_DEFENSIVE].Count > 0) ? 1 : 0) + ((m_Fit[SLOT.SUB_OFFENSIVE].Count > 0) ? 1 : 0) + ((m_Fit[SLOT.SUB_PROPULSION].Count > 0) ? 1 : 0); if (nSubsystems == 4) { uint HS = SD.m_HighSlots; uint MS = SD.m_MedSlots; uint LS = SD.m_LowSlots; foreach (SLOT Slot in new SLOT[] { SLOT.SUB_CORE,SLOT.SUB_DEFENSIVE,SLOT.SUB_OFFENSIVE,SLOT.SUB_PROPULSION }) { foreach (KeyValuePair <int,uint> kvp in m_Fit[Slot]) { int ModuleTypeID = kvp.Key; int Index = -1; bool Ok = ModuleTypeIDToIndex.TryGetValue(ModuleTypeID,out Index); Debug.Assert(Ok && Index > 0); ModuleDescription MD = ModuleDescriptions[Index]; if (MD.m_ShipTypeID == m_ShipTypeID) { if (MD.m_Effects.ContainsKey(LAYER.NONE)) { foreach (KeyValuePair <EFFECT,Dictionary <ACTIVE,Tuple <float,int> > > effect in MD.m_Effects[LAYER.NONE]) { if (effect.Value.ContainsKey(ACTIVE.PASSIVE)) { switch (effect.Key) { case EFFECT.HIGH_SLOTS: HS += (uint)effect.Value[ACTIVE.PASSIVE].Item1; break; case EFFECT.MEDIUM_SLOTS: MS += (uint)effect.Value[ACTIVE.PASSIVE].Item1; break; case EFFECT.LOW_SLOTS: LS += (uint)effect.Value[ACTIVE.PASSIVE].Item1; break; } } } } } break; // only process first module. If there is more than one, fit is invalid anyway. } } m_Slots[SLOT.HIGH] = HS; m_Slots[SLOT.MEDIUM] = MS; m_Slots[SLOT.LOW] = LS; } else { m_Slots[SLOT.HIGH] = 8; m_Slots[SLOT.MEDIUM] = 8; m_Slots[SLOT.LOW] = 8; } } }
/// <summary> /// Calculates the initial ship scale values, based on the player selection. /// </summary> /// <param name="selection">Current player selection.</param> /// <returns>Dictionary containing an Scale value for each ship.</returns> IDictionary <ShipDescription, Vector2> GetDefaultScales(ShipDescription selection) { return(_ships.ToDictionary(i => i, i => i == selection ? new Vector2(2) : Vector2.One)); }