Dev log - what's cooking today?

Currently Viewing (Users: 0, Guests: 1)

Status
Not open for further replies.

gsanders

Grandmaster Knight
Best answers
0
Today is a long dissection of Rigale crafting, as implemented at build v155 B5 of Phantasy 2018:

first, some scripts
Code:
  # script_cf_player_has_item_without_modifier
  # Input: arg1 = item_id, arg2 = modifier
  # Output: none (can_fail)
  ("cf_player_has_item_without_modifier",
    [
      (store_script_param, ":item_id", 1),
      (store_script_param, ":modifier", 2),
      (player_has_item, ":item_id"),
      #checking if any of the meat is not rotten
      (assign, ":has_without_modifier", 0),
      (troop_get_inventory_capacity, ":inv_size", "trp_player"),
      (try_for_range, ":i_slot", 10, ":inv_size"),  # GS was starting at 0 so counted worn items as well
        (troop_get_inventory_slot, ":cur_item", "trp_player", ":i_slot"),
        (eq, ":cur_item", ":item_id"),
        (troop_get_inventory_slot_modifier, ":cur_modifier", "trp_player", ":i_slot"),
        (neq, ":cur_modifier", ":modifier"),
        (assign, ":has_without_modifier", 1),
        (assign, ":inv_size", 10), #break
      (try_end),
      (eq, ":has_without_modifier", 1),
  ]),

  # script_player_has_item_get_modifier
  # Input: arg1 = item_id, arg2 = item_count
  # Output: reg3 = sum of imod values for this item
  ("player_has_item_get_modifier",
    [
    (store_script_param, ":item_id", 1),
    (store_script_param, ":item_count", 2),
    
    (assign, reg3, 0),
    (player_has_item, ":item_id"),     
    (assign, ":counted", 0),
    (assign, ":imod_sum", 0),

    (troop_get_inventory_capacity, ":inv_size", "trp_player"),
    ## GS first clean any rotten items
    (try_for_range, ":i_slot", 10, ":inv_size"),
        (troop_get_inventory_slot_modifier, ":cur_modifier", "trp_player", ":i_slot"),
        (eq, ":cur_modifier", imod_rotten),
        (troop_set_inventory_slot, "trp_player", ":i_slot", -1),
    (try_end),

    (try_for_range, ":i_slot", 10, ":inv_size"),    # GS start at 10 to skip items player is wearing
        (troop_get_inventory_slot, ":cur_item", "trp_player", ":i_slot"),
        (eq, ":cur_item", ":item_id"),
        (troop_get_inventory_slot_modifier, ":cur_modifier", "trp_player", ":i_slot"),

        (assign, ":imod_weighting", 0),
        (try_begin),
            (this_or_next|eq, ":cur_modifier", imod_plain),
            (this_or_next|eq, ":cur_modifier", imod_day_old),
            (this_or_next|eq, ":cur_modifier", imod_two_day_old), 
            (eq, ":cur_modifier", imod_fresh),

        (else_try),
            (this_or_next|eq, ":cur_modifier", imod_chipped),
            (this_or_next|eq, ":cur_modifier", imod_poor),
            (this_or_next|eq, ":cur_modifier", imod_cheap),
            (this_or_next|eq, ":cur_modifier", imod_old),
            (this_or_next|eq, ":cur_modifier", imod_stubborn),
            (this_or_next|eq, ":cur_modifier", imod_rough),
            (eq, ":cur_modifier", imod_crude),

            (assign, ":imod_weighting", -1),

        (else_try),
            (this_or_next|eq, ":cur_modifier", imod_bent),
            (this_or_next|eq, ":cur_modifier", imod_rusty),
            (this_or_next|eq, ":cur_modifier", imod_battered),
            (this_or_next|eq, ":cur_modifier", imod_ragged),
            (this_or_next|eq, ":cur_modifier", imod_tattered),
            (this_or_next|eq, ":cur_modifier", imod_swaybacked),
            (eq, ":cur_modifier", imod_smelling),

            (assign, ":imod_weighting", -2),

        (else_try),
            (this_or_next|eq, ":cur_modifier", imod_cracked),
            (eq, ":cur_modifier", imod_lame),

            (assign, ":imod_weighting", -3),

        (else_try),
            (this_or_next|eq, ":cur_modifier", imod_timid),
            (this_or_next|eq, ":cur_modifier", imod_meek),
            (this_or_next|eq, ":cur_modifier", imod_sturdy),
            (this_or_next|eq, ":cur_modifier", imod_thick),
            (this_or_next|eq, ":cur_modifier", imod_sharp),
            (eq, ":cur_modifier", imod_fine),

            (assign, ":imod_weighting", 1),
    
        (else_try),
            (this_or_next|eq, ":cur_modifier", imod_spirited),
            (this_or_next|eq, ":cur_modifier", imod_hardened),
            (this_or_next|eq, ":cur_modifier", imod_heavy),
            (this_or_next|eq, ":cur_modifier", imod_strong),
            (this_or_next|eq, ":cur_modifier", imod_powerful),
            (this_or_next|eq, ":cur_modifier", imod_deadly),
            (eq, ":cur_modifier", imod_well_made),

            (assign, ":imod_weighting", 2),

        (else_try),
            (this_or_next|eq, ":cur_modifier", imod_exquisite),
            (this_or_next|eq, ":cur_modifier", imod_reinforced),
            (this_or_next|eq, ":cur_modifier", imod_superb),
            (this_or_next|eq, ":cur_modifier", imod_tempered),
            (eq, ":cur_modifier", imod_balanced),

            (assign, ":imod_weighting", 3),

        (else_try),
            (this_or_next|eq, ":cur_modifier", imod_champion),
            (this_or_next|eq, ":cur_modifier", imod_masterwork),
            (eq, ":cur_modifier", imod_lordly),

            (assign, ":imod_weighting", 4),
        (try_end),

        (val_add, ":imod_sum", ":imod_weighting"),
        (val_add, ":counted", 1),
    
        (try_begin),
            (eq, ":counted", ":item_count"),
            (assign, ":inv_size", 10), #break
        (try_end),
    (try_end),

    (assign, reg3, ":imod_sum"),
  ]),


  # script_player_remove_crafting_items
  # Input: arg1 = item_id, arg2 = item_count
  # Output: reg3 = sum of imod values for this item
  ("player_remove_crafting_items",
    [
    (store_script_param, ":item_id", 1),
    (store_script_param, ":item_count", 2),

    (player_has_item, ":item_id"),     
    (assign, ":counted", 0),

    (troop_get_inventory_capacity, ":inv_size", "trp_player"),
    (try_for_range, ":i_slot", 10, ":inv_size"),
        (troop_get_inventory_slot, ":cur_item", "trp_player", ":i_slot"),
        (eq, ":cur_item", ":item_id"),
        (val_add, ":counted", 1),
        (troop_set_inventory_slot, "trp_player", ":i_slot", -1),    # GS item removed

        (try_begin),
            (eq, ":counted", ":item_count"),
            (assign, ":inv_size", 10), #break
        (try_end),
    (try_end),
  ]),

 ## OUTPUT: no change to regs; interprets result in global "$type_of_gathering_success"
 # script_rigale_check_crafting_success
