"use strict";

DATA_SDS_SCRIPTED_EVENTS["Gabe_circlet"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Gabe_circlet"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_advice_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_advice_0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.gabe = new GO_Gabe();
					cacheVars.gabe.sprite.x = (55<<4);
					cacheVars.gabe.sprite.y = (1<<4);
					cacheVars.gabe.direction = -1;
					//cacheVars.meli.sprite.map_room.addSprite(cacheVars.gabe.sprite);
					cacheVars.gabe.addToRoom(cacheVars.meli.sprite.map_room);
					cacheVars.objMgr.add(cacheVars.gabe);
				}
			},
			controls : {
				//"Raviene":{right:true},
				//"Meli":{A:true}
				"Gabe":{
					A:true,
					down:true,
					left:true
				}
			},
			customPost : noop
		};
evt[t+=24] = {
			customPre : function(cacheVars){
				
			},
			controls : {
				"Gabe":{
					A:true,
					down:true,
					left:false,
					right:true
				}
			},
			customPost : noop
		};
evt[t+=32] = {
			customPre : function(cacheVars){
				
			},
			controls : {
				"Gabe":{
					A:true,
					down:false,
					left:true,
					right:false
				}
			},
			customPost : noop
		};
evt[t+=16] = {
			customPre : function(cacheVars){
				
			},
			controls : {
				"Gabe":{
					A:false,
					left:false
				}
			},
			customPost : noop
		};
evt[t+=5] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe && cacheVars.meli){
					cacheVars.gabe.direction = (cacheVars.meli.sprite.x > cacheVars.gabe.sprite.x) ? 1 : -1;
					cacheVars.meli.direction = (cacheVars.gabe.sprite.x > cacheVars.meli.sprite.x) ? 1 : -1;
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_advice_1"+(GLOBAL_DIARY.check(4,"SLEEP")?"b":"")]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_advice_1"+(GLOBAL_DIARY.check(4,"SLEEP")?"b":""),function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping

							// TODO?: psych state based on retval
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Gabe_c5_advice_2"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_advice_2",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping

							if (retval==0) GLOBAL_DIARY.note(5,"DISLIKED_GABE");
							else if (retval==1) GLOBAL_DIARY.note(5,"LIKED_GABE");
							else GLOBAL_DIARY.note(5,"MET_GABE");
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Gabe_c5_advice_3"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_advice_3",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping

							// TODO?: psych state based on retval
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
// faux get-circlet
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["ReGet_Circlet"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("ReGet_Circlet",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}

				cacheVars.bgmName = SDS.bgmName;
				SDS.switchBgm("Found A Shiny Thing",false);

			},
			controls : {},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				GLOBAL_DIARY.hasCirclet=true;
				SDS.switchBgm(cacheVars.bgmName,true);
			}
		}
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Gabe_c5_advice_4"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_advice_4",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				
			},
			controls : {
				"Gabe":{
					A:true,
					right:true
				}
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : function(cacheVars){
				
			},
			controls : {
				"Gabe":{
					A:false
				}
			},
			customPost : noop
		};
evt[t+=3] = {
			customPre : function(cacheVars){
				
			},
			controls : {
				"Gabe":{
					A:true
				}
			},
			customPost : noop
		};
evt[t+=5] = {
			customPre : function(cacheVars){
				
			},
			controls : {
				"Gabe":{
					up:true
				}
			},
			customPost : noop
		};
evt[t+=10] = {
			customPre : function(cacheVars){
				
			},
			controls : {
				"Gabe":{
					right:false
				}
			},
			customPost : noop
		};
evt[t+=10] = {
			customPre : function(cacheVars){
				
			},
			controls : {
				"Gabe":{
					left:true
				}
			},
			customPost : noop
		};
evt[t+=60] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					//cacheVars.gabe.sprite.map_room.removeSprite(cacheVars.gabe.sprite);
					cacheVars.gabe.clearFromRoom(cacheVars.gabe.sprite.map_room);
					cacheVars.objMgr.remove(cacheVars.gabe);
				}

				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Zeke_reveal"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Zeke_reveal"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (DATA_SDS_DIALOGUE["Zeke_c5_metgabe_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Zeke_c5_metgabe_0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							cacheVars.dlgPath = ["A","B","C"][retval];
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Zeke_c5_metgabe_1"+cacheVars.dlgPath]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Zeke_c5_metgabe_1"+cacheVars.dlgPath,function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				GLOBAL_DIARY.hasCirclet=false;
				GLOBAL_DIARY.note(5,"MET_ZEKE");
				if (DATA_SDS_DIALOGUE["Zeke_c5_metgabe_2"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Zeke_c5_metgabe_2",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Zeke_c5_metgabe_3"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Zeke_c5_metgabe_3",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Zeke_c5_metgabe_4"+cacheVars.dlgPath]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Zeke_c5_metgabe_4"+cacheVars.dlgPath,function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Zeke_c5_metgabe_5"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Zeke_c5_metgabe_5",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Zeke":{
					A: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Zeke":{
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=6] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.pass = new GO_Passage(
						1<<4,
						1<<4,
						function(){return "mountainshrine_inside";},
						function(sprite){
							sprite.x = sprite.x;
							sprite.y = sprite.y;
							GLOBAL_SCRATCHPAD.note("flash",true);
							GLOBAL_SCRATCHPAD.persist("flash");
						});
					cacheVars.pass.spawnOnSprite(cacheVars.meli.sprite,cacheVars.meli.manager);	
				}

				SDS.bgmOverride = null;
			},
			controls : {},
			customPost : noop
		};

evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Mountainshrine_descent"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Mountainshrine_descent"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// this is a "cutscene" event; we want to lock down movement
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
			},
			controls : {
			},
			customPost : noop
		};

evt[t+=60] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {},
			customPost : noop
		};


