Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLEANUP] Refactoring of python files inside cats, cat_relations, and clan_resoucres folders #3251

Open
wants to merge 59 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
66c4400
Removed completely unused text
Dec 20, 2024
7340cde
Refactoring dealign with leader death
Dec 20, 2024
374461a
cats status_change refactoring
Dec 20, 2024
6e88b9c
cats rank_change_traits_skill refactoring
Dec 20, 2024
fade5cc
cats refactorign life givers in leader ceremony
Dec 20, 2024
2f201eb
refacotring pickign dead ledaer inder leader ceremony
Dec 20, 2024
21899cd
Fixed strange leader_lives modifications for leader birth death
Dec 20, 2024
9ba4d93
Minor code cleaning
Dec 21, 2024
d15b5dc
cats refactoring illness and injury recovery
Dec 21, 2024
4c1eb34
replaced minimum duration check with clamp range
Dec 21, 2024
3703b06
cats get_permanent_condition refactor
Dec 21, 2024
a2fff38
Checking if a mentor is even needed first in is_valid_mentor
Dec 21, 2024
662c9fd
cats set_mate refactoring
Dec 21, 2024
ea8633f
cats set_adoptive_parent refactoring
Dec 21, 2024
a50c376
cats create_relationships_new_cat refactoring
Dec 21, 2024
9ef1778
cats mediate_relationship refactoring
Dec 21, 2024
ccac41c
names Handles predefined suffixes refactoring
filvas2 Dec 21, 2024
393b079
Fixed typo where it said 1/8, but was 1/4 chance
filvas2 Dec 21, 2024
70e444b
name give_suffix refactoring
filvas2 Dec 21, 2024
a909e74
names give_prefix refactoring
filvas2 Dec 21, 2024
14c80d2
pelts check and convert, and inhherit refactoring
filvas2 Dec 21, 2024
0d2cf6c
personality refactoring of adjust range to use clamp utility
filvas2 Dec 21, 2024
fe162fd
skills mentor influence and progress skill refactoring
filvas2 Dec 21, 2024
c5378e8
thoughts cats_fulfill_thought_constraints refactoring
filvas2 Dec 21, 2024
d74c0db
found strange code in cats_fulfill_thought_constraints, making refact…
filvas2 Dec 21, 2024
1c800aa
using os.path.exists instead of try catch in new_death_thought, leade…
filvas2 Dec 21, 2024
0374110
inheritance update_all_related_inheritance refactor
filvas2 Dec 21, 2024
1e94454
Inheritance init_kits refactoring
filvas2 Dec 21, 2024
e65078d
relationship start_interaction refactoring
filvas2 Dec 21, 2024
f3716f9
relationship get_amount refactor
filvas2 Dec 21, 2024
b2032eb
Usage of clamp functionality for relationship setters
filvas2 Dec 21, 2024
2471ceb
freshkill tactic_less_nutrition_first, tactic_hunter_first, feed_grou…
filvas2 Dec 21, 2024
a1d5160
Fixed typo i made
filvas2 Dec 22, 2024
468b615
Typo fix
filvas2 Dec 22, 2024
008e9df
variable clarification
filvas2 Dec 22, 2024
f99e134
Merge branch 'ClanGenOfficial:development' into development
filvas2 Dec 22, 2024
dfff735
give_prefix further refactoring
filvas2 Dec 22, 2024
d03e196
typo fix in thought
filvas2 Dec 22, 2024
3dd20be
names __repr__ bugfix of bug i made
filvas2 Dec 22, 2024
66198c4
fixed incorrect load_thoughts readings
filvas2 Dec 22, 2024
27b3fb2
Wrong order of test in if statement
filvas2 Dec 22, 2024
3793273
Merge branch 'ClanGenOfficial:development' into development
filvas2 Dec 23, 2024
b232dc7
Merge branch 'ClanGenOfficial:development' into Refactoring
filvas2 Dec 24, 2024
8ab527d
Merge remote-tracking branch 'origin/Base' into Refactoring
filvas2 Dec 24, 2024
6101761
missing excepting after merge
filvas2 Dec 24, 2024
a87f34f
Accidental removal of wrong code during merge
filvas2 Dec 24, 2024
57ebf76
Merge branch 'ClanGenOfficial:development' into Refactoring
filvas2 Dec 25, 2024
2c1eebc
pelt_ -> _pelt
filvas2 Dec 26, 2024
dbaaeeb
Merge branch 'Refactoring' of github.com:filvas2/clangenRefactorignAt…
filvas2 Dec 26, 2024
5201a18
Exception -> IOError
filvas2 Dec 26, 2024
0c8268c
typo fix
filvas2 Dec 26, 2024
a82b6a0
Accidental import removed
filvas2 Dec 26, 2024
2b8830c
typo fix
filvas2 Dec 26, 2024
004bdb5
Merge branch 'ClanGenOfficial:development' into Refactoring
filvas2 Dec 26, 2024
52e69c8
Merge branch 'ClanGenOfficial:development' into Refactoring
filvas2 Dec 27, 2024
2110c24
Merge branch 'ClanGenOfficial:development' into Refactoring
filvas2 Dec 29, 2024
6a14cb7
Merge branch 'ClanGenOfficial:development' into Refactoring
filvas2 Dec 29, 2024
b6b2fff
Merge remote-tracking branch 'origin/Base' into Refactoring
filvas2 Jan 3, 2025
63ed142
Merge remote-tracking branch 'origin/Base' into Refactoring
Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
511 changes: 165 additions & 346 deletions scripts/cat/cats.py

