Example #1
0
        internal static void AddCargo(CargoStorageDB storeDB, ICargoable item, long amount)
        {
            if (item is CargoAbleTypeDB)
            {
                CargoAbleTypeDB cargoItem = (CargoAbleTypeDB)item;
                if (cargoItem.MustBeSpecificCargo)
                {
                    if (!storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites.ContainsKey(cargoItem.ID))
                    {
                        storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites.Add(cargoItem.ID, new List <Entity>());
                    }
                    storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites[cargoItem.ID].Add(cargoItem.OwningEntity);
                }
            }
            if (!storeDB.StoredCargoTypes.ContainsKey(item.CargoTypeID))
            {
                storeDB.StoredCargoTypes.Add(item.CargoTypeID, new CargoTypeStore());
            }
            else if (!storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts.ContainsKey(item.ID))
            {
                storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts.Add(item.ID, 0);
            }

            storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts[item.ID] += amount;
            //FreeCapacity is *MASS*
            storeDB.StoredCargoTypes[item.CargoTypeID].FreeCapacityKg -= item.Mass * amount;
        }
 internal static bool HasEntity(CargoStorageDB storeDB, CargoAbleTypeDB item)
 {
     if (storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites.ContainsKey(item.ID))
     {
         if (storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites[item.ID].Contains(item.OwningEntity))
         {
             return(true);
         }
     }
     return(false);
 }
        internal static bool HasEntity(VolumeStorageDB storeDB, CargoAbleTypeDB item)
        {
            throw new NotImplementedException();

            /*
             * if(storeDB.TypeStores[item.CargoTypeID].CurrentStore.ContainsKey(item.ID))
             *  if (storeDB.TypeStores[item.CargoTypeID].CurrentStore[item.ID].Contains(item.OwningEntity))
             *      return true;
             * return false;
             */
        }
Example #4
0
 /// <summary>
 /// Does not check if cargo or cargotype exsists. will throw normal dictionary exptions if you try.
 /// just removes the amount from store and updates the free capacity
 /// </summary>
 /// <param name="storeDB"></param>
 /// <param name="item"></param>
 /// <param name="amount"></param>
 internal static void RemoveCargo(CargoStorageDB storeDB, ICargoable item, long amount)
 {
     if (item is CargoAbleTypeDB)
     {
         CargoAbleTypeDB cargoItem = (CargoAbleTypeDB)item;
         if (cargoItem.MustBeSpecificCargo)
         {
             storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites[cargoItem.ID].Remove(cargoItem.OwningEntity);
         }
     }
     storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts[item.ID] -= amount;
     //FreeCapacity is *MASS*
     storeDB.StoredCargoTypes[item.CargoTypeID].FreeCapacityKg += item.Mass * amount;
 }
        /// <summary>
        /// checks the toCargo and transferes the item if there is enough space.
        /// </summary>
        /// <param name="fromCargo"></param>
        /// <param name="toCargo"></param>
        /// <param name="entityItem"></param>
        internal static void TransferEntity(CargoStorageDB fromCargo, CargoStorageDB toCargo, Entity entityItem)
        {
            CargoAbleTypeDB cargotypedb = entityItem.GetDataBlob <CargoAbleTypeDB>();
            Guid            cargoTypeID = cargotypedb.CargoTypeID;
            float           itemWeight  = cargotypedb.Mass;
            Guid            itemID      = cargotypedb.ID;

            long remainingWeightCapacity = RemainingCapacity(toCargo, cargoTypeID);
            long remainingNumCapacity    = (long)(remainingWeightCapacity / itemWeight);

            if (remainingNumCapacity >= 1)
            {
                if (fromCargo.StoredEntities[cargoTypeID].Remove(entityItem))
                {
                    AddToCargo(toCargo, entityItem, cargotypedb);
                }
            }
        }
        internal static void AddCargo(CargoStorageDB storeDB, ICargoable item, long amount)
        {
            if (item is CargoAbleTypeDB)
            {
                CargoAbleTypeDB cargoItem = (CargoAbleTypeDB)item;
                if (cargoItem.MustBeSpecificCargo)
                {
                    if (!storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites.ContainsKey(cargoItem.ID))
                    {
                        storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites.Add(cargoItem.ID, new List <Entity>());
                    }
                    storeDB.StoredCargoTypes[item.CargoTypeID].SpecificEntites[cargoItem.ID].Add(cargoItem.OwningEntity);
                }
            }

            var id = item.ID;

            //if the item is a componentInstance, and has no damage we store it by design.
            if (item is ComponentInstance)
            {
                ComponentInstance ci = (ComponentInstance)item;
                if (ci.HTKRemaining == ci.HTKMax)
                {
                    id = ci.Design.ID;
                }
            }
            if (!storeDB.StoredCargoTypes.ContainsKey(item.CargoTypeID))
            {
                storeDB.StoredCargoTypes.Add(item.CargoTypeID, new CargoTypeStore());
            }

            if (!storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts.ContainsKey(item.ID))
            {
                storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts.Add(id, (item, amount));
            }
            else
            {
                long total = storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts[item.ID].amount + amount;
                storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts[item.ID] = (item, total);
            }
            //FreeCapacity is *MASS*
            storeDB.StoredCargoTypes[item.CargoTypeID].FreeCapacityKg -= item.Mass * amount;
        }
