//0 - human
//1 - machine gun
//2 - heli rockets
//3 - heli

void initguibars() {
	ABITMAP *tmp;
	int x;
	tmp = load_bitmap("graphics\\digits.tga");
	for(x = 0; x < 10; x++) {
		digits[x] = create_bitmap_ex(32, 16, 17);
		blitopaque(tmp, digits[x], x * 16, 0, 0, 0, 16, 17);
	}
	destroy_bitmap(tmp);
	inf = load_bitmap("graphics\\inf.tga");

	guibars[0] = load_bitmap("graphics\\guibar_soldier.tga");
	guibars[1] = load_bitmap("graphics\\guibar_weapgun.tga");
	guibars[2] = load_bitmap("graphics\\guibar_weaphelirocket.tga");
	guibars[3] = load_bitmap("graphics\\guibar_heli.tga");

	guibarposx[0] = 0;
	guibarposy[0] = 39;
	guibarposx[1] = 700;
	guibarposy[1] = 39;
	guibarposx[2] = 700;
	guibarposy[2] = 39;
	guibarposx[3] = 0;
	guibarposy[3] = 79;
	guibaron[0] = true;
	guibaron[1] = true;
	guibaron[2] = false;
}

void doguinumbers(float num, int nodigits, float x, float y) {
	int i;
	int dig;
	for(i = nodigits; i > 0; i--) {
		if(num >= pow(10, i - 1)) {
			dig = (int)(num * pow(10, -i + 1)) % 10;
			gldrawsprite(x + (nodigits - i) * 16, y, digits[dig]);
		}
	}
}

void drawguibars() {
	if(human->invehicle && human->inheli != NULL) {
		guibarposx[1] = 600;
		guibaron[2] = true;
		guibaron[3] = true;
	}
	else {
		guibarposx[1] = 700;
		guibaron[2] = false;
		guibaron[3] = false;
	}

	if(guibaron[0]) {
		gldrawsprite(lx + guibarposx[0], guibarposy[0], guibars[0]);
		doguinumbers(human->health, 3, lx + guibarposx[0] + 59, guibarposy[0] - 11);
	}

	if(guibaron[1]) {
		gldrawsprite(lx + guibarposx[1], guibarposy[1], guibars[1]);
		gldrawsprite(lx + guibarposx[1] + 63, guibarposy[1] - 12, inf);
	}

	if(guibaron[2]) {
		gldrawsprite(lx + guibarposx[2], guibarposy[2], guibars[2]);
		gldrawsprite(lx + guibarposx[2] + 65, guibarposy[2] - 12, inf);
	}

	if(guibaron[3]) {
		gldrawsprite(lx + guibarposx[3], guibarposy[3], guibars[3]);
		doguinumbers(100 - human->inheli->damage * 0.5, 3, lx + guibarposx[3] + 59, guibarposy[3] - 11);
	}
}

void eraseguibars() {
	int i;
	for(i = 0; i < MAXGUIBARS; i++)
		if(guibaron[i])
			blit(bg, buf, lx + guibarposx[i], guibarposy[i], lx + guibarposx[i], guibarposy[i], guibars[i]->w, guibars[i]->h);
}