// /klon/lib/d/Polska/std/latarnia.c

/* Lantern
 *
 */

#pragma strict_types

inherit "/std/torch";
inherit "/lib/keep";

#include <cmdparse.h>
#include <composite.h>
#include <files.h>
#include <macros.h>
#include <stdproperties.h>

void set_lamp_value(int value);
public int lamp_value();

private int lamp_val; // Value of the empty lamp

/*
 *
 */
void
create_lamp()
{
}

nomask void
create_torch()
{
  set_name("lantern");
  set_pname("lanterns");
  set_short("lantern");
  set_pshort("lanterns");

  set_long("The lantern, lit every night by lamplighter every night " +
	   "lights the streets.\n");

  //add_prop(OBJ_M_NO_GET, "Lampe chceto walnoc");
  add_prop(OBJ_M_NO_GET, "Do you want to attack the lantern?!\n");
  
  create_lamp();

  set_time_left(0); // lantern is empty at the start
}

void
set_value(int value)
{
  set_lamp_value(value);
}

void
reset_lamp()
{
}

nomask public void
reset_torch()
{
  reset_lamp();
}

// Calculate actual value of the lamp
public int
lamp_value()
{
  return torch_value() + lamp_val;
}

// Check if the object is an oil and we need to use fill_other()
int
check_oil(object ob)
{
  return (function_exists("fill_other", ob) != 0);
}

// We fill the lamp
int
do_fill(string str)
{
  string vb = capitalize(query_verb());
  string *tab;
  object *list;
  int i;

  notify_fail(vb + "what?\n");
  if (!str)
    return 0;

  // original !id(tab[0],PL_BIE))
  tab = explode(str," ");
  if (!id(tab[0]))
    return 0;

  notify_fail("Lantern is full.\n");
  if (query_time(1) == query_max_time())
    return 0;

  notify_fail(vb + " " + tab[0] + " czym?\n");
  if (sizeof(tab) < 2)
    return 0;

  // original (!list[i]->id(tab[1],PL_NAR))
  list = all_inventory(this_player());
  for (i = 0; i < sizeof(list); i++)
    if (!list[i]->id(tab[1]))
      list-=({list[i]});
  list = filter (list, check_oil);

  if (!sizeof(list))
    return 0;

  list[0]->fill_other(this_object());

  return 1;
}

void
set_lamp_value(int value)
{
  lamp_val = value;
}

void
init()
{
  ::init();

  add_action(do_fill, "fill up");
}

/*
 * It's necessery to shadow the object due to uslessnes in torch?
 *
 */
//public string
//query_light_fail()
//{
//  if (!query_time[0])
//    return "You try light the " + short() + ", but fail... " +
//      "it's useless!\n";
  
//  if (query_lit(0))
//    return capitalize(short()) + "is already full.\n";

//  return "";
//}

// Lamp is not burned out, so another shadow
//public void
//burned_out()
//{
//  ::burned_out();
//  remove_adj ("burn out");
//  odmien_short();
//  odmien_plural_short();
//}

// Lamp recovery
public string
query_recover()
{
  return MASTER + ":" + query_torch_recover() + query_keep_recover();
}

public void
init_recover(string arg)
{
  init_torch_recover(arg);
  init_keep_recover(arg);
}

// Additional line in lantern description about it fill_up state
// original: lamp_cond_desc (object dla)
public string
lamp_cond_desc (object ob)
{
  string tmp;

  tmp = capitalize(short(ob)) + " is ";
  if (query_max_time() == query_time(1))
    tmp += "full";
  else
    if (query_time(1) == 0)
      tmp += "empty";
    else
      tmp += "partly filled up";

  return tmp + ".\n";
}

varargs public mixed
long (string str, object ob)
{
  return (::long(str, ob) + lamp_cond_desc(ob));
}
