"use strict";

function SDS_BuildEnding(name){
	var comp = [];
	if (DATA_SDS_ENDINGS[name]) comp=comp.concat(DATA_SDS_ENDINGS[name]);
	
	if (GLOBAL_DIARY.check(5,"MALFOSE_DEAD")){

		// ugly, but not worth rigging more state
		var meliLive = (
			name == "Second Chance" ||
			name == "Fresh Start" ||
			name == "A New Soul" ||
			name == "A New Goddess"
			);

		// Ravi
		comp=comp.concat(DATA_SDS_ENDINGS["BIG_BREAK"]);
		if (GLOBAL_DIARY.check(5,"RAVI_KILL")){
			comp = comp.concat(DATA_SDS_ENDINGS["Raviene_Dead"]);
		}
		else if (meliLive){
			comp = comp.concat(DATA_SDS_ENDINGS["Raviene_Meli"]);
		}
		else{
			comp = comp.concat(DATA_SDS_ENDINGS["Raviene_Solo"]);
		}

		// Sea Village
		comp=comp.concat(DATA_SDS_ENDINGS["BIG_BREAK"]);

		comp = comp.concat(DATA_SDS_ENDINGS["Charis"]);
		comp=comp.concat(DATA_SDS_ENDINGS["SMALL_BREAK"]);

		comp = comp.concat(DATA_SDS_ENDINGS["LelaErnest"]);
		comp=comp.concat(DATA_SDS_ENDINGS["SMALL_BREAK"]);

		comp = comp.concat(DATA_SDS_ENDINGS["FredNed"]);
		comp=comp.concat(DATA_SDS_ENDINGS["SMALL_BREAK"]);

		comp = comp.concat(DATA_SDS_ENDINGS["Vince"]);
		comp=comp.concat(DATA_SDS_ENDINGS["SMALL_BREAK"]);

		if (GLOBAL_DIARY.check(2,"BOSS_GOOD")){
			comp = comp.concat(DATA_SDS_ENDINGS["MelodyGrace"]);
		}
		else{
			comp = comp.concat(DATA_SDS_ENDINGS["MelodySolo"]);
		}
		comp=comp.concat(DATA_SDS_ENDINGS["SMALL_BREAK"]);

		if (meliLive){
			comp = comp.concat(DATA_SDS_ENDINGS["RindaMeli"]);
		}
		else{
			comp = comp.concat(DATA_SDS_ENDINGS["RindaSolo"]);
		}

		// Landtown
		comp=comp.concat(DATA_SDS_ENDINGS["BIG_BREAK"]);

		comp = comp.concat(DATA_SDS_ENDINGS["MustyFrog"]);

		// Monkeyville
		comp=comp.concat(DATA_SDS_ENDINGS["BIG_BREAK"]);

		comp = comp.concat(DATA_SDS_ENDINGS["Monkeys"]);
		comp=comp.concat(DATA_SDS_ENDINGS["SMALL_BREAK"]);

		comp = comp.concat(DATA_SDS_ENDINGS["Lief"]);
		comp=comp.concat(DATA_SDS_ENDINGS["SMALL_BREAK"]);

		comp = comp.concat(DATA_SDS_ENDINGS["Yorick"]);

		// Sky Shrine
		comp=comp.concat(DATA_SDS_ENDINGS["BIG_BREAK"]);

		if (GLOBAL_DIARY.check(5,"BOSS")){
			comp = comp.concat(DATA_SDS_ENDINGS["Gabe"]);
			comp=comp.concat(DATA_SDS_ENDINGS["SMALL_BREAK"]);
			comp = comp.concat(DATA_SDS_ENDINGS["ZekeGabe"]);
		}
		else{
			comp = comp.concat(DATA_SDS_ENDINGS["ZekeSolo"]);
		}

		// Goddess
		comp=comp.concat(DATA_SDS_ENDINGS["BIG_BREAK"]);

		comp = comp.concat(DATA_SDS_ENDINGS["Goddess"]);
	}

	comp=comp.concat(DATA_SDS_ENDINGS["BIG_BREAK"])
		.concat(DATA_SDS_ENDINGS["Credits"])
		.concat(DATA_SDS_ENDINGS["Fin"]);

	return comp;
}

