示例#1
0
        public EmpireManager(EmpireData empire)
        {
            m_data           = empire;
            m_data.m_faction = MyAPIGateway.Session.Factions.TryGetFactionByTag(m_data.empireTag);
            if (m_data.m_faction == null)
            {
                Util.Error("Faction (" + m_data.empireTag + ") not found. Empire will stagnate.");
                m_data = null;
                return;
            }
            MyAPIGateway.Session.Factions.ChangeAutoAccept(
                m_data.m_faction.FactionId,
                m_data.m_faction.FounderId,
                false,
                false);

            m_shipManager = new SpawnManager(m_data);
        }
示例#2
0
        /// <inheritdoc />
        public void ApplyToState(EmpireData empire)
        {
            switch (Mode)
            {
            case CommandMode.Add:
                empire.OwnedFleets[FleetKey].Waypoints.Add(Waypoint);
                break;

            case CommandMode.Delete:
                empire.OwnedFleets[FleetKey].Waypoints.RemoveAt(Index);
                break;

            case CommandMode.Edit:
                empire.OwnedFleets[FleetKey].Waypoints.RemoveAt(Index);
                empire.OwnedFleets[FleetKey].Waypoints.Insert(Index, Waypoint);
                break;
            }
        }
示例#3
0
 /**
  * If a peaceful empire 'calls the police', the police faction will temporarially declare
  * war against the attacking faction.
  */
 public static void CallPolice(EmpireData callerEmpire, EmpireData targetEmpire)
 {
     if (callerEmpire == null || targetEmpire == null)
     {
         return;
     }
     if (WarIsDefault(callerEmpire))
     {
         return;
     }
     foreach (EmpireData empireA in GlobalData.world.empires)
     {
         if ((EmpireType)empireA.empireType != EmpireType.POLICE)
         {
             continue;
         }
         DeclareWar(empireA, targetEmpire);
     }
 }
示例#4
0
        /// <summary>
        /// Contributes allocated research from the star.
        /// </summary>
        /// <param name="race">Star's owner race.</param>
        /// <param name="star">Star to process.</param>
        /// <remarks>
        /// Note that stars which contribute only leftovers are not accounted for.
        /// </remarks>
        private void ContributeAllocatedResearch(Star star)
        {
            if (star.Owner == Global.Nobody)
            {
                return;
            }

            EmpireData empire = serverState.AllEmpires[star.Owner];

            TechLevel targetAreas = empire.ResearchTopics;

            TechLevel.ResearchField targetArea = TechLevel.ResearchField.Energy; // default to Energy.

            // Find the first research priority
            // TODO: Implement a proper hierarchy of research ("next research field") system.
            foreach (TechLevel.ResearchField area in Enum.GetValues(typeof(TechLevel.ResearchField)))
            {
                if (targetAreas[area] == 1)
                {
                    targetArea = area;
                    break;
                }
            }

            // Consume resources for research for added paranoia.
            empire.ResearchResources[targetArea] = empire.ResearchResources[targetArea] + star.ResearchAllocation;
            star.ResearchAllocation = 0;

            while (true)
            {
                int cost = Research.Cost(targetArea, empire.Race, empire.ResearchLevels, empire.ResearchLevels[targetArea] + 1);

                if (empire.ResearchResources[targetArea] >= cost)
                {
                    TechLevelUp(targetArea, empire);
                }
                else
                {
                    break;
                }
            }
        }
示例#5
0
        /**
         * Declares a temporary war between two factions.
         */
        public static void DeclareWar(EmpireData empireA, EmpireData empireB)
        {
            EmpireStanding standings = FindStandings(empireA, empireB);

            if (standings == null)
            {
                return;
            }
            bool previouslyAtWar = standings.atWar;

            standings.atWar = true;
            if (!WarIsDefault(empireA))
            {
                standings.inStateTill = GlobalData.world.currentTick + AGRESSION_TIMER_TICKS;
            }
            if (!previouslyAtWar)
            {
                TryDeclareWar(empireA, empireB);
            }
        }
