;/*
sc RESOPT IGNORE=73 DATA=NEAR NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE ScreenFall.c
slink from LIB:c.o ScreenFall.o to //Clients/ScreenFall LIB LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD STRIPDEBUG NOICONS
delete ScreenFall.o
quit

 ScreenFall 1.0  (Client for BServer)

 Copyright © 1995 Stefano Reksten of 3AM - The Three Amigos!!!
 All rights reserved.
*/

#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuitionbase.h>

#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>

#include "/include/client.h"

char *ver = "$VER: ScreenFall 1.2 "__AMIGADATE__;

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct DisplayIDInformation *dinfo;

void ScreenFall( void )
{
struct Screen *blackscr, *scr, *tmpscr;
UWORD scrtop, scrfall;
UBYTE gravity;
BOOL StillBlanking = TRUE, StillDropping = TRUE;

if ( blackscr = OpenScreenTags( NULL,
	SA_Depth, 0,
	SA_Behind, TRUE,
	SA_DisplayID, DISPLAYID( dinfo ),
	TAG_END ) )
	{
	register struct ViewPort *vp = &(blackscr->ViewPort);

	SetRGB4( vp, 0, 0, 0, 0 );

	scr = IntuitionBase->FirstScreen;
	scrtop = scr->TopEdge;
	scrfall = 0;
	gravity = 1;

	while( StillDropping && StillBlanking )
		{
		StillBlanking = ( GetServerCommand() == COMMAND_IDLE );

		if ( scrtop + scrfall <= scr->Height )
			{
			MoveScreen( scr, 0, gravity );
			scrfall += gravity;
			gravity++;
			}
		else
			{
			tmpscr = scr->NextScreen;
			ScreenToBack( scr );
			MoveScreen( scr, 0, - scrfall );
			scr = tmpscr;
			scrtop = scr->TopEdge;
			scrfall = 0;
			gravity = 1;
			if ( scr == blackscr )
				StillDropping = FALSE;
			}
		}

	if ( StillBlanking )
		{
		SpritesOff();
		WaitServerCommand();
		SpritesOn();
		}
	else
		{
		ScreenToBack( scr );
		MoveScreen( scr, 0, - scrfall );
		while ( scr != blackscr )
			{
			scr = IntuitionBase->FirstScreen;
			ScreenToBack( scr );
			}
		}

	CloseScreen( blackscr );
	}
else
	SendClientMsg( ACTION_FAILED );
}


void __main( char *line )
{
if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
	{
	if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
		{
		if ( dinfo = OpenCommunication() )
			{
			ScreenFall();
			CloseCommunication( dinfo );
			}
		CloseLibrary( (struct Library *)GfxBase );
		}
	CloseLibrary( (struct Library *)IntuitionBase );
	}
}
