示例#1
0
    public bool TakeDamage(DamageData damage)
    {
        Defenses.ModDamage(damage);

        if (damage.Amount <= 0)
        {
            return(false);
        }

        Health.TakeDamage(damage.Amount);
        Debug.Log(Name + " took " + damage.Amount + " damage!");
        Debug.Log(Name + " has " + HealthRemaining + " health left!");

        if (HealthRemaining <= 0)
        {
            Debug.Log(Name + " Died!");
            SpriteRenderer.color = Color.black;
            this.PostNotification(Notifications.ACTOR_LEFT_POINT, Position);
            IsDead = true;
            SpriteRenderer.sortingLayerName = "Actors";
            FacingIndicator.SetActive(false);
            if (BattleController.Instance.Enemy.Pawns.Contains(this))
            {
                BattleController.Instance.Enemy.Pawns.Remove(this);
            }
        }


        return(true);
    }
示例#2
0
    public string GetRandomDefense(string rarity)
    {
        if (Defenses.ContainsKey(rarity))
        {
            if (Defenses[rarity].Count > 0)
            {
                int i = Random.Range(0, Defenses[rarity].Count);
                return(Defenses[rarity][i]);
            }
        }

        return(string.Empty);
    }
示例#3
0
        public void DefenseCoverageTest()
        {
            const int InitialDefenseCount = 100;

            Star star = new Star();

            star.DefenseType = "Neutron";
            star.Defenses    = InitialDefenseCount;

            Defenses.ComputeDefenseCoverage(star);

            Assert.AreEqual(0.9791, Defenses.PopulationCoverage, 0.001);
            Assert.AreEqual(0.8524, Defenses.SmartBombCoverage, 0.001);
        }
示例#4
0
        public void BombingEffect()
        {
            const int InitialColonistCount = 10000;
            const int InitialDefenseCount  = 100;

            Star star = new Star();

            star.DefenseType = "Neutron";
            star.Defenses    = InitialDefenseCount;
            star.Colonists   = InitialColonistCount;

            Defenses.ComputeDefenseCoverage(star);

            // In line with the example in the FAQ bomb with 10 Cherry bombs and 5 M70s

            Bomb totalBombs = new Bomb();

            const int CherryBombCount = 10;

            totalBombs.PopKill       += 2.5 * CherryBombCount;
            totalBombs.Installations += 10 * CherryBombCount;
            totalBombs.MinimumKill   += 300 * CherryBombCount;

            const int M70BombCount = 5;

            totalBombs.PopKill       += 1.2 * M70BombCount;
            totalBombs.Installations += 6 * M70BombCount;
            totalBombs.MinimumKill   += 300 * M70BombCount;

            // Just verify the algorithm, not the whole routine

            double killFactor     = totalBombs.PopKill / 100;
            double defenseFactor  = 1.0 - Defenses.PopulationCoverage;
            double populationKill = killFactor * defenseFactor;
            double killed         = (double)star.Colonists * populationKill;

            double minKilled = totalBombs.MinimumKill * (1 - Defenses.PopulationCoverage);

            int dead = (int)Math.Max(killed, minKilled);

            Assert.AreEqual(0.006448, populationKill, 0.01);
            Assert.AreEqual(64.48, killed, 1);
            Assert.AreEqual(94, minKilled, 1);
            Assert.AreEqual(94, dead, 1);
        }
示例#5
0
    private void Awake()
    {
        defs     = this.GetComponent <Defenses>();
        inter    = this.GetComponent <Interactables>();
        wave     = this.GetComponent <WaveController>();
        santa    = FindObjectOfType <Santa>();
        cam      = FindObjectOfType <Camera>();
        building = GameObject.FindGameObjectWithTag("Building").GetComponent <Building>();
        if (instance != null && instance != this)
        {
            // Destroy(this.gameObject);
            //temp TODO REPLACE to enable quick restart
            Destroy(instance.gameObject);
        }

        instance = this;
        DontDestroyOnLoad(this.gameObject);

        wave.LoadNextWave();
    }