DATA_SDS_SCRIPTED_EVENTS["ReReflect"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["ReReflect"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				if (DATA_SDS_DIALOGUE["Cat5_reset"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Cat5_reset",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							cacheVars.dlgPath = retval;
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.dlgPath){
					if (DATA_SDS_DIALOGUE["Cat5_resetNo"]){
						cacheVars.wait=true;
						cacheVars.dlgMgr.open("Cat5_resetNo",function(index,retval){
							if (retval!=null){
								cacheVars.wait=false; // yay js scoping
								//cacheVars.dlgPath = retval;
							}
						});
					}
				}
				else{
					if (DATA_SDS_DIALOGUE["Cat5_resetYes"]){
						cacheVars.wait=true;
						cacheVars.dlgMgr.open("Cat5_resetYes",function(index,retval){
							if (retval!=null){
								cacheVars.wait=false; // yay js scoping
								//cacheVars.dlgPath = retval;
							}
						});
					}
				}

				
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.dlgPath){
					//GLOBAL_SCRATCHPAD.note("Cat5q",1);
					GLOBAL_SCRATCHPAD.unpersist("Cat5q");

					//GLOBAL_SCRATCHPAD.note("Cat5mood",0);
					GLOBAL_SCRATCHPAD.unpersist("Cat5mood");

					// mildly embarassing to forget this.
					if (GLOBAL_DIARY.check(5,"MOOD_0",true)){
						GLOBAL_DIARY.clear(5,"MOOD_0");
						GLOBAL_DIARY.clear(5,"MOOD_1");
						GLOBAL_DIARY.clear(5,"MOOD_2");
						GLOBAL_DIARY.clear(5,"MOOD_3");
						GLOBAL_DIARY.clear(5,"MOOD_4");
						GLOBAL_DIARY.clear(5,"MOOD_5");
						GLOBAL_DIARY.clear(5,"MOOD_6");
						GLOBAL_DIARY.clear(5,"MOOD_7");
					}

					if (cacheVars.meli){
						cacheVars.pass = new GO_Passage(
							1<<4,
							1<<4,
							function(){
								return "mountainshrine_entry";
							},
							function(sprite){
								sprite.x = sprite.x;
								sprite.y = sprite.y;
								GLOBAL_SCRATCHPAD.note("flash",true);
								GLOBAL_SCRATCHPAD.persist("flash");

								SDS.screenFXColor = MOOD_TO_BURN["0"];
							});
						cacheVars.pass.spawnOnSprite(cacheVars.meli.sprite,cacheVars.meli.manager);	
					}
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Reflecting"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Reflecting"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				// just in case the trigger callback in
				// room mountainshrine_psi was somehow
				// not hit *coughdangheckingspeedrunnerscough*
				if (!GLOBAL_SCRATCHPAD.check("Cat5q")){
					GLOBAL_SCRATCHPAD.note("Cat5q",1);
					GLOBAL_SCRATCHPAD.persist("Cat5q");

					GLOBAL_SCRATCHPAD.note("Cat5mood",0);
					GLOBAL_SCRATCHPAD.persist("Cat5mood");
				}

				if (DATA_SDS_DIALOGUE["Cat5_c"+GLOBAL_SCRATCHPAD.check("Cat5q")]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Cat5_c"+GLOBAL_SCRATCHPAD.check("Cat5q"),function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							cacheVars.dlgPath = retval;
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Cat5_a"+GLOBAL_SCRATCHPAD.check("Cat5q")+cacheVars.dlgPath]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Cat5_a"+GLOBAL_SCRATCHPAD.check("Cat5q")+cacheVars.dlgPath,function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping

							GLOBAL_SCRATCHPAD.note("Cat5mood",GLOBAL_SCRATCHPAD.check("Cat5mood")+cacheVars.dlgPath-1);
							GLOBAL_SCRATCHPAD.note("Cat5q",GLOBAL_SCRATCHPAD.check("Cat5q")+1);

							if (MOOD_TO_BURN[GLOBAL_SCRATCHPAD.check("Cat5mood").toString()]){
								SDS.screenFXColor = MOOD_TO_BURN[GLOBAL_SCRATCHPAD.check("Cat5mood").toString()];
							}
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.pass = new GO_Passage(
						1<<4,
						1<<4,
						function(){
							if (typeof(cacheVars.dlgPath)=="number" && cacheVars.dlgPath>=0 && cacheVars.dlgPath<=2)
								return "mountainshrine_"+(["bmi","beq","bpl"][cacheVars.dlgPath]);
							return "mountainshrine_beq";
						},
						function(sprite){
							sprite.x = sprite.x;
							sprite.y = sprite.y;
							GLOBAL_SCRATCHPAD.note("flash",true);
							GLOBAL_SCRATCHPAD.persist("flash");
						});
					cacheVars.pass.spawnOnSprite(cacheVars.meli.sprite,cacheVars.meli.manager);	
				}

				SDS.bgmOverride = null;
			},
			controls : {},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Awareness"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Awareness"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				if (DATA_SDS_DIALOGUE["Cat5_q8"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Cat5_q8",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Cat5_c8"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Cat5_c8",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							cacheVars.dlgPath = retval;
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Cat5_a8"+cacheVars.dlgPath]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Cat5_a8"+cacheVars.dlgPath,function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Cat5_conclude"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Cat5_conclude",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping

							if (GLOBAL_SCRATCHPAD.check("Cat5mood")>=0){
								GLOBAL_DIARY.note(5,"MOOD_"+GLOBAL_SCRATCHPAD.check("Cat5mood"));
							}
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {},
			customPost : noop
		};


DATA_SDS_SCRIPTED_EVENTS["Goddess_C5_0"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Goddess_C5_0"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				if (DATA_SDS_DIALOGUE["Goddess_C5_Welcome"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Goddess_C5_Welcome",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if(GLOBAL_DIARY.check(5,"MOOD_0",true)){
					if (DATA_SDS_DIALOGUE["Goddess_C5_GoodContinue"]){
						cacheVars.wait=true;
						cacheVars.dlgMgr.open("Goddess_C5_GoodContinue",function(index,retval){
							if (retval!=null){
								cacheVars.wait=false; // yay js scoping
							}
						});
					}
				}
				else{
					if (DATA_SDS_DIALOGUE["Goddess_C5_BadEnd"]){
						cacheVars.wait=true;
						cacheVars.dlgMgr.open("Goddess_C5_BadEnd",function(index,retval){
							if (retval!=null){
								cacheVars.wait=false; // yay js scoping
								
								// END GAME
								SDS.ending = "Only Human";
								// t+=[end]
							}
						});
					}
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Goddess_C5_1"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Goddess_C5_1"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				if (DATA_SDS_DIALOGUE["Goddess_C5_Query"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Goddess_C5_Query",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							cacheVars.dlgPath = retval;
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){

				switch(cacheVars.dlgPath){
					case 0:
						if (DATA_SDS_DIALOGUE["Goddess_C5_Malfose"]){
							cacheVars.wait=true;
							cacheVars.dlgMgr.open("Goddess_C5_Malfose",function(index,retval){
								if (retval!=null){
									cacheVars.wait=false; // yay js scoping
									cacheVars.frameCounter+=3; // skip next step (go straight to end)
								}
							});
						}
					break;
					case 1:
						if (DATA_SDS_DIALOGUE["Goddess_C5_Treasures"]){
							cacheVars.wait=true;
							cacheVars.dlgMgr.open("Goddess_C5_Treasures",function(index,retval){
								if (retval!=null){
									cacheVars.wait=false; // yay js scoping
									cacheVars.frameCounter+=3; // skip next step (go straight to end)
								}
							});
						}
					break;
					case 2:
						if (DATA_SDS_DIALOGUE["Goddess_C5_Meli"]){
							cacheVars.wait=true;
							cacheVars.dlgMgr.open("Goddess_C5_Meli",function(index,retval){
								if (retval!=null){
									cacheVars.wait=false; // yay js scoping
									cacheVars.frameCounter+=3; // skip next step (go straight to end)
								}
							});
						}
					break;
					case 4:
						if (DATA_SDS_DIALOGUE["Goddess_C5_BadEnd"]){
							cacheVars.wait=true;
							cacheVars.dlgMgr.open("Goddess_C5_BadEnd",function(index,retval){
								if (retval!=null){
									cacheVars.wait=false; // yay js scoping
									
									// END GAME
									SDS.ending = "Only Human";

									cacheVars.frameCounter+=3; // skip next step (go straight to end)
								}
							});
						}
					break;
					default://case 3:
						if (DATA_SDS_DIALOGUE["Goddess_C5_Help"]){
							cacheVars.wait=true;
							cacheVars.dlgMgr.open("Goddess_C5_Help",function(index,retval){
								if (retval!=null){
									cacheVars.wait=false; // yay js scoping
									// flow normally to next step
								}
							});
						}
					break;
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Get_Blessing"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Get_Blessing",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping

							GLOBAL_DIARY.note(5,"BLESSING");
							GLOBAL_DIARY.hasBracelets=true;
							GLOBAL_DIARY.hasCollar=true;
							GLOBAL_DIARY.hasBelt=true;
							GLOBAL_DIARY.hasCirclet=true;
							GLOBAL_DIARY.hasBlessing=true;
							// and we want to trigger a dark chi charge
							// so players notice (and be sure Gabe can't be
							// cheesed with normal waves if the blue bar is
							// somehow more than cosmetic)
							GLOBAL_DIARY.subchi = GLOBAL_DIARY.chi = 1;
						}
					});
				}

				cacheVars.bgmName = SDS.bgmName;
				SDS.switchBgm("Found A Shiny Thing",false);
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Goddess_C5_Farewell"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Goddess_C5_Farewell",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
				SDS.switchBgm(cacheVars.bgmName,true);
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.pass = new GO_Passage(
						1<<4,
						1<<4,
						function(){return "mountainshrine_sanctuary";},
						function(sprite){
							sprite.x = sprite.x;
							sprite.y = sprite.y;
							GLOBAL_SCRATCHPAD.note("flash",true);
							GLOBAL_SCRATCHPAD.persist("flash");
						});
					cacheVars.pass.spawnOnSprite(cacheVars.meli.sprite,cacheVars.meli.manager);	
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {},
			customPost : noop
		};


DATA_SDS_SCRIPTED_EVENTS["Gabe_bossfight"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Gabe_bossfight"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.ravi = cacheVars.objMgr.getNamedObject("Raviene");
				cacheVars.gabe = cacheVars.objMgr.getNamedObject("BossGabe");
				cacheVars.wind = cacheVars.objMgr.getNamedObject("Wind");
				if (cacheVars.meli){
					// this is a multi-dialog event AND we'll be puppeting Meli; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.gabe){
					// turn off ability to be hit, since we'll be spawning a lot of smoke
					cacheVars.gabe.sprite.collision_flags &= ~DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_PASSIVE;
				}
				if (cacheVars.wind){
					cacheVars.wind.active = false;
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
				SDS.switchBgm("A-minor Waltz in 4",true);
			},
			controls : {
				"Raviene" : {
					A: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Meli" : {
					left: true,
					A: true,
				}
			},
			customPost : noop
		};
evt[t+=6] = {
			customPre : noop,
			controls : {
				"Meli" : {
					left: true,
					A: false,
				}
			},
			customPost : noop
		};
evt[t+=6] = {
			customPre : noop,
			controls : {
				"Meli" : {
					left: false,
				}
			},
			customPost : noop
		};
evt[t+=10] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.frame = 69;
				}
				// this is a timed dialog so Ravi can cut in
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_1"]){
					//cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_1",function(index,retval){
						//if (retval!=null){
						//	cacheVars.wait=false; // yay js scoping
						//}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[t+=80] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.frame = 69;
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_2"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_2",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Gabe_c5_boss_3");
evt[++t] = DlgEvent("Gabe_c5_boss_4");
evt[++t] = DlgEvent("Gabe_c5_boss_5");
evt[++t] = DlgEvent("Gabe_c5_boss_6");
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					right: true,
					down: true,
				}
			},
			customPost : noop
		};
