コード例 #1
0
    void ChangeCount(QuadrantTypes QT, int Num)
    {
        switch (QT)
        {
        case QuadrantTypes.Fore:
        {
            CountFore += Num;
            break;
        }

        case QuadrantTypes.Aft:
        {
            CountAft += Num;
            break;
        }

        case QuadrantTypes.Port:
        {
            CountPort += Num;
            break;
        }

        case QuadrantTypes.Starboard:
        {
            CountStarboard += Num;
            break;
        }

        case QuadrantTypes.Center:
        {
            CountCenter += Num;
            break;
        }
        }
    }
コード例 #2
0
    // Use this for initialization
    public ShipQuadrant(ShipData SD, ShipDesignQuadData quadData, QuadrantTypes quadType)
    {
        parentShip = SD;

        foreach (SavedWeapon weapon in quadData.Weapons)
        {
            QuadrantTypes firingDirection = quadType;

            if (weapon.weapon.AlwaysForward)
            {
                if (weapon.rotation == 0f)
                {
                    firingDirection = QuadrantTypes.Fore;
                }
                else if (weapon.rotation == 90f)
                {
                    firingDirection = QuadrantTypes.Starboard;
                }
                else if (weapon.rotation == 180f)
                {
                    firingDirection = QuadrantTypes.Aft;
                }
                else
                {
                    firingDirection = QuadrantTypes.Port;
                }
            }
            AttachedWeapon attachedWeapon = new AttachedWeapon(weapon.weapon);
            attachedWeapon.SetFiringQuadrant(firingDirection);
            Weapons.Add(attachedWeapon);
        }

        health          = quadData.Health;
        healthMax       = quadData.Health;
        armorHealth     = quadData.ArmorHealth;
        armorHealthMax  = quadData.ArmorHealth;
        armorRating     = quadData.ArmorRating;
        shieldHealth    = quadData.ShieldHealth;
        shieldHealthMax = quadData.ShieldHealth;
        shieldRating    = quadData.ShieldRating;
        shieldRecharge  = quadData.ShieldRechargeRate;
        shieldDelay     = quadData.ShieldRechargeDelay;
        engineThrust    = quadData.EngineThrust;
        engineTurn      = quadData.EngineTurn;
    }
コード例 #3
0
 void CheckShieldHit(Vector3 point, QuadrantTypes quad)
 {
     if (inCloakingState())
     {
         return;
     }
     else if (shipData.HasCenterShields())
     {
         ShieldHit(point);
     }
     else
     {
         if (quad == QuadrantTypes.Fore)
         {
             if (GetShipData().HasForeShields())
             {
                 ShieldHit(point);
             }
         }
         else if (quad == QuadrantTypes.Aft)
         {
             if (GetShipData().HasAftShields())
             {
                 ShieldHit(point);
             }
         }
         else if (quad == QuadrantTypes.Port)
         {
             if (GetShipData().HasPortShields())
             {
                 ShieldHit(point);
             }
         }
         else
         {
             if (GetShipData().HasStarboardShields())
             {
                 ShieldHit(point);
             }
         }
     }
 }
コード例 #4
0
    public void TakeDamage(AttachedWeapon weapon, Vector3 hitPoint, Vector3 source, float damage, bool ignoreShields, bool ignoreArmor, bool ignoreArmorRating)
    {
        if (!ValidMoveOrder && Target == null)
        {
            SetNewTarget(weapon.GetParentUnit(), true);
        }

        Vector2 direction = new Vector2(source.x - transform.position.x, source.z - transform.position.z);

        if (inCloakingState())
        {
            ignoreShields = true;
        }

        QuadrantTypes quadHit = GetQuadrantDirection(direction);

        if (!ignoreShields)
        {
            CheckShieldHit(hitPoint, quadHit);
        }

        shipData.TakeDamage(weapon, hitPoint, damage, quadHit, ignoreShields, ignoreArmor, ignoreArmorRating);
    }
コード例 #5
0
 public Vector3[] GetRandomHardpoints(Weapon weapon, QuadrantTypes quad)
 {
     if (quad == QuadrantTypes.Fore && ForeHardPointSets.Length > 0)
     {
         return(GetRandomHardpointsFromSet(weapon, ForeHardPointSets));
     }
     else if (quad == QuadrantTypes.Aft && AftHardPointSets.Length > 0)
     {
         return(GetRandomHardpointsFromSet(weapon, AftHardPointSets));
     }
     else if (quad == QuadrantTypes.Port && PortHardPointSets.Length > 0)
     {
         return(GetRandomHardpointsFromSet(weapon, PortHardPointSets));
     }
     else if (quad == QuadrantTypes.Starboard && StarboardHardPointSets.Length > 0)
     {
         return(GetRandomHardpointsFromSet(weapon, StarboardHardPointSets));
     }
     else
     {
         return(GetZeroHardPoints());
     }
 }
