#define INC_EXEC
#define INC_DOS
#define INC_GRAPHICS
#define INC_INTUITION
#define NO_BASE

#include ".H:macros.h"
#include ".H:game.h"

/*-------------------------------------------------------------------------*/

EXTERN SCR *drawscr = NL;
EXTERN SCR_BUF *buf[ NUMBUF ] = {NL,NL};

EXTERN ULONG drawsig = NL;
EXTERN ULONG usersig = NL;
EXTERN MSG_PORT *drawport = NL;
EXTERN MSG_PORT *userport = NL;

EXTERN BIT_MAP_OBJ *bmo_cur= NL;

EXTERN ULONG RangeSeed;

/*-------------------------------------------------------------------------*/

ULONG current=NL, nextdraw=NL, nextswap=NL;

ULONG dbuf_status[ NUMBUF ]= {NL,NL};
ULONG draw_status=DRAW;
ULONG scro_status=WAIT;

ULONG nbmo=NL; /* num of curent bitmapobject */

/*-------------------------------------------------------------------------*/

EXTERN VOID InitAllLib( VOID );
EXTERN VOID UnInitAllLib( VOID );
EXTERN VOID InitIntuition( VOID );
EXTERN VOID UnInitIntuition( VOID );
EXTERN BOOL HandleUserMsg( INTUI_MSG *usermsg );
EXTERN VOID InitAllBitMap( VOID );
EXTERN VOID UnInitAllBitMap( VOID );
EXTERN VOID Redraw( BIT_MAP_OBJ *obj ,ULONG n, WORD mousex, WORD mousey );

VOID main( VOID );
VOID bye( ULONG n);
VOID wbmain(VOID){ main(); }

/*-------------------------------------------------------------------------*/

VOID main( VOID )
{
BOOL end = FALSE;
ULONG sig=0,debug=0;
UWORD x,y;

InitAllLib();

FindMyTask();
InitCel();
InitAllBitMap();

InitIntuition();

current = 0;
nextdraw = 1;
nextswap = 1;

dbuf_status[ 0 ] = OK_REDRAW;
dbuf_status[ 1 ] = OK_REDRAW;
draw_status = DRAW;

WHILE( end==FALSE )
{
INTUI_MSG *usermsg;
MSG *drawmsg;

IF( sig & usersig )
{
WHILE( usermsg =(INTUI_MSG *) GT_GetIMsg( userport ) )
{
end=HandleUserMsg( usermsg );
GT_ReplyIMsg( usermsg );
}
}

IF( sig & drawsig )
{
WHILE( drawmsg =(MSG *) GetMsg( drawport ) )
{
REGISTER current=NL;
current=( ULONG )*( ( APTR ** )( drawmsg+1 ));
dbuf_status[ current^1 ] = OK_REDRAW;
}
}

GetStatus( bmo_cur );

IF( draw_status != WAIT OR scro_status== DRAW ) /* Donc draw_status==DRAW|REFR|SCRO|SMOU */
{
IF( dbuf_status[ nextdraw ] == OK_REDRAW )
{
IF( draw_status==SCRO )
{
Scroll( nextdraw );
DrawBgd( nextdraw );
scro_status=DRAW;
draw_status=REFR;
}ELSE

IF( scro_status==DRAW )
{
REGISTER BOOL smouted=Smout( nextdraw );
DrawBgd( nextdraw );
IF( smouted == TRUE ) scro_status=WAIT;
} ELSE

IF( draw_status==DRAW )
{
DrawBgd( nextdraw );
DrawObj( bmo_cur, nextdraw );
draw_status=REFR;
} ELSE

IF( draw_status==REFR )
{
DrawBgd( nextdraw );
draw_status=WAIT;
}

dbuf_status[ nextdraw ] = OK_SWAPIN;
nextdraw ^= 1;
}
IF( dbuf_status[ nextswap ] == OK_SWAPIN )
{
buf[nextswap]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=drawport;
WaitBlit();
IF( ChangeScreenBuffer( drawscr, buf[ nextswap ] ) )
{
dbuf_status[ nextswap ] = 0;
current = nextswap;
nextswap ^= 1;
}
ELSE
{
WaitTOF();
}
}
sig = Wait( drawsig | usersig );
}
}
bye( 0 );
}

VOID bye( ULONG n)
{
UnInitIntuition();
UnInitAllBitMap();
UnInitAllLib();
exit(n);
}

/* menu.c */
#define INC_GRAPHICS
#define INC_INTUITION
#define INC_GADTOOLS
#define NO_BASE

#include ".H:macros.h"
#include ".H:game.h"

/*-------------------------------------------------------------------------*/

EXTERN ULONG nbmo; /* num of curent bitmapobject */
EXTERN LONG stepx, stepy; /* offset of scroll */
EXTERN WIN *userwin;

EXTERN BIT_MAP_OBJ *roads[13];

EXTERN BIT_MAP_OBJ *house[8];
EXTERN BIT_MAP_OBJ *comme[8];
EXTERN BIT_MAP_OBJ *indus[8];
EXTERN BIT_MAP_OBJ *agric[8];

EXTERN BIT_MAP_OBJ *base[4];

EXTERN BIT_MAP_OBJ *bmo_cur;

EXTERN GAD ga_house;
EXTERN GAD ga_agric;
EXTERN GAD ga_comme;
EXTERN GAD ga_indus;
EXTERN GAD ga_rails;
EXTERN GAD ga_roads;
EXTERN GAD ga_polic;
EXTERN GAD ga_pompi;
EXTERN GAD ga_avion;
EXTERN GAD ga_batea;
EXTERN GAD ga_ecolo;
EXTERN GAD ga_money;

EXTERN GAD *ga_click;

/*-------------------------------------------------------------------------*/

MENU *menu = NL;

MENU_NEW nm[] ={
{ NM_TITLE," Game ", NL, NL, NL, NL, },
{ NM_ITEM, " Restart this game ", NL, NL, NL, ( APTR ) MENU_RESTART,},
{ NM_ITEM, " Load... ", NL, NL, NL, ( APTR ) MENU_LOAD, },
{ NM_ITEM, " Save... ", NL, NL, NL, ( APTR ) MENU_SAVE, },
{ NM_ITEM, " About. ", NL, NL, NL, ( APTR ) MENU_ABOUT, },
{ NM_ITEM, NM_BARLABEL, NL, NL, NL, NL, },
{ NM_ITEM, " Quit. ", NL, NL, NL, ( APTR ) MENU_QUIT, },
{ NM_TITLE," Scroll ", NL, NL, NL, NL, },
{ NM_ITEM, " + ", NL, NL, NL, ( APTR ) MENU_SINC, },
{ NM_ITEM, " - ", NL, NL, NL, ( APTR ) MENU_SDEC, },
{ NM_END, NL, NL, NL, NL, NL, },
};

VOID ExcludeGadget( ULONG type );

/*-------------------------------------------------------------------------*/

BOOL HandleUserMsg( INTUI_MSG *usermsg )
{
REGISTER code = NL;
BOOL end = FALSE;

code = usermsg->Code;
ga_click= ( GAD * ) usermsg->IAddress;

SWITCH( usermsg->Class )
{
CASE IDCMP_MENUPICK:
{
MENU_ITEM *item;
item = (MENU_ITEM *)ItemAddress(menu,code);

WHILE( code != MENUNULL )
{
SWITCH( (ULONG) GTMENUITEM_USERDATA( item ) )
{
CASE MENU_RESTART: BREAK;
CASE MENU_LOAD: BREAK;
CASE MENU_SAVE: BREAK;
CASE MENU_QUIT: end = TRUE; BREAK;
CASE MENU_SINC: stepx++; stepy++; BREAK;
CASE MENU_SDEC: stepx--; stepy--; BREAK;
}
code = item->NextSelect;
}
}
CASE IDCMP_GADGETUP:
CASE IDCMP_GADGETDOWN:
{
switch ( ga_click->GadgetID )
{
CASE GA_HOUSE: ExcludeGadget(GA_HOUSE); bmo_cur=base[0]; BREAK;
CASE GA_COMME: ExcludeGadget(GA_COMME); bmo_cur=base[1]; BREAK;
CASE GA_INDUS: ExcludeGadget(GA_INDUS); bmo_cur=base[2]; BREAK;
CASE GA_AGRIC: ExcludeGadget(GA_AGRIC); bmo_cur=base[3]; BREAK;
CASE GA_AVION: ExcludeGadget(GA_AVION); BREAK;
CASE GA_BATEA: ExcludeGadget(GA_BATEA); BREAK;
CASE GA_ECOLO: ExcludeGadget(GA_ECOLO); BREAK;
CASE GA_MONEY: ExcludeGadget(GA_MONEY); BREAK;
CASE GA_POLIC: ExcludeGadget(GA_POLIC); BREAK;
CASE GA_POMPI: ExcludeGadget(GA_POMPI); BREAK;
CASE GA_RAILS: ExcludeGadget(GA_RAILS); BREAK;
CASE GA_ROADS: ExcludeGadget(GA_ROADS); bmo_cur=roads[4]; BREAK;
} BREAK;
} BREAK;
}
RETURN(end);
}

VOID ExcludeGadget( ULONG type )
{
IF( (ga_house.GadgetID != type) AND (ga_house.Flags ANDBIT GFLG_SELECTED) ){ ga_house.Flags &=~ GFLG_SELECTED; }
IF( (ga_agric.GadgetID != type) AND (ga_agric.Flags ANDBIT GFLG_SELECTED) ){ ga_agric.Flags &=~ GFLG_SELECTED; }
IF( (ga_comme.GadgetID != type) AND (ga_comme.Flags ANDBIT GFLG_SELECTED) ){ ga_comme.Flags &=~ GFLG_SELECTED; }
IF( (ga_indus.GadgetID != type) AND (ga_indus.Flags ANDBIT GFLG_SELECTED) ){ ga_indus.Flags &=~ GFLG_SELECTED; }
IF( (ga_rails.GadgetID != type) AND (ga_rails.Flags ANDBIT GFLG_SELECTED) ){ ga_rails.Flags &=~ GFLG_SELECTED; }
IF( (ga_roads.GadgetID != type) AND (ga_roads.Flags ANDBIT GFLG_SELECTED) ){ ga_roads.Flags &=~ GFLG_SELECTED; }
IF( (ga_polic.GadgetID != type) AND (ga_polic.Flags ANDBIT GFLG_SELECTED) ){ ga_polic.Flags &=~ GFLG_SELECTED; }
IF( (ga_pompi.GadgetID != type) AND (ga_pompi.Flags ANDBIT GFLG_SELECTED) ){ ga_pompi.Flags &=~ GFLG_SELECTED; }
IF( (ga_avion.GadgetID != type) AND (ga_avion.Flags ANDBIT GFLG_SELECTED) ){ ga_avion.Flags &=~ GFLG_SELECTED; }
IF( (ga_batea.GadgetID != type) AND (ga_batea.Flags ANDBIT GFLG_SELECTED) ){ ga_batea.Flags &=~ GFLG_SELECTED; }
IF( (ga_ecolo.GadgetID != type) AND (ga_ecolo.Flags ANDBIT GFLG_SELECTED) ){ ga_ecolo.Flags &=~ GFLG_SELECTED; }
IF( (ga_money.GadgetID != type) AND (ga_money.Flags ANDBIT GFLG_SELECTED) ){ ga_money.Flags &=~ GFLG_SELECTED; }

RefreshGList( &ga_money, userwin, NL, -1);
}

/* lib.c */
#define INC_EXEC
#define INC_GRAPHICS
#define INC_INTUITION
#define INC_GADTOOLS
#define INC_FONT

#include ".H:macros.h"

/*-------------------------------------------------------------------------*/