Large diffs are not rendered by default.

97 changes: 35 additions & 62 deletions scripts/cat/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,39 +174,26 @@ def __str__(self):

# Generate possible prefix
def give_prefix(self, eyes, colour, biome):
"""Generate possible prefix."""
# decided in game config: cat_name_controls
if game.config["cat_name_controls"]["always_name_after_appearance"]:
named_after_appearance = True
else:
named_after_appearance = not random.getrandbits(
2
) # Chance for True is '1/4'

named_after_biome_ = not random.getrandbits(3) # chance for True is 1/8

# Add possible prefix categories to list.
"""Generate possible prefix. Prefix preference is biome->appearance->generic"""
name_distribution = random.randint(1,8)
possible_prefix_categories = []
if (
eyes in self.names_dict["eye_prefixes"]
and game.config["cat_name_controls"]["allow_eye_names"]
):
possible_prefix_categories.append(self.names_dict["eye_prefixes"][eyes])
if colour in self.names_dict["colour_prefixes"]:
possible_prefix_categories.append(
self.names_dict["colour_prefixes"][colour]
)
if biome is not None and biome in self.names_dict["biome_prefixes"]:
possible_prefix_categories.append(self.names_dict["biome_prefixes"][biome])
# named after biome is '1/8'
if(name_distribution <= 1):
if biome is not None and biome in self.names_dict["biome_prefixes"]:
possible_prefix_categories.append(self.names_dict["biome_prefixes"][biome])
# named after appearance is '1/4' or in game config: cat_name_controls or
elif name_distribution <= 3 or game.config["cat_name_controls"]["always_name_after_appearance"]:
if eyes in self.names_dict["eye_prefixes"] and game.config["cat_name_controls"][
"allow_eye_names"
]:
possible_prefix_categories.append(self.names_dict["eye_prefixes"][eyes])
if colour in self.names_dict["colour_prefixes"]:
possible_prefix_categories.append(
self.names_dict["colour_prefixes"][colour]
)

# Choose appearance-based prefix if possible and named_after_appearance because True.
if (
named_after_appearance
and possible_prefix_categories
and not named_after_biome_
or named_after_biome_
and possible_prefix_categories
):
# If prefix based on appearcane or biome was identified
if possible_prefix_categories:
prefix_category = random.choice(possible_prefix_categories)
self.prefix = random.choice(prefix_category)
else:
Expand All @@ -231,13 +218,13 @@ def give_prefix(self, eyes, colour, biome):
# Generate possible suffix
def give_suffix(self, pelt, biome, tortiepattern):
"""Generate possible suffix."""
if pelt is None or pelt == "SingleColour":
self.suffix = random.choice(self.names_dict["normal_suffixes"])
else:
named_after_pelt = not random.getrandbits(2) # Chance for True is '1/8'.
named_after_biome = not random.getrandbits(3) # 1/8
# Pelt name only gets used if there's an associated suffix.
if named_after_pelt:
self.suffix = random.choice(self.names_dict["normal_suffixes"])

if pelt is not None and pelt != "SingleColour":
name_distribution = random.randint(1,8)
# 1/8 chance for pelt suffix
if(name_distribution <=1):
# Pelt name only gets used if there's an associated suffix.
if (
pelt in ["Tortie", "Calico"]
and tortiepattern in self.names_dict["tortie_pelt_suffixes"]
Expand All @@ -247,42 +234,27 @@ def give_suffix(self, pelt, biome, tortiepattern):
)
elif pelt in self.names_dict["pelt_suffixes"]:
self.suffix = random.choice(self.names_dict["pelt_suffixes"][pelt])
else:
self.suffix = random.choice(self.names_dict["normal_suffixes"])
elif named_after_biome:
# 1/8 chance for biome suffix
elif(name_distribution <=2):
if biome in self.names_dict["biome_suffixes"]:
self.suffix = random.choice(
self.names_dict["biome_suffixes"][biome]
)
else:
self.suffix = random.choice(self.names_dict["normal_suffixes"])
else:
self.suffix = random.choice(self.names_dict["normal_suffixes"])