コード例 #6
0
 public void SetFiringQuadrant(QuadrantTypes direction)
 {
     FiringQuadrant = direction;
 }
コード例 #7
0
ファイル: ShipData.cs プロジェクト: regstar/OpenSpace4x
    public ShipData(ShipDesignData shipDesignData)
    {
        designData  = shipDesignData;
        DisplayName = designData.Design.Name;

        ForeSection      = new ShipQuadrant(this, designData.ForeQuadrant, QuadrantTypes.Fore);
        AftSection       = new ShipQuadrant(this, designData.AftQuadrant, QuadrantTypes.Aft);
        StarboardSection = new ShipQuadrant(this, designData.StarboardQuadrant, QuadrantTypes.Starboard);
        PortSection      = new ShipQuadrant(this, designData.PortQuadrant, QuadrantTypes.Port);
        CenterSection    = new ShipQuadrant(this, designData.CenterQuadrant, QuadrantTypes.Center);

        //Add Fighters
        foreach (KeyValuePair <FighterDefinition, int> keyVal in shipDesignData.Fighters)
        {
            Fighters.Add(new FighterComplement(keyVal.Key, keyVal.Value));
        }
        foreach (KeyValuePair <FighterDefinition, int> keyVal in shipDesignData.HeavyFighters)
        {
            HeavyFighters.Add(new FighterComplement(keyVal.Key, keyVal.Value));
        }
        foreach (KeyValuePair <FighterDefinition, int> keyVal in shipDesignData.AssaultPods)
        {
            AssaultPods.Add(new FighterComplement(keyVal.Key, keyVal.Value));
        }

        fuelMax         = designData.Fuel;
        fuel            = fuelMax;
        ammo            = designData.Ammo;
        ammoMax         = designData.Ammo;
        power           = designData.PowerStorage;
        powerMax        = designData.PowerStorage;
        crew            = designData.Crew;
        crewMax         = designData.Crew;
        supplies        = designData.Supplies;
        suppliesMax     = designData.Supplies;
        troops          = designData.Troops;
        troopsMax       = designData.Troops;
        commandPoints   = designData.CommandPoints;
        mass            = designData.Mass;
        powerGenerated  = designData.PowerGenerated;
        FTLSpeed        = designData.FTLSpeed;
        research        = designData.Research;
        mining          = designData.Mining;
        repair          = designData.Repair;
        ammoGenerated   = designData.AmmoGenerated;
        transporter     = designData.Transporter;
        medical         = designData.Medical;
        cloakingPower   = designData.CloakingPower;
        stealth         = designData.Stealth;
        boardingDefense = designData.BoardingDefense;
        colonies        = designData.Colonies;
        diplomacy       = designData.Diplomacy;
        sensor          = designData.Sensor;
        longRangeSensor = designData.LongRangeSensor;
        advancedSensor  = designData.AdvancedSensor;

        CalculateEngines();
        AttackDirection = designData.Design.attackDirection;
        AttackStyle     = designData.Design.attackStyle;
        if (designData.Design.attackRange != -1)
        {
            attackRange = designData.Design.attackRange;
        }
        else
        {
            attackRange = designData.maxRange;
        }

        SetCrewEffeciency();
    }