示例#6
0
        public void ApplyToState(EmpireData empire)
        {
            switch (Mode)
            {
            case CommandMode.Add:
                empire.Designs.Add(Design.Key, Design);
                break;

            case CommandMode.Delete:
                empire.Designs.Remove(Design.Key);
                UpdateFleetCompositions(empire);
                break;

            case CommandMode.Edit:
                empire.Designs.Remove(Design.Key);
                UpdateFleetCompositions(empire);
                empire.Designs.Add(Design.Key, Design);
                break;
            }
        }
示例#7
0
 /**
  * Declares a faction ware between two factions, and cancels any outstanding peace negotiations.
  */
 private static void TryDeclareWar(EmpireData empireA, EmpireData empireB)
 {
     if (!MyAPIGateway.Multiplayer.IsServer)
     {
         return;
     }
     if (empireA.m_faction == null || empireB.m_faction == null)
     {
         return;
     }
     if (MyAPIGateway.Session.Factions.IsPeaceRequestStateSent(empireA.m_faction.FactionId, empireB.m_faction.FactionId))
     {
         MyAPIGateway.Session.Factions.CancelPeaceRequest(empireA.m_faction.FactionId, empireB.m_faction.FactionId);
     }
     if (MyAPIGateway.Session.Factions.AreFactionsEnemies(empireA.m_faction.FactionId, empireB.m_faction.FactionId))
     {
         return;
     }
     Util.Log("Empires go to war: " + empireA.empireTag + " and " + empireB.empireTag);
     MyAPIGateway.Session.Factions.DeclareWar(empireA.m_faction.FactionId, empireB.m_faction.FactionId);
 }
示例#8
0
        public bool IsValid(Fleet fleet, Mappable target, EmpireData sender, EmpireData reciever)
        {
            Message message = new Message();

            Messages.Add(message);

            message.Audience = fleet.Owner;
            message.Text     = fleet.Name + " attempted to colonise ";

            if (fleet.InOrbit == null || target == null || !(target is Star))
            {
                message.Text += "something that is not a star.";
                return(false);
            }

            Star star = (Star)target;

            message.Text += target.Name;

            if (star.Colonists != 0)
            {
                message.Text += " but it is already occupied.";
                return(false);
            }

            if (fleet.Cargo.ColonistsInKilotons == 0)
            {
                message.Text += " but no colonists were on board.";
                return(false);
            }

            if (fleet.CanColonize == false)
            {
                message.Text += " but no ships with colonization module were present.";
                return(false);
            }

            Messages.Clear();
            return(true);
        }
示例#9
0
 /**
  * Sends a peace negotiation between two factions, with faction A as the initiator.
  */
 private static void TryDeclarePeace(EmpireData empireA, EmpireData empireB)
 {
     if (!MyAPIGateway.Multiplayer.IsServer)
     {
         return;
     }
     if (empireA.m_faction == null || empireB.m_faction == null)
     {
         return;
     }
     if (!MyAPIGateway.Session.Factions.AreFactionsEnemies(empireA.m_faction.FactionId, empireB.m_faction.FactionId))
     {
         return;
     }
     if (MyAPIGateway.Session.Factions.IsPeaceRequestStateSent(empireA.m_faction.FactionId, empireB.m_faction.FactionId))
     {
         Util.Log("Empires beg for peace: " + empireA.empireTag + " and " + empireB.empireTag);
         return;
     }
     Util.Log("Empires try to restore peace: " + empireA.empireTag + " and " + empireB.empireTag);
     MyAPIGateway.Session.Factions.SendPeaceRequest(empireA.m_faction.FactionId, empireB.m_faction.FactionId);
 }
