The Dink Network

Burning screenmatched trees

July 26th 2024, 12:48 AM
death.gif
Seseler
Peasant He/Him Heard Island And Mcdonald Islands
 
Everyone here knows that when you burn a tree that's on border of the screen, the matching tree in adjacent screen stays unburned. A bit annoying, isn't it?

I think that there was some discussion on how to solve this back in the day, but I can't find it now, so I ended up making my own cross-screen burnable tree script.

I'd like to know if anyone remembers any earlier scripts for burnable screenmatched trees?

void main (void)
{
	&save_x = sp_x(&current_sprite, -1);
	&save_y = sp_y(&current_sprite, -1);
	check_burned(&save_x, &save_y, &player_map);
	if(&return == 1)
	{
		//Tree's burned
		sp_pseq(&current_sprite, 20);
		sp_pframe(&current_sprite, 29);
		draw_hard_map();
		kill_this_task();
	}

}

void check_burned ( void )
{
	//Check if tree centered on another screen is burned
	if(&arg2 < 0)
	{
		if(&arg3 > 32)
		{
			&player_map -= 32;
			&save_y += 400;
		}
		else
		{
			goto checkfail;
		}
	}

	if(&arg2 > 399)
	{
		if(&arg3 < 737)
		{
			&player_map += 32;
			&save_y -= 400;
		}
		else
		{
			goto checkfail;
		}
	}

	if(&arg1 < 20)
	{
		math_mod(&player_map, 32);
		if(&return != 1)
		{
			&save_x += 600;
			&player_map -= 1;
		}
		else
		{
			goto checkfail;
		}
	}

	if(&arg1 > 619)
	{
		math_mod(&player_map, 32);
		if(&return != 0)
		{
			&save_x -= 600;
			&player_map += 1;
		}
		else
		{
			goto checkfail;
		}
	}

	if(inside_box(&save_x, &save_y, 20, 0, 619, 399) != 1)
	{
		debug("Tree on screen &arg3, x=&arg1 y=&arg2 is WAY out of bounds!");
		goto checkfail;
	}

	&save_x /= 2;
	&save_y /= 2;
	&save_y *= 300;
	&save_x += &save_y;

	&save_y = 99;

	checkloop:
	if(editor_frame(&save_y, -1) == 255)
	{
		if(editor_seq(&save_y, -1) == &save_x)
		{
			goto checktrue;
		}
	}
	&save_y -= 1;
	if(&save_y > 0)
	{
		goto checkloop;
	}
	goto checkfail;

	checktrue:

	&player_map = &arg3;
	&save_x = &arg1;
	&save_y = &arg2;
	return(1);

	checkfail:

	&player_map = &arg3;
	&save_x = &arg1;
	&save_y = &arg2;
	return(0);
}

void die(void)
{
	&save_x = sp_x(&current_sprite, -1);
	&save_y = sp_y(&current_sprite, -1);
	mark_burned(&save_x, &save_y, &player_map);
	sp_pseq(&current_sprite, 20);
	sp_pframe(&current_sprite, 29);
	sp_hard(&current_sprite, 0);
	draw_hard_sprite(&current_sprite);
	sp_seq(&current_sprite, 20);
	playsound(6, 8000,0,&current_sprite,0);
	return;
}

void mark_burned(void)
{

	if(sp_editor_num(&current_sprite) == 0)
	{
		debug("Tree not placed on editor, skip marking");
		return;
	}

	if(&arg2 < 0)
	{
		if(&arg3 > 32)
		{
			&player_map -= 32;
			&save_y += 400;
		}
		else
		{
			goto simplesave;
		}
	}

	if(&arg2 > 399)
	{
		if(&arg3 < 737)
		{
			&player_map += 32;
			&save_y -= 400;
		}
		else
		{
			goto simplesave;
		}
	}

	if(&arg1 < 20)
	{
		math_mod(&player_map, 32);
		if(&return != 1)
		{
			&save_x += 600;
			&player_map -= 1;
		}
		else
		{
			goto simplesave;
		}
	}

	if(&arg1 > 619)
	{
		math_mod(&player_map, 32)
		if(&return != 0)
		{
			&save_x -= 600;
			&player_map += 1;
		}
		else
		{
			goto simplesave;
		}
	}

	if(inside_box(&save_x, &save_y, 20, 0, 619, 399) != 1)
	{
		debug("Tree on screen &arg3, x=&arg1 y=&arg2 is WAY out of bounds!");
		goto markend;
	}

	&save_x /= 2;
	&save_y /= 2;
	&save_y *= 300;
	&save_x += &save_y;

	&save_y = 99;
	markloop:
	if(editor_frame(&save_y, -1) == 255)
	{
		if(editor_seq(&save_y, -1) == &save_x)
		{
			debug("mark_burned(&arg1, &arg2, &arg3): tree was already burned");
			goto markend;
		}
	}
	if(editor_frame(&save_y, -1) == 0)
	{
		if(editor_seq(&save_y, -1) == 0)
		{
			//Found unused editor slot
			editor_frame(&save_y, 255);
			editor_seq(&save_y, &save_x);
			goto markend;
		}
	}
	&save_y -= 1;
	//Editor slots don't have to be limited 50-99 range, but hopefully this makes is less likely to screw up anything
	if(&save_y > 49)
	{
		goto markloop;
	}
	else
	{
		debug("Could not find unused editor slot on screen &player_map.");
	}

	markend:

	&player_map = &arg3;
	&save_x = &arg1;
	&save_y = &arg2;
	return;

	simplesave:
	&save_x = sp_editor_num(&current_sprite);
	if (&save_x != 0)
	{
		editor_type(&save_x, 4);
		editor_seq(&save_x, 20);
		editor_frame(&save_x, 29);
	}
	&save_x = &arg1;
	&save_y = &arg2;
	return;

}


Edit: fixed computation of stored editor_seq
Edit2: Removed load_screen()'s
July 26th 2024, 10:58 PM
custom_robj.png
Robj
Jester He/Him Australia
You feed the madness, and it feeds on you. 
You don't need load_screen() to check editor information, you only need to change &player_map. Best to not use any screen loading at all if you don't have to so it has the least chance to mess with the current screen

July 27th 2024, 10:19 AM
death.gif
Seseler
Peasant He/Him Heard Island And Mcdonald Islands
 
Thanks, that's good to know.