// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains
// special encounters and code accessible from anywhere in the scenario. It
// also contains the code that initializes important special things in the
// scenario (like shops and names and descriptions of special items).

// You can create your own states, but you should give all of them numbers greater than
// or equal to 10.

//
// global flags: 50, 0 = counter for energy drainer
//               50, 1 = got through without 'waking'
//               50, 2 = went through bush
//               50, 3 = lever magic value
//               50, 4 = 1 when magic number matched
//               50, 5 = 1 when goddess book read
//               50, 6 = 1 got delivery job, 2 finished, 10 rewarded
//               50, 7 = 1-5 got find job, > 5 finished, 10 got reward
//               50, 8 = 1-5 got help job, > 5 finished, 10 got reward
//               50, 9 = given number hint
//               50, 10 = told number
//               50, 11 = counter to start hint (town 2 entry count)
//               50, 12 = start state flag
//               100, 0 = 1, somebody in party [still] naked
//

beginscenarioscript;

variables;

short i, e, val, choice;
string valline;

body;

// This is the state that is called every time the scenario is loaded,
// even when a save file in the scenario is loaded. Some things that should go here:
//    Names and descriptions of special items.
//    Names and effects of custom special abilities.
beginstate LOAD_SCEN_STATE;
	set_flag(50, 0, 0);

	// quests (0 never given, others ways to get money within Pergamos)
	init_quest(0, "What, why and how", "You need to discover what you are doing in Pergamos.");
	init_quest(1, "Deliver message", "The mayor of Pergamos will pay to have a message delivered to Father Antipas.");
	init_quest(2, "Find bottles of wine", "Stan, the spirit shop proprietor will pay for each bottle of most excellent wine found.");
	init_quest(3, "Help finish planting", "Farmer Wormwood needs help to finish planting his crop.");

	// special items
	init_special_item(1, "Stamped Key", "A heavy, bronze key.  A lever is stamped on it.");
