Beispiel #1
0
        private static void BatchJobItemComplete(Entity colonyEntity, CargoStorageDB storage, ConstructionJob batchJob, ComponentDesign designInfo)
        {
            var colonyConstruction = colonyEntity.GetDataBlob <ConstructionDB>();

            batchJob.NumberCompleted++;
            batchJob.ProductionPointsLeft = designInfo.BuildPointCost;
            batchJob.MineralsRequired     = designInfo.MineralCosts;
            batchJob.MineralsRequired     = designInfo.MaterialCosts;
            batchJob.MineralsRequired     = designInfo.ComponentCosts;

            ComponentInstance specificComponent = new ComponentInstance(designInfo);

            if (batchJob.InstallOn != null)
            {
                if (batchJob.InstallOn == colonyEntity || StorageSpaceProcessor.HasEntity(storage, colonyEntity.GetDataBlob <CargoAbleTypeDB>()))
                {
                    EntityManipulation.AddComponentToEntity(batchJob.InstallOn, specificComponent);
                    ReCalcProcessor.ReCalcAbilities(batchJob.InstallOn);
                }
            }
            else
            {
                StorageSpaceProcessor.AddCargo(storage, specificComponent, 1);
            }

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                colonyConstruction.JobBatchList.Remove(batchJob);
                if (batchJob.Auto)
                {
                    colonyConstruction.JobBatchList.Add(batchJob);
                }
            }
        }
        private static void BatchJobItemComplete(Entity colonyEntity, CargoStorageDB storage, ConstructionJob batchJob, ComponentInfoDB designInfo)
        {
            var colonyConstruction = colonyEntity.GetDataBlob <ColonyConstructionDB>();

            batchJob.NumberCompleted++;
            batchJob.PointsLeft       = designInfo.BuildPointCost;
            batchJob.MineralsRequired = designInfo.MinerialCosts;
            batchJob.MineralsRequired = designInfo.MaterialCosts;
            batchJob.MineralsRequired = designInfo.ComponentCosts;
            var    factionInfo       = colonyEntity.GetDataBlob <OwnedDB>().ObjectOwner.GetDataBlob <FactionInfoDB>();
            Entity designEntity      = factionInfo.ComponentDesigns[batchJob.ItemGuid];
            Entity specificComponent = ComponentInstanceFactory.NewInstanceFromDesignEntity(designEntity, colonyEntity.GetDataBlob <OwnedDB>().ObjectOwner);

            if (batchJob.InstallOn != null)
            {
                if (batchJob.InstallOn == colonyEntity || StorageSpaceProcessor.HasEntity(storage, colonyEntity))
                {
                    EntityManipulation.AddComponentToEntity(batchJob.InstallOn, specificComponent);
                    ReCalcProcessor.ReCalcAbilities(batchJob.InstallOn);
                }
            }
            else
            {
                StorageSpaceProcessor.AddItemToCargo(storage, specificComponent);
            }

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                colonyConstruction.JobBatchList.Remove(batchJob);
                if (batchJob.Auto)
                {
                    colonyConstruction.JobBatchList.Add(batchJob);
                }
            }
        }
