:- [data].
:- [gui_actions].

/**
Place both buddhas on the Buddhist Temple village tile. 
**/
place_buddha_all:-
	buddhafield(VillageField),
	tile(VillageField,Xbase,Ybase,_),
	free(@buddhasymbol1),
	free(@buddhasymbol2),
	free(@buddha1),
	free(@buddha2),
	buddha(@buddha1,A,B),
	buddha(@buddha2,C,D),
	X1 is Xbase + A,
	Y1 is Ybase + B,
	X2 is Xbase + C,
	Y2 is Ybase + D,
	file(buddhafigure,BuddhaFile),
	new(@buddha1,bitmap(BuddhaFile)),
	new(@buddha2,bitmap(BuddhaFile)),
	send(@playground,display,@buddha1,point(X1,Y1)),
	send(@playground,display,@buddha2,point(X2,Y2)).



/**
	Like place_buddha_all, but with offset.
	
	**/


place_buddha_offset(XOffset,YOffset2,AOffset3,BOffset4):-
	free(@buddhasymbol1),
	free(@buddhasymbol2),
	free(@buddha1),
	free(@buddha2),
	buddha(@buddha1,X,Y),
	buddha(@buddha2,A,B),
	file(buddhafigure,BuddhaFile),
	new(@buddha1,bitmap(BuddhaFile)),
	new(@buddha2,bitmap(BuddhaFile)),
	XPos is X + XOffset,
	YPos is Y + YOffset2,
	APos is A + AOffset3,
	BPos is B + BOffset4,
	retractall(buddha(@buddha1,X,Y)),
	retractall(buddha(@buddha2,A,B)),
	assert(buddha(@buddha1,XPos,YPos)),
	assert(buddha(@buddha2,APos,BPos)),
	send(@playground,display,@buddha1,point(XPos,YPos)),
	send(@playground,display,@buddha2,point(APos,BPos)).





/**
	puts a buddhafigure to the playersgroup besides the players name.

**/

player_takes_buddha(PlayerColour,BuddhaID):-
	id2buddha(BuddhaID,Buddha,Buddhasymbol),
	free(Buddha),
	active(_,Player,PlayerColour,_,_,_),
	buddha_symbol(Buddha,Buddhasymbol),
	player_buddha(Player,X,Y,Buddha),
	file(buddhafiguresmall,BuddhaFile),
	new(Buddhasymbol,bitmap(BuddhaFile)),
	send(@playersgroup,display,Buddhasymbol,point(X,Y)),
	assert(save(PlayerColour,Buddha)).

/**
	puts the buddha back to the village tile and removes the symbol beside the players name
	
**/

replace_buddha(BuddhaID):-
	buddhafield(FieldID),
	id2buddha(BuddhaID,Buddha,BuddhaSymbol),
	free(BuddhaSymbol),
	retractall(save(_,Buddha)),
	place_buddha_villagefield(BuddhaID,FieldID).
	

place_buddha_villagefield(BuddhaID,FieldID):-
	id2buddha(BuddhaID,Buddha,Symbol),
	%buddha(Buddha,X,Y),
	%free(Buddha),
	%file(buddhafigure,BuddhaFile),
	%new(Buddha,bitmap(BuddhaFile)),
	%send(@playground,display,Buddha,point(X,Y)).
	tile(FieldID,Xbase,Ybase,_),
	free(Buddha),
	free(Symbol),
	buddha(Buddha,A,B),
	X1 is Xbase + A,
	Y1 is Ybase + B,
	file(buddhafigure,BuddhaFile),
	new(Buddha,bitmap(BuddhaFile)),
	send(@playground,display,Buddha,point(X1,Y1)).
	
/**
	place the buddha on a ghost tile
	
	**/


place_buddha_ghostfield(BuddhaID,GhostFieldID):-
	id2buddha(BuddhaID,Buddha,_),
	replace_buddha(BuddhaID),
	%tile(GhostFieldID,X,Y,_),
	%ghostfield_buddha_offset(GhostFieldID,Offset,Offset2),
	tile(GhostFieldID,Xbase,Ybase,_),
	buddha(Buddha,Xoffset,Yoffset),
	GhostFieldID = (_,_),
	XPos is Xbase + Xoffset,
	YPos is Ybase + Yoffset,
	send(@playground,display,Buddha,point(XPos,YPos)).


/**
	Remove buddha from ghost tile
	
	**/

replace_buddha_from_ghostfield(Buddha):-
      	free(Buddha),
	buddha(Buddha,X,Y),
	file(buddhafigure,BuddhaFile),
	new(Buddha,bitmap(BuddhaFile)),
	send(@playground,display,Buddha,point(X,Y)).

	