var DATA_SDS_ENDINGS = {};

DATA_SDS_ENDINGS["Credits"]=
	[ 
		"",
		"",
		"",
		"",
		"All game content © Sean Kelly",
		"2013-2023",
		"",
		"Original game source code, narrative, art, and music is released under the terms of Creative Commons 4.0, Noncommercial use, Share-Alike, with Attribution.",
		"https://creativecommons.org/licenses",
		"/by-nc-sa/4.0/",
		"",
		"This does not preclude any future, packaged, closed-source commercial version of the game by the original author, but the original version shall remain free and open in perpetuity.",
		"",
		"",
		"",
		"",
		"Special thanks to Ryan, Chris, Cory, Erin, Savannah, Sarah, Blueglass, Prof (no relation), and anyone I may have missed who gave me direct or accidental feedback during development!",
		"",
		"Thanks also to TheRPGValkyries for having the faith that a completely new and unknown indie game would be interesting enough to show in a marathon.  I still can't believe you gave me the very second slot in the event! O.O;",
		"",
		"",
		"",
		"And, since it's sometimes hard to believe anyone will, as boilerplate as it sounds...",
		"",
		"Thank YOU for playing!",
		"~ GG ~",
		"",
		"",
		"",
	];
DATA_SDS_ENDINGS["Fin"]=
	[ 
		"",
		"",
		"",
		"",
		"THE END",
		"",
		"",
		"",
		"",
		"",
	];

//
// ENDING TOPLINES
//

// "bad" ending
DATA_SDS_ENDINGS["Only Human"]=
	[ 
		"And so her story reached its conclusion.",
		"",
		"Meli's body was entombed in the Goddess' own halls; her soul stilled in merciful oblivion until the end of time.  The goddess, devoid of hope, sublimated the last of her essence, returning it to the Children she loved but could no longer care for.",
		"",
		"Back out in the world, Meli was gradually forgotten- an orphan of turbulent times who had made a few fleeting and ultimately insubstantial friendships before moving on.  Surely she had accomplished her mission to return to the Goddess and secure peace, for had not a winged angel of death descended from the Sky Shrine into the earth to mete out punishment?  Had not everyone, the world over, felt touched by the Goddess, just briefly?",
		"",
		"Only the old Keepers spoke, abstractly, of a great loss, urging the people to keep the Goddess alive in their hearts and minds while gradually replacing calls to prayer with calls to reflection.  For how do you tell a congregation that the deity they worship is forever gone, sacrificed to their own over-reliant expectations?",
		"",
		"Time passed.",
		"The world turned.",
		"The children of land, sea, and sky drifted apart and forgot one another's existence outside of legend.",
		"Eventually, the Goddess herself was forgotten by all, her record in historic texts serving only as a lesson on outmoded and ineffectual belief systems.",
		"People came to accept that the madnesses of anger, mistrust, resentment, and despair were simply natural; that the voices in their heads urging them towards destructive retribution, or towards surrender to annihilation, were their own.",
		"However, they also came inevitably to appreciate that if there was to be a source of good, of concern, of support, or of acceptance in the world, it had to equally arise from their own nature and action.",
		"",
		"So perhaps this was, in the end, the correct path.",
	];

