/* Plik:          monster.c
 * Autor:         Silvy
 * Data:          14.10.97
 * Last update:   14.11.97
 * Opis:          Standardowy npc w domenie Imperium
 * Update:	  Dodanie funkcji umozliwiajacych klonowanie
 *		  npcow o okreslonych porach dnia i roku
 */

inherit "/std/monster.c";
inherit "/std/act/add_things";

#include <macros.h>
#include <money.h>
#include "/d/Imperium/sys/alarm.h"


private static string *bronie = ({});
private static string *zbroje = ({});
private static mixed kiedy_npc = ({});
private mixed stare_miejsce = VOID;



int czy_npc_nie_wystepuje(string pora_d, string pora_r);


void
ustaw_stare_miejsce(mixed l)
{
  stare_miejsce = l;
}


mixed
query_stare_miejsce()
{
  return stare_miejsce;
}



void
szykuj()
{
    int i;
    object ob;

    for ( i = 0; i < sizeof(zbroje); i++ )
    {
        ob = clone_object(zbroje[i]);
        if (objectp(ob))
        {
            ob -> move(this_object(), 1);
            this_object()->command("zaloz " + ob->query_nazwa(3));
        }
    } 
    for ( i = 0; i < sizeof(bronie); i++ )
    {
        ob = clone_object(bronie[i]);
        if (objectp(ob))
        {
            ob -> move(this_object(), 1);
            command("dobadz " + ob->query_nazwa(1));
        }
    }                                                    
}    


    
void
add_armour(string sciezka)
{
    zbroje+=({sciezka});
}



void
add_weapon(string sciezka)
{
    bronie+=({sciezka});
}



void
dodaj_miedz(int ile)
{
    MONEY_MAKE_CC(ile)->move(this_object());
}


void
dodaj_srebro(int ile)
{
    MONEY_MAKE_SC(ile)->move(this_object());
}


void
dodaj_zloto(int ile)
{
    MONEY_MAKE_GC(ile)->move(this_object());
}



int
czy_npc_nie_wystepuje(string pora_d, string pora_r)
{
  int i=0, il = sizeof(kiedy_npc);
  mapping pom = ([	"polnoc"	: A_POLNOC,
  			"swit"	 	: A_SWIT,
  			"ranek"         : A_RANEK,
  			"wczesny ranek" : A_WCZRANEK,
  			"poludnie"	: A_POLUDNIE,
  			"popoludnie"	: A_POPOLUDNIE,
  			"wieczor"	: A_WIECZOR,
  			"pozny wieczor"	: A_PWIECZOR,
  			"noc"		: A_NOC,		]);
  
  if (!il)
    return 0;
  
  while ((--il >= 0)&&(kiedy_npc[il][0] != pora_r));
  if (il<0)
    return 1;
  return !(pom[pora_d]&kiedy_npc[il][1]);
}



void
pora_znikac(string s, mixed skad)
{
    this_object()->move(VOID);
}



void
pora_pojawic_sie(string s, mixed gdzie)
{
     this_object() -> move(gdzie);
}


public void 
czas(string s)
{
  object ob = environment(this_object());
  if (czy_npc_nie_wystepuje(s, VOID->pora_roku()))
  {
    if ((ob!=VOID)&&ob)
    {
      stare_miejsce = ob;
      pora_znikac(s, ob);
    }
  }
  else
    if ((ob!=stare_miejsce)&&ob)
    {
      pora_pojawic_sie(s, stare_miejsce);
      stare_miejsce = VOID;
    }
}



void
ustaw_czas_wystepowania(mixed kiedy)
{
    kiedy_npc = kiedy;
    if (sizeof(kiedy))
      ALARM->dodaj_obiekt(this_object(), A_CALY_DZIEN);
}



int
remove_object()
{
  if (sizeof(kiedy_npc))
    ALARM -> usun_obiekt(this_object());
  return ::remove_object();
}


mixed
query_czas_wystepowania()
{
  return kiedy_npc + ({});
}
