From 2b7a09042cec52fcc1e768997141ee2f73aff770 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 16 Oct 2015 19:07:11 -0700 Subject: [PATCH] Reconfigure RSTE species randomization Fixes the hang bug that was reported, and includes new improvements: Assigning a new species is done within the same line as assigning the pkm info for visual ease. Enabled BST (smart) randomization for type themed trainers, and implemented an expanding window if the initial search stat range is insufficient. Could probably speed up things by just defining a full personal array instead of fetching every time, but whatever. --- pk3DS/Subforms/RSTE.cs | 38 +++++++++++++++++------------------ pk3DS/Subforms/TrainerRand.cs | 3 --- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/pk3DS/Subforms/RSTE.cs b/pk3DS/Subforms/RSTE.cs index 7409082..b30f8b0 100644 --- a/pk3DS/Subforms/RSTE.cs +++ b/pk3DS/Subforms/RSTE.cs @@ -405,7 +405,7 @@ private void showTeams(int i) { if (tr == null) return; if (i >= tr.Team.Length) { pba[i].Image = null; return; } - Bitmap rawImg = (Bitmap)Util.getSprite(tr.Team[i].Species, tr.Team[i].Form, tr.Team[i].Gender, tr.Team[i].Item); + Bitmap rawImg = Util.getSprite(tr.Team[i].Species, tr.Team[i].Form, tr.Team[i].Gender, tr.Team[i].Item); pba[i].Image = Util.scaleImage(rawImg, 2); } private void showText() @@ -642,7 +642,6 @@ private void Randomize() int type = GetRandomType(i); bool mevo = rEnsureMEvo.Contains(i); - // Randomize Pokemon for (int p = 0; p < CB_numPokemon.SelectedIndex; p++) { @@ -651,35 +650,34 @@ private void Randomize() if (rPKM) { // randomize pokemon - int species = Randomizer.getRandomSpecies(ref sL, ref ctr); - pkm = new PersonalInfo(personal[species]); + int species; + pkm = new PersonalInfo(personal[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]); if (rTypeTheme) { - while (pkm.Types[0] != type && pkm.Types[1] != type || (mevo && p == CB_numPokemon.SelectedIndex - 1 && !megaEvos.Contains(species))) - { + int tries = 0; + while ((pkm.Types[0] != type && pkm.Types[1] != type) || ((mevo && p == CB_numPokemon.SelectedIndex - 1 && !megaEvos.Contains(species)))) if (p == CB_numPokemon.SelectedIndex - 1 && mevo) - { - species = GetRandomMegaEvolvablePokemon(type); - } + pkm = new PersonalInfo(personal[species = GetRandomMegaEvolvablePokemon(type)]); else if (rSmart) // Get a new Pokemon with a close BST { - while (!(pkm.BST * 5 / 6 < oldpkm.BST && pkm.BST * 6 / 5 > oldpkm.BST)) - { species = sL[rand.Next(1, sL.Length)]; pkm = new PersonalInfo(personal[species]); } + pkm = new PersonalInfo(personal[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]); + while (!((pkm.BST * (5 - ++tries / 722) / 6 < oldpkm.BST) && (pkm.BST * (6 + ++tries / 722) / 5) > oldpkm.BST)) + { + pkm = new PersonalInfo(personal[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]); + } } else - { - species = Randomizer.getRandomSpecies(ref sL, ref ctr); - } - } + pkm = new PersonalInfo(personal[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]); } else if (p == CB_numPokemon.SelectedIndex - 1 && mevo) - { - species = megaEvos[rnd32() % megaEvos.Length]; - } + pkm = new PersonalInfo(personal[species = megaEvos[rnd32() % megaEvos.Length]]); else if (rSmart) // Get a new Pokemon with a close BST { - while (!(pkm.BST * 5 / 6 < oldpkm.BST && pkm.BST * 6 / 5 > oldpkm.BST)) - { species = sL[rand.Next(1, sL.Length)]; pkm = new PersonalInfo(personal[species]); } + int tries = 0; + while (!((pkm.BST * (5 - ++tries / 722) / 6 < oldpkm.BST) && (pkm.BST * (6 + ++tries / 722) / 5) > oldpkm.BST)) + { + pkm = new PersonalInfo(personal[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]); + } } trpk_pkm[p].SelectedIndex = species; diff --git a/pk3DS/Subforms/TrainerRand.cs b/pk3DS/Subforms/TrainerRand.cs index 539a0e1..e2dcbba 100644 --- a/pk3DS/Subforms/TrainerRand.cs +++ b/pk3DS/Subforms/TrainerRand.cs @@ -114,10 +114,7 @@ private void changeGiftPercent(object sender, EventArgs e) private void CHK_TypeTheme_CheckedChanged(object sender, EventArgs e) { - CHK_BST.Enabled = !CHK_TypeTheme.Checked; CHK_GymTrainers.Enabled = CHK_GymTrainers.Checked = CHK_TypeTheme.Checked; - if (CHK_TypeTheme.Checked) - CHK_BST.Checked = false; } private void CHK_RandomClass_CheckedChanged(object sender, EventArgs e)