Beispiel #3
0
        internal static void MineResources(Entity colonyEntity)
        {
            Dictionary <Guid, int> mineRates = colonyEntity.GetDataBlob <ColonyMinesDB>().MineingRate;
            Dictionary <Guid, MineralDepositInfo> planetMinerals = colonyEntity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <SystemBodyInfoDB>().Minerals;
            //Dictionary<Guid, int> colonyMineralStockpile = colonyEntity.GetDataBlob<ColonyInfoDB>().MineralStockpile;
            CargoStorageDB stockpile   = colonyEntity.GetDataBlob <CargoStorageDB>();
            float          mineBonuses = 1;//colonyEntity.GetDataBlob<ColonyBonusesDB>().GetBonus(AbilityType.Mine);

            foreach (var kvp in mineRates)
            {
                double accessability = planetMinerals[kvp.Key].Accessibility;
                double actualRate    = kvp.Value * mineBonuses * accessability;
                int    mineralsMined = (int)Math.Min(actualRate, planetMinerals[kvp.Key].Amount);
                long   capacity      = StorageSpaceProcessor.RemainingCapacity(stockpile, stockpile.CargoTypeID(kvp.Key));
                if (capacity > 0)
                {
                    //colonyMineralStockpile.SafeValueAdd<Guid>(kvp.Key, mineralsMined);
                    StorageSpaceProcessor.AddItemToCargo(stockpile, kvp.Key, mineralsMined);
                    MineralDepositInfo mineralDeposit = planetMinerals[kvp.Key];
                    int newAmount = mineralDeposit.Amount -= mineralsMined;

                    accessability = Math.Pow((float)mineralDeposit.Amount / mineralDeposit.HalfOriginalAmount, 3) * mineralDeposit.Accessibility;
                    double newAccess = GMath.Clamp(accessability, 0.1, mineralDeposit.Accessibility);

                    mineralDeposit.Amount        = newAmount;
                    mineralDeposit.Accessibility = newAccess;
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// consumes resources in the stockpile, and updates the dictionary.
 /// </summary>
 /// <param name="stockpile"></param>
 /// <param name="toUse"></param>
 private static void ConsumeResources(CargoStorageDB fromCargo, IDictionary <Guid, int> toUse)
 {
     foreach (KeyValuePair <Guid, int> kvp in toUse.ToArray())
     {
         ICargoable cargoItem          = fromCargo.OwningEntity.Manager.Game.StaticData.GetICargoable(kvp.Key);
         Guid       cargoTypeID        = cargoItem.CargoTypeID;
         int        amountUsedThisTick = 0;
         if (fromCargo.StoredCargoTypes.ContainsKey(cargoTypeID))
         {
             if (fromCargo.StoredCargoTypes[cargoTypeID].ItemsAndAmounts.ContainsKey(cargoItem.ID))
             {
                 if (fromCargo.StoredCargoTypes[cargoTypeID].ItemsAndAmounts[cargoItem.ID] >= kvp.Value)
                 {
                     amountUsedThisTick = kvp.Value;
                 }
                 else
                 {
                     amountUsedThisTick = (int)fromCargo.StoredCargoTypes[cargoTypeID].ItemsAndAmounts[cargoItem.ID];
                 }
             }
         }
         StorageSpaceProcessor.RemoveCargo(fromCargo, cargoItem, amountUsedThisTick);
         toUse[kvp.Key] -= amountUsedThisTick;
     }
 }
Beispiel #5
0
        /// <summary>
        /// TODO: refineing rates should also limit the amount that can be refined for a specific mat each tick.
        /// </summary>
        internal static void RefineMaterials(Entity colony, Game game)
        {
            CargoStorageDB   stockpiles = colony.GetDataBlob <CargoStorageDB>();
            ColonyRefiningDB refiningDB = colony.GetDataBlob <ColonyRefiningDB>();
            int RefineryPoints          = refiningDB.PointsPerTick;

            for (int jobIndex = 0; jobIndex < refiningDB.JobBatchList.Count; jobIndex++)
            {
                if (RefineryPoints > 0)
                {
                    var job = refiningDB.JobBatchList[jobIndex];
                    ProcessedMaterialSD    material = game.StaticData.ProcessedMaterials[job.ItemGuid];
                    Dictionary <Guid, int> costs    = new Dictionary <Guid, int>(material.RawMineralCosts);
                    if (material.RefinedMateraialsCosts != null)
                    {
                        costs.Concat(new Dictionary <Guid, int>(material.RefinedMateraialsCosts));
                    }
                    while (job.NumberCompleted < job.NumberOrdered && job.PointsLeft > 0)
                    {
                        if (job.PointsLeft == material.RefineryPointCost)
                        {
                            //consume all ingredients for this job on the first point use.
                            if (StorageSpaceProcessor.HasReqiredItems(stockpiles, costs))
                            {
                                StorageSpaceProcessor.RemoveResources(stockpiles, costs);
                            }
                            else
                            {
                                break;
                            }
                        }

                        //use Refinery points
                        ushort pointsUsed = (ushort)Math.Min(job.PointsLeft, material.RefineryPointCost);
                        job.PointsLeft -= pointsUsed;
                        RefineryPoints -= pointsUsed;

                        //if job is complete
                        if (job.PointsLeft == 0)
                        {
                            job.NumberCompleted++;                                                                //complete job,
                            StorageSpaceProcessor.AddItemToCargo(stockpiles, material.ID, material.OutputAmount); //and add the product to the stockpile
                            job.PointsLeft = material.RefineryPointCost;                                          //and reset the points left for the next job in the batch.
                        }
                    }
                    //if the whole batch is completed
                    if (job.NumberCompleted == job.NumberOrdered)
                    {
                        //remove it from the list
                        refiningDB.JobBatchList.RemoveAt(jobIndex);
                        if (job.Auto) //but if it's set to auto, re-add it.
                        {
                            job.PointsLeft      = material.RefineryPointCost;
                            job.NumberCompleted = 0;
                            refiningDB.JobBatchList.Add(job);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public static void StartNonNewtTranslation(Entity entity)
        {
            var moveDB       = entity.GetDataBlob <TranslateMoveDB>();
            var propulsionDB = entity.GetDataBlob <PropulsionAbilityDB>();
            var positionDB   = entity.GetDataBlob <PositionDB>();
            var maxSpeedMS   = propulsionDB.MaximumSpeed_MS;

            positionDB.SetParent(null);
            Vector3 targetPosMt       = Distance.AuToMt(moveDB.TranslateExitPoint_AU);
            Vector3 currentPositionMt = Distance.AuToMt(positionDB.AbsolutePosition_AU);

            Vector3 postionDelta  = currentPositionMt - targetPosMt;
            double  totalDistance = postionDelta.Length();

            double maxKMeters        = ShipMovementProcessor.CalcMaxFuelDistance_KM(entity);
            double fuelMaxDistanceMt = maxKMeters * 1000;

            if (fuelMaxDistanceMt >= totalDistance)
            {
                var currentVelocityMS = Vector3.Normalise(targetPosMt - currentPositionMt) * maxSpeedMS;
                propulsionDB.CurrentVectorMS       = currentVelocityMS;
                moveDB.CurrentNonNewtonionVectorMS = currentVelocityMS;
                moveDB.LastProcessDateTime         = entity.Manager.ManagerSubpulses.StarSysDateTime;

                CargoStorageDB storedResources = entity.GetDataBlob <CargoStorageDB>();
                foreach (var item in propulsionDB.FuelUsePerKM)
                {
                    var fuel = staticData.GetICargoable(item.Key);
                    StorageSpaceProcessor.RemoveCargo(storedResources, fuel, (long)(item.Value * totalDistance / 1000));
                }
            }
        }
 /// <summary>
 /// consumes resources in the stockpile, and updates the dictionary.
 /// </summary>
 /// <param name="stockpile"></param>
 /// <param name="toUse"></param>
 private static void ConsumeResources(CargoStorageDB stockpile, IDictionary <Guid, int> toUse)
 {
     foreach (KeyValuePair <Guid, int> kvp in toUse.ToArray())
     {
         int amountUsedThisTick = (int)StorageSpaceProcessor.SubtractValue(stockpile, kvp.Key, kvp.Value);
         toUse[kvp.Key] -= amountUsedThisTick;
     }
 }
 public void OnComponentInstalation(Entity parentEntity, Entity componentInstance)
 {
     if (!parentEntity.HasDataBlob <CargoStorageDB>())
     {
         parentEntity.SetDataBlob(new CargoStorageDB());
     }
     StorageSpaceProcessor.ReCalcCapacity(parentEntity);
 }
Beispiel #9
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <VolumeStorageDB>())
     {
         var newdb = new VolumeStorageDB();
         parentEntity.SetDataBlob(newdb);
     }
     StorageSpaceProcessor.RecalcVolumeCapacityAndRates(parentEntity);
 }
Beispiel #10
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <CargoStorageDB>())
     {
         var db = new CargoStorageDB();
         parentEntity.SetDataBlob(db);
         StorageSpaceProcessor.ReCalcCapacity(parentEntity);
     }
 }
Beispiel #11
0
        /// <summary>
        /// calculates, sets and returns DV.
        /// </summary>
        /// <param name="parentEntity"></param>
        /// <returns></returns>
        public static double CalcDeltaV(Entity parentEntity)
        {
            var db = parentEntity.GetDataBlob <NewtonThrustAbilityDB>();
            var ft = db.FuelType;
            var ev = db.ExhaustVelocity;

            var wetmass = parentEntity.GetDataBlob <MassVolumeDB>().Mass;
            ProcessedMaterialSD fuel = StaticRefLib.StaticData.CargoGoods.GetMaterials()[ft];
            var cargo      = parentEntity.GetDataBlob <CargoStorageDB>();
            var fuelAmount = StorageSpaceProcessor.GetAmount(cargo, fuel);
            var dryMass    = wetmass - fuelAmount;

            return(db.DeltaV = OrbitMath.TsiolkovskyRocketEquation(wetmass, dryMass, ev));
        }
Beispiel #12
0
        public void OnConstructionComplete(Entity industryEntity, CargoStorageDB storage, Guid productionLine, IndustryJob batchJob, IConstrucableDesign designInfo)
        {
            var industryDB = industryEntity.GetDataBlob <IndustryAbilityDB>();
            ProcessedMaterialSD material = (ProcessedMaterialSD)designInfo;

            StorageSpaceProcessor.AddCargo(storage, material, material.OutputAmount); //and add the product to the stockpile
            batchJob.ProductionPointsLeft = material.IndustryPointCosts;              //and reset the points left for the next job in the batch.

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                industryDB.ProductionLines[productionLine].Jobs.Remove(batchJob);
                if (batchJob.Auto)
                {
                    industryDB.ProductionLines[productionLine].Jobs.Add(batchJob);
                }
            }
        }
        public static int CalcMaxFuelDistance(Entity shipEntity)
        {
            CargoStorageDB  storedResources = shipEntity.GetDataBlob <CargoStorageDB>();
            PropulsionDB    propulsionDB    = shipEntity.GetDataBlob <PropulsionDB>();
            StaticDataStore staticData      = shipEntity.Manager.Game.StaticData;
            ICargoable      resource        = (ICargoable)staticData.FindDataObjectUsingID(propulsionDB.FuelUsePerKM.Keys.First());
            int             kmeters         = (int)(StorageSpaceProcessor.GetAmountOf(storedResources, resource.ID) / propulsionDB.FuelUsePerKM[resource.ID]);

            foreach (var usageKVP in propulsionDB.FuelUsePerKM)
            {
                resource = (ICargoable)staticData.FindDataObjectUsingID(usageKVP.Key);
                if (kmeters > (StorageSpaceProcessor.GetAmountOf(storedResources, usageKVP.Key) / usageKVP.Value))
                {
                    kmeters = (int)(StorageSpaceProcessor.GetAmountOf(storedResources, usageKVP.Key) / usageKVP.Value);
                }
            }
            return(kmeters);
        }
Beispiel #14
0
        private void MineResources(Entity colonyEntity)
        {
            Dictionary <Guid, int> mineRates = colonyEntity.GetDataBlob <MiningDB>().MineingRate;
            Dictionary <Guid, MineralDepositInfo> planetMinerals = colonyEntity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <SystemBodyInfoDB>().Minerals;

            CargoStorageDB stockpile   = colonyEntity.GetDataBlob <CargoStorageDB>();
            float          mineBonuses = 1;//colonyEntity.GetDataBlob<ColonyBonusesDB>().GetBonus(AbilityType.Mine);

            foreach (var kvp in mineRates)
            {
                ICargoable mineral         = _minerals[kvp.Key];
                Guid       cargoTypeID     = mineral.CargoTypeID;
                int        itemMassPerUnit = mineral.Mass;


                double accessability         = planetMinerals[kvp.Key].Accessibility;
                double actualRate            = kvp.Value * mineBonuses * accessability;
                int    amountMinableThisTick = (int)Math.Min(actualRate, planetMinerals[kvp.Key].Amount);

                long freeCapacity = stockpile.StoredCargoTypes[mineral.CargoTypeID].FreeCapacity;

                long weightMinableThisTick = itemMassPerUnit * amountMinableThisTick;
                weightMinableThisTick = Math.Min(weightMinableThisTick, freeCapacity);

                int  actualAmountToMineThisTick = (int)(weightMinableThisTick / itemMassPerUnit);                                        //get the number of items from the mass transferable
                long actualweightMinaedThisTick = actualAmountToMineThisTick * itemMassPerUnit;

                StorageSpaceProcessor.AddCargo(stockpile, mineral, actualAmountToMineThisTick);

                MineralDepositInfo mineralDeposit = planetMinerals[kvp.Key];
                int newAmount = mineralDeposit.Amount -= actualAmountToMineThisTick;

                accessability = Math.Pow((float)mineralDeposit.Amount / mineralDeposit.HalfOriginalAmount, 3) * mineralDeposit.Accessibility;
                double newAccess = GMath.Clamp(accessability, 0.1, mineralDeposit.Accessibility);

                mineralDeposit.Amount        = newAmount;
                mineralDeposit.Accessibility = newAccess;
            }
        }
        /// <summary>
        /// process PropulsionDB movement for a single system
        /// </summary>
        /// <param name="manager">the system to process</param>
        /// <param name="deltaSeconds">amount of time in seconds</param>
        internal static void Process(EntityManager manager, int deltaSeconds)
        {
            OrderProcessor.ProcessSystem(manager);
            foreach (Entity shipEntity in manager.GetAllEntitiesWithDataBlob <PropulsionDB>())
            {
                PositionDB   positionDB   = shipEntity.GetDataBlob <PositionDB>();
                PropulsionDB propulsionDB = shipEntity.GetDataBlob <PropulsionDB>();


                Queue <BaseOrder> orders = shipEntity.GetDataBlob <ShipInfoDB>().Orders;

                if (orders.Count > 0)
                {
                    if (orders.Peek().OrderType == orderType.MOVETO)
                    {
                        // Check to see if we will overtake the target

                        MoveOrder order   = (MoveOrder)orders.Peek();
                        Vector4   shipPos = positionDB.AbsolutePosition;
                        Vector4   targetPos;
                        Vector4   currentSpeed = shipEntity.GetDataBlob <PropulsionDB>().CurrentSpeed;
                        Vector4   nextTPos     = shipPos + (currentSpeed * deltaSeconds);
                        Vector4   newPos       = shipPos;
                        Vector4   deltaVecToTarget;
                        Vector4   deltaVecToNextT;

                        double distanceToTarget;
                        double distanceToNextTPos;

                        double speedDelta;
                        double distanceDelta;
                        double newDistanceDelta;
                        double fuelMaxDistanceAU;

                        double currentSpeedLength = currentSpeed.Length();

                        CargoStorageDB            storedResources = shipEntity.GetDataBlob <CargoStorageDB>();
                        Dictionary <Guid, double> fuelUsePerMeter = propulsionDB.FuelUsePerKM;
                        int maxKMeters = CalcMaxFuelDistance(shipEntity);

                        if (order.PositionTarget == null)
                        {
                            targetPos = order.Target.GetDataBlob <PositionDB>().AbsolutePosition;
                        }
                        else
                        {
                            targetPos = order.PositionTarget.AbsolutePosition;
                        }

                        deltaVecToTarget = shipPos - targetPos;

                        distanceToTarget = deltaVecToTarget.Length();  //in au


                        deltaVecToNextT   = shipPos - nextTPos;
                        fuelMaxDistanceAU = GameConstants.Units.KmPerAu * maxKMeters;


                        distanceToNextTPos = deltaVecToNextT.Length();
                        if (fuelMaxDistanceAU < distanceToNextTPos)
                        {
                            newDistanceDelta = fuelMaxDistanceAU;
                            double percent = fuelMaxDistanceAU / distanceToNextTPos;
                            newPos = nextTPos + deltaVecToNextT * percent;
                            Event usedAllFuel = new Event(manager.ManagerSubpulses.SystemLocalDateTime, "Used all Fuel", shipEntity.GetDataBlob <OwnedDB>().ObjectOwner, shipEntity);
                            usedAllFuel.EventType = EventType.FuelExhausted;
                            manager.Game.EventLog.AddEvent(usedAllFuel);
                        }
                        else
                        {
                            newDistanceDelta = distanceToNextTPos;
                            newPos           = nextTPos;
                        }



                        if (distanceToTarget < newDistanceDelta) // moving would overtake target, just go directly to target
                        {
                            newDistanceDelta          = distanceToTarget;
                            propulsionDB.CurrentSpeed = new Vector4(0, 0, 0, 0);
                            newPos = targetPos;
                            if (order.Target != null && order.Target.HasDataBlob <SystemBodyInfoDB>())
                            {
                                positionDB.SetParent(order.Target);
                            }
                            if (order.Target != null)
                            {
                                if (order.Target.HasDataBlob <SystemBodyInfoDB>())  // Set position to the target body
                                {
                                    positionDB.SetParent(order.Target);
                                }
                            }

                            else // We arrived, get rid of the order
                            {
                                shipEntity.GetDataBlob <ShipInfoDB>().Orders.Dequeue();
                            }
                        }
                        positionDB.AbsolutePosition = newPos;
                        int kMetersMoved = (int)(newDistanceDelta * GameConstants.Units.KmPerAu);
                        Dictionary <Guid, int> fuelAmounts = new Dictionary <Guid, int>();
                        foreach (var item in propulsionDB.FuelUsePerKM)
                        {
                            fuelAmounts.Add(item.Key, (int)item.Value * kMetersMoved);
                        }
                        StorageSpaceProcessor.RemoveResources(storedResources, fuelAmounts);
                    }
                }
            }
        }
Beispiel #16
0
        public static Entity DefaultHumans(Game game, Player owner, string name)
        {
            StarSystemFactory starfac       = new StarSystemFactory(game);
            StarSystem        sol           = starfac.CreateSol(game);
            Entity            earth         = sol.SystemManager.Entities[3]; //should be fourth entity created
            Entity            factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity            speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);
            Entity            colonyEntity  = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);

            ComponentTemplateSD mineSD     = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesign     mineDesign = GenericComponentFactory.StaticToDesign(mineSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity mineEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, mineDesign);


            ComponentTemplateSD RefinerySD     = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesign     RefineryDesign = GenericComponentFactory.StaticToDesign(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity RefineryEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, RefineryDesign);

            ComponentTemplateSD labSD     = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesign     labDesign = GenericComponentFactory.StaticToDesign(labSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity labEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, labDesign);

            ComponentTemplateSD facSD     = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesign     facDesign = GenericComponentFactory.StaticToDesign(facSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity facEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, facDesign);

            Entity scientistEntity = CommanderFactory.CreateScientist(game.GlobalManager, factionEntity);

            colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists.Add(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            TechProcessor.MakeResearchable(factionTech);
            Entity fuelTank         = DefaultFuelTank(game, factionEntity);
            Entity cargoInstalation = DefaultCargoInstalation(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, mineEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, RefineryEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, fuelTank);

            EntityManipulation.AddComponentToEntity(colonyEntity, cargoInstalation);
            ReCalcProcessor.ReCalcAbilities(colonyEntity);
            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;



            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid);
            //test systems
            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).Guid);
            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).Guid);



            // Todo: handle this in CreateShip
            Entity shipClass    = DefaultShipDesign(game, factionEntity);
            Entity gunShipClass = GunShipDesign(game, factionEntity);

            Vector4 position = earth.GetDataBlob <PositionDB>().AbsolutePosition;


            // Problem - the component instances, both the design and the instances themselves, are the same entities on each ship
            // IE, the fire control on ship1 is the same entity as on ship2
            // Both the design and instances should be unique

            Entity ship1 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            Entity ship2 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Ensuing Calm");

            StorageSpaceProcessor.AddItemToCargo(ship1.GetDataBlob <CargoStorageDB>(), new Guid("33e6ac88-0235-4917-a7ff-35c8886aad3a"), 200000000000);
            StorageSpaceProcessor.AddItemToCargo(ship2.GetDataBlob <CargoStorageDB>(), new Guid("33e6ac88-0235-4917-a7ff-35c8886aad3a"), 200000000000);
            // Strange bug - seems to update the ship orbit once, then never again
            // TODO: Fix to allow normal orbiting.
            //ship.SetDataBlob<OrbitDB>(new OrbitDB(earth.GetDataBlob<OrbitDB>()));

            Entity gunShip = ShipFactory.CreateShip(gunShipClass, sol.SystemManager, factionEntity, position, sol, "Prevailing Stillness");

            StorageSpaceProcessor.AddItemToCargo(gunShipClass.GetDataBlob <CargoStorageDB>(), new Guid("33e6ac88-0235-4917-a7ff-35c8886aad3a"), 2000000000);

            sol.SystemManager.SetDataBlob(ship1.ID, new TransitableDB());
            sol.SystemManager.SetDataBlob(ship2.ID, new TransitableDB());
            sol.SystemManager.SetDataBlob(gunShip.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            Entity rock = AsteroidFactory.CreateAsteroid(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));

            return(factionEntity);
        }