def __repr__(self):
# Handles predefined suffixes (such as newborns being kit),
# then suffixes based on ages (fixes #2004, just trust me)

# Handles suffix assignment with outside cats
if self.cat.status in ["exiled", "lost"]:
adjusted_status: str = ""
if self.cat.moons >= 15:
adjusted_status = "warrior"
elif self.cat.moons >= 6:
adjusted_status = "apprentice"
if self.cat.moons == 0:
adjusted_status = "newborn"
elif self.cat.moons < 6:
adjusted_status = "kitten"
elif self.cat.moons < 12:
adjusted_status = "apprentice"
else:
adjusted_status = "warrior"

if adjusted_status != "warrior":
return (
self.prefix + self.names_dict["special_suffixes"][adjusted_status]
)
if(self.cat.moons < 1):
return self.prefix + self.names_dict["special_suffixes"]["newborn"]
elif(self.cat.moons < 6):
return self.prefix + self.names_dict["special_suffixes"]["kitten"]
elif(self.cat.moons < 12):
return self.prefix + self.names_dict["special_suffixes"]["apprentice"]
if (
self.cat.status in self.names_dict["special_suffixes"]
and not self.specsuffix_hidden
Expand All @@ -291,6 +263,7 @@ def __repr__(self):
if game.config["fun"]["april_fools"]:
return f"{self.prefix}egg"
return self.prefix + self.suffix



names = Name()
Expand Down
97 changes: 44 additions & 53 deletions scripts/cat/pelts.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,13 @@ class Pelt:
"FULLWHITE",
]

