// v1.0.0
// t01Almaria.txt
// Xoid (xoid@hotmail.com)

begintownscript;

variables;

int i,j,k,r1,choice;
int disable_state = 0;

body;

// This state called whenever this town is entered.
beginstate INIT_STATE;
	// Names must appear first.
	//set_name(,"");

	if (town_status(current_town()) < 2) {
		enable_add_chars(1);
		set_crime_tolerance(5);
	}
	else turn_off_training(1);
break;

// Always called when the town is left.
beginstate EXIT_STATE;
break;

// This state is called every turn the party is in this town.
beginstate START_STATE;
break;

beginstate 10;
	block_entry(1);
break;

beginstate 11;
	if ((disable_state == 0) && town_status(current_town()) < 2) {
		reset_dialog();
		add_dialog_str(0,"You approach the gate, and a grumpy guard pokes his head out a window and says _Greetings, friend. The toll for the bridge is 5 coins._",0);

		add_dialog_choice(0,"Leave.");
		add_dialog_choice(1,"Pay the toll.");
		add_dialog_choice(2,"Attack!");

		choice = run_dialog(0);

		reset_dialog();
		if (choice == 1) {
			block_entry(1);
			end();
		}
		else if (choice == 2) {
			if (coins_amount() >= 5)
				add_dialog_str(0,"The guard takes your coins and signals to another guard to open the gates. You are free to enter Almaria.",0);
				change_coins(-5);
				flip_terrain(55,31);
				flip_terrain(55,32);
				flip_terrain(55,33);
				disable_state = 1;
			else {
				add_dialog_str(0,"When the guard realises you do not have the coins to pay the toll he grumbles, mutters an obscenity and walks back to his post.",0);
				block_entry(1);
			}
			run_dialog(0);
		}
		else {
			add_dialog_str(0,"When you start drawing weapons, the previously grumpy guard begins to get jumpy, and calls out an alarm just to be on the safe side.",0);
			run_dialog(0);
			disable_state = 1;
			make_town_hostile();
			// add this too? change_crime_level(5);
		}
	}
break;