Example #7
0
        /// <summary>
        /// Creates Entity and blobs.
        /// </summary>
        /// <param name="globalEntityManager"></param>
        /// <param name="componentDesign"></param>
        /// <param name="factionTech"></param>
        /// <returns></returns>
        public static Entity DesignToDesignEntity(Game game, Entity factionEntity, ComponentDesign componentDesign)
        {
            EntityManager   globalEntityManager = game.GlobalManager;
            StaticDataStore staticData          = game.StaticData;
            FactionTechDB   factionTech         = factionEntity.GetDataBlob <FactionTechDB>();
            FactionInfoDB   faction             = factionEntity.GetDataBlob <FactionInfoDB>();
            //TODO probilby do checking to see if valid here?
            Entity component = new Entity(globalEntityManager, factionEntity);

            TechSD tech = new TechSD();

            tech.ID          = Guid.NewGuid();
            tech.Name        = componentDesign.Name + " Design Research";
            tech.Description = "Research into building " + componentDesign.Name;
            tech.MaxLevel    = 1;
            tech.CostFormula = componentDesign.ResearchCostValue.ToString();

            factionTech.ResearchableTechs.Add(tech, 0);
            NameDB nameDB = new NameDB(componentDesign.RawName);

            nameDB.SetName(factionEntity.Guid, componentDesign.Name);
            Dictionary <Guid, int> mineralCosts   = new Dictionary <Guid, int>();
            Dictionary <Guid, int> materalCosts   = new Dictionary <Guid, int>();
            Dictionary <Guid, int> componentCosts = new Dictionary <Guid, int>();

            foreach (var kvp in componentDesign.MineralCostValues)
            {
                if (staticData.CargoGoods.IsMaterial(kvp.Key))
                {
                    materalCosts.Add(kvp.Key, kvp.Value);
                }
                else if (staticData.ComponentTemplates.ContainsKey(kvp.Key))
                {
                    componentCosts.Add(kvp.Key, kvp.Value);
                }
                else if (staticData.CargoGoods.IsMineral(kvp.Key))
                {
                    mineralCosts.Add(kvp.Key, kvp.Value);
                }
                else
                {
                    throw new Exception("GUID object {" + kvp.Key + "} not found in materialCosting for " + componentDesign.Name + " This object needs to be either a mineral, material or component defined in the Data folder");
                }
            }

            ComponentInfoDB componentInfo = new ComponentInfoDB(component.Guid, componentDesign.MassValue, componentDesign.HTKValue, componentDesign.BuildCostValue, mineralCosts, materalCosts, componentCosts, tech.ID, componentDesign.CrewReqValue);

            componentInfo.ComponentMountType = componentDesign.ComponentMountType;
            componentInfo.ConstructionType   = componentDesign.ConstructionType;
            CargoAbleTypeDB cargoType = new CargoAbleTypeDB(componentDesign.CargoTypeID);

            component.SetDataBlob(componentInfo);
            component.SetDataBlob(nameDB);
            component.SetDataBlob(cargoType);
            //note: MassVolumeDB stores mass in kg and volume in km^3, however we use kg and m^3 in the json data.
            component.SetDataBlob(MassVolumeDB.NewFromMassAndVolume(componentDesign.MassValue, componentDesign.VolumeValue * 1e-9));
            foreach (var designAttribute in componentDesign.ComponentDesignAttributes)
            {
                if (designAttribute.DataBlobType != null)
                {
                    if (designAttribute.DataBlobArgs == null)
                    {
                        designAttribute.SetValue();  //force recalc.
                    }
                    object[] constructorArgs = designAttribute.DataBlobArgs;
                    dynamic  datablob        = (BaseDataBlob)Activator.CreateInstance(designAttribute.DataBlobType, constructorArgs);
                    component.SetDataBlob(datablob);
                    if (datablob is IComponentDesignAttribute)
                    {
                        componentInfo.DesignAttributes.Add(datablob);
                    }
                }
            }

            faction.InternalComponentDesigns.Add(component.Guid, component);
            return(component);
        }
