Added class GameData::GenderRatio

This commit is contained in:
Maruno17
2021-02-06 23:11:48 +00:00
parent 2e125019a9
commit eda301b57b
9 changed files with 141 additions and 93 deletions

View File

@@ -15,7 +15,7 @@ module GameData
attr_reader :evs attr_reader :evs
attr_reader :base_exp attr_reader :base_exp
attr_reader :growth_rate attr_reader :growth_rate
attr_reader :gender_rate attr_reader :gender_ratio
attr_reader :catch_rate attr_reader :catch_rate
attr_reader :happiness attr_reader :happiness
attr_reader :moves attr_reader :moves
@@ -119,7 +119,7 @@ module GameData
ret["InternalName"] = [0, "n"] ret["InternalName"] = [0, "n"]
ret["Name"] = [0, "s"] ret["Name"] = [0, "s"]
ret["GrowthRate"] = [0, "e", :PBGrowthRates] ret["GrowthRate"] = [0, "e", :PBGrowthRates]
ret["GenderRate"] = [0, "e", :PBGenderRates] ret["GenderRate"] = [0, "e", :GenderRatio]
ret["Incense"] = [0, "e", :Item] ret["Incense"] = [0, "e", :Item]
ret["Evolutions"] = [0, "*ses", nil, :PBEvolution, nil] ret["Evolutions"] = [0, "*ses", nil, :PBEvolution, nil]
end end
@@ -142,7 +142,7 @@ module GameData
@evs = hash[:evs] || [0, 0, 0, 0, 0, 0] @evs = hash[:evs] || [0, 0, 0, 0, 0, 0]
@base_exp = hash[:base_exp] || 100 @base_exp = hash[:base_exp] || 100
@growth_rate = hash[:growth_rate] || PBGrowthRates::Medium @growth_rate = hash[:growth_rate] || PBGrowthRates::Medium
@gender_rate = hash[:gender_rate] || PBGenderRates::Female50Percent @gender_ratio = hash[:gender_ratio] || :Female50Percent
@catch_rate = hash[:catch_rate] || 255 @catch_rate = hash[:catch_rate] || 255
@happiness = hash[:happiness] || 70 @happiness = hash[:happiness] || 70
@moves = hash[:moves] || [] @moves = hash[:moves] || []

View File

@@ -0,0 +1,75 @@
# If a Pokémon's gender ratio is none of :AlwaysMale, :AlwaysFemale or
# :Genderless, then it will choose a random number between 0 and 255 inclusive,
# and compare it to the @female_chance. If the random number is lower than this
# chance, it will be female; otherwise, it will be male.
module GameData
class GenderRatio
attr_reader :id
attr_reader :real_name
attr_reader :female_chance
DATA = {}
extend ClassMethodsSymbols
include InstanceMethods
def self.load; end
def self.save; end
def initialize(hash)
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"
@female_chance = hash[:female_chance]
end
# @return [String] the translated name of this gender ratio
def name
return _INTL(@real_name)
end
end
end
GameData::GenderRatio.register({
:id => :AlwaysMale,
:name => _INTL("Always Male")
})
GameData::GenderRatio.register({
:id => :AlwaysFemale,
:name => _INTL("Always Female")
})
GameData::GenderRatio.register({
:id => :Genderless,
:name => _INTL("Genderless")
})
GameData::GenderRatio.register({
:id => :FemaleOneEighth,
:name => _INTL("Female One Eighth"),
:female_chance => 32
})
GameData::GenderRatio.register({
:id => :Female25Percent,
:name => _INTL("Female 25 Percent"),
:female_chance => 64
})
GameData::GenderRatio.register({
:id => :Female50Percent,
:name => _INTL("Female 50 Percent"),
:female_chance => 128
})
GameData::GenderRatio.register({
:id => :Female75Percent,
:name => _INTL("Female 75 Percent"),
:female_chance => 192
})
GameData::GenderRatio.register({
:id => :FemaleSevenEighths,
:name => _INTL("Female Seven Eighths"),
:female_chance => 224
})

View File

@@ -1,26 +0,0 @@
module PBGenderRates
Genderless = 0
AlwaysMale = 1
FemaleOneEighth = 2
Female25Percent = 3
Female50Percent = 4
Female75Percent = 5
FemaleSevenEighths = 6
AlwaysFemale = 7
def self.maxValue; return 7; end
def self.genderByte(gender)
case gender
when AlwaysMale then return 0
when FemaleOneEighth then return 32
when Female25Percent then return 64
when Female50Percent then return 128
when Female75Percent then return 192
when FemaleSevenEighths then return 224
when AlwaysFemale then return 254
when Genderless then return 255
end
return 255 # Default value (genderless)
end
end

