public Roster KreateRoster(RandomAccumulator ra, Roster currentRoster) { SpecificAccumulator sa; Roster returnRoster = new Roster( ); Logger.LogEvent("Generating a new Roster"); for (int i = 0; i < ra.NumberToCreate; i++) { sa = RandomToSpecificAccumulator(ra); Kerbal k = KreateKerbal(sa); //validate our kerbal if (!currentRoster.ValidateKerbal(k)) { i--; } else { //if the kerbal is valid, increment our counts, //and add the kerbal. incrementCounts(sa); returnRoster.AddKerbal(k); } } //reset our temp values below. return(returnRoster); }
public frm_Krb_Gen( ) { InitializeComponent( ); generator = new Therapist( ); specAccum = new SpecificAccumulator( ); randAccum = new RandomAccumulator( ); }
private bool PickRandomAccumBadAss(RandomAccumulator ra) { if (badassCreated < ra.MinNumberOfBadasses) { return(true); } else { return(Util.GetRandomFloat( ) > Util.GetRandomFloat( )); } }
/// <summary> /// Kreates the roster. /// </summary> /// <param name="ra">Ra is a RandomAccumulator which holds the values for creating a roster</param> internal void KreateRoster ( RandomAccumulator ra ) { Roster r = new KerbalMaker ( ).KreateRoster ( ra, roster ); switch ( PreviewRoster ( r ) ) { case ( DialogResult.Yes ): roster.AddRoster ( r ); break; default: break; } UpdateSaveStats ( ); UpdateKerbalStats ( ); }
private bool PickRandomAccumGender(RandomAccumulator ra) { if (ra.useRatio) { //create a temporary ratio that we check against. float ratio = (float)Math.Abs(ra.FtMRatio); //don't worry about it here. if (ra.FtMRatio == 1 || ra.FtMRatio == -1) { //either all males or all females return(ra.FtMRatio.Equals(-1)); } //or here. else if (ra.FtMRatio == 0) { //if ratio is 0, just toggle female back and forth until all kerbals are created. //toggle nextIsFemale before we can return. nextIsFemale = !nextIsFemale; return(nextIsFemale); } //if ratio is negative, we need to create more females than males. else if (ra.FtMRatio < 0) { //create more females float f = (float)femalesCreated / (float)ra.NumberToCreate; return(f <= ratio); } //else we need to create more males than females. else if (ra.FtMRatio > 0) { //create more males. float m = (float)malesCreated / (float)ra.NumberToCreate; return(m >= ratio); } //else default to female; else { return(true); } } //else we're not using a ratio, so randomize things else { //create two random floats float one = Util.GetRandomFloat( ); float two = Util.GetRandomFloat( ); return(one > two); } }
private SpecificAccumulator RandomToSpecificAccumulator(RandomAccumulator ra) { SpecificAccumulator sa = new SpecificAccumulator( ); //get our gender first, so that we can generate a gender appropriate name; sa.Female = PickRandomAccumGender(ra); //always true. I forgot, we pick our names during Kerbal Generation. sa.RandName = true; //just copy isKerman from RA to SA. sa.IsKerman = ra.isKerman; //assign our traits; sa.Trait = assignTrait(ra); //generate our stupid and brave values; sa.Brave = Util.GetRandomFloatInRange(ra.MinBrave, ra.MaxBrave); sa.Dumb = Util.GetRandomFloatInRange(ra.MinStupid, ra.MaxStupid); //just some counting variables. //TODO: Move This if (badassCreated < ra.MinNumberOfBadasses) { sa.Badass = true; } else { //Each kerbal has a 50/50 shot of being badass. if (Util.GetRandomFloat( ) > .5f) { sa.Badass = true; } else { sa.Badass = false; } } if (touristCreated < ra.MaxNumberOfTourists) { //Each Kerbal has a ~5% chance of being a tourist. if (Util.GetRandomFloat( ) > .95f) { sa.Tourist = true; } else { sa.Tourist = false; } } return(sa); }
string assignTrait(RandomAccumulator ra) { if (pilotsCreated < ra.Pilots) { return("Pilot"); } if (engineersCreated < ra.Engineers) { return("Engineer"); } if (scientistsCreated < ra.Scientists) { return("Scientist"); } return("Pilot"); }
private void btn_rnd_reset_Click(object sender, EventArgs e) { randAccum = randAccum.Reset( ); tbar_rnd_Pilots.Value = 0; tbar_rnd_Scientists.Value = 0; tbar_rnd_Engineers.Value = 0; chk_rnd_isKerman.Checked = false; tbar_rnd_FtMRatio.Value = 0; chk_rnd_useRatio.Checked = false; tbar_rnd_MaxBrave.Value = 0; tbar_rnd_MaxStupid.Value = 0; tbar_rnd_MinBrave.Value = 0; tbar_rnd_MinStupid.Value = 0; tbar_rnd_MinNumberOfBadasses.Value = 0; tbar_rnd_MaxNumberOfTourists.Value = 0; UpdateRandomDisplay( ); }
private SpecificAccumulator RandomToSpecificAccumulator(RandomAccumulator ra) { SpecificAccumulator sa = new SpecificAccumulator( ); //get our gender first, so that we can generate a gender appropriate name; sa.Female = PickRandomAccumGender(ra); //always true. I forgot, we pick our names during Kerbal Generation. sa.RandName = true; //just copy isKerman from RA to SA. sa.IsKerman = ra.isKerman; //assign our traits; sa.Trait = assignTrait(ra); //generate our stupid and brave values; sa.Brave = Util.GetRandomFloatInRange(ra.MinBrave, ra.MaxBrave); sa.Dumb = Util.GetRandomFloatInRange(ra.MinStupid, ra.MaxStupid); //Tourist or Badass? sa.Badass = PickRandomAccumBadAss(ra); sa.Tourist = PickRandomAccumTourist(ra); return(sa); }
private bool PickRandomAccumTourist(RandomAccumulator ra) { return(touristCreated < ra.MaxNumberOfTourists && Util.GetRandomFloat( ) > .95f); }