public void OnConstructionComplete(Entity industryEntity, CargoStorageDB storage, Guid productionLine, IndustryJob batchJob, IConstrucableDesign designInfo)
        {
            var colonyConstruction = industryEntity.GetDataBlob <IndustryAbilityDB>();

            batchJob.NumberCompleted++;
            batchJob.ResourcesRequired = designInfo.ResourceCosts;

            batchJob.ProductionPointsLeft = designInfo.IndustryPointCosts;


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

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                colonyConstruction.ProductionLines[productionLine].Jobs.Remove(batchJob);
                if (batchJob.Auto)
                {
                    colonyConstruction.ProductionLines[productionLine].Jobs.Add(batchJob);
                }
            }
        }
Beispiel #2
0
 public CargoListPannelSimple(StaticDataStore staticData, EntityState entity)
 {
     _staticData      = staticData;
     _entityState     = entity;
     _storageDatablob = entity.Entity.GetDataBlob <CargoStorageDB>();
     entity.Entity.Manager.ManagerSubpulses.SystemDateChangedEvent += ManagerSubpulses_SystemDateChangedEvent;
     Update();
 }
Beispiel #3
0
        public CargoListPannelSimple(StaticDataStore staticData, EntityState entity)
        {
            _staticData      = staticData;
            _entityState     = entity;
            _storageDatablob = entity.Entity.GetDataBlob <CargoStorageDB>();

            Update();
        }
Beispiel #4
0
 public CargoListPannelComplex(StaticDataStore staticData, EntityState entity, Dictionary <Guid, bool> headersOpenDict)
 {
     _staticData       = staticData;
     _entityState      = entity;
     _storageDatablob  = entity.Entity.GetDataBlob <CargoStorageDB>();
     HeadersIsOpenDict = headersOpenDict;
     Update();
 }
Beispiel #5
0
 public CargoListPannelComplex(StaticDataStore staticData, EntityState entity, Dictionary <Guid, bool> headersOpenDict)
 {
     _staticData       = staticData;
     _entityState      = entity;
     _storageDatablob  = entity.Entity.GetDataBlob <CargoStorageDB>();
     HeadersIsOpenDict = headersOpenDict;
     entity.Entity.Manager.ManagerSubpulses.SystemDateChangedEvent += ManagerSubpulses_SystemDateChangedEvent;
     Update();
 }
Beispiel #6
0
 public void Initialise(Entity entity)
 {
     _storageDB = entity.GetDataBlob <CargoStorageDB>();
     foreach (var item in _storageDB.CargoCapicity)
     {
         CargoStorageByTypeVM storeType = new CargoStorageByTypeVM(_gameVM);
         storeType.Initalise(_storageDB, item.Key);
         CargoStore.Add(storeType);
     }
     _storageDB.CargoCapicity.CollectionChanged  += _storageDB_CollectionChanged;
     _storageDB.StoredEntities.CollectionChanged += StoredEntities_CollectionChanged;
 }
Beispiel #7
0
        public static void LaunchMissile(Entity launchingEntity, Entity targetEntity, MissileLauncherAtb launcherAtb, OrdnanceDesign missileDesign)
        {
            var     atDatetime = launchingEntity.Manager.StarSysDateTime;
            var     positionDB = launchingEntity.GetDataBlob <PositionDB>();
            Vector3 position   = positionDB.AbsolutePosition_m;

            var tgtEntityOrbit = targetEntity.GetDataBlob <OrbitDB>();

            //MissileLauncherAtb launcherAtb;
            CargoStorageDB cargo  = launchingEntity.GetDataBlob <CargoStorageDB>();
            int            numMis = (int)StorageSpaceProcessor.GetAmount(cargo, missileDesign);

            if (numMis < 1)
            {
                return;
            }
            double launchSpeed = launcherAtb.LaunchForce / missileDesign.Mass;

            //missileDesign.

            double burnTime = (missileDesign.WetMass - missileDesign.DryMass) / missileDesign.BurnRate;
            double dv       = OrbitMath.TsiolkovskyRocketEquation(missileDesign.WetMass, missileDesign.DryMass, missileDesign.ExaustVelocity);
            double avgSpd   = launchSpeed + dv * 0.5;

            var tgtEstPos = OrbitMath.GetInterceptPosition_m(position, avgSpd, tgtEntityOrbit, atDatetime);

            Vector3 parentVelocity = Entity.GetVelocity_m(launchingEntity, launchingEntity.Manager.StarSysDateTime);

            Vector3 tgtEstVector   = tgtEstPos.position - position; //future target position
            Vector3 launchVelocity = parentVelocity + tgtEstVector;

            List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>();

            dataBlobs.Add((PositionDB)positionDB.Clone());

            var newMissile = Entity.Create(launchingEntity.Manager, launchingEntity.FactionOwner, dataBlobs);

            foreach (var tuple in missileDesign.Components)
            {
                EntityManipulation.AddComponentToEntity(newMissile, tuple.design, tuple.count);
            }

            StorageSpaceProcessor.RemoveCargo(cargo, missileDesign, 1);
            var thrusting = new NewtonMoveDB(positionDB.Parent, launchVelocity);

            thrusting.ActionOnDateTime   = atDatetime;
            thrusting.DeltaVForManuver_m = Vector3.Normalise(tgtEstPos.position) * dv;
            newMissile.SetDataBlob(thrusting);
        }