VOID InitAllLib( VOID )
{
OpenExec();
OpenGraphics();
OpenIntuition();
OpenGadtools();
OpenFontDisk();
}

/*-------------------------------------------------------------------------*/

VOID UnInitAllLib( VOID )
{
CloseFontDisk();
CloseGadtools();
CloseIntuition();
CloseGraphics();
CloseExec();
}

/*-------------------------------------------------------------------------*/

/* init.c */
#define INC_EXEC
#define INC_GRAPHICS
#define INC_INTUITION
#define INC_GADTOOLS
#define INC_UTILITY
#define INC_FONT

#define NO_BASE

#include ".H:macros.h"
#include ".H:game.h"

/*-------------------------------------------------------------------------*/

EXTERN BIT_MAP *userbg = NL;
EXTERN MENU *menu;
EXTERN MENU_NEW nm[];
EXTERN GAD ga_money;
EXTERN CEL celbgnd[120][81]; /* drawbm WIDTH , HEIGHT */

/*-------------------------------------------------------------------------*/

#define DSCR_ID (DEFAULT_MONITOR_ID|LORES_KEY)
#define USCR_ID (DEFAULT_MONITOR_ID|LORES_KEY)

TAG drawvc[] = {VTAG_BORDERSPRITE_SET,TRUE,VTAG_SPRITERESN_SET,SPRITERESN_70NS,0};
TAG uservc[] = {VTAG_BORDERSPRITE_SET,TRUE,VTAG_SPRITERESN_SET,SPRITERESN_70NS,0};
SCR *drawscr = NL;
SCR *userscr = NL; /* SPRITERESN_ECS 0 */
WIN *drawwin = NL; /* SPRITERESN_140NS 1 */
WIN *userwin = NL; /* SPRITERESN_70NS 2 */
APTR drawvi = NL; /* SPRITERESN_35NS 3 */
APTR uservi = NL; /* SPRITERESN_DEFAULT -1 */
ULONG drawsig = NL;
ULONG usersig = NL;
MSG_PORT *drawport = NL;
MSG_PORT *userport = NL;

TEXT_FONT *tfont = NL;
TEXT_ATTR font = { ( STRPTR )"topaz.font", 8, 0x00, 0x00 };

SCR_BUF *buf[ NUMBUF ] = {NL,NL};
RAST_PORT *rp [ NUMBUF ] = {NL,NL};

/*-------------------------------------------------------------------------*/

ULONG palette32[98] ={
0x00200000, /* Record Header */
0x05555555,0x06666666,0x06666666,
0x22222222,0x28888888,0x28888888,
0x44444444,0x50000000,0x50000000,
0x66666666,0x78888888,0x78888888,
0x86666666,0x9EEEEEEE,0x9EEEEEEE,
0xA9999999,0xC7777777,0xC7777777,
0xCBBBBBBB,0xEFFFFFFF,0xEFFFFFFF,
0xD4444444,0xF9999999,0xF9999999,
0xD4444444,0xF9999999,0xF9999999,
0xD4444444,0xF9999999,0x06666666,
0x74444444,0xC6666666,0xF9999999,
0x22222222,0x9EEEEEEE,0xF9999999,
0x05555555,0x86666666,0xE1111111,
0x05555555,0x78888888,0xC9999999,
0xD4444444,0x57777777,0x58888888,
0x52222222,0x32222222,0x06666666,
0x78888888,0x58888888,0x13333333,
0xA1111111,0x82222222,0x23333333,
0xCBBBBBBB,0xB0000000,0x37777777,
0x39999999,0xF8888888,0x3EEEEEEE,
0x22222222,0xBBBBBBBB,0x23333333,
0x0AAAAAAA,0x80000000,0x09999999,
0xD4444444,0x88888888,0x55555555,
0x2FFFFFFF,0xB0000000,0xF9999999,
0x2BBBBBBB,0xCCCCCCCC,0x2EEEEEEE,
0xB6666666,0x9AAAAAAA,0x48888888,
0xA5555555,0x3EEEEEEE,0x3EEEEEEE,
0xD4444444,0xF9999999,0x06666666,
0xD4444444,0xF9999999,0x06666666,
0xD4444444,0xF9999999,0x06666666,
0xD4444444,0xF9999999,0x06666666,
0xD4444444,0xF9999999,0x06666666,
0x00000000 /* Terminator */
};

UWORD pens[] ={
0, /* DETAILPEN */
4, /* BLOCKPEN */
0, /* TEXTPEN */
6, /* SHINEPEN */
2, /* SHADOWPEN */
4, /* FILLPEN */
1, /* FILLTEXTPEN */
4, /* BACKGROUNDPEN */
7, /* HIGHLIGHTTEXTPEN */
6, /* BARDETAILPEN */
13, /* BARBLOCKPEN */
13, /* BARTRIMPEN */
~0,};

/*-------------------------------------------------------------------------*/

VOID InitIntuition( VOID );
VOID fill( WORD c, WORD x, WORD y, WORD w, WORD h);
VOID UnInitIntuition( VOID );

/*-------------------------------------------------------------------------*/

VOID InitIntuition( VOID )
{
REGISTER x=NL,y=NL;

NewFont(tfont,font);

OpenMsgPort( userport ); usersig=GetSig( userport );
OpenMsgPort( drawport ); drawsig=GetSig( drawport );

drawscr=(SCR *)OpenScrTag( SA_VideoControl, drawvc,
SA_DisplayID, DSCR_ID,
SA_Left, DSCR_LEFT,
SA_Top, DSCR_TOP,
SA_Width, DSCR_WIDTH,
SA_Height, DSCR_HEIGHT,
SA_Depth, DSCR_DEPTH,
SA_Title, "Draw Screen",
SA_Type, CUSTOMSCREEN,
SA_Draggable, FALSE,
SA_Interleaved, TRUE,
SA_Pens, pens,
SA_Colors32, &palette32[0],
SA_Font, &font, TAG_DONE);
GetVI(drawvi,drawscr);

userscr=(SCR *)OpenScrTag( SA_Parent, drawscr,
SA_VideoControl, uservc,
SA_DisplayID, USCR_ID,
SA_Left, USCR_LEFT,
SA_Top, USCR_TOP,
SA_Width, USCR_WIDTH,
SA_Height, USCR_HEIGHT,
SA_Depth, USCR_DEPTH,
SA_ShowTitle, FALSE,
SA_Quiet, TRUE,
SA_Draggable, FALSE,
SA_Interleaved, TRUE,
SA_Pens, pens,
SA_Colors32, &palette32[0],
SA_Font, &font,
TAG_DONE );
GetVI(uservi,userscr);

drawwin=(WIN *)OpenWinTag( WA_CustomScreen, drawscr,
WA_NoCareRefresh, TRUE,
WA_Activate, TRUE,
WA_Borderless, TRUE,
WA_Backdrop, TRUE,
WA_NewLookMenus, TRUE,
TAG_DONE);

drawwin->UserPort=userport;
ModifyIDCMP( drawwin, IDCMP_MENUPICK );

userwin=(WIN *)OpenWinTag( WA_CustomScreen, userscr,
WA_NoCareRefresh, TRUE,
WA_Activate, TRUE,
WA_Borderless, TRUE,
WA_Backdrop, TRUE,
WA_NewLookMenus, TRUE,
WA_SuperBitMap, userbg,
WA_Gadgets, &ga_money,
TAG_DONE);

userwin->UserPort=userport;
ModifyIDCMP( userwin, IDCMP_MENUPICK | IDCMP_GADGETDOWN | IDCMP_GADGETUP );

NewMenu(menu,nm,drawvi,drawwin);
CloneMenu(drawwin,userwin);

NewScrBuf(buf[0],drawscr,NL,SB_SCREEN_BITMAP, 0 );
NewScrBuf(buf[1],drawscr,NL,SB_COPY_BITMAP , 1 );

NewChip( rp[0], RAST_PORT ); InitRastPort( rp[0] );
NewChip( rp[1], RAST_PORT ); InitRastPort( rp[1] );

rp[0]->BitMap=buf[0]->sb_BitMap;
rp[1]->BitMap=buf[1]->sb_BitMap;

SetDrMd( rp[0], JAM1 );
SetDrMd( rp[1], JAM1 );

fill( 4, 0, 12, 319, 199 );
fill( 6, 0, 12, 318, 12 );
fill( 6, 0, 12, 0, 198 );
fill( 2, 1, 199, 319, 199 );
fill( 2, 319, 13, 319, 199 );
fill( 5, 1, 13, 317, 13 );
fill( 5, 1, 13, 1, 197 );
fill( 3, 2, 198, 318, 198 );
fill( 3, 318, 15, 318, 198 );
fill( 2, 6, 15, 236, 15 );
fill( 2, 6, 15, 6, 195 );
fill( 6, 7, 196, 237, 196 );
fill( 6, 237, 16, 237, 196 );

SetAPen( rp[0], 6 ); /* blanco.*/
SetAPen( rp[1], 6 );

FOR(x=0;x<120;x+=2)
{
FOR(y=0;y<81;y+=2)
{
IF( celbgnd[x][y].type == BROUS )
{
SetAPen( userwin->RPort, 20 ); /* VERT */
}
ELSE
IF( celbgnd[x][y].type == FLOTS )
{
SetAPen( userwin->RPort, 11 ); /* BLEU */
}
ELSE
{
SetAPen( userwin->RPort, 17 ); /* MARRON */
}
WritePixel( userwin->RPort, (x/2)+4 , (y/2)+4 );
}
}
}

/*-------------------------------------------------------------------------*/

VOID fill( WORD c, WORD x, WORD y, WORD w, WORD h)
{
SetAPen( rp[0], c );
RectFill( rp[0],x,y,w,h);

SetAPen( rp[1], c );
RectFill( rp[1],x,y,w,h);
}

/*-------------------------------------------------------------------------*/

VOID UnInitIntuition( VOID )
{
UnCloneMenu(userwin);
RemMenu(menu,drawwin);

CloseWin( userwin );
CloseWin( drawwin );

CloseScr( userscr );
CloseScr( drawscr );

CloseMsgPort( drawport );
CloseMsgPort( userport );

RemVI( drawvi );
RemVI( uservi );

RemScrBuf( buf[0], drawscr );
RemScrBuf( buf[1], drawscr );

RemMem( rp[0], RAST_PORT );
RemMem( rp[1], RAST_PORT );

RemFont( tfont );
}

/*-------------------------------------------------------------------------*/

/* draw.c */

#define INC_GRAPHICS
#define INC_INTUITION
#define NO_BASE

#include ".H:macros.h"
#include ".H:game.h"

EXTERN RAST_PORT *rp [ NUMBUF ];
EXTERN WIN *drawwin;
EXTERN WIN *userwi;

EXTERN ULONG draw_status;

EXTERN CEL celbgnd[120][81]; /* drawbm WIDTH , HEIGHT */
EXTERN CEL celview[23][18]; /* VIEW WIDTH , HEIGHT */

EXTERN BIT_MAP_OBJ *drawbg;

EXTERN BIT_MAP_OBJ *roads[13];
EXTERN BIT_MAP_OBJ *house[8] ;
EXTERN BIT_MAP_OBJ *comme[8] ;
EXTERN BIT_MAP_OBJ *indus[8] ;
EXTERN BIT_MAP_OBJ *agric[8] ;
EXTERN BIT_MAP_OBJ *base[4] ;

LONG sx=NL,sy=NL; /* scroll x,y */
LONG mx=NL,my=NL; /* mouse x,y */

LONG stepx=5,stepy=5;
ULONG click=FALSE;

VOID GetStatus( BIT_MAP_OBJ *obj );
VOID DrawBgd( SHORT bufn );
VOID Scroll( SHORT bufn );
BOOL Smout( SHORT bufn );
VOID DrawObj( BIT_MAP_OBJ *obj ,USHORT bufn);
BOOL SetRoads( WORD bgposx, WORD bgposy );

