#include <macros.h>
#include <filter_funs.h>
#include <composite.h>

#include "woz.h"

inherit "/std/room.c";

object woz;

int yell(string str);
int zsiadz(string a);
int rozejrzyj(string a);

void
create_room()
{
    add_item("okolice", "@@okolica");
}

void
init()
{
    add_action(yell, "krzyknij");
    add_action(zsiadz, "zsiadz");
    add_action(zsiadz, "zeskocz");
    add_action(rozejrzyj, "rozejrzyj");
    ::init();
}

string
okolica()
{
    string str = environment(woz)->long();
    object *oblist = all_inventory(environment(woz));
    oblist = FILTER_LIVE(oblist);

    if (sizeof(oblist))
	str += capitalize(COMPOSITE_LIVE(oblist, PL_MIA) + ".\n");

    say(QCIMIE(this_player(), PL_MIA) + " rozglada sie po okolicy.\n");
    
    return str;
}

int
rozejrzyj(string str)
{
    if (str != "sie")
    {
	notify_fail("Rozejrzyj sie?\n");
	return 0;
    }

    this_player()->catch_msg(okolica());
    return 1;
}
    
void
ustaw_obiekt_wozu(object ob)
{
    woz = ob;
}

int
yell(string str)
{
    if (!stringp(str))
	return 0;

    tell_room(environment(woz), QCIMIE(this_player(), PL_MIA) + 
	      " krzyczy z wozu: " + str + "\n");
    return 0;
}

int
zsiadz(string str)
{
    if (str != "z wozu")
    {
	notify_fail("Zsiasc skad? Moze z wozu?\n");
	return 0;
    }

    if (query_verb() == "zsiadz" && woz->query_jedzie())
    {
	notify_fail("Nie mozesz zsiasc kiedy woz jedzie, mozesz jedynie zeskoczyc.\n");
	return 0;
    }

    if (query_verb() == "zeskocz" && woz->query_jedzie())
    {
	say(QCIMIE(this_player(), PL_MIA) + " zeskakuje nagle z jadacego wozu.\n");
	this_player()->move_living("M", environment(woz), 1, 0);
	say(QCIMIE(this_player(), PL_MIA) + " zeskakuje nagle z jadacego wozu.\n");
	this_player()->remove_prop(ZAPLACILEM_ZA_WOZ);
	return 1;
    }

    say(QCIMIE(this_player(), PL_MIA) + " zsiada z wozu.\n");
    this_player()->move_living("M", environment(woz), 1, 0);
    say(QCIMIE(this_player(), PL_MIA) + " zsiada z wozu.\n");
    return 1;
}

void
enter_inv(object ob, object from)
{
    if (living(ob))
	woz->add_pasazer();
    ::enter_inv(ob, from);
}

void
leave_inv(object ob, object to)
{
    if (living(ob))
	woz->sub_pasazer();
    ::leave_inv(ob, to);
}
	    
