//Town 1: The Brigands' Madhouse

begintownscript;

variables;
int i;

body;

beginstate INIT_STATE;
//called when the party enters the town
	if(get_flag(2,1) == 1)
		set_terrain(51,54,57);
	else if(get_flag(1,2) == 1){
		relocate_character(11,52,52);
		set_creature_memory_cell(11,3,1);
	}
	set_name(6,"Whisper"); //d
	set_name(8,"Mathersly"); //d
	set_name(7,"Gabston"); //d
	set_name(9,"Hu"); //d
	set_name(11,"Crosby"); //d
	set_name(24,"Slice"); //d
	set_name(23,"Black"); //d
	set_name(10,"Nick"); //d
	set_name(13,"Ol' Jimbob"); //d
	set_name(14,"Knuckles");  //d
	set_name(20,"Absford");
	set_name(28,"Cole");
	set_name(36,"Boris"); //All bodyguards are named Boris, right?
	set_level(36,18);
	
	add_char_to_group(6,1);
	add_char_to_group(7,1);
	add_char_to_group(8,1);
	add_char_to_group(36,1);
	
	if(get_flag(2,29) == 100){
		i = 6;
		while(i < 120){
			set_attitude(i,10);
			i = i + 1;
		}
	}
break;

beginstate EXIT_STATE;
//called when the party leaves the town
	if(get_flag(2,29) == 0){ //whole town not mad yet
		i = 6;
		while(i < 120){
			if(char_ok(i) && get_attitude(i) == 10){
				//but they will be
				set_flag(2,29,1);
				i = 1000; //break out
			}
			i = i + 1;
		}
		if((i < 1000) && get_flag(2,28) == 1){
			set_flag(2,29,1);
		}
	}
break;

beginstate START_STATE;
//called every turn when the party is in the town
	if(get_ran(1,1,100) < 1)
		flip_terrain(30,44);
	if(get_ran(1,1,100) < 1)
		flip_terrain(37,44);
	if((get_flag(2,28) == 0) && ((char_ok(6) == 0 || char_ok(7) == 0 || char_ok(8) == 0 || char_ok(36) == 0) || 
		(get_attitude(6) == 10 || get_attitude(7) == 10 || get_attitude(8) == 10 || get_attitude(36) == 10))){
		set_attitude(1001,10);
		set_flag(2,28,1);
		i = 400 + get_current_tick();
		set_flag(2,9,i/256);
		set_flag(2,10,i%256);
	}
	if((get_flag(2,28) == 1) && (get_flag(2,29) == 0)){
		i = (get_flag(2,9) * 256) + get_flag(2,10);
		if(get_current_tick() > i){
			message_dialog("You hear a sudden outburst of shouting. It sounds like the brigands have found out about what you did to their leaders.","");
			i = 6;
			while(i < 120){
				set_attitude(i,10);
				i = i + 1;
			}
			set_flag(2,29,1);
		}
	}
break;

beginstate 10;
	if(get_flag(2,0)==0){
		message_dialog("It appears that this storeroom is not being used much at the moment. ","");
		set_flag(2,0,1);
	}
break;

beginstate 11;
	if(char_ok(23)){
		message_dialog("As you step toward the loot in the back of the room, Black growls, _You lot stay away from that stuff, hear?_","You back away.");
		block_entry(1);
	}
break;

beginstate 12;
	if(character_in_party(105)>0){
		message_dialog("Crosby motions you to stop. _Don't take this tunnel, it triggers a barricade up ahead. There's a secret passage a few feet north; use it instead._","");
		block_entry(1);
	}
	else{
		set_terrain(32,10,39);
	}
break;

beginstate 13;
	if(get_flag(2,2)==0){
		set_flag(2,2,1);
		message_dialog("Across a deep pit stand several brigands with bows. They raise their weapons at you, but lower them again when they see Crosby.","_Yep,_ he says, _Nobody's just going to waltz in here. Place is better defended than the Castle itself._");
	}
break;

beginstate 14;
	if(get_flag(2,3)==0){
		set_flag(2,3,1);
		message_dialog("You step into a well lit room whose primary feature is a tough looking guard box with several bored looking brigands inside.","Seeing Crosby with you, they make no move to hinder your progress.");
	}
break;

beginstate 15;
	if(get_flag(2,4)==0){
		set_flag(2,4,1);
		message_dialog("As you walk down the passage, Crosby speaks up. _This here is really one of the most historical locals in all of Avernum. Those of us who. . . prefer to conduct business our own way have been gathering here for decades._","There was a time when there were fancy magical teleporters here, but some vigilantes got in and almost shut the whole operation down. Still, our security's better now than it was back then, so we got nothin' to worry about.");
	}
break;

beginstate 16;
	if(get_flag(2,6)==0 && char_ok(42)){
		message_dialog("The guard motions you to go no further. Nobody around here trusts you much, it seems.","");
		block_entry(1);
	}
break;

beginstate 17;
	if(get_flag(2,6)==0 && char_ok(41)){
		message_dialog("The guard motions you to go no further. Nobody around here trusts you much, it seems.","");
		block_entry(1);
	}
break;

beginstate 18;
	if(get_flag(2,7)==0){
		set_flag(2,7,1);
		message_dialog("_Go down to that door on your right side. You need to go through the meeting room to the offices and talk to Gabston about what you're gonna do around here._ Crosby says.","_By the way, Gabston is second in command here, right after Whisper._");
	}
break;

beginstate 19;
	if(get_flag(2,8)==0){
		set_flag(2,8,1);
		message_dialog("_Ok, _ Crosby says with a cheerful tone, _Here you are. Gabston's office is dead ahead. _","I'll take my leave now, but I'll be in the dining hall if you wanna talk.");
		remove_char_from_party(105);
		spawn_creature(11);
	}
break;

beginstate 20;
	if((get_flag(2,6) == 0) && char_ok(8) && (get_attitude(8) != 10)){
		message_dialog("As you try to walk past him, the secretary scowls. _Kindly stop where you are, strangers. Mr. Whisper is far too busy for you to bother._","");
		block_entry(1);
	}
break;

beginstate 21;
	if(get_flag(2,12) == 0){
		message_dialog("Interestingly, it looks as if this storeroom isn't as unused as it first seemed. This appears to be someone's private stash.","");
		set_flag(2,12,1);
	}
break;

beginstate 22;
	if(get_flag(2,6) == 1 && get_flag(2,13) == 0){
		message_dialog("Now that the bosses here trust you somewhat, it may be time to start poking around to see what evidence you can find for Captain Parseval.","");
		set_flag(2,13,1);
	}
break;

beginstate 23;
	if(get_flag(2,14) == 0){
		message_dialog("This seems to be a secret exit. Apparently Whisper is a pretty paranoid sort of guy.","");
		set_flag(2,14,1);
	}
break;

beginstate 24;
	if(get_flag(2,15) == 0){
		message_dialog("You enter what seems to be the most opulently decorated room in the hideout. It must, therefore, be Whisper's room. ","");
		set_flag(2,15,1);
	}
break;

beginstate 25;
	if(get_flag(2,16) == 0){
		message_dialog("This is one of the bunk-rooms that most of the brigands sleep in. You're not really all interested in taking a nap in the middle of your undercover mission, though. ","");
		set_flag(2,16,1);
	}
break;

beginstate 26;
	if(get_flag(2,17) == 0){
		message_dialog("This back corridor is quiet, without many people around. It looks like it mostly just has a couple of storerooms off of it, as well as the entrances to the ledges guarding the path into the hideout.","");
		set_flag(2,17,1);
	}
break;