/*-------------------------------------------------------------------------*/

VOID GetStatus( BIT_MAP_OBJ *obj )
{
REGISTER BYTE hwmx=NL,hwmy=NL;
REGISTER UBYTE button=NL;

mx = drawwin->MouseX;
my = drawwin->MouseY;

button=Mouse(&hwmx,&hwmy);

IF ( mx >= VIEW_LEFT AND mx <= VIEW_WIDTH + VIEW_LEFT AND /* mouse in the view */
my >= VIEW_TOP AND my <= VIEW_HEIGHT + VIEW_TOP)
{
draw_status=DRAW;
IF( button ANDBIT LEFT_BUTTON ) click=TRUE;
}

sx=NL;sy=NL;

IF ( mx == MOUSE_LEFT ) { sx=-stepx; draw_status=SCRO; SetTask40(); } ELSE
IF ( mx == MOUSE_RIGHT ) { sx=+stepx; draw_status=SCRO; SetTask40(); }

IF ( my == MOUSE_TOP ) { sy=-stepy; draw_status=SCRO; SetTask40(); } ELSE
IF ( my == MOUSE_BOTTOM ) { sy=+stepy; draw_status=SCRO; SetTask40(); }

IF(( mx == MOUSE_LEFT AND hwmx > 0 ) OR
( mx == MOUSE_RIGHT AND hwmx < 0 ) OR
( my == MOUSE_TOP AND hwmy > 0 ) OR
( my == MOUSE_BOTTOM AND hwmy < 0 ) )
{
SetTask10();
}
}

/*-------------------------------------------------------------------------*/

VOID DrawBgd( SHORT bufn )
{
BltBitMapRastPort(drawbg->bm,drawbg->posx,drawbg->posy,rp[bufn],VIEW_LEFT,VIEW_TOP,VIEW_WIDTH,VIEW_HEIGHT,BLIT);
}

/*-------------------------------------------------------------------------*/

VOID Scroll( SHORT bufn )
{
REGISTER WORD *bgposx=&drawbg->posx;
REGISTER WORD *bgposy=&drawbg->posy;

*bgposx += sx;
*bgposy += sy;

IF( *bgposx < 0 ){ *bgposx = 0; } ELSE
IF( *bgposx > drawbg->w-VIEW_WIDTH ){ *bgposx = drawbg->w-VIEW_WIDTH; }
IF( *bgposy < 0 ){ *bgposy = 0; } ELSE
IF( *bgposy > drawbg->h-VIEW_HEIGHT ){ *bgposy = drawbg->h-VIEW_HEIGHT;}

}

/*-------------------------------------------------------------------------*/

BOOL Smout( SHORT bufn )
{
REGISTER WORD *bgposx=&drawbg->posx;
REGISTER WORD *bgposy=&drawbg->posy;

WORD x=(*bgposx/10);
WORD y=(*bgposy/10);

WORD statusx=FALSE;
WORD statusy=FALSE;

IF( celbgnd[x][y].posx != *bgposx )
{
*bgposx += ( *bgposx - celbgnd[x][y].posx > 4 ? +1 : -1 );
statusx=FALSE;
}
ELSE { statusx=TRUE; }

IF( celbgnd[x][y].posy != *bgposy )
{
*bgposy += ( *bgposy - celbgnd[x][y].posy > 4 ? +1 : -1 );
statusy=FALSE;
}
ELSE { statusy=TRUE; }

BltBitMapRastPort(drawbg->bm,*bgposx,*bgposy,rp[bufn],VIEW_LEFT,VIEW_TOP,VIEW_WIDTH,VIEW_HEIGHT,BLIT);

IF( statusx != TRUE OR statusy != TRUE )
{
RETURN(FALSE);
}
ELSE { RETURN(TRUE); }
}

/*-------------------------------------------------------------------------*/

VOID DrawObj( BIT_MAP_OBJ *obj ,USHORT bufn )
{
REGISTER UWORD ocw=obj->cw,och=obj->ch;

UWORD mousex=mx, mousey=my,x=NL,y=NL,ix=NL,iy=NL;

UWORD posx=NL,posy=NL,bgposx=NL,bgposy=NL;

UWORD isinbg=TRUE,pen[4];

IF( mousex <= VIEW_LEFT + ocw ) { /* gere le positionnement obj in view */
mousex = VIEW_LEFT + ocw;
}
IF( mousex >= ( VIEW_LEFT + VIEW_WIDTH ) - ocw ) {
mousex = ( VIEW_LEFT + VIEW_WIDTH ) - ocw;
}
IF( mousey <= VIEW_TOP + och ) {
mousey = VIEW_TOP + och;
}
IF( mousey >= ( VIEW_TOP + VIEW_HEIGHT ) - och ) {
mousey = ( VIEW_TOP + VIEW_HEIGHT ) - och;
}

obj->posx=mousex-ocw;
obj->posy=mousey-och;

posx=(obj->posx-VIEW_LEFT+4)/10;
posy=(obj->posy-VIEW_TOP +4)/10;

bgposx=(drawbg->posx+(obj->posx-VIEW_LEFT+4))/10;
bgposy=(drawbg->posy+(obj->posy-VIEW_TOP +4))/10;

ix=(obj->w/10)-1;
iy=(obj->h/10)-1;

x=celview[posx][posy].posx;
y=celview[posx][posy].posy;

pen[0]=6;pen[1]=6;pen[2]=6;pen[3]=6;

IF( celbgnd[bgposx][bgposy].type != TERRE AND
celbgnd[bgposx][bgposy].type != BROUS )
{
isinbg=FALSE;
pen[0]=14;
}

IF( celbgnd[bgposx+ix][bgposy].type != TERRE AND
celbgnd[bgposx+ix][bgposy].type != BROUS )
{
isinbg=FALSE;
pen[1]=14;
}

IF( celbgnd[bgposx][bgposy+iy].type != TERRE AND
celbgnd[bgposx][bgposy+iy].type != BROUS )
{
isinbg=FALSE;
pen[2]=14;
}

IF( celbgnd[bgposx+ix][bgposy+iy].type != TERRE AND
celbgnd[bgposx+ix][bgposy+iy].type != BROUS )
{
isinbg=FALSE;
pen[3]=14;
}

IF( isinbg == TRUE )
{
IF( click == TRUE )
{
BOOL result=FALSE;
UWORD x=NL,y=NL;

IF( obj->type >= ROAD0 AND obj->type <= ROAD12 )
{
result=SetRoads( bgposx, bgposy );
}
ELSE
{
BltBMO(obj,drawbg,celbgnd[bgposx][bgposy].posx,celbgnd[bgposx][bgposy].posy);

FOR( x = 0; x <= ix; x++ )
{
FOR( y = 0; y <= iy; y++ )
{
celbgnd[bgposx+x][bgposy+y].type = obj->type;
}
}
}
click=FALSE;
}
}
ELSE { click=FALSE; }

SetAPen( rp[bufn], pen[0] );

WritePixel( rp[bufn], x , y ); /* the user pos indicator */
WritePixel( rp[bufn], x+1 , y );
WritePixel( rp[bufn], x , y+1 );

SetAPen( rp[bufn], pen[1] );

WritePixel( rp[bufn], x+obj->w-1 , y );
WritePixel( rp[bufn], x+obj->w-1-1 , y );
WritePixel( rp[bufn], x+obj->w-1 , y+1 );

SetAPen( rp[bufn], pen[2] );

WritePixel( rp[bufn], x , y+obj->h-1 );
WritePixel( rp[bufn], x , y+obj->h-1-1 );
WritePixel( rp[bufn], x+1 , y+obj->h-1 );

SetAPen( rp[bufn], pen[3] );

WritePixel( rp[bufn], x+obj->w-1 , y+obj->h-1 );
WritePixel( rp[bufn], x+obj->w-1-1 , y+obj->h-1 );
WritePixel( rp[bufn], x+obj->w-1 , y+obj->h-1-1 );

BltBitMapRastPort(obj->bm,0,0,rp[bufn],obj->posx,obj->posy,obj->w,obj->h,BLIT);
}

/*-------------------------------------------------------------------------*/

#define IN(n) ( c[n]->type >= ROAD0 AND c[n]->type <= ROAD12 )
#define OUT(n) ( c[n]->type < ROAD0 OR c[n]->type > ROAD12 )
#define IS(n,t) ( c[n]->type == t )
#define ISNOT(n,t) ( c[n]->type != t )
#define SET(n,t) { c[n]->type = t; }

