/* Obiek sluzacy do uciszania niewygodnych osob ......
 *
 * Napisane przez Mithandira na podstawie oiektu Alfena.
 *
 */

#include "mith.h"
#include "ryc_zak.h"
inherit "/std/paralyze";

/* Some commands may always be issued. */
#define ALLOWED ({ "?", "pomoc", "reply" })

stop_paralize()
{
    object ob = environment(this_object());
    
    if (ob && living(ob) && ob->query_prop(RZ_O_CIALO))
	tell_room(environment(ob->query_prop(RZ_O_CIALO)), 
		  QCIMIE(this_player(), PL_MIA)+" otwiera oczy i powoli podnosi sie"
		  +" z ziemi.\n");
    write("Otwierasz oczy i powoli podnosisz sie z ziemi.\n");
}

void
create_paraliz()
{
  set_standard_paralyze(" byc ogluszonym");
  set_stop_verb("robaczek");
}


public nomask void
create_paralyze()
{
  create_paraliz();
}


/*
 * Function name: stop
 * Description  : Here all commands the player gives comes.
 * Argument     : string str - The command line argument.
 * Returns      : int 1/0    - success/failure.
 */
int
stop(string str)
{
    /* Only paralyze our environment */
    if (environment() != this_player())
    {
	return 0;
    }

    /* Some commands may always be issued. */
    if (member_array(query_verb(), ALLOWED) != -1)
    {
	return 0;
    }

    /* If there is a verb stopping the paralyze, check it. */
    if (stringp(stop_verb) &&
	(query_verb() == stop_verb))
    {
	/* If a stop_fun is defined it MUST return 1 in order not stop the
	 * paralyze.
	 */
	if (objectp(stop_object) &&
	    call_other(stop_object, stop_fun, str))
	{
	    return 1;
	}

	set_alarm(0.3, 0.0, remove_object);

	if (stringp(stop_message))
	{
	    this_player()->catch_msg(stop_message);
	}

	return 1;
    }

    /* We allow VBFC, so here we may use catch_msg(). */
    if (stringp(fail_message))
    {
	this_player()->catch_msg(fail_message);
    }

    /* Only paralyze mortals. */
    if ((this_player()->query_real_name())!="mithandir")
    {
	return 1;
    }
    else
    {
      write("No coz na tworcy sie nie da uzyc tego obiektu.... \n");
      if (objectp(stop_object) &&
	    call_other(stop_object, stop_fun, str))
	{
	    return 1;
	}

	set_alarm(0.3, 0.0, remove_object);

	if (stringp(stop_message))
	{
	    this_player()->catch_msg(stop_message);
	}

	return 1;
    }
    return 0;
}


void
enter_env(object dest, object old)
{
  if (dest&&living(dest))
  {
    dest->add_prop(LIVE_S_EXTRA_SHORT,
      " lezy na ziemi ogluszon"+dest->koncowka("y","a"));
    dest->add_prop(LIVE_I_STUNNED, 40);
  } 
  ::enter_env(dest, old);
}


int
remove_object()
{
    object ob = environment(this_object());
    object *inv;
    int tmp, s;

    if (ob && living (ob) )
    {
	ob->remove_prop(LIVE_S_EXTRA_SHORT);
	ob->remove_prop(LIVE_I_STUNNED);
	ob->add_prop (P_OGL, ob->query_prop (P_OGL) / 3); 
	ob->move(environment(ob->query_prop(RZ_O_CIALO)));
	
	inv = all_inventory(ob->query_prop(RZ_O_CIALO));
	s = sizeof(inv);

	for (tmp = 0 ; tmp < s ; tmp++)
	    inv[tmp]->move(ob, 1);
	ob->query_prop(RZ_O_CIALO)->remove_object();
    }
    return ::remove_object();
}

void
kill_and_remove(object killer)
{
    object ob = environment(this_object());
    object *inv;
    int tmp, s;

    if (ob && living (ob) )
    {
	ob->remove_prop(LIVE_S_EXTRA_SHORT);
	ob->remove_prop(LIVE_I_STUNNED);
	ob->add_prop (P_OGL, ob->query_prop (P_OGL) / 3); 
	ob->move(environment(ob->query_prop(RZ_O_CIALO)));
	
	inv = all_inventory(ob->query_prop(RZ_O_CIALO));
	s = sizeof(inv);

	for (tmp = 0 ; tmp < s ; tmp++)
	    inv[tmp]->move(ob, 1);
	ob->query_prop(RZ_O_CIALO)->remove_object();
	ob->set_hp (0);
	ob->do_die (killer);
	if (!ob->query_ghost() )
	{
	    ob->set_hp(0);
	    ob->do_die (killer);
	}
    }
    ::remove_object();
}
