Skip to content

Commit c77d01b

Browse files
committed
Added Evolution Randomization. Fixed rare Move Randomization bug.
1 parent e1ca2a2 commit c77d01b

File tree

5 files changed

+129
-12
lines changed

5 files changed

+129
-12
lines changed

src/randomizer/Pokemon_TCG/MonCardData.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class MonCardData {
3434

3535
public static int moveSize = 19;
3636

37+
//non data variables
38+
boolean highestStage = false;
39+
3740
public MonCardData(byte[] rom, int startIndex){
3841
int c = startIndex;
3942

@@ -63,9 +66,7 @@ public MonCardData(byte[] rom, int startIndex){
6366
weight = new Word(rom,c,true); c+=2;
6467
description = new Word(rom,c,true); c+=2;
6568
unknownByte2 = rom[c++];
66-
6769

68-
6970
}
7071

7172
public void writeToRom(byte[] rom, int startIndex){

src/randomizer/Pokemon_TCG/PTCG1_Randomizer.java

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,27 +288,34 @@ public void randomizeMoves(boolean keepStage, boolean keepMoveAmount){
288288
ArrayList<Move> moveList = new ArrayList<Move>();
289289
ArrayList<MonCardData> monList = new ArrayList<MonCardData>();
290290

291+
292+
291293
for(int i = 0; i < monAmount; i++){
292294
moveList.add(mons[i].move1);
293295
if(mons[i].move2.isExists())
294296
moveList.add(mons[i].move2);
295297
monList.add(mons[i]);
296298
}
297299

298-
299300
Collections.shuffle(moveList, rand);
300301
Collections.shuffle(monList, rand);
302+
301303
for(int i = moveList.size()-1; i >= 0; i--){
304+
302305
if(moveList.get(i).isPokePower()){
303-
moveList.add(moveList.remove(i++));//move it to the back of the list
306+
moveList.add(moveList.remove(i));//move it to the back of the list
304307
}
305308
}
306309

310+
307311
for(int i = 0; i< monList.size(); i++){
308312
MonCardData curr = monList.get(i);
309313
int stage = 0xFF & curr.stage;
310314
// System.out.println(stage);
311315
boolean foundPokePower = false;
316+
317+
318+
312319
for(int j = moveList.size()-1; j >= 0; j--){
313320
Move currMove = moveList.get(j);
314321

@@ -341,14 +348,12 @@ public void randomizeMoves(boolean keepStage, boolean keepMoveAmount){
341348

342349

343350
}
344-
345351
if(foundPokePower){
346352
//if after all that we got two moves (move + pokepower), remove self from list
347353
monList.remove(i--);
348354

349355
}
350356
}
351-
352357
//Alright so where are we now?
353358
//we have a list of mons with only one move, and a list of moves that still don't have a home
354359
for(int i = 0; i< monList.size(); i++){
@@ -366,7 +371,6 @@ public void randomizeMoves(boolean keepStage, boolean keepMoveAmount){
366371

367372

368373
}
369-
370374
for(int i = 0; i < monList.size(); i++){
371375
monList.get(i).move2 = blankMove;
372376

@@ -523,7 +527,96 @@ public void setInstantText(){
523527
rom[ldaLocation] = 0x00;
524528
}
525529

526-
530+
public ArrayList<MonCardData> indicesOfPokemonFromNamePointer(Word namePointer, ArrayList<MonCardData> mons){
531+
ArrayList<MonCardData> ret = new ArrayList<MonCardData>();
532+
for(int i = 0; i < mons.size(); i++){
533+
534+
if(mons.get(i).name.equals(namePointer))
535+
ret.add(mons.get(i));
536+
}
537+
return ret;
538+
}
539+
public void randomizeEvolutions(int maxSize, boolean monoType){
540+
541+
ArrayList<MonCardData> randMons = new ArrayList<MonCardData>(Arrays.asList(mons));
542+
Collections.shuffle(randMons, rand);
543+
ArrayList<MonCardData> tempInd; // used a few times for a short amount of time
544+
ArrayList<MonCardData> usedMons = new ArrayList<MonCardData>();
545+
546+
while(randMons.size() > 0){
547+
548+
MonCardData currMon = randMons.get(0);
549+
550+
tempInd = indicesOfPokemonFromNamePointer(currMon.name, randMons);
551+
for(MonCardData mc : tempInd){
552+
mc.stage = 0x0; // basic
553+
mc.preEvoName = new Word(); // no pre evo (default constructor returns 0000 word)
554+
usedMons.add(mc);
555+
randMons.remove(mc);
556+
}
557+
558+
559+
560+
int maxBound = maxSize;
561+
if(randMons.size() < maxBound)
562+
maxBound = randMons.size();
563+
564+
565+
//this lets us skip randomization and the for loop if we have no pokems left
566+
//we go straight to setting this mon to highest evo
567+
int rnum;
568+
if(maxBound < 1)
569+
rnum = 0;
570+
else
571+
rnum = rand.nextInt(maxBound);
572+
573+
574+
for(int i = rnum; i > 0; i--){
575+
576+
boolean monFound = false;
577+
int newMonNum;
578+
579+
for(newMonNum = 0; newMonNum < randMons.size(); newMonNum++){
580+
if(!monoType || randMons.get(newMonNum).type == currMon.type){
581+
monFound = true;
582+
break;
583+
}
584+
}
585+
586+
if(!monFound)
587+
break;
588+
589+
MonCardData newMon = randMons.get(newMonNum);
590+
591+
if(currMon.stage > 0)
592+
newMon.stage = 0x02;
593+
else
594+
newMon.stage = 0x01;
595+
596+
597+
598+
tempInd = indicesOfPokemonFromNamePointer(newMon.name, randMons);
599+
for(MonCardData mc : tempInd){
600+
mc.stage = newMon.stage;
601+
mc.preEvoName = currMon.name;
602+
usedMons.add(mc);
603+
randMons.remove(mc);
604+
}
605+
606+
607+
currMon = newMon;
608+
}
609+
610+
tempInd = indicesOfPokemonFromNamePointer(currMon.name, randMons);
611+
for(MonCardData mc : tempInd){
612+
mc.highestStage = true;
613+
}
614+
615+
616+
}
617+
618+
619+
}
527620

528621
public void setMoveTypeToMonType() {
529622
for( MonCardData mon : mons){

src/randomizer/Pokemon_TCG/PTCG1_UI.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@
663663
<Component class="javax.swing.JCheckBox" name="setMaxEvolutionChain">
664664
<Properties>
665665
<Property name="text" type="java.lang.String" value="Set Max Evolution Size:"/>
666-
<Property name="toolTipText" type="java.lang.String" value="If selected, sets evolution chanes between 1 and value in the textbox"/>
666+
<Property name="toolTipText" type="java.lang.String" value="If selected, sets evolution chains between 1 and value in the textbox"/>
667667
</Properties>
668668
</Component>
669669
<Component class="javax.swing.JTextField" name="maxEvolutionChainValue">

src/randomizer/Pokemon_TCG/PTCG1_UI.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
424424
keepEvolutionsMonotype.setToolTipText("Generated after types are modified.");
425425

426426
setMaxEvolutionChain.setText("Set Max Evolution Size:");
427-
setMaxEvolutionChain.setToolTipText("If selected, sets evolution chanes between 1 and value in the textbox");
427+
setMaxEvolutionChain.setToolTipText("If selected, sets evolution chains between 1 and value in the textbox");
428428

429429
maxEvolutionChainValue.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
430430
maxEvolutionChainValue.setText("3");
@@ -615,6 +615,19 @@ else if(movesCostColorless.isSelected()){
615615
rando.randomizeTypes();
616616
}
617617

618+
619+
620+
// Has to go after type randomization, before HP Fix though
621+
if(randomizeEvolutions.isSelected()){
622+
String maxSize = maxEvolutionChainValue.getText();
623+
if(!maxSize.matches("[0-9]+"))
624+
maxSize = "999";
625+
626+
rando.randomizeEvolutions(Integer.parseInt(maxSize), keepEvolutionsMonotype.isSelected());
627+
}
628+
629+
630+
//goes after evolution randomization
618631
if(randomizeMovesInStages.isSelected()){
619632
rando.randomizeMoves(true, false);
620633
}
@@ -623,11 +636,12 @@ else if(randomizeMovesFully.isSelected()){
623636
}
624637

625638

639+
626640
// THIS MUST GO AFTER TYPE AND MOVE RANDOMIZATION
627641
if(movesCostSameAsType.isSelected()){
628642
rando.setMoveTypeToMonType();
629-
}
630-
643+
}
644+
631645

632646
fc.setSelectedFile(new File("TCG Randomized.gbc"));
633647
fc.showOpenDialog(PTCG1_UI.this);

src/randomizer/Word.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,13 @@ public byte getHigh(){
5353
public String toString(){
5454
return "" + (0xFFFF & ((0xFF00 & high << 8) + (low & 0xFF)));
5555
}
56+
public boolean equals(Object other){
57+
if (other instanceof Word){
58+
Word o = (Word) other;
59+
return o.high == high && o.low == low;
60+
61+
}
62+
return false;
63+
64+
}
5665
}

0 commit comments

Comments
 (0)