DATA_SDS_ENDINGS["Pacifism"]=[
		"And so, in the end, she stopped the fighting in the only way she knew would be certain: by ceasing to continue it.",
		"By depriving war of its antagonist, she granted it the most hollow of victories.",
		"By depriving Malfose of his servants, she bought the Goddess the chance to seal him away again, out of direct contact with humanity.",
		"",
		"But the act of renewing the seal cost the Goddess her life.",
		"",
		"Back out in the world, Meli was gradually forgotten- an orphan of turbulent times who had made a few fleeting and ultimately insubstantial friendships before moving on.  Surely she had accomplished her mission to return to the Goddess and secure peace, for had not a winged angel of death descended from the Sky Shrine into the earth to mete out punishment?  Had not everyone, the world over, felt touched by the Goddess, just briefly?",
		"",
		"Only the old Keepers spoke, abstractly, of a great loss, urging the people to keep the Goddess alive in their hearts and minds while gradually replacing calls to prayer with calls to reflection.  For how do you tell a congregation that the deity they worship is forever gone, sacrificed to their own over-reliant expectations?",
		"",
		"Time passed.",
		"The world turned.",
		"The children of land, sea, and sky drifted apart and forgot one another's existence outside of legend.",
		"Eventually, the Goddess herself was forgotten by all, her record in historic texts serving only as a lesson on outmoded and ineffectual belief systems.",
		"People came to accept that the madnesses of anger, mistrust, resentment, and despair were simply natural; that the voices in their heads urging them towards destructive retribution, or towards surrender to annihilation, were their own.",
		"However, they also came inevitably to appreciate that if there was to be a source of good, of concern, of support, or of acceptance in the world, it had to equally arise from their own nature and action.",
		"",
		"So perhaps this was, in the end, the correct path.",
];

// "normal" ending
DATA_SDS_ENDINGS["Finally Over"]=
	[ 
		"Meli's story ended, not with a tearful reunion, or parades, medals, high honors, or the like, but on a cold slab of stone, in the middle of the bay, one more mute testament to the cost of human avarice.",
		"Only her story lives on, and who can say that it hasn't grown in the telling?  Can it truly be believed that any ordinary mortal, subject to such circumstance and abuse, would have come so far or triumphed so significantly over an evil which was such a legitimate threat?",
		"Perhaps... or perhaps the value in the story is in how, for being passed on, it inspires others with a glimmer of hope that such things might be possible.",
		"Or, conversely, that not all good endings are happy endings, and that's ok.",
	];
// "normal" all tears
DATA_SDS_ENDINGS["Somewhere Out There"]=
	[ 
		"Many are grateful to get one life.",
		"Few get a second chance, or a third.",
		"But when each life is progressively more difficult?",
		"When each life ends more painfully than the last?",
		"Ultimately, Meli's spirit chose rest.  No accolades, no gratitude.  But, equally, no expectation to be the hero she never asked to be; no getting called upon to redress violence with violence, loss with loss.",
		"",
		"Her soul drifted in peace.",
		"",
		"Charis would go on to swear, so long as she lived, that she occasionally caught the faintest glimpse of a friendly face out of the corner of her eye, and few so much as touched the Goddess' treasures henceforth without experiencing a wave of deep melancholy.",
		"So perhaps something of Meli did continue to engage with this world.  Perhaps it still does...",
	];

// low% souls
DATA_SDS_ENDINGS["Second Chance"]=
	[ 
		"Deja vu, all over again.",
		"",
		"Fighting back her own anxiety, Meli allowed herself to fall back into the body waiting for her; into the life waiting for her.",
		"It was not going to be an easy life, perhaps, but for once, it was a life she chose.  A normal life.  A chance to play, and make friends; to learn, to grow up, and to grow old.",
		"",
		"And yet, the reputation of hero is a heavy weight, particularly to be borne by one who only relates to the experience as a distant memory; a past self acting under coercion and duress.  Soon enough, she retreated from the eyes of those who would claim more knowledge of her than she could of them, living as her own self, by her own will, and creating fresh stories with no right to be told here.",
		"However, Charis did, for a time, appear to return to her periodic wanderings, invariably returning with praise for the artistic progress of a new student she'd taken on; one whose works eventually made it to such vaunted walls as the private quarters of the Sky Palace, the sacred alcove of the Sea Shrine, and the back stairwell of the Musty Frog.",
		"",
		"And when, but a week before her passing, old Rinda was mysteriously joined by a younger assistant with her selfsame careworn joviality and mystique, and to whom, without compunction, she willed the post of keeper and all its entitlements, none of the village elders raised any objection.",
	];