evt[t+=24] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.frame = 6;
				}
			},
			controls : {
				"Raviene" : {
					down: false,
				}
			},
			customPost : noop
		};
evt[t+=8] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.frame = 4;
				}
			},
			controls : {
				"Raviene" : {
					right: false,
				}
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Gabe_c5_boss_7");;
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					up: true,
					left: true,
				}
			},
			customPost : noop
		};
evt[t+=24] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.frame = 68;
				}
			},
			controls : {
				"Raviene" : {
					up: false,
					left: false,
					right: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					right: false,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_8"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_8",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				cacheVars.vent1 = new GO_SmokeVent();
				cacheVars.vent1.sprite.x = (83<<4);
				cacheVars.vent1.sprite.y = (11<<4);
				cacheVars.meli.sprite.map_room.addSprite(cacheVars.vent1.sprite);
				cacheVars.objMgr.add(cacheVars.vent1);
			},
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[t+=10] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_9"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_9",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				cacheVars.vent2 = new GO_SmokeVent();
				cacheVars.vent2.sprite.x = (81<<4);
				cacheVars.vent2.sprite.y = (11<<4);
				cacheVars.meli.sprite.map_room.addSprite(cacheVars.vent2.sprite);
				cacheVars.objMgr.add(cacheVars.vent2);
			},
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[t+=10] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_10"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_10",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				cacheVars.vent3 = new GO_SmokeVent();
				cacheVars.vent3.sprite.x = (82<<4);
				cacheVars.vent3.sprite.y = (11<<4);
				cacheVars.meli.sprite.map_room.addSprite(cacheVars.vent3.sprite);
				cacheVars.objMgr.add(cacheVars.vent3);
			},
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[t+=10] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.frame = 69;
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_11"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_11",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					right: true,
				}
			},
			customPost : noop
		};
evt[t+=5] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					down: true,
				}
			},
			customPost : noop
		};
evt[t+=5] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					right: false,
				}
			},
			customPost : noop
		};
evt[t+=5] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					left: true,
				}
			},
			customPost : noop
		};
evt[t+=5] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					down: false,
				}
			},
			customPost : noop
		};
evt[t+=5] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					up: true,
				}
			},
			customPost : noop
		};
evt[t+=60] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					//cacheVars.ravi.sprite.map_room.removeSprite(cacheVars.ravi.sprite);
					cacheVars.ravi.clearFromRoom(cacheVars.ravi.sprite.map_room);
					cacheVars.objMgr.remove(cacheVars.ravi);
					cacheVars.ravi = null;
				}

				SDS.switchBgm("",false);

				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_12"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_12",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.frame = 5;
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_13"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_13",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"BossGabe":{
					down: true,
				}
			},
			customPost : noop
		};
for (var l=1; l<10; ++l){
	evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.visible=false;
					cacheVars.gabe.sprite.visible=true;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
	evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.visible=true;
					cacheVars.gabe.sprite.visible=false;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
}
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.visible=false;
					cacheVars.gabe.sprite.visible=true;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[t+=10] = DlgEvent("Gabe_c5_boss_14");;
evt[t+=10] = {
			customPre : function(cacheVars){
				cacheVars.vent1.clearFromRoom(cacheVars.vent1.sprite.map_room);
				cacheVars.objMgr.remove(cacheVars.vent1);
				cacheVars.vent1 = null;
				cacheVars.vent2.clearFromRoom(cacheVars.vent2.sprite.map_room);
				cacheVars.objMgr.remove(cacheVars.vent2);
				cacheVars.vent2 = null;
				cacheVars.vent3.clearFromRoom(cacheVars.vent3.sprite.map_room);
				cacheVars.objMgr.remove(cacheVars.vent3);
				cacheVars.vent3 = null;

				SDS.switchBgm("Rumble",true); // at least until we have, say, Malfose caves II done

				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_15"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_15",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"BossGabe":{
					down: false,
					B: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.zeke = new GO_Zeke();
					cacheVars.zeke.sprite.x = (87<<4);
					cacheVars.zeke.sprite.y = (10<<4);
					cacheVars.zeke.direction = -1;
					cacheVars.zeke.spell = 1; // hardcode fakeblocks
					cacheVars.meli.sprite.map_room.addSprite(cacheVars.zeke.sprite);
					cacheVars.objMgr.add(cacheVars.zeke);

					SDS.switchBgm("Og Sananab!",true);

					// doing this in controls would be an extra frame
					cacheVars.meli.direction = 1;
				}
			},
			controls : {
				"BossGabe":{
					B: false,
				},
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Zeke" : {
					A: true,
				}
			},
			customPost : noop
		};
evt[t+=5] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_16"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_16",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Zeke" : {
					A: false,
				}
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Gabe_c5_boss_17");
evt[++t] = DlgEvent("Gabe_c5_boss_18");
evt[++t] = {
			customPre : noop,
			controls : {
				"Zeke" : {
					A: true,
				}
			},
			customPost : noop
		};