示例#10
0
        /// <summary>
        /// Allocate an initial set of resources to a player's "home" star system. for
        /// each player giving it some colonists and initial resources.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param>
        private void AllocateHomeStarResources(Star star, EmpireData empire)
        {
            Random random = new Random();

            // Set the owner of the home star in order to obtain proper
            // starting resources.
            star.Owner    = empire.Id;
            star.ThisRace = empire.Race;

            // Set the habital values for this star to the optimum for each race.
            // This should allTurnedIn in a planet value of 100% for this race's home
            // world.
            star.Radiation   = empire.Race.RadiationTolerance.OptimumLevel;
            star.Temperature = empire.Race.TemperatureTolerance.OptimumLevel;
            star.Gravity     = empire.Race.GravityTolerance.OptimumLevel;

            star.OriginalRadiation   = star.Radiation;
            star.OriginalGravity     = star.Gravity;
            star.OriginalTemperature = star.Temperature;

            star.Colonists = empire.Race.GetStartingPopulation();

            star.ResourcesOnHand.Boranium  = this.homeStarDefaultSurfaceMinerals.Boranium; // ToDo: leftover advantage points
            star.ResourcesOnHand.Ironium   = this.homeStarDefaultSurfaceMinerals.Ironium;
            star.ResourcesOnHand.Germanium = this.homeStarDefaultSurfaceMinerals.Germanium;
            star.Mines     = 10;
            star.Factories = 10;
            star.ResourcesOnHand.Energy = star.GetResourceRate();

            star.MineralConcentration.Boranium  = this.homeStarDefaultMineralConcentration.Boranium;
            star.MineralConcentration.Ironium   = this.homeStarDefaultMineralConcentration.Ironium;
            star.MineralConcentration.Germanium = this.homeStarDefaultMineralConcentration.Germanium;

            star.ScannerType = "Scoper 150"; // TODO (priority 4) get from component list
            star.DefenseType = "SDI";        // TODO (priority 4) get from component list
            star.ScanRange   = 50;           // TODO (priority 4) get from component list

            HomeStarLeftoverpointsAdjuster.Adjust(star, empire.Race);
        }
示例#11
0
        private void AddStars(EmpireData empire)
        {
            foreach (Star star in serverState.AllStars.Values)
            {
                if (star.Owner == empire.Id)
                {
                    if (!empire.OwnedStars.Contains(star))
                    {
                        empire.OwnedStars.Add(star);
                    }
                    else
                    {
                        empire.OwnedStars[star.Name] = serverState.AllStars[star.Name];
                    }

                    if (!empire.StarReports.ContainsKey(star.Name))
                    {
                        empire.StarReports.Add(star.Name, star.GenerateReport(ScanLevel.Owned, serverState.TurnYear));
                    }
                    else
                    {
                        empire.StarReports[star.Name].Update(star, ScanLevel.Owned, serverState.TurnYear);
                    }
                }
                else
                {
                    if (empire.OwnedStars.Contains(star))
                    {
                        empire.OwnedStars.Remove(star);
                    }

                    if (!empire.StarReports.ContainsKey(star.Name))
                    {
                        empire.StarReports.Add(star.Name, star.GenerateReport(ScanLevel.None, Global.Unset));
                    }
                }
            }
        }
示例#12
0
        /// <summary>
        /// Handle destroying ships of the deleted/edited design.
        /// </summary>
        private void UpdateFleetCompositions(EmpireData empire)
        {
            // Note that we are not allowed to delete the ships or fleets on the
            // iteration as that is not allowed (it
            // destroys the validity of the iterator). Consequently we identify
            // anything that needs deleting and remove them separately from their
            // identification.
            List <Fleet> fleetsToRemove = new List <Fleet>();

            foreach (Fleet fleet in empire.OwnedFleets.Values)
            {
                List <ShipToken> tokensToRemove = new List <ShipToken>();

                foreach (ShipToken token in fleet.Composition.Values)
                {
                    if (token.Design.Key == Design.Key)
                    {
                        tokensToRemove.Add(token);
                    }
                }

                foreach (ShipToken token in tokensToRemove)
                {
                    fleet.Composition.Remove(token.Design.Key);
                }

                if (fleet.Composition.Count == 0)
                {
                    fleetsToRemove.Add(fleet);
                }
            }

            foreach (Fleet fleet in fleetsToRemove)
            {
                empire.OwnedFleets.Remove(fleet.Key);
                empire.FleetReports.Remove(fleet.Key);
            }
        }