// low% souls all tears
DATA_SDS_ENDINGS["Fresh Start"]=
	[ 
		"Deja vu, all over again.",
		"",
		"Fighting back her own anxiety, Meli allowed herself to fall back into the body waiting for her; into the life waiting for her.",
		"It was not going to be an easy life, perhaps, but for once, it was a life she chose.  A normal life.  A chance to play, and make friends; to learn, to grow up, and to grow old.",
		"",
		"And it would be HER story, this time.  Not the girl once drafted by fate into a war against evil, but the girl whose heart originally took her far from home, and into the arms of a friend who, even now, she could feel awakening at her side.",
		"Where would they go?  Back to the beach; back to the cabin; away on a ship; off together on a journey across sea, land, and sky?  Perhaps all of the above, or perhaps merely their separate ways.  Only the Goddess and the Creator would know for sure, but she wouldn't dare ask either of them to spoil the ending!",
	];

// "all" souls
DATA_SDS_ENDINGS["A New Soul"]=
	[ 
		"Meli was born anew; the same, and yet perhaps not.",
		"But one is not defined by what she is made of, or by the events beyond one's control which lead to one's existence in the present moment.",
		"Whatever had changed of her, outwardly or inwardly, she held fast to her continuity of \"self.\"  She had the body of the hero, and the memories of the hero.  Why should it matter if neither had been obtained \"normally\"?  If the people could believe in her, she would do her best to be worth believing in.",
		"Undoing generations of antagonism and frustration, need and desperation, would take time.  But, crucially, rather than the might of fist and tail she had employed in the battles of others, she could and would make her OWN legacy about generosity and compassion.",
	];
// "all" souls all tears
DATA_SDS_ENDINGS["A New Goddess"]=
	[ 
		"Taking her fate in both hands, Meli accepted herself back into the world, and yet still apart from it.  She would not presume to meet the Goddess as an equal, but neither would she be drawn into the drama of humanity as an equal player.  ",
		"",
		"She might retain a material presence, so long as her friends and believers lived.",
		"Where protection was needed, she would protect.",
		"Where destruction was needed, she would destroy.",
		"",
		"She would be there to mind the cycle, yes, and to do the unpopular work calling souls to death and seeing them to the boatman.",
		"She would equally be there- everywhere- for the multitude of small, unique, uniquely HUMAN needs that never seem worth bothering other humans about, let alone gods.  Needs for which humans, in their own self-directed blindness, suffer unnecessarily.",
		"",
		"But crucially, when the Goddess needed someone- ",
		"someone to believe in her, ",
		"someone to, herself, believe in, ",
		"someone simply to talk to, to talk WITH, as more than a mere stream of blind worship, desperate invocation, or destructive echo chamber, ",
		"Meli would be there.",
	];

//
// ENDING CONDITIONALS & SNIPPETS
//

DATA_SDS_ENDINGS["SMALL_BREAK"]=
	[
		"",
		"~",
		"",
	];

DATA_SDS_ENDINGS["BIG_BREAK"]=
	[
		"",
		"",
		"***",
		"",
		"",
	];

DATA_SDS_ENDINGS["Raviene_Meli"]=
	[
		"Raviene returned, briefly, to the Sky Palace before subjecting herself to an exile of atonement.  Her whereabouts at any given time have proven beyond the ability of any willing diviner to track (and willing diviners continue to become UN-willing within months of taking up the attempt).  Nonetheless, several pieces of credible correspondence from Meli indicate Raviene's visits to her are quite common, almost too much so to merit mention.  It has thus been posited that anyone who wishes to seek out Ravi should first seek out Meli.",
		"",
		"Practitioners of this approach have so far encountered one particularly immediate difficulty.",
		"",
		"Nonetheless, Raviene appears to be in reasonable spirits, having with some frequency submitted arcane but enlightening riddles with even more arcane seals to the newly-formed advanced holistic arcana departments of preeminent academies... provided said academies admit women as students AND instructors.",
		"One proudly patriarchal college did air a public complaint that such discoveries and their benefits deserved to be shared among ALL with sufficient skill to appreciate them.  Said college subsequently received exactly one missive and spent a full year attempting to decipher the first seal.",
	];