evt[t+=20] = {
			customPre : noop,
			controls : {
				"Zeke" : {
					A: false,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Zeke" : {
					A: true,
				}
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Gabe_c5_boss_19");
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_20"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_20",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Zeke" : {
					A: false,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Zeke" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=32] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					// plan A was for a fancy animated fill
					// but since this is offscreen, just add them all at once.
					// Whoever does the HD remake can hammer out the cache
					// to add 1 block per event tick.
					for (cacheVars.i=0; cacheVars.i<44; ++cacheVars.i){
						cacheVars.block = new GO_HolyBlock(1,1);
						cacheVars.block.sprite.x = ((63+cacheVars.i)<<4);
						cacheVars.block.sprite.y = (19<<4);
						cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
						cacheVars.objMgr.add(cacheVars.block);
					}
					for (cacheVars.i=0; cacheVars.i<15; ++cacheVars.i){
						cacheVars.block = new GO_HolyBlock(1,1);
						cacheVars.block.sprite.x = (62<<4);
						cacheVars.block.sprite.y = ((1+cacheVars.i)<<4);
						cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
						cacheVars.objMgr.add(cacheVars.block);
					}
					for (cacheVars.i=0; cacheVars.i<15; ++cacheVars.i){
						cacheVars.block = new GO_HolyBlock(1,1);
						cacheVars.block.sprite.x = (107<<4);
						cacheVars.block.sprite.y = ((1+cacheVars.i)<<4);
						cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
						cacheVars.objMgr.add(cacheVars.block);
					}
					cacheVars.block = null;
				}
			},
			controls : {
				"Zeke" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[t+=30] = {
			customPre : function(cacheVars){
				cacheVars.zeke.direction=1;

				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_21"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_21",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : function(cacheVars){
				cacheVars.zeke.clearFromRoom(cacheVars.zeke.sprite.map_room);
				cacheVars.objMgr.remove(cacheVars.zeke);
				cacheVars.zeke = null;

				SDS.switchBgm("",false);
			},
			controls : {
				
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : function(cacheVars){
				// should only be one of these on the screen
				cacheVars.door = cacheVars.objMgr.getNamedObject("Door");
				if (cacheVars.door){
					cacheVars.door.unlocked = false;
					cacheVars.door.playSound("FX_switchoff");
					cacheVars.door = null;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.direction = -1;
				}

				if (DATA_SDS_DIALOGUE["Gabe_c5_boss_22"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_boss_22",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.sprite.collision_flags |= DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_PASSIVE;
					cacheVars.gabe.startFight();
				}

				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				// restore wind
				if (cacheVars.wind){
					cacheVars.wind.active = true;
				}
				SDS.switchBgm("Rumble",true);
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Gabe_bossfight_quick"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Gabe_bossfight_quick"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.gabe = cacheVars.objMgr.getNamedObject("BossGabe");
				cacheVars.door = cacheVars.objMgr.getNamedObject("Door");
				if (cacheVars.meli){
					for (cacheVars.i=0; cacheVars.i<44; ++cacheVars.i){
						cacheVars.block = new GO_HolyBlock(1,1);
						cacheVars.block.sprite.x = ((63+cacheVars.i)<<4);
						cacheVars.block.sprite.y = (19<<4);
						cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
						cacheVars.objMgr.add(cacheVars.block);
					}
					for (cacheVars.i=0; cacheVars.i<15; ++cacheVars.i){
						cacheVars.block = new GO_HolyBlock(1,1);
						cacheVars.block.sprite.x = (62<<4);
						cacheVars.block.sprite.y = ((1+cacheVars.i)<<4);
						cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
						cacheVars.objMgr.add(cacheVars.block);
					}
					for (cacheVars.i=0; cacheVars.i<15; ++cacheVars.i){
						cacheVars.block = new GO_HolyBlock(1,1);
						cacheVars.block.sprite.x = (107<<4);
						cacheVars.block.sprite.y = ((1+cacheVars.i)<<4);
						cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
						cacheVars.objMgr.add(cacheVars.block);
					}
					cacheVars.block = null;
				}
				if (cacheVars.door){
					cacheVars.door.unlocked = false;
					cacheVars.door.playSound("FX_switchoff");
					cacheVars.door = null;
				}
				if (cacheVars.gabe){
					cacheVars.gabe.chibiSprite.visible = false;
					cacheVars.gabe.sprite.visible = true;
					cacheVars.gabe.sprite.collision_flags |= DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_PASSIVE;
					cacheVars.gabe.startFight();
				}
				SDS.switchBgm("Rumble",true);
			},
			controls : {
				
			},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Gabe_endfight_bad"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Gabe_endfight_bad"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.gabe = cacheVars.objMgr.getNamedObject("BossGabe");
				cacheVars.wind = cacheVars.objMgr.getNamedObject("Wind");
				if (cacheVars.meli){
					// this is a multi-dialog event AND we'll be puppeting Meli; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.wind){
					cacheVars.wind.active = false;
				}
				if (cacheVars.gabe){
					cacheVars.gabe.spell = cacheVars.gabe.SPELLS.LIGHT;
					cacheVars.gabe.spell_target = null;
					cacheVars.gabe.spell_target_name = "BossGabe";
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_bossdeath_s0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_bossdeath_s0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Gabe_c5_bossdeath_s1b");
evt[++t] = {
			customPre : noop,
			controls : {
				"BossGabe" : {
					down: false,
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=90] = {
			customPre : noop,
			controls : {
				"BossGabe" : {
					B: false,
				}
			},
			customPost : noop
		};
for (var l=1; l<30; ++l){
	evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.sprite.visible=!cacheVars.gabe.sprite.visible;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
}
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.clearFromRoom(cacheVars.gabe.sprite.map_room);
					cacheVars.objMgr.remove(cacheVars.gabe);
					cacheVars.gabe = null;
				}
				
			},
			controls : {},
			customPost : noop
		};

evt[t+=15] = {
			customPre : function(cacheVars){
				cacheVars.door = cacheVars.objMgr.getNamedObject("Door");
				if (cacheVars.door){
					cacheVars.door.unlocked = true;
					cacheVars.door.playSound("FX_switchon");
					cacheVars.door = null;
				}

				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				// restore wind
				if (cacheVars.wind){
					cacheVars.wind.active = true;
				}

				GLOBAL_DIARY.note(5,"BOSS");
				GLOBAL_SCRATCHPAD.note("CH5_INTERMISSION_READY",true);
				GLOBAL_SCRATCHPAD.persist("CH5_INTERMISSION_READY");
				
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Gabe_endfight_good"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Gabe_endfight_good"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				GLOBAL_DIARY.note(5,"BOSS"); // up top so soul doesn't trigger a sequence break flag
				GLOBAL_SCRATCHPAD.note("CH5_INTERMISSION_READY",true);
				GLOBAL_SCRATCHPAD.persist("CH5_INTERMISSION_READY");

				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.gabe = cacheVars.objMgr.getNamedObject("BossGabe");
				cacheVars.wind = cacheVars.objMgr.getNamedObject("Wind");
				if (cacheVars.meli){
					// this is a multi-dialog event AND we'll be puppeting Meli; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.wind){
					cacheVars.wind.active = false;
				}
				if (cacheVars.gabe){
					cacheVars.gabe.spell = cacheVars.gabe.SPELLS.LIGHT;
					cacheVars.gabe.spell_target = null;
					cacheVars.gabe.spell_target_name = "BossGabe";
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_bossdeath_s0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_bossdeath_s0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Gabe_c5_bossdeath_s1g");
evt[++t] = {
			customPre : function(cacheVars){
				if (GLOBAL_DIARY.souls.length===0 || (GLOBAL_DIARY.souls.length===1 && GLOBAL_DIARY.hasSoul("MELI"))){
					cacheVars.path="l";
				}
				else{
					cacheVars.path="h";
				}

				if (DATA_SDS_DIALOGUE["Gabe_c5_bossdeath_s2g"+cacheVars.path]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_bossdeath_s2g"+cacheVars.path,function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							// if on low%, you have a choice, otherwise skip to get soul
							if (cacheVars.path==="h"){
								cacheVars.frameCounter += 1;
							}
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Gabe_c5_bossdeath_s3gl"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_bossdeath_s3gl",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping

							// choose to NOT take the soul and we just end
							if (retval==0){
								cacheVars.frameCounter += 130; // a bit fudgy, precise count is 123-137
							}
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"BossGabe" : {
					down: false,
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=90] = {
			customPre : noop,
			controls : {
				"BossGabe" : {
					B: false,
				}
			},
			customPost : noop
		};
for (var l=0; l<30; ++l){
	evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.sprite.visible=!cacheVars.gabe.sprite.visible;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
}
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.clearFromRoom(cacheVars.gabe.sprite.map_room);
					cacheVars.objMgr.remove(cacheVars.gabe);
					cacheVars.gabe = null;
				}

				if (cacheVars.meli){
					cacheVars.soul = new GO_Soul("GABE");
					cacheVars.soul.spawnOnSprite(cacheVars.meli.sprite,cacheVars.objMgr,0,0);
					cacheVars.soul = null;
				}
				
			},
			controls : {},
			customPost : noop
		};
evt[++t] = DlgEvent("Gabe_c5_bossdeath_s4g");

evt[t+=15] = {
			customPre : function(cacheVars){
				cacheVars.door = cacheVars.objMgr.getNamedObject("Door");
				if (cacheVars.door){
					cacheVars.door.unlocked = true;
					cacheVars.door.playSound("FX_switchon");
					cacheVars.door = null;
				}

				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				// restore wind
				if (cacheVars.wind){
					cacheVars.wind.active = true;
				}
				
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Gabe_endfight_good2"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Gabe_endfight_good2"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.gabe = cacheVars.objMgr.getNamedObject("BossGabe");
				cacheVars.wind = cacheVars.objMgr.getNamedObject("Wind");
				if (cacheVars.meli){
					// this is a multi-dialog event AND we'll be puppeting Meli; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.wind){
					cacheVars.wind.active = false;
				}
				if (cacheVars.gabe){
					cacheVars.gabe.spell = cacheVars.gabe.SPELLS.LIGHT;
					cacheVars.gabe.spell_target = null;
					cacheVars.gabe.spell_target_name = "BossGabe";
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_bossdeath_s3gl"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_bossdeath_s3gl",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping

							// choose to NOT take the soul and we just end
							if (retval==0){
								cacheVars.frameCounter += 130; // a bit fudgy, precise count is 123-137
							}
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"BossGabe" : {
					down: false,
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=90] = {
			customPre : noop,
			controls : {
				"BossGabe" : {
					B: false,
				}
			},
			customPost : noop
		};
for (var l=0; l<30; ++l){
	evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.sprite.visible=!cacheVars.gabe.sprite.visible;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
}
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.gabe.clearFromRoom(cacheVars.gabe.sprite.map_room);
					cacheVars.objMgr.remove(cacheVars.gabe);
					cacheVars.gabe = null;
				}

				if (cacheVars.meli){
					cacheVars.soul = new GO_Soul("GABE");
					cacheVars.soul.spawnOnSprite(cacheVars.meli.sprite,cacheVars.objMgr,0,0);
					cacheVars.soul = null;
				}
				
			},
			controls : {},
			customPost : noop
		};
evt[++t] = DlgEvent("Gabe_c5_bossdeath_s4gl");

evt[t+=15] = {
			customPre : function(cacheVars){
				cacheVars.door = cacheVars.objMgr.getNamedObject("Door");
				if (cacheVars.door){
					cacheVars.door.unlocked = true;
					cacheVars.door.playSound("FX_switchon");
					cacheVars.door = null;
				}

				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				// restore wind
				if (cacheVars.wind){
					cacheVars.wind.active = true;
				}
				
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Gabe_death"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Gabe_death"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.gabe = cacheVars.objMgr.getNamedObject("BossGabe");
				cacheVars.wind = cacheVars.objMgr.getNamedObject("Wind");
				if (cacheVars.meli){
					// this is a multi-dialog event AND we'll be puppeting Meli; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.wind){
					cacheVars.wind.active = false;
				}
				if (cacheVars.gabe){
					cacheVars.gabe.spell = cacheVars.gabe.SPELLS.DARK;
					cacheVars.gabe.spell_target = null;
					cacheVars.gabe.spell_target_name = "BossGabe";
				}
				if (DATA_SDS_DIALOGUE["Gabe_c5_bossdeath_k0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Gabe_c5_bossdeath_k0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"BossGabe" : {
					down: false,
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=90] = {
			customPre : noop,
			controls : {
				"BossGabe" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.gabe){
					cacheVars.poof = new GO_Poof();
					cacheVars.poof.spawnOnSprite(cacheVars.gabe.sprite,cacheVars.objMgr,0,0);
					cacheVars.poof = null;

					cacheVars.gabe.clearFromRoom(cacheVars.gabe.sprite.map_room);
					cacheVars.objMgr.remove(cacheVars.gabe);
					cacheVars.gabe = null;
				}
				
			},
			controls : {},
			customPost : noop
		};
evt[++t] = DlgEvent("Gabe_c5_bossdeath_k1");

evt[t+=15] = {
			customPre : function(cacheVars){
				cacheVars.door = cacheVars.objMgr.getNamedObject("Door");
				if (cacheVars.door){
					cacheVars.door.unlocked = true;
					cacheVars.door.playSound("FX_switchon");
					cacheVars.door = null;
				}

				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				// restore wind
				if (cacheVars.wind){
					cacheVars.wind.active = true;
				}

				GLOBAL_DIARY.note(5,"BOSS_KILL");
				GLOBAL_SCRATCHPAD.note("CH5_INTERMISSION_READY",true);
				GLOBAL_SCRATCHPAD.persist("CH5_INTERMISSION_READY");
				
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Get_Sealkey"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Get_Sealkey"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Get_Sealkey"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Get_Sealkey",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}

			},
			controls : {},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				// would ideally know which key we just got,
				// but that would mean duping the event N times.
				// So instead, loop through all possible keys
				// and check for walls for any that we have.
				for (cacheVars.i=0; cacheVars.i<6; ++cacheVars.i){
					if (GLOBAL_DIARY.check(5,"SEALKEY_"+cacheVars.i)){
						cacheVars.wall = cacheVars.objMgr.getNamedObject("Sealwall_"+cacheVars.i);
						if (cacheVars.wall) cacheVars.wall.Destruct();
					}
				}
			}
		}

DATA_SDS_SCRIPTED_EVENTS["Raviene_unseal"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Raviene_unseal"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.ravi = cacheVars.objMgr.getNamedObject("Raviene");
				if (cacheVars.meli){
					// this is a multi-dialog event AND we'll be puppeting Meli; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.ravi){
					cacheVars.ravi.spell = cacheVars.ravi.SPELLS.SMOKE;
				}
				SDS.switchBgm("A-minor Waltz in 4",true);
				if (DATA_SDS_DIALOGUE["Raviene_c5_unseal_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Raviene_c5_unseal_0",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping

							// choose to NOT take the soul and we just end
							//if (retval==0){
							//	cacheVars.frameCounter += 130; // a bit fudgy, precise count is 123-137
							//}
						}
					});
				}
			},
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				cacheVars.wall = cacheVars.objMgr.getNamedObject("Beamwall");
				if (cacheVars.wall){
					cacheVars.sparkle = new GO_Sparkle(10,-5,-5);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(10,5,-5);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(10,5,5);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(10,-5,5);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);

					cacheVars.sparkle = new GO_Sparkle(10,-7,0);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(10,0,-7);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(10,7,0);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(10,0,7);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = null;
				}
			},
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[t+=30] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Raviene_c5_unseal_1"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Raviene_c5_unseal_1",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
				
			},
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.wall){
					cacheVars.sparkle = new GO_Sparkle(20,-5,-5);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(20,5,-5);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(20,5,5);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(20,-5,5);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);

					cacheVars.sparkle = new GO_Sparkle(20,-7,0);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(20,0,-7);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(20,7,0);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = new GO_Sparkle(20,0,7);
					cacheVars.sparkle.spawnOnSprite(cacheVars.wall.wall,cacheVars.objMgr);
					cacheVars.sparkle = null;
				}
			},
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[t+=30] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.spell = cacheVars.ravi.SPELLS.LIGHTNING;
				}
				if (DATA_SDS_DIALOGUE["Raviene_c5_unseal_2"]){
					// gonna get a bit triksy here.
					// Dialogue has timed delivery;
					// we want to sync with action;
					// this means we can't just set wait,
					// but we need flags enough to determine later
					// if we should wait.

					//cacheVars.wait=true;
					cacheVars.dlgDone = false;
					cacheVars.dlgMgr.open("Raviene_c5_unseal_2",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping
							cacheVars.dlgDone = true;
						}
					});
				}
			},
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[t+=15] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=30] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : function(cacheVars){
				// and here we re-sync- wait so long as dialogue hasn't already concluded.
				// when it concludes, it will clear wait, otherwise we don't even set it
				if (!cacheVars.dlgDone) cacheVars.wait=true;
			}
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_3");
evt[t] = {
			customPre : function(cacheVars){
				// must have been nice to Ravi at least once
				// AND seen her diary & journal (diary is literally journal-locked)
				// in order to get the salvation option
				//cacheVars.rep = 0;
				//if (GLOBAL_DIARY.check(4,"RAVIENE_EMPATH")) ++cacheVars.rep;
				//if (GLOBAL_DIARY.check(4,"RAVIENE_NEMESIS")) --cacheVars.rep;
				//if (GLOBAL_DIARY.check(4,"NOTREASURE_EMPATH")) ++cacheVars.rep;
				//if (GLOBAL_DIARY.check(4,"NOTREASURE_NEMESIS")) --cacheVars.rep;
				//cacheVars.good = GLOBAL_DIARY.check(4,"RAVI_DIARY") && (cacheVars.rep>=0);

				// for more consistency, just use the validity checker
				// for RAVI_SAVE
				cacheVars.good = DEFINE_DIARY_EVENTS.CHAPTER5.RAVI_SAVE.requisites(GLOBAL_DIARY);


				if (DATA_SDS_DIALOGUE["Raviene_c5_unseal_4"+(cacheVars.good?"g":"b")]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Raviene_c5_unseal_4"+(cacheVars.good?"g":"b"),function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping

							// taunt and we proceed to combat
							if (retval==0){
								//SDS.switchBgm("Forced Fit",true);
								SDS.bgmName = null;
								SDS.bgm.stop();
								cacheVars.frameCounter += 0;
							}
							// do nothing and we walk away; trigger resets
							else if (retval==1){
								
								SDS.bgmName = null;
								SDS.bgm.stop();
								cacheVars.frameCounter += 15; // sloppy guess; range should be 11-20
							}
							// encourage and head to the loooong exchange & salvation path
							else if (retval==2){
								SDS.switchBgm("Self; Pity",true);
								cacheVars.frameCounter += 47; // 42-51
							}
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
// boss branch
evt[++t] = DlgEvent("Raviene_c5_unseal_5s");
evt[++t] = {
			customPre : function(cacheVars){
				SDS.switchBgm("Forced Fit",true);
			},
			controls : {
				"Raviene" : {
					left: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					left: false,
				}
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_6s");
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.spell = cacheVars.ravi.SPELLS.NONE;
				}

				cacheVars.block = new GO_Forceblock();
				cacheVars.block.sprite.x = (2<<4);
				cacheVars.block.sprite.y = (13<<4);
				cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
				cacheVars.objMgr.add(cacheVars.block);
				cacheVars.poof = new GO_Poof();
				cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.block.manager);

				cacheVars.block = new GO_Forceblock();
				cacheVars.block.sprite.x = (2<<4);
				cacheVars.block.sprite.y = (14<<4);
				cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
				cacheVars.objMgr.add(cacheVars.block);
				cacheVars.poof = new GO_Poof();
				cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.block.manager);

				cacheVars.block = new GO_Forceblock();
				cacheVars.block.sprite.x = (2<<4);
				cacheVars.block.sprite.y = (15<<4);
				cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
				cacheVars.objMgr.add(cacheVars.block);
				cacheVars.poof = new GO_Poof();
				cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.block.manager);


				cacheVars.block = new GO_Forceblock();
				cacheVars.block.sprite.x = (18<<4);
				cacheVars.block.sprite.y = (2<<4);
				cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
				cacheVars.objMgr.add(cacheVars.block);
				cacheVars.poof = new GO_Poof();
				cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.block.manager);

				cacheVars.block = new GO_Forceblock();
				cacheVars.block.sprite.x = (19<<4);
				cacheVars.block.sprite.y = (2<<4);
				cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
				cacheVars.objMgr.add(cacheVars.block);
				cacheVars.poof = new GO_Poof();
				cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.block.manager);


				cacheVars.block = new GO_Forceblock();
				cacheVars.block.sprite.x = (35<<4);
				cacheVars.block.sprite.y = (13<<4);
				cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
				cacheVars.objMgr.add(cacheVars.block);
				cacheVars.poof = new GO_Poof();
				cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.block.manager);

				cacheVars.block = new GO_Forceblock();
				cacheVars.block.sprite.x = (35<<4);
				cacheVars.block.sprite.y = (14<<4);
				cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
				cacheVars.objMgr.add(cacheVars.block);
				cacheVars.poof = new GO_Poof();
				cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.block.manager);

				cacheVars.block = new GO_Forceblock();
				cacheVars.block.sprite.x = (35<<4);
				cacheVars.block.sprite.y = (15<<4);
				cacheVars.block.addToRoom(cacheVars.meli.sprite.map_room);
				cacheVars.objMgr.add(cacheVars.block);
				cacheVars.poof = new GO_Poof();
				cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.block.manager);

				delete cacheVars.block;
				delete cacheVars.poof;
			},
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=5] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				if (cacheVars.ravi){
					cacheVars.ravi.startFight();
				}
				cacheVars.frameCounter += 1000; // jic
			},
			controls : {
				
			},
			customPost : noop
		};