("rigale_check_crafting_success",
 [
##	(store_script_param, ":recipe_type", 1),
	(store_script_param, ":difficulty", 2),  
        (store_script_param, ":imod_bonus", 3),

  	(try_begin),
		(is_between,"$level_of_gathering_skill",0,4),
		(assign,":modificateur",-4),
	(else_try),
		(is_between,"$level_of_gathering_skill",4,7),
		(assign,":modificateur",-2),
 	(else_try),
		(is_between,"$level_of_gathering_skill",7,11),
		(assign,":modificateur",0),
 	(else_try),
		(is_between,"$level_of_gathering_skill",11,14),
		(assign,":modificateur",2),
 	(else_try),
		(is_between,"$level_of_gathering_skill",14,18),
		(assign,":modificateur",3),
 	(else_try),
		(ge,"$level_of_gathering_skill",18),
		(assign,":modificateur",4),		
	(try_end),
 
      (assign, ":specific_recipe_knowledge", "$level_of_gathering_skill"),
      (val_div,":specific_recipe_knowledge",4), # GS was 7
      (store_random_in_range,":random_factor2",2,6), 
      (store_sub,":final_mod_specific_recipe_knowledge",":specific_recipe_knowledge",":random_factor2"), # modifier from -4 to whatever

      (store_random_in_range,":random_factor",1,11),
      (val_mul,":random_factor",2), #random 2-20
      (assign,":final_factor",":random_factor"),#random 2-20
      (val_add,":final_factor",":modificateur"), #add skill mod level
        
      (assign, ":final_difficulty", "$level_of_gathering_skill"),
      (val_sub,":final_difficulty",":difficulty"), # substract object difficulty
      (val_add,":final_factor",":final_difficulty"),
        
      (val_add,":final_factor",":final_mod_specific_recipe_knowledge"), #add (or substract) specific recipe knowledge
        ## GS bonus for using good materials here:
      (val_add,":final_factor",	":imod_bonus"),

	(try_begin),
		(this_or_next|eq,":random_factor",2),
		(le,":final_factor",3),
		(neq,":modificateur",4),#no critical failure for grand masters
		(assign, "$type_of_gathering_success", 4), (str_store_string, s2, "@Critical failure!!!"),
	(else_try),
		(is_between,":final_factor",4,11),
		(assign, "$type_of_gathering_success", 3), (str_store_string, s2, "@Failure!!!"),
 	(else_try),
		(is_between,":final_factor",11,18),
		(assign, "$type_of_gathering_success", 2), (str_store_string, s2, "@Success!!!"),
	(else_try),
 		(this_or_next|eq,":random_factor",20),
		(ge,":final_factor",18),
		(assign, "$type_of_gathering_success", 1), (str_store_string, s2, "@Critical success!!!"),
	(try_end),
 ]
 ),