DATA_SDS_ENDINGS["Raviene_Solo"]=
	[
		"Raviene returned, briefly, to the Sky Palace before subjecting herself to an exile of atonement.  Rumors purportedly from those close to her would cite a manic focus on \"locating a lost soul,\" although associated rumormongers are hard-pressed to cite anyone with whom she might have been close enough to divulge such personal motives.",
		"",
		"It is at least commonly held, and with better justification, that she is the one behind a series of unsigned, heavily warded missives which have arrived at various scholarly institutions over the years, each one rewarding whoever is adept enough to break the seals with new and frequently controversial insight into the reconciliation of what have to date been considered opposed \"dark\" and \"light\" branches of magic.",
		"",
		"The seals themselves have been described as \"fiendishly complex and difficult\" by masters of the art, although the frequency with which enterprising students, disproportionately female, have opened them \"merely by chance application of relevant principles they thought to be self-evident\" may demand a different evaluation.  The direction of difference remains a point of heated debate.",
	];
DATA_SDS_ENDINGS["Raviene_Dead"]=
	[
		"Nothing more was ever heard of Raviene.  Her story ended as fairly as she could have hoped: a misguided and exacting mistress, consumed by mastery of her art, but whose contribution was no less critical to the fall of Malfose.  Her copious notes, while often relegated to the restricted archives of magical institutions, have become a focus for a new generation of scholars attempting to reconcile \"light\" and \"dark\" magical theory in the new era of holistic arcane study.",
	];

// big break

DATA_SDS_ENDINGS["Charis"]=
	[
		"Charis remained in the bay village, continuing to develop her painting skills with works often haunting... and occasionally haunted.",
	];

DATA_SDS_ENDINGS["LelaErnest"]=
	[
		"After finishing her version of Meli's story, Lela continued to document and conjecture upon Ernest's archaeological findings, and was more surprised than dismayed when they ultimately took him- and her- off across the world.  Coincidentally, her books became progressively smaller and lighter in her later years, while containing no less information.",
		"",
		"Libraries are now eagerly awaiting the publication of her third volume of shorthand keys.",
	];

DATA_SDS_ENDINGS["FredNed"]=
	[
		"Fred and Ned ultimately graduated out of perpetual bachelorhood and settled down into less physically demanding civil service jobs where their long-honed skillsets were even more highly valued.",
	];

DATA_SDS_ENDINGS["Vince"]=
	[
		"Vince was succeeded as seachild village mayor by his long-absent grown son.  Nobody much noticed the change in leadership, or if they did, they went on ignoring it anyway.",
	];

DATA_SDS_ENDINGS["MelodyGrace"]=
	[
		"Melody took over administration of all three shrines in the bay area from her room conveniently equidistant between them, often assisted by an ingeniously valved flask of wine gifted her by one passing sailor or another.",
		"",
		"Despite never truly outgrowing her incessant curiosity and fearlessness, Grace concluded her childhood with relatively few disfiguring reminders of ultimately ill-advised decisions.  While the appellation of \"keeper\" may be premature, she has taken up regular service of the Nautilus.  She briefly explored giving ghost tours of its ever-changing passages, but it turned out the ghosts had mostly heard all the stories already, and very few of them could pay for a ticket to begin with.",
	];
DATA_SDS_ENDINGS["MelodySolo"]=
	[
		"Melody surprised everyone by finally getting married.  Or at least, this is the general assumption, given that by the time of her second pregnancy, she had a ring, and subsequently, some landchild gentleman apparently remained on amicable terms despite having primary custody of their second child, Basie.",
		"She still can't bring herself to go back into the Nautilus, but frequently gets compliments from visitors on how well-maintained it is.  She doesn't remember hiring the two current caretakers- one blonde and one raven-haired from all accounts- but since the young ladies appear to be doing such a fine job, she's willing to write it off as one of the better decisions she made while drinking off the death of Grace.",
	];

DATA_SDS_ENDINGS["RindaSolo"]=
	[
		"Rinda remained a fixture in the village shrine until her death.  Her will clearly specified the epitaph \"Twice was enough.\" although nobody ventured any guess what that meant.",
	];
DATA_SDS_ENDINGS["RindaMeli"]=
	[
		"Rinda remained a fixture in the village shrine until her death.  Her will clearly specified the epitaph \"Twice was enough.\" although nobody ventured any guess what that meant.",
		"",
		"Her mossy-haired successor was, however, seen to smile wistfully at the sentiment when it was read.",
	];

