public static void CreateGiftEvent(Empire eGifter, Empire eReceiver, int gift)
        {
            Relation relation = null;
            foreach(Relation r in eReceiver.EmpireRelations)
            {
                if (r.EmpireName == eGifter.EmpireName)
                    relation = r;
            }
            if (relation != null)
            {
                int i = gift / 512;
                if (relation.RelationPoints < 0)
                    i = (int)(i * 1.5);
                else
                    i = (int)(i * 2.5);

                if (i > 50)
                    i = 50;
                else if (i < 1)
                    i = 1;
                //Cerca se nella relazione c'è già un evento sul regalo e aggiungi punti
                foreach (Event e in relation.RelationEvents)
                {
                    if (e.Motivation == Event.EventMotivation.GIFT && e.Type == Event.EventType.POSITIVE)
                    {
                        e.AddPointsToEvent(i);
                        return;
                    }
                }
                //Altrimenti creane uno nuovo
                relation.RelationEvents.Add(new Event(Event.EventType.POSITIVE, Event.EventMotivation.GIFT, i));
            }
        }
        static void SaveEmpire(XmlWriter xw, Empire e)
        {
            xw.WriteStartElement("EMPIRE");
            xw.WriteAttributeString("NAME", e.EmpireName);
            xw.WriteAttributeString("RELIGION", e.EmpireReligion.ToString());

            // Scrivi ora i sistemi posseduti e conosciuti
            SaveKnownSystem(xw, "OWNEDSYSTEMS", e.OwnedSystems);
            SaveKnownSystem(xw, "KNOWNSYSTEMS", e.KnownSystems);

            // Relazioni con altri imperi
            SaveRelation(xw, e.EmpireRelations);

            // Flotta
            SaveFleet(xw, e.Fleet);

            xw.WriteEndElement();//Di EMPIRE
        }
        public static void CreateCommerceEvent(Empire player, Empire commerced, int prize, bool playerSell)
        {
            Relation relation = null;
            foreach (Relation r in commerced.EmpireRelations)
            {
                if (r.EmpireName == player.EmpireName)
                    relation = r;
            }
            if (relation != null)
            {
                int i = prize / 1024;
                if (relation.RelationPoints < 0)
                    i = (int)(i * 1.5);
                else
                    i = (int)(i * 2.5);

                if (playerSell)
                    i = (int)(i * 0.88);
                else
                    i = (int)(i * 1.5);

                if (i > 50)
                    i = 50;
                else if (i < 1)
                    i = 1;
                //Cerca se nella relazione c'è già un evento sul commercio e aggiungi punti
                foreach(Event e in relation.RelationEvents)
                {
                    if (e.Motivation == Event.EventMotivation.COMMERCE && e.Type == Event.EventType.POSITIVE)
                    {
                        e.AddPointsToEvent(i);
                        return;
                    }
                }
                //Altrimenti creane uno nuovo
                relation.RelationEvents.Add(new Event(Event.EventType.POSITIVE, Event.EventMotivation.COMMERCE, i));
            }
        }
        /// <summary>
        /// Metodo che crea un nuovo gioco
        /// </summary>
        public static void NewGame()
        {
            isLoading = true;
            // Crea una nuova lista e cancellala se era già stata creata in precedenza
            solarSystems = new List<SolarSystem>();
            solarSystems.Clear();
            // Fai lo stesso per gli imperi
            empires = new List<Empire>();
            empires.Clear();
            // Prendi il numero dei sistemi e degli imperi
            int systems = GameParams.starNumber;
            int numEmpires = GameParams.empireNumber;

            List<Vector3> vect = new List<Vector3>();
            for (int i = -1 * systems / 2; i < systems / 2; i++)
                for (int j = -1 * systems / 2; j < systems / 2; j++)
                    vect.Add(new Vector3(i * 32, 0, j * 32));

            vect.Remove(new Vector3(0, 0, 0));
            Random rnd = new Random();
            for (int i = 0; i < systems; i++)
            {
                int index = rnd.Next(0, vect.Count);
                Vector3 pos = vect[index];
                SolarSystem solar = new SolarSystem(pos);
                solarSystems.Add(solar);
                vect.RemoveAt(index);
            }
            vect.Clear();
            // Crea i pianeti per ogni sistema solare
            foreach (SolarSystem ss in solarSystems)
                ss.CreatePlanets();
            // Crea gli imperi
            CreateEmpires();
            //Crea il sistema solare di partenza per il giocatore
            SolarSystem startingSystem = new SolarSystem(new Vector3(0, 0, 0));
            startingSystem.IsDiscovered = true;
            startingSystem.CreatePlanets(true);
            if (GameParams.name == null)
                GameParams.name = NameGenerator.GetName();
            playerEmpire = new Empire(startingSystem, GameParams.religionType, GameParams.name);
            solarSystems.Add(startingSystem);
            foreach (Planet p in startingSystem.Planets)
                if (p.PlanetSettlement != null)
                    playerCapital = p;

            //empires.Add(playerEmpire);
            PlayerShip.Initialize(new Vector3(0, 50, 0), 1500, 500);

            isLoading = false;
        }
        /// <summary>
        /// Metodo che crea gli imperi
        /// </summary>
        private static void CreateEmpires()
        {
            Random rnd = new Random();
            // Terrascore minimo definito a partire dal numero degli imperi da creare
            int terrascore = 24;
            int empireNumber = GameParams.empireNumber;
            if (empireNumber < 150)
                terrascore = 27;
            else if (empireNumber < 125)
                terrascore = 30;

            int empireCount = 0;
            foreach(SolarSystem ss in solarSystems)
            {
                foreach(Planet p in ss.Planets)
                {
                    // Se il terrascore va bene e non si sono creati abbastanza imperi, creane uno
                    if(p.Terrascore >= terrascore && empireCount < empireNumber)
                    {
                        Empire empire = new Empire(ss);
                        int money = rnd.Next(10000, 100000); // Soldi e abitanti random
                        int inhabitants = rnd.Next(10000, 1000000);

                        // Definisci potenza di attacco e difese a seconda della religione
                        int minD = 300; int minO = 10;
                        if (empire.EmpireReligion == Religion.ReligionType.ATOM || empire.EmpireReligion == Religion.ReligionType.BLESS)
                            minD = 1000;
                        else if (empire.EmpireReligion == Religion.ReligionType.CURSER)
                            minO = 100;
                        int defense = rnd.Next(minD, 10000);
                        int offense = rnd.Next(minO, 200);
                        // Crea insediamento
                        Settlement settlement = new Settlement(Settlement.SettlementType.CAPITAL, money, inhabitants, defense, offense, empire.EmpireReligion);
                        p.CreateSettlement(settlement);
                        empire.SetEmpireCapital(p);
                        // Aggiungilo agli imperi
                        empires.Add(empire);
                        empireCount++;
                        break;
                    }
                }
                // Se si sono creati tutti gli imperi, esci da for
                if (empireCount > empireNumber)
                    break;
            }
        }
 /// <summary>
 /// Metodo che controlla il proprietario del sistema su cui si trova attualmente la nave
 /// </summary>
 public static void SystemOwner()
 {
     actualSystemOwner = SystemOwner(actualSystem);
 }
 public static void SetActualSystemOwner(Empire e)
 {
     e.OwnedSystems.Add(actualSystem);
     SystemOwner();
 }
示例#8
0
        public void CreateNewRelation(Empire otherEmpire)
        {
            List<Event> events = new List<Event>();
            //Evento religione
            int i = Religion.ReligionIndex(empireReligion, otherEmpire.EmpireReligion) * 10;
            Event.EventType type;
            if (i < 0)
                type = Event.EventType.NEGATIVE;
            else if (i == 0)
                type = Event.EventType.NEUTRAL;
            else
                type = Event.EventType.POSITIVE;

            events.Add(new Event(type, Event.EventMotivation.RELIGION, i));

            //Crea relazione e aggiungila alla lista
            empireRelations.Add(new Relation(otherEmpire.EmpireName, events));
        }