BOOL SetRoads( WORD bgposx, WORD bgposy )
{
CEL *c[9];
SHORT x=0,y=0,ok=FALSE;

c[0] =(CEL *) &celbgnd[bgposx-1][bgposy-1];
c[1] =(CEL *) &celbgnd[bgposx-1][bgposy ];
c[2] =(CEL *) &celbgnd[bgposx-1][bgposy+1];

c[3] =(CEL *) &celbgnd[bgposx ][bgposy-1];
c[4] =(CEL *) &celbgnd[bgposx ][bgposy ]; /* center */
c[5] =(CEL *) &celbgnd[bgposx ][bgposy+1];

c[6] =(CEL *) &celbgnd[bgposx+1][bgposy-1];
c[7] =(CEL *) &celbgnd[bgposx+1][bgposy ];
c[8] =(CEL *) &celbgnd[bgposx+1][bgposy+1];

IF( OUT(1) AND OUT(3) AND OUT(5) AND OUT(7))
{ /* A0 */
SET(4,ROAD4);
} ELSE
IF( OUT(0) AND OUT(3) AND OUT(2) AND OUT(5) AND
IS(1,ROAD3) OR IS(1,ROAD4) )
{ /* A1 */
SET(4,ROAD3);
SET(1,ROAD3);
} ELSE

IF( OUT(0) AND OUT(1) AND OUT(6) AND OUT(7) AND
IS(3,ROAD1) OR IS(3,ROAD4) )
{ /* A2 */
SET(4,ROAD1);
SET(3,ROAD1);
} ELSE

IF( OUT(1) AND OUT(2) AND OUT(7) AND OUT(8) AND
IS(5,ROAD1) OR IS(5,ROAD4) )
{ /* A3 */
SET(4,ROAD1);
SET(5,ROAD1);
} ELSE

IF( OUT(3) AND OUT(5) AND OUT(6) AND OUT(8) AND
IS(7,ROAD3) OR IS(7,ROAD4) )
{ /* A4 */
SET(4,ROAD3);
SET(7,ROAD3);
}

IF( OUT(3) AND OUT(5) AND IN(0) AND IN(1) AND IN(2) )
{ /* B0 */
SET(4,ROAD3);

IF( IS(1,ROAD1 ) ) { SET(1,ROAD11); } ELSE
IF( IS(1,ROAD9 ) ) { SET(1,ROAD4 ); }
}

IF( OUT(1) AND OUT(7) AND IN(0) AND IN(3) AND IN(6) )
{ /* B1 */
SET(4,ROAD1);

IF( IS(3,ROAD3 ) ) { SET(3,ROAD10); } ELSE
IF( IS(3,ROAD12) ) { SET(3,ROAD4 ); }
}

IF( OUT(1) AND OUT(7) AND IN(2) AND IN(5) AND IN(8) )
{ /* B2 */
SET(4,ROAD1);

IF( IS(5,ROAD3 ) ) { SET(5,ROAD12); } ELSE
IF( IS(5,ROAD10) ) { SET(5,ROAD4 ); }
}

IF( OUT(3) AND OUT(5) AND IN(6) AND IN(7) AND IN(8) )
{ /* B3 */
SET(4,ROAD3);

IF( IS(7,ROAD1 ) ) { SET(7,ROAD9); } ELSE
IF( IS(7,ROAD11) ) { SET(7,ROAD4); }
}

IF( OUT(0) AND OUT(2) AND OUT(6) AND OUT(7) AND OUT(8) AND
IS(1,ROAD3) AND IS(3,ROAD1) AND IS(5,ROAD1) )
{ /* c0 */
SET(4,ROAD9);
} ELSE

IF( OUT(0) AND OUT(2) AND OUT(5) AND OUT(6) AND OUT(8) AND
IS(1,ROAD3) AND IS(3,ROAD1) AND IS(7,ROAD3) )
{ /* c1 */
SET(4,ROAD12);
} ELSE

IF( OUT(0) AND OUT(2) AND OUT(3) AND OUT(6) AND OUT(8) AND
IS(1,ROAD3) AND IS(5,ROAD1) AND IS(7,ROAD3) )
{ /* c2 */
SET(4,ROAD10);
} ELSE

IF( OUT(0) AND OUT(1) AND OUT(2) AND OUT(6) AND OUT(8) AND
IS(3,ROAD1) AND IS(5,ROAD1) AND IS(7,ROAD3) )
{ /* c3 */
SET(4,ROAD11);
} ELSE

IF( OUT(0) AND OUT(2) AND OUT(6) AND OUT(8) AND
IS(1,ROAD3) AND IS(3,ROAD1) AND IS(5,ROAD1) AND IS(7,ROAD3) )
{ /* c4 */
SET(4,ROAD4);
}

IF( OUT(0) AND OUT(2) AND OUT(5) AND OUT(6) AND OUT(7) AND
IS(1,ROAD3) AND IS(3,ROAD1) )
{ /* d0 */
SET(4,ROAD8);
} ELSE

IF( OUT(0) AND OUT(1) AND OUT(5) AND OUT(6) AND OUT(8) AND
IS(3,ROAD1) AND IS(7,ROAD3) )
{ /* d1 */
SET(4,ROAD2);
} ELSE

IF( OUT(1) AND OUT(2) AND OUT(3) AND OUT(6) AND OUT(8) AND
IS(5,ROAD1) AND IS(7,ROAD3) )
{ /* d2 */
SET(4,ROAD0);
} ELSE

IF( OUT(0) AND OUT(2) AND OUT(3) AND OUT(7) AND OUT(8) AND
IS(1,ROAD3) AND IS(5,ROAD1) )
{ /* d3 */
SET(4,ROAD6);
}

IF( OUT(2) AND OUT(3) AND IS(0,ROAD1) AND IS(1,ROAD1) OR IS(1,ROAD8) )
{ /* e0 */
SET(4,ROAD3);

IF( IS(5,ROAD1 ) ) { SET(4,ROAD6 ); }

IF( IS(1,ROAD1 ) ) { SET(1,ROAD2 ); } ELSE
IF( IS(1,ROAD8 ) ) { SET(1,ROAD12); }

IF( IS(7,ROAD11) ) { SET(7,ROAD4 ); } ELSE
IF( IS(7,ROAD0 ) ) { SET(7,ROAD10); } ELSE
IF( IS(7,ROAD2 ) ) { SET(7,ROAD12); }
}

IF( OUT(0) AND OUT(7) AND IS(6,ROAD3) AND IS(3,ROAD3) OR IS(3,ROAD2) )
{ /* e1 */
SET(4,ROAD1);

IF( IS(1,ROAD3 ) ) { SET(4,ROAD8 ); }

IF( IS(3,ROAD3 ) ) { SET(3,ROAD0 ); } ELSE
IF( IS(3,ROAD2 ) ) { SET(3,ROAD11); }

IF( IS(5,ROAD12) ) { SET(5,ROAD4 ); } ELSE
IF( IS(5,ROAD0 ) ) { SET(5,ROAD11); } ELSE
IF( IS(5,ROAD6 ) ) { SET(5,ROAD9 ); }
}

IF( OUT(5) AND OUT(6) AND IS(8,ROAD1) AND IS(7,ROAD1) OR IS(7,ROAD0) )
{ /* e2 */
SET(4,ROAD3);

IF( IS(3,ROAD1 ) ) { SET(4,ROAD2 ); }

IF( IS(7,ROAD1 ) ) { SET(7,ROAD6 ); } ELSE
IF( IS(7,ROAD0 ) ) { SET(7,ROAD10); }

IF( IS(1,ROAD9 ) ) { SET(1,ROAD4 ); } ELSE
IF( IS(1,ROAD6 ) ) { SET(1,ROAD10); } ELSE
IF( IS(1,ROAD8 ) ) { SET(1,ROAD12); }
}

IF( OUT(1) AND OUT(8) AND IS(2,ROAD3) AND IS(5,ROAD3) OR IS(5,ROAD6) )
{ /* e3 */
SET(4,ROAD1);

IF( IS(7,ROAD3 ) ) { SET(4,ROAD0 ); }

IF( IS(5,ROAD3 ) ) { SET(5,ROAD8 ); } ELSE
IF( IS(5,ROAD6 ) ) { SET(5,ROAD9 ); }

IF( IS(3,ROAD12) ) { SET(3,ROAD4 ); } ELSE
IF( IS(3,ROAD2 ) ) { SET(3,ROAD11); } ELSE
IF( IS(3,ROAD8 ) ) { SET(3,ROAD9 ); }
}

IF( OUT(1) AND OUT(6) AND IS(0,ROAD3) AND IS(3,ROAD3) OR IS(3,ROAD8))
{ /* f0 */
SET(4,ROAD1);

IF( IS(7,ROAD3 ) ) { SET(4,ROAD2 ); }

IF( IS(3,ROAD3 ) ) { SET(3,ROAD6 ); } ELSE
IF( IS(3,ROAD8 ) ) { SET(3,ROAD9 ); }

IF( IS(5,ROAD10) ) { SET(5,ROAD4 ); } ELSE
IF( IS(5,ROAD0 ) ) { SET(5,ROAD11); } ELSE
IF( IS(5,ROAD6 ) ) { SET(5,ROAD9 ); }
}

IF( OUT(3) AND OUT(8) AND IS(6,ROAD1) AND IS(7,ROAD1) OR IS(7,ROAD2) )
{ /* f1 */
SET(4,ROAD3);

IF( IS(5,ROAD1 ) ) { SET(4,ROAD0 ); }

IF( IS(7,ROAD1 ) ) { SET(7,ROAD8 ); } ELSE
IF( IS(7,ROAD2 ) ) { SET(7,ROAD12); }

IF( IS(1,ROAD9 ) ) { SET(1,ROAD4 ); } ELSE
IF( IS(1,ROAD8 ) ) { SET(1,ROAD12); } ELSE
IF( IS(1,ROAD6 ) ) { SET(1,ROAD10); }
}

IF( OUT(2) AND OUT(7) AND IS(8,ROAD3) AND IS(5,ROAD3) OR IS(5,ROAD0) )
{ /* f2 */
SET(4,ROAD1);

IF( IS(1,ROAD3 ) ) { SET(4,ROAD6 ); }

IF( IS(5,ROAD3 ) ) { SET(5,ROAD2 ); } ELSE
IF( IS(5,ROAD0 ) ) { SET(5,ROAD11); }

IF( IS(3,ROAD12) ) { SET(3,ROAD4 ); } ELSE
IF( IS(3,ROAD2 ) ) { SET(3,ROAD11); } ELSE
IF( IS(3,ROAD8 ) ) { SET(3,ROAD9 ); }
}

IF( OUT(0) AND OUT(5) AND IS(2,ROAD1) AND IS(1,ROAD1) OR IS(1,ROAD6) )
{ /* f3 */
SET(4,ROAD3);

IF( IS(3,ROAD1 ) ) { SET(4,ROAD8 ); }

IF( IS(1,ROAD1 ) ) { SET(1,ROAD0 ); } ELSE
IF( IS(1,ROAD6 ) ) { SET(1,ROAD10); }

IF( IS(7,ROAD11) ) { SET(7,ROAD4 ); } ELSE
IF( IS(7,ROAD2 ) ) { SET(7,ROAD12); } ELSE
IF( IS(7,ROAD0 ) ) { SET(7,ROAD10); }
}

FOR(x=0;x<9;x++)
{
SWITCH( c[x]->type )
{
CASE ROAD0 : BltBMO(roads[0 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD1 : BltBMO(roads[1 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD2 : BltBMO(roads[2 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD3 : BltBMO(roads[3 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD4 : BltBMO(roads[4 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD5 : BltBMO(roads[5 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD6 : BltBMO(roads[6 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD7 : BltBMO(roads[7 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD8 : BltBMO(roads[8 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD9 : BltBMO(roads[9 ],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD10: BltBMO(roads[10],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD11: BltBMO(roads[11],drawbg,c[x]->posx,c[x]->posy); BREAK;
CASE ROAD12: BltBMO(roads[12],drawbg,c[x]->posx,c[x]->posy); BREAK;
}
}
}

/* cel.c */

#define INC_GRAPHICS
#define NO_BASE

#include ".H:macros.h"
#include ".H:game.h"

CEL celview[23][18]; /* VIEW WIDTH , HEIGHT */
CEL celbgnd[120][81]; /* drawbm WIDTH , HEIGHT */

VOID InitCel( VOID )
{
REGISTER LONG x=NL,y=NL;

FOR(x=0;x<120;x++) /* background celules */
{
FOR(y=0;y<81;y++)
{
celbgnd[x][y].posx=(x*10);
celbgnd[x][y].posy=(y*10);
celbgnd[x][y].type=TERRE;
}
}
FOR(x=0;x<23;x++)
{
FOR(y=0;y<18;y++)
{
celview[x][y].posx=(x*10)+VIEW_LEFT;
celview[x][y].posy=(y*10)+VIEW_TOP;
celview[x][y].type=NL;
}
}
}

/* bm.c */

#define INC_EXEC
#define INC_GRAPHICS
#define NO_BASE

#include ".H:macros.h"
#include ".H:game.h"
#include ".H:data.h"

EXTERN ULONG RangeSeed;

EXTERN RAST_PORT *rp [ NUMBUF ];

EXTERN CEL celbgnd[120][81]; /* drawbm WIDTH , HEIGHT */

/*-------------------------------------------------------------------------*/

BIT_MAP_OBJ *drawbg = NL;
BIT_MAP *userbg = NL;

BIT_MAP_OBJ *terre= NL;
BIT_MAP_OBJ *arbre= NL;
BIT_MAP_OBJ *pbuis= NL;
BIT_MAP_OBJ *gbuis= NL;
BIT_MAP_OBJ *gravi= NL;
BIT_MAP_OBJ *creva= NL;

BIT_MAP_OBJ *brous0[4]=NL;
BIT_MAP_OBJ *brous1[4]=NL;
BIT_MAP_OBJ *brous2[4]=NL;
BIT_MAP_OBJ *brous3[4]=NL;
BIT_MAP_OBJ *brous4[9]=NL;
BIT_MAP_OBJ *brous5[4]=NL;
BIT_MAP_OBJ *brous6[4]=NL;
BIT_MAP_OBJ *brous7[4]=NL;
BIT_MAP_OBJ *brous8[4]=NL;

BIT_MAP_OBJ *flots0[4]=NL;
BIT_MAP_OBJ *flots1[4]=NL;
BIT_MAP_OBJ *flots2[4]=NL;
BIT_MAP_OBJ *flots3[4]=NL;
BIT_MAP_OBJ *flots4[9]=NL;
BIT_MAP_OBJ *flots5[4]=NL;
BIT_MAP_OBJ *flots6[4]=NL;
BIT_MAP_OBJ *flots7[4]=NL;
BIT_MAP_OBJ *flots8[4]=NL;

BIT_MAP_OBJ *roads[13]= NL;

BIT_MAP_OBJ *house[8]= NL;
BIT_MAP_OBJ *comme[8]= NL;
BIT_MAP_OBJ *indus[8]= NL;
BIT_MAP_OBJ *agric[8]= NL;

BIT_MAP_OBJ *base[4]= NL;

BIT_MAP_OBJ *bmo_cur= NL;

/*-------------------------------------------------------------------------*/

VOID UnInitAllBitMap( VOID );
VOID AspergeBitMap(BIT_MAP_OBJ *o, INT n, INT type);
VOID Blit(BIT_MAP_OBJ *o, INT x, INT y, INT type);
VOID InitAllBitMap( VOID );

/*-------------------------------------------------------------------------*/

goflots(INT x, INT y)
{
INT n=NL,endtrace=FALSE;
endtrace=FALSE;

WHILE( endtrace==FALSE )
{
celbgnd[x ][y ].type=FLOT4;
celbgnd[x+1][y ].type=FLOT4;
celbgnd[x+1][y+1].type=FLOT4;
celbgnd[x ][y+1].type=FLOT4;

x+=(RangeRand(4)>1 ? 1 : -1);
IF( x>118 ) { endtrace=TRUE; } ELSE IF( x<0 ) x=0;

y+=(RangeRand(4)>1 ? 1 : -1);
IF( y>79 ) { endtrace=TRUE; } ELSE IF( y<0 ) y=0;
}
}

gobrous(INT x, INT y)
{
INT n=NL,endtrace=FALSE;
endtrace=FALSE;

WHILE( endtrace==FALSE )
{
IF(celbgnd[x ][y ].type!=FLOT4 AND celbgnd[x+1][y ].type!=FLOT4 AND
celbgnd[x+1][y+1].type!=FLOT4 AND celbgnd[x ][y+1].type!=FLOT4 )
{
celbgnd[x ][y ].type=BROU4;
celbgnd[x+1][y ].type=BROU4;
celbgnd[x+1][y+1].type=BROU4;
celbgnd[x ][y+1].type=BROU4;
}
x+=(RangeRand(4)>1 ? 1 : -1);
IF( x>118 ) { endtrace=TRUE; } ELSE IF( x<0 ) x=0;

y+=(RangeRand(4)>1 ? 1 : -1);
IF( y>79 ) { endtrace=TRUE; } ELSE IF( y<0 ) y=0;
}
}

/*-------------------------------------------------------------------------*/

VOID InitAllBitMap( VOID )
{
UWORD x,y;

NewBMO( drawbg, 1200, 810, 5);

userbg=(BIT_MAP *)NewBitMapPlanes(320,50,5,&user0[0],&user1[0],&user2[0],&user3[0],&user4[0]);

terre=(BIT_MAP_OBJ *)NewBMOPlanes(ARBRE,30,30,5,&terre0[0],&terre1[0],&terre2[0],&terre3[0],&terre4[0]);
arbre=(BIT_MAP_OBJ *)NewBMOPlanes(PBUIS,10,10,5,&arbre0[0],&arbre1[0],&arbre2[0],&arbre3[0],&arbre4[0]);
pbuis=(BIT_MAP_OBJ *)NewBMOPlanes(GBUIS,10,10,5,&pbuis0[0],&pbuis1[0],&pbuis2[0],&pbuis3[0],&pbuis4[0]);
gbuis=(BIT_MAP_OBJ *)NewBMOPlanes(GRAVI,10,10,5,&gbuis0[0],&gbuis1[0],&gbuis2[0],&gbuis3[0],&gbuis4[0]);
gravi=(BIT_MAP_OBJ *)NewBMOPlanes(MONTA,10,10,5,&gravi0[0],&gravi1[0],&gravi2[0],&gravi3[0],&gravi4[0]);
creva=(BIT_MAP_OBJ *)NewBMOPlanes(CREVA,10,10,5,&creva0[0],&creva1[0],&creva2[0],&creva3[0],&creva4[0]);

brous0[0] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU0,10,10,5,&brous000[0],&brous001[0],&brous002[0],&brous003[0],&brous004[0]);
brous0[1] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU0,10,10,5,&brous010[0],&brous011[0],&brous012[0],&brous013[0],&brous014[0]);
brous0[2] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU0,10,10,5,&brous020[0],&brous021[0],&brous022[0],&brous023[0],&brous024[0]);
brous0[3] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU0,10,10,5,&brous030[0],&brous031[0],&brous032[0],&brous033[0],&brous034[0]);

brous1[0] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU1,10,10,5,&brous100[0],&brous101[0],&brous102[0],&brous103[0],&brous104[0]);
brous1[1] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU1,10,10,5,&brous110[0],&brous111[0],&brous112[0],&brous113[0],&brous114[0]);
brous1[2] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU1,10,10,5,&brous120[0],&brous121[0],&brous122[0],&brous123[0],&brous124[0]);
brous1[3] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU1,10,10,5,&brous130[0],&brous131[0],&brous132[0],&brous133[0],&brous134[0]);

brous2[0] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU2,10,10,5,&brous200[0],&brous201[0],&brous202[0],&brous203[0],&brous204[0]);
brous2[1] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU2,10,10,5,&brous210[0],&brous211[0],&brous212[0],&brous213[0],&brous214[0]);
brous2[2] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU2,10,10,5,&brous220[0],&brous221[0],&brous222[0],&brous223[0],&brous224[0]);
brous2[3] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU2,10,10,5,&brous230[0],&brous231[0],&brous232[0],&brous233[0],&brous234[0]);

brous3[0] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU3,10,10,5,&brous300[0],&brous301[0],&brous302[0],&brous303[0],&brous304[0]);
brous3[1] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU3,10,10,5,&brous310[0],&brous311[0],&brous312[0],&brous313[0],&brous314[0]);
brous3[2] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU3,10,10,5,&brous320[0],&brous321[0],&brous322[0],&brous323[0],&brous324[0]);
brous3[3] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU3,10,10,5,&brous330[0],&brous331[0],&brous332[0],&brous333[0],&brous334[0]);

brous5[0] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU5,10,10,5,&brous500[0],&brous501[0],&brous502[0],&brous503[0],&brous504[0]);
brous5[1] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU5,10,10,5,&brous510[0],&brous511[0],&brous512[0],&brous513[0],&brous514[0]);
brous5[2] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU5,10,10,5,&brous520[0],&brous521[0],&brous522[0],&brous523[0],&brous524[0]);
brous5[3] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU5,10,10,5,&brous530[0],&brous531[0],&brous532[0],&brous533[0],&brous534[0]);

brous6[0] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU6,10,10,5,&brous600[0],&brous601[0],&brous602[0],&brous603[0],&brous604[0]);
brous6[1] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU6,10,10,5,&brous610[0],&brous611[0],&brous612[0],&brous613[0],&brous614[0]);
brous6[2] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU6,10,10,5,&brous620[0],&brous621[0],&brous622[0],&brous623[0],&brous624[0]);
brous6[3] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU6,10,10,5,&brous630[0],&brous631[0],&brous632[0],&brous633[0],&brous634[0]);