// retreat branch
evt[t+=10] = {
			customPre : noop,
			controls : {
				"Meli" : {
					left: true,
				}
			},
			customPost : noop
		};
evt[t+=20] = {
			customPre : noop,
			controls : {
				"Meli" : {
					left: false,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				GLOBAL_SCRATCHPAD.note("Triggered_Raviene",false);
				cacheVars.frameCounter += 1000; // jic
			},
			controls : {
				
			},
			customPost : noop
		};
// salvation branch
evt[t+=10] = DlgEvent("Raviene_c5_unseal_5a");
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					left: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					left: false,
				}
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_6a");
evt[++t] = DlgEvent("Raviene_c5_unseal_7a");
evt[++t] = DlgEvent("Raviene_c5_unseal_8a");
evt[++t] = DlgEvent("Raviene_c5_unseal_9a");
evt[++t] = DlgEvent("Raviene_c5_unseal_10a");
evt[++t] = DlgEvent("Raviene_c5_unseal_11a");
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.hurt = true;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_12a");
evt[++t] = {
			customPre : function(cacheVars){
				SDS.bgmName = null;
				SDS.bgm.stop();
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_13a"); // FROM HERE ON, BE SURE ANY CHANGES ARE SYNC'D WITH Raviene_endfight_good
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.spell = cacheVars.ravi.SPELLS.KILL;
					cacheVars.ravi.spell_target = cacheVars.meli;
					cacheVars.ravi.spell_target_name = "Meli";
					cacheVars.ravi.hurt = false;
				}
			},
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=90] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : function(cacheVars){
				SDS.switchBgm("Divine Pity",true);
				GLOBAL_DIARY.note(5,"RAVI_SAVE");
				GLOBAL_DIARY.collectSoul("RAVIENE");
			}
		};
