Improves npc appearance generation algorithm

This commit is contained in:
chardub
2025-03-17 10:36:36 -04:00
parent 563390c166
commit 455bebbd1b
15 changed files with 35 additions and 22 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -87,6 +87,7 @@ end
def shiftHairColor(incr) def shiftHairColor(incr)
$Trainer.hair_color = 0 if !$Trainer.hair_color $Trainer.hair_color = 0 if !$Trainer.hair_color
$Trainer.hair_color += incr $Trainer.hair_color += incr
echoln "Hair color: #{$Trainer.hair_color}"
refreshPlayerOutfit() refreshPlayerOutfit()
end end
@@ -248,20 +249,6 @@ def generateNPCClothedBitmapStatic(trainerAppearance,action = "walk")
hatBitmapWrapper = AnimatedBitmap.new(hatFilename, hat_color_shift) if pbResolveBitmap(hatFilename) hatBitmapWrapper = AnimatedBitmap.new(hatFilename, hat_color_shift) if pbResolveBitmap(hatFilename)
hat2BitmapWrapper = AnimatedBitmap.new(hat2Filename, hat2_color_shift) if pbResolveBitmap(hat2Filename) hat2BitmapWrapper = AnimatedBitmap.new(hat2Filename, hat2_color_shift) if pbResolveBitmap(hat2Filename)
if hatBitmapWrapper
frame_count = 4 # Assuming 4 frames for hair animation; adjust as needed
hat_frame_bitmap = duplicateHatForFrames(hatBitmapWrapper.bitmap, frame_count)
frame_width = baseSprite.bitmap.width / frame_count # Calculate frame width
frame_count.times do |i|
# Calculate offset for each frame
frame_offset = [i * frame_width, 0]
# Adjust Y offset if frame index is odd
frame_offset[1] -= 2 if i.odd?
positionHat(baseBitmap, hat_frame_bitmap, frame_offset, i, frame_width)
end
end
if hat2BitmapWrapper if hat2BitmapWrapper
frame_count = 4 # Assuming 4 frames for hair animation; adjust as needed frame_count = 4 # Assuming 4 frames for hair animation; adjust as needed
@@ -278,6 +265,21 @@ def generateNPCClothedBitmapStatic(trainerAppearance,action = "walk")
end end
end end
if hatBitmapWrapper
frame_count = 4 # Assuming 4 frames for hair animation; adjust as needed
hat_frame_bitmap = duplicateHatForFrames(hatBitmapWrapper.bitmap, frame_count)
frame_width = baseSprite.bitmap.width / frame_count # Calculate frame width
frame_count.times do |i|
# Calculate offset for each frame
frame_offset = [i * frame_width, 0]
# Adjust Y offset if frame index is odd
frame_offset[1] -= 2 if i.odd?
positionHat(baseBitmap, hat_frame_bitmap, frame_offset, i, frame_width)
end
end
return baseBitmap return baseBitmap
end end

View File

@@ -315,13 +315,16 @@ def randomizePlayerOutfitUnlocked()
end end
def convert_letter_to_number(letter, max_number = nil) def convert_letter_to_number(letter, max_number = nil)
return 0 if !letter return 0 unless letter
return letter.ord if !max_number base_value = (letter.ord * 31) & 0xFFFFFFFF # Use a prime multiplier to spread values
return letter.ord % max_number return base_value unless max_number
return base_value % max_number
end end
def generate_appearance_from_name(name) def generate_appearance_from_name(name)
name_seed_length = 11 name_seed_length = 13
max_dye_color=360
seed = name[0, name_seed_length] # Truncate if longer than 8 seed = name[0, name_seed_length] # Truncate if longer than 8
seed += seed[0, name_seed_length - seed.length] while seed.length < name_seed_length # Repeat first characters if shorter seed += seed[0, name_seed_length - seed.length] while seed.length < name_seed_length # Repeat first characters if shorter
@@ -333,17 +336,24 @@ def generate_appearance_from_name(name)
hairstyles_list = $PokemonGlobal.hairstyles_data.keys hairstyles_list = $PokemonGlobal.hairstyles_data.keys
hat = hats_list[convert_letter_to_number(seed[0],hats_list.length)] hat = hats_list[convert_letter_to_number(seed[0],hats_list.length)]
hat_color = convert_letter_to_number(seed[1],200) hat_color = convert_letter_to_number(seed[1],max_dye_color)
hat2_color = convert_letter_to_number(seed[2],max_dye_color)
hat_color = 0 if convert_letter_to_number(seed[2]) % 2 == 0 #1/2 chance of no dyed hat hat_color = 0 if convert_letter_to_number(seed[2]) % 2 == 0 #1/2 chance of no dyed hat
hat2 = hats_list[convert_letter_to_number(seed[10],hats_list.length)]
hat2_color = 0 if convert_letter_to_number(seed[11]) % 2 == 0 #1/2 chance of no dyed ha
hat2 = "" if convert_letter_to_number(seed[12]) % 2 == 0 #1/2 chance of no 2nd hat
clothes = clothes_list[convert_letter_to_number(seed[3],clothes_list.length)] clothes = clothes_list[convert_letter_to_number(seed[3],clothes_list.length)]
clothes_color = convert_letter_to_number(seed[4],200) clothes_color = convert_letter_to_number(seed[4],max_dye_color)
clothes_color = 0 if convert_letter_to_number(seed[5]) % 2 == 0 #1/2 chance of no dyed clothes clothes_color = 0 if convert_letter_to_number(seed[5]) % 2 == 0 #1/2 chance of no dyed clothes
hair_base = hairstyles_list[convert_letter_to_number(seed[6],hairstyles_list.length)] hair_base = hairstyles_list[convert_letter_to_number(seed[6],hairstyles_list.length)]
hair_number = [1,2,3,4][convert_letter_to_number(seed[7],3)] hair_number = [1,2,3,4][convert_letter_to_number(seed[7],3)]
echoln "hair_number: #{hair_number}"
hair=getFullHairId(hair_base,hair_number) hair=getFullHairId(hair_base,hair_number)
hair_color = convert_letter_to_number(seed[8],200) hair_color = convert_letter_to_number(seed[8],max_dye_color)
hair_color = 0 if convert_letter_to_number(seed[9]) % 2 == 0 #1/2 chance of no dyed hair hair_color = 0 if convert_letter_to_number(seed[9]) % 2 == 0 #1/2 chance of no dyed hair
echoln hair_color echoln hair_color
@@ -352,7 +362,8 @@ def generate_appearance_from_name(name)
skin_tone = [1,2,3,4,5,6][convert_letter_to_number(seed[10],5)] skin_tone = [1,2,3,4,5,6][convert_letter_to_number(seed[10],5)]
return TrainerAppearance.new(skin_tone,hat,clothes, hair, return TrainerAppearance.new(skin_tone,hat,clothes, hair,
hair_color, clothes_color, hat_color) hair_color, clothes_color, hat_color,
hat2,hat2_color)
end end

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.