break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
//    The stuff in shops.
//    Creating horses and boats.
beginstate START_SCEN_STATE;
	// set lever 'magic' value (changes every game!)
	set_flag(50, 3, get_ran(1, 1, 255));

	// Horses
	create_horse(0, 0, 25, 37, 1);
	create_horse(1, 0, 26, 43, 1);
	create_horse(2, 0, 29, 45, 1);

	// set all npc level up...
	set_creature_type_level(1, 99);
	set_creature_type_level(2, 99);
	set_creature_type_level(3, 99);
	set_creature_type_level(4, 99);
	set_creature_type_level(5, 99);
	i = 10;
	while (i < 19) {
		set_creature_type_level(i, 99);
		i = i + 1;
	}
	set_creature_type_level(49, 99);
	set_creature_type_level(68, 99);
	i = 73;
	while (i < 83) {
		set_creature_type_level(i, 99);
		i = i + 1;
	}
	set_creature_type_level(86, 50); // child!
	set_creature_type_level(96, 99);
	set_creature_type_level(97, 99);
	set_creature_type_level(99, 99);
	set_creature_type_level(104, 99);
	set_creature_type_level(105, 99);
	set_creature_type_level(106, 99);
	set_creature_type_level(123, 99);
	set_creature_type_level(124, 99);
	set_creature_type_level(125, 99);
	set_creature_type_level(131, 99);
	set_creature_type_level(133, 99);
	set_creature_type_level(175, 99);
	i = 186;
	while (i < 191) {
		set_creature_type_level(i, 99);
		i = i + 1;
	}
	set_creature_type_level(226, 99);

	// Initialize a few shops.
	// Shop 0 - food, general
	add_item_to_shop(0, 4, get_ran(1, 1, 50));
	add_item_to_shop(0, 5, get_ran(1, 1, 50));
	add_item_to_shop(0, 6, get_ran(1, 1, 50));
	add_item_to_shop(0, 7, get_ran(1, 1, 50));
	add_item_to_shop(0, 12, get_ran(1, 1, 50));
	add_item_to_shop(0, 397, get_ran(1, 1, 10));
	add_item_to_shop(0, 398, get_ran(1, 1, 10));
	add_item_to_shop(0, 399, get_ran(1, 1, 8));

	// Shop 1 - food, meats only
	add_item_to_shop(1, 7, get_ran(1, 1, 50));
	add_item_to_shop(1, 8, get_ran(1, 1, 50));
	add_item_to_shop(1, 9, get_ran(1, 1, 50));
	add_item_to_shop(1, 10, get_ran(1, 1, 50));
	add_item_to_shop(1, 11, get_ran(1, 1, 50));

	// Shop 2 - food, fruits/veggies only
	add_item_to_shop(2, 5, get_ran(1, 1, 50));
	add_item_to_shop(2, 6, get_ran(1, 1, 50));
	add_item_to_shop(2, 397, get_ran(1, 1, 25));
	add_item_to_shop(2, 398, get_ran(1, 1, 25));

	// Shop 3 - food, spirits
	add_item_to_shop(3, 166, get_ran(1, 1, 25));
	add_item_to_shop(3, 393, get_ran(1, 1, 25));
	add_item_to_shop(3, 414, get_ran(1, 1, 10));
	add_item_to_shop(3, 415, get_ran(1, 1, 10));
	add_item_to_shop(3, 418, get_ran(1, 1, 4));

	// Shop 4 - clothes
	add_item_to_shop(4, 18, 4);
	add_item_to_shop(4, 19, 4);
	add_item_to_shop(4, 20, 4);
	add_item_to_shop(4, 21, 4);
	add_item_to_shop(4, 22, 4);
	add_item_to_shop(4, 23, 4);

	// Shop 5 - home
	add_item_to_shop(5, 149, get_ran(1, 1, 5));
	add_item_to_shop(5, 150, get_ran(1, 1, 5));
	add_item_to_shop(5, 151, get_ran(1, 1, 5));
	add_item_to_shop(5, 152, get_ran(1, 1, 5));
	add_item_to_shop(5, 153, get_ran(1, 1, 5));
	add_item_to_shop(5, 163, get_ran(1, 1, 5));
	add_item_to_shop(5, 165, get_ran(1, 1, 5));
	add_item_to_shop(5, 168, get_ran(1, 1, 5));
	add_item_to_shop(5, 169, get_ran(1, 1, 5));
	add_item_to_shop(5, 173, get_ran(1, 1, 10));
	add_item_to_shop(5, 183, get_ran(1, 1, 5));
	add_item_to_shop(5, 184, get_ran(1, 1, 5));
	add_item_to_shop(5, 373, get_ran(1, 1, 5));
	add_item_to_shop(5, 374, get_ran(1, 1, 5));
	add_item_to_shop(5, 375, get_ran(1, 1, 5));
	add_item_to_shop(5, 401, get_ran(1, 1, 5));
	add_item_to_shop(5, 402, get_ran(1, 1, 5));
	add_item_to_shop(5, 403, get_ran(1, 1, 5));
	add_item_to_shop(5, 404, get_ran(1, 1, 5));
	add_item_to_shop(5, 405, get_ran(1, 1, 5));

	// Shop 6 - hardware
	add_item_to_shop(6, 158, get_ran(1, 1, 5));
	add_item_to_shop(6, 159, get_ran(1, 1, 5));
	add_item_to_shop(6, 160, get_ran(1, 1, 5));
	add_item_to_shop(6, 161, get_ran(1, 1, 5));
	add_item_to_shop(6, 170, get_ran(1, 1, 5));
	add_item_to_shop(6, 190, get_ran(1, 1, 5));
	add_item_to_shop(6, 316, get_ran(1, 1, 5));
	add_item_to_shop(6, 317, get_ran(1, 1, 5));
	add_item_to_shop(6, 318, get_ran(1, 1, 5));
	add_item_to_shop(6, 319, get_ran(1, 1, 5));
	add_item_to_shop(6, 391, get_ran(1, 1, 5));
	add_item_to_shop(6, 411, get_ran(1, 1, 5));
	add_item_to_shop(6, 412, get_ran(1, 1, 25));
	add_item_to_shop(6, 413, get_ran(1, 1, 25));

	// Shop 7 - various
	add_item_to_shop(7, 164, get_ran(1, 1, 5));
	add_item_to_shop(7, 182, get_ran(1, 1, 5));
	add_item_to_shop(7, 186, get_ran(1, 1, 5));
	add_item_to_shop(7, 195, get_ran(1, 1, 5));
	add_item_to_shop(7, 376, get_ran(1, 1, 5));
	add_item_to_shop(7, 406, get_ran(1, 1, 5));
	add_item_to_shop(7, 408, get_ran(1, 1, 5));
	add_item_to_shop(7, 417, get_ran(1, 1, 5));
	add_item_to_shop(7, 458, get_ran(1, 1, 2));

	// Shop 8 - taylor
	add_item_to_shop(8, 154, get_ran(1, 1, 5));
	add_item_to_shop(8, 155, get_ran(1, 1, 5));
	add_item_to_shop(8, 156, get_ran(1, 1, 5));
	add_item_to_shop(8, 157, get_ran(1, 1, 10));
	add_item_to_shop(8, 188, get_ran(1, 1, 15));
	add_item_to_shop(8, 189, get_ran(1, 1, 25));
	add_item_to_shop(8, 372, get_ran(1, 1, 10));

	// Shop 9 - office
	add_item_to_shop(9, 185, get_ran(1, 1, 50));
	add_item_to_shop(9, 187, get_ran(1, 1, 5));
	add_item_to_shop(9, 194, get_ran(1, 1, 15));
	add_item_to_shop(9, 372, get_ran(1, 1, 10));
	add_item_to_shop(9, 407, get_ran(1, 1, 5));
	add_item_to_shop(9, 408, get_ran(1, 1, 5));

	// Shop 10 - head!
	add_item_to_shop(10, 5, get_ran(1, 1, 50));
	add_item_to_shop(10, 170, get_ran(1, 1, 10));
	add_item_to_shop(10, 184, get_ran(1, 1, 5));
	add_item_to_shop(10, 188, get_ran(1, 1, 10));
	add_item_to_shop(10, 193, get_ran(1, 1, 10));
	add_item_to_shop(10, 306, 2);
	add_item_to_shop(10, 373, get_ran(1, 1, 5));
	add_item_to_shop(10, 410, get_ran(1, 1, 5));
	add_item_to_shop(10, 417, get_ran(1, 1, 25));

	// Shop 11 - pawn (just buys)
	add_item_to_shop(11, 196, 3);
	add_item_to_shop(11, 197, 3);
	add_item_to_shop(11, 198, 3);

	// shop 12 - masks only
	add_item_to_shop(12, 450, 10);
