コード例 #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 decharge sa cargaison avant de pouvoir en charger.
        /// </summary>
        /// <param name="possibleUnload">nombre de m3 qu'on peut decharger cette fois</param>
        /// <returns>le nombre de m3 decharge</returns>
        private int Unload(int possibleUnload)
        {
            int     result  = 0;
            Station station = Ship.CurrentStation;

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

            int qteUnloaded = 0;

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

            if (null != myHangarInStation)
            {
                foreach (LoadData l in _unloads)
                {
                    if (!_unloaded.ContainsKey(l.type))
                    {
                        _unloaded.Add(l.type, 0);
                    }
                    int present = Ship.Cargo.GetResourceQte(l.type);
                    int toLoad  = Math.Min(present, l.qte - _unloaded[l.type]);
                    toLoad = Math.Min(toLoad, possibleUnload);

                    if (toLoad > 0)
                    {
                        myHangarInStation.Add(Ship.Cargo.GetStack(l.type, toLoad));
                        qteUnloaded       += toLoad;
                        _unloaded[l.type] += toLoad;
                        possibleUnload    -= toLoad;
                    }
                }
            }
            return(qteUnloaded);
        }