/
teeny/db/
teeny/dbm/
teeny/doc/
teeny/includes/
#include <stdio.h>

#include "teeny.h"

/*
Copyright(C) 1990, Andrew Molitor, All Rights Reserved.
This software may be freely used, modified, and redistributed,
as long as this copyright message is left intact, and this
software is not used to develop any commercial product, or used
in any product that is provided on a pay-for-use basis.

No warranties whatsoever. This is not guaranteed to compile, nor,
in the event that it does compile to binaries, are these binaries
guaranteed to perform any function whatsoever.
*/

/*
	Routines for sending strings to players.
*/

notify_bad(player)
int player;
{
	notify_player(player,"Something truly horrid happened. Good luck.\n");
}

do_huh(player)
int player;
{
	notify_player(player,"Huh? (type \"help\" for help)\n");
}
/*

	Echoes the string to everyone in the room the player is in, except the
player itself

*/

notify_oall(player,str)
int player;
char *str;

{
	notify_except(player,str,player);
}

/*
	Echoes the string to everyone in the room the player is in.
*/
notify_all(player,str)

int player;
char *str;

{
	notify_except(player,str,-1);
}

/*
	Writes a list out to a player, displaying numbers and so forth when
appropriate.

*/

notify_list(player,list,buff,siz,dark_ok)

int player;	/* Obj # of player. */
int list;	/* Obj # of 1st list element */
char *buff;
int siz;
int dark_ok;

{
	char *name,*end;
	int count,spaceleft;
	int ret;
	int flags;

	/* Loop over the whole list */

	end = buff;
	spaceleft = siz-1; /* Save one space for \0 terminator */

	for(count = 0; list != -1 && count < MAXLIST; count++){

		if(!dark_ok){
			if(get_int_elt(list,FLAGS,&flags) == -1){
				warning("notify_list","bad flags reference");
				break;
			}

			if(flags & DARK){ /* Skip this name */
				if(get_int_elt(list,NEXT,&list) == -1){
					warning("notify_list"
						,"bad next reference");
					break;
				}
				continue;
			}
		}
			
		if(list != player){
			if(get_str_elt(list,NAME,&name) == -1){
				warning("notify_list","bad name reference");
				break;
			}

			ret = stuff_name(player,list,end,spaceleft);

			if(ret == -1){ /* Name didn't fit */
				*end = '\0';
				notify_player(player,buff);
				end = buff;
				spaceleft = siz-1;

				/* Shove this name in again. */

				ret = stuff_name(player,list,end,spaceleft);
				if(ret != -1){
					end += ret;
					*end++ = '\n';
					spaceleft -= (ret+1);
				} /* Else fuckit. */
			} else {
				end += ret;
				*end++ = '\n';
				*end = '\0';
				spaceleft -= (ret+1);
			}
		}

		if(get_int_elt(list,NEXT,&list) == -1){
			warning("notify_list","bad next reference");
			break;
		}
	}

	/* Is there anything left in the buffer? */

	if(end != buff){
		notify_player(player,buff);
	}
}



/*
	Notifies everyone in the room where player is, except possibly the
specified object number (typically either player or -1)

*/

notify_except(player,str,except)
int player;
char *str;

{
	int location,list,flags;

	if(get_int_elt(player,LOC,&location) == -1){
		warning("notify_except","bad player location ref");
		return;
	}

	/* Grab the first thing in the contents list */

	if(get_int_elt(location,CONTENTS,&list) == -1){
		warning("notify_except","bad contents reference on player loc");
		return;
	}

	/* Trot down the contents list, looking for objects that are alive */

	while(list != -1){
		if(!exists_object(list)){
			warning("notify_except",
				"non existant object in contents list");
			return;
		}
		if(get_int_elt(list,FLAGS,&flags) == -1){
			warning("notify_except","bad flags ref");
			return;
		}
		if((flags & ALIVE) && list != except){
			notify_player(list,str);
		}

		if(get_int_elt(list,NEXT,&list) == -1){
			warning("notify_except"
				,"bad reference to contents list");
			return;
		}
	}
}