#For converting outdated white patch format
OLD_WHITE_PATCH_DICT = {
'POINTMARK': "SEALPOINT",
'PANTS2': 'PANTSTWO',
'ANY2': 'ANYTWO',
"VITILIGO2": "VITILIGOTWO"
}
skin_sprites = [
"BLACK",
"PINK",
Expand Down Expand Up @@ -718,18 +725,12 @@ def generate_new_pelt(gender: str, parents: tuple = (), age: str = "adult"):

def check_and_convert(self, convert_dict):
"""Checks for old-type properties for the appearance-related properties
that are stored in Pelt, and converts them. To be run when loading a cat in."""

that are stored in Pelt, and converts them. To be run when loading a cat in. """
# First, convert from some old names that may be in white_patches.
if self.white_patches == "POINTMARK":
self.white_patches = "SEALPOINT"
elif self.white_patches == "PANTS2":
self.white_patches = "PANTSTWO"
elif self.white_patches == "ANY2":
self.white_patches = "ANYTWO"
elif self.white_patches == "VITILIGO2":
self.white_patches = "VITILIGOTWO"

if self.white_patches in Pelt.OLD_WHITE_PATCH_DICT.keys():
self.white_patches = Pelt.OLD_WHITE_PATCH_DICT[self.white_patches]

if self.vitiligo == "VITILIGO2":
self.vitiligo = "VITILIGOTWO"

Expand Down Expand Up @@ -759,10 +760,7 @@ def check_and_convert(self, convert_dict):
self.eye_colour2 = "COBALT"

if self.eye_colour in ["BLUEYELLOW", "BLUEGREEN"]:
if self.eye_colour == "BLUEYELLOW":
self.eye_colour2 = "YELLOW"
elif self.eye_colour == "BLUEGREEN":
self.eye_colour2 = "GREEN"
self.eye_colour2 = self.eye_colour.replace('BLUE','')
self.eye_colour = "BLUE"

if self.length == "long":
Expand Down Expand Up @@ -850,25 +848,25 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"):
par_peltnames = set()
par_pelts = []
par_white = []
for p in parents:
if p:
for parent in parents:
if parent:
# Gather pelt color.
par_peltcolours.add(p.pelt.colour)
par_peltcolours.add(parent.pelt.colour)

# Gather pelt length
par_peltlength.add(p.pelt.length)
par_peltlength.add(parent.pelt.length)

# Gather pelt name
if p.pelt.name in Pelt.torties:
par_peltnames.add(p.pelt.tortiebase.capitalize())
if parent.pelt.name in Pelt.torties:
par_peltnames.add(parent.pelt.tortiebase.capitalize())
else:
par_peltnames.add(p.pelt.name)
par_peltnames.add(parent.pelt.name)

# Gather exact pelts, for direct inheritance.
par_pelts.append(p.pelt)
par_pelts.append(parent.pelt)

# Gather if they have white in their pelt.
par_white.append(p.pelt.white)
par_white.append(parent.pelt.white)
else:
# If order for white patches to work correctly, we also want to randomly generate a "pelt_white"
# for each "None" parent (missing or unknown parent)
Expand Down Expand Up @@ -901,24 +899,17 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"):
# ------------------------------------------------------------------------------------------------------------#

# Determine pelt.
weights = [
0,
0,
0,
0,
] # Weights for each pelt group. It goes: (tabbies, spotted, plain, exotic)
for p_ in par_peltnames:
if p_ in Pelt.tabbies:
weights = [0, 0, 0, 0] # Weights for each pelt group. It goes: (tabbies, spotted, plain, exotic)
for _pelt in par_peltnames:
if _pelt in Pelt.tabbies:
add_weight = (50, 10, 5, 7)
elif p_ in Pelt.spotted:
elif _pelt in Pelt.spotted:
add_weight = (10, 50, 5, 5)
elif p_ in Pelt.plain:
elif _pelt in Pelt.plain:
add_weight = (5, 5, 50, 0)
elif p_ in Pelt.exotic:
elif _pelt in Pelt.exotic:
add_weight = (15, 15, 1, 45)
elif (
p_ is None
): # If there is at least one unknown parent, a None will be added to the set.
elif _pelt is None: # If there is at least one unknown parent, a None will be added to the set.
add_weight = (35, 20, 30, 15)
else:
add_weight = (0, 0, 0, 0)
Expand All @@ -940,8 +931,8 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"):
"base_female_tortie"
] # There is a default chance for female tortie
tortie_chance_m = game.config["cat_generation"]["base_male_tortie"]
for p_ in par_pelts:
if p_.name in Pelt.torties:
for _pelt in par_pelts:
if _pelt.name in Pelt.torties:
tortie_chance_f = int(tortie_chance_f / 2)
tortie_chance_m = tortie_chance_m - 1
break
Expand All @@ -966,16 +957,16 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"):
# ------------------------------------------------------------------------------------------------------------#
# Weights for each colour group. It goes: (ginger_colours, black_colours, white_colours, brown_colours)
weights = [0, 0, 0, 0]
for p_ in par_peltcolours:
if p_ in Pelt.ginger_colours:
for _pelt in par_peltcolours:
if _pelt in Pelt.ginger_colours:
add_weight = (40, 0, 0, 10)
elif p_ in Pelt.black_colours:
elif _pelt in Pelt.black_colours:
add_weight = (0, 40, 2, 5)
elif p_ in Pelt.white_colours:
elif _pelt in Pelt.white_colours:
add_weight = (0, 5, 40, 0)
elif p_ in Pelt.brown_colours:
elif _pelt in Pelt.brown_colours:
add_weight = (10, 5, 0, 35)
elif p_ is None:
elif _pelt is None:
add_weight = (40, 40, 40, 40)
else:
add_weight = (0, 0, 0, 0)
Expand All @@ -996,14 +987,14 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"):
# ------------------------------------------------------------------------------------------------------------#

weights = [0, 0, 0] # Weights for each length. It goes (short, medium, long)
for p_ in par_peltlength:
if p_ == "short":
for _pelt in par_peltlength:
if _pelt == "short":
add_weight = (50, 10, 2)
elif p_ == "medium":
elif _pelt == "medium":
add_weight = (25, 50, 25)
elif p_ == "long":
elif _pelt == "long":
add_weight = (2, 10, 50)
elif p_ is None:
elif _pelt is None:
add_weight = (10, 10, 10)
else:
add_weight = (0, 0, 0)
Expand All @@ -1026,8 +1017,8 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"):
# will keep that the same.
percentage_add_per_parent = int(94 / len(par_white))
chance = 3
for p_ in par_white:
if p_:
for _pelt in par_white:
if _pelt:
chance += percentage_add_per_parent

chosen_white = random.randint(1, 100) <= chance
Expand Down
10 changes: 3 additions & 7 deletions scripts/cat/personality.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import ujson

from scripts.utility import clamp


class Personality:
"""Hold personality information for a cat, and functions to deal with it"""
Expand Down Expand Up @@ -170,13 +172,7 @@ def stability(self, new_val):
@staticmethod
def adjust_to_range(val: int) -> int:
"""Take an integer and adjust it to be in the trait-range"""

if val < Personality.facet_range[0]:
val = Personality.facet_range[0]
elif val > Personality.facet_range[1]:
val = Personality.facet_range[1]

return val
return clamp(val, Personality.facet_range[0], Personality.facet_range[1])

def set_kit(self, kit: bool):
"""Switch the trait-type. True for kit, False for normal"""
Expand Down
Loading
Loading