Beispiel #8
0
        public void StorageSpaceProcessor_When_AskedToCheckIfItHasACargoTypeThatItDoesnotHave_Should_ReturnFalse()
        {
            var cookies = SetupCookieTradeGood();

            var cookiePile = new CargoStorageDB();

            var cookieCheck = new Dictionary <ICargoable, int>
            {
                { cookies, 1 }
            };

            var hasCookies = StorageSpaceProcessor.HasRequiredItems(cookiePile, cookieCheck);

            Assert.IsFalse(hasCookies);
        }
Beispiel #9
0
        public void StorageSpaceProcessor_When_AskedToCheckIfItHasCargoThatItHasMoreTHanEnoughOf_Should_ReturnTrue()
        {
            var cookies = SetupCookieTradeGood();

            var cookiePile = new CargoStorageDB();

            cookiePile.StoredCargoTypes.Add(cookies.CargoTypeID, new CargoTypeStore()
            {
                MaxCapacityKg = 9999999999999, FreeCapacityKg = 9999999999999
            });
            StorageSpaceProcessor.AddCargo(cookiePile, cookies, 99);

            var cookieCheck = new Dictionary <ICargoable, int>
            {
                { cookies, 7 }
            };
            var hasCookies = StorageSpaceProcessor.HasRequiredItems(cookiePile, cookieCheck);

            Assert.IsTrue(hasCookies);
        }
Beispiel #10
0
 void SetIconFor(CargoStorageDB cargodb)
 {
     /*
      * int stackHeight = 0;
      * float red = 128 / 255;
      * float green = 128 / 255;
      * float blue = 128 / 255;
      * Color colour = new Color(128 /255, 128/255, 128/255);
      * foreach (var item in cargodb.CargoCapicity)
      * {
      *  int height = (int)(item.Value / 100);
      *  int width = (int)(item.Value / 100);
      *  Pen containerPen = new Pen(new Color(red, green, blue));
      *  green += 20 / 255;
      *  GraphicsPath containerPath = new GraphicsPath();
      *  containerPath.AddRectangle(width / 2, stackHeight, width, height);
      *  PenPathPair container = new PenPathPair() { Pen = containerPen, Path = containerPath };
      *  _shapes.Add(container);
      *  stackHeight += height;
      * }
      */
 }
Beispiel #11
0
        public void Initalise(CargoStorageDB storageDB, Guid storageTypeID)
        {
            _storageDB = storageDB;
            TypeID     = storageTypeID;

            CargoTypeSD cargoType = _dataStore.CargoTypes[TypeID];

            TypeName = cargoType.Name;
            foreach (var itemKVP in StorageSpaceProcessor.GetResourcesOfCargoType(storageDB, TypeID))
            {
                CargoItemVM cargoItem = new CargoItemVM(_gameVM, _storageDB, itemKVP.Key);
                TypeStore.Add(cargoItem);
            }
            if (_storageDB.StoredEntities.ContainsKey(TypeID))
            {
                InitEntities();
            }

            HeaderText = cargoType.Name + ": " + NetWeight.ToString() + " of " + MaxWeight.ToString() + " used, " + RemainingWeight.ToString() + " remaining";
            _storageDB.OwningEntity.Manager.ManagerSubpulses.SystemDateChangedEvent += ManagerSubpulses_SystemDateChangedEvent;
            _storageDB.MinsAndMatsByCargoType[TypeID].CollectionChanged             += _storageDB_CollectionChanged;
            _storageDB.StoredEntities.CollectionChanged += StoredEntities_CollectionChanged;
        }