evt[t+=30] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.hurt = true;
				}
				if (DATA_SDS_DIALOGUE["Raviene_c5_unseal_14a"]){
					cacheVars.wait=true;
					cacheVars.dlgDone = false;
					cacheVars.dlgMgr.open("Raviene_c5_unseal_14a",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_15a");
evt[++t] = DlgEvent("Raviene_c5_unseal_16a");
evt[++t] = DlgEvent("Raviene_c5_unseal_17a");
evt[++t] = {
			customPre : function(cacheVars){
				SDS.bgmName = null;
				SDS.bgm.stop();
			},
			controls : {},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_18a");
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.hurt = false;
					cacheVars.ravi.spell = cacheVars.ravi.SPELLS.NONE;
				}

				SDS.switchBgm("Teamwork",true);
			},
			controls : {
				"Raviene" : {
					right: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					right: false,
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=30] = {
			customPre : function(cacheVars){
				cacheVars.wall = cacheVars.objMgr.getNamedObject("Beamwall");
				if (cacheVars.wall){
					cacheVars.wall.active = false;
					cacheVars.wall.playSound("FX_switchoff");
				}
			},
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_19a");
evt[++t] = DlgEvent("Raviene_c5_unseal_20a");
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {
				
			},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Raviene_endfight_bad"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Raviene_endfight_bad"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.ravi = cacheVars.objMgr.getNamedObject("Raviene");
				if (cacheVars.meli){
					// this is a multi-dialog event
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.ravi){
					cacheVars.ravi.hurt = true;
				}
				SDS.bgmName = null;
				SDS.bgm.stop();
				if (DATA_SDS_DIALOGUE["Raviene_c5_killravi_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Raviene_c5_killravi_0",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
for (var l=0; l<30; ++l){
	evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.sprite.visible=!cacheVars.ravi.sprite.visible;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
}
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.clearFromRoom(cacheVars.ravi.sprite.map_room);
					cacheVars.objMgr.remove(cacheVars.ravi);
					cacheVars.ravi = null;
				}
				// selectively clear the forceblocks in the beamwall
				// (I ~may~ even be nice and not put the other ones back
				// when the room respawns... but the player did just
				// save the frames / kill the friendo, so...)
				cacheVars.blocks = [];
				cacheVars.objMgr.getAllNamedObjects("Forceblock",cacheVars.blocks);
				for (cacheVars.i=0; cacheVars.i<cacheVars.blocks.length; ++cacheVars.i){
					cacheVars.block = cacheVars.blocks[cacheVars.i];
					if (cacheVars.block.sprite.x>(34<<4)){
						// shameless copypasta from sealwall destruct
						cacheVars.poof = new GO_Poof("");
						cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.poof = null;
						cacheVars.sparkle = new GO_Sparkle(10,-5,-5);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,5,-5);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,5,5);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,-5,5);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);

						cacheVars.sparkle = new GO_Sparkle(10,-7,0);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,0,-7);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,7,0);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,0,7);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = null;

						cacheVars.block.clearFromRoom(cacheVars.block.sprite.map_room);
					}
				}
				cacheVars.blocks = null;
				cacheVars.wall = cacheVars.objMgr.getNamedObject("Beamwall");
				if (cacheVars.wall){
					cacheVars.wall.active = false;
					cacheVars.wall.playSound("FX_shatter");
				}
				cacheVars.wall = null;
				
			},
			controls : {},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_killravi_1");
