Disaster with Doors

Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /var/www/pied-piper.ermarian.net/includes/common.inc).
AuthorTopic: Disaster with Doors
Infiltrator
Member # 154
Profile #0
My godparty is able to open Difficulty 200 doors.

I present you with a modified edition of door.txt to cure this.
// door.txt - This is the basic script that powers all doors. If you are
// working on a scenario that contains doors, DO NOT REMOVE THIS SCRIPT.

// If you place a door, this script is automatically attached to it. The
// default settings for the script are for a basic, unlocked door. To make it
// locked, you will need to change the memory cells.

// Memory Cells -
// 0 - Lock level. If left at 0, door is unlocked. Otherwise, the strength/tool
// use needed to get it open. If this is set to a really high number (say, 200),
// it can't be unlocked by normal means
// 1 - Key needed. If left at 0, no special item helps unlock the door. Otherwise,
// if that party has this special item, the door automatically unlocks.
// 2,3 - Coordinates for a stuff done flag. If these are 0 and 0, ignored. Otherwise,
// the stuff done flag is set to 1 when the door is unlocked. If the flag is non-zero,
// than when the party enters this zone, the door will ebcome unlocked.

beginterrainscript;

variables;
short i_am_open = 0;
short cur_terrain;
short i_am_locked = 0;

short door_opened;
short choice;
body;

beginstate INIT_STATE;
cur_terrain = terrain_in_this_spot();
if (((cur_terrain >= 14) && (cur_terrain <= 17)) ||
((cur_terrain >= 50) && (cur_terrain <= 53)))
i_am_open = 1;
else i_am_open = 0;

if (get_memory_cell(0) > 0) {
i_am_locked = 1;
set_mechanism_difficulty(get_memory_cell(0));
set_physical_strength(get_memory_cell(0));

if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0)
i_am_locked = 0;
}
}

break;

beginstate START_STATE;
break;

beginstate SEARCH_STATE;
if (i_am_open == 1) {
print_str_color("You close the door.",2);
flip_terrain(my_loc_x(),my_loc_y());
i_am_open = 0;
play_sound(-59);
}
break;

beginstate BLOCK_MOVE_STATE;
if (i_am_open == 0) {
block_entry(1);

door_opened = 1;

if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0)
i_am_locked = 0;
}

if ((get_memory_cell(1) > 0) && (i_am_locked > 0)) {
if (has_special_item(get_memory_cell(1))) {
print_str_color("You have the key which unlocks this door.",2);
if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0))
set_flag(get_memory_cell(2),get_memory_cell(3),1);
i_am_locked = 0;
}
}

if ((get_memory_cell(0) > 199) && (i_am_locked)) {
reset_dialog();

add_dialog_str(0, "This door has a strong magical aura around it, one stronger than you will be able to break. Even without it's magical field, the door looks extremely strong and hefty.", 0);
add_dialog_str(1, "You won't be able to open this door through forceful means.", 0);

add_dialog_choice(0, "OK.");
run_dialog(0);

end();
}

if (i_am_locked) {
reset_dialog();


if (get_memory_cell(1) > 0)
add_dialog_str(0,"This door is locked, and you don't have the right key. You can have your strongest character try to bash it down (which requires high strength) or have your most skilled character try to pick the lock (which requires Tool Use skill and a lockpick).",0);
else add_dialog_str(0,"This door is locked. You can have your strongest character try to bash it down (which requires high strength) or have your most skilled character try to pick the lock (which requires Tool Use skill and a lockpick).",0);
add_dialog_choice(0,"Leave the door alone.");
add_dialog_choice(1,"Try to bash it down.");
add_dialog_choice(2,"Try to pick the lock.");
choice = run_dialog(0);

if (choice == 1)
end();
if (choice == 2) {
if (run_bash_door(get_physical_strength()) == FALSE)
door_opened = 0;
}
if (choice == 3) {
if (run_pick_lock(get_mechanism_difficulty()) == FALSE)
door_opened = 0;
else if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0))
award_party_xp(BASE_TRAP_XP,1 + 2 * get_mechanism_difficulty());

}
}

if (door_opened) {
print_str("You open the door.");
if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0))
set_flag(get_memory_cell(2),get_memory_cell(3),1);
flip_terrain(my_loc_x(),my_loc_y());
i_am_open = 1;
i_am_locked = 0;
play_sound(-160);
}
}
break;

beginstate UNLOCK_SPELL_STATE;
if ((i_am_open > 0) || (i_am_locked == 0))
print_str_color("Unlock Doors: The spell doesn't affect unlocked doors.",2);
else {
if (get_memory_cell(0) > 199) {
print_str_color("Unlock Doors: The door resists the spell.",2);
end();
}
if (get_unlock_spell_strength() >= get_mechanism_difficulty() * 2) {
print_str_color("Unlock Doors: The spell unlocks a door.",2);
i_am_locked = 0;
play_sound(9);
if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0))
set_flag(get_memory_cell(2),get_memory_cell(3),1);
}
else {
print_str_color("Unlock Doors: The spell isn't strong enough to affect the door.",2);
print_str_color(" (This spell usually only affects doors with magical protection.)",2);
}
}
break;

