// uses hack/region-downtown-test.df
uses paul/region-layout.df

// "../deathforth/hack/gasbar.txt" $load-rooms
// "additional-rooms.txt" $add-rooms

map{ regiondef{

: wooded xyp.xy tile>pos 0 1 frnd * pine lt .pos! lt .sprw 0.5 * 4 + lt .wallbox.x! drift ;

: spawnhere spawn xyp.xy tile>pos lt .pos! ;

: smallball bbox lt .rad.x@ lt .rad.y@ min 0 lt .rad.y! lt .rad.x! ;

0 value splitdir

: missionchar? #teamchar .party@ if 1 then; 0 ;

: team-follow-thing args( thing )
	0 begin dup missionchar? while
		( index ) <- thing thing# over #teamchar .thing@ .ai.followid! 1+
	repeat
	drop
;


: .tent-enter args( tent thing )
	<- tent <- thing .enter
;

: camping-road-start
	"SAY THAT WAS A NICE SLEEP, MAYBE SOMEONE GOT HEALED OR IS NOT SICK ANYMORE OR HAD A WEIRD DREAM OR SOMETHING"
	$cyoa-ok-dialog
;

// NOTE: Could also queue this in the road stack as before... just testing new stuff
: end-camping to-road 90 global_delay! -90 fade_to 1 ' camping-road-start timer_add ;

: cyoa-tent args( thing )

	player .inside_id@ if then;

	<- thing player .tent-enter
	player team-follow-thing
	0 <- thing .cyoa!
	90 fade_to

	120 ' end-camping timer_add
;

: cyoa-chatter args( thing )
	"HEY I MAYBE SOMEONE CAN TREAT MY WOUNDS OR MY COUSIN HAS A HIDDEN BUNKER IN THE WOODS OR I HEARD SOME URBAN LEGEND"
	" TO INVESTIGATE AS A TRIP-LENGTHENING SIDE-QUEST OR WE CAN JUST CHAT ABOUT STUFF" .. $cyoa-ok-dialog
	// TODO: ... And then a side quest could be QUEUED into the road event stack
;

: team-camp-setup
	0 begin dup missionchar? while
		' cyoa-chatter over #teamchar .thing@ .cyoa!
		0.025 over #teamchar .ai.wander_chance!
	1+
	repeat drop
;

: tenthere spawnhere
	special_objects48_base_id 0x 28 + lt .spriteid!
	rnd5050 lt .flip!
	bbox 0 lt .rad.y! 0.5 lt .rad.x@ * lt .rad.x!
	15 lt .hitpoints!
	100 lt .flammability!
	1 lt .no_hit!
	immovable
	0.25 lt .wind!
	splitdir 24 * lt .pos.x@ + lt .pos.x!
	' cyoa-tent lt .cyoa!
	particles_base_id 0x 3d + lt .action_icon!
;


: campfire-events args( me eventid )
	<- eventid THING_EVENT_TIMER <> if then;
	0.1 <- me

	5 10 rnd <- me .timer!

	hour 23 < hour 17 > and weather@ 0.2 < and if
		special_objects48_base_id 0x 29 + <- me .spriteid!
		10 onein if .flames else
			rnd5050 if
				.licks
			else
				.embers
				rnd5050 if
					sfx{ noise 0.1 0.25 frnd fx .scale! 1 5 frnd fx .pitch!
						2000 5000 frnd fx .filt_high!
						2 10 rnd fx .a!
						5 15 rnd fx .d! 0.7 0.95 fx .q! }
					<- me .adjust-vol
				then
			then
		then

		1 <- me .no_lighting!

		<- me .clr.r@ 1 < if 1 else 0.9 then <- me .clr.r!
		0.9 <- me .clr.g!
		0.9 <- me .clr.b!

	else
		0 <- me .no_lighting!
		special_objects48_base_id 0x 2a + <- me .spriteid!
	then
;


: cyoa-fire
	"HMMM WE COULD COOK AN EXTRA GOOD MEAL OR MARSHMALLOWS OR TELL SPOOKY STORIES OR HAVE AN NPC SHOW UP"
	$cyoa-ok-dialog
;

: campfirehere spawnhere lt args( t )
	special_objects48_base_id 0x 29 + lt .spriteid!
	rnd5050 lt .flip!
	1 lt .no_hit!
	1000 lt .hitpoints!
	0 lt .flammability!
	smallball
	immovable
	' campfire-events lt .events!
	1 lt .timer!
	splitdir -24 * lt .pos.x@ + lt .pos.x!
	1 lt .no_lighting!
	1 lt .uncentered!

	// Hang around the campfire
	lt team-follow-thing
	' cyoa-fire lt .cyoa!
;


' plotdirt >defer ft

: pt
	xyp.xy ft // Plot the current floor by default

	xyp.i char c = if campfirehere then;
	xyp.i char C = if tenthere then;
	xyp.i char t = if wooded then;
;

"
.....................
.....................
.....................
.....................
.....................
.....................
.......ttttttt.......
.....ttttttttttt.....
....ttttt...ttttt....
...tt.....C.....tt...
..tt.............tt..
.tt.......c.......tt.
.....................
.....................
.....................
.....................
.....................
....................."
constant maplayout

: plotmap
	0 -1 maplayout xyplot: pt
;

: campsite-light tint_default 1 light_mode!
	1 0.5 0 tint_near!
	0 0 1 tint_far!
;

: site-setup
	1 no_time!
	rndsign to splitdir

	-1 1 frnd wind_force!

	' plotgrass to ft plotmap
	mission{ no-leaving }
	mission{ no-edge-spawns }
	hour 19 < if 19 o'clock then
	-30 fade_to
	team-camp-setup

	// NOTE: Don't let you just drive away! Or should we... (good way to abandon everyone)
//	mission.vehicle@ if setup-vehicle then
;

region: campsite
	w: maplayout layoutw
	h: maplayout layouth 1-

	start-mode: 1

	post-script: site-setup

} }

//	: iconxy particle{ new pos! spriteid! 1 ticks! 0 layer! 0 global_colour! } ;