brous7[0] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU7,10,10,5,&brous700[0],&brous701[0],&brous702[0],&brous703[0],&brous704[0]);
brous7[1] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU7,10,10,5,&brous710[0],&brous711[0],&brous712[0],&brous713[0],&brous714[0]);
brous7[2] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU7,10,10,5,&brous720[0],&brous721[0],&brous722[0],&brous723[0],&brous724[0]);
brous7[3] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU7,10,10,5,&brous730[0],&brous731[0],&brous732[0],&brous733[0],&brous734[0]);

brous8[0] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU8,10,10,5,&brous800[0],&brous801[0],&brous802[0],&brous803[0],&brous804[0]);
brous8[1] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU8,10,10,5,&brous810[0],&brous811[0],&brous812[0],&brous813[0],&brous814[0]);
brous8[2] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU8,10,10,5,&brous820[0],&brous821[0],&brous822[0],&brous823[0],&brous824[0]);
brous8[3] =(BIT_MAP_OBJ *)NewBMOPlanes(BROU8,10,10,5,&brous830[0],&brous831[0],&brous832[0],&brous833[0],&brous834[0]);

brous4[0]=(BIT_MAP_OBJ *)NewBMOPlanes(BROU4,10,10,5,&brous400[0],&brous401[0],&brous402[0],&brous403[0],&brous404[0]);
brous4[1]=(BIT_MAP_OBJ *)NewBMOPlanes(BROU4,10,10,5,&brous410[0],&brous411[0],&brous412[0],&brous413[0],&brous414[0]);
brous4[2]=(BIT_MAP_OBJ *)NewBMOPlanes(BROU4,10,10,5,&brous420[0],&brous421[0],&brous422[0],&brous423[0],&brous424[0]);
brous4[3]=(BIT_MAP_OBJ *)NewBMOPlanes(BROU4,10,10,5,&brous430[0],&brous431[0],&brous432[0],&brous433[0],&brous434[0]);
brous4[4]=(BIT_MAP_OBJ *)NewBMOPlanes(BROU4,10,10,5,&brous440[0],&brous441[0],&brous442[0],&brous443[0],&brous444[0]);
brous4[5]=(BIT_MAP_OBJ *)NewBMOPlanes(BROU4,10,10,5,&brous450[0],&brous451[0],&brous452[0],&brous453[0],&brous454[0]);
brous4[6]=(BIT_MAP_OBJ *)NewBMOPlanes(BROU4,10,10,5,&brous460[0],&brous461[0],&brous462[0],&brous463[0],&brous464[0]);
brous4[7]=(BIT_MAP_OBJ *)NewBMOPlanes(BROU4,10,10,5,&brous470[0],&brous471[0],&brous472[0],&brous473[0],&brous474[0]);
brous4[8]=(BIT_MAP_OBJ *)NewBMOPlanes(BROU4,10,10,5,&brous480[0],&brous481[0],&brous482[0],&brous483[0],&brous484[0]);

flots0[0] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT0,10,10,5,&flots000[0],&flots001[0],&flots002[0],&flots003[0],&flots004[0]);
flots0[1] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT0,10,10,5,&flots010[0],&flots011[0],&flots012[0],&flots013[0],&flots014[0]);
flots0[2] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT0,10,10,5,&flots020[0],&flots021[0],&flots022[0],&flots023[0],&flots024[0]);
flots0[3] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT0,10,10,5,&flots030[0],&flots031[0],&flots032[0],&flots033[0],&flots034[0]);

flots1[0] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT1,10,10,5,&flots100[0],&flots101[0],&flots102[0],&flots103[0],&flots104[0]);
flots1[1] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT1,10,10,5,&flots110[0],&flots111[0],&flots112[0],&flots113[0],&flots114[0]);
flots1[2] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT1,10,10,5,&flots120[0],&flots121[0],&flots122[0],&flots123[0],&flots124[0]);
flots1[3] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT1,10,10,5,&flots130[0],&flots131[0],&flots132[0],&flots133[0],&flots134[0]);

flots2[0] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT2,10,10,5,&flots200[0],&flots201[0],&flots202[0],&flots203[0],&flots204[0]);
flots2[1] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT2,10,10,5,&flots210[0],&flots211[0],&flots212[0],&flots213[0],&flots214[0]);
flots2[2] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT2,10,10,5,&flots220[0],&flots221[0],&flots222[0],&flots223[0],&flots224[0]);
flots2[3] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT2,10,10,5,&flots230[0],&flots231[0],&flots232[0],&flots233[0],&flots234[0]);

flots3[0] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT3,10,10,5,&flots300[0],&flots301[0],&flots302[0],&flots303[0],&flots304[0]);
flots3[1] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT3,10,10,5,&flots310[0],&flots311[0],&flots312[0],&flots313[0],&flots314[0]);
flots3[2] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT3,10,10,5,&flots320[0],&flots321[0],&flots322[0],&flots323[0],&flots324[0]);
flots3[3] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT3,10,10,5,&flots330[0],&flots331[0],&flots332[0],&flots333[0],&flots334[0]);

