An alternate and compatible door.txt
- monsters can open/bash/pick-lock doors when adjacent to them (bashing/picking-lock only if the creature is hostile)
- multiple doors (up to 8) can share the same SDF for their lock status, this is the door index in memory cell (4)
(this can save a lot of SDFs when there are many locked doors in a town)
- doors can be locked back with the corresponding key (special item) and with lock-picking
Show script source Script:
beginterrainscript ; variables ; short i_am_open , i_am_locked , door_opened , door_closed , door_unlocked , door_relocked ; short ter_loc_x , ter_loc_y , index_power , direction , thechar , result , choice , done , val_1 , val_2 , i , j ; short last_force_tick = -1 , last_run_tick = -1 ; body ; beginstate INIT_STATE ; choice = terrain_in_this_spot ( ) ; if ( ( choice >= 10 && choice <= 13 ) || ( choice >= 46 && choice <= 49 ) ) i_am_open = 0 ; else if ( ( choice >= 14 && choice <= 17 ) || ( choice >= 50 && choice <= 53 ) ) i_am_open = 1 ; else { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " wrong terrain number in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } i = 5 ; while ( i <= 7 ) { if ( get_memory_cell ( i ) != 0 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " unused mem_cell defined in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } i = i + 1 ; } if ( get_memory_cell ( 0 ) < 0 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " wrong lock level in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } if ( get_memory_cell ( 0 ) > 0 && i_am_open == 1 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " open doors cannot have a lock level in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } if ( get_memory_cell ( 1 ) < 0 || get_memory_cell ( 1 ) > 59 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " wrong special item number in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } if ( get_memory_cell ( 0 ) == 0 && get_memory_cell ( 1 ) != 0 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " inconsistent special item in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } if ( get_memory_cell ( 2 ) < 0 || get_memory_cell ( 2 ) > 299 || get_memory_cell ( 3 ) < 0 || get_memory_cell ( 3 ) > 29 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " wrong flag address in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } choice = get_memory_cell ( 4 ) ; if ( choice < 0 || choice > 7 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " wrong door index in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } else if ( choice != 0 && get_memory_cell ( 2 ) == 0 && get_memory_cell ( 3 ) == 0 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " inconsistent door index in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } ter_loc_x = my_loc_x ( ) ; ter_loc_y = my_loc_y ( ) ; choice = terrain_in_this_spot ( ) ; if ( choice == 10 || choice == 14 || choice == 46 || choice == 50 ) direction = 1 ; else if ( choice == 11 || choice == 15 || choice == 47 || choice == 51 ) direction = 2 ; else if ( choice == 12 || choice == 16 || choice == 48 || choice == 52 ) direction = 3 ; else if ( choice == 13 || choice == 17 || choice == 49 || choice == 53 ) direction = 4 ; choice = get_memory_cell ( 4 ) ; index_power = 1 ; i = 1 ; while ( i <= choice ) { index_power = index_power * 2 ; i = i + 1 ; } i_am_locked = 0 ; if ( get_memory_cell ( 0 ) > 0 ) { i_am_locked = 1 ; if ( get_memory_cell ( 2 ) > 0 || get_memory_cell ( 3 ) > 0 ) { done = get_flag ( get_memory_cell ( 2 ) , get_memory_cell ( 3 ) ) / index_power ; done = done % 2 ; if ( done > 0 ) i_am_locked = 0 ; } } set_mechanism_difficulty ( get_memory_cell ( 0 ) ) ; set_physical_strength ( get_memory_cell ( 0 ) ) ; set_script_mode ( 2 ) ; break ; beginstate START_STATE ; if ( last_run_tick == get_current_tick ( ) && is_combat ( ) == 0 ) end ( ) ; last_run_tick = get_current_tick ( ) ; choice = terrain_in_this_spot ( ) ; if ( ( choice >= 10 && choice <= 13 ) || ( choice >= 46 && choice <= 49 ) ) i_am_open = 0 ; else if ( ( choice >= 14 && choice <= 17 ) || ( choice >= 50 && choice <= 53 ) ) i_am_open = 1 ; else end ( ) ; if ( get_memory_cell ( 0 ) < 0 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " wrong lock level in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } if ( get_memory_cell ( 2 ) < 0 || get_memory_cell ( 2 ) > 299 || get_memory_cell ( 3 ) < 0 || get_memory_cell ( 3 ) > 29 ) { print_str_color ( " *** error *** " , 1 ) ; print_big_str ( " wrong flag address in Door at XXYY: " , ( my_loc_x ( ) * 100 ) + my_loc_y ( ) , " " ) ; end ( ) ; } if ( i_am_open == 1 && i_am_locked == 1 ) { i_am_locked = 0 ; if ( get_memory_cell ( 2 ) > 0 || get_memory_cell ( 3 ) > 0 ) inc_flag ( get_memory_cell ( 2 ) , get_memory_cell ( 3 ) , index_power ) ; } if ( i_am_open == 0 && is_object_on_space ( ter_loc_x , ter_loc_y , 4 ) == 0 && ( ( last_force_tick != get_current_tick ( ) && get_memory_cell ( 0 ) < 250 ) || i_am_locked == 0 ) ) { done = 0 ; val_1 = 0 ; i = ter_loc_x - 1 ; if ( direction != 2 ) i = i + 1 ; if ( direction != 4 ) val_1 = 1 ; while ( i <= ( ( ter_loc_x + 1 ) - val_1 ) && done == 0 ) { val_2 = 0 ; j = ter_loc_y - 1 ; if ( direction != 1 ) j = j + 1 ; if ( direction != 3 ) val_2 = 1 ; while ( j <= ( ( ter_loc_y + 1 ) - val_2 ) && done == 0 ) { thechar = char_on_spot ( i , j ) ; if ( thechar > 5 ) { choice = get_species ( thechar ) ; if ( char_ok ( thechar ) != 1 ) result = 0 ; else if ( choice == 5 || choice == 6 || choice == 9 || choice == 10 || choice == 11 ) result = 0 ; else if ( ( get_char_status ( thechar , 10 ) + get_char_status ( thechar , 11 ) + get_char_status ( thechar , 13 ) + get_char_status ( thechar , 18 ) + get_char_status ( thechar , 29 ) ) > 0 ) result = 0 ; else result = 1 ; if ( result == 1 ) { if ( i_am_locked == 0 ) { flip_terrain ( ter_loc_x , ter_loc_y ) ; if ( dist_to_party ( ) <= 8 ) play_sound ( -58 ) ; done = 1 ; } else { if ( get_attitude ( thechar ) >= 10 ) { result = 0 ; val_1 = get_stat ( thechar , 0 ) + ( get_level ( thechar ) / 2 ) ; if ( ( val_1 * 9 ) >= ( get_physical_strength ( ) * 10 ) && get_health ( thechar ) > get_physical_strength ( ) ) { result = result + 1 ; } choice = get_species ( thechar ) ; if ( get_stat ( thechar , 2 ) >= 3 && ( choice == 0 || choice == 2 || choice == 3 || choice == 13 ) ) { val_2 = ( get_stat ( thechar , 1 ) + get_stat ( thechar , 2 ) + get_stat ( thechar , 15 ) + get_level ( thechar ) ) / 3 ; if ( choice == 2 ) val_2 = val_2 + 4 ; if ( char_has_item ( thechar , 176 ) == 1 ) val_2 = val_2 + 10 ; else if ( char_has_item ( thechar , 175 ) == 1 ) val_2 = val_2 + 4 ; else if ( char_has_item ( thechar , 174 ) == 1 ) val_2 = val_2 + 2 ; if ( val_2 >= get_mechanism_difficulty ( ) ) result = result + 2 ; } if ( result != 0 ) { last_force_tick = get_current_tick ( ) ; if ( result == 3 ) { if ( get_ran ( 1 , 1 , val_1 - get_physical_strength ( ) ) > get_ran ( 1 , 1 , val_2 - get_mechanism_difficulty ( ) ) ) result = 1 ; else result = 2 ; } if ( result == 1 ) { if ( get_ran ( 1 , 1 , val_1 ) >= ( get_physical_strength ( ) + get_ran ( 1 , -3 , 3 ) ) ) { result = 1 ; set_physical_strength ( 0 ) ; } else { result = 0 ; choice = get_ran ( 1 , 1 , get_physical_strength ( ) ) ; if ( choice > ( get_level ( thechar ) + 1 ) / 2 ) choice = ( get_level ( thechar ) + 1 ) / 2 ; change_char_health ( thechar , choice * -1 ) ; } play_sound ( -152 ) ; } else if ( result == 2 ) { if ( get_ran ( 1 , 1 , val_2 ) >= ( get_mechanism_difficulty ( ) + get_ran ( 1 , -3 , 3 ) ) ) { result = 1 ; if ( dist_to_party ( ) <= 6 ) play_sound ( -9 ) ; } else { result = 0 ; } } if ( result == 1 ) { if ( get_memory_cell ( 2 ) > 0 || get_memory_cell ( 3 ) > 0 ) inc_flag ( get_memory_cell ( 2 ) , get_memory_cell ( 3 ) , index_power ) ; i_am_locked = 0 ; flip_terrain ( ter_loc_x , ter_loc_y ) ; done = 1 ; } } } } } } if ( direction != 4 ) val_1 = 1 ; else val_1 = 0 ; if ( direction != 3 ) val_2 = 1 ; else val_2 = 0 ; j = j + 1 ; } i = i + 1 ; } } break ; beginstate SEARCH_STATE ;