View File

@@ -310,13 +310,14 @@ class Pokemon
# @return [0, 1, 2] this Pokémon's gender (0 = male, 1 = female, 2 = genderless) # @return [0, 1, 2] this Pokémon's gender (0 = male, 1 = female, 2 = genderless)
def gender def gender
if !@gender if !@gender
gender_rate = species_data.gender_rate gender_ratio = species_data.gender_ratio
case gender_rate case gender_ratio
when PBGenderRates::AlwaysMale then @gender = 0 when :AlwaysMale then @gender = 0
when PBGenderRates::AlwaysFemale then @gender = 1 when :AlwaysFemale then @gender = 1
when PBGenderRates::Genderless then @gender = 2 when :Genderless then @gender = 2
else else
@gender = ((@personalID & 0xFF) < PBGenderRates.genderByte(gender_rate)) ? 1 : 0 female_chance = GameData::GenderRatio.get(gender_ratio).female_chance
@gender = ((@personalID & 0xFF) < female_chance) ? 1 : 0
end end
end end
return @gender return @gender
@@ -350,9 +351,8 @@ class Pokemon
# @return [Boolean] whether this Pokémon species is restricted to only ever being one # @return [Boolean] whether this Pokémon species is restricted to only ever being one
# gender (or genderless) # gender (or genderless)
def singleGendered? def singleGendered?
gender_rate = species_data.gender_rate gender_ratio = species_data.gender_ratio
return [PBGenderRates::AlwaysMale, PBGenderRates::AlwaysFemale, return [:AlwaysMale, :AlwaysFemale, :Genderless].include?(gender_ratio)
PBGenderRates::Genderless].include?(gender_rate)
end end
alias isSingleGendered? singleGendered? alias isSingleGendered? singleGendered?

View File

@@ -150,11 +150,11 @@ class PokemonPokedexInfo_Scene
next if sp.pokedex_form != sp.form next if sp.pokedex_form != sp.form
multiple_forms = true if sp.form > 0 multiple_forms = true if sp.form > 0
$Trainer.seen_forms[@species] = [[], []] if !$Trainer.seen_forms[@species] $Trainer.seen_forms[@species] = [[], []] if !$Trainer.seen_forms[@species]
case sp.gender_rate case sp.gender_ratio
when PBGenderRates::AlwaysMale, PBGenderRates::AlwaysFemale, PBGenderRates::Genderless when :AlwaysMale, :AlwaysFemale, :Genderless
real_gender = (sp.gender_rate == PBGenderRates::AlwaysFemale) ? 1 : 0 real_gender = (sp.gender_ratio == :AlwaysFemale) ? 1 : 0
next if !$Trainer.seen_forms[@species][real_gender][sp.form] && !Settings::DEX_SHOWS_ALL_FORMS next if !$Trainer.seen_forms[@species][real_gender][sp.form] && !Settings::DEX_SHOWS_ALL_FORMS
real_gender = 2 if sp.gender_rate == PBGenderRates::Genderless real_gender = 2 if sp.gender_ratio == :Genderless
ret.push([sp.form_name, real_gender, sp.form]) ret.push([sp.form_name, real_gender, sp.form])
else # Both male and female else # Both male and female
for real_gender in 0...2 for real_gender in 0...2

View File