flots5[0] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT5,10,10,5,&flots500[0],&flots501[0],&flots502[0],&flots503[0],&flots504[0]);
flots5[1] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT5,10,10,5,&flots510[0],&flots511[0],&flots512[0],&flots513[0],&flots514[0]);
flots5[2] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT5,10,10,5,&flots520[0],&flots521[0],&flots522[0],&flots523[0],&flots524[0]);
flots5[3] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT5,10,10,5,&flots530[0],&flots531[0],&flots532[0],&flots533[0],&flots534[0]);

flots6[0] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT6,10,10,5,&flots600[0],&flots601[0],&flots602[0],&flots603[0],&flots604[0]);
flots6[1] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT6,10,10,5,&flots610[0],&flots611[0],&flots612[0],&flots613[0],&flots614[0]);
flots6[2] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT6,10,10,5,&flots620[0],&flots621[0],&flots622[0],&flots623[0],&flots624[0]);
flots6[3] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT6,10,10,5,&flots630[0],&flots631[0],&flots632[0],&flots633[0],&flots634[0]);

flots7[0] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT7,10,10,5,&flots700[0],&flots701[0],&flots702[0],&flots703[0],&flots704[0]);
flots7[1] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT7,10,10,5,&flots710[0],&flots711[0],&flots712[0],&flots713[0],&flots714[0]);
flots7[2] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT7,10,10,5,&flots720[0],&flots721[0],&flots722[0],&flots723[0],&flots724[0]);
flots7[3] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT7,10,10,5,&flots730[0],&flots731[0],&flots732[0],&flots733[0],&flots734[0]);

flots8[0] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT8,10,10,5,&flots800[0],&flots801[0],&flots802[0],&flots803[0],&flots804[0]);
flots8[1] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT8,10,10,5,&flots810[0],&flots811[0],&flots812[0],&flots813[0],&flots814[0]);
flots8[2] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT8,10,10,5,&flots820[0],&flots821[0],&flots822[0],&flots823[0],&flots824[0]);
flots8[3] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT8,10,10,5,&flots830[0],&flots831[0],&flots832[0],&flots833[0],&flots834[0]);

flots4[0] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT4,10,10,5,&flots400[0],&flots401[0],&flots402[0],&flots403[0],&flots404[0]);
flots4[1] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT4,10,10,5,&flots410[0],&flots411[0],&flots412[0],&flots413[0],&flots414[0]);
flots4[2] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT4,10,10,5,&flots420[0],&flots421[0],&flots422[0],&flots423[0],&flots424[0]);
flots4[3] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT4,10,10,5,&flots430[0],&flots431[0],&flots432[0],&flots433[0],&flots434[0]);
flots4[4] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT4,10,10,5,&flots440[0],&flots441[0],&flots442[0],&flots443[0],&flots444[0]);
flots4[5] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT4,10,10,5,&flots450[0],&flots451[0],&flots452[0],&flots453[0],&flots454[0]);
flots4[6] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT4,10,10,5,&flots460[0],&flots461[0],&flots462[0],&flots463[0],&flots464[0]);
flots4[7] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT4,10,10,5,&flots470[0],&flots471[0],&flots472[0],&flots473[0],&flots474[0]);
flots4[8] =(BIT_MAP_OBJ *)NewBMOPlanes(FLOT4,10,10,5,&flots480[0],&flots481[0],&flots482[0],&flots483[0],&flots484[0]);

roads[0] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD0 ,10,10,5,&roads00[0],&roads01[0],&roads02[0],&roads03[0],&roads04[0]);
roads[1] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD1 ,10,10,5,&roads10[0],&roads11[0],&roads12[0],&roads13[0],&roads14[0]);
roads[2] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD2 ,10,10,5,&roads20[0],&roads21[0],&roads22[0],&roads23[0],&roads24[0]);
roads[3] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD3 ,10,10,5,&roads30[0],&roads31[0],&roads32[0],&roads33[0],&roads34[0]);
roads[4] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD4 ,10,10,5,&roads40[0],&roads41[0],&roads42[0],&roads43[0],&roads44[0]);
roads[5] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD5 ,10,10,5,&roads50[0],&roads51[0],&roads52[0],&roads53[0],&roads54[0]);
roads[6] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD6 ,10,10,5,&roads60[0],&roads61[0],&roads62[0],&roads63[0],&roads64[0]);
roads[7] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD7 ,10,10,5,&roads70[0],&roads71[0],&roads72[0],&roads73[0],&roads74[0]);
roads[8] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD8 ,10,10,5,&roads80[0],&roads81[0],&roads82[0],&roads83[0],&roads84[0]);
roads[9] =(BIT_MAP_OBJ *)NewBMOPlanes(ROAD9 ,10,10,5,&roads90[0],&roads91[0],&roads92[0],&roads93[0],&roads94[0]);
roads[10]=(BIT_MAP_OBJ *)NewBMOPlanes(ROAD10,10,10,5,&roads100[0],&roads101[0],&roads102[0],&roads103[0],&roads104[0]);
roads[11]=(BIT_MAP_OBJ *)NewBMOPlanes(ROAD11,10,10,5,&roads110[0],&roads111[0],&roads112[0],&roads113[0],&roads114[0]);
roads[12]=(BIT_MAP_OBJ *)NewBMOPlanes(ROAD12,10,10,5,&roads120[0],&roads121[0],&roads122[0],&roads123[0],&roads124[0]);

house[0]=(BIT_MAP_OBJ *)NewBMOPlanes(HOUS0,30,30,5,&house00[0],&house01[0],&house02[0],&house03[0],&house04[0]);
house[1]=(BIT_MAP_OBJ *)NewBMOPlanes(HOUS1,30,30,5,&house10[0],&house11[0],&house12[0],&house13[0],&house14[0]);
house[2]=(BIT_MAP_OBJ *)NewBMOPlanes(HOUS2,30,30,5,&house20[0],&house21[0],&house22[0],&house23[0],&house24[0]);
house[3]=(BIT_MAP_OBJ *)NewBMOPlanes(HOUS3,30,30,5,&house30[0],&house31[0],&house32[0],&house33[0],&house34[0]);
house[4]=(BIT_MAP_OBJ *)NewBMOPlanes(HOUS4,30,30,5,&house40[0],&house41[0],&house42[0],&house43[0],&house44[0]);
house[5]=(BIT_MAP_OBJ *)NewBMOPlanes(HOUS5,30,30,5,&house50[0],&house51[0],&house52[0],&house53[0],&house54[0]);
house[6]=(BIT_MAP_OBJ *)NewBMOPlanes(HOUS6,30,30,5,&house60[0],&house61[0],&house62[0],&house63[0],&house64[0]);
house[7]=(BIT_MAP_OBJ *)NewBMOPlanes(HOUS7,30,30,5,&house70[0],&house71[0],&house72[0],&house73[0],&house74[0]);

comme[0]=(BIT_MAP_OBJ *)NewBMOPlanes(COMM0,30,30,5,&comme00[0],&comme01[0],&comme02[0],&comme03[0],&comme04[0]);
comme[1]=(BIT_MAP_OBJ *)NewBMOPlanes(COMM1,30,30,5,&comme10[0],&comme11[0],&comme12[0],&comme13[0],&comme14[0]);
comme[2]=(BIT_MAP_OBJ *)NewBMOPlanes(COMM2,30,30,5,&comme20[0],&comme21[0],&comme22[0],&comme23[0],&comme24[0]);
comme[3]=(BIT_MAP_OBJ *)NewBMOPlanes(COMM3,30,30,5,&comme30[0],&comme31[0],&comme32[0],&comme33[0],&comme34[0]);
comme[4]=(BIT_MAP_OBJ *)NewBMOPlanes(COMM4,30,30,5,&comme40[0],&comme41[0],&comme42[0],&comme43[0],&comme44[0]);
comme[5]=(BIT_MAP_OBJ *)NewBMOPlanes(COMM5,30,30,5,&comme50[0],&comme51[0],&comme52[0],&comme53[0],&comme54[0]);
comme[6]=(BIT_MAP_OBJ *)NewBMOPlanes(COMM6,30,30,5,&comme60[0],&comme61[0],&comme62[0],&comme63[0],&comme64[0]);
comme[7]=(BIT_MAP_OBJ *)NewBMOPlanes(COMM7,30,30,5,&comme70[0],&comme71[0],&comme72[0],&comme73[0],&comme74[0]);

indus[0]=(BIT_MAP_OBJ *)NewBMOPlanes(INDU0,30,30,5,&indus00[0],&indus01[0],&indus02[0],&indus03[0],&indus04[0]);
indus[1]=(BIT_MAP_OBJ *)NewBMOPlanes(INDU1,30,30,5,&indus10[0],&indus11[0],&indus12[0],&indus13[0],&indus14[0]);
indus[2]=(BIT_MAP_OBJ *)NewBMOPlanes(INDU2,30,30,5,&indus20[0],&indus21[0],&indus22[0],&indus23[0],&indus24[0]);
indus[3]=(BIT_MAP_OBJ *)NewBMOPlanes(INDU3,30,30,5,&indus30[0],&indus31[0],&indus32[0],&indus33[0],&indus34[0]);
indus[4]=(BIT_MAP_OBJ *)NewBMOPlanes(INDU4,30,30,5,&indus40[0],&indus41[0],&indus42[0],&indus43[0],&indus44[0]);
indus[5]=(BIT_MAP_OBJ *)NewBMOPlanes(INDU5,30,30,5,&indus50[0],&indus51[0],&indus52[0],&indus53[0],&indus54[0]);
indus[6]=(BIT_MAP_OBJ *)NewBMOPlanes(INDU6,30,30,5,&indus60[0],&indus61[0],&indus62[0],&indus63[0],&indus64[0]);
indus[7]=(BIT_MAP_OBJ *)NewBMOPlanes(INDU7,30,30,5,&indus70[0],&indus71[0],&indus72[0],&indus73[0],&indus74[0]);

agric[0]=(BIT_MAP_OBJ *)NewBMOPlanes(AGRI0,30,30,5,&agric00[0],&agric01[0],&agric02[0],&agric03[0],&agric04[0]);
agric[1]=(BIT_MAP_OBJ *)NewBMOPlanes(AGRI1,30,30,5,&agric10[0],&agric11[0],&agric12[0],&agric13[0],&agric14[0]);
agric[2]=(BIT_MAP_OBJ *)NewBMOPlanes(AGRI2,30,30,5,&agric20[0],&agric21[0],&agric22[0],&agric23[0],&agric24[0]);
agric[3]=(BIT_MAP_OBJ *)NewBMOPlanes(AGRI3,30,30,5,&agric30[0],&agric31[0],&agric32[0],&agric33[0],&agric34[0]);
agric[4]=(BIT_MAP_OBJ *)NewBMOPlanes(AGRI4,30,30,5,&agric40[0],&agric41[0],&agric42[0],&agric43[0],&agric44[0]);
agric[5]=(BIT_MAP_OBJ *)NewBMOPlanes(AGRI5,30,30,5,&agric50[0],&agric51[0],&agric52[0],&agric53[0],&agric54[0]);
agric[6]=(BIT_MAP_OBJ *)NewBMOPlanes(AGRI6,30,30,5,&agric60[0],&agric61[0],&agric62[0],&agric63[0],&agric64[0]);
agric[7]=(BIT_MAP_OBJ *)NewBMOPlanes(AGRI7,30,30,5,&agric70[0],&agric71[0],&agric72[0],&agric73[0],&agric74[0]);