示例#6
0
    public void initAttackDefend(string shape)
    {
        if (transform.position.x > 0)
        {
            //assume player 2
            attackKey = KeyCode.RightControl;
            defendKey = KeyCode.Keypad0;
        }
        else
        {
            //asume player 1
            attackKey = KeyCode.LeftShift;
            defendKey = KeyCode.Space;
        }

        switch (shape)
        {
        case "C":
            attack  = Attacks.Bomb;
            defense = Defenses.Phaseout;
            break;

        case "S":
            attack  = Attacks.Bullet;
            defense = Defenses.Wall;
            break;

        case "T":
            attack  = Attacks.Charge;
            defense = Defenses.Heal;
            break;

        default:
            break;
        }
    }
示例#7
0
 // Use this for initialization
 void Start()
 {
     defenses   = player.GetComponent <Defenses>();
     healthText = GetComponent <Text>();
 }
示例#8
0
        /// <Summary>
        /// Update all the fields in the planet Detail display.
        /// </Summary>
        private void UpdateFields()
        {
            if (selectedStar == null)
            {
                return;
            }

            productionQueue.Populate(selectedStar);

            Defenses.ComputeDefenseCoverage(selectedStar);

            defenseType.Text     = selectedStar.DefenseType;
            defenses.Text        = selectedStar.Defenses.ToString(System.Globalization.CultureInfo.InvariantCulture);
            defenseCoverage.Text = Defenses.SummaryCoverage.ToString(System.Globalization.CultureInfo.InvariantCulture);

            factories.Text = selectedStar.Factories.ToString(System.Globalization.CultureInfo.InvariantCulture)
                             + " of " +
                             selectedStar.GetOperableFactories().ToString(System.Globalization.CultureInfo.InvariantCulture);
            mines.Text = selectedStar.Mines.ToString(System.Globalization.CultureInfo.InvariantCulture)
                         + " of " + selectedStar.GetOperableMines().ToString(System.Globalization.CultureInfo.InvariantCulture);
            population.Text = selectedStar.Colonists.ToString(System.Globalization.CultureInfo.InvariantCulture);

            resourceDisplay.ResourceRate = selectedStar.GetResourceRate();

            if (selectedStar.OnlyLeftover == false)
            {
                resourceDisplay.ResearchBudget = empireState.ResearchBudget;
            }
            else
            {
                // We treat Stars contributing only leftover resources as having
                // a 0% budget allocation.

                resourceDisplay.ResearchBudget = 0;
            }

            resourceDisplay.Value = selectedStar.ResourcesOnHand;

            scannerRange.Text = selectedStar.ScanRange.ToString(System.Globalization.CultureInfo.InvariantCulture);
            scannerType.Text  = selectedStar.ScannerType;

            if (selectedStar.Starbase == null)
            {
                starbasePanel.Text    = "No Starbase";
                starbasePanel.Enabled = false;
            }
            else
            {
                Fleet starbase = selectedStar.Starbase;
                starbaseArmor.Text    = starbase.TotalArmorStrength.ToString(System.Globalization.CultureInfo.InvariantCulture);
                starbaseCapacity.Text =
                    starbase.TotalDockCapacity.ToString(System.Globalization.CultureInfo.InvariantCulture);
                starbaseDamage.Text   = "0";
                starbasePanel.Enabled = true;
                starbasePanel.Text    = starbase.Name;
                starbaseShields.Text  = starbase.TotalShieldStrength.ToString();

                massDriverType.Text        = "None";
                massDriverDestination.Text = "None";
                targetButton.Enabled       = false;
            }

            List <string> fleetnames = new List <string>();

            fleetsInOrbit = new Dictionary <string, Fleet>();
            foreach (Fleet fleet in empireState.OwnedFleets.Values)
            {
                if (fleet.InOrbit != null && fleet.InOrbit.Name == selectedStar.Name && !fleet.IsStarbase)
                {
                    fleetnames.Add(fleet.Name);
                    fleetsInOrbit[fleet.Name] = fleet;
                }
            }
            fleetnames.Sort();
            comboFleetsInOrbit.Items.Clear();
            bool haveFleets = fleetnames.Count > 0;

            if (haveFleets)
            {
                comboFleetsInOrbit.Items.AddRange(fleetnames.ToArray());
                comboFleetsInOrbit.SelectedIndex = 0;
            }
            buttonGoto.Enabled = haveFleets;
            buttonGoto.Enabled = haveFleets;
        }