beginstate DISPEL_BARRIER_STATE;
if ((i_am_open == 0) && (i_am_locked)) {
print_str_color("Dispel Barrier: The spell fails to affect a locked door.",2);
}
break;
Not thouroughly tested. Use at your own risk.

--------------------
Apparently still annoying.
Posts: 612 | Registered: Saturday, October 13 2001 07:00
Board Administrator
Member # 1
Profile Homepage #1
Just as a note, you might want to post these things in the Blades of Avernum Editor forum. They're much more likely to be seen by the relevant people and less likely to confuse and terrify regular players.

- Jeff Vogel

--------------------
Official Board Admin
spidweb@spiderwebsoftware.com
Posts: 960 | Registered: Tuesday, September 18 2001 07:00
Infiltrator
Member # 154
Profile #2
Good point. Thanks for moving it.

[ Monday, June 07, 2004 12:54: Message edited by: Grey-Eyed Stranger ]

--------------------
Apparently still annoying.
Posts: 612 | Registered: Saturday, October 13 2001 07:00
...b10010b...
Member # 869
Profile Homepage #3
Nice scripting, although I'm not sure how much use it should see. God parties are a legitimate tool for both debugging and reviewing.

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Infiltrator
Member # 154
Profile #4
Well, it also has the advantage of clearly defining which doors you can't open right now (no trying to bash down unopenable doors.)

--------------------
Apparently still annoying.
Posts: 612 | Registered: Saturday, October 13 2001 07:00
Post Navel Trauma ^_^
Member # 67
Profile Homepage #5
You'll only try to bash down an unopenable door once.

--------------------
Barcoorah: I even did it to a big dorset ram.

New Mac BoE
Posts: 1798 | Registered: Thursday, October 4 2001 07:00
Infiltrator
Member # 154
Profile #6
Yes, but if you have a weak party it might not work even if it is bash-openable at your level.

Bad luck, that is.

--------------------
Apparently still annoying.
Posts: 612 | Registered: Saturday, October 13 2001 07:00
Shake Before Using
Member # 75
Profile #7
Er. BoA has no luck involved in bashing doors.
Posts: 3234 | Registered: Thursday, October 4 2001 07:00
Law Bringer
Member # 2984
Profile Homepage #8
I don't think the technical term 'luck', as defined by the BoA editor, was intended here. But hey. :P

--------------------
EncyclopaediaArchivesMembersRSS [Topic / Forum] • BlogPolarisNaNoWriMo
Look on my works, ye mighty, and despair.
I have a love of woodwind instruments.
Posts: 8752 | Registered: Wednesday, May 14 2003 07:00
...b10010b...
Member # 869
Profile Homepage #9
There's no randomness involved either. If you can bash a particular door, you will succeed in doing so every time.

Anyway, it tells you the strength of the door when you fail to open it. If it's 200, you won't try again. :P

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Infiltrator
Member # 154
Profile #10
Yeah, I knew about how it told the difficulty after bashing. And I didn't know randomness wasn't involved in bashing, that's rather surprising.

But hey, it saves you a bash. :P

--------------------
Apparently still annoying.
Posts: 612 | Registered: Saturday, October 13 2001 07:00
Infiltrator
Member # 148
Profile #11
And the common problem with the this door script is the same as the one provided by Spiderweb.

The script does NOT CHECK TO SEE IF TERRAIN 174 is the current terrain.

174 is the open fence gate, but because it is excluded from the if statement you cannot shut the door.

However if you open a closed fence gate the boolean variable flips allowing you to later shut it.

--------------------
My ego is bigger than yours.
Posts: 480 | Registered: Thursday, October 11 2001 07:00
Infiltrator
Member # 154
Profile #12
Putting difficulty of 200 on an open fence gate is kind of pointless. :P

And also, the manual "more than" "less than" checking is rather messy. A cleaner approach would be..
short cTerrain;
short openDoors[15];
openDoors[] = 40; // first open door terrain
openDoors[] = 50; // first open door terrain
openDoors[] = 60; // first open door terrain

cTerrain = terrain_in_this_spot();
if (in_array(cTerrain, openDoors)) {
// do stuff
}
Unfortunately, Spiderweb is unlikely to ever include such array support.

Or perhaps something like...
// Inside an Item Declaration
is_open_door = 1;
is_closed_door = 0;
And in door.txt...
if (get_terrain_info('is_open_door',party_move_into_terrain() == true)) {
// etc
}
Essentially, burying numbers that could change inside code which is likely to be duplicated (say, a very special door) is bad. Because then you have to trudge through all the scripts and change all the relevant numbers.

[ Thursday, June 10, 2004 04:08: Message edited by: Grey-Eyed Stranger ]

--------------------
Apparently still annoying.
Posts: 612 | Registered: Saturday, October 13 2001 07:00