// big break

DATA_SDS_ENDINGS["MustyFrog"]=
	[
		"With news of Malfose's fall, the cloud of superstition over the town of the landchildren lifted somewhat.  More ship traffic made the town more lively, and after one particularly profitable evening, Brill got up the courage to petition Gar for a family of their own.  Both proud parents now hope twins Joe and Eata will some day take over the family business, and ideally, the family humor.",
		"They've already picked out an enchanter to illuminate a new, flashy sign...",
	];

// big break

DATA_SDS_ENDINGS["Monkeys"]=
	[
		"Lolo took over as chief of the monkeys, but feels he might be getting boxed in.",
		"Coco did ultimately develop a sweet tooth.",
		"Momo is just peachy.",
		"Yoyo is up and down, but spends most of his time hanging out when he's not too wound up.",
		"Toto misses the rains back in Kansas.",
		"Nobody has seen Dodo in years.",
	];

DATA_SDS_ENDINGS["Lief"]=
	[
		"Lief continues to make like a tree, but the monkeys are starting to grow on him.",
		"He wonders if he isn't starting to get a bit sappy...",
	];

DATA_SDS_ENDINGS["Yorick"]=
	[
		"Yorick, it was discovered, willed his body to theater.",
		"The new Forest Shrine keeper, Lenore, seems a promising replacement.",
	];

// big break

DATA_SDS_ENDINGS["Gabe"]=
	[
		"Gabe simply reappeared one day, taking over pro-temp administration of the Sky Shrine until new keepers could be consecrated.  While nobody was surprised at his insistence on formality, the reasoning of \"because it's not like any decent person in off the street could take over this job, leastways not until I get this blasted sensor recalibrated\" did turn a few heads.",
		"When pressed for details, he only shrugs: \"Pops was right.  The Goddess is big and real and out there, and we don't get to know how she works.  But if the old stories contained everything we needed, why would she keep making new ones, hm?\"",
		"",
		"He still hopes to see Meli again someday.",
	];

DATA_SDS_ENDINGS["ZekeGabe"]=
	[
		"Zeke lived to the ripe old age of \"ain't as if I've been countin' lately, but damned if a doctor any younger'n me is gonna convince me to lay off the Frog's pork crisp 'n' dark chili chocolate cream pie! Now, pass me the coffee, will ya?\"",
		"",
		"That he passed away happily in his sleep was only half surprising.",
	];
DATA_SDS_ENDINGS["ZekeSolo"]=
	[
		"Zeke lived to the ripe old age of \"ain't as if I've been countin' lately, but damned if a doctor any younger'n me is gonna convince me to lay off the Frog's pork crisp 'n' dark chili chocolate cream pie! Now, pass me the coffee, will ya?\"",
		"",
		"That he passed away happily in his sleep was only half surprising.",
		"",
		"",
		"It remains unclear whether Zeke put the fear of the Goddess into the new young keepers of the Sky and Mountain shrines before his passing, or whether he has not actually ceased doing so to this day.",
	];

// big break

DATA_SDS_ENDINGS["Goddess"]=
	[
		"Time passed.",
		"The world turned.",
		"With the cycle restored, the Goddess gradually regained her power.",
		"And yet, the words with which Malfose had poisoned the peoples' hearts- and the Goddess'- were not easily erased.  To erase them from her children would be to remove their free will, to impose upon them a uniformity from which it would be in their nature to again rebel.  To erase them from herself... was impossible so long as she could not serve the needs of ALL her children impartially.",
		"But, for the first time in a great many generations, she had hope.",
		"She had seen her children face the evil among themselves and confront it.",
		"She had seen them overcome their fear of the powers she herself had feared to inflict upon them.",
		"And in so doing, she came to a peace within herself, as her whole self, that she had not felt since before the creation of Malfose.",
		"",
		"And her peace was the world's peace.",
	];


// You Have Chosen Poorly.
DATA_SDS_ENDINGS["She Lost"]=
	[ 
		"She Lost.",
	];