:- consult('../network/client.pl').

%%%%%%%%%%%%%%%%%
% chat predicates %
%%%%%%%%%%%%%%%%%
sendmessage(Message):-
	format('(chatmessage): ~w ~n', [Message]),
	myID(ID),send(chat(ID,Message)).
	
append_to_history(chat(ID, Text)):-
	% send message to gui:
	% get(Message, value, Atom),
	%atom_to_term(Atom, chat(Id, Text),_),
	atom_concat(ID, ': ', A1),
	atom_concat(A1, Text, Msg),
	write_ln(Msg),
	gui_chat_append_to_history(Msg).

append_status_to_history(Msg):-
	write_ln(Msg),
	gui_chat_append_to_history(Msg).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% predicates pertaining to player/2 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set_player_color(Color):-
	gui_set_player_color(Color).

set_player_name(Color,Name):-
	gui_set_player_name(Color,Name).

set_this_player(Color):-
	% Network:
	
	% Do not change:
	gui_set_this_player(Color).

set_current_player(Color):-
	% Network:
	
	% Do not change:
	gui_set_current_player(Color).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% predicates for player movement %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
get_player_move(PossibleMoves):-
	gui_get_player_move(PossibleMoves).

return_player_move(Move):-
	% FIXME: Network here
%	myID(ID),send(move(ID, Move)),
	player(me,Color),send(move(Color, Move)),
	format('(Player moves to): ~d ~n', [Move]).

move_player(Color,Place):-
	moveFigure(Color,Place).

% predicate for taomarkers an qi	
set_taomarker_and_qi(Colour,List):-
	gui_set_taomarker_and_qi(Colour,List).

%predicate for death-message
death(Colour):-
	gui_death(Colour).

%predicate for alive-message
alive(Colour):-
	gui_alive(Colour).

%%%%%%%%%%%%%%%%%%
% ghost predicates %
%%%%%%%%%%%%%%%%%%

preview_ghost(GhostID):-
	show_preview_ghost(GhostID).

hide_preview_ghost:-
	remove_preview_ghost.

placeGhost(FieldID,GhostID):-
	FieldID = (X,Y),
	place_ghost(GhostID,X,Y).


get_ghost_placement(PossiblePlaces,GhostID):-
	% FIXME: Have to get the ghostID from network!
	gui_get_ghost_placement(PossiblePlaces,GhostID).

return_ghost_placement(Place):-
	player(me,Color),
	send(placeGhost(Color,Place)),
	Place = (X,Y),
	format('(Ghost placed at): ~d / ~d ~n',[X,Y]).
remove_ghost(FieldID):-
	gui_remove_ghost(FieldID).

ghostSelect(GhostList):-
	assert(returnFor(ghost)),
	gui_select_ghost(GhostList).

return_select_ghost(FieldID):-
	player(me, Color),
	% debug output
	write_ln('sending to ghostSelect(...)'),
	send(ghostSelect(Color, FieldID)).

% give me a list of ghostfields
select_ghost_village(GhostList):-
	assert(returnFor(village)),
	gui_select_ghost(GhostList).
	
return_ghost_village(FieldID):-
	player(me, Color),
	write_ln('sending to village(...)'),
	send(village(Color, FieldID)).



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% predicates concerning haunting %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
haunt(FieldID,Counter):-
	draw_haunter_ghost(FieldID,Counter).

haunt_village(Place,VillageType):-
	gui_haunt_village(Place,VillageType).

unhaunt_village(Place, VillageType):-
	gui_unhaunt_village(Place,VillageType).

remove_haunter(FieldID):-
	gui_remove_haunter(FieldID).


%%%%%%%%%%%%%%%%%%%
% buddha predicates %
%%%%%%%%%%%%%%%%%%%
buddha_to_player(Player,BuddhaID):-
	gui_buddha_to_player(Player, BuddhaID).


place_buddha(BuddhaID,FieldID):-
	gui_buddha_to_place(BuddhaID,FieldID).

get_buddha_placement(PossiblePlaces,BuddhaID):-
	gui_get_buddha_placement(PossiblePlaces,BuddhaID).


return_buddha_placement(Place):-
	player(me,Color),
	send(placeBuddha(Color,Place)).



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% predicates concerning gameplay %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
do_next(List):-
	gui_do_next(List).

return_do_next(Choice):-
	player(me,Color),
	% debug output
	send(doNext(Color, Choice)),
	write_ln('You made your choice').

next_action:-
	% network code
	player(me, Color),
	player(current, Color),
	myID(_),
	send(nextPhase(Color)).

return_fight_aborted :-
	% debug_output
	player(me, Color),
	send(chooseMarkers(Color,[])).

return_fight_accepted(White, Taos) :-
	player(me, Color),
	% debug output
	send(chooseMarkers(Color, White, Taos)).

gameover:-
	gui_gameover.

win :-
	gui_youwin.

set_village_fields(OrderList):-
	gui_set_villagefields(OrderList).

%opens a window for choosing a player, returns the color of the player when its Button is clicked
choose_player(PlayerList):-
	gui_choose_player(PlayerList).

% predicate for opening a window for choosing a tao marker color
choose_tao_marker:-
	gui_choose_tao_marker_window.

% predicat for sending the chosen tao marker to the server (called in choose_tao_marker.pl
markerChosen(ListWithColor):-
	player(me, Color),
	send(chooseOneMarker(Color,ListWithColor)).

return_choose_player(Player) :-
	%debug output
	send(chooseTaoist(Color,Player)).
	
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dice predicate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

show_curse_die(Num):-
	gui_show_curse_dice(Num).

color_dice(Count,ColorList):-
	roll_the_dice(Count,ColorList).

clear_dice:-
	hide_dice,
	gui_hide_curse_dice.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% predicates concerning fight %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% is called from fightdialog to send result back to network
markersChosen(White, Taos) :- 
	%write_ln('we are here!').
	% debug output
	player(me, Color),
	send(chooseMarkers(Color, White,Taos)).

% is called from network
choose_markers(Resistance,White,Taos,GhostID):-
        gui_fight(Resistance,White,Taos,GhostID).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% predicates for village people %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% sets a tao marker onto the circle of prayer field
set_tao_onto_prayer(ListWithColor):-
	gui_set_tao_onto_prayer(ListWithColor).

% removes the tao marker from the circle of prayer field
delete_tao_from_prayer:-
	gui_delete_tao_from_prayer.



%%%%%%%%%%%%%%%%%%%%%% Villagefield Stuff %%%%%%%%%%%%%%%%

select_villagefield(FieldList):-
	gui_select_villagefield(FieldList).

return_select_villagefield(FieldID):-
	player(me, Color),
	% debug output
	send(village(Color, FieldID)).

%NoHighlighting

no_highlight:-
	nohighlight.