示例#9
0
    void OnGUI()
    {
        //Use PreExisting Prefab
        /*
        if(isEdit)
        {
            newTitle = newUnit.title;
            newName = newUnit.title;
            //
            newHealth = newUnit.health;
            newSpeed = newUnit.speed;
            newDefenseType = newUnit.defenseType;
            newDefenseRating = newUnit.defenseRating;
            newSprite = newUnit.sprite;
            newAnimator = newUnit.animator;
            isEdit = false;
        }
        */

        prefabType = (PrefabTypes)EditorGUILayout.EnumPopup (prefabType);
        EditorGUILayout.Space ();

        switch (prefabType)
        {
        case PrefabTypes.Tower:
            type = "Tower";
            isUnit = false;
            /*hasSecondAtk = true;
            atk2IsActive = false;
            canMine = true;
            mineIsActive = true;*/
            break;
        case PrefabTypes.Unit:
            EditorGUILayout.BeginHorizontal ();
            unitType = (UnitTypes)EditorGUILayout.EnumPopup (unitType);
            type = unitType.ToString ();
            EditorGUILayout.Space ();
            EditorGUILayout.EndHorizontal ();
            EditorGUILayout.Space ();

            isUnit = true;
            /*hasSecondAtk = false;
            atk2IsActive = false;
            canMine = false;
            mineIsActive = false;*/
            break;
        }

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 0;
        EditorGUILayout.LabelField ("Title: ", GUILayout.Width (35));
        newTitle = EditorGUILayout.TextField (newTitle, GUILayout.Width (200), GUILayout.ExpandWidth(true));
        EditorGUILayout.LabelField ("Unique:", GUILayout.Width (50), GUILayout.ExpandWidth(false));
        isUnique = EditorGUILayout.Toggle(isUnique, GUILayout.Width (10), GUILayout.ExpandWidth(false));
        EditorGUILayout.Space ();
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.Space ();

        if (isUnique)
        {
            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 1;
            EditorGUILayout.LabelField ("Name: ", GUILayout.Width (60));
            newName = EditorGUILayout.TextField (newName,GUILayout.Width (200), GUILayout.ExpandWidth(true));
            EditorGUILayout.EndHorizontal ();
            EditorGUI.indentLevel = 0;
        }
        else
        {
            newName = newTitle;
        }

        EditorGUILayout.Space ();
        newSprite = (Sprite)EditorGUILayout.ObjectField ("Sprite: ", newSprite, typeof(Sprite), true);
        EditorGUILayout.Space ();

        //Animator???
        newAnimator = (Animator)EditorGUILayout.ObjectField ("Animator: ", newAnimator, typeof(Animator), true);
        EditorGUILayout.Space ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 1;
        EditorGUILayout.LabelField ("Health: ", GUILayout.Width (80));
        newHealth = EditorGUILayout.IntField (newHealth);
        EditorGUILayout.Space ();
        if (isUnit)
        {
            EditorGUILayout.LabelField ("Speed:", GUILayout.Width (80));
            newSpeed = EditorGUILayout.FloatField (newSpeed);
            EditorGUILayout.Space ();
        }
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.Space ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 1;
        EditorGUILayout.LabelField ("Defense: ", GUILayout.Width (80));
        newDefenseType = (Defenses)EditorGUILayout.EnumPopup (newDefenseType, GUILayout.Width (100));
        //EditorGUILayout.Space ();
        EditorGUILayout.LabelField ("Rating:", GUILayout.Width (60));
        newDefenseRating = EditorGUILayout.FloatField (newDefenseRating, GUILayout.Width (40));
        EditorGUILayout.Space ();
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.Space ();
        EditorGUILayout.Space ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 0;
        EditorGUILayout.LabelField ("Attack :", GUILayout.Width (150));
        EditorGUILayout.Space ();
        atk1IsActive = EditorGUILayout.Toggle (atk1IsActive, GUILayout.Width (30));
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 1;
        EditorGUILayout.LabelField ("Object: ", GUILayout.Width (80));
        newAttack1Projectile = (GameObject)EditorGUILayout.ObjectField (newAttack1Projectile, typeof(GameObject), true);//, GUILayout.Width(100));
        EditorGUILayout.LabelField ("Damage: ", GUILayout.Width(80));
        atk1Damage = EditorGUILayout.FloatField (atk1Damage);
        EditorGUILayout.EndHorizontal ();

        atk1Type = (AttackTypes)EditorGUILayout.EnumPopup("Type: ", atk1Type);

        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.LabelField ("Range: ", GUILayout.Width (80));
        atk1Range = EditorGUILayout.FloatField (atk1Range);
        EditorGUILayout.LabelField ("CoolDown: ",GUILayout.Width (80));
        atk1CD = EditorGUILayout.FloatField (atk1CD);
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.LabelField ("Accuracy: ", GUILayout.Width (80));
        atk1Accuracy = EditorGUILayout.FloatField (atk1Accuracy);
        EditorGUILayout.LabelField ("Speed: ", GUILayout.Width (80));
        atk1Speed = EditorGUILayout.FloatField (atk1Speed);
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.Space ();
        hasSecondAtk = EditorGUILayout.Toggle ("Has Second Attack: ", hasSecondAtk);
        EditorGUILayout.EndHorizontal ();
        EditorGUILayout.Space ();
        EditorGUILayout.Space ();

        if(hasSecondAtk)
        {
            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 0;
            EditorGUILayout.LabelField ("Attack 2 :", GUILayout.Width (150));
            EditorGUILayout.Space ();
            atk2IsActive = EditorGUILayout.Toggle (atk2IsActive, GUILayout.Width (30));
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 1;
            EditorGUILayout.LabelField ("Object: ", GUILayout.Width (80));
            newAttack2Projectile = (GameObject)EditorGUILayout.ObjectField (newAttack1Projectile, typeof(GameObject), true);
            EditorGUILayout.LabelField ("Damage: ", GUILayout.Width(80));
            atk2Damage = EditorGUILayout.FloatField (atk1Damage);
            EditorGUILayout.EndHorizontal ();

            atk2Type = (AttackTypes)EditorGUILayout.EnumPopup ("Type: ", atk2Type);

            EditorGUILayout.BeginHorizontal ();
            EditorGUILayout.LabelField ("Range: ", GUILayout.Width(80));
            atk2Range = EditorGUILayout.FloatField (atk2Range);
            EditorGUILayout.LabelField ("CoolDown: ", GUILayout.Width (80));
            atk2CD = EditorGUILayout.FloatField (atk2CD);
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUILayout.LabelField ("Accuracy: ", GUILayout.Width (80));
            atk2Accuracy = EditorGUILayout.FloatField (atk2Accuracy);
            EditorGUILayout.LabelField ("Speed: ", GUILayout.Width (80));
            atk2Speed = EditorGUILayout.FloatField (atk2Speed);
            EditorGUILayout.EndHorizontal ();

            atk2OnGC = EditorGUILayout.Toggle ("On GC: ", atk2OnGC);
        }

        EditorGUI.indentLevel = 1;
        EditorGUILayout.Space ();
        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.Space ();
        canMine = EditorGUILayout.Toggle ("Can Mine: ", canMine);
        EditorGUILayout.EndHorizontal ();
        EditorGUILayout.Space ();

        if(canMine)
        {
            ///Needs to Include:
            /// Mining Range, Mining Cooldown, Mining Efficiency x4
            ///
            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel= 0;
            EditorGUILayout.LabelField ("Mining: ", GUILayout.Width (150));
            EditorGUILayout.Space ();
            mineIsActive = EditorGUILayout.Toggle (mineIsActive, GUILayout.Width (30));
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 1;
            EditorGUILayout.LabelField ("Range: ", GUILayout.Width (80));
            mineRange = EditorGUILayout.FloatField (mineRange);
            EditorGUILayout.LabelField ("CoolDown: ", GUILayout.Width (80));
            mineCD = EditorGUILayout.FloatField (mineCD);
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 2;
            EditorGUILayout.LabelField ("Iron:    ", GUILayout.Width (80));
            mineEffIron = EditorGUILayout.FloatField (mineEffIron);
            EditorGUILayout.LabelField ("Lode:    ", GUILayout.Width (80));
            mineEffLode = EditorGUILayout.FloatField (mineEffLode);
            EditorGUILayout.Space ();
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUILayout.LabelField ("Brin:    ", GUILayout.Width (80));
            mineEffBrin = EditorGUILayout.FloatField (mineEffBrin);
            EditorGUILayout.LabelField ("Mithril: ", GUILayout.Width (80));
            mineEffMith = EditorGUILayout.FloatField (mineEffMith);
            EditorGUILayout.Space ();
            EditorGUILayout.EndHorizontal ();
        }

        EditorGUILayout.Space ();

        if(GUILayout.Button ("Register " + type))
        {
            //Build a New Prefab
            GameObject newUnit = (GameObject.Find ("UnitPrefab"));
            newUnit.name = newName;
            string folder = "Tower";
            if(isUnit)
            {
                folder = "Units";
            }
            string path = AssetDatabase.GenerateUniqueAssetPath ("Assets/Prefabs/" + folder + "/" + newUnit.name + ".prefab");
            PrefabUtility.CreatePrefab (path, newUnit);

            //if(size == medium)
            var capsule = newUnit.GetComponent<CapsuleCollider>();

            capsule.radius = 1;
            capsule.height = 4;

            var body = newUnit.AddComponent<BodyScript>();

            body.title = newTitle;
            //body.speed = newSpeed;
            body.maxHealth = newHealth;
            body.health = newHealth;
            body.defenseRating = newDefenseRating;
            body.defenseType = newDefenseType.ToString ();

            if(isUnit)
            {
                //var seeker = newUnit.AddComponent<Seeker>();

                var controller = newUnit.AddComponent<CharacterController>();

                controller.radius = 0;
                controller.height = 0;

                var walker = newUnit.AddComponent<WalkScript>();
                walker.baseSpeed = newSpeed;

                var funnelMod = newUnit.AddComponent<Pathfinding.FunnelModifier>();
                //funnelMod.priority = 2;
                var alternMod = newUnit.AddComponent<Pathfinding.AlternativePath>();
                //alternMod.priority = 3;
            }

            var attack = newUnit.AddComponent<AttackScript>();

            attack.attackIsActive = atk1IsActive;
            attack.attackProjectile = newAttack1Projectile;
            attack.attackDamage = atk1Damage;
            attack.attackType = atk1Type;
            attack.attackRange = atk1Range;
            attack.attackCooldown = atk1CD;
            attack.attackAccuracy = atk1Accuracy;
            attack.attackSpeed = atk1Speed;

            if(hasSecondAtk)
            {
                attack.attack2IsActive = atk2IsActive;
                attack.attack2Projectile = newAttack2Projectile;
                attack.attack2Damage = atk2Damage;
                attack.attack2Type = atk2Type;
                attack.attack2Range = atk2Range;
                attack.attack2Cooldown = atk2CD;
                attack.attack2Accuracy = atk2Accuracy;
                attack.attack2Speed = atk2Speed;
                attack.attack2OnGC = atk2OnGC;
            }

            if(canMine)
            {
                var mine = newUnit.AddComponent<MiningScript>();

                mine.miningRange = mineRange;
                mine.miningCooldown = mineCD;
                mine.ironMiningRate = mineEffIron;
                mine.lodestoneMiningRate = mineEffLode;
                mine.brinmistrMiningRate = mineEffBrin;
                mine.mithrilMiningRate = mineEffMith;
            }
        }
    }