base[0]=(BIT_MAP_OBJ *)NewBMOPlanes(HOUS,30,30,5,&house_base0[0],&house_base1[0],&house_base2[0],&house_base3[0],&house_base4[0]);
base[1]=(BIT_MAP_OBJ *)NewBMOPlanes(COMM,30,30,5,&comme_base0[0],&comme_base1[0],&comme_base2[0],&comme_base3[0],&comme_base4[0]);
base[2]=(BIT_MAP_OBJ *)NewBMOPlanes(INDU,30,30,5,&indus_base0[0],&indus_base1[0],&indus_base2[0],&indus_base3[0],&indus_base4[0]);
base[3]=(BIT_MAP_OBJ *)NewBMOPlanes(AGRI,30,30,5,&agric_base0[0],&agric_base1[0],&agric_base2[0],&agric_base3[0],&agric_base4[0]);

RangeSeed=(VBeamPos()*100);

FOR(x=0;x<drawbg->w;x+=terre->w)
{
FOR(y=0;y<drawbg->h;y+=terre->h)
{
BltBMO( terre, drawbg, x, y );
}
}

AspergeBitMap(arbre,800,TERRE);
AspergeBitMap(pbuis, 30,TERRE);
AspergeBitMap(gbuis, 60,TERRE);
AspergeBitMap(gravi, 20,TERRE);
AspergeBitMap(creva, 20,TERRE);

goflots(RangeRand(30),RangeRand(20));
goflots(RangeRand(30)+90,RangeRand(20)+60);

gobrous(RangeRand(30)+90,RangeRand(30));
gobrous(RangeRand(30),RangeRand(30)+50);

#define GND >8
#define BRS <=8

FOR(x=0;x<120;x++)
{
FOR(y=0;y<81;y++)
{
IF(celbgnd[x][y].type==BROU4)
{
IF( celbgnd[x-1][y].type GND AND celbgnd[x][y-1].type GND AND
celbgnd[x+1][y].type BRS AND celbgnd[x][y+1].type BRS )
{
celbgnd[x][y].type=BROU0;
} ELSE

IF( celbgnd[x-1][y].type GND AND celbgnd[x][y-1].type BRS AND
celbgnd[x+1][y].type BRS AND celbgnd[x][y+1].type BRS )
{
celbgnd[x][y].type=BROU1;
} ELSE

IF( celbgnd[x-1][y].type GND AND celbgnd[x][y-1].type BRS AND
celbgnd[x+1][y].type BRS AND celbgnd[x][y+1].type GND )
{
celbgnd[x][y].type=BROU2;
} ELSE

IF( celbgnd[x-1][y].type BRS AND celbgnd[x][y-1].type GND AND
celbgnd[x+1][y].type BRS AND celbgnd[x][y+1].type BRS )
{
celbgnd[x][y].type=BROU3;
} ELSE

IF( celbgnd[x-1][y].type BRS AND celbgnd[x][y-1].type BRS AND
celbgnd[x+1][y].type BRS AND celbgnd[x][y+1].type GND )
{
celbgnd[x][y].type=BROU5;
}

IF( celbgnd[x-1][y].type BRS AND celbgnd[x][y-1].type GND AND
celbgnd[x+1][y].type GND AND celbgnd[x][y+1].type BRS )
{
celbgnd[x][y].type=BROU6;
} ELSE

IF( celbgnd[x-1][y].type BRS AND celbgnd[x][y-1].type BRS AND
celbgnd[x+1][y].type GND AND celbgnd[x][y+1].type BRS )
{
celbgnd[x][y].type=BROU7;
} ELSE

IF( celbgnd[x-1][y].type BRS AND celbgnd[x][y-1].type BRS AND
celbgnd[x+1][y].type GND AND celbgnd[x][y+1].type GND )
{
celbgnd[x][y].type=BROU8;
}
} ELSE

IF(celbgnd[x][y].type==FLOT4)
{
IF((celbgnd[x-1][y].type <9 OR celbgnd[x-1][y].type >17) AND
(celbgnd[x][y-1].type <9 OR celbgnd[x][y-1].type >17) AND
celbgnd[x+1][y].type >=9 AND celbgnd[x+1][y].type <=17 AND
celbgnd[x][y+1].type >=9 AND celbgnd[x][y+1].type <=17 )
{
celbgnd[x][y].type=FLOT0;
} ELSE

IF((celbgnd[x-1][y].type <9 OR celbgnd[x-1][y].type >17) AND
celbgnd[x][y-1].type >=9 AND celbgnd[x][y-1].type <=17 AND
celbgnd[x+1][y].type >=9 AND celbgnd[x+1][y].type <=17 AND
celbgnd[x][y+1].type >=9 AND celbgnd[x][y+1].type <=17 )
{
celbgnd[x][y].type=FLOT1;
} ELSE

IF((celbgnd[x-1][y].type <9 OR celbgnd[x-1][y].type >17) AND
celbgnd[x][y-1].type >=9 AND celbgnd[x][y-1].type <=17 AND
celbgnd[x+1][y].type >=9 AND celbgnd[x+1][y].type <=17 AND
(celbgnd[x][y+1].type <9 OR celbgnd[x][y+1].type >17) )
{
celbgnd[x][y].type=FLOT2;
} ELSE

IF( celbgnd[x-1][y].type >=9 AND celbgnd[x-1][y].type <=17 AND
(celbgnd[x][y-1].type <9 OR celbgnd[x][y-1].type >17) AND
celbgnd[x+1][y].type >=9 AND celbgnd[x+1][y].type <=17 AND
celbgnd[x][y+1].type >=9 AND celbgnd[x][y+1].type <=17 )
{
celbgnd[x][y].type=FLOT3;
} ELSE

IF( celbgnd[x-1][y].type >=9 AND celbgnd[x-1][y].type <=17 AND
celbgnd[x][y-1].type >=9 AND celbgnd[x][y-1].type <=17 AND
celbgnd[x+1][y].type >=9 AND celbgnd[x+1][y].type <=17 AND
(celbgnd[x][y+1].type <9 OR celbgnd[x][y+1].type >17) )
{
celbgnd[x][y].type=FLOT5;
}

IF( celbgnd[x-1][y].type >=9 AND celbgnd[x-1][y].type <=17 AND
(celbgnd[x][y-1].type <9 OR celbgnd[x][y-1].type >17) AND
(celbgnd[x+1][y].type <9 OR celbgnd[x+1][y].type >17) AND
celbgnd[x][y+1].type >=9 AND celbgnd[x][y+1].type <=17 )
{
celbgnd[x][y].type=FLOT6;
} ELSE

IF( celbgnd[x-1][y].type >=9 AND celbgnd[x-1][y].type <=17 AND
celbgnd[x][y-1].type >=9 AND celbgnd[x][y-1].type <=17 AND
(celbgnd[x+1][y].type <9 OR celbgnd[x+1][y].type >17) AND
celbgnd[x][y+1].type >=9 AND celbgnd[x][y+1].type <=17 )
{
celbgnd[x][y].type=FLOT7;
} ELSE

IF( celbgnd[x-1][y].type >=9 AND celbgnd[x-1][y].type <=17 AND
celbgnd[x][y-1].type >=9 AND celbgnd[x][y-1].type <=17 AND
(celbgnd[x+1][y].type <9 OR celbgnd[x+1][y].type >17) AND
(celbgnd[x][y+1].type <9 OR celbgnd[x][y+1].type >17) )
{
celbgnd[x][y].type=FLOT8;
}
}
}
}

FOR(x=0;x<120;x++) /* background celules */
{
FOR(y=0;y<81;y++)
{
REGISTER n=RangeRand(4);
SWITCH( celbgnd[x][y].type )
{
CASE BROU0: Blit(brous0[n],x,y,BROUS); BREAK;
CASE BROU1: Blit(brous1[n],x,y,BROUS); BREAK;
CASE BROU2: Blit(brous2[n],x,y,BROUS); BREAK;
CASE BROU3: Blit(brous3[n],x,y,BROUS); BREAK;
CASE BROU5: Blit(brous5[n],x,y,BROUS); BREAK;
CASE BROU6: Blit(brous6[n],x,y,BROUS); BREAK;
CASE BROU7: Blit(brous7[n],x,y,BROUS); BREAK;
CASE BROU8: Blit(brous8[n],x,y,BROUS); BREAK;

CASE FLOT0: Blit(flots0[n],x,y,FLOTS); BREAK;
CASE FLOT1: Blit(flots1[n],x,y,FLOTS); BREAK;
CASE FLOT2: Blit(flots2[n],x,y,FLOTS); BREAK;
CASE FLOT3: Blit(flots3[n],x,y,FLOTS); BREAK;
CASE FLOT5: Blit(flots5[n],x,y,FLOTS); BREAK;
CASE FLOT6: Blit(flots6[n],x,y,FLOTS); BREAK;
CASE FLOT7: Blit(flots7[n],x,y,FLOTS); BREAK;
CASE FLOT8: Blit(flots8[n],x,y,FLOTS); BREAK;

CASE BROU4: n=RangeRand(9); Blit(brous4[n],x,y,BROUS); BREAK;
CASE FLOT4: n=RangeRand(9); Blit(flots4[n],x,y,FLOTS); BREAK;
}
}
}
bmo_cur = roads[4];
}
/*-------------------------------------------------------------------------*/

VOID AspergeBitMap(BIT_MAP_OBJ *o,INT n,INT type)
{
REGISTER UWORD x,y,i;

FOR(i=0;i<n;i++)
{
x=RangeRand(120);
y=RangeRand(81);

BltBMO( o, drawbg, celbgnd[x][y].posx, celbgnd[x][y].posy );
celbgnd[x][y].type=type;

}
}

VOID Blit(BIT_MAP_OBJ *o,INT x, INT y, INT type)
{
BltBMO( o, drawbg, celbgnd[x][y].posx, celbgnd[x][y].posy );
celbgnd[x][y].type=type;
}

/*-------------------------------------------------------------------------*/

