/*
 * Support for selling food and drinks
 *
 * Made by Nick
 *
 * Sierpien 96: Generalne spolszczenie /Alvin
 */


#include <stdproperties.h>
#include <macros.h>
#include <money.h>
#include <language.h>
#include <pl.h>

#define OBJECT_FN "/std/object.c"
#define ZIOLA_FN "/d/Imperium/std/ziola"

#define MONEY_SHORT(i,p) ((string)ZIOLA_FN->money_short(i,p))
#define OBLICZ_PRZYM(lp,lmn,przyp,rodz,licz) ((string)OBJECT_FN->oblicz_przym\
			(lp,lmn,przyp,rodz,licz))

inherit "/lib/pub.c";

do_przejrzyj(string s);

/*
 * Function name: init_pub
 * Description:   This function adds the buy and order command to this_player()
 *		  call it from your init()
 */
void
init_pub()
{
    add_action(do_przejrzyj, "przejrzyj");
    ::init_pub();
}


/*
 * Function name: fix_drink
 * Description:   Set up a drink and return the object
 * Arguments:	  data - The drink data from drinks arrayen
 * Returns:	  The configured drink object
 */
object
fix_drink(mixed data)
{
    int i;
    object ob;

    seteuid(getuid(this_object()));
    ob = clone_object("/std/drink");
    ob->ustaw_nazwe(data[0], data[1], data[7]);
    if ((i=sizeof(data[2]))==2)
    {  
       ob->dodaj_przym(data[2][0], data[2][1]); 
    }

    ob->set_soft_amount(data[3]);
    ob->set_alco_amount(data[4]);
    ob->set_long(data[6]);
//    ob->set_rodzaj(data[7]);
//    ob->ustaw_shorty(data[8], data[9], data[7]);
    ob->add_prop(HEAP_I_UNIT_VOLUME, data[3] + data[4]);
    ob->add_prop(HEAP_I_UNIT_WEIGHT, data[3] + data[4]);
    ob->add_prop(HEAP_I_UNIT_VALUE, data[5]);

    return ob;
}

/*
 * Function name: fix_food
 * Description:   Configure the food object and return it
 * Arguments:	  data - The data for the food
 * Returns:	  The food object
 */
object
fix_food(mixed data)
{
    int i;
    object ob;
    
    

    seteuid(getuid(this_object()));
    ob = clone_object("/std/food");
    ob->ustaw_nazwe(data[0], data[1], data[6]);
    
    if ((i=sizeof(data[2]))==2)
    { 
      ob->dodaj_przym(data[2][0], data[2][1]);
    }
          
    ob->set_amount(data[3]);
//    ob->set_rodzaj(data[6]);
//    ob->ustaw_shorty(data[7], data[8], data[6]);
    ob->set_long(data[5]);
    ob->add_prop(HEAP_I_UNIT_VOLUME, data[3]);
    ob->add_prop(HEAP_I_UNIT_WEIGHT, data[3]);
    ob->add_prop(HEAP_I_UNIT_VALUE, data[4]);

    return ob;
}



int
do_przejrzyj(string s)
{
  int i;
  
  
  if (s!="cennik")
  {
    notify_fail("Co chcesz przejrzec?\n");
    return 0;
  }
  
  say (QCIMIE(this_player(), PL_MIA) + " przeglada cennik.\n");
  if (sizeof(drinks))
  {
    write("Napoje:\n");
    for (i=1; i <= sizeof(drinks); i++)
      write(sprintf("%2d. %-30s %39s",
        i , 
        OBLICZ_PRZYM(
          drinks[i-1][2][0], drinks[i-1][2][1],PL_MIA, drinks[i-1][6], 0) +
      	" "+ drinks[i-1][0][0],
      	MONEY_SHORT(MONEY_SPLIT(drinks[i-1][4]), 1)) +"\n");
  }
  
  if (sizeof(food))
  {
    write("Jedzenie:\n");
    for (i=1; i <= sizeof(food); i++)
      write(sprintf("%2d. %-30s %39s",
        i, OBLICZ_PRZYM(
             food[i-1][2][0], food[i-1][2][1],PL_MIA, food[i-1][6], 0) +
      	   " "+ food[i-1][0][0],
      	   MONEY_SHORT(MONEY_SPLIT(food[i-1][4]), 1)) +"\n");
  }
  return 1;
}
