/**
 @descr inform every player about movement
 @form broadcastMove(PlayerID,TileID)
 */


%% player %%
broadcastCurrentPlayer :-
	currentPlayer(ID),
	broadcasting(set_current_player(ID)).

broadcastMove(PlayerID,TileID) :-
	broadcasting(move_player(PlayerID,TileID)).

broadcastQi(PlayerID) :-
	taoist(PlayerID,_,A,Qi,_,_),
	broadcasting(set_taomarker_and_qi(PlayerID,[Qi|A])).	 


broadcastTaoMarkers(PlayerID,MarkerList):-
	taoist(PlayerID,_,_,Qi,_,_),
	broadcasting(set_taomarker_and_qi(PlayerID,[Qi|MarkerList])).

broadcastUpdate :-
	broadcastUpdateVillageOrder,
	broadcastUpdateTaoist(yellow),
	broadcastUpdateTaoist(red),
	broadcastUpdateTaoist(green),
	broadcastUpdateTaoist(blue).

broadcastUpdateVillageOrder :-
	% Order of village fields
	village(Pos1,_,_,_,1),
	village(Pos2,_,_,_,2),
	village(Pos3,_,_,_,3),
	village(Pos4,_,_,_,4),
	village(Pos5,_,_,_,5),
	village(Pos6,_,_,_,6),
	village(Pos7,_,_,_,7),
	village(Pos8,_,_,_,8),
	village(Pos9,_,_,_,9),
	PosList = [Pos1,Pos2,Pos3,Pos4,Pos5,Pos6,Pos7,Pos8,Pos9],
	broadcasting(set_village_fields(PosList)).

broadcastUpdateTaoist(Player) :-
	taoist(Player,_,Taos,Qi,YY,Pos),
	broadcasting(set_taomarker_and_qi(Player,[Qi|Taos])),
	broadcasting(setYY(YY)), % FIXME kein gegenpart
	broadcasting(move(Player,Pos)).	

broadcastTaoistAlive(TargetPlayer) :-
	broadcasting(alive(TargetPlayer)).

broadcastTaoistDead(ID) :-
	broadcasting(death(ID)).

%% ghosts %%
broadcastGhostDraw(GhostID) :-
	broadcasting(preview_ghost(GhostID)).

broadcastGhostPlace(GhostID,FieldID) :-
	broadcasting(placeGhost(FieldID,GhostID)).

broadcastDeleteGhost(Pos) :-
	broadcasting(remove_ghost(Pos)).

broadcastHidePreviewGhost:-
	broadcasting(hide_preview_ghost).


%% haunting %%
broadcastGhostHaunt(FieldID,Counter) :-
	broadcasting(haunt(FieldID,Counter)).

broadcastVillageHaunt(TileID) :-
	village(TileID,_,_,_,Pos),
	broadcasting(haunt_village(Pos,TileID)).

broadcastVillageUnhaunt(TileID) :-
	village(TileID,_,_,_,Pos),
	broadcasting(unhaunt_village(Pos,TileID)).


broadcastDeleteHaunter(Pos) :-
	broadcasting(remove_haunter(Pos)).


%% buddhas %%
broadcastBuddhaToPlayer(PlayerID,BuddhaID):-
	broadcasting(buddha_to_player(PlayerID,BuddhaID)).

broadcastBuddhaPlace(BuddhaID,FieldID) :-
	broadcasting(place_buddha(BuddhaID,FieldID)).

%%  Dice %%%

broadcastCurseDie(Curse):-
	broadcasting(show_curse_die(Curse)).

broadcastColorDice(Count,ColorList) :-
	broadcasting(color_dice(Count,ColorList)).

%%%%
% predicates not implemented by gui group
%%%%
broadcastPrayer([0,0,0,0,0]) :-
	broadcasting(delete_tao_from_prayer),
	!.

broadcastPrayer(TaoMarker):-
	broadcasting(set_tao_onto_prayer(TaoMarker)).

broadcastYY(Player) :-
	broadcasting(yy_change(Player)).

broadcastNoGhost :-
	true.
	%broadcasting(noGhost).

broadcastUndefeatable :-
	broadcasting(undefeatable).

broadcastTaoistLost(PlayerID):-
	broadcastQi(PlayerID),
	broadcasting(youLoose(PlayerID)).

broadcastGameOver(win) :-
	broadcasting(win).

broadcastGameOver(lost):-
	broadcasting(gameover).

broadcastClearDice :-
	broadcasting(clear_dice).

broadcastNoHighlight:-
	broadcasting(no_highlight).