Beispiel #17
0
        public static Entity DefaultHumans(Game game, Player owner, string name)
        {
            StarSystemFactory starfac = new StarSystemFactory(game);
            StarSystem        sol     = starfac.CreateSol(game);
            //sol.ManagerSubpulses.Init(sol);
            Entity earth         = sol.Entities[3]; //should be fourth entity created
            Entity factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);
            Entity colonyEntity  = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);

            var namedEntites = sol.GetAllEntitiesWithDataBlob <NameDB>();

            foreach (var entity in namedEntites)
            {
                var nameDB = entity.GetDataBlob <NameDB>();
                nameDB.SetName(factionEntity, nameDB.DefaultName);
            }


            ComponentTemplateSD mineSD     = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesign     mineDesign = GenericComponentFactory.StaticToDesign(mineSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity mineEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, mineDesign);


            ComponentTemplateSD RefinerySD     = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesign     RefineryDesign = GenericComponentFactory.StaticToDesign(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity RefineryEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, RefineryDesign);

            ComponentTemplateSD labSD     = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesign     labDesign = GenericComponentFactory.StaticToDesign(labSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity labEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, labDesign);

            ComponentTemplateSD facSD     = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesign     facDesign = GenericComponentFactory.StaticToDesign(facSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity facEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, facDesign);

            Entity scientistEntity = CommanderFactory.CreateScientist(game.GlobalManager, factionEntity);

            colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists.Add(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            ResearchProcessor.MakeResearchable(factionTech);
            Entity fuelTank         = DefaultFuelTank(game, factionEntity);
            Entity cargoInstalation = DefaultCargoInstalation(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, mineEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, RefineryEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, fuelTank);

            EntityManipulation.AddComponentToEntity(colonyEntity, cargoInstalation);
            EntityManipulation.AddComponentToEntity(colonyEntity, FacPassiveSensor(game, factionEntity));
            ReCalcProcessor.ReCalcAbilities(colonyEntity);
            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;
            var rawSorium = NameLookup.TryGetMineralSD(game, "Sorium");

            StorageSpaceProcessor.AddCargo(colonyEntity.GetDataBlob <CargoStorageDB>(), rawSorium, 5000);


            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid);
            var facSystemInfo = FactionFactory.CreateSystemFactionEntity(game, factionEntity, sol);

            //test systems
            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).Guid);
            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).Guid);


            factionEntity.GetDataBlob <NameDB>().SetName(factionEntity, "UEF");


            // Todo: handle this in CreateShip
            Entity shipClass    = DefaultShipDesign(game, factionEntity);
            Entity gunShipClass = GunShipDesign(game, factionEntity);

            Entity ship1 = ShipFactory.CreateShip(shipClass, sol, factionEntity, earth, sol, "Serial Peacemaker");
            Entity ship2 = ShipFactory.CreateShip(shipClass, sol, factionEntity, earth, sol, "Ensuing Calm");
            var    fuel  = NameLookup.TryGetMaterialSD(game, "Sorium Fuel");

            StorageSpaceProcessor.AddCargo(ship1.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            StorageSpaceProcessor.AddCargo(ship2.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);


            Entity gunShip = ShipFactory.CreateShip(gunShipClass, sol, factionEntity, earth, sol, "Prevailing Stillness");

            StorageSpaceProcessor.AddCargo(gunShipClass.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);

            sol.SetDataBlob(ship1.ID, new TransitableDB());
            sol.SetDataBlob(ship2.ID, new TransitableDB());
            sol.SetDataBlob(gunShip.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            Entity rock = AsteroidFactory.CreateAsteroid(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));

            return(factionEntity);
        }
        public void ProcessEntity(Entity entity, int deltaSeconds)
        {
            var manager      = entity.Manager;
            var moveDB       = entity.GetDataBlob <TranslateMoveDB>();
            var propulsionDB = entity.GetDataBlob <PropulsionDB>();
            //var currentVector = propulsionDB.CurrentSpeed;
            var maxSpeed        = propulsionDB.MaximumSpeed;
            var positionDB      = entity.GetDataBlob <PositionDB>();
            var currentPosition = positionDB.AbsolutePosition;
            //targetPosition taking the range (how close we want to get) into account.
            var targetPos = moveDB.TargetPosition * (1 - (moveDB.MoveRangeInKM / GameConstants.Units.KmPerAu) / moveDB.TargetPosition.Length());

            var deltaVecToTarget = currentPosition - targetPos;


            var currentSpeed = GMath.GetVector(currentPosition, targetPos, maxSpeed);

            propulsionDB.CurrentVector = currentSpeed;
            moveDB.CurrentVector       = currentSpeed;
            StaticDataStore           staticData      = entity.Manager.Game.StaticData;
            CargoStorageDB            storedResources = entity.GetDataBlob <CargoStorageDB>();
            Dictionary <Guid, double> fuelUsePerMeter = propulsionDB.FuelUsePerKM;
            double maxKMeters = ShipMovementProcessor.CalcMaxFuelDistance(entity);

            var nextTPos = currentPosition + (currentSpeed * deltaSeconds);


            var distanceToTargetAU = deltaVecToTarget.Length();  //in au

            var deltaVecToNextT   = currentPosition - nextTPos;
            var fuelMaxDistanceAU = maxKMeters / GameConstants.Units.KmPerAu;



            Vector4 newPos = currentPosition;

            double distanceToNextTPos = deltaVecToNextT.Length();
            double distanceToMove;

            if (fuelMaxDistanceAU < distanceToNextTPos)
            {
                distanceToMove = fuelMaxDistanceAU;
                double percent = fuelMaxDistanceAU / distanceToNextTPos;
                newPos = nextTPos + deltaVecToNextT * percent;
                Event usedAllFuel = new Event(manager.ManagerSubpulses.SystemLocalDateTime, "Used all Fuel", entity.GetDataBlob <OwnedDB>().OwnedByFaction, entity);
                usedAllFuel.EventType = EventType.FuelExhausted;
                manager.Game.EventLog.AddEvent(usedAllFuel);
            }
            else
            {
                distanceToMove = distanceToNextTPos;
                newPos         = nextTPos;
            }



            if (distanceToTargetAU < distanceToMove) // moving would overtake target, just go directly to target
            {
                distanceToMove             = distanceToTargetAU;
                propulsionDB.CurrentVector = new Vector4(0, 0, 0, 0);
                newPos            = targetPos;
                moveDB.IsAtTarget = true;
                entity.RemoveDataBlob <TranslateMoveDB>();
            }

            positionDB.AbsolutePosition = newPos;
            int kMetersMoved = (int)(distanceToMove * GameConstants.Units.KmPerAu);

            foreach (var item in propulsionDB.FuelUsePerKM)
            {
                var fuel = staticData.GetICargoable(item.Key);
                StorageSpaceProcessor.RemoveCargo(storedResources, fuel, (long)(item.Value * kMetersMoved));
            }
        }
        public static Entity DefaultHumans(Game game, string name)
        {
            StarSystemFactory starfac = new StarSystemFactory(game);
            StarSystem        solSys  = starfac.CreateSol(game);
            //sol.ManagerSubpulses.Init(sol);
            Entity solStar = solSys.Entities[0];
            Entity earth   = solSys.Entities[3]; //should be fourth entity created
            //Entity factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity factionEntity = FactionFactory.CreateFaction(game, name);
            Entity speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);

            var namedEntites = solSys.GetAllEntitiesWithDataBlob <NameDB>();

            foreach (var entity in namedEntites)
            {
                var nameDB = entity.GetDataBlob <NameDB>();
                nameDB.SetName(factionEntity.Guid, nameDB.DefaultName);
            }

            Entity colonyEntity = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);
            Entity marsColony   = ColonyFactory.CreateColony(factionEntity, speciesEntity, NameLookup.GetFirstEntityWithName(solSys, "Mars"));

            ComponentTemplateSD mineSD     = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesign     mineDesign = GenericComponentFactory.StaticToDesign(mineSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity mineEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, mineDesign);


            ComponentTemplateSD RefinerySD     = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesign     RefineryDesign = GenericComponentFactory.StaticToDesign(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity RefineryEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, RefineryDesign);

            ComponentTemplateSD labSD     = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesign     labDesign = GenericComponentFactory.StaticToDesign(labSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity labEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, labDesign);

            ComponentTemplateSD facSD     = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesign     facDesign = GenericComponentFactory.StaticToDesign(facSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity facEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, facDesign);

            Entity scientistEntity = CommanderFactory.CreateScientist(game.GlobalManager, factionEntity);

            colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists.Add(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            ResearchProcessor.MakeResearchable(factionTech);
            Entity fuelTank         = DefaultFuelTank(game, factionEntity);
            Entity cargoInstalation = DefaultCargoInstalation(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, mineEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, RefineryEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, fuelTank);

            EntityManipulation.AddComponentToEntity(colonyEntity, cargoInstalation);
            EntityManipulation.AddComponentToEntity(marsColony, cargoInstalation);
            Entity colonySensor = FacPassiveSensor(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, colonySensor);
            ReCalcProcessor.ReCalcAbilities(colonyEntity);


            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;
            var rawSorium = NameLookup.GetMineralSD(game, "Sorium");

            StorageSpaceProcessor.AddCargo(colonyEntity.GetDataBlob <CargoStorageDB>(), rawSorium, 5000);


            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(solSys.Guid);

            //test systems
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).Guid);
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).Guid);


            factionEntity.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "UEF");


            // Todo: handle this in CreateShip
            Entity shipClass    = DefaultShipDesign(game, factionEntity);
            Entity gunShipClass = GunShipDesign(game, factionEntity);

            Entity ship1 = ShipFactory.CreateShip(shipClass, solSys, factionEntity, earth, solSys, "Serial Peacemaker");
            Entity ship2 = ShipFactory.CreateShip(shipClass, solSys, factionEntity, earth, solSys, "Ensuing Calm");
            Entity ship3 = ShipFactory.CreateShip(shipClass, solSys, factionEntity, earth, solSys, "Touch-and-Go");
            var    fuel  = NameLookup.GetMaterialSD(game, "Sorium Fuel");

            StorageSpaceProcessor.AddCargo(ship1.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            StorageSpaceProcessor.AddCargo(ship2.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            StorageSpaceProcessor.AddCargo(ship3.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);



            double  test_a           = 0.5; //AU
            double  test_e           = 0;
            double  test_i           = 0;   //°
            double  test_loan        = 0;   //°
            double  test_aop         = 0;   //°
            double  test_M0          = 0;   //°
            double  test_bodyMass    = ship2.GetDataBlob <MassVolumeDB>().Mass;
            OrbitDB testOrbtdb_ship2 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().Mass, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship2.RemoveDataBlob <OrbitDB>();
            ship2.SetDataBlob(testOrbtdb_ship2);
            ship2.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship2, 0);

            test_a   = 0.51;
            test_i   = 180;
            test_aop = 0;
            OrbitDB testOrbtdb_ship3 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().Mass, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship3.RemoveDataBlob <OrbitDB>();
            ship3.SetDataBlob(testOrbtdb_ship3);
            ship3.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship3, 0);


            Entity gunShip = ShipFactory.CreateShip(gunShipClass, solSys, factionEntity, earth, solSys, "Prevailing Stillness");

            gunShip.GetDataBlob <PositionDB>().RelativePosition_AU = new Vector3(8.52699302490434E-05, 0, 0);
            StorageSpaceProcessor.AddCargo(gunShipClass.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            //give the gunship a hypobolic orbit to test:
            var velInAU = Distance.KmToAU(25);

            //var orbit = OrbitDB.FromVector(earth, gunShip, new Vector4(0, velInAU, 0, 0), game.CurrentDateTime);
            gunShip.RemoveDataBlob <OrbitDB>();
            var nmdb = new NewtonMoveDB(earth)
            {
                CurrentVector_kms = new Vector3(0, -10.0, 0)
            };

            gunShip.SetDataBlob <NewtonMoveDB>(nmdb);

            Entity courier = ShipFactory.CreateShip(CargoShipDesign(game, factionEntity), solSys, factionEntity, earth, solSys, "Planet Express Ship");

            StorageSpaceProcessor.AddCargo(courier.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);

            solSys.SetDataBlob(ship1.ID, new TransitableDB());
            solSys.SetDataBlob(ship2.ID, new TransitableDB());
            solSys.SetDataBlob(gunShip.ID, new TransitableDB());
            solSys.SetDataBlob(courier.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            //Entity rock = AsteroidFactory.CreateAsteroid2(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));
            Entity rock = AsteroidFactory.CreateAsteroid3(solSys, earth, StaticRefLib.CurrentDateTime + TimeSpan.FromDays(365));

            var entitiesWithSensors = solSys.GetAllEntitiesWithDataBlob <SensorReceverAtbDB>();

            foreach (var entityItem in entitiesWithSensors)
            {
                if (entityItem.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity != null) //don't do the designs, just the actual physical entity components.
                {
                    StaticRefLib.ProcessorManager.GetInstanceProcessor(nameof(SensorScan)).ProcessEntity(entityItem, StaticRefLib.CurrentDateTime);
                }
            }



            return(factionEntity);
        }
Beispiel #20
0
        public static Entity DefaultHumans(Game game, string name)
        {
            //USE THIS TO TEST CODE
            //TESTING STUFFF
            //return completeTest(game, name);
            // while(true){

            //}
            //TESTING STUFF
            var log = StaticRefLib.EventLog;
            StarSystemFactory starfac = new StarSystemFactory(game);
            StarSystem        solSys  = starfac.CreateSol(game);
            //sol.ManagerSubpulses.Init(sol);
            Entity solStar = solSys.Entities[0];
            Entity earth   = solSys.Entities[3]; //should be fourth entity created
            //Entity factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity factionEntity = FactionFactory.CreateFaction(game, name);
            Entity speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);

            var namedEntites = solSys.GetAllEntitiesWithDataBlob <NameDB>();

            foreach (var entity in namedEntites)
            {
                var nameDB = entity.GetDataBlob <NameDB>();
                nameDB.SetName(factionEntity.Guid, nameDB.DefaultName);
            }

            Entity colonyEntity = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);
            Entity marsColony   = ColonyFactory.CreateColony(factionEntity, speciesEntity, NameLookup.GetFirstEntityWithName(solSys, "Mars"));

            ComponentTemplateSD mineSD       = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesigner   mineDesigner = new ComponentDesigner(mineSD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     mineDesign   = mineDesigner.CreateDesign(factionEntity);


            ComponentTemplateSD RefinerySD       = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesigner   refineryDesigner = new ComponentDesigner(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     refinaryDesign   = refineryDesigner.CreateDesign(factionEntity);

            ComponentTemplateSD labSD       = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesigner   labDesigner = new ComponentDesigner(labSD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     labEntity   = labDesigner.CreateDesign(factionEntity);

            ComponentTemplateSD facSD       = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesigner   facDesigner = new ComponentDesigner(facSD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     facEntity   = facDesigner.CreateDesign(factionEntity);

            Scientist scientistEntity = CommanderFactory.CreateScientist(factionEntity, colonyEntity);

            colonyEntity.GetDataBlob <TeamsHousedDB>().AddTeam(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new ID("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            ResearchProcessor.CheckRequrements(factionTech);

            DefaultThrusterDesign(game, factionEntity);
            DefaultWarpDesign(game, factionEntity);
            DefaultFuelTank(game, factionEntity);
            DefaultCargoInstalation(game, factionEntity);
            DefaultSimpleLaser(game, factionEntity);
            DefaultBFC(game, factionEntity);
            ShipDefaultCargoHold(game, factionEntity);
            ShipSmallCargo(game, factionEntity);
            ShipPassiveSensor(game, factionEntity);
            FacPassiveSensor(game, factionEntity);
            DefaultFisionReactor(game, factionEntity);
            DefaultBatteryBank(game, factionEntity);
            DefaultFragPayload(game, factionEntity);
            DefaultMissileSRB(game, factionEntity);
            DefaultMissileSensors(game, factionEntity);
            DefaultMissileTube(game, factionEntity);
            MissileDesign250(game, factionEntity);
            ShipSmallOrdnanceStore(game, factionEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, mineDesign);
            EntityManipulation.AddComponentToEntity(colonyEntity, refinaryDesign);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, _fuelTank_500);

            EntityManipulation.AddComponentToEntity(colonyEntity, _cargoInstalation);
            EntityManipulation.AddComponentToEntity(marsColony, _cargoInstalation);

            EntityManipulation.AddComponentToEntity(colonyEntity, _sensorInstalation);
            EntityManipulation.AddComponentToEntity(colonyEntity, SpacePort(factionEntity));
            ReCalcProcessor.ReCalcAbilities(colonyEntity);


            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;
            var rawSorium = NameLookup.GetMineralSD(game, "Sorium");

            StorageSpaceProcessor.AddCargo(colonyEntity.GetDataBlob <CargoStorageDB>(), rawSorium, 5000);
            var iron = NameLookup.GetMineralSD(game, "Iron");

            StorageSpaceProcessor.AddCargo(colonyEntity.GetDataBlob <CargoStorageDB>(), iron, 5000);
            var hydrocarbon = NameLookup.GetMineralSD(game, "Hydrocarbons");

            StorageSpaceProcessor.AddCargo(colonyEntity.GetDataBlob <CargoStorageDB>(), hydrocarbon, 5000);
            var stainless = NameLookup.GetMaterialSD(game, "Stainless Steel");

            StorageSpaceProcessor.AddCargo(colonyEntity.GetDataBlob <CargoStorageDB>(), stainless, 1000);
            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(solSys.Guid);



            //test systems
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).ID);
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).ID);


            factionEntity.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "UEF");


            // Todo: handle this in CreateShip
            ShipDesign shipDesign    = DefaultShipDesign(game, factionEntity);
            ShipDesign gunShipDesign = GunShipDesign(game, factionEntity);

            Entity ship1   = ShipFactory.CreateShip(shipDesign, factionEntity, earth, solSys, "Serial Peacemaker");
            Entity ship2   = ShipFactory.CreateShip(shipDesign, factionEntity, earth, solSys, "Ensuing Calm");
            Entity ship3   = ShipFactory.CreateShip(shipDesign, factionEntity, earth, solSys, "Touch-and-Go");
            Entity gunShip = ShipFactory.CreateShip(gunShipDesign, factionEntity, earth, solSys, "Prevailing Stillness");
            Entity courier = ShipFactory.CreateShip(CargoShipDesign(game, factionEntity), factionEntity, earth, solSys, "Planet Express Ship");
            var    fuel    = NameLookup.GetMaterialSD(game, "Sorium Fuel");
            var    rp1     = NameLookup.GetMaterialSD(game, "LOX/Hydrocarbon");

            StorageSpaceProcessor.AddCargo(ship1.GetDataBlob <CargoStorageDB>(), rp1, 15000);
            StorageSpaceProcessor.AddCargo(ship2.GetDataBlob <CargoStorageDB>(), rp1, 15000);
            StorageSpaceProcessor.AddCargo(ship3.GetDataBlob <CargoStorageDB>(), rp1, 15000);
            StorageSpaceProcessor.AddCargo(gunShip.GetDataBlob <CargoStorageDB>(), rp1, 15000);
            StorageSpaceProcessor.AddCargo(gunShip.GetDataBlob <CargoStorageDB>(), MissileDesign250(game, factionEntity), 20);
            StorageSpaceProcessor.AddCargo(courier.GetDataBlob <CargoStorageDB>(), rp1, 15000);
            var elec = NameLookup.GetMaterialSD(game, "Electrical Energy");

            ship1.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID]   = 2750;
            ship2.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID]   = 2750;
            ship3.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID]   = 2750;
            gunShip.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID] = 2750;
            courier.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID] = 2750;



            NewtonionMovementProcessor.CalcDeltaV(ship1);
            NewtonionMovementProcessor.CalcDeltaV(ship2);
            NewtonionMovementProcessor.CalcDeltaV(ship3);
            NewtonionMovementProcessor.CalcDeltaV(gunShip);
            NewtonionMovementProcessor.CalcDeltaV(courier);
            //StorageSpaceProcessor.AddCargo(ship1.GetDataBlob<CargoStorageDB>(), fuel, 200000000000);
            //StorageSpaceProcessor.AddCargo(ship2.GetDataBlob<CargoStorageDB>(), fuel, 200000000000);
            //StorageSpaceProcessor.AddCargo(ship3.GetDataBlob<CargoStorageDB>(), fuel, 200000000000);


            double  test_a           = 0.5; //AU
            double  test_e           = 0;
            double  test_i           = 0;   //°
            double  test_loan        = 0;   //°
            double  test_aop         = 0;   //°
            double  test_M0          = 0;   //°
            double  test_bodyMass    = ship2.GetDataBlob <MassVolumeDB>().Mass;
            OrbitDB testOrbtdb_ship2 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().Mass, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship2.RemoveDataBlob <OrbitDB>();
            ship2.SetDataBlob(testOrbtdb_ship2);
            ship2.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship2, 0);

            test_a   = 0.51;
            test_i   = 180;
            test_aop = 0;
            OrbitDB testOrbtdb_ship3 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().Mass, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship3.RemoveDataBlob <OrbitDB>();
            ship3.SetDataBlob(testOrbtdb_ship3);
            ship3.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship3, 0);


            gunShip.GetDataBlob <PositionDB>().RelativePosition_AU = new Vector3(8.52699302490434E-05, 0, 0);
            //give the gunship a hypobolic orbit to test:
            //var orbit = OrbitDB.FromVector(earth, gunShip, new Vector4(0, velInAU, 0, 0), game.CurrentDateTime);
            gunShip.RemoveDataBlob <OrbitDB>();
            var nmdb = new NewtonMoveDB(earth, new Vector3(0, -10000.0, 0));

            gunShip.SetDataBlob <NewtonMoveDB>(nmdb);



            solSys.SetDataBlob(ship1.ID, new TransitableDB());
            solSys.SetDataBlob(ship2.ID, new TransitableDB());
            solSys.SetDataBlob(gunShip.ID, new TransitableDB());
            solSys.SetDataBlob(courier.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipDesign, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipDesign, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            //Entity rock = AsteroidFactory.CreateAsteroid2(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));
            Entity rock = AsteroidFactory.CreateAsteroid(solSys, earth, StaticRefLib.CurrentDateTime + TimeSpan.FromDays(365));


            var pow = solSys.GetAllEntitiesWithDataBlob <EnergyGenAbilityDB>();

            foreach (var entityItem in pow)
            {
                StaticRefLib.ProcessorManager.GetInstanceProcessor(nameof(EnergyGenProcessor)).ProcessEntity(entityItem, StaticRefLib.CurrentDateTime);
            }

            var entitiesWithSensors = solSys.GetAllEntitiesWithDataBlob <SensorAbilityDB>();

            foreach (var entityItem in entitiesWithSensors)
            {
                StaticRefLib.ProcessorManager.GetInstanceProcessor(nameof(SensorScan)).ProcessEntity(entityItem, StaticRefLib.CurrentDateTime);
            }
            return(factionEntity);
        }