/// <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); }
/// <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); }
/// <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); }