From 9f94a372f0aabc2967efa38023086ca904f59c2d Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Fri, 5 Apr 2024 16:59:45 -0400 Subject: all: add reset breakables --- srb_lib.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'srb_lib.py') diff --git a/srb_lib.py b/srb_lib.py index be3683a..3cfa318 100644 --- a/srb_lib.py +++ b/srb_lib.py @@ -21,7 +21,6 @@ # # Improve: # Rewrite as a class so we do not have to pass data around everywhere? -# Write: set level breakables # Documentation: # winetricks vd=1024x768 # winetricks vd=off @@ -412,6 +411,27 @@ def get_collected_breakables(data_object,profile_id, level, silent=False): print(f"Debug: abs 0x{CHECKSUM_LENGTH+pos_level_which_breakables:04x} which breakables: b{profile_level_which_breakables:05b}") return ','.join(breakables_list), breakables_mask +def set_collected_breakables(data_object, profile_id, level, amount = "none"): + """ This resets the collected breakables for a level. Returns silently if given a level that does not have breakables. """ + data = _get_data_from_data_object(data_object) + level_obj, message = get_level_info(level) + if message != "" or level == -1: + return -1, f"Unable to set collected breakables for {level}." + levelset_obj, message = get_levelset_info(level_obj["setid"]) + if message != "" or levelset_obj == -1: + return -1, f"Unable to get levelset info for {level_obj['setid']}." + if not level_obj["r"]: + return data, "" + else: + thisint = 0 if amount == "none" else 5 + thismask = 0 if amount == "none" else [i["p"] for i in BREAKABLES if i["name"] == "all"][0] + pos_level_balloons = PROFILE_START_POSITION[profile_id]+POS_LEVEL_BALLOONS+(level_obj["setid"]*POS_LEVEL_BALLOONS_MULTIPLIER_LEVELSET)+(POS_LEVEL_BALLOONS_MULTIPLIER_LEVEL*level_obj["set_pos"]) + pos_level_breakables = pos_level_balloons + ((-2 * levelset_obj["id"]) + 12) * INT_SIZE + pos_level_which_breakables = pos_level_breakables + INT_SIZE + data = srb_pack("<1I",data,pos_level_breakables,thisint) + data = srb_pack("<1I",data,pos_level_which_breakables,thismask) + return data, "" + def set_level_status(data_object,profile_id,level,status,fix_levelset_completed_levels=True): """ Set completion rank for a level, e.g., general """ data = _get_data_from_data_object(data_object) -- cgit