
begintalkscript;

variables;
int revive;
string resurrect;

begintalknode 10;
	state = -1;
	nextstate = 10;
	question = "Martha";
	text1 = "Martha doesn't even turn to look at you, she's so focused on the portal.";
	text2 = "_Leave me to concentrate! Go, you know what to do!_";
	code = 
		if((get_flag(0,3) == 2) && (get_flag(10,0) == 0)) {
			message_dialog("Martha doesn't even turn to look at you, she's so focused on the portal.","_Leave me to concentrate! Go, stop Ethalia!_");
			end();
		}
		else if((get_flag(10,0) == 2) && (get_flag(0,3) < 3)) {
		message_dialog("Martha looks at you nervously, as if surveying a crash site. When she's satisfied that you're mostly in one piece, she speaks.","_Well, what happened?_");
	}
	else if((get_flag(10,0) == 4) && (get_flag(0,3) == 3)) {
	message_dialog("Martha looks much more stressed than before, as if she hasn't slept for days.","_Alright, what now?_");
}
else if((get_flag(10,0) == 6) && (get_flag(0,3) == 4)) {
message_dialog("Thankfully, Martha's still alive, she's just out cold. However, given that she was stabilizing the portal so that you could use it, this is probably a bad thing.","");
}
else
end();
	break;
begintalknode 11;
	state = 10;
	nextstate = 11;
	condition = (get_flag(10,0) == 2) && (get_flag(0,3) < 3);
	question = "It didn't go very well.";
	text1 = "You describe your encounter with Ethalia, and Martha winces.";
	text2 = "_Lovely. So she can't be reasoned with, and she knows how to banish you. It was a long shot, I'll admit, but we had to try it._";
	text3 = "_Luckily, the portal is holding together, and I don't think it will implode any time soon. Of course, if Ethalia begins propagating changes back down the timeline then who knows what will happen?_";

begintalknode 12;
	state = 11;
	nextstate = 12;
	question = "Well, then what now?";
	text1 = "Martha doesn't speak for a long time.";
	text2 = "_Then I guess the only thing to do is to make sure she does as little damage as possible. I think we might have to help her. The faster she gets it over with, the fewer changes she can make._";
	text3 = "_Of course, then what happens to us is a completely different matter. There's no way of knowing what will come from Ethalia's meddling._";

begintalknode 13;
	state = 12;
	nextstate = -1;
	question = "So what do we do?";
	text1 = "_Well... the demon. That's it! The demon! If you can destroy the demon, then Ethalia will arrive to find that... wait, but that assumes that she mis-times it. And then it still creates a paradox._";
	text2 = "_Or, or how about this? If you manage to destroy the demon before she can, then her younger self will surely try to summon it again. But Ethalia will find no demon when she returns, so she will come back to the present._";
	text3 = "_Maybe, just maybe, that will be a subtle enough change to prevent a wholesale collapse of the timeline. It's worth a shot, at least._";
	text4 = "Ethalia nods, satisfied with her own answer.";
	text5 = "_So that's it. Go back, and destroy the demon. I'll try to finesse your arrival, and I'll keep an eye on this end of the portal._";
	text6 = "With that, she goes back towards the portal.";
	action = END_TALK;
	code = 
		set_flag(0,3,3);
		set_flag(1,6,1);
		init_quest(0,"A Stitch in Time","Since negotiating with Ethalia worked so well, Martha has decided that it's better to head her off at the pass by killing the demon before Ethalia can stop... or something like that.");
		print_str_color("A quest has been updated.",3);
		relocate_character(8,20,14);
		set_character_facing(8,0);
		set_character_pose(8,1);
		force_instant_terrain_redraw();
	break;
begintalknode 14;
	state = 10;
	nextstate = 13;
	condition = (get_flag(10,0) == 4) && (get_flag(0,3) == 3);
	question = "Well... (Describe the fight)";
	text1 = "You describe your encounter with the demon, and Martha frowns.";
	text2 = "_Well, it was worth a shot. But damn, can everyone control time except me? And how did I miss the summoning by so much? This is ridiculous... but we have to keep trying._";
	text3 = "_Thankfully, the portal is still operational, and so am I. Mostly. This is exhausting, and I think I'm going to have to start employing some less draining techniques._";
	text4 = "She pulls a few flasks out of her robe, and hands them to you.";
	text5 = "_And of course, there's always a bit of good old-fashioned alchemy. Drink up, you'll need the energy for what comes next._";
	code = 
		if(get_flag(1,5) == 1) {
			remove_string(4);
			remove_string(5);
		}
		else {
		reward_give(223); //energy potion
		reward_give(223); //energy potion
		reward_give(220); //healing potion
		reward_give(220); //healing potion
		reward_give(220); //healing potion
		set_flag(1,5,1);
	}
	break;