break;

// This state is called every tick wherever the party is in the scenario.
// You can use the set_state
beginstate START_STATE;
	// zero spell energy every 2 steps
	if (get_flag(50, 0) >= 2) {
		set_flag(50, 0, 0);
		set_flag(50, 12, 1);
		set_state_continue(19);
	}
	else {
		inc_flag(50, 0, 1);
	}
	set_state_continue(10);
break;

// Place your own states below. Give each a number at least 10.
beginstate 10;
	// check if naked
	set_flag(100, 0, 0);
	i = 0;
	while (i < 4) {
		if (char_ok(i)) {
			if ((item_type_in_slot(i, 0) < 0) && (item_type_in_slot(i, 11) < 0)) {
				set_flag(100, 0, 1); // one or more 'naked'
				i = 4;
			}
		}
		i = i + 1;
	}
	set_state(START_STATE);
break;

beginstate 11;
	// goddesses vol 1 - page 1
	reset_dialog();
	add_dialog_str(0, "There is a large contingent of goddesses worshiped around the world and in the past, in Pergamos.", 0);
	add_dialog_str(1, "One group of the goddesses we can look at include these sixteen entities.", 0);
	add_dialog_str(2, "Note spelling of goddesses names is varied and these represent one spelling of many for some of the enclosed goddesses.", 0);
	add_dialog_str(3, "First we have Amenti or Lady at the Gates.  Then there is Ammit or Devourer of Souls.", 0);
	add_dialog_str(4, "Bast or Sacred Cat, Hathor or Cow Mother, then Isis or Lady of Life, the most well known of all.", 0);
	add_dialog_str(5, "Ma'at or Cosmic Balance, Neith or Lady Supreme, Nekhbet or Lady Vulture and Nephthys or Lady of the House are others.", 0);
	add_dialog_choice(0, "Next Page");
	add_dialog_choice(1, "Close");
	choice = run_dialog(1);
	if (choice == 1) {
		set_state_continue(17);
	}
break;

beginstate 12;
	// goddesses vol 2, page 1
	reset_dialog();
	add_dialog_str(0, "The goddesses have represented many things to the people of Pergamos.", 0);
	add_dialog_str(1, "In volume I, a list of the common goddesses worshiped in the past were listed.", 0);
	add_dialog_str(2, "A common legend of lore tells of selfless giving to the goddesses in order to get rewarded with an item to get ahead in life.", 0);
	add_dialog_str(3, "Perhaps this legend can be tested by giving at the museum of the statues.", 0);
	add_dialog_str(4, "If there is any truth to the legend, either the Mistress of Books or the Lady of Life would be giving the reward.", 0);
	add_dialog_choice(0, "Next Page");
	add_dialog_choice(1, "Close");
	choice = run_dialog(1);
	if (choice == 1) {
		set_state_continue(18);
	}
break;