@@ -598,9 +598,8 @@ DebugMenuCommands.register("fillboxes", {
if f == 0 if f == 0
$Trainer.set_seen(sp) $Trainer.set_seen(sp)
$Trainer.set_owned(sp) $Trainer.set_owned(sp)
if [PBGenderRates::AlwaysMale, PBGenderRates::AlwaysFemale, if [:AlwaysMale, :AlwaysFemale, :Genderless].include?(species_data.gender_ratio)
PBGenderRates::Genderless].include?(species_data.gender_rate) g = (species_data.gender_ratio == :AlwaysFemale) ? 1 : 0
g = (species_data.gender_rate == PBGenderRates::AlwaysFemale) ? 1 : 0
$Trainer.seen_forms[sp][g][f] = true $Trainer.seen_forms[sp][g][f] = true
$Trainer.last_seen_forms[sp] = [g, f] if f == 0 $Trainer.last_seen_forms[sp] = [g, f] if f == 0
else # Both male and female else # Both male and female
@@ -609,7 +608,7 @@ DebugMenuCommands.register("fillboxes", {
$Trainer.last_seen_forms[sp] = [0, f] if f == 0 $Trainer.last_seen_forms[sp] = [0, f] if f == 0
end end
elsif species_data.real_form_name && !species_data.real_form_name.empty? elsif species_data.real_form_name && !species_data.real_form_name.empty?
g = (species_data.gender_rate == PBGenderRates::AlwaysFemale) ? 1 : 0 g = (species_data.gender_ratio == :AlwaysFemale) ? 1 : 0
$Trainer.seen_forms[sp][g][f] = true $Trainer.seen_forms[sp][g][f] = true
end end
# Add Pokémon (if form 0) # Add Pokémon (if form 0)

View File

@@ -948,50 +948,50 @@ end
#=============================================================================== #===============================================================================
def pbPokemonEditor def pbPokemonEditor
species_properties = [ species_properties = [
[_INTL("InternalName"), ReadOnlyProperty, _INTL("Internal name of the Pokémon.")], [_INTL("InternalName"), ReadOnlyProperty, _INTL("Internal name of the Pokémon.")],
[_INTL("Name"), LimitStringProperty.new(Pokemon::MAX_NAME_SIZE), _INTL("Name of the Pokémon.")], [_INTL("Name"), LimitStringProperty.new(Pokemon::MAX_NAME_SIZE), _INTL("Name of the Pokémon.")],
[_INTL("FormName"), StringProperty, _INTL("Name of this form of the Pokémon.")], [_INTL("FormName"), StringProperty, _INTL("Name of this form of the Pokémon.")],
[_INTL("Kind"), StringProperty, _INTL("Kind of Pokémon species.")], [_INTL("Kind"), StringProperty, _INTL("Kind of Pokémon species.")],
[_INTL("Pokédex"), StringProperty, _INTL("Description of the Pokémon as displayed in the Pokédex.")], [_INTL("Pokédex"), StringProperty, _INTL("Description of the Pokémon as displayed in the Pokédex.")],
[_INTL("Type1"), TypeProperty, _INTL("Pokémon's type. If same as Type2, this Pokémon has a single type.")], [_INTL("Type1"), TypeProperty, _INTL("Pokémon's type. If same as Type2, this Pokémon has a single type.")],
[_INTL("Type2"), TypeProperty, _INTL("Pokémon's type. If same as Type1, this Pokémon has a single type.")], [_INTL("Type2"), TypeProperty, _INTL("Pokémon's type. If same as Type1, this Pokémon has a single type.")],
[_INTL("BaseStats"), BaseStatsProperty, _INTL("Base stats of the Pokémon.")], [_INTL("BaseStats"), BaseStatsProperty, _INTL("Base stats of the Pokémon.")],
[_INTL("EffortPoints"), EffortValuesProperty, _INTL("Effort Value points earned when this species is defeated.")], [_INTL("EffortPoints"), EffortValuesProperty, _INTL("Effort Value points earned when this species is defeated.")],
[_INTL("BaseEXP"), LimitProperty.new(9999), _INTL("Base experience earned when this species is defeated.")], [_INTL("BaseEXP"), LimitProperty.new(9999), _INTL("Base experience earned when this species is defeated.")],
[_INTL("GrowthRate"), EnumProperty2.new(PBGrowthRates), _INTL("Pokémon's growth rate.")], [_INTL("GrowthRate"), EnumProperty2.new(PBGrowthRates), _INTL("Pokémon's growth rate.")],
[_INTL("GenderRate"), EnumProperty2.new(PBGenderRates), _INTL("Proportion of males to females for this species.")], [_INTL("GenderRate"), GameDataProperty.new(:GenderRatio), _INTL("Proportion of males to females for this species.")],
[_INTL("Rareness"), LimitProperty.new(255), _INTL("Catch rate of this species (0-255).")], [_INTL("Rareness"), LimitProperty.new(255), _INTL("Catch rate of this species (0-255).")],
[_INTL("Happiness"), LimitProperty.new(255), _INTL("Base happiness of this species (0-255).")], [_INTL("Happiness"), LimitProperty.new(255), _INTL("Base happiness of this species (0-255).")],
[_INTL("Moves"), MovePoolProperty, _INTL("Moves which the Pokémon learns while levelling up.")], [_INTL("Moves"), MovePoolProperty, _INTL("Moves which the Pokémon learns while levelling up.")],
[_INTL("TutorMoves"), EggMovesProperty, _INTL("Moves which the Pokémon can be taught by TM/HM/Move Tutor.")], [_INTL("TutorMoves"), EggMovesProperty, _INTL("Moves which the Pokémon can be taught by TM/HM/Move Tutor.")],
[_INTL("EggMoves"), EggMovesProperty, _INTL("Moves which the Pokémon can learn via breeding.")], [_INTL("EggMoves"), EggMovesProperty, _INTL("Moves which the Pokémon can learn via breeding.")],
[_INTL("Ability1"), AbilityProperty, _INTL("One ability which the Pokémon can have.")], [_INTL("Ability1"), AbilityProperty, _INTL("One ability which the Pokémon can have.")],
[_INTL("Ability2"), AbilityProperty, _INTL("Another ability which the Pokémon can have.")], [_INTL("Ability2"), AbilityProperty, _INTL("Another ability which the Pokémon can have.")],
[_INTL("HiddenAbility 1"), AbilityProperty, _INTL("A secret ability which the Pokémon can have.")], [_INTL("HiddenAbility 1"), AbilityProperty, _INTL("A secret ability which the Pokémon can have.")],
[_INTL("HiddenAbility 2"), AbilityProperty, _INTL("A secret ability which the Pokémon can have.")], [_INTL("HiddenAbility 2"), AbilityProperty, _INTL("A secret ability which the Pokémon can have.")],
[_INTL("HiddenAbility 3"), AbilityProperty, _INTL("A secret ability which the Pokémon can have.")], [_INTL("HiddenAbility 3"), AbilityProperty, _INTL("A secret ability which the Pokémon can have.")],
[_INTL("HiddenAbility 4"), AbilityProperty, _INTL("A secret ability which the Pokémon can have.")], [_INTL("HiddenAbility 4"), AbilityProperty, _INTL("A secret ability which the Pokémon can have.")],
[_INTL("WildItemCommon"), ItemProperty, _INTL("Item commonly held by wild Pokémon of this species.")], [_INTL("WildItemCommon"), ItemProperty, _INTL("Item commonly held by wild Pokémon of this species.")],
[_INTL("WildItemUncommon"), ItemProperty, _INTL("Item uncommonly held by wild Pokémon of this species.")], [_INTL("WildItemUncommon"), ItemProperty, _INTL("Item uncommonly held by wild Pokémon of this species.")],
[_INTL("WildItemRare"), ItemProperty, _INTL("Item rarely held by wild Pokémon of this species.")], [_INTL("WildItemRare"), ItemProperty, _INTL("Item rarely held by wild Pokémon of this species.")],
[_INTL("Compat1"), GameDataProperty.new(:EggGroup), _INTL("Compatibility group (egg group) for breeding purposes.")], [_INTL("Compat1"), GameDataProperty.new(:EggGroup), _INTL("Compatibility group (egg group) for breeding purposes.")],
[_INTL("Compat2"), GameDataProperty.new(:EggGroup), _INTL("Compatibility group (egg group) for breeding purposes.")], [_INTL("Compat2"), GameDataProperty.new(:EggGroup), _INTL("Compatibility group (egg group) for breeding purposes.")],
[_INTL("StepsToHatch"), LimitProperty.new(99999), _INTL("Number of steps until an egg of this species hatches.")], [_INTL("StepsToHatch"), LimitProperty.new(99999), _INTL("Number of steps until an egg of this species hatches.")],
[_INTL("Incense"), ItemProperty, _INTL("Item needed to be held by a parent to produce an egg of this species.")], [_INTL("Incense"), ItemProperty, _INTL("Item needed to be held by a parent to produce an egg of this species.")],
[_INTL("Evolutions"), EvolutionsProperty.new, _INTL("Evolution paths of this species.")], [_INTL("Evolutions"), EvolutionsProperty.new, _INTL("Evolution paths of this species.")],
[_INTL("Height"), NonzeroLimitProperty.new(999), _INTL("Height of the Pokémon in 0.1 metres (e.g. 42 = 4.2m).")], [_INTL("Height"), NonzeroLimitProperty.new(999), _INTL("Height of the Pokémon in 0.1 metres (e.g. 42 = 4.2m).")],
[_INTL("Weight"), NonzeroLimitProperty.new(9999), _INTL("Weight of the Pokémon in 0.1 kilograms (e.g. 42 = 4.2kg).")], [_INTL("Weight"), NonzeroLimitProperty.new(9999), _INTL("Weight of the Pokémon in 0.1 kilograms (e.g. 42 = 4.2kg).")],
[_INTL("Color"), GameDataProperty.new(:BodyColor), _INTL("Pokémon's body color.")], [_INTL("Color"), GameDataProperty.new(:BodyColor), _INTL("Pokémon's body color.")],
[_INTL("Shape"), LimitProperty.new(14), _INTL("Body shape of this species (0-14).")], [_INTL("Shape"), LimitProperty.new(14), _INTL("Body shape of this species (0-14).")],
[_INTL("Habitat"), GameDataProperty.new(:Habitat), _INTL("The habitat of this species.")], [_INTL("Habitat"), GameDataProperty.new(:Habitat), _INTL("The habitat of this species.")],
[_INTL("Generation"), LimitProperty.new(99999), _INTL("The number of the generation the Pokémon debuted in.")], [_INTL("Generation"), LimitProperty.new(99999), _INTL("The number of the generation the Pokémon debuted in.")],
[_INTL("BattlerPlayerX"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")], [_INTL("BattlerPlayerX"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")],
[_INTL("BattlerPlayerY"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")], [_INTL("BattlerPlayerY"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")],
[_INTL("BattlerEnemyX"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")], [_INTL("BattlerEnemyX"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")],
[_INTL("BattlerEnemyY"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")], [_INTL("BattlerEnemyY"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")],
[_INTL("BattlerAltitude"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")], [_INTL("BattlerAltitude"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")],
[_INTL("BattlerShadowX"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")], [_INTL("BattlerShadowX"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")],
[_INTL("BattlerShadowSize"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")], [_INTL("BattlerShadowSize"), ReadOnlyProperty, _INTL("Affects positioning of the Pokémon in battle. This is edited elsewhere.")],
] ]
pbListScreenBlock(_INTL("Pokémon species"), SpeciesLister.new(0, false)) { |button, species| pbListScreenBlock(_INTL("Pokémon species"), SpeciesLister.new(0, false)) { |button, species|
if species if species
@@ -1027,7 +1027,7 @@ def pbPokemonEditor
spec.evs.clone, spec.evs.clone,
spec.base_exp, spec.base_exp,
spec.growth_rate, spec.growth_rate,
spec.gender_rate, spec.gender_ratio,
spec.catch_rate, spec.catch_rate,
spec.happiness, spec.happiness,
moves, moves,
@@ -1084,7 +1084,7 @@ def pbPokemonEditor
:evs => data[8], :evs => data[8],
:base_exp => data[9], :base_exp => data[9],
:growth_rate => data[10], :growth_rate => data[10],
:gender_rate => data[11], :gender_ratio => data[11],
:catch_rate => data[12], :catch_rate => data[12],
:happiness => data[13], :happiness => data[13],
:moves => data[14], :moves => data[14],

View File

@@ -459,7 +459,7 @@ module Compiler
:evs => contents["EffortPoints"], :evs => contents["EffortPoints"],
:base_exp => contents["BaseEXP"], :base_exp => contents["BaseEXP"],
:growth_rate => contents["GrowthRate"], :growth_rate => contents["GrowthRate"],
:gender_rate => contents["GenderRate"], :gender_ratio => contents["GenderRate"],
:catch_rate => contents["Rareness"], :catch_rate => contents["Rareness"],
:happiness => contents["Happiness"], :happiness => contents["Happiness"],
:moves => contents["Moves"], :moves => contents["Moves"],

View File

@@ -273,7 +273,7 @@ module Compiler
f.write(sprintf("Type1 = %s\r\n", species.type1)) f.write(sprintf("Type1 = %s\r\n", species.type1))
f.write(sprintf("Type2 = %s\r\n", species.type2)) if species.type2 != species.type1 f.write(sprintf("Type2 = %s\r\n", species.type2)) if species.type2 != species.type1
f.write(sprintf("BaseStats = %s\r\n", species.base_stats.join(","))) f.write(sprintf("BaseStats = %s\r\n", species.base_stats.join(",")))
f.write(sprintf("GenderRate = %s\r\n", getConstantName(PBGenderRates, species.gender_rate))) f.write(sprintf("GenderRate = %s\r\n", species.gender_ratio))
f.write(sprintf("GrowthRate = %s\r\n", getConstantName(PBGrowthRates, species.growth_rate))) f.write(sprintf("GrowthRate = %s\r\n", getConstantName(PBGrowthRates, species.growth_rate)))
f.write(sprintf("BaseEXP = %d\r\n", species.base_exp)) f.write(sprintf("BaseEXP = %d\r\n", species.base_exp))
f.write(sprintf("EffortPoints = %s\r\n", species.evs.join(","))) f.write(sprintf("EffortPoints = %s\r\n", species.evs.join(",")))