evt[++t] = {
			customPre : function(cacheVars){
				GLOBAL_DIARY.note(5,"RAVI_KILL");
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {
				
			},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Raviene_endfight_good"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Raviene_endfight_good"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				cacheVars.ravi = cacheVars.objMgr.getNamedObject("Raviene");
				if (cacheVars.meli){
					// this is a multi-dialog event
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
				if (cacheVars.ravi){
					cacheVars.ravi.hurt = true;
				}
				SDS.bgmName = null;
				SDS.bgm.stop();
				if (DATA_SDS_DIALOGUE["Raviene_c5_boss_concede"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Raviene_c5_boss_concede",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
				cacheVars.good = DEFINE_DIARY_EVENTS.CHAPTER5.RAVI_SAVE.requisites(GLOBAL_DIARY);
				if (cacheVars.good){
					// can branch to a salvation path if deserving
					cacheVars.frameCounter += 40; // 34-44
				}
			},
			controls : {
				
			},
			customPost : noop
		};
// dies anyway - pretty much a dup of endfight_bad
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.hurt = true;
				}
				if (DATA_SDS_DIALOGUE["Raviene_c5_killravi_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Raviene_c5_killravi_0",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
for (var l=0; l<30; ++l){
	evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.sprite.visible=!cacheVars.ravi.sprite.visible;
				}
			},
			controls : {
				
			},
			customPost : noop
		};
}
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.clearFromRoom(cacheVars.ravi.sprite.map_room);
					cacheVars.objMgr.remove(cacheVars.ravi);
					cacheVars.ravi = null;
				}

				// selectively clear the forceblocks in the beamwall
				// (I ~may~ even be nice and not put the other ones back
				// when the room respawns... but the player did just
				// save the frames / kill the friendo, so...)
				cacheVars.blocks = [];
				cacheVars.objMgr.getAllNamedObjects("Forceblock",cacheVars.blocks);
				for (cacheVars.i=0; cacheVars.i<cacheVars.blocks.length; ++cacheVars.i){
					cacheVars.block = cacheVars.blocks[cacheVars.i];
					if (cacheVars.block.sprite.x>(34<<4)){
						// shameless copypasta from sealwall destruct
						cacheVars.poof = new GO_Poof("");
						cacheVars.poof.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.poof = null;
						cacheVars.sparkle = new GO_Sparkle(10,-5,-5);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,5,-5);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,5,5);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,-5,5);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);

						cacheVars.sparkle = new GO_Sparkle(10,-7,0);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,0,-7);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,7,0);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = new GO_Sparkle(10,0,7);
						cacheVars.sparkle.spawnOnSprite(cacheVars.block.sprite,cacheVars.objMgr);
						cacheVars.sparkle = null;

						cacheVars.block.clearFromRoom(cacheVars.block.sprite.map_room);
					}
				}
				cacheVars.blocks = null;
				cacheVars.wall = cacheVars.objMgr.getNamedObject("Beamwall");
				if (cacheVars.wall){
					cacheVars.wall.active = false;
					cacheVars.wall.playSound("FX_shatter");
				}
				cacheVars.wall = null;
				
			},
			controls : {},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_killravi_1");
evt[++t] = {
			customPre : function(cacheVars){
				GLOBAL_DIARY.note(5,"RAVI_KILL");
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
				cacheVars.frameCounter += 1000; // jic
			},
			controls : {
				
			},
			customPost : noop
		};
// salvation
// FROM HERE ON, BE SURE ANY CHANGES ARE SYNC'D WITH Raviene_unseal
// (excepting here we clear out the forceblocks, and set RAVI_ROUGH instead of RAVI_SAVE)
evt[t+=10] = DlgEvent("Raviene_c5_unseal_13a"); 
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.spell = cacheVars.ravi.SPELLS.KILL;
					cacheVars.ravi.spell_target = cacheVars.meli;
					cacheVars.ravi.spell_target_name = "Meli";
					cacheVars.ravi.hurt = false;
				}
			},
			controls : {
				"Raviene" : {
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=90] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : function(cacheVars){
				SDS.switchBgm("Divine Pity",true);
				GLOBAL_DIARY.note(5,"RAVI_ROUGH");
				GLOBAL_DIARY.collectSoul("RAVIENE");
			}
		};
evt[t+=30] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.hurt = true;
				}
				if (DATA_SDS_DIALOGUE["Raviene_c5_unseal_14a"]){
					cacheVars.wait=true;
					cacheVars.dlgDone = false;
					cacheVars.dlgMgr.open("Raviene_c5_unseal_14a",function(index,retval){
						if (retval!==null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_15a");
evt[++t] = DlgEvent("Raviene_c5_unseal_16a");
evt[++t] = DlgEvent("Raviene_c5_unseal_17a");
evt[++t] = {
			customPre : function(cacheVars){
				SDS.bgmName = null;
				SDS.bgm.stop();
			},
			controls : {},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_18a");
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.ravi){
					cacheVars.ravi.hurt = false;
					cacheVars.ravi.spell = cacheVars.ravi.SPELLS.NONE;
				}

				SDS.switchBgm("Teamwork",true);
			},
			controls : {
				"Raviene" : {
					right: true,
				}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene" : {
					right: false,
					B: true,
				}
			},
			customPost : noop
		};
evt[t+=30] = {
			customPre : function(cacheVars){
				cacheVars.wall = cacheVars.objMgr.getNamedObject("Beamwall");
				if (cacheVars.wall){
					cacheVars.wall.active = false;
					cacheVars.wall.playSound("FX_switchoff");
				}
				// ONLY HERE we add more for the salvation path:
				// clear out the forceblocks
				// selectively clear the forceblocks in the beamwall
				// (I ~may~ even be nice and not put the other ones back
				// when the room respawns... but the player did just
				// save the frames / kill the friendo, so...)
				cacheVars.blocks = [];
				cacheVars.objMgr.getAllNamedObjects("Forceblock",cacheVars.blocks);
				for (cacheVars.i=0; cacheVars.i<cacheVars.blocks.length; ++cacheVars.i){
					cacheVars.block = cacheVars.blocks[cacheVars.i];
					cacheVars.block.clearFromRoom(cacheVars.block.sprite.map_room);
				}
				cacheVars.blocks = null;
			},
			controls : {
				"Raviene" : {
					B: false,
				}
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Raviene_c5_unseal_19a");
evt[++t] = DlgEvent("Raviene_c5_unseal_20a");
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {
				
			},
			customPost : noop
		};


DATA_SDS_SCRIPTED_EVENTS["Meet_Malfose"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Meet_Malfose"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				//cacheVars.malfose = cacheVars.objMgr.getNamedObject("Malfose");
				if (cacheVars.meli){
					// this is a multi-dialog event
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
			},
			controls : {},
			customPost : noop
		};

evt[++t] = DlgEvent("Malfose_c5_prefight_0");

evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Malfose_c5_prefight_1"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_prefight_1",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
					SDS.switchBgm("Seeking the Darkness II",true);
				}
			},
			controls : {},
			customPost : noop
		};

for (var l=2; l<=5; ++l){
	evt[++t] = DlgEvent("Malfose_c5_prefight_"+l);
}

evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Malfose_c5_prefight_6"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_prefight_6",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Malfose":{B:true}
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Malfose_c5_prefight_7");
evt[++t] = DlgEvent("Malfose_c5_prefight_8");
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Malfose_c5_prefight_9"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_prefight_9",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Malfose":{B:false, A:true}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Malfose_c5_prefight_10"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_prefight_10",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Malfose":{A:false}
			},
			customPost : noop
		};
for (var l=11; l<=14; ++l){
	evt[++t] = DlgEvent("Malfose_c5_prefight_"+l);
}
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Malfose_c5_prefight_15"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_prefight_15",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Malfose":{A:true}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Malfose_c5_prefight_16"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_prefight_16",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Malfose":{A:false}
			},
			customPost : noop
		};
for (var l=17; l<=19; ++l){
	evt[++t] = DlgEvent("Malfose_c5_prefight_"+l);
}
evt[++t] = {
			customPre : noop,
			controls : {
				"Malfose":{A:true}
			},
			customPost : noop
		};
for (var l=20; l<=25; ++l){
	evt[++t] = DlgEvent("Malfose_c5_prefight_"+l);
}
evt[++t] = {
			customPre : noop,
			controls : {
				"Malfose":{A:false}
			},
			customPost : noop
		};
for (var l=26; l<=27; ++l){
	evt[++t] = DlgEvent("Malfose_c5_prefight_"+l);
}
evt[++t] = {
			customPre : noop,
			controls : {},
			customPost : function(cacheVars){
				GLOBAL_SCRATCHPAD.note("Met_Malfose",true);
				GLOBAL_SCRATCHPAD.persist("Met_Malfose");

				// manhandle meli's event trigger slots
				// since that's the least-ugly option
				// I can think of compared with grabbing
				// for globals or making all ending branches
				// line-GOTO indices of the same event
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;

					cacheVars.meli.triggering = {
						triggerEvent: function(sourceGO){
							return GLOBAL_DIARY.check(5,"RAVI_KILL") ? "Malfose_Solo" : "Malfose_Ravi";
						},
					};
				}
			}
		};