VOID UnInitAllBitMap( VOID )
{
RemBMOPlanes( base[0] );
RemBMOPlanes( base[1] );
RemBMOPlanes( base[2] );
RemBMOPlanes( base[3] );

RemBMOPlanes( house[0] );
RemBMOPlanes( house[1] );
RemBMOPlanes( house[2] );
RemBMOPlanes( house[3] );
RemBMOPlanes( house[4] );
RemBMOPlanes( house[5] );
RemBMOPlanes( house[6] );
RemBMOPlanes( house[7] );

RemBMOPlanes( comme[0] );
RemBMOPlanes( comme[1] );
RemBMOPlanes( comme[2] );
RemBMOPlanes( comme[3] );
RemBMOPlanes( comme[4] );
RemBMOPlanes( comme[5] );
RemBMOPlanes( comme[6] );
RemBMOPlanes( comme[7] );

RemBMOPlanes( indus[0] );
RemBMOPlanes( indus[1] );
RemBMOPlanes( indus[2] );
RemBMOPlanes( indus[3] );
RemBMOPlanes( indus[4] );
RemBMOPlanes( indus[5] );
RemBMOPlanes( indus[6] );
RemBMOPlanes( indus[7] );

RemBMOPlanes( agric[0] );
RemBMOPlanes( agric[1] );
RemBMOPlanes( agric[2] );
RemBMOPlanes( agric[3] );
RemBMOPlanes( agric[4] );
RemBMOPlanes( agric[5] );
RemBMOPlanes( agric[6] );
RemBMOPlanes( agric[7] );

RemBMOPlanes( roads[0] );
RemBMOPlanes( roads[1] );
RemBMOPlanes( roads[2] );
RemBMOPlanes( roads[3] );
RemBMOPlanes( roads[4] );
RemBMOPlanes( roads[5] );
RemBMOPlanes( roads[6] );
RemBMOPlanes( roads[7] );
RemBMOPlanes( roads[8] );
RemBMOPlanes( roads[9] );
RemBMOPlanes( roads[10] );
RemBMOPlanes( roads[11] );
RemBMOPlanes( roads[12] );

RemBMOPlanes( brous0[0] );
RemBMOPlanes( brous0[1] );
RemBMOPlanes( brous0[2] );
RemBMOPlanes( brous0[3] );

RemBMOPlanes( brous1[0] );
RemBMOPlanes( brous1[1] );
RemBMOPlanes( brous1[2] );
RemBMOPlanes( brous1[3] );

RemBMOPlanes( brous2[0] );
RemBMOPlanes( brous2[1] );
RemBMOPlanes( brous2[2] );
RemBMOPlanes( brous2[3] );

RemBMOPlanes( brous3[0] );
RemBMOPlanes( brous3[1] );
RemBMOPlanes( brous3[2] );
RemBMOPlanes( brous3[3] );

RemBMOPlanes( brous5[0] );
RemBMOPlanes( brous5[1] );
RemBMOPlanes( brous5[2] );
RemBMOPlanes( brous5[3] );

RemBMOPlanes( brous6[0] );
RemBMOPlanes( brous6[1] );
RemBMOPlanes( brous6[2] );
RemBMOPlanes( brous6[3] );

RemBMOPlanes( brous7[0] );
RemBMOPlanes( brous7[1] );
RemBMOPlanes( brous7[2] );
RemBMOPlanes( brous7[3] );

RemBMOPlanes( brous8[0] );
RemBMOPlanes( brous8[1] );
RemBMOPlanes( brous8[2] );
RemBMOPlanes( brous8[3] );

RemBMOPlanes( brous4[0] );
RemBMOPlanes( brous4[1] );
RemBMOPlanes( brous4[2] );
RemBMOPlanes( brous4[3] );
RemBMOPlanes( brous4[4] );
RemBMOPlanes( brous4[5] );
RemBMOPlanes( brous4[6] );
RemBMOPlanes( brous4[7] );
RemBMOPlanes( brous4[8] );

RemBMOPlanes( flots0[0] );
RemBMOPlanes( flots0[1] );
RemBMOPlanes( flots0[2] );
RemBMOPlanes( flots0[3] );

RemBMOPlanes( flots1[0] );
RemBMOPlanes( flots1[1] );
RemBMOPlanes( flots1[2] );
RemBMOPlanes( flots1[3] );

RemBMOPlanes( flots2[0] );
RemBMOPlanes( flots2[1] );
RemBMOPlanes( flots2[2] );
RemBMOPlanes( flots2[3] );

RemBMOPlanes( flots3[0] );
RemBMOPlanes( flots3[1] );
RemBMOPlanes( flots3[2] );
RemBMOPlanes( flots3[3] );

RemBMOPlanes( flots5[0] );
RemBMOPlanes( flots5[1] );
RemBMOPlanes( flots5[2] );
RemBMOPlanes( flots5[3] );

RemBMOPlanes( flots6[0] );
RemBMOPlanes( flots6[1] );
RemBMOPlanes( flots6[2] );
RemBMOPlanes( flots6[3] );

RemBMOPlanes( flots7[0] );
RemBMOPlanes( flots7[1] );
RemBMOPlanes( flots7[2] );
RemBMOPlanes( flots7[3] );

RemBMOPlanes( flots8[0] );
RemBMOPlanes( flots8[1] );
RemBMOPlanes( flots8[2] );
RemBMOPlanes( flots8[3] );

RemBMOPlanes( flots4[0] );
RemBMOPlanes( flots4[1] );
RemBMOPlanes( flots4[2] );
RemBMOPlanes( flots4[3] );
RemBMOPlanes( flots4[4] );
RemBMOPlanes( flots4[5] );
RemBMOPlanes( flots4[6] );
RemBMOPlanes( flots4[7] );
RemBMOPlanes( flots4[8] );

RemBMOPlanes( terre );
RemBMOPlanes( arbre );
RemBMOPlanes( pbuis );
RemBMOPlanes( gbuis );
RemBMOPlanes( gravi );
RemBMOPlanes( creva );

RemBitMapPlanes( userbg );

RemBMO( drawbg );
}

/* amiga.c */
#define INC_EXEC
#define INC_DOS
#define INC_GRAPHICS
#define INC_INTUITION
#define INC_HARDWARE

#define NO_BASE

#include ".H:macros.h"

EXTERN ULONG bye( ULONG ); /* Attention a la d├ęclaration de 'bye' dans 'main' */
/* Si le prototypage ne correspond, pas de branchement */

/*-------------------------------------------------------------------------*/

INT Request ( WIN *win, STRPTR gad, STRPTR mes, APTR arg, ... );
VOID Error ( WIN *win, STRPTR txt, LONG no );
LIB OpenLib ( STRPTR name, LONG ver );
VOID CloseLib ( LIB lib );
WIN *OpenWinTag( ULONG tag,... );
VOID CloseWin ( WIN *win );
SCR *OpenScrTag( ULONG tag,... );
VOID CloseScr ( SCR *scr );
VOID FlushMsg ( MSG_PORT *mp, WIN *win );

/*-------------------------------------------------------------------------*/

INT Request( WIN *win, STRPTR gad, STRPTR mes, APTR arg, ... )
{
INT result;
STRUCT EasyStruct es;

es.es_StructSize = (ULONG) SIZEOF(struct EasyStruct);
es.es_Flags = 0;
es.es_Title = 0;
es.es_TextFormat = (UBYTE *) mes;
es.es_GadgetFormat = (UBYTE *) gad;

result=EasyRequestArgs(win,&es,0,&arg);

RETURN((INT)result);
}

/*-------------------------------------------------------------------------*/

VOID Error( WIN *win, STRPTR txt, LONG no )
{
Request(win,"Ok","\nError: %s\nCode: %ld\n",txt,no);
bye( no );
}

/*-------------------------------------------------------------------------*/

LIB OpenLib( STRPTR name, LONG ver )
{
LIB lib;
if( NOT ( lib = (LIB) OpenLibrary (name,ver) ) )
{
Request(NL,"Ok","\nError open library: %s\n Version: %ld\n",name,ver);
bye( 1 );
}
RETURN((LIB)lib);
}

/*-------------------------------------------------------------------------*/

VOID CloseLib( LIB lib )
{
if(lib) CloseLibrary(lib);
}

/*-------------------------------------------------------------------------*/

WIN *OpenWinTag( ULONG tag,...)
{
WIN *win;
if( NOT ( win = (WIN *) OpenWindowTagList (NL,&tag) ) )
{
Error(NL,"OpenWindowTags",2);
}
RETURN((WIN *)win);
}

/*-------------------------------------------------------------------------*/

SCR *OpenScrTag( ULONG tag,...)
{
SCR *scr;
if( NOT (scr=(SCR *)OpenScreenTagList(NL,&tag)))
{
Error(NL,"OpenScreenTags",2);
}
RETURN((SCR *)scr);
}

/*-------------------------------------------------------------------------*/

VOID CloseWin( WIN *win )
{
Forbid();
FlushMsg( win->UserPort, win );
win->UserPort = NL;
ModifyIDCMP( win, 0L );
Permit();
if(win) CloseWindow( win );
}

/*-------------------------------------------------------------------------*/

VOID CloseScr( SCR *scr )
{
if(scr) CloseScreen( scr );
}

/*-------------------------------------------------------------------------*/

VOID FlushMsg( MSG_PORT *mp, WIN *win )
{
INTUI_MSG *msg;
NODE *succ;

msg = ( INTUI_MSG * ) mp->mp_MsgList.lh_Head;

while( succ = msg->ExecMessage.mn_Node.ln_Succ )
{
if( msg->IDCMPWindow == win )
{
Remove( (NODE *) msg );
ReplyMsg( (MSG *) msg );
}
msg = ( INTUI_MSG * ) succ;
}
}

/*-------------------------------------------------------------------------*/

BIT_MAP *NewBitMapPlanes(ULONG w,ULONG h,ULONG d,UWORD *p0,UWORD *p1,UWORD *p2,UWORD *p3,UWORD *p4,UWORD *p5,UWORD *p6,UWORD *p7)
{
BIT_MAP *bm;
NewChip(bm,BIT_MAP); InitBitMap(bm,d,w,h);

if (p0) bm->Planes[0]=(PLANEPTR)p0;
if (p1) bm->Planes[1]=(PLANEPTR)p1;
if (p2) bm->Planes[2]=(PLANEPTR)p2;
if (p3) bm->Planes[3]=(PLANEPTR)p3;
if (p4) bm->Planes[4]=(PLANEPTR)p4;
if (p5) bm->Planes[5]=(PLANEPTR)p5;
if (p6) bm->Planes[6]=(PLANEPTR)p6;
if (p7) bm->Planes[7]=(PLANEPTR)p7;

RETURN((BIT_MAP *)bm);
}

/*-------------------------------------------------------------------------*/

BIT_MAP_OBJ *NewBMOPlanes(ULONG type,ULONG w,ULONG h,ULONG d,UWORD *p0,UWORD *p1,UWORD *p2,UWORD *p3,UWORD *p4,UWORD *p5,UWORD *p6,UWORD *p7)
{
BIT_MAP_OBJ *bmo;
NewChip( bmo, BIT_MAP_OBJ );
NewChip(bmo->bm,BIT_MAP);
InitBitMap(bmo->bm,d,w,h);

bmo->w = w;
bmo->h = h;
bmo->d = d;

bmo->cw = w/2;
bmo->ch = h/2;

bmo->type = type;

if (p0) bmo->bm->Planes[0]=(PLANEPTR)p0;
if (p1) bmo->bm->Planes[1]=(PLANEPTR)p1;
if (p2) bmo->bm->Planes[2]=(PLANEPTR)p2;
if (p3) bmo->bm->Planes[3]=(PLANEPTR)p3;
if (p4) bmo->bm->Planes[4]=(PLANEPTR)p4;
if (p5) bmo->bm->Planes[5]=(PLANEPTR)p5;
if (p6) bmo->bm->Planes[6]=(PLANEPTR)p6;
if (p7) bmo->bm->Planes[7]=(PLANEPTR)p7;

RETURN((BIT_MAP_OBJ *)bmo);
}

/*-------------------------------------------------------------------------*/
#define CIAAPRA 0xBFE001

#define PORT1 1
#define PORT2 2

#define LEFT_BUTTON 1
#define MIDDLE_BUTTON 2
#define RIGHT_BUTTON 4

EXTERN __far struct Custom custom;
struct CIA *cia = (struct CIA *) CIAAPRA;

UBYTE Mouse( BYTE *mx, BYTE *my )
{
UBYTE data = 0;
UWORD joy, pot;
static BYTE x=0, y=0, old_x=0, old_y=0;

custom.potgo = 0xFF00;
pot = custom.potinp;

joy = custom.joy0dat;
data += !( cia->ciapra & 0x0040 ) ? LEFT_BUTTON : 0;
data += !( pot & 0x0100 ) ? MIDDLE_BUTTON : 0;
data += !( pot & 0x0400 ) ? RIGHT_BUTTON : 0;

old_x = x;
x = joy & 0x00FF;
*mx = x - old_x;

old_y = y;
y = joy >> 8;
*my = y - old_y;

return( data );
}

/*-------------------------------------------------------------------------*/

TASK *task=NL;
ULONG task_status=10;

VOID FindMyTask( VOID )
{
Forbid();
task=(TASK *)FindTask(NL);
SetTaskPri(FindTask("input.device"),20);
Permit();
}

VOID SetTask40( VOID )
{
IF( task_status == 10 )
{
SetTaskPri(task,40);
task_status=40;
/* OFF_SPRITE; */
}
}

VOID SetTask10( VOID )
{
IF( task_status == 40 )
{
SetTaskPri(task,10);
task_status=10;
/* ON_SPRITE; */
}
}