/***
@author 8boomgaa & 8njemz
@date   2010/02/25 13:13
@descr
*/

/**
@form	nick(+Nicknam)
@descr	short predicate for setting a nick
*/
nick(Nick):-
	not(Nick=''),
	get_all_ids(IDList),
        send_nicks(IDList,Nick).

/**
@form	send_nicks(+ListOfIDs,+Nick)
@descr	sets same nick for all IDs in list
*/
send_nicks([],_).
send_nicks([ID|IDList],Nick):-
	send(nick_chosen(ID,Nick)),
	send_nicks(IDList,Nick).

/**
@form	get_all_ids(-ListOfIDs)
@descr	gets all IDs for current client
*/
get_all_ids(IDlist):-
	findall(ID,myID(ID),List),
	reverse(List,IDlist).

/**
@form	reduce_number_player
@descr	decrements the number in number_of_clients(Number) with 1
*/
reduce_number_player:-
	retract(number_of_clients(Num)),
	Num1 is Num - 1,
	assert(number_of_clients(Num1)).

/**
@form	do_assert(+(assert(Predicate)))
@descr	if an assert-predicate is received, checks the type and does different things
*/
do_assert(Cmd):-
	Cmd =.. [assert,Command],
	Command =.. [myID|[ID]],
	number_of_clients(Num),
	( Num > 0 -> reduce_number_player, send(connection_request(ID)) ; true),
	Cmd.
do_assert(Cmd):-
	Cmd.