コード例 #8
0
ファイル: ShipData.cs プロジェクト: regstar/OpenSpace4x
    public void TakeDamage(AttachedWeapon weapon, Vector3 position, float damage, QuadrantTypes quad, bool ignoreShields, bool ignoreArmor, bool ignoreArmorRating)
    {
        //Apply defense bonus
        damage -= damage * GetDefenseBonus();

        //Record damage taken
        damageTaken += damage;

        if (CurrentUnit == null)
        {
            return;
        }

        if (weapon.baseWeapon.PowerDamageModifier != 0)
        {
            power -= damage * weapon.baseWeapon.PowerDamageModifier;
            if (power < 0)
            {
                power = 0;
            }
        }

        if (weapon.baseWeapon.DamageAllQuads)
        {
            float ForeDamage      = damage / 4f;
            float PortDamage      = ForeDamage;
            float StarboardDamage = ForeDamage;
            float AftDamage       = ForeDamage;

            if (!ignoreShields)
            {
                ForeDamage      = CenterSection.TakeShieldDamage(weapon, position, ForeDamage);
                PortDamage      = CenterSection.TakeShieldDamage(weapon, position, PortDamage);
                StarboardDamage = CenterSection.TakeShieldDamage(weapon, position, StarboardDamage);
                AftDamage       = CenterSection.TakeShieldDamage(weapon, position, AftDamage);
            }

            if (!ForeSection.isDestroyed())
            {
                ForeSection.TakeDamage(weapon, position, ForeDamage, ignoreShields, ignoreArmor, ignoreArmorRating);
            }
            else
            {
                CenterSection.TakeDamage(weapon, position, ForeDamage, ignoreShields, ignoreArmor, ignoreArmorRating);
            }

            if (!Destroyed)
            {
                if (!PortSection.isDestroyed())
                {
                    PortSection.TakeDamage(weapon, position, PortDamage, ignoreShields, ignoreArmor, ignoreArmorRating);
                }
                else
                {
                    CenterSection.TakeDamage(weapon, position, PortDamage, ignoreShields, ignoreArmor, ignoreArmorRating);
                }
            }

            if (!Destroyed)
            {
                if (!StarboardSection.isDestroyed())
                {
                    StarboardSection.TakeDamage(weapon, position, StarboardDamage, ignoreShields, ignoreArmor, ignoreArmorRating);
                }
                else
                {
                    CenterSection.TakeDamage(weapon, position, StarboardDamage, ignoreShields, ignoreArmor, ignoreArmorRating);
                }
            }

            if (!Destroyed)
            {
                if (!AftSection.isDestroyed())
                {
                    AftSection.TakeDamage(weapon, position, AftDamage, ignoreShields, ignoreArmor, ignoreArmorRating);
                }
                else
                {
                    CenterSection.TakeDamage(weapon, position, AftDamage, ignoreShields, ignoreArmor, ignoreArmorRating);
                }
            }
        }
        else
        {
            //Center shield take damage first
            if (!ignoreShields)
            {
                damage = CenterSection.TakeShieldDamage(weapon, position, damage);
            }

            if (quad == QuadrantTypes.Fore && !ForeSection.isDestroyed())
            {
                ForeSection.TakeDamage(weapon, position, damage, ignoreShields, ignoreArmor, ignoreArmorRating);
            }
            else if (quad == QuadrantTypes.Aft && !AftSection.isDestroyed())
            {
                AftSection.TakeDamage(weapon, position, damage, ignoreShields, ignoreArmor, ignoreArmorRating);
            }
            else if (quad == QuadrantTypes.Port && !PortSection.isDestroyed())
            {
                PortSection.TakeDamage(weapon, position, damage, ignoreShields, ignoreArmor, ignoreArmorRating);
            }
            else if (quad == QuadrantTypes.Starboard && !StarboardSection.isDestroyed())
            {
                StarboardSection.TakeDamage(weapon, position, damage, ignoreShields, ignoreArmor, ignoreArmorRating);
            }
            else
            {
                CenterSection.TakeDamage(weapon, position, damage, ignoreShields, ignoreArmor, ignoreArmorRating);
            }
        }
    }