beginstate 13;
	// the good book
	reset_dialog();
	add_dialog_str(0, "Book I, Chapter I.", 0);
	add_dialog_str(1, "There is only One, ignore all others.  Do not believe the hype of the goddesses.", 10);
	add_dialog_str(2, "Long life is yours if you live it well.  Do not worship false idols, now or ever.", 10);
	add_dialog_str(3, "Eternal life is yours if you live life well and pious.  This is the word of the True One.", 10);
	add_dialog_str(4, "Pious living includes being kind and empathetic to others.  Do this or suffer greatly later.", 10);
	add_dialog_str(5, "This theme seems to go on and on throughout the book.", 0);
	add_dialog_choice(0, "Close book");
	choice = run_dialog(1);
break;

beginstate 14;
	// reapers in the corn
	reset_dialog();
	add_dialog_str(0, "Chapter 1", 0);
	add_dialog_str(1, "He was alone in the middle of the corn field.  Not sure of why he was there, he just sat.  Some people reaping the corn came close to him.", 10);
	add_dialog_str(2, "They were reapers in the corn!  He moved a little so they wouldn't bother him.", 10);
	add_dialog_str(3, "He sat watching them for awhile wondering how long they had been reaping the corn.  Time passed and he got bored, so he stood up and moved out of the corn field.", 10);
	add_dialog_str(4, "Not sure of where he was going, he left the reapers in the corn and walked down the street.", 10);
	add_dialog_str(5, "You're not sure if you can gag down any more the the story.", 0);
	add_dialog_choice(0, "Close book");
	choice = run_dialog(1);
break;

beginstate 15;
	// losing it all
	reset_dialog();
	add_dialog_str(0, "Chapter 1 - Enjoy Life", 0);
	add_dialog_str(1, "Some people seem to feel that life is not worth living.  I say 'What!'  Life is worth living, even if you've lost it all.", 10);
	add_dialog_str(2, "When you've lost it all, you need to find the one thing that will allow you to continue on.  Get a dream, go west, settle, do something else.", 10);
	add_dialog_str(3, "You stop reading realizing the book contains 20 chapters of more of the same.", 0);
	add_dialog_str(4, "The author obviously figured out a way to get it back after losing it all in the past.", 0);
	add_dialog_str(5, "Judging by the price on the back, the author wasn't wasting any time in doing so.", 0);
	add_dialog_choice(0, "Close book");
	choice = run_dialog(1);
break;

beginstate 16;
	val = get_flag(50, 3);
	clear_buffer();
	append_string("Magic number is ");
	append_number(val);
	get_buffer_text(valline);
	reset_dialog();
	add_dialog_str(0, "You read the note given to you by Angus.", 0);
	add_dialog_str(1, "In shaky writing, the note reads:", 0);
	add_dialog_str(2, valline, 20);
	add_dialog_choice(0, "Ok");
	choice = run_dialog(1);
break;

beginstate 17;
	// goddesses vol 1 - page 2
	reset_dialog();
	add_dialog_str(0, "Nut or Celestial Mistress, Qetesh or Sacred Love and Sekhmet or Fierce Lioness are in this group.", 0);
	add_dialog_str(1, "Seshat or Mistress of Books, Taueret or Lady of Birth and Uadjet or Lady Cobra are the last in this group.", 0);
	add_dialog_str(2, "Each of this group was worshiped by people in Pergamos in the past.", 0);
	add_dialog_str(3, "Because of this, Pergamos has a museum with statues of the goddesses from times past.", 0);
	add_dialog_choice(0, "Previous Page");
	add_dialog_choice(1, "Close");
	choice = run_dialog(1);
	if (choice == 1) {
		set_state_continue(11);
	}
break;

beginstate 18;
	// goddesses vol 2, page 2
	set_flag(50, 5, 1);
	reset_dialog();
	add_dialog_str(0, "But perhaps the legend is not true after all or this author might have already been rewarded.", 0);
	add_dialog_str(1, "In the bottom of the page scrawled in pencil, a note reads:", 0);
	add_dialog_str(2, "Give (donate) 5 times and you will be rewarded!", 20);
	add_dialog_choice(0, "Previous Page");
	add_dialog_choice(1, "Close");
	choice = run_dialog(1);
	if (choice == 1) {
		set_state_continue(12);
	}
break;

beginstate 19;
	i = 0;
	while (i < 4) {
		if (char_ok(i) == TRUE) {
			e = get_energy(i);
			if (e > 0) {
				e = 0 - e;
				change_char_energy(i, e);
			}
		}
		i = i + 1;
	}
	if (get_flag(50, 12) > 0) {
		set_flag(50, 12, 0);
		set_state(START_STATE);
	}
break;