DATA_SDS_SCRIPTED_EVENTS["Malfose_Solo"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Malfose_Solo"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				
				if (DATA_SDS_DIALOGUE["Malfose_c5_killravi_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_killravi_0",function(index,retval){
						if (retval!=null){
							if (cacheVars.meli){
								cacheVars.meli.triggering = {
									triggerEvent: function(sourceGO){
										if (retval==0) return "Malfose_Solo_Fight";
										else if (retval==1) return "Malfose_Solo_Fall";
										else return "Malfose_Solo_Flee";
									},
								};
							}


							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Malfose_Solo_Fight"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Malfose_Solo_Fight"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				//cacheVars.malfose = cacheVars.objMgr.getNamedObject("Malfose");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				if (DATA_SDS_DIALOGUE["Malfose_c5_killravi_1a"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_killravi_1a",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Malfose_c5_killravi_2a");
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;

					var room = cacheVars.meli.sprite.map_room;
					var getDestName = function(room){
						return function(){
							return "underdark_arena";
						};
					}(room);
					// full-room autoport trigger
					var port = new GO_Passage(room.pixel_width,room.pixel_height,getDestName,noop);
					port.sprite.x = 0;
					port.sprite.y = 0;

					room.addSprite(port.sprite);
					cacheVars.objMgr.add(port);

					GLOBAL_SCRATCHPAD.note("flash",true);
					GLOBAL_SCRATCHPAD.persist("flash");
				}
			},
			controls : {
				
			},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Malfose_Solo_Fall"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Malfose_Solo_Fall"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				//cacheVars.malfose = cacheVars.objMgr.getNamedObject("Malfose");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				if (DATA_SDS_DIALOGUE["Malfose_c5_killravi_1b"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_killravi_1b",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Malfose_c5_killravi_2b"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_killravi_2b",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Malfose":{B:true}
			},
			customPost : noop
		};
evt[t+=30] = {
			customPre : function(cacheVars){
				//var room = cacheVars.meli.sprite.map_room;
				//var getDestName = function(room){
				//	return function(){
				//		return "the_void";
				//	};
				//}(room);
				//// full-room autoport trigger
				//var port = new GO_Passage(room.pixel_width,room.pixel_height,getDestName,noop);
				//port.sprite.x = 0;
				//port.sprite.y = 0;
				//
				//room.addSprite(port.sprite);
				//cacheVars.objMgr.add(port);

				cacheVars.poof = new GO_Poof("FX_splat");
				cacheVars.poof.spawnOnSprite(cacheVars.meli.sprite,cacheVars.objMgr);
				cacheVars.poof = null;
				SDS.meters.visible = false;
				Logging_Save_Score();
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				cacheVars.meli.overrideFrame=30; // empty/hidden frame; don't trust visibility=false to not be overridden
			},
			controls : {
			},
			customPost : noop
		};
evt[t+=60] = {
			customPre : function(cacheVars){
				if (DATA_SDS_DIALOGUE["Malfose_c5_killravi_3b"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_killravi_3b",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
							
							//GLOBAL_SCRATCHPAD.unpersist("Met_Malfose");
							// ^ on second thought, replayers, you're welcome.

							// END GAME
							//SDS.switchBgm("Self; Pity",true);
							SDS.ending = "Pacifism";
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {
				
			},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Malfose_Solo_Flee"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Malfose_Solo_Flee"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				//cacheVars.malfose = cacheVars.objMgr.getNamedObject("Malfose");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				if (DATA_SDS_DIALOGUE["Malfose_c5_killravi_1c"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_killravi_1c",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Malfose_c5_killravi_2c");
evt[++t] = {
			customPre : noop,
			controls : {
				"Meli":{left:true, A:true}
			},
			customPost : noop
		};
evt[t+=10] = {
			customPre : noop,
			controls : {
				"Meli":{A:false}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Meli":{A:true}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Meli":{A:false}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Meli":{A:true}
			},
			customPost : noop
		};
evt[t+=60] = {
			customPre : noop,
			controls : {
				"Meli":{A:false, left:false}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {
				
			},
			customPost : noop
		};








DATA_SDS_SCRIPTED_EVENTS["Malfose_Ravi"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Malfose_Ravi"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				//cacheVars.malfose = cacheVars.objMgr.getNamedObject("Malfose");
				if (cacheVars.meli){
					// this is a multi-dialog event
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				if (DATA_SDS_DIALOGUE["Malfose_c5_saveravi_0"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_saveravi_0",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				SDS.switchBgm("A-minor Waltz in 4",true);
			},
			controls : {
				"Raviene":{right:true}
			},
			customPost : noop
		};
evt[t+=60] = {
			customPre : noop,
			controls : {
				"Raviene":{right:false}
			},
			customPost : noop
		};
for (var l=1; l<=3; ++l){
	evt[++t] = DlgEvent("Malfose_c5_saveravi_"+l);
}

evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene":{left:true}
			},
			customPost : noop
		};
evt[++t] = {
			customPre : noop,
			controls : {
				"Raviene":{left:false}
			},
			customPost : noop
		};

evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;

					cacheVars.meli.triggering = {
						triggerEvent: function(sourceGO){
							return "Malfose_Ravi_Choice";
						},
					};
				}
			},
			controls : {
				
			},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Malfose_Ravi_Choice"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Malfose_Ravi_Choice"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				
				if (DATA_SDS_DIALOGUE["Malfose_c5_saveravi_4"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_saveravi_4",function(index,retval){
						if (retval!=null){
							if (cacheVars.meli){
								cacheVars.meli.triggering = {
									triggerEvent: function(sourceGO){
										if (retval==0) return "Malfose_Ravi_Fight";
										else return "Malfose_Ravi_Flee";
									},
								};
							}


							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Malfose_Ravi_Fight"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Malfose_Ravi_Fight"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				//cacheVars.malfose = cacheVars.objMgr.getNamedObject("Malfose");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}

				if (DATA_SDS_DIALOGUE["Malfose_c5_saveravi_5a"]){
					cacheVars.wait=true;
					cacheVars.dlgMgr.open("Malfose_c5_saveravi_5a",function(index,retval){
						if (retval!=null){
							cacheVars.wait=false; // yay js scoping
						}
					});
				}
			},
			controls : {
				"Malfose":{B:true},
			},
			customPost : noop
		};
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;

					var room = cacheVars.meli.sprite.map_room;
					var getDestName = function(room){
						return function(){
							return "underdark_arena";
						};
					}(room);
					// full-room autoport trigger
					var port = new GO_Passage(room.pixel_width,room.pixel_height,getDestName,noop);
					port.sprite.x = 0;
					port.sprite.y = 0;

					room.addSprite(port.sprite);
					cacheVars.objMgr.add(port);

					GLOBAL_SCRATCHPAD.note("flash",true);
					GLOBAL_SCRATCHPAD.persist("flash");
				}
			},
			controls : {
				
			},
			customPost : noop
		};

DATA_SDS_SCRIPTED_EVENTS["Malfose_Ravi_Flee"] = {};
var evt = DATA_SDS_SCRIPTED_EVENTS["Malfose_Ravi_Flee"];
var t=0;
evt[t] = {
			customPre : function(cacheVars){
				cacheVars.meli = cacheVars.objMgr.getNamedObject("Meli");
				//cacheVars.malfose = cacheVars.objMgr.getNamedObject("Malfose");
				if (cacheVars.meli){
					// this is a multi-dialog event; we want to lock down movement between them
					cacheVars.controls = cacheVars.meli.controls;
					cacheVars.meli.controls = new Controls();
				}
			},
			controls : {
				"Raviene":{B:true},
			},
			customPost : noop
		};

evt[t+=30] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					var room = cacheVars.meli.sprite.map_room;
					var getDestName = function(room){
						return function(){
							return "underdark_seal";
						};
					}(room);
					// full-room autoport trigger
					var port = new GO_Passage(room.pixel_width,room.pixel_height,getDestName,function(sprite){
						sprite.x=30<<4;
						sprite.y=12<<4;
					});
					port.sprite.x = 0;
					port.sprite.y = 0;

					room.addSprite(port.sprite);
					cacheVars.objMgr.add(port);

					GLOBAL_SCRATCHPAD.note("flash",true);
					GLOBAL_SCRATCHPAD.persist("flash");
				}
			},
			controls : {
				//"Raviene":{B:false}, // moot- will be a different ravi
			},
			customPost : noop
		};
evt[++t] = DlgEvent("Malfose_c5_saveravi_5b");
evt[++t] = {
			customPre : function(cacheVars){
				if (cacheVars.meli){
					cacheVars.meli.controls = cacheVars.controls;
					delete cacheVars.controls;
				}
			},
			controls : {
				
			},
			customPost : noop
		};

evt = null;
t=null;