コード例 #9
0
    // Use this for initialization
    void Start()
    {
        //Force Camera to correct position
        Camera.main.transform.position = new Vector3(0f, 5f, 0f);
        Camera.main.transform.rotation = Quaternion.Euler(90, 0, 0);

        Indent = Screen.width * 0.15f;
        //Build all of the rectangles for slots
        Slots.Clear();
        for (int x = (int)Indent; x < Screen.width - 16; x += 16)
        {
            for (int y = 0; y < Screen.height - 16; y += 16)
            {
                Slots.Add(new Slot(new Rect(x, y, 16, 16)));
            }
        }

        if (loadLayout != null)
        {
            LayoutName = loadLayout.name;
            ShipSlotLayout loadedLayout = (ShipSlotLayout) new XmlSerializer(typeof(ShipSlotLayout)).Deserialize(new StringReader(loadLayout.text));

            foreach (Rect foreslot in loadedLayout.ForeSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Fore;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
            foreach (Rect foreslot in loadedLayout.AftSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Aft;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
            foreach (Rect foreslot in loadedLayout.PortSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Port;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
            foreach (Rect foreslot in loadedLayout.StarboardSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Starboard;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
            foreach (Rect foreslot in loadedLayout.CenterSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Center;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
        }

        selectedQuadrantType   = QuadrantTypes.Fore;
        QuadrantTypeButtonRect = new Rect(Screen.width * 0.05f, 0f, 100f, 40f);
        ResestButtonRect       = new Rect(QuadrantTypeButtonRect.x, QuadrantTypeButtonRect.y + 60f, 100f, 40f);
        SaveButtonRect         = new Rect(ResestButtonRect.x, ResestButtonRect.y + 60f, 100f, 40f);

        NameFieldRect = new Rect(Screen.width * 0.01f, SaveButtonRect.y + 60f, Screen.width * 0.13f, 30f);

        ForeCountRect      = new Rect(ResestButtonRect.x, NameFieldRect.y + 60f, 100f, 40f);
        AftCountRect       = new Rect(ResestButtonRect.x, ForeCountRect.y + 60f, 100f, 40f);
        PortCountRect      = new Rect(ResestButtonRect.x, AftCountRect.y + 60f, 100f, 40f);
        StarboardCountRect = new Rect(ResestButtonRect.x, PortCountRect.y + 60f, 100f, 40f);
        CenterCountRect    = new Rect(ResestButtonRect.x, StarboardCountRect.y + 60f, 100f, 40f);
        TotalCountRect     = new Rect(ResestButtonRect.x, CenterCountRect.y + 60f, 100f, 40f);
    }
コード例 #10
0
    void OnGUI()
    {
        //Draw slots to screen
        foreach (Slot slot in Slots)
        {
            if (slot.Active)
            {
                switch (slot.Quadrant)
                {
                case QuadrantTypes.Fore:
                {
                    GUI.DrawTexture(slot.rect, Tex_Fore);
                    break;
                }

                case QuadrantTypes.Aft:
                {
                    GUI.DrawTexture(slot.rect, Tex_Aft);
                    break;
                }

                case QuadrantTypes.Port:
                {
                    GUI.DrawTexture(slot.rect, Tex_Port);
                    break;
                }

                case QuadrantTypes.Starboard:
                {
                    GUI.DrawTexture(slot.rect, Tex_Starboard);
                    break;
                }

                case QuadrantTypes.Center:
                {
                    GUI.DrawTexture(slot.rect, Tex_Center);
                    break;
                }
                }
            }
            else
            {
                GUI.Box(slot.rect, "");
            }
        }

        //Draw slot counts
        GUI.Label(ForeCountRect, "Fore: " + CountFore.ToString());
        GUI.Label(AftCountRect, "Aft: " + CountAft.ToString());
        GUI.Label(PortCountRect, "Port: " + CountPort.ToString());
        GUI.Label(StarboardCountRect, "Starboard: " + CountStarboard.ToString());
        GUI.Label(CenterCountRect, "Center: " + CountCenter.ToString());
        GUI.Label(TotalCountRect, "Total: " + (CountFore + CountAft + CountPort + CountStarboard + CountCenter).ToString());

        //Quadrant change button
        if (GUI.Button(QuadrantTypeButtonRect, selectedQuadrantType.ToString()))
        {
            if (selectedQuadrantType == QuadrantTypes.Center)
            {
                selectedQuadrantType = QuadrantTypes.Fore;
            }
            else
            {
                selectedQuadrantType++;
            }
        }
        //Reset Button
        if (GUI.Button(ResestButtonRect, "Reset"))
        {
            foreach (Slot slot in Slots)
            {
                slot.Active = false;
            }
            CountFore      = 0;
            CountAft       = 0;
            CountPort      = 0;
            CountStarboard = 0;
            CountCenter    = 0;
        }
        //Save button
        if (GUI.Button(SaveButtonRect, "Save"))
        {
            ShipSlotLayout shipSlotLayout = new ShipSlotLayout();

            foreach (Slot slot in Slots)
            {
                if (slot.Active)
                {
                    switch (slot.Quadrant)
                    {
                    case QuadrantTypes.Fore:
                    {
                        shipSlotLayout.ForeSlots.Add(slot.rect);
                        break;
                    }

                    case QuadrantTypes.Aft:
                    {
                        shipSlotLayout.AftSlots.Add(slot.rect);
                        break;
                    }

                    case QuadrantTypes.Port:
                    {
                        shipSlotLayout.PortSlots.Add(slot.rect);
                        break;
                    }

                    case QuadrantTypes.Starboard:
                    {
                        shipSlotLayout.StarboardSlots.Add(slot.rect);
                        break;
                    }

                    case QuadrantTypes.Center:
                    {
                        shipSlotLayout.CenterSlots.Add(slot.rect);
                        break;
                    }
                    }
                }
            }

            Directory.CreateDirectory(Application.dataPath + "/ShipSlotLayouts");

            string        path   = Application.dataPath + "/ShipSlotLayouts/" + LayoutName + ".xml";
            XmlSerializer Writer = new XmlSerializer(typeof(ShipSlotLayout));
            FileStream    file   = File.Create(path);
            Writer.Serialize(file, shipSlotLayout);
            file.Close();
        }

        LayoutName = GUI.TextField(NameFieldRect, LayoutName);
    }