"../deathforth/rooms/tutorial.txt" $load-rooms
"../deathforth/rooms/city.txt" $add-rooms

cyoa{

cyoa-choice: tutorchat-1
	pchar choosechar
	($ pname .. " tells " .. bname .. " to " .. "COOL IT!" pbold $) text!
	($ bname .. " is infuriated by this! " .. bHe .. " gets " .. "SUPER STEAMING MAD!" rbold $) +crtext
	($ "I'm not sure if telling someone to " .. "'COOL IT'" pbold .. " has ever worked, in the history of the whole world." $) +crtext
	1 cchar .wits! 1 cchar .attitude!
	witsattREV badfx clear-cyoa morale2-all
;

cyoa-choice: tutorchat-2
	pchar choosechar
	($ pname .. " tries to lay on the charm and get " .. bname .. " to help fight the zombies swarming in.
	" .. bname .. " sweats visibly." $) text!
	($ "I'm busy! I'm busy doing stuff! You go do it!" pbold $) +crtext
	"Well, it was worth a try. This might have worked on someone that was less of a jerk." +crtext
	6 cchar .wits! 6 cchar .attitude!
	witsattREV badfx clear-cyoa
;

cyoa-choice: tutorchat-3 
	pchar choosechar
	($ pname .. " calls " .. bname .. " a " .. "dink." pbold $) text!
	($ bname .. " is shocked! It was fun to finally tell " .. bhim .. " what a dink " .. bhe .. " was." $) +crtext
	goodfx clear-cyoa morale++all
;

cyoa: tutorchat
	rescue choosechar cicon
	cchar to bully
	dead? if npc-died then;
	($ pname .. " sees " .. cname .. ", who is a real dink.
	" .. "Zombies have broken into my home! This is probably your fault! It certainly isn't mine!" pbold .. "
	When the group found this zombie bunker, " .. bname .. " called dibs on this big bedroom before anyone else." $) text!
	
	choice( "Leave " .. chim .. " be for now" )choice
	choice( "Tell " .. chim .. " to 'Cool It'" )choice: tutorchat-1
	choice( "Convince " .. chim .. " to help fight zombies" )choice: tutorchat-2
	choice( "Call " .. chim .. " a dink" )choice: tutorchat-3
;

cyoa: tutorrecruit
	recruitee choosechar cicon
	dead? if npc-died then;
	($ pname .. " greets " .. rname .. ".
	" .. "I think we will have to leave this safehouse. At least we got to rest for awhile.
	We should try heading to Canada! Would you like me to travel with you?" pbold .. "
	More people means more hands to loot and fight with. It also means more people to get in the way, eat up the food, and argue." $) text!
	0.25 cchar .ai.wander_chance! 0 nearest .unseen! clear-cyoa
	recruit-yesno
	
;

}

: tutorial-npc1 
	new-npc@ 0 over .ai.wander_chance! 180 lt .aim_angle! lt .character@ to rescue
	cyoa{ ' tutorchat cyoa! } drop
;

: tutorial-npc2
	// new-rescue-npc 0 lt .character@ .ai.wander_chance!
	new-npc@ rescue-weapon over .weapona! 1 lt .unseen! 0 over .ai.wander_chance! 180 lt .aim_angle! lt .character@ to recruitee 
	cyoa{ ' tutorrecruit cyoa! } drop
;

mission{ 

: door-tutorial-escape
	cyoa-start
	beep "door-no-escape" print
	"No Exit" cyoa-title!
	($ "You can't leave from this location!
	This door just leads to the " .. "Garbage Room" rbold .. ", which is nearly full. Whoever designed this zombie bunker didn't put a lot of thought into how long it would last.
	You will have to find another way out. " $) cyoa-text!
	"Or, if you'd like, you can skip the tutorial." rbold +text
		choice( "Go Back to Tutorial" )choice
		cyoa-add-choice
		"Skip Tutorial!" cyoa-choice-text!
			cyoa{ ' tutorial-ladder-end cyoa-choice-handler! }
;

: tutortopmsg
	eventid THING_EVENT_TIMER <> if drop then;
	( beep ) // Good for debugging timers
	me .retrigger_timer
	curmapview me .mapid@ <> if then;
	WHITE swap $cat 60 view_w 0.5 * 16 msgtickxy
;

: best_btn_name args( cmd ) <- cmd p1_cmd_joy_alt <- cmd p1_btn_name ;


: attackbtn CMD_ATTACK best_btn_name ;
: swapbtn CMD_SWAP best_btn_name ;
: usebtn CMD_USE best_btn_name ;
: startbtn CMD_START best_btn_name ;

: upbtn CMD_UP best_btn_name ;
: downbtn CMD_DOWN best_btn_name ;
: leftbtn CMD_LEFT best_btn_name ;
: rightbtn CMD_RIGHT best_btn_name ;

: usebtns usebtn
	// .. usebtn $len 1 usebtn $len and if "OR " else "" then .. 1 usebtn
;
: attackbtns attackbtn 
	// .. attackbtn $len 1 attackbtn $len and if "OR " else "" then .. 1 attackbtn
;
: swapbtns swapbtn
	// .. swapbtn $len 1 swapbtn $len and if "OR " else "" then .. 1 swapbtn 
;
: startbtns startbtn 
	// .. startbtn $len 1 startbtn $len and if "OR " else "" then .. 1 startbtn 
;

: arrowbtns
	upbtn ", " .. downbtn .. ", " .. leftbtn .. ", " .. rightbtn ..
;

: tutorial_touch_check touch_controls@ 0 > ;

thing-event: tutormsg1
	tutorial_touch_check if
		($ "DRAG LEFT THUMB TO MOVE
		TAP USE BUTTON TO OPEN" $)
		// ADJUST CONTROLS IN TOP LEFT OF PAUSE MENU - Removed from second line for now
		// Could we have the USE button glow here or something? That way could get rid of the third line maybe...
	else
		($ arrowbtns .. " TO MOVE " .. usebtns .. " TO OPEN OR USE" $) 
	then tutortopmsg ;
thing-event: tutormsg2 
	tutorial_touch_check if
		($ "USE BUTTON TO PICK UP WEAPONS
		SWAP BUTTON TO SWAP
		HOLD USE TO DROP" $) 
	else
		($ usebtns .. " TO PICK UP WEAPONS
		" .. swapbtns .. " TO SWAP WEAPONS
		HOLD " .. usebtn .. " TO DROP WEAPON" $) 
	then tutortopmsg ;
thing-event: tutormsg3 
	tutorial_touch_check if
		($ "USE BUTTON TO PICK UP CHAIRS
		TAP RIGHT SIDE OF SCREEN TO THROW CHAIR
		SWAP BUTTON TO DROP" $)
	else
		($ usebtns .. " TO PICK UP CHAIRS
		" .. attackbtns .. " TO THROW CHAIR
		" .. swapbtns .. " TO DROP CHAIR" $)
	then tutortopmsg ;
thing-event: tutormsg4 
	tutorial_touch_check if
		($ "TAP RIGHT SIDE OF SCREEN TO ATTACK
		TRY TO PACE YOURSELF" $)
	else
		($ attackbtns .. " TO ATTACK
		TRY TO PACE YOURSELF" $)
	then tutortopmsg ;

thing-event: tutormsg5 
	"WATCH OUT FOR HUGE SWARMS
	RUNNING OFTEN BEATS FIGHTING" tutortopmsg ;
thing-event: tutormsg6 
	"LADDER LEADS TO OUTSIDE
	GOOD LUCK OUT THERE" tutortopmsg ;

thing-event: tutormsg7 
	tutorial_touch_check if
		($ "USE BUTTON TO TALK OR INTERACT" $)
	else
		($ usebtns .. " TO TALK OR INTERACT" $)
	then tutortopmsg ;

thing-event: tutormsg8 
	"CHOOSE YOUR PALS WISELY" tutortopmsg ;
thing-event: tutormsg9 
	"BATHROOMS MAY HAVE MEDS" tutortopmsg ;
thing-event: tutormsg10 
	"ALWAYS BE LOOTING" tutortopmsg ;

	thing-event: tutormsg11
	tutorial_touch_check if
		($ "PAUSE FOR TEAM SWAP OR INFO
		YOU CAN SWAP LEADERS" $)
	else
		($ startbtns .. " FOR TEAM SWAP OR INFO
		YOU CAN SWAP LEADERS" $)
	then tutortopmsg ;
}

map{ roomgen{

: tutorialbars
	spawn special_objects64_base_id 0x 9 + lt .spriteid!
	bbox immovable as-metal
;

: tutormsg lt .events! 1 sec>tick lt .repeating_timer invisible ;

: tutor1msg spawn mission{ ' tutormsg1 } tutormsg ;
: tutor2msg spawn mission{ ' tutormsg2 } tutormsg ;
: tutor3msg spawn mission{ ' tutormsg3 } tutormsg ;
: tutor4msg spawn mission{ ' tutormsg4 } tutormsg ;
: tutor5msg spawn mission{ ' tutormsg5 } tutormsg ;
: tutor6msg spawn mission{ ' tutormsg6 } tutormsg ;

: tutorbedmsg spawn mission{ ' tutormsg7 } tutormsg ;
: tutorkitchmsg spawn mission{ ' tutormsg8 } tutormsg ;
: tutorbathmsg spawn mission{ ' tutormsg9 } tutormsg ;
: tutorstormsg spawn mission{ ' tutormsg10 } tutormsg ;

: tutor11msg spawn mission{ ' tutormsg11 } tutormsg ;

} }

locdef{

location: tutorial
		max-rooms: 11
		entry-tags: tutor1
		script: set-theme-house
		pre-script: set-theme-house
		post-script: nad

		: tutor1script
			e random-edge-door "tutor2" only-with-door
			tutor1msg
		;

		: tutor2script
			e random-edge-door "tutor3" only-with-door
			s random-edge-door "tutorbath" only-with-door
			n random-edge-door "bedroom" only-with-door
			tutor2msg
			baseball .scatter wrench .scatter
		;
		
		: tutor3script
			e random-edge-door "tutor4" only-with-door
			n random-edge-door "kitchen" only-with-door
			tutor3msg
		;
		
		: tutor4script
			e random-edge-door "tutor5" only-with-door
			s random-edge-door "tutorstorage" only-with-door
			tutor4msg
		;
		
		: tutor5script
			e random-edge-door "tutor6" only-with-door
			tutor5msg
		;
		
		: tutor6script
			e random-edge-door "tutorend" only-with-door
			tutor11msg
		;

		room-choice: tutor1
			room-weight: 300
			room-count: 1
			room-script:
			room-post-script: tutor1script
			filter-only

		room-choice: tutor2
			room-weight: 300
			room-count: 1
			room-post-script: tutor2script
			filter-only

		room-choice: tutor3
			room-weight: 300
			room-count: 1
			room-post-script: tutor3script
			filter-only
		
		room-choice: tutor4
			room-weight: 300
			room-count: 1
			room-script: gcloset-theme
			room-post-script: tutor4script
			filter-only

		room-choice: tutorstorage
			room-weight: 300
			room-count: 1
			room-script: gcloset-theme
			room-post-script: tutorstormsg
			filter-only
		
		room-choice: tutor5
			room-weight: 300
			room-count: 1
			room-script: gcloset-theme
			room-post-script: tutor5script
			filter-only		
			
		room-choice: tutor6
			room-weight: 300
			room-count: 1
			room-script: gcloset-theme
			room-post-script: tutor6script
			filter-only		
		
		room-choice: tutorend
			room-weight: 300
			room-count: 1
			room-script: gcloset-theme
			// gcloset-theme gbath-theme
			room-post-script: tutor6msg
			filter-only

		room-choice: tutorbath
			room-weight: 1
			room-count: 1
			room-script: floor-bath
			room-post-script: tutorbathmsg

		room-choice: bedroom
			room-weight: 10
			room-count: 1
			room-post-script: tutorbedmsg tutorial-npc1

		room-choice: kitchen
			room-weight: 10
			room-count: 1
			room-script: floor-kitchen
			room-post-script: tutorial-npc2 tutorkitchmsg
}
			
regiondef{			

	: tutorial-setup
		mission{ ' door-tutorial-escape to main-event-mission-location-leave }
		easy-music-fade 0 region.zombie_basespawn!
	;

	region: tutorial
		script: timeofday o'clock

		inside
					
		loc-choice: tutorial
			loc-weight: 99
			loc-count: 1

		post-script: tutorial-setup
}
