/* notify.c */ #include "copyright.h" #include "config.h" #include <stdio.h> #include "teeny.h" void notify_except(); /* * Routines for sending strings to players. */ void notify_bad(player) int player; { notify_player(player, "Something truly horrid happened. Good luck.\r\n"); } void do_huh(player) int player; { notify_player(player, "Huh? (Type \"help\" for help.)\r\n"); } /* * Echoes the string to everyone in the room the player is in, except the player * itself * */ void 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. */ void 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. * */ void 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; { int count, len; /* Loop over the whole list */ for (count = 0; list != -1 && count < MAXLIST; count++) { if (!dark_ok) { if (!can_see(player, list)) { /* Skip this name */ if (get_int_elt(list, NEXT, &list) == -1) { warning("notify_list", "bad next reference"); break; } continue; } } if ((dark_ok && (list == player)) || list != player) { if ((len = stuff_name(player, list, buff, siz - 3)) != -1) { buff[len] = '\r'; buff[len + 1] = '\n'; buff[len + 2] = '\0'; notify_player(player, buff); } /* just what the fuck should i do if it didn't fit? crash? */ } if (get_int_elt(list, NEXT, &list) == -1) { warning("notify_list", "bad next reference"); break; } } } /* * Notifies everyone in the room where player is, except possibly the * specified object number (typically either player or -1) * */ void notify_except(player, str, except) int player; char *str; int except; { 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"); continue; } if (get_int_elt(list, FLAGS, &flags) == -1) { warning("notify_except", "bad flags ref"); continue; } 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; } } } /* notify everyone in player's location except two people */ void notify_except2(player, string, except1, except2) int player; char *string; int except1, except2; { int loc, list; if (get_int_elt(player, LOC, &loc) == -1) { warning("notify_except2", "bad loc ref on player"); return; } if (get_int_elt(loc, CONTENTS, &list) == -1) { warning("notify_except2", "bad contents list on loc"); return; } while (list != -1) { if (isalive(list) && (list != except1 && list != except2)) notify_player(list, string); if (get_int_elt(list, NEXT, &list) == -1) { warning("notify_except2", "bad next ref on object"); return; } } }