Beispiel #12
0
        internal static void ConsumeResources(CargoStorageDB fromCargo, ref IDictionary <Guid, int> toUse)
        {
            foreach (KeyValuePair <Guid, int> kvp in toUse.ToArray())
            {
                ICargoable cargoItem = StaticRefLib.StaticData.CargoGoods.GetAny(kvp.Key);//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))
                    {
                        amountUsedThisTick = Math.Min((int)fromCargo.StoredCargoTypes[cargoTypeID].ItemsAndAmounts[cargoItem.ID].amount, kvp.Value);
                    }
                }

                if (amountUsedThisTick > 0)
                {
                    StorageSpaceProcessor.RemoveCargo(fromCargo, cargoItem, amountUsedThisTick);
                    toUse[kvp.Key] -= amountUsedThisTick;
                }
            }
        }
Beispiel #13
0
 public CargoItemVM(GameVM gameVM, CargoStorageDB storageDB, ICargoable item)
 {
     ItemID     = item.ID;
     ItemName   = item.Name;
     _storageDB = storageDB;
     ItemWeight = item.Mass;
     _storageDB.OwningEntity.Manager.ManagerSubpulses.SystemDateChangedEvent += ManagerSubpulses_SystemDateChangedEvent;
     if (item is MineralSD)
     {
         ItemTypeName = "Raw Mineral";
     }
     else if (item is ProcessedMaterialSD)
     {
         ItemTypeName = "Processed Material";
     }
     else if (item is CargoAbleTypeDB)
     {
         CargoAbleTypeDB itemdb     = (CargoAbleTypeDB)item;
         Entity          itemEntity = itemdb.OwningEntity;
         ItemTypeName = itemEntity.GetDataBlob <ComponentInstanceInfoDB>()?.
                        DesignEntity.GetDataBlob <NameDB>().GetName(itemEntity.GetDataBlob <OwnedDB>().
                                                                    ObjectOwner) ?? "Unknown Construct Type";
     }
 }
Beispiel #14
0
        public void StorageSpaceProcessor_When_AskedToCheckAvailableStorageSpace_Should_ReturnCorrectAnswerForTheRequestedCargoItem()
        {
            var rocks   = SetupRockTradeGood();
            var library = new CargoDefinitionsLibrary();

            library.LoadOtherDefinitions(new List <ICargoable>()
            {
                rocks
            });

            var rockPile = new CargoStorageDB();

            rockPile.StoredCargoTypes.Add(rocks.CargoTypeID, new CargoTypeStore()
            {
                MaxCapacityKg = 35007, FreeCapacityKg = 32154
            });
            rockPile.StoredCargoTypes.Add(Guid.NewGuid(), new CargoTypeStore()
            {
                MaxCapacityKg = 99998, FreeCapacityKg = 99997
            });
            rockPile.StoredCargoTypes.Add(Guid.NewGuid(), new CargoTypeStore()
            {
                MaxCapacityKg = 99996, FreeCapacityKg = 99995
            });

            var canStoreThisManyItems = StorageSpaceProcessor.GetAvailableSpace(rockPile, rocks.ID, library);

            Assert.AreEqual(3215, canStoreThisManyItems.FreeCapacityItem);
            Assert.AreEqual(32154, canStoreThisManyItems.FreeCapacityKg);

            StorageSpaceProcessor.AddCargo(rockPile, rocks, 215);

            canStoreThisManyItems = StorageSpaceProcessor.GetAvailableSpace(rockPile, rocks.ID, library);
            Assert.AreEqual(3000, canStoreThisManyItems.FreeCapacityItem);
            Assert.AreEqual(30004, canStoreThisManyItems.FreeCapacityKg);
        }