示例#13
0
        /// <inheritdoc />
        public bool Perform(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
        {
            Fleet secondFleet = null;

            // Look for an appropiate fleet for a merge.
            if (OtherFleetKey != 0)
            {
                // This allows to merge with other empires if desired at some point.
                if (receiver != null && receiver.OwnedFleets.ContainsKey(OtherFleetKey))
                {
                    secondFleet = receiver.OwnedFleets[OtherFleetKey];
                }
                else if (sender.OwnedFleets.ContainsKey(OtherFleetKey))
                {
                    // The other fleet is also ours: OtherFleetKey belongs to the same Race/Player as the fleet with the SplitMergeTask waypoint order.
                    secondFleet = sender.OwnedFleets[OtherFleetKey];
                }
            }

            // Found fleet => Merge
            if (secondFleet != null)
            {
                MergeFleets(fleet, secondFleet);
            }
            else
            {
                // Else it's a split. Need a new fleet so clone original
                // and change stuff.
                secondFleet = sender.MakeNewFleet(fleet);

                ReassignShips(fleet, secondFleet);

                // Now send new Fleets to limbo pending inclusion.
                sender.TemporaryFleets.Add(secondFleet);
            }

            return(true);
        }
示例#14
0
        public bool IsValid(EmpireData empire)
        {
            switch (Mode)
            {
            case CommandMode.Add:
                if (empire.Designs.ContainsKey(Design.Key))
                {
                    // Cant re-add same design.
                    return(false);
                }
                break;

            case CommandMode.Delete:     // Botch cases check for existing design before editing/deleting.
            case CommandMode.Edit:
                if (!empire.Designs.ContainsKey(Design.Key))
                {
                    return(false);
                }
                break;
            }

            return(true);
        }
示例#15
0
        public void TakeStandingsHit(EmpireData aggressorEmpire)
        {
            if (m_nextStandingsChange > GlobalData.world.currentTick)
            {
                return;
            }
            m_nextStandingsChange = GlobalData.world.currentTick + Tick.Seconds(STANDINGS_DEBOUCE_SEC);

            EmpireData.EmpireStanding standings = Diplomacy.FindStandings(m_data, aggressorEmpire);
            if (standings == null)
            {
                return;
            }
            standings.reputation--;
            if (standings.atWar)
            {
                return;
            }
            Diplomacy.CallPolice(m_data, aggressorEmpire);
            if (standings.reputation < 0)
            {
                Diplomacy.DeclareWar(m_data, aggressorEmpire);
            }
        }
示例#16
0
        /// <Summary>
        /// Initializes a new instance of the FleetReport class.
        /// </Summary>
        public FleetReport(EmpireData empireState)
        {
            this.empireState = empireState;

            InitializeComponent();
        }
示例#17
0
        /// <summary>
        /// Allocate an initial set of resources to a player's "home" star system. for
        /// each player giving it some colonists and initial resources.
        /// </summary>
        /// <param name="star"></param>
        /// <param name="race"></param>
        private void AllocateHomeStarOrbitalInstallations(Star star, EmpireData empire, string player)
        {
            ShipDesign colonyShipDesign = null;

            foreach (ShipDesign design in empire.Designs.Values)
            {
                if (design.Name == "Santa Maria")
                {
                    colonyShipDesign = design;
                }
            }

            if (empire.Race.Traits.Primary.Code != "HE")
            {
                ShipToken cs     = new ShipToken(colonyShipDesign, 1);
                Fleet     fleet1 = new Fleet(cs, star, empire.GetNextFleetKey());
                fleet1.Name = colonyShipDesign.Name + " #1";
                empire.AddOrUpdateFleet(fleet1);
            }
            else
            {
                for (int i = 1; i <= 3; i++)
                {
                    ShipToken cs    = new ShipToken(colonyShipDesign, 1);
                    Fleet     fleet = new Fleet(cs, star, empire.GetNextFleetKey());
                    fleet.Name = string.Format("{0} #{1}", colonyShipDesign.Name, i);
                    empire.AddOrUpdateFleet(fleet);
                }
            }

            ShipDesign scoutDesign = null;

            foreach (ShipDesign design in empire.Designs.Values)
            {
                if (design.Name == "Scout")
                {
                    scoutDesign = design;
                }
            }

            ShipToken scout      = new ShipToken(scoutDesign, 1);
            Fleet     scoutFleet = new Fleet(scout, star, empire.GetNextFleetKey());

            scoutFleet.Name = "Scout #1";
            empire.AddOrUpdateFleet(scoutFleet);

            ShipDesign starbaseDesign = null;

            foreach (ShipDesign design in empire.Designs.Values)
            {
                if (design.Name == "Starbase")
                {
                    starbaseDesign = design;
                }
            }

            ShipToken starbase      = new ShipToken(starbaseDesign, 1);
            Fleet     starbaseFleet = new Fleet(starbase, star, empire.GetNextFleetKey());

            starbaseFleet.Name = star.Name + " Starbase";
            star.Starbase      = starbaseFleet;
            empire.AddOrUpdateFleet(starbaseFleet);
        }
示例#18
0
        /// <summary>
        /// Initialize some starting designs.
        /// </summary>
        /// <param name="race">The <see cref="Race"/> of the player being initialized.</param>
        /// <param name="player">The player being initialized.</param>
        private void PrepareDesigns(EmpireData empire, string player)
        {
            // Read components data and create some basic stuff
            AllComponents components = new AllComponents();

            Component colonyShipHull = null, scoutHull = null;
            Component colonizer = null;
            Component scaner    = components.Fetch("Bat Scanner");
            Component armor     = components.Fetch("Tritanium");
            Component shield    = components.Fetch("Mole-skin Shield");
            Component laser     = components.Fetch("Laser");
            Component torpedo   = components.Fetch("Alpha Torpedo");

            Component starbaseHull     = components.Fetch("Space Station");
            Component engine           = components.Fetch("Quick Jump 5");
            Component colonyShipEngine = null;

            if (empire.Race.Traits.Primary.Code != "HE")
            {
                colonyShipHull = components.Fetch("Colony Ship");
            }
            else
            {
                colonyShipEngine = components.Fetch("Settler's Delight");
                colonyShipHull   = components.Fetch("Mini-Colony Ship");
            }

            scoutHull = components.Fetch("Scout");

            if (empire.Race.HasTrait("AR") == true)
            {
                colonizer = components.Fetch("Orbital Construction Module");
            }
            else
            {
                colonizer = components.Fetch("Colonization Module");
            }


            if (colonyShipEngine == null)
            {
                colonyShipEngine = engine;
            }

            ShipDesign cs = new ShipDesign(empire.GetNextDesignKey());

            cs.Blueprint = colonyShipHull;
            foreach (HullModule module in cs.Hull.Modules)
            {
                if (module.ComponentType == "Engine")
                {
                    module.AllocatedComponent = colonyShipEngine;
                    module.ComponentCount     = 1;
                }
                else if (module.ComponentType == "Mechanical")
                {
                    module.AllocatedComponent = colonizer;
                    module.ComponentCount     = 1;
                }
            }
            cs.Icon = new ShipIcon(colonyShipHull.ImageFile, (Bitmap)colonyShipHull.ComponentImage);

            cs.Type = ItemType.Ship;
            cs.Name = "Santa Maria";
            cs.Update();

            ShipDesign scout = new ShipDesign(empire.GetNextDesignKey());

            scout.Blueprint = scoutHull;
            foreach (HullModule module in scout.Hull.Modules)
            {
                if (module.ComponentType == "Engine")
                {
                    module.AllocatedComponent = engine;
                    module.ComponentCount     = 1;
                }
                else if (module.ComponentType == "Scanner")
                {
                    module.AllocatedComponent = scaner;
                    module.ComponentCount     = 1;
                }
            }
            scout.Icon = new ShipIcon(scoutHull.ImageFile, (Bitmap)scoutHull.ComponentImage);

            scout.Type = ItemType.Ship;
            scout.Name = "Scout";
            scout.Update();

            ShipDesign starbase = new ShipDesign(empire.GetNextDesignKey());

            starbase.Name      = "Starbase";
            starbase.Blueprint = starbaseHull;
            starbase.Type      = ItemType.Starbase;
            starbase.Icon      = new ShipIcon(starbaseHull.ImageFile, (Bitmap)starbaseHull.ComponentImage);
            bool weaponSwitcher = false; // start with laser
            bool armorSwitcher  = false; // start with armor

            foreach (HullModule module in starbase.Hull.Modules)
            {
                if (module.ComponentType == "Weapon")
                {
                    if (weaponSwitcher == false)
                    {
                        module.AllocatedComponent = laser;
                    }
                    else
                    {
                        module.AllocatedComponent = torpedo;
                    }
                    weaponSwitcher        = !weaponSwitcher;
                    module.ComponentCount = 8;
                }
                if (module.ComponentType == "Shield")
                {
                    module.AllocatedComponent = shield;
                    module.ComponentCount     = 8;
                }
                if (module.ComponentType == "Shield or Armor")
                {
                    if (armorSwitcher == false)
                    {
                        module.AllocatedComponent = armor;
                    }
                    else
                    {
                        module.AllocatedComponent = shield;
                    }
                    module.ComponentCount = 8;
                    armorSwitcher         = !armorSwitcher;
                }
            }

            starbase.Update();

            empire.Designs[starbase.Key] = starbase;
            empire.Designs[cs.Key]       = cs;
            empire.Designs[scout.Key]    = scout;

            /*
             * switch (race.Traits.Primary.Code)
             * {
             *  case "HE":
             *      // Start with one armed scout + 3 mini-colony ships
             *  case "SS":
             *      // Start with one scout + one colony ship.
             *  case "WM":
             *      // Start with one armed scout + one colony ship.
             *      break;
             *
             *  case "CA":
             *      // Start with an orbital terraforming ship
             *      break;
             *
             *  case "IS":
             *      // Start with one scout and one colony ship
             *      break;
             *
             *  case "SD":
             *      // Start with one scout, one colony ship, Two mine layers (one standard, one speed trap)
             *      break;
             *
             *  case "PP":
             *      empireData.ResearchLevel[TechLevel.ResearchField.Energy] = 4;
             *      // Two shielded scouts, one colony ship, two starting planets in a non-tiny universe
             *      break;
             *
             *  case "IT":
             *      empireData.ResearchLevel[TechLevel.ResearchField.Propulsion] = 5;
             *      empireData.ResearchLevel[TechLevel.ResearchField.Construction] = 5;
             *      // one scout, one colony ship, one destroyer, one privateer, 2 planets with 100/250 stargates (in non-tiny universe)
             *      break;
             *
             *  case "AR":
             *      empireData.ResearchLevel[TechLevel.ResearchField.Energy] = 1;
             *
             *      // starts with one scout, one orbital construction colony ship
             *      break;
             *
             *  case "JOAT":
             *      // two scouts, one colony ship, one medium freighter, one mini miner, one destroyer
             *      break;
             */
        }
示例#19
0
 public bool Perform(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
 {
     return(true);
 }
示例#20
0
        /// <summary>
        /// Load <see cref="Intel">ClientState</see> from an xml document.
        /// </summary>
        /// <param name="xmldoc">Produced using XmlDocument.Load(filename).</param>
        public ClientData(XmlDocument xmldoc)
        {
            XmlNode xmlnode = xmldoc.DocumentElement;
            XmlNode textNode;

            while (xmlnode != null)
            {
                try
                {
                    switch (xmlnode.Name.ToLower())
                    {
                    case "root":
                        xmlnode = xmlnode.FirstChild;
                        continue;

                    case "clientstate":
                        xmlnode = xmlnode.FirstChild;
                        continue;

                    case "empiredata":
                        EmpireState = new EmpireData(xmlnode);
                        break;

                    case "commands":
                        textNode = xmlnode.FirstChild;
                        while (textNode != null)
                        {
                            switch (textNode.Attributes["Type"].Value.ToString().ToLower())
                            {
                            case "research":
                                Commands.Push(new ResearchCommand(textNode));
                                break;
                            }
                            textNode = textNode.NextSibling;
                        }
                        break;

                    case "message":
                        Messages.Add(new Message(xmlnode));
                        break;

                    case "intel":
                        // THIS HAS TO GO!
                        InputTurn = new Intel();
                        InputTurn.LoadFromXmlNode(xmlnode);
                        break;

                    case "firstturn":
                        FirstTurn = bool.Parse(xmlnode.FirstChild.Value);
                        break;

                    case "gamefolder":
                        GameFolder = xmlnode.FirstChild.Value;
                        break;

                    case "statepathname":
                        StatePathName = xmlnode.FirstChild.Value;
                        break;
                    }

                    xmlnode = xmlnode.NextSibling;
                }
                catch (Exception e)
                {
                    Report.FatalError(e.Message + "\n Details: \n" + e);
                }
            }
        }
示例#21
0
        public static List <SectorId> FindSectorsByOwner(EmpireData empire)
        {
            List <SectorId> sectors = new List <SectorId>();

            return(sectors);
        }
示例#22
0
        private void Scan(EmpireData empire)
        {
            foreach (Mappable scanner in empire.IterateAllMappables())
            {
                int scanRange    = 0;
                int penScanRange = 0;

                //Do some self scanning (Update reports) and set ranges..
                if (scanner is Star)
                {
                    scanRange    = (scanner as Star).ScanRange;
                    penScanRange = (scanner as Star).ScanRange; // TODO:(priority 6) Planetary Pen-Scan not implemented yet.
                    empire.StarReports[scanner.Name].Update(scanner as Star, ScanLevel.Owned, serverState.TurnYear);
                }
                else
                {
                    scanRange    = (scanner as Fleet).ScanRange;
                    penScanRange = (scanner as Fleet).PenScanRange;
                    empire.FleetReports[scanner.Key].Update(scanner as Fleet, ScanLevel.Owned, empire.TurnYear);
                }

                // Scan everything
                foreach (Mappable scanned in serverState.IterateAllMappables())
                {
                    // ...That isn't ours!
                    if (scanned.Owner == empire.Id)
                    {
                        continue;
                    }

                    ScanLevel scanLevel = ScanLevel.None;
                    double    range     = 0;
                    range = PointUtilities.Distance(scanner.Position, scanned.Position);

                    if (scanned is Star)
                    {
                        Star star = scanned as Star;

                        // There are two ways to get information from a Star:
                        // 1. In orbit with a fleet,
                        // 2. Not in orbit with a Pen Scan (fleet or star).
                        // Non penetrating distance scans won't tell anything about it.
                        if ((scanner is Fleet) && range == 0)
                        {
                            scanLevel = (scanner as Fleet).CanScan ? ScanLevel.InDeepScan : ScanLevel.InPlace;
                        }
                        else // scanner is Star or non orbiting Fleet
                        {
                            scanLevel = (range <= penScanRange) ? ScanLevel.InDeepScan : ScanLevel.None;
                        }

                        // Dont update if we didn't scan to allow report to age.
                        if (scanLevel == ScanLevel.None)
                        {
                            continue;
                        }

                        if (empire.StarReports.ContainsKey(scanned.Name))
                        {
                            empire.StarReports[scanned.Name].Update((scanned as Star), scanLevel, serverState.TurnYear);
                        }
                        else
                        {
                            empire.StarReports.Add(scanned.Name, (scanned as Star).GenerateReport(scanLevel, serverState.TurnYear));
                        }
                    }
                    else // scanned is Fleet
                    {
                        // Fleets are simple as scan levels (PenScan for example) won't affect them. We only
                        // care for non penetrating distance scans.
                        if (range > scanRange)
                        {
                            continue;
                        }

                        // Check if we have a record of this design(s).
                        foreach (ShipToken token in (scanned as Fleet).Composition.Values)
                        {
                            if (empire.EmpireReports[scanned.Owner].Designs.ContainsKey(token.Design.Key))
                            {
                                continue;
                            }

                            // If not, add just the empty Hull.
                            ShipDesign newDesign = new ShipDesign(token.Design);
                            newDesign.Key = token.Design.Key;
                            newDesign.ClearAllocated();
                            empire.EmpireReports[scanned.Owner].Designs.Add(newDesign.Key, newDesign);
                        }

                        if (!empire.FleetReports.ContainsKey(scanned.Key))
                        {
                            empire.FleetReports.Add(scanned.Key, (scanned as Fleet).GenerateReport(ScanLevel.InScan, serverState.TurnYear));
                        }
                        else
                        {
                            empire.FleetReports[scanned.Key].Update((scanned as Fleet), ScanLevel.InScan, serverState.TurnYear);
                        }
                    }
                }
            }
        }
示例#23
0
 /**
  * Return if this empire type prefers to be at war.
  * A empire diplomacy timer indicates that this faction is temporarially at peace, and upon
  * expiration, the faction will attempt to go to war again.
  */
 private static bool WarIsDefault(EmpireData empire)
 {
     return((EmpireType)empire.empireType == EmpireType.TRUE_HOSTILE ||
            (EmpireType)empire.empireType == EmpireType.HOSTILE);
 }
示例#24
0
        /// <Summary>
        /// Initializes a new instance of the SelectionSummary class.
        /// </Summary>
        public SelectionSummary(EmpireData empireState)
        {
            this.empireState = empireState;

            InitializeComponent();
        }
示例#25
0
 public void ApplyToState(EmpireData empire)
 {
     empire.ResearchBudget = Budget;
     empire.ResearchTopics = Topics;
 }
示例#26
0
        public bool IsValid(EmpireData empire)
        {
            switch (Mode)
            {
            case CommandMode.Add:
                // When adding something to the production, it's cost can't be lower than
                // it's actual cost.
                if (ProductionOrder.Unit is ShipProductionUnit)
                {
                    try
                    {
                        if (!(ProductionOrder.Unit.Cost >= empire.Designs[(ProductionOrder.Unit as ShipProductionUnit).DesignKey].Cost))
                        {
                            return(false);
                        }
                    }
                    catch (System.Collections.Generic.KeyNotFoundException)
                    {
                        return(false);
                    }
                }
                if (ProductionOrder.Unit is FactoryProductionUnit)
                {
                    if (!(ProductionOrder.Unit.Cost >= empire.Race.GetFactoryResources()))
                    {
                        return(false);
                    }
                }
                if (ProductionOrder.Unit is MineProductionUnit)
                {
                    if (!(ProductionOrder.Unit.Cost >= empire.Race.GetMineResources()))
                    {
                        return(false);
                    }
                }
                // Don't add cheated pre-built units.
                if (!(ProductionOrder.Unit.Cost == ProductionOrder.Unit.RemainingCost))
                {
                    return(false);
                }
                break;

            case CommandMode.Edit:
                // Check the order actually exists.

                // FIXME (priority 5) - this causes a false positive when edditing production orders
                // if (!empire.OwnedStars[StarKey].ManufacturingQueue.Queue.Contains(ProductionOrder)) {return false;}

                // Don't allow modification of the total cost.
                if (!(ProductionOrder.Unit.RemainingCost >= empire.OwnedStars[StarKey].ManufacturingQueue.Queue[Index].Unit.RemainingCost))
                {
                    return(false);
                }
                // Don't allow modification of the remaining cost.
                if (!(ProductionOrder.Unit.Cost >= empire.OwnedStars[StarKey].ManufacturingQueue.Queue[Index].Unit.Cost))
                {
                    return(false);
                }

                break;

            case CommandMode.Delete:
                // Check the order actually exists.
                // if (!empire.OwnedStars[StarKey].ManufacturingQueue.Queue.Contains(ProductionOrder)) {return false;} // FIXME (priority 5) - flase positive prevents deletion of production items.
                break;
            }

            return(true);
        }
示例#27
0
 public bool IsValid(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
 {
     return(true);
 }
示例#28
0
        /// <Summary>
        /// Initializes a new instance of the FleetSummary class.
        /// </Summary>
        public FleetSummary(EmpireData empireState)
        {
            this.empireState = empireState;

            InitializeComponent();
        }
示例#29
0
 public Sector(EmpireData owner)
 {
     m_owner = owner;
 }
示例#30
0
 /**
  * Return if this empire type prefers to be at peace.
  * A empire diplomacy timer indicates that this faction is temporarially at war, and upon
  * expiration, the faction will attempt to negotiate peace.
  */
 private static bool PeaceIsDefault(EmpireData empire)
 {
     return(!WarIsDefault(empire));
 }