/*
 * Latarnia
 *
 * Kod powinien zachowac charakter standardu
 */

#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;   // Wartosc pustej lampy

/* Ta funkcje mozna redefiniowac w klonach
 */
void
create_lamp()
{
} 

nomask void
create_torch()
{
  //    ustaw_nazwe( ({ "latarnia", "latarni", "latarni", "latarnie", 
  //      "latarnia", "latarni" }), ({ "latarnie", "latarni", "latarniom",
  //      "latarnie", "latarniami", "latarniach" }), PL_ZENSKI);

  set_long("Latarnia co noc zapalana przez latarnika by w nocy " +
	   "oswieltic mroczne ulice.\n");

  add_prop(OBJ_M_NO_GET,"Lampe chceto walnoc?\n");

  create_lamp();

  set_time_left(0); // Na poczatku lampa jest pusta
}

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

void
reset_lamp()
{
}

nomask public void
reset_torch()
{
  reset_lamp();
}
 
// Obliczamy aktualna wartosc lampy
public int
lamp_value()
{
  return torch_value() + lamp_val;
}

// Kontrola czy sprawdzany obiekt jest olejem, wymagane od niego posiadanie
// funkcji fill_other()
int
check_oil(object ob)
{
  return (function_exists("fill_other",ob)!=0);
}

// Napelnianie lampy
int
do_fill(string str)
{
  string vb=capitalize(query_verb());
  string *tab;
  object *lista;
  int i;
    
  notify_fail(vb+" co?\n");
  if (!str)
    return 0;

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

  notify_fail("Lampa jest juz pelna.\n");
  if (query_time(1)==query_max_time())
    return 0;
  
  notify_fail(vb+" "+tab[0]+" czym?\n");
  if (sizeof(tab)<2)
    return 0;  
  
  lista=all_inventory(this_player());
  for (i=0;i<sizeof(lista);i++)
    if (!lista[i]->id(tab[1],PL_NAR))
      lista-=({lista[i]});
  lista=filter(lista,check_oil);

  if (!sizeof(lista))
    return 0;
  
  lista[0]->fill_other(this_object());

  return 1;
}

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

void
init()
{
  ::init();

  add_action(do_fill, "napelnij");  
  add_action(do_fill, "wypelnij");
}

/*
 * Konieczne bylo pokrycie ze wzgledu na uwage o
 * bezuzytecznosci w pochodni
 */
public string
query_light_fail()
{
  if (!query_time(0))
    return "Probujesz zapalic " + short(PL_BIE) + ", ale ci sie nie "+
      "udaje... " + (query_tylko_mn() ? "sa" : "jest") +
      " wyczerpan" + koncowka("y", "a", "e", "i", "e") + ".\n";
  
    if (query_lit(0))
      return capitalize(short(PL_MIA)) + " juz " + 
	(query_tylko_mn() ? "sa" : "jest") + " zapal" + 
	koncowka("ony", "ona", "one", "eni", "one") + ".\n";
    
    return "";
}

// Lampa nie jest tez wypalona, wiec znow pokrycie
public void
burned_out()
{
  ::burned_out();
    remove_adj("wypalony");
    odmien_short();
    odmien_plural_short();
}

// Odzyskiwanie lampy
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);
}

// Dodatkowa linijka w opisie lampy, o stanie jej napelnienia
public string
lamp_cond_desc(object dla)
{
    string tmp;
    
    tmp=capitalize(short(dla,PL_MIA))+" jest ";
    if (query_max_time()==query_time(1))
      tmp+="peln";
    else
      if (query_time(1)==0)
       tmp+="pust";
      else
	tmp+="czesciowo wypelnion";
    
    return (tmp+koncowka("y","a","e")+".\n");
}

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