begintalknode 15;
	state = 13;
	nextstate = 14;
	question = "So what happens next?";
	text1 = "Martha sighs.";
	text2 = "_Well, I feel like we were on the right track. If we can just get Ethalia's past self to avoid the demon while Ethalia is stalking the basement in the past..._";
	text3 = "She stops and straightens up, and for a moment she almost looks like she hasn't been channeling all of her energy into maintaining a massive existence-threatening portal created by an insane mage.";
	text4 = "_That's it! The solution isn't Ethalia, or even the demon. It's Ethalia in the past! If we can stop her from meeting the demon, or even just delaying it until future-her leaves, then future-her can't interfere and the paradox is resolved!_";

begintalknode 16;
	state = 14;
	nextstate = -1;
	question = "So... what needs to be done?";
	text1 = "_It's simple. Just go back through the portal, find Ethalia. Convince her not to meet the demon, or to delay it. Make it a day, a week, it doesn't matter. It ought to preserve everything._";
	text2 = "_Just like before, I'll be here making sure the portal doesn't erase existence. If I can't maintain the portal, I might pull you back. Just be ready._";
	text3 = "With that, she heads back toward the portal.";
	action = END_TALK;
	code = 
		set_flag(0,3,4);
		set_flag(1,6,1);
		init_quest(0,"A Stitch in Time","Martha has another plan. This time, you need to go back through the portal, negotiate with a younger version of Ethalia, and get her to delay or avoid the meeting with the demon.");
		print_str_color("A quest has been updated.",3);
		relocate_character(8,20,14);
		set_character_facing(8,0);
		set_character_pose(8,1);
		force_instant_terrain_redraw();
	break;
begintalknode 17;
	state = 10;
	nextstate = 15;
	condition = (get_flag(10,0) == 6) && (get_flag(0,3) == 4);
	question = "(Try to wake her)";
	text1 = "It takes a little while, but you manage to bring Martha around. Her eyes flutter open, and she looks around groggily. Then she remembers where she is, and she sits bolt upright.";
	text2 = "_I take it that... things did not go very well?_";
	text3 = "You can tell she's trying to cover how exhausted she is, and she's not doing a very good job of it.";

begintalknode 18;
	state = 15;
	nextstate = 16;
	question = "(Explain what happened)";
	text1 = "_Wait, you told her WHAT? What did you expect would happen? I should've just gone back myself!_";
	text2 = "_Well, knowing Ethalia, I guess I'm not surprised. Maybe you still bought us enough time._";
	text3 = "She stops to think.";
	text4 = "_Okay, okay... we can still do this. I have an idea. Another idea. A better idea._";
	text5 = "_Let's just crash the damn summoning and see what happens._";
	code = 
		if(get_flag(2,6) != 3)
			remove_string(1);
		else
		remove_string(2);
	break;
begintalknode 19;
	state = 16;
	nextstate = -1;
	question = "Are you sure that's a good idea?";
	text1 = "Martha snatches a pair of potions from her belt, and chugs them in one go. She looks a little less tired now.";
	text2 = "_Look at it this way. Have you got a better idea?_";
	text3 = "You stop to think for a while, but you don't have a better idea. This is all too confusing for you. You miss the days when adventurers just had to hit things until they stopped moving.";
	text4 = "_That's what I thought. I'll keep the portal stable for you, and with any luck it'll take you right to the moment where Ethalia summons the demon. Oh, and take this. The portal coughed it up a little while ago. Might come in handy._";
	text5 = "She hands you a thin wand, and starts chanting like before.";
	action = END_TALK;
	code = 
		set_flag(0,3,5);
		set_flag(1,6,1);
		init_quest(0,"A Stitch in Time","Finally, a plan you can understand. Martha wants you to jump back in the portal, and simply disrupt the summoning as you see fit. Which means you'll probably get to fight something or someone.");
		print_str_color("A quest has been updated.",3);
		relocate_character(8,20,14);
		set_character_facing(8,0);
		set_character_pose(8,1);
		force_instant_terrain_redraw();
		reward_give(447);
	break;
