예제 #1
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;
             */
        }
예제 #2
0
        /// <summary>
        /// When state is loaded from file, objects may contain references to other objects.
        /// As these may be loaded in any order (or be cross linked) it is necessary to tidy
        /// up these references once the state is fully loaded and all objects exist.
        /// In most cases a placeholder object has been created with the Key set from the file,
        /// and we need to find the actual reference using this Key.
        /// Objects can't do this themselves as they don't have access to the state data,
        /// so we do it here.
        /// </summary>
        private void LinkReferences()
        {
            AllComponents allComponents = new AllComponents();

            // HullModule reference to a component
            foreach (ShipDesign design in Designs.Values)
            {
                foreach (HullModule module in design.Hull.Modules)
                {
                    if (module.AllocatedComponent != null && module.AllocatedComponent.Name != null)
                    {
                        module.AllocatedComponent = allComponents.Fetch(module.AllocatedComponent.Name);
                    }
                }

                design.Update();

                if (design.Id >= designCounter)
                {
                    designCounter = design.Id + 1;
                }
            }

            // Link enemy designs too
            foreach (EmpireIntel enemy in EmpireReports.Values)
            {
                foreach (ShipDesign design in enemy.Designs.Values)
                {
                    foreach (HullModule module in design.Hull.Modules)
                    {
                        if (module.AllocatedComponent != null && module.AllocatedComponent.Name != null)
                        {
                            module.AllocatedComponent = allComponents.Fetch(module.AllocatedComponent.Name);
                        }
                    }

                    design.Update();
                }
            }

            // Fleet reference to Star
            foreach (Fleet fleet in OwnedFleets.Values)
            {
                if (fleet.InOrbit != null)
                {
                    if (StarReports[fleet.InOrbit.Name].Owner == fleet.Owner)
                    {
                        fleet.InOrbit = OwnedStars[fleet.InOrbit.Name];
                    }
                    else
                    {
                        fleet.InOrbit = StarReports[fleet.InOrbit.Name];
                    }
                }

                // Ship reference to Design
                foreach (ShipToken token in fleet.Composition.Values)
                {
                    token.Design = Designs[token.Design.Key];
                }
            }

            // Set designs in any Battle Reports
            foreach (BattleReport battle in BattleReports)
            {
                foreach (Stack stack in battle.Stacks.Values)
                {
                    if (stack.Owner == empireId)
                    {
                        stack.Token.Design = Designs[stack.Token.Key];
                    }
                    else
                    {
                        stack.Token.Design = EmpireReports[stack.Owner].Designs[stack.Token.Key];
                    }
                }
            }

            // Link reports to Designs to get accurate data.
            foreach (FleetIntel report in FleetReports.Values)
            {
                foreach (ShipToken token in report.Composition.Values)
                {
                    if (report.Owner == Id)
                    {
                        token.Design = Designs[token.Design.Key];
                    }
                    else
                    {
                        token.Design = EmpireReports[report.Owner].Designs[token.Design.Key];
                    }
                }
            }

            // Link Star Races and Starbases
            foreach (Star star in OwnedStars.Values)
            {
                if (star.Owner == Id)
                {
                    star.ThisRace = Race;
                }
                else
                {
                    star.ThisRace = null;
                }

                if (star.Starbase != null)
                {
                    star.Starbase = OwnedFleets[star.Starbase.Key];
                }
            }
        }
예제 #3
0
        /// <summary>
        /// When state is loaded from file, objects may contain references to other objects.
        /// As these may be loaded in any order (or be cross linked) it is necessary to tidy
        /// up these references once the file is fully loaded and all objects exist.
        /// In most cases a placeholder object has been created with the Name set from the file,
        /// and we need to find the actual reference using this Name.
        /// Objects can't do this themselves as they don't have access to the state data,
        /// so we do it here.
        /// </summary>
        private void LinkServerStateReferences()
        {
            AllComponents allComponents = new AllComponents();

            foreach (Star star in AllStars.Values)
            {
                // Star reference to the Race that owns it
                if (star.ThisRace != null)
                {
                    // Redundant, but works to check if race is valid...
                    if (star.Owner == AllEmpires[star.Owner].Id)
                    {
                        star.ThisRace = AllRaces[star.ThisRace.Name];
                    }
                    else
                    {
                        star.ThisRace = null;
                    }
                }

                // Star reference to it's Starbase if any
                if (star.Starbase != null)
                {
                    star.Starbase = AllEmpires[star.Starbase.Key.Owner()].OwnedFleets[star.Starbase.Key];
                }
            }

            // Link inside EmpireData
            foreach (EmpireData empire in AllEmpires.Values)
            {
                foreach (ShipDesign design in empire.Designs.Values)
                {
                    foreach (HullModule module in design.Hull.Modules)
                    {
                        if (module.AllocatedComponent != null && module.AllocatedComponent.Name != null)
                        {
                            module.AllocatedComponent = allComponents.Fetch(module.AllocatedComponent.Name);
                        }
                    }
                }

                foreach (Fleet fleet in empire.OwnedFleets.Values)
                {
                    // Fleet reference to Star it is orbiting
                    if (fleet.InOrbit != null)
                    {
                        fleet.InOrbit = AllStars[fleet.InOrbit.Name];
                    }
                    // Ship reference to Design
                    foreach (ShipToken token in fleet.Composition.Values)
                    {
                        token.Design = empire.Designs[token.Design.Key];
                    }
                }

                foreach (Star star in empire.OwnedStars.Values)
                {
                    if (star.ThisRace != null)
                    {
                        // Reduntant, but works to check if race name is valid...
                        if (star.Owner == empire.Id)
                        {
                            star.ThisRace = empire.Race;
                        }
                        else
                        {
                            star.ThisRace = null;
                        }
                    }

                    if (star.Starbase != null)
                    {
                        star.Starbase = empire.OwnedFleets[star.Starbase.Key];
                    }
                }
            }
        }