示例#10
0
        /// ----------------------------------------------------------------------------
        /// <Summary>
        /// Populate the display. We use unbound population because some of the fields
        /// need a little logic to decode (we don't just have a bunch of strings).
        /// </Summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ----------------------------------------------------------------------------
        private void OnLoad(object sender, EventArgs e)
        {
            const int NumColumns = 12;

            this.planetGridView.Columns[8].Name = "Minerals";
            this.planetGridView.AutoSize        = true;

            foreach (Star report in empireState.OwnedStars.Values)
            {
                if (report.Owner == empireState.Id)
                {
                    string[] row = new string[NumColumns];

                    string starbase = "-";
                    if (report.Starbase != null)
                    {
                        starbase = report.Starbase.Name;
                    }

                    int i = 0;
                    row[i++] = report.Name;
                    row[i++] = starbase;
                    row[i++] = report.Colonists.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    row[i++] = report.Capacity(empireState.Race).ToString(System.Globalization.CultureInfo.InvariantCulture);
                    row[i++] = Math.Ceiling(empireState.Race.HabValue(report) * 100).ToString(System.Globalization.CultureInfo.InvariantCulture);
                    row[i++] = report.Mines.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    row[i++] = report.Factories.ToString(System.Globalization.CultureInfo.InvariantCulture);

                    Defenses.ComputeDefenseCoverage(report);
                    row[i++] = Defenses.SummaryCoverage.ToString(System.Globalization.CultureInfo.InvariantCulture);

                    Nova.Common.Resources resources = report.ResourcesOnHand;
                    StringBuilder         text      = new StringBuilder();

                    text.AppendFormat(
                        "{0} {1} {2}",
                        resources.Ironium,
                        resources.Boranium,
                        resources.Germanium);

                    string energy = ((int)resources.Energy).ToString(System.Globalization.CultureInfo.InvariantCulture);

                    row[i++] = text.ToString();

                    resources = report.MineralConcentration;
                    text      = new StringBuilder();

                    text.AppendFormat(
                        "{0} {1} {2}",
                        resources.Ironium,
                        resources.Boranium,
                        resources.Germanium);
                    row[i++] = text.ToString();
                    row[i++] = energy;

                    this.planetGridView.Rows.Add(row);
                }
            }

            this.planetGridView.AutoResizeColumns();
        }