##OUTPUT: no regs changed
("rigale_remove_some_tools",
 [
  (store_script_param_1, ":min_number_of_tools"),
  (store_script_param_2, ":max_number_of_tools"),

    #(troop_get_inventory_slot, ":item_id", "trp_player", 10),  # GS ok now we can have tools anywhere
    (troop_get_inventory_capacity, ":inv_size", "trp_player"),
    (assign,":slot_tools",-1),
  
    (try_for_range, ":i_slot", 10, ":inv_size"),
        (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
        (eq, ":item_id", "itm_tools"),
        (assign,":slot_tools",":i_slot"),   # GS first tools, what slot :)
        (assign,":inv_size",":i_slot"), # GS implicit Break
    (try_end),
  
    (try_begin),
        (eq, ":item_id", "itm_tools"),
        (store_random_in_range,":number_of_tools_to_remove",":min_number_of_tools",":max_number_of_tools"),
        (assign,reg32,":number_of_tools_to_remove"),
        (troop_inventory_slot_get_item_amount,":actual_amount","trp_player",":slot_tools"),
        (val_sub,":actual_amount",":number_of_tools_to_remove"),
        (try_begin),
            (lt,":actual_amount",1),
            (troop_remove_item,"trp_player",":item_id"),#(in this case, remove object 	
            (str_store_string,s23,"@You used all your remaining stack of tools."),
        (else_try),
            (ge,":actual_amount",1),
            (troop_inventory_slot_set_item_amount,"trp_player",":slot_tools",":actual_amount"),
            (str_store_string,s23,"@You lost {reg32} tools while gathering."),
        (try_end),	
    (try_end),
 ]
 ),


## OUTPUT reg1 
("rigale_check_number_of_components_available",
 [
  (store_script_param, ":type_of_components",1),
	
  (assign,":number_of_current_components",0),
  (troop_get_inventory_capacity, ":inv_size", "trp_player"),
  (try_begin),
      (try_for_range, ":i_slot", 10, ":inv_size"),  # GS skip equipped/worn items when looking
          (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
          (eq, ":item_id", ":type_of_components"),	
          (neg|call_script, "script_cf_player_has_item_without_modifier", ":item_id", imod_rotten),
          (val_add,":number_of_current_components",1),
      (try_end),
  (try_end),  # GS added a missing try_end here
  (assign,reg1,":number_of_current_components"),
  (set_trigger_result, reg1)
 ]
 ),

 ## OUTPUT sets "$g_b_enough_components_available"
("rigale_check_enough_components_available", #utilisation lumberjacking et mining camps
 [
  (store_script_param, ":type_of_components",1),
  (store_script_param, ":number_of_required_components",2),

  (assign,":number_of_current_components",0),
  (troop_get_inventory_capacity, ":inv_size", "trp_player"),
  (try_begin),
      (try_for_range, ":i_slot", 10, ":inv_size"),
          (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
	  (eq, ":item_id", ":type_of_components"),
	  (val_add,":number_of_current_components",1),
      (try_end),

      (try_begin),
          (ge,":number_of_current_components",":number_of_required_components"),
          (assign, "$g_b_enough_components_available", 1), #instead of reg2
          (set_trigger_result, "$g_b_enough_components_available"),
      (else_try),
          (lt,":number_of_current_components",":number_of_required_components"),
          (assign, "$g_b_enough_components_available", 0),	
          (set_trigger_result, "$g_b_enough_components_available"),
      (try_end),
  (try_end),    # GS added a missing try_end here
 ]
 ),

## OUTPUT sets  "$g_b_enough_complete_tools_available"
("rigale_check_enough_complete_tools_available",
 [
  (store_script_param, ":number_of_complete_tools",1),
	
  (assign,":number_of_current_components",0),
  (troop_get_inventory_capacity, ":inv_size", "trp_player"),
  (try_begin),
      (try_for_range, ":i_slot", 10, ":inv_size"),
          (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
          (eq, ":item_id", "itm_tools"),
	  (try_begin),
              (troop_inventory_slot_get_item_amount,":tools_amount","trp_player",":i_slot"),
	      (eq,":tools_amount",50),
	      (val_add,":number_of_current_components",1),
	  (try_end),
      (try_end),

      (try_begin),
          (ge,":number_of_current_components",":number_of_complete_tools"),
          (assign, "$g_b_enough_complete_tools_available", 1),	

          (set_trigger_result, "$g_b_enough_complete_tools_available"),
      (else_try),
          (lt,":number_of_current_components",":number_of_complete_tools"),
          (assign, "$g_b_enough_complete_tools_available", 0),	
          (set_trigger_result, "$g_b_enough_complete_tools_available"),
      (try_end),
  (try_end),    # GS added a try_end here
 ]
 ),

## OUTPUT no regs harmed
("rigale_check_crafting_possible_and_start_crafting",
 [
  (store_script_param, ":slot_specific_recipe",1),	
  (store_script_param, ":object_difficulty",2),
  (store_script_param, ":type_of_component_1",3),
  (store_script_param, ":amount_of_required_component_1",4),
  (store_script_param, ":type_of_component_2",5),
  (store_script_param, ":amount_of_required_component_2",6),
  (store_script_param, ":type_of_component_3",7),
  (store_script_param, ":amount_of_required_component_3",8),
  (store_script_param, ":type_of_component_4",9),
  (store_script_param, ":amount_of_required_component_4",10),	
  (store_script_param, ":type_of_component_5",11),
  (store_script_param, ":amount_of_required_component_5",12),	
	
  (store_script_param, ":basic_hours_required",13),
  (store_script_param, ":particular_type_of_crafted_object",14),
  (store_script_param, ":general_type_of_crafted_object",15),

  #(assign,":component_types_number",0),
	
  (assign,":number_of_current_components_1",0),
  (assign,":number_of_current_components_2",0),
  (assign,":number_of_current_components_3",0),
  (assign,":number_of_current_components_4",0),
  (assign,":number_of_current_components_5",0),
	
  (troop_get_inventory_capacity, ":inv_size", "trp_player"),

    (try_for_range, ":i_slot_1", 10, ":inv_size"),  # GS need to skip worn/equipped items
        (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot_1"),
        (try_begin),
            (eq, ":item_id", ":type_of_component_1"),	
            (neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_1", imod_rotten),
            (val_add,":number_of_current_components_1",1),		
        (try_end),
  
        (try_begin),
            (eq, ":item_id", ":type_of_component_2"),	
            (neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_2", imod_rotten),
            (val_add,":number_of_current_components_2",1),		
        (try_end),			
			
        (try_begin),
            (eq, ":item_id", ":type_of_component_3"),	
            (neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_3", imod_rotten),
            (val_add,":number_of_current_components_3",1),		
        (try_end),			

        (try_begin),
	  (eq, ":item_id", ":type_of_component_4"),	
	  (neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_4", imod_rotten),
	  (val_add,":number_of_current_components_4",1),		
        (try_end),			

        (try_begin),
	  (eq, ":item_id", ":type_of_component_5"),	
	  (neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_5", imod_rotten),
	  (val_add,":number_of_current_components_5",1),		
        (try_end),	
    (try_end),

    (try_begin),
        (assign, ":can_craft", 1),  # GS initially assume we CAN craft and then flip it to another value if we find an issue
        (gt,":amount_of_required_component_1", 0),
        (try_begin),
            (lt,":number_of_current_components_1",":amount_of_required_component_1"),
            (assign,":can_craft",2),
        (try_end),

        (try_begin),
            (gt,":amount_of_required_component_2", 0),
            (try_begin),
                (lt,":number_of_current_components_2",":amount_of_required_component_2"),
                (assign,":can_craft",2),
            (try_end),
	  # (else_try),
	  # (eq,":amount_of_required_component_2",0),	
	  # (try_begin),
		# (eq,":number_of_current_components_2",0),
		# (assign,":can_craft",1),
	  # (try_end),
        (try_end),

        (try_begin),
            (gt,":amount_of_required_component_3", 0),
            (try_begin),
                (lt,":number_of_current_components_3",":amount_of_required_component_3"),
                (assign,":can_craft",2),
            (try_end),
    # (else_try),
        # (eq,":amount_of_required_component_3",0),	
        # (try_begin),
              # (eq,":number_of_current_components_3",0),
	      # (assign,":can_craft",1),
	# (try_end),
        (try_end),		

        (try_begin),
            (gt,":amount_of_required_component_4", 0),
            (try_begin),
                (lt,":number_of_current_components_4",":amount_of_required_component_4"),
                (assign,":can_craft",2),
            (try_end),
    # (else_try),
	# (eq,":amount_of_required_component_4",0),	
	# (try_begin),
            # (eq,":number_of_current_components_4",0),
	    # (assign,":can_craft",1),
	# (try_end),
        (try_end),		

        (try_begin),
            (gt,":amount_of_required_component_5", 0),
            (try_begin),
                (lt,":number_of_current_components_5",":amount_of_required_component_5"),
                (assign,":can_craft",2),
            (try_end),
	# (else_try),
            # (eq,":amount_of_required_component_5",0),	
	    # (try_begin),
                # (eq,":number_of_current_components_5",0),
		# (assign,":can_craft",1),
	    # (try_end),
        (try_end),		
	
       (try_begin),    # GS technically this was already done before this got called, so commented out for test! (for now)
         #   (neg|troop_slot_ge,"trp_player", ":slot_specific_recipe:",20),     # GS not sure what this was supposed to do, but
            (lt, "$level_of_gathering_skill", ":object_difficulty"),    # GS this works for now
                                                                        # GS eventually needs to look at ":slot_specific_recipe" to determine crafting type
                                                                        # GS then determine skill in that category...
            (assign,":can_craft",2),
        (try_end),
       
        (assign, ":savereg3", reg3),
        (try_begin),
            (call_script, "script_time_avail"),
            (eq, reg3, 0),
            (assign, ":can_craft", 0),      # GS only if already busy change the values built so far...
        (try_end),
        (assign, reg3, ":savereg3"),
  
        (try_begin),
            (eq,":can_craft",1),

            ## GS gather pluses and minuses as a parameter to pass to "script_rigale_check_crafting_success"
            (troop_get_inventory_capacity, ":inv_size", "trp_player"),

            (assign, ":savereg3", reg3),
            (assign, ":imod1", 0),  
            (assign, ":imod2", 0),  
            (assign, ":imod3", 0),  

            (assign, ":imod_weighting", 0),
            (call_script, "script_player_has_item_get_modifier", ":type_of_component_1", ":amount_of_required_component_1"),
            (assign, ":imod1", reg3),  
            (val_add,  ":imod_weighting", ":imod1"),

            (try_begin),
                (gt, ":amount_of_required_component_2", 0),	
                (call_script, "script_player_has_item_get_modifier", ":type_of_component_2", ":amount_of_required_component_2"),
                (assign, ":imod2", reg3),  
                (val_div, ":imod2", 2),
                (val_add,  ":imod_weighting", ":imod2"),
            (try_end),			
			
            (try_begin),
                (gt, ":amount_of_required_component_3", 0),	
                (call_script, "script_player_has_item_get_modifier", ":type_of_component_3", ":amount_of_required_component_3"),
                (assign, ":imod2", reg3),  
                (val_div, ":imod3", 3),
                (val_add,  ":imod_weighting", ":imod3"),
            (try_end),			
            (assign, reg3, ":savereg3"),

###             # GS we can skip components 4 and 5 for checking imods
##                (try_begin),
##                  (eq, ":item_id", ":type_of_component_4"),	
##                  (neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_4", imod_rotten),
##                  (val_add,":number_of_current_components_4",1),		
##                (try_end),			

##                (try_begin),
##                  (eq, ":item_id", ":type_of_component_5"),	
##                  (neg|call_script, "script_cf_player_has_item_without_modifier", ":type_of_component_5", imod_rotten),
##                  (val_add,":number_of_current_components_5",1),		
##                (try_end),	
  
	  # (this_or_next|ge,":number_of_current_components_1",":amount_of_required_component_1"),	
	  # (this_or_next|ge,":number_of_current_components_2",":amount_of_required_component_2"),
	  # (this_or_next|ge,":number_of_current_components_3",":amount_of_required_component_3"),
	  # (this_or_next|ge,":number_of_current_components_4",":amount_of_required_component_4"),	
	  # (ge,":number_of_current_components_5",":amount_of_required_component_5"),			
	  # (store_skill_level, "$level_of_gathering_skill", ":skl_used", "trp_player"),	#deja dans le menu basique d'arrivee chez le smith   
            (call_script,"script_rigale_check_crafting_success",":slot_specific_recipe",":object_difficulty", ":imod_weighting"),  # GS newly added imod bonus 10 May 2018

            (assign,"$crafting_basic_hours_required",":basic_hours_required"),
          #   (assign,"$crafting_basic_hours_required",2),       # GS only for test!
            (assign,"$crafted_item",":particular_type_of_crafted_object"),
            (assign,"$crafted_object_type",":general_type_of_crafted_object"),

            (try_begin),
                (ge,":amount_of_required_component_1", 1),
                (call_script, "script_player_remove_crafting_items", ":type_of_component_1", ":amount_of_required_component_1"), 
            (try_end),
            (try_begin),
                (ge,":amount_of_required_component_2",1),
                (call_script, "script_player_remove_crafting_items", ":type_of_component_2", ":amount_of_required_component_2"), 
            (try_end),	
            (try_begin),
                (ge,":amount_of_required_component_3",1),
                (call_script, "script_player_remove_crafting_items", ":type_of_component_3", ":amount_of_required_component_3"),
            (try_end),
            (try_begin),
                (ge,":amount_of_required_component_4",1),
                (call_script, "script_player_remove_crafting_items", ":type_of_component_4", ":amount_of_required_component_4"),
            (try_end),			
            (try_begin),
                (ge,":amount_of_required_component_5",1),
                (call_script, "script_player_remove_crafting_items", ":type_of_component_5", ":amount_of_required_component_5"),
            (try_end),

            (call_script, "script_set_time_busy", ":basic_hours_required"),
            (assign, "$auto_enter_town", -1),
       #     (assign, "$g_town_visit_after_rest", 1),
            (rest_for_hours,":basic_hours_required","$g_phantasy_wait_multiplier",0),	# GS this needs changing to use locks scheme		
     #       (change_screen_return),
			(change_screen_map), #WR possible bug fix
  
        (else_try),
            (ge,":can_craft",2),
            (jump_to_menu,"mnu_crafting_no_component"),
        (else_try),
            (le, ":can_craft", 0),
            (call_script, "script_time_aggregate", 1),  # GS mention how many hours they should wait based on largest time flag set
        (try_end),
  (try_end),    # GS added missing try_end here
 ]
 ),
 

gsanders

Grandmaster Knight
Best answers
0
now some menus
Code:
### Rigale Crafting
 # GS mnu_crafting_result   searchable text
    (
    "crafting_result",0,
    "{s31}",
    "none",
    [
    (try_begin),
	(ge,"$level_of_gathering_skill",20),
	(assign,":craft_mastery_bonus","$level_of_gathering_skill"),
        (store_random_in_range, ":mastery_offset", 12,18),       # GS too many "lordly" things made from even slight skill > 20
        (val_sub, ":craft_mastery_bonus", ":mastery_offset"), 
    (try_end),
			
    (try_begin),
	(eq,"$type_of_gathering_success",1),
	(call_script,"script_rigale_remove_some_tools",2,5),
	(store_random_in_range,":critical_bonus",15,26),
	(assign,":crafting_success_modification",":critical_bonus"),
	(str_store_string,s16,"@ "),
	#(str_store_string,s17,"@ "),			
	(call_script,"script_rigale_raise_custom_skill", "$type_of_gathering_skill_used", 1,0,0,0,0),			
			
    (else_try),	
	(eq,"$type_of_gathering_success",2),(assign,":crafting_success_modification",10),
	(call_script,"script_rigale_raise_custom_skill", "$type_of_gathering_skill_used", 1,0,0,0,0),			
	(str_store_string,s16,"@ "),
	#(str_store_string,s17,"@ "),
	(call_script,"script_rigale_remove_some_tools",4,8),			
			
    (else_try),	
	(eq,"$type_of_gathering_success",3),(assign,":crafting_success_modification",-5),			
	(call_script,"script_rigale_learn_from_failure", 20, 35),
	(call_script,"script_rigale_raise_custom_skill", "$type_of_gathering_skill_used", 0,1,0,0,0),
	#(call_script,"script_rigale_raise_custom_skill", "$type_of_gathering_skill_used", -5),
	(call_script,"script_rigale_remove_some_tools",5,9),
	(str_store_string, s31, "@Your crafting attempt is a FAILURE. ^This failure teaches you a lesson (granting {reg7} XP.).^{s23} ^{s16} ^{s17}"),			

    (else_try),
	(eq,"$type_of_gathering_success",4),(assign,":crafting_success_modification",-15),

	(call_script,"script_rigale_remove_some_tools",6,10),

	(store_random_in_range, reg7, 15, 35),
	(add_xp_to_troop, reg7, "trp_player"),			
	(call_script,"script_rigale_learn_from_failure", 30, 50),
	(call_script,"script_rigale_raise_custom_skill", "$type_of_gathering_skill_used", 0,0,1,0,0),
	#(call_script,"script_rigale_raise_custom_skill", "$type_of_gathering_skill_used", 5),

	(store_random_in_range,":player_health_from_critical_failure",30,45),
	(troop_set_health,"trp_player",":player_health_from_critical_failure"),

	(str_store_string, s31, "@Your crafting attempt is a CRITICAL FAILURE. ^This critical failure teaches you a HARSH life lesson (granting {reg7} XP.). ^ Moreover, you hurt yourself pretty badly. ^{s23} ^{s16} ^{s17}"),			
    (try_end),
			
    (assign,":object_quality_final_check",0),
    (store_random_in_range,":random_object_check",1,11),
    (val_mul,":random_object_check",2), #2d10

    (val_add,":object_quality_final_check",":random_object_check"), #+facteur aleatoire
    (val_add,":object_quality_final_check","$level_of_gathering_skill"), # + niveau en craft
    (val_add,":object_quality_final_check",":craft_mastery_bonus"), # + bonus de maitrise
    (val_add,":object_quality_final_check",":crafting_success_modification"), # + niveau de reussite

    (try_begin),
        (eq,"$crafted_object_type",1),# tools
	(try_begin),
	    (le,":object_quality_final_check",15),
	    (assign,":item_final_modifier",imod_tattered),(str_store_string,s28,"@tattered"),
	    (store_random_in_range,":number_of_crafted_items",10,20),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
	(else_try),
	    (is_between,":object_quality_final_check",16,30),
	    (assign,":item_final_modifier",imod_battered),(str_store_string,s28,"@battered"),			
	    (store_random_in_range,":number_of_crafted_items",10,20),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
	(else_try),
	    (is_between,":object_quality_final_check",30,45),
	    (assign,":item_final_modifier",imod_plain),	(str_store_string,s28,"@plain"),			
	    (store_random_in_range,":number_of_crafted_items",10,20),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
	(else_try),
	    (is_between,":object_quality_final_check",45,60),
	    (assign,":item_final_modifier",imod_fine),	(str_store_string,s28,"@fine"),		
	    (store_random_in_range,":number_of_crafted_items",10,20),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
	(else_try),
	    (ge,":object_quality_final_check",60),
	    (assign,":item_final_modifier",imod_balanced),(str_store_string,s28,"@balanced"),			
	    (store_random_in_range,":number_of_crafted_items",10,20),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
	(try_end),

	(str_store_item_name,s29,"$crafted_item"),
	(try_begin),
	    (is_between,"$type_of_gathering_success",1,4),
	    (call_script,"script_rigale_add_random_item_amount_and_quality","$crafted_item",":number_of_crafted_items",":item_final_modifier"),
	    (str_store_string,s31,"@ You crafted a/an {s28} {s29} ^^{s16} {s17}"),		
	(try_end),				
				
    (else_try),
        (eq,"$crafted_object_type",2), #armor
	(try_begin),
	    (le,":object_quality_final_check",15),
	    (assign,":item_final_modifier",imod_cracked),(str_store_string,s28,"@cracked"),(assign,":number_of_crafted_items",1),
	(else_try),
	    (is_between,":object_quality_final_check",16,20),
	    (assign,":item_final_modifier",imod_rusty),	(str_store_string,s28,"@rusty"),(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",20,24),
	    (assign,":item_final_modifier",imod_ragged),(str_store_string,s28,"@ragged"),(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",24,28),
	    (assign,":item_final_modifier",imod_battered),(str_store_string,s28,"@battered"),(assign,":number_of_crafted_items",1),			
	(else_try),
	    (is_between,":object_quality_final_check",28,32),
	    (assign,":item_final_modifier",imod_crude),(str_store_string,s28,"@crude"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",32,36),
            (assign,":item_final_modifier",imod_plain),(str_store_string,s28,"@plain"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",36,40),
	    (assign,":item_final_modifier",imod_sturdy),(str_store_string,s28,"@sturdy"),(assign,":number_of_crafted_items",1),			
	(else_try),
	    (is_between,":object_quality_final_check",40,44),
	    (assign,":item_final_modifier",imod_heavy),(str_store_string,s28,"@heavy"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",44,48),
	    (assign,":item_final_modifier",imod_thick),(str_store_string,s28,"@thick"),	(assign,":number_of_crafted_items",1),		
	(else_try),
            (is_between,":object_quality_final_check",48,52),
	    (assign,":item_final_modifier",imod_hardened),(str_store_string,s28,"@hardened"),(assign,":number_of_crafted_items",1),			
	(else_try),
	    (is_between,":object_quality_final_check",52,56),
	    (assign,":item_final_modifier",imod_strong),	(str_store_string,s28,"@strong"),	(assign,":number_of_crafted_items",1),	
	(else_try),
	    (is_between,":object_quality_final_check",56,58),
	    (assign,":item_final_modifier",imod_lordly),	(str_store_string,s28,"@lordly"),	(assign,":number_of_crafted_items",1),	
	(else_try),
	    (ge,":object_quality_final_check",60),
	    (assign,":item_final_modifier",imod_reinforced),(str_store_string,s28,"@reinforced"),	(assign,":number_of_crafted_items",1),		
	(try_end),		

	(str_store_item_name,s29,"$crafted_item"),
	(try_begin),
	    (is_between,"$type_of_gathering_success",1,4),
	    (call_script,"script_rigale_add_random_item_amount_and_quality","$crafted_item",":number_of_crafted_items",":item_final_modifier"),
	    (str_store_string,s31,"@ You crafted a/an {s28} {s29} ^^{s16} {s17}"),		
	(try_end),

    (else_try),
	(eq,"$crafted_object_type",3), #weapon
	(try_begin),
	    (le,":object_quality_final_check",15),
	    (assign,":item_final_modifier",imod_cracked),(str_store_string,s28,"@cracked"),(assign,":number_of_crafted_items",1),
	(else_try),
	    (is_between,":object_quality_final_check",16,20),
	    (assign,":item_final_modifier",imod_rusty),(str_store_string,s28,"@rusty"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",20,24),
	    (assign,":item_final_modifier",imod_rough),(str_store_string,s28,"@rough"),	(assign,":number_of_crafted_items",1),			
	(else_try),
	    (is_between,":object_quality_final_check",24,28),
	    (assign,":item_final_modifier",imod_bent),(str_store_string,s28,"@bent"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",28,32),
	    (assign,":item_final_modifier",imod_chipped),(str_store_string,s28,"@chipped"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",32,36),
	    (assign,":item_final_modifier",imod_crude),(str_store_string,s28,"@crude"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",36,40),
	    (assign,":item_final_modifier",imod_plain),(str_store_string,s28,"@plain"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",40,44),
	    (assign,":item_final_modifier",imod_fine),(str_store_string,s28,"@fine"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",44,48),
	    (assign,":item_final_modifier",imod_balanced),(str_store_string,s28,"@balanced"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",48,52),
	    (assign,":item_final_modifier",imod_strong),	(str_store_string,s28,"@strong"),	(assign,":number_of_crafted_items",1),	
	 (else_try),
	    (is_between,":object_quality_final_check",52,54),
	    (assign,":item_final_modifier",imod_masterwork),(str_store_string,s28,"@masterwork"),	(assign,":number_of_crafted_items",1),		
	(else_try),
	    (ge,":object_quality_final_check",54),
	    (assign,":item_final_modifier",imod_tempered),(str_store_string,s28,"@tempered"),	(assign,":number_of_crafted_items",1),		
	(try_end),	

	(str_store_item_name,s29,"$crafted_item"),
	(try_begin),
	    (is_between,"$type_of_gathering_success",1,4),
	    (call_script,"script_rigale_add_random_item_amount_and_quality","$crafted_item",":number_of_crafted_items",":item_final_modifier"),
	    (str_store_string,s31,"@ You crafted a/an {s28} {s29} ^^{s16} {s17}"),		
	(try_end),			
				
    (else_try),
	(eq,"$crafted_object_type",5),# food
	(try_begin),
	    (le,":object_quality_final_check",15),
	    (store_random_in_range,":number_of_crafted_items",15,25),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
#	    (store_random_in_range,"$cooked_food_quality",1,3),
				
	(else_try),
	    (is_between,":object_quality_final_check",16,35),
	    (store_random_in_range,":number_of_crafted_items",20,30),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
#	    (store_random_in_range,"$cooked_food_quality",2,5),

	(else_try),
	    (is_between,":object_quality_final_check",30,45),
	    (store_random_in_range,":number_of_crafted_items",25,35),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
#	    (store_random_in_range,"$cooked_food_quality",4,8),				

	(else_try),
	    (is_between,":object_quality_final_check",45,60),
	    (store_random_in_range,":number_of_crafted_items",30,40),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
#	    (store_random_in_range,"$cooked_food_quality",6,11),					
				
	(else_try),
	    (ge,":object_quality_final_check",60),
            (store_random_in_range,":number_of_crafted_items",40,50),(val_add,":number_of_crafted_items","$level_of_gathering_skill"),
#	    (store_random_in_range,"$cooked_food_quality",9,13),
	(try_end),

       (str_store_item_name,s29,"$crafted_item"),				
	(try_begin),
	    (eq,"$type_of_gathering_success",1),
	    (call_script,"script_rigale_add_cooked_item",":number_of_crafted_items"),
	    (str_store_string,s31,"@ Critical success. ^You cooked a/an {s29} ^^{s16} {s17}"),		
	(else_try),				
	    (eq,"$type_of_gathering_success",2),
	    (call_script,"script_rigale_add_cooked_item",":number_of_crafted_items"),
	    (str_store_string,s31,"@ Success. You cooked a/an {s29} ^^{s16} {s17}"),		
	(else_try),				
	    (eq,"$type_of_gathering_success",3),
	    (call_script,"script_rigale_add_cooked_item",":number_of_crafted_items"),
	    (str_store_string,s31,"@ Failure. ^You barely cooked a/an {s29} ^^{s16} {s17}"),		
	(else_try),				
	    (eq,"$type_of_gathering_success",4),
	    (str_store_string,s31,"@ Critical failure. ^You cook nothing, and burn all the components. ^^{s16} {s17}"),		
	(try_end),
		
    (else_try),
	(eq,"$crafted_object_type",4), #ammunitions
	(try_begin),
	    (le,":object_quality_final_check",15),
	    (assign,":item_final_modifier",imod_cracked), (str_store_string,s28,"@cracked"),
	(else_try),
	    (is_between,":object_quality_final_check",16,20),
	    (assign,":item_final_modifier",imod_rusty), (str_store_string,s28,"@rusty"),	
	(else_try),
	    (is_between,":object_quality_final_check",20,24),
	    (assign,":item_final_modifier",imod_rough), (str_store_string,s28,"@rough"),
	(else_try),
            (is_between,":object_quality_final_check",24,28),
	    (assign,":item_final_modifier",imod_bent), (str_store_string,s28,"@bent"),
	(else_try),
	    (is_between,":object_quality_final_check",28,32),
	    (assign,":item_final_modifier",imod_chipped),(str_store_string,s28,"@chipped"),	
	(else_try),
	    (is_between,":object_quality_final_check",32,36),
	    (assign,":item_final_modifier",imod_crude),(str_store_string,s28,"@crude"),
	(else_try),
	    (is_between,":object_quality_final_check",36,40),
	    (assign,":item_final_modifier",imod_plain),	(str_store_string,s28,"@plain"),
	(else_try),
	    (is_between,":object_quality_final_check",40,44),
	    (assign,":item_final_modifier",imod_fine), (str_store_string,s28,"@fine"),	
	(else_try),
	    (is_between,":object_quality_final_check",44,48),
	    (assign,":item_final_modifier",imod_balanced), (str_store_string,s28,"@balanced"),	
	(else_try),
	    (is_between,":object_quality_final_check",48,52),
	    (assign,":item_final_modifier",imod_strong), (str_store_string,s28,"@strong"),
	(else_try),
	    (is_between,":object_quality_final_check",52,57),
	    (assign,":item_final_modifier",imod_tempered), (str_store_string,s28,"@tempered"),	
	(else_try),
	    (ge,":object_quality_final_check",57),
	    (assign,":item_final_modifier",imod_masterwork), (str_store_string,s28,"@masterwork"),		
    	(try_end),	

	(str_store_item_name,s29,"$crafted_item"),
        (str_store_string,s31,"@ You crafted a/an {s28} {s29} ^^{s16} {s17}"),
    
        (try_begin),
	    (is_between,"$type_of_gathering_success",1,4),
                (assign, ":cap", 96), #inventory cap

                (try_for_range, ":i_slot", 10, ":cap"),  
                    (troop_get_inventory_slot, ":item", "trp_player", ":i_slot"),  
                    (eq, ":item", -1), #empty  
                    (troop_set_inventory_slot, "trp_player", ":i_slot", "$crafted_item"),  
                    (troop_set_inventory_slot_modifier, "trp_player", ":i_slot", ":item_final_modifier"),
                    (assign, ":cap", 10), #break loop
                (try_end),
               
        (else_try),
	    (eq,"$type_of_gathering_success",4),
	    (str_store_string,s31,"@ Critical Failure. ^^{s16} {s17}"),	    # GS instead you get nothing if you reach here.	
        (try_end),

    (else_try),
	(eq,"$crafted_object_type",6), #other objects
        (assign, ":crafted_imod", 0),   # imod_plain
	(try_begin),
	    (eq,"$crafted_item","itm_leatherwork"),(assign,":crafted_item_2","itm_bits_of_leather"), 
	(else_try),
	    (eq,"$crafted_item","itm_furs"),(assign,":crafted_item_2","itm_bits_of_leather"),
	(else_try),
	    (eq,"$crafted_item","itm_raw_leather"),(assign,":crafted_item_2","itm_wasted_leather"),						
	(else_try),
            (assign, ":crafted_item_2","itm_grain"), # GS except try hard to not give away free grain!
        (try_end),
    
	(try_begin),
            (le,":object_quality_final_check",15),
	    (assign,":num_main_crafted_items",0),(assign,":num_secondary_crafted_items",1),
	(else_try),
	    (is_between,":object_quality_final_check",16,30),
	    (store_random_in_range,":number_items",1,3),
	    (assign,":num_main_crafted_items",0),(assign,":num_secondary_crafted_items",":number_items"),		
        (else_try),
	    (is_between,":object_quality_final_check",30,45),
	    (assign,":num_main_crafted_items",1),(assign,":num_secondary_crafted_items",0),		
	(else_try),
	    (is_between,":object_quality_final_check",45,60),
	    (assign,":num_main_crafted_items",1),(assign,":num_secondary_crafted_items",1),				
            (assign, ":crafted_imod", imod_sturdy),
	(else_try),
	    (is_between,":object_quality_final_check",60,75),
	    (store_random_in_range,":number_items",1,3),
            (assign, ":crafted_imod", imod_sturdy),
	    (assign,":num_main_crafted_items",1),(assign,":num_secondary_crafted_items",":number_items"),		
            (assign, ":crafted_imod", imod_thick),
	(else_try),
	    (ge,":object_quality_final_check",75),
	    (assign,":num_main_crafted_items",2),(assign,":num_secondary_crafted_items",0),
            (assign, ":crafted_imod", imod_hardened),
	(try_end),	
	
	(str_store_item_name,s29,"$crafted_item"),
	(str_store_item_name,s30,":crafted_item_2"),
    
	(assign,reg25,":num_main_crafted_items"),
	(assign,reg26,":num_secondary_crafted_items"),
        (try_begin),
            (eq, ":crafted_item_2", "itm_grain"),
            (assign, ":num_secondary_crafted_items", 0), # GS zero out secondary items
            (troop_add_items,"trp_player","$crafted_item",":num_main_crafted_items"),
    
            (str_store_string,s31,"@ You crafted {reg25} {s29}  ^^{s16} {s17}"),
    
        (else_try),
	  ##  (troop_add_items,"trp_player","$crafted_item",":num_main_crafted_items"),     # GS can't set imod value by this call
            (assign, ":itmcount", 0),
            (troop_get_inventory_capacity, ":inv_size", "trp_player"),
            (try_for_range, ":i_slot", 10, ":inv_size"),
                (troop_get_inventory_slot, ":item", "trp_player", ":i_slot"),  
                (eq, ":item", -1), #empty  
                (troop_set_inventory_slot, "trp_player", ":i_slot", "$crafted_item"),  
                (troop_set_inventory_slot_modifier, "trp_player", ":i_slot", ":crafted_imod"),
                (val_add, ":itmcount", 1),
                (eq, ":itmcount", ":num_main_crafted_items"),
                (assign, ":inv_size", 10), #break loop
            (try_end),

	    (troop_add_items,"trp_player",":crafted_item_2",":num_secondary_crafted_items"),

	    (str_store_string,s31,"@ You crafted {reg25} {s29} and {reg26} {s30} ^^{s16} {s17}"),		
	(try_end),		
	
    (else_try),
	(eq,"$crafted_object_type",7), #shields
	(try_begin),
	    (le,":object_quality_final_check",15),
	    (assign,":item_final_modifier",imod_cracked),(str_store_string,s28,"@cracked"),(assign,":number_of_crafted_items",1),
	(else_try),
	    (is_between,":object_quality_final_check",16,30),
	    (assign,":item_final_modifier",imod_battered),(str_store_string,s28,"@battered"),(assign,":number_of_crafted_items",1),			
	(else_try),
	    (is_between,":object_quality_final_check",30,45),
	    (assign,":item_final_modifier",imod_plain),(str_store_string,s28,"@normal"),(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",45,60),
	    (assign,":item_final_modifier",imod_thick),(str_store_string,s28,"@thick"),(assign,":number_of_crafted_items",1),			
	(else_try),
	    (ge,":object_quality_final_check",60),
	    (assign,":item_final_modifier",imod_reinforced),(str_store_string,s28,"@reinforced"),   (assign,":number_of_crafted_items",1),		
	(try_end),		

	(str_store_item_name,s29,"$crafted_item"),
	(try_begin),
	    (is_between,"$type_of_gathering_success",1,4),
	    (call_script,"script_rigale_add_random_item_amount_and_quality","$crafted_item",":number_of_crafted_items",":item_final_modifier"),
	    (str_store_string,s31,"@ You crafted a {s28} {s29} ^^{s16} {s17}"),		
	(try_end),			

    (else_try),
	(eq,"$crafted_object_type",8), #GS Mounts  (from leather / chain / plate barding)
        (assign, ":crafted_imod", 0),   # imod_plain

	(try_begin),
	    (le,":object_quality_final_check",15),
	    (assign,":item_final_modifier",imod_swaybacked),(str_store_string,s28,"@swaybacked"),(assign,":number_of_crafted_items",1),
	(else_try),
	    (is_between,":object_quality_final_check",16,30),
	    (assign,":item_final_modifier",imod_lame),(str_store_string,s28,"@lame"),(assign,":number_of_crafted_items",1),			
	(else_try),
	    (is_between,":object_quality_final_check",30,45),
	    (assign,":item_final_modifier",imod_plain),(str_store_string,s28,"@normal"),(assign,":number_of_crafted_items",1),		
	(else_try),
	    (is_between,":object_quality_final_check",45,60),
	    (assign,":item_final_modifier",imod_heavy),(str_store_string,s28,"@heavy"),(assign,":number_of_crafted_items",1),			
	(else_try),
	    (ge,":object_quality_final_check",60),
	    (assign,":item_final_modifier",imod_spirited),(str_store_string,s28,"@spirited"),(assign,":number_of_crafted_items",1),		
	(try_end),		

	(str_store_item_name,s29,"$crafted_item"),
	(try_begin),
	    (is_between,"$type_of_gathering_success",1,4),
	    (call_script,"script_rigale_add_random_item_amount_and_quality","$crafted_item",":number_of_crafted_items",":item_final_modifier"),
	    (str_store_string,s31,"@ You crafted a {s28} {s29} ^^{s16} {s17}"),		
	(try_end),

    (try_end),
    ],
	[  
      ("final_crafting_result",
	  [],
	  "Leave...",
      [
      (jump_to_menu,"mnu_crafters_workshops"),
	  (assign,reg10,0),
	## (call_script,"script_rigale_reset_craft_variables"), # GS appears to not exist anymore
      ],
	),
     ]
  ),

    (
    "crafting_no_component",0,
    "You do not have the required components, or don't know the specific recipe well enough.",
    "none",
    [],
	   [  
      ("final_crafting_leave",
	  [],
	  "Leave...",
      [
      (jump_to_menu,"mnu_crafters_workshops"),#(call_script,"script_rigale_reset_craft_variables"),
      ],
	  ),
     ]
  ),

## and now an example recipe; first a menu of recipes by category, then a single recipe under it
##################
    (
    "smith_firearms",0,
    "Here are the firearms you can craft:",
    "none",
    [],
    [
###
    ("crafting_flintlock_pistol",
       [
	(ge,"$level_of_gathering_skill",12),	   
        (try_begin),	   
		(call_script,"script_rigale_check_number_of_components_available","itm_iron"),
		(assign,reg10,reg1),
	(try_end),
 	(try_begin),	   
		(call_script,"script_rigale_check_number_of_components_available","itm_wood"),
		(assign,reg11,reg1),
	(try_end),
        (try_begin),	   
		(call_script,"script_rigale_check_number_of_components_available","itm_oil"),
		(assign,reg12,reg1),
	(try_end),
       ],
       "Flintlock Pistol: Basic crafting time: 13 hours, Available/required components: {reg10}/3 Iron, {reg11}/1 Wood, {reg12}/1 Oil.",
       [
	(call_script,"script_rigale_check_crafting_possible_and_start_crafting",slot_global_knowledge,12,"itm_iron",3,"itm_wood",1,"itm_oil",1,"itm_no_item",0,"itm_no_item",0,13,"itm_flintlock_pistol",3),
	   # in order: required item 1, number of required items 1, required item 2, number of required items 2, hours required to craft, type of crafted item, type of crafted item type 1 tools, 2 armor 3 weapon 4 ammunitions 5 food, 6 trade item
        (play_sound, "snd_distant_blacksmith"),
        ]),  
####			
      ("leave_smith_crafting",
       [
       ],
       "I want to craft something else",
       [
           (jump_to_menu,"mnu_town_smith"),   #GS this could have been   mnu_town for example if you had not made a menu "town_smith"
        ]),	

    ]
  ),

  There are 3 more layers we'll want to define:
a)  there is a check for the crafting timer to count down in  simple_triggers
Code:
  #rigale_craft_ongoing  # 157
( 1, 
  [
    (eq, "$g_not_classic", 1),      # GS when 0 skip this trigger

    (store_distance_to_party_from_party,"$distance_reference","p_main_party","p_town_13"),  # GS moved to another timer so that they dont fire at the same time and thus think the party never moved
   
    (try_begin),
        (gt,"$crafting_basic_hours_required",1),
        (val_sub, "$crafting_basic_hours_required", 1),
	(store_random_in_range,":show_overrall_message",1,5),
	(try_begin),		 
            (eq,":show_overrall_message",1),
	    (store_random_in_range,":show_message",1,11),

	    (val_add,":show_message","$type_of_gathering_success"), 
	    (val_sub,":show_message",2),		 
	    (try_begin),
		(lt,":show_message",4),
		(display_message,"@You have good feelings about this crafting...",0x66CC33),		 
	    (else_try),
		(is_between,":show_message",4,8),
		(display_message,"@Your crafting goes on",0x6699CC),		 
	    (else_try),
                (ge,":show_message",8),
		(display_message,"@You have bad feelings about this crafting",0xFF6666),		 
	    (try_end),
	(try_end),
		 
	#(rest_for_hours,2,"$g_phantasy_wait_multiplier",0),
    (else_try), 
	(eq,"$crafting_basic_hours_required",1),
	(display_message,"@Your crafting ends.",),
	(rest_for_hours, 0, "$g_phantasy_wait_multiplier", 0),
	(val_sub, "$crafting_basic_hours_required", 1),
	(jump_to_menu,"mnu_crafting_result"),
		 
    (try_end),	
    ]
  ),

b) I'll also call some lists for a trivial sort.  Yes, its a lot of overhead to sort 3 ways, but actually this lets you sort an arbitrary length list, so
if I for example wanted any of 5 items to substitute for each other the same code handles that, without changes...
  So let's add the list system to scripts, which is from  https://forums.taleworlds.com/index.php/topic,341079.0.html
I've added a few calls so I'll list only changes here, but to be clear most of the list system is simply copied verbatim from the topic above and not something I whipped up:
Code:
  #-## List management (no dependency)  from https://forums.taleworlds.com/index.php/topic,341079.0.html the_Dragon modified from Lumos
## GS list manager probably fails when number of slots for a troop is exceeded
## so for Perisno 0.73 around 550 elements; for Warsword 725; for Phantasy 2018 around 800

## The list's zero slot holds the number of current items in it
# script_list_clear_deep
# Clears all items from the list
# INPUT: arg1 - list no
# OUTPUT: none
("list_clear_deep", [
  (store_script_param, ":list_no", 1),
  (troop_get_slot, ":num_elements", ":list_no", 0),
  (val_add, ":num_elements", 1),
  (try_for_range, ":slot", 1, ":num_elements"),
    (troop_set_slot, ":list_no", ":slot", 0),
  (try_end),
  (troop_set_slot, ":list_no", 0, 0), # Reset number of elements
]),

# script_list_sort
# heap sort an arbitrary list
# INPUT: arg1 - list no
("list_sort", [
  (store_script_param, ":list_no", 1),
  (store_script_param, ":direction", 2),    # 0 = high to low (descending), 1 = low to high (ascending)

    (troop_get_slot, ":num_elements", ":list_no", 0),
    (gt, ":num_elements", 1),
    (store_add, ":num_elements2", ":num_elements", 1),
    (try_for_range, ":pass", 1, ":num_elements"),
        (troop_get_slot, ":value1", ":list_no", ":pass"),
        (store_add, ":pass2", ":pass", 1),
        (try_for_range, ":slot", ":pass2", ":num_elements2"),
            (troop_get_slot, ":value2", ":list_no", ":slot"),  
            (try_begin),
                (eq, ":direction", 0),
                (try_begin),
                    (gt, ":value2", ":value1"),
                    (troop_set_slot, ":list_no", ":pass", ":value2"),
                    (troop_set_slot, ":list_no", ":slot",":value1"),
                    (assign, ":value1", ":value2"),
                (try_end),
            (else_try), 
                (eq, ":direction", 1),
                (try_begin),
                    (lt, ":value2", ":value1"),
                    (troop_set_slot, ":list_no", ":pass", ":value2"),
                    (troop_set_slot, ":list_no", ":slot",":value1"),
                    (assign, ":value1", ":value2"),
                (try_end),
            (try_end),
        (try_end),
    (try_end),
]),

#-## List management end

## OUTPUT reg2  number of matching components
##        reg1  first inv slot matching
("rigale_check_depth_of_components_available",
 [
    (store_script_param, ":type_of_components",1),
	
    (assign, ":number_of_current_components", 0),
    (assign, ":first_slot", -1),
    (troop_get_inventory_capacity, ":inv_size", "trp_player"),
    (try_begin),
        (try_for_range, ":i_slot", 10, ":inv_size"),  # GS skip equipped/worn items when looking
            (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
            (eq, ":item_id", ":type_of_components"),	
            (neg|call_script, "script_cf_player_has_item_without_modifier", ":item_id", imod_rotten),
            (val_add,":number_of_current_components",1),
            (eq, ":first_slot", -1),
            (assign, ":first_slot", ":i_slot"),
        (try_end),
    (try_end),  # GS added a missing try_end here
    (assign, reg2, ":number_of_current_components"),
    (assign, reg1, ":first_slot"),
 ]
 ),

c) and now lets add an extension to game_menus
Code:
 ("leatherworker_various_3",0,
    "Here are the leather armors for horses you can craft:",
    "none",
    [	    ],
    [

      ("crafting_warg",
       [
	(ge,"$level_of_gathering_skill",9),

        # GS here's the problem: there are THREE items called "warg", that all look identical and have same stats
        (try_begin),	   
	    (call_script,"script_rigale_check_number_of_components_available","itm_warg_1"),
	    (assign,reg13,reg1),
	(try_end),
        (try_begin),	   
	    (call_script,"script_rigale_check_number_of_components_available","itm_warg_2"),
	    (assign,reg14,reg1),
	(try_end),
        (try_begin),	   
	    (call_script,"script_rigale_check_number_of_components_available","itm_warg_3"),
	    (assign,reg15,reg1),
	(try_end),
        (store_add, reg10, reg13, reg14),
        (val_add, reg10, reg15),
    
 	(try_begin),	   
	    (call_script,"script_rigale_check_number_of_components_available","itm_leatherwork"),
	    (assign,reg11,reg1),
	(try_end),
 	(try_begin),	   
	    (call_script,"script_rigale_check_number_of_components_available","itm_wool_cloth"),
	    (assign,reg12,reg1),
	(try_end),
        ],
       "Armored Warg: Basic crafting time: 13 hours, Available/required components: {reg10}/1 warg, {reg11}/5 leatherwork, {reg12}/1 wool cloth.",
       [
        (call_script, "script_list_clear_deep", "trp_list_14"),     # GS clean up the PREVIOUS use of the lists
        (call_script, "script_list_clear_deep", "trp_list_15"),
        (call_script, "script_list_clear_deep", "trp_list_16"),

        (call_script,"script_rigale_check_depth_of_components_available","itm_warg_1"),
        (assign, ":depth1", reg1),
        (assign, ":warg1",  reg2),
        (try_begin),
            (gt, ":warg1", 0),
            (call_script, "script_list_add", "trp_list_14", ":depth1"),
            (call_script, "script_list_add", "trp_list_15", ":depth1"),
            (call_script, "script_list_add", "trp_list_16", "itm_warg_1"),
        (try_end),

        (call_script,"script_rigale_check_depth_of_components_available","itm_warg_2"),
        (assign,":depth2", reg1),
        (assign, ":warg2", reg2),
        (try_begin),
            (gt, ":warg2", 0),
            (call_script, "script_list_add", "trp_list_14", ":depth2"),
            (call_script, "script_list_add", "trp_list_15", ":depth2"),
            (call_script, "script_list_add", "trp_list_16", "itm_warg_2"),
        (try_end),

        (call_script,"script_rigale_check_depth_of_components_available","itm_warg_3"),
        (assign,":depth3", reg1),
        (assign, ":warg3", reg2),
        (try_begin),
            (gt, ":warg3", 0),
            (call_script, "script_list_add", "trp_list_14", ":depth3"),
            (call_script, "script_list_add", "trp_list_15", ":depth3"),
            (call_script, "script_list_add", "trp_list_16", "itm_warg_3"),
        (try_end),

        (call_script, "script_list_count", "trp_list_14"),  # reg1 has the count  0 is empty, any other value > 0 is # elements
        (assign, ":count", reg1),

 ##       (assign, reg11, ":warg1"),
 ##       (assign, reg12, ":warg2"),
 ##       (assign, reg13, ":warg3"),
 ##       (display_message, "@warg1 {reg11}, warg2 {reg12}, warg3 {reg13}"),

        (try_begin),
            (ge, ":count", 1),
            (try_begin),
                (ge, ":count", 2), 
                (call_script, "script_list_sort", "trp_list_14", 1),    # sort list_14  low to high 
            (try_end),
            (call_script, "script_list_at", "trp_list_14", 1),
            (assign, ":slot", reg1),
        
            (call_script, "script_list_index_of", "trp_list_15", ":slot"),   # here we want to find a match in list_15 of that same value for inventory location #
            (assign, ":depth", reg1),
            (call_script, "script_list_at", "trp_list_16", ":depth"),    # and here we have the item that originally was at that location, which we'll use below
            (assign, ":virtual_item", reg1),

 ##           (assign, reg13, ":virtual_item"),
 ##           (str_clear, s11),
 ##           (str_store_item_name, s11, ":virtual_item"),
 ##           (display_message, "@v item {reg13} {s11}"),
        
            (call_script,"script_rigale_check_crafting_possible_and_start_crafting",slot_global_knowledge,9,":virtual_item",1,"itm_leatherwork",5,"itm_wool_cloth",1,"itm_no_item",0,"itm_no_item",0,13,"itm_a_warg_1",8),
	   # in order: required item 1, number of required items 1, required item 2, number of required items 2, hours required to craft, type of crafted item, type of crafted item type 1 tools, 2 armor 3 weapon 4 ammunitions 5 food, 6 trade item
        (try_end),
        (play_sound, "snd_distant_carpenter"),
        ]),


   ("leave_leatherworking_crafting",
       [
       ],
       "I want to craft something else",
       [
            (jump_to_menu,"mnu_town_leatherworker"),	  #(call_script,"script_rigale_reset_craft_variables"),
        ]),	
	]
	),

EDIT: small tweak to script_list_sort  should roughly double performance on larger lists.
EDIT2: adjust boundary for inner loop.
 

gsanders

Grandmaster Knight
Best answers
0
1) Made some changes to base code in preparation for Warsword Conquest:
  a) activated Windyplain's  "prsnt_sort_the_defenders", which works fine in a test within Phantasy 2018 (v156 unreleased version).

  b) It's obvious to me I'm not allowed to make changes according to my schedule or instinct, so I'll let Phantasy 2018 update after Warsword Conquest.  That should give me plenty of time to please everyone, while still struggling to hold onto what little inspiration still comes.  Honestly the more I do, the more demanding people are to sign me up for stuff I didn't ask for.  If I just gave less, there would be less expected, and everyone would be more grateful for what little there was, instead of angry that I am not doing enough.  I therefore don't have motivation for Phantasy 2018 right now, which is a pity, as it let me test routines away from Warsword Conquest, in a so-called neutral setting.  So called...

  c) This whole "let's mod and share the work as it comes to me" lost its sparkle after other people got involved.  I should have just sat on it, like everyone else did.  Thats how mods go years without updates.
 
Status
Not open for further replies.