#include "defs.h"
inherit "/d/Warhammer/std/room";
private mixed health_state, denom_strings;
void create_loza();
string opis_areny();
int sprawdz(string str);
void
create_room()
{
	set_short("Standardowa loza");
	set_long("Standardowa loza.\n");
	add_item("arene", "@@opis_areny");
	health_state = 	({ SD_HEALTH("y"), SD_HEALTH("a"), SD_HEALTH("e") });
	denom_strings = 	SD_STAT_DENOM;
	create_loza();
}
void
init()
{
	::init();
	add_action("sprawdz", "sprawdz");
}
public varargs string
get_proc_text(int num, mixed maindesc, int turnpoint, mixed subdesc)
{
    int a, b, c, d,j;
    mixed subs;
    if (!sizeof(maindesc))
	return ">normal<";
    if (num < 0)
	num = 0;
    if (num > 99)
	num = 99;
    j = sizeof(maindesc) * num / 100;    
    
    if (!pointerp(subdesc))
	subs = denom_strings;
    else if (sizeof(subdesc))
	subs = subdesc;
    else
	return maindesc[j];
    a = num - (j * 100 / sizeof(maindesc));
    b = (sizeof(subs) * a * sizeof(maindesc)) / 100;
    if (j < turnpoint)
	b = (sizeof(subs) - 1) - b;
    return subs[b] + maindesc[j];
}
public string
show_subloc_health(object on, object for_obj)
{
    int hp, mhp;
    hp = on->query_hp();
    mhp = on->query_max_hp();
    if (mhp == 0)
	mhp = 1;
	
    return get_proc_text((hp * 100) / mhp, (on == this_player() ?
	health_state[this_player()->koncowka(0, 1, 2)] : 
	health_state[on->koncowka(0, 1, 2)]), 0, ({}) );
}
void
create_loza()
{
}
string
opis_areny()
{
	string str;
	int i;
	object *glady;
	
	glady = SILNIK->query_zawodnicy();
	if(!sizeof(glady))
	  str = "Na arenie obecnie nikogo niema.\n";
	else
      str = "Obecni na arenie zauwazasz " + COMPOSITE_FILE->desc_live(glady, PL_BIE, 1) + ".\n";
     
    return str;	
}
int
sprawdz(string str)
{
	object *arena_n, *arena_s, *arena_w, *arena_e, *arena_sr;
	string text = "";
	int i;
	
	notify_fail("Co chcesz sprawdzic? Moze kondycje walczacych na arenie?\n");
	if(!str && str != "kondycje walczacych") return 0;
	notify_fail("Na arenie nie ma obecnie nikogo.\n");
	if(!sizeof(SILNIK->query_zawodnicy())) return 0;
	arena_n = FILTER_LIVE(SILNIK->query_zawodnicy_arena(KAMERA_N));
	arena_s = FILTER_LIVE(SILNIK->query_zawodnicy_arena(KAMERA_S));
	arena_w = FILTER_LIVE(SILNIK->query_zawodnicy_arena(KAMERA_W));
	arena_e = FILTER_LIVE(SILNIK->query_zawodnicy_arena(KAMERA_E));
	arena_sr = FILTER_LIVE(SILNIK->query_zawodnicy_arena(KAMERA_SR));
	if(sizeof(arena_n))
	{
		text += "Na polnocnej czesci areny:\n";
		for(i=0; i<sizeof(arena_n); i++)
		   text += arena_n[i]->query_Imie(this_player(), PL_MIA) + " " + show_subloc_health(arena_n[i], this_player()) + ".\n";
	}
	if(sizeof(arena_s))
	{
		text += "Na poludniowej czesci areny:\n";
		for(i=0; i<sizeof(arena_s); i++)
		   text += arena_s[i]->query_Imie(this_player(), PL_MIA) + " " + show_subloc_health(arena_s[i], this_player()) + ".\n";
	}
	if(sizeof(arena_w))
	{
		text += "Na zachodniej czesci areny:\n";
		for(i=0; i<sizeof(arena_w); i++)
		   text += arena_w[i]->query_Imie(this_player(), PL_MIA) + " " + show_subloc_health(arena_w[i], this_player()) + ".\n";
	}
	if(sizeof(arena_e))
	{
		text += "Na wschodniej czesci areny:\n";
		for(i=0; i<sizeof(arena_e); i++)
		   text += arena_e[i]->query_Imie(this_player(), PL_MIA) + " " + show_subloc_health(arena_e[i], this_player()) + ".\n";
	}
	if(sizeof(arena_sr))
	{
		text += "Na srodku areny:\n";
		for(i=0; i<sizeof(arena_sr); i++)
		   text += arena_sr[i]->query_Imie(this_player(), PL_MIA) + " " + show_subloc_health(arena_sr[i], this_player()) + ".\n";
	}
	write(text);
	return 1;
}