Beispiel #15
0
        public void StorageSpaceProcessor_When_AskedToCheckIfItHasASpecificItemThatItDoesnotHave_Should_ReturnFalse()
        {
            var cookies  = SetupCookieTradeGood();
            var biscuits = SetupCookieTradeGood();

            biscuits.CargoTypeID = cookies.CargoTypeID;

            var cookiePile = new CargoStorageDB();

            cookiePile.StoredCargoTypes.Add(cookies.CargoTypeID, new CargoTypeStore()
            {
                MaxCapacityKg = 9999999999999, FreeCapacityKg = 9999999999999
            });
            StorageSpaceProcessor.AddCargo(cookiePile, biscuits, 1);

            var cookieCheck = new Dictionary <ICargoable, int>
            {
                { cookies, 1 }
            };

            var hasCookies = StorageSpaceProcessor.HasRequiredItems(cookiePile, cookieCheck);

            Assert.IsFalse(hasCookies);
        }
Beispiel #16
0
        internal static void ConstructStuff(Entity industryEntity)
        {
            CargoStorageDB stockpile = industryEntity.GetDataBlob <CargoStorageDB>();
            Entity         faction;

            industryEntity.Manager.FindEntityByGuid(industryEntity.FactionOwner, out faction);
            var factionInfo = faction.GetDataBlob <FactionInfoDB>();
            var industryDB  = industryEntity.GetDataBlob <IndustryAbilityDB>();

            //var pointRates = industryDB.IndustryTypeRates;
            //int maxPoints = industryDB.ConstructionPoints;


            //List<JobBase> constructionJobs = new List<JobBase>(industryDB.JobBatchList);
            foreach (var kvp in industryDB.ProductionLines.ToArray())
            {
                Guid prodLineID = kvp.Key;
                var  prodLine   = kvp.Value;
                var  industryPointsRemaining = new Dictionary <Guid, int>(prodLine.IndustryTypeRates);
                List <IndustryJob> Joblist   = prodLine.Jobs;
                float productionPercentage   = 1;



                for (int i = 0; i < Joblist.Count; i++)
                {
                    IndustryJob         batchJob   = Joblist[i];
                    IConstrucableDesign designInfo = factionInfo.IndustryDesigns[batchJob.ItemGuid];
                    float pointsToUse = industryPointsRemaining[designInfo.IndustryTypeID] * productionPercentage;
                    //total number of resources requred for a single job in this batch
                    var resourceSum = designInfo.ResourceCosts.Sum(item => item.Value);
                    //how many construction points each resourcepoint is worth.
                    float pointPerResource = (float)designInfo.IndustryPointCosts / resourceSum;

                    while (
                        productionPercentage > 0 &&
                        batchJob.NumberCompleted < batchJob.NumberOrdered &&
                        pointsToUse > 0)
                    {
                        //gather availible resorces for this job.
                        //right now we take all the resources we can, for an individual item in the batch.
                        //even if we're taking more than we can use in this turn, we're using/storing it.
                        IDictionary <Guid, int> resourceCosts = batchJob.ResourcesRequired;
                        //Note: this is editing batchjob.ResourcesRequired variable.
                        ConsumeResources(stockpile, ref resourceCosts);
                        //we calculate the difference between the design resources and the amount of resources we've squirreled away.


                        // this is the total of the resources that we don't have access to for this item.
                        int unusableResourceSum = resourceCosts.Sum(item => item.Value);
                        // this is the total resources that can be used on this item.
                        int useableResourcePoints = resourceSum - unusableResourceSum;

                        pointsToUse = Math.Min(industryPointsRemaining[designInfo.IndustryTypeID], batchJob.ProductionPointsLeft);
                        pointsToUse = Math.Min(pointsToUse, useableResourcePoints * pointPerResource);

                        var remainingPoints = industryPointsRemaining[designInfo.IndustryTypeID] - pointsToUse;


                        if (pointsToUse < 0)
                        {
                            throw new Exception("Can't have negative production");
                        }

                        //construct only enough for the amount of resources we have.
                        batchJob.ProductionPointsLeft -= (int)Math.Floor(pointsToUse);

                        productionPercentage -= remainingPoints * productionPercentage;

                        if (batchJob.ProductionPointsLeft == 0)
                        {
                            designInfo.OnConstructionComplete(industryEntity, stockpile, prodLineID, batchJob, designInfo);
                        }
                    }
                }
            }
        }