示例#1
0
        /// <summary>
        /// Demande a la recette de s'executer pour une station donnee
        /// </summary>
        /// <param name="station"></param>
        /// <param name="timestamp">l'heure en cours</param>
        public bool ProduceOneBatch(Station station, int timestamp)
        {
            Hangar homeHangar = station.GetHangar(-1);

            foreach (ResourceElement.ResourceType e in _inputs.Keys)
            {
                if (homeHangar.GetResourceQte(e) < _inputs[e])
                {
                    return(false);
                }
            }
            //toutes les inputs sont presentes
            foreach (ResourceElement.ResourceType e in _inputs.Keys)
            {
                ResourceStack stack = homeHangar.GetStack(e, _inputs[e]);
            }

            foreach (ResourceElement.ResourceType e in _outputs.Keys)
            {
                //trouver tout les gens qui ont un standing
                HashSet <int> withStanding = station.GetCorpWithStanding(e);
                int           qteToProd    = _outputs[e];
                foreach (int i in withStanding)
                {
                    Hangar hisHangar = station.GetHangar(i);
                    if (null != hisHangar)
                    {
                        ResourceElement elem  = new ResourceElement(e, station, qteToProd, timestamp);
                        ResourceStack   stack = new ResourceStack(elem);
                        hisHangar.Add(stack);
                    }
                }
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// demande de vendre tout ce qui peut l'etre sans depasser la quantite qu'on a decharge
        /// </summary>
        private void Sell()
        {
            Hangar myHangar      = Ship.CurrentStation.GetHangar(Ship.Owner.ID);
            Hangar stationHangar = Ship.CurrentStation.GetHangar(-1);

            foreach (ResourceElement.ResourceType t in _unloaded.Keys)
            {
                if (Ship.CurrentStation.Buyings.Contains(t))
                {
                    int qteToSell = Math.Min(_unloaded[t], myHangar.GetResourceQte(t));
                    if (qteToSell > 0)
                    {
                        ResourceStack s = myHangar.GetStack(t, qteToSell);
                        stationHangar.Add(s);
                        int qte = Ship.CurrentStation.GetBuyingPrice(t) * qteToSell;
                        Ship.Owner.AddICU(qte, "selling stuff");
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// le vaisseau est en train de se charger dans la station. Il partira quand il aura fini de charger ce qu'il doit
        /// ou quand il sera plein.
        /// <param name="possibleLoad">nombre de m3 qu'on peut charger cette fois</param>
        /// </summary>
        /// <returns>le nombre de m3 charge</returns>
        private int Load(int possibleLoad)
        {
            int     qteLoaded = 0;
            Station station   = Ship.CurrentStation;

            if (null == station)
            {
                return(qteLoaded);
            }

            Hangar myHangarInStation = station.GetHangar(Ship.Owner.ID);

            if (null != myHangarInStation)
            {
                foreach (LoadData l in _loads)
                {
                    if (!_loaded.ContainsKey(l.type))
                    {
                        _loaded.Add(l.type, 0);
                    }
                    int present = myHangarInStation.GetResourceQte(l.type);
                    int toLoad  = Math.Min(present, l.qte - _loaded[l.type]);
                    toLoad = Math.Min(toLoad, possibleLoad);

                    Destination.InformLoading(Ship, l.type);
                    if (toLoad > 0)
                    {
                        Ship.Cargo.Add(myHangarInStation.GetStack(l.type, toLoad));
                        qteLoaded       += toLoad;
                        _loaded[l.type] += toLoad;
                        possibleLoad    -= toLoad;
                    }
                }
            }

            return(qteLoaded);
        }