/*
 * Function name: using_soul
 * Description  : Called once by the living object using this soul. Adds
 *                sublocations responsible for extra descriptions of the
 *                living object.
 * Arguments    : object live - the living using the soul.
 */
public void
using_soul(object live)
{
    live->add_subloc(SUBLOC_SOULEXTRA, file_name(this_object()));
}

/*
 * Function name: show_subloc
 * Description  : Shows the specific sublocation description for a living.
 * Arguments    : string subloc  - the subloc to display.
 *                object on      - the object to which the subloc is linked.
 *                object for_obj - the object that wants to see the subloc.
 * Returns      : string - the subloc description.
 */
public string
show_subloc(string subloc, object on, object for_obj)
{
    if ((subloc != SUBLOC_SOULEXTRA) ||
        on->query_prop(TEMP_SUBLOC_SHOW_ONLY_THINGS) ||
	!(subloc = on->query_prop(LIVE_S_SOULEXTRA)))

	return "";

    if (for_obj == on)
    {
        string *wyrazy = explode(subloc, " ");
        string pierwszy = wyrazy[0];

        switch (pierwszy)
        {
            case "jest":
                wyrazy[0] = "jestes";
                break;
            case "jestes,":
                wyrazy[0] = "jestes,";
                break;
            default:
                if (pierwszy[-1..] == ",")
                    wyrazy[0] = pierwszy[..-2] + "sz,";
                else
                    wyrazy[0] = pierwszy + "sz";
        }
        subloc = implode(wyrazy, " ");
    }
    return capitalize(subloc + ".\n");
}

/*
 * Function name: query_cmd_soul
 * Description  : This is a command soul. This defines it as such.
 * Returns      : int 1 - always.
 */
public int
query_cmd_soul()
{
    return 1;
}

/*
 * Function name: dump_emotions
 * Description  : This function can be used to dump all emotions to a file
 *                in a sorted and formatted way. This dump can be used for
 *                the 'help emotions' document. The output of this function
 *                will be written to the file DUMP_EMOTIONS_OUT.
 * Returns      : int 1 - always.
 */
public nomask int
dump_emotions()
{
    int index = -1;
    int size = strlen(ALPHABET);
    string *words;

    setuid();
    seteuid(getuid());
    catch(rm(DUMP_EMOTIONS_OUT));
    while(++index < size)
    {
	words = filter(m_indices(query_cmdlist()),
		       &wildmatch((ALPHABET[index..index] + "*")));

	if (!sizeof(words))
	    continue;

	if (strlen(words[0]) < 12)
	    words[0] = (words[0] + "                ")[..11];

	write_file(DUMP_EMOTIONS_OUT,
	    sprintf("%-76#s\n\n", implode(sort_array(words), "\n")));
    }
    return 1;
}

/*
 * Function name: find_neighbour
 * Description  : This function will recursively search through the
 *                neighbouring rooms to a particular room to find the
 *                rooms a shout or scream will be heard in.
 * Arguments    : object *found  - the rooms already found.
 *                object *search - the rooms still to search.
 *                int    depth   - the depth still to search.
 * Returns      : object * - the neighbouring rooms.
 */
static object *
find_neighbour(object *found, object *search, int depth)
{
    int index;
    int size;
    int index2;
    int size2;
    mixed *exit_arr;
    object *new_search, *rooms, troom;

    if (!depth)
	return found;

    rooms = found;
    new_search = ({});

    index = -1;
    size = sizeof(search);
    while(++index < size)
    {
	exit_arr = (mixed *) search[index]->query_exit();

	index2 = -3;
	size2 = sizeof(exit_arr);
	while((index2 += 3) < size2)
	{
	    if (objectp(exit_arr[index2]))
		troom = exit_arr[index2];
	    else
		troom = find_object(exit_arr[index2]);
	    if (objectp(troom) &&
		(member_array(troom, rooms) < 0))
	    {
		rooms += ({ troom });
		new_search += ({ troom });
	    }
	}
    }

    return find_neighbour(rooms, new_search, depth - 1);
}

string
shout_name()
{
    /* Odbiorca. Zauwazmy, ze previous_object() to VBFC_OBJECT. */
    object pobj = previous_object(-1);

    if (environment(pobj) == environment(this_player()) &&
        CAN_SEE_IN_ROOM(pobj) && CAN_SEE(pobj, this_player()))
        return this_player()->query_Imie(pobj, PL_MIA);
    if (pobj->query_met(this_player()))
        return this_player()->query_name(PL_MIA);
    return /*this_player()->query_osobno ?
           this_player()->koncowka("Jakis mezczyzna", "Jakas kobieta") : */
           this_player()->koncowka("Jakis ", "Jakas ")
         + this_player()->query_rasa(PL_MIA);
}


string
comp_zaimki(object *kogo, int przyp, int krotki=0)
{
	string *zaimki=({"oni","ich","im","ich","nimi","nich"});
	int i;
	
	if (sizeof(kogo)==1)
	{
		return kogo[0]->query_zaimek(przyp, krotki);
	}
	if (!krotki && przyp==PL_BIE) return zaimki[przyp];
	switch (przyp)
	{
		case PL_MIA:
		    for (i=sizeof(kogo)-1;i>=0;i--)
		    { 
		    	if (kogo[i]->query_gender()==0)
		    	{
		    		return zaimki[przyp];
		    	}
		    }
		    return "one";
		case PL_BIE:
		    for (i=sizeof(kogo)-1;i>=0;i--)
		    { 
		    	if (kogo[i]->query_gender()==0)
		    	{
		    		return zaimki[przyp];
		    	}
		    }
		    return "je";
		default:
			return zaimki[przyp];
	}
}
		    
		    	