Example #8
0
 public CargoAbleTypeDB(CargoAbleTypeDB cargoTypeDB)
 {
     CargoTypeID         = cargoTypeDB.CargoTypeID;
     MustBeSpecificCargo = cargoTypeDB.MustBeSpecificCargo;
 }
Example #9
0
        public static Entity CreateNewShipClass(Game game, Entity faction, string className = null)
        {
            //check className before any to use it in NameDB constructor
            if (string.IsNullOrEmpty(className))
            {
                ///< @todo source the class name from faction theme.
                className = "New Class"; // <- Hack for now.
            }

            // lets start by creating all the Datablobs that make up a ship class: TODO only need to add datablobs for compoents it has abilites for.
            var shipInfo      = new ShipInfoDB();
            var armor         = new ArmorDB();
            var buildCost     = new BuildCostDB();
            var cargotype     = new CargoAbleTypeDB();
            var crew          = new CrewDB();
            var damage        = new DamageDB();
            var maintenance   = new MaintenanceDB();
            var sensorProfile = new SensorProfileDB();
            var name          = new NameDB(className);

            name.SetName(faction.Guid, className);
            var componentInstancesDB = new ComponentInstancesDB();
            var massVolumeDB         = new MassVolumeDB();

            // now lets create a list of all these datablobs so we can create our new entity:
            List <BaseDataBlob> shipDBList = new List <BaseDataBlob>()
            {
                shipInfo,
                armor,
                buildCost,
                cargotype,
                crew,
                damage,
                maintenance,
                sensorProfile,
                name,
                componentInstancesDB,
                massVolumeDB,
            };

            // now lets create the ship class:
            Entity         shipClassEntity = new Entity(game.GlobalManager, faction.Guid, shipDBList);
            FactionOwnerDB factionOwner    = faction.GetDataBlob <FactionOwnerDB>();

            factionOwner.SetOwned(shipClassEntity);
            // also gets factionDB:
            FactionInfoDB factionDB = faction.GetDataBlob <FactionInfoDB>();

            // and add it to the faction:
            factionDB.ShipClasses.Add(shipClassEntity);

            // now lets set some ship info:
            shipInfo.ShipClassDefinition = Guid.Empty; // just make sure it is marked as a class and not a ship.

            // now lets add some components:
            ///< @todo Add ship components
            // -- basic armour of current faction tech level
            // -- minimum crew quaters defaulting to 3 months deployment time.
            // -- a bridge
            // -- an engineering space
            // -- a fuel tank

            // now update the ship system DBs to reflect the components:
            ///< @todo update ship to reflect added components

            return(shipClassEntity);
        }
Example #10
0
 public CargoAbleTypeDB(CargoAbleTypeDB cargoTypeDB)
 {
     CargoTypeID = cargoTypeDB.CargoTypeID;
 }