//returns the pay for a codesharing agreement - one wayed public static double GetCodesharingPrice(CodeshareAgreement agreement) { return GetCodesharingPrice(agreement.Airline1, agreement.Airline2); }
//returns if an airline wants to have code sharing with another airline public static Boolean AcceptCodesharing(Airline airline, Airline asker, CodeshareAgreement.CodeshareType type) { double coeff = type == CodeshareAgreement.CodeshareType.One_Way ? 0.25 : 0.40; IEnumerable<Country> sameCountries = asker.Airports.Select(a => a.Profile.Country).Distinct().Intersect(airline.Airports.Select(a => a.Profile.Country).Distinct()); IEnumerable<Airport> sameDestinations = asker.Airports.Distinct().Intersect(airline.Airports); IEnumerable<Country> sameCodesharingCountries = airline.getCodesharingAirlines().SelectMany(a => a.Airports).Select(a => a.Profile.Country).Distinct().Intersect(airline.Airports.Select(a => a.Profile.Country).Distinct()); double airlineDestinations = airline.Airports.Count; double airlineRoutes = airline.Routes.Count; double airlineCountries = airline.Airports.Select(a => a.Profile.Country).Distinct().Count(); double airlineCodesharings = airline.Codeshares.Count; double airlineAlliances = airline.Alliances.Count; //declines if asker is much smaller than the invited airline if (airlineRoutes > 3 * asker.Routes.Count) return false; //declines if there is a match for x% of the airlines if (sameDestinations.Count() >= airlineDestinations * coeff) return false; //declines if there is a match for 75% of the airlines if (sameCountries.Count() >= airlineCountries * 0.75) return false; //declines if the airline already has a code sharing or alliance in that area if (sameCodesharingCountries.Count() >= airlineCountries * coeff) return false; return true; }
//adds a codeshare agreement public void addCodeshareAgreement(CodeshareAgreement share) { this.Codeshares.Add(share.Airline1 == this.Airline ? share.Airline2 : share.Airline1); this.Airline.addCodeshareAgreement(share); this.HasAlliance = this.Alliance != null || this.Codeshares.Count > 0; }
private void hlCodeSharing_Click(object sender, RoutedEventArgs e) { object o = PopUpCodeshareAgreement.ShowPopUp(this.Airline.Airline); if (o != null) { CodeshareAgreement.CodeshareType type = (CodeshareAgreement.CodeshareType)o; Boolean accepted = AirlineHelpers.AcceptCodesharing(this.Airline.Airline, GameObject.GetInstance().HumanAirline,type); if (accepted) { this.HasCodesharing = true; this.ShowActionMenu = !this.Airline.Airline.IsHuman && (this.CanHaveAlliance || !this.HasCodesharing); CodeshareAgreement agreement = new CodeshareAgreement(this.Airline.Airline, GameObject.GetInstance().HumanAirline,type); this.Airline.addCodeshareAgreement(agreement); GameObject.GetInstance().HumanAirline.addCodeshareAgreement(agreement); } else WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2408"), string.Format(Translator.GetInstance().GetString("MessageBox", "2408", "message"), this.Airline.Airline.Profile.Name), WPFMessageBoxButtons.Ok); } }
public CodeshareAgreementMVVM(CodeshareAgreement agreement) { this.Agreement = agreement; }
//removes a code share agreement from the airline public void removeCodeshareAgreement(CodeshareAgreement share) { this.Codeshares.Remove(share); }
//adds a code share agreement to the airline public void addCodeshareAgreement(CodeshareAgreement share) { this.Codeshares.Add(share); }