示例#11
0
        public bool Perform(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
        {
            Star star = (Star)target;

            // The troops are now committed to take the star or die trying
            int troops = fleet.Cargo.ColonistNumbers;

            fleet.Cargo.ColonistsInKilotons = 0;

            // Set up the message recipients before the star (potentially) changes hands.
            Message wolfMessage = new Message();

            wolfMessage.Audience = fleet.Owner;
            Message lambMessage = new Message();

            lambMessage.Audience = star.Owner;

            // Take into account the Defenses
            Defenses.ComputeDefenseCoverage(star);
            int troopsOnGround = (int)(troops * (1.0 - Defenses.InvasionCoverage));

            // Apply defender and attacker bonuses
            double attackerBonus = 1.1;

            if (sender.Race.HasTrait("WM"))
            {
                attackerBonus *= 1.5;
            }

            double defenderBonus = 1.0;

            if (receiver.Race.HasTrait("IS"))
            {
                defenderBonus *= 2.0;
            }

            int defenderStrength = (int)(star.Colonists * defenderBonus);
            int attackerStrength = (int)(troopsOnGround * attackerBonus);
            int survivorStrength = defenderStrength - attackerStrength; // will be negative if attacker wins

            string messageText = fleet.Owner + "'s fleet " + fleet.Name + " attacked " +
                                 star.Name + " with " + troops + " troops. ";

            if (survivorStrength > 0)
            {
                // defenders win
                int remainingDefenders = (int)(survivorStrength / defenderBonus);
                remainingDefenders = Math.Max(remainingDefenders, Global.ColonistsPerKiloton);
                int defendersKilled = star.Colonists - remainingDefenders;
                star.Colonists = remainingDefenders;

                messageText += "The attackers were slain but "
                               + defendersKilled +
                               " colonists were killed in the attack.";

                wolfMessage.Text = messageText;
                Messages.Add(wolfMessage);

                lambMessage.Text = messageText;
                Messages.Add(lambMessage);
            }
            else if (survivorStrength < 0)
            {
                // attacker wins
                star.ManufacturingQueue.Clear();
                int remainingAttackers = (int)(-survivorStrength / attackerBonus);
                remainingAttackers = Math.Max(remainingAttackers, Global.ColonistsPerKiloton);
                int attackersKilled = troops - remainingAttackers;
                star.Colonists = remainingAttackers;

                receiver.OwnedStars.Remove(star);
                star.Owner = fleet.Owner;
                sender.OwnedStars.Add(star);
                sender.StarReports[star.Key].Update(star, ScanLevel.Owned, sender.TurnYear);

                messageText += "The defenders were slain but "
                               + attackersKilled +
                               " troops were killed in the attack.";

                wolfMessage.Text = messageText;
                Messages.Add(wolfMessage);

                lambMessage.Text = messageText;
                Messages.Add(lambMessage);
            }
            else
            {
                // no survivors!
                messageText += "Both sides fought to the last and none were left to claim the planet!";

                wolfMessage.Text = messageText;
                Messages.Add(wolfMessage);

                lambMessage.Text = messageText;
                Messages.Add(lambMessage);

                // clear out the colony
                star.ManufacturingQueue.Clear();
                star.Colonists = 0;
                star.Mines     = 0;
                star.Factories = 0;
                star.Owner     = Global.Nobody;
            }

            return(true);
        }
示例#12
0
        /// <summary>
        /// See if we can bomb the planet.
        /// </summary>
        /// <param name="fleet">Potential bombing fleet.</param>
        /// <param name="star">Potential bombing target.</param>
        public void Bomb(Fleet fleet, Star star)
        {
            // The fleet is in orbit around a planet. If it has no colonists or
            // has a starbase then to do nothing here (we'll leave anything else
            // to the battle engine.

            if (star.Colonists == 0 || star.Starbase != null)
            {
                return;
            }

            // See if this is an enemy planet. If not, leave it alone.

            if (!serverState.AllEmpires[fleet.Owner].IsEnemy(star.Owner))
            {
                return;
            }

            // If we don't have bombers then there is nothing more to do here

            if (fleet.HasBombers == false)
            {
                return;
            }

            // Get the summary information
            Defenses.ComputeDefenseCoverage(star);
            Bomb totalBombs = fleet.BombCapability;


            // Bomb colonists
            double killFactor     = totalBombs.PopKill / 100.0;
            double defenseFactor  = 1.0 - Defenses.PopulationCoverage;
            double populationKill = killFactor * defenseFactor;
            double killed         = (double)star.Colonists * populationKill;

            double minKilled = totalBombs.MinimumKill
                               * (1 - Defenses.PopulationCoverage);

            int dead = (int)Math.Max(killed, minKilled);

            star.Colonists -= dead;


            // Get installation details
            double totalBuildings = star.Mines + star.Factories + star.Defenses;

            double buildingKills = totalBombs.Installations * (1 - Defenses.BuildingCoverage);
            double damagePercent = buildingKills / totalBuildings;

            if (damagePercent > 1)
            {
                damagePercent = 1;
            }

            // We now have the percentage of each building type to destroy (which
            // has been clamped at a maximum of 100% (normalised so that 100% =
            // 1). Let's apply that percentage to each building type in
            // turn. First Defenses:

            // Defenses
            int defensesDestroyed = (int)((double)star.Defenses * damagePercent);

            star.Defenses -= defensesDestroyed;

            // Now Factories
            double factories          = (double)star.Factories;
            int    factoriesDestroyed = (int)(factories * damagePercent);

            star.Factories -= factoriesDestroyed;

            // Now Mines
            double mines          = (double)star.Mines;
            int    minesDestroyed = (int)(mines * damagePercent);

            star.Mines -= minesDestroyed;

            // Build message


            string messageText = "Fleet " + fleet.Name + " has bombed " + star.Name;


            if (star.Colonists > 0)
            {
                messageText += " killing " + dead.ToString(System.Globalization.CultureInfo.InvariantCulture) +
                               " of the colonists and destroying " +
                               defensesDestroyed + " defenses, " +
                               factoriesDestroyed + " factories, and " +
                               minesDestroyed + " mines.";
            }
            else
            {
                messageText += " killing all of the colonists.";

                // clear out the colony
                star.ManufacturingQueue.Clear();
                star.Colonists = 0;
                star.Mines     = 0;
                star.Factories = 0;
                star.Owner     = Global.Nobody;
            }

            Message lamb = new Message();

            lamb.Text     = messageText;
            lamb.Audience = star.Owner;
            serverState.AllMessages.Add(lamb);

            Message wolf = new Message();

            wolf.Text     = messageText;
            wolf.Audience = fleet.Owner;
            serverState.AllMessages.Add(wolf);
        }
示例#13
0
 public bool IsResistant(DamageType damageType)
 {
     return(Defenses.Any(def => def.IsResistant(damageType)));
 }
示例#14
0
 private bool IsImmune(DamageType damageType)
 {
     return(Defenses.Any(def => def.IsImmune(damageType)));
 }