#include "Unit.h"



	
//Unit.cpp


bool Unit::is_collision( Unit b)
{
    if ((x > b.x + b.w -1) || // is a on the right side
        (y > b.y + b.h -1) || // is a under
        (b.x > x + w -1) || // is b on the right side
        (b.y > y + h -1))   // is b under
    {
        // this means that there is no collision
        return 0; // means no colide
    }

    return 1; // means colide
}
	//gets
string Unit::Get_name()
{

	return name;
}
int Unit::Get_inarea()
{
	return inarea;
}
int Unit::Get_id()
{
	return id;
}
int Unit::Get_socketid()
{
	return socketid;
}

int Unit::Get_X()
{
	return x;
}
int Unit::Get_Y()
{
	return y;
}
	//gets
int Unit::Get_W()
{
	return w;
}
int Unit::Get_H()
{
	return h;
}
int Unit::Get_frame()
{
	return frame;
}
int Unit::Get_source_X()
{
	return source_X;
}
int Unit::Get_source_Y()
{
	return source_Y;
}
int Unit::Get_layer()
{
	return layer;
}

int Unit::Is_in_collision()
{
	return collision;
}
int Unit::Get_direction()
{
	return direction;
}
int Unit::Get_sourcebitmap()
{
	return source;
}
int Unit::Get_destbitmap()
{
	return dest;
}
	//sets
void Unit::Set_name(string New_name)
{
	name =  New_name ;
}
void Unit::Set_inarea(int new_area)
{
	inarea = new_area;
}
void Unit::Set_id(int new_id)
{
	id = new_id;
}
void Unit::Set_socketid(int new_id)
{
	socketid = new_id;
}

void Unit::Set_X(int new_x)
{
	x=new_x;
}
void Unit::Set_Y(int new_y)
{
	y=new_y;
}
void Unit::Set_W(int new_W)
{
	w=new_W;
}
void Unit::Set_H(int new_H)
{
	h=new_H;
}
void Unit::Set_source_X(int new_x)
{
	source_X=new_x;
}
void Unit::Set_source_Y(int new_y)
{
	source_Y=new_y;
}
void Unit::Set_frame(int new_frame)
{
	frame=new_frame;
}
void Unit::Set_layer(int new_layer)
{
	layer=new_layer;
}
void Unit::Set_collision(int new_state)
{
	collision = new_state;
}
void Unit::Set_direction(int new_direction)
{
	direction = new_direction;
}
void Unit::Set_sourcebitmap(int new_bitmap)
{
	source = new_bitmap;
}
void Unit::Set_destbitmap(int new_bitmap)
{
	dest = new_bitmap;
}
	//constutors
Unit::Unit()
{
socketid = -1;
name = "none";
	//data=load_datafile("data.dat");//riged for test
	 x = 2060;
	 y = 1594;
	 w = 32;
	 h = 32;
	 layer = 3;
	 source_X = 32;
	 source_Y = 32;
	 collision = 0;
	 frame = 1;
	direction = 0;
	source = 4;
	id = 1;
scroll_x =0;
 screen_pos_y =0;
 scroll_y =0;
 screen_pos_x =0;
}

Unit::Unit(int s,BITMAP* d)
{
socketid = -1;
name = "none";
	//data=load_datafile("data.dat");//riged for test
	source = s;
	//dest = d;
	 x = 2060;
	 y = 1594;
	 w = 32;
	 h = 32;
	 layer = 3;
	 source_X = 0;
	 source_Y = 0;
	 collision = 0;
	 frame = 1;
	direction = 0;
	id = 1;

scroll_x =0;
 screen_pos_y =0;
 scroll_y =0;
 screen_pos_x =0;
}

void Unit::draw(BITMAP* n)
{
	//if ((x>=v.get_screen_pos_x()*32 && x<=(v.get_screen_pos_x()+v.get_GRID_WIDTH())*32) &&
	//	(y>=v.get_screen_pos_y()*32 && y<=(v.get_screen_pos_y()+v.get_GRID_HEIGHT())*32))
	//{								
		//masked_blit(source,dest, source_X,source_Y,x,  y, w, h);
		
		masked_stretch_blit((BITMAP*)data[source].dat, n, source_X*w,source_Y*h, w, h,x-screen_pos_x*32-scroll_x-w,y-screen_pos_y*32-scroll_y-h, w*2, h*2);

		//masked_blit((BITMAP*)data[source].dat,n,source_X*w,source_Y*h,x-v.get_screen_pos_x()*32-v.get_scroll_x()-w,y-v.get_screen_pos_y()*32-v.get_scroll_y()-h, w,h);
//	}
}

Unit::~Unit()
{
	//unload_datafile(data);

}
void Unit::showname(BITMAP* n)
{

	//if (mouse_x >= x-v.get_screen_pos_x()*32-v.get_scroll_x()-w && mouse_y >= y-v.get_screen_pos_y()*32-v.get_scroll_y()-h)
	//{
	//	if (mouse_x <= x-v.get_screen_pos_x()*32-v.get_scroll_x()+w && mouse_y <= y-v.get_screen_pos_y()*32-v.get_scroll_y()+h)
	//	{

			textout(n,font,name.c_str(),x-screen_pos_x*32-scroll_x-w,y-screen_pos_y*32-scroll_y-h,makecol(255,255,255));//makecol(255,0,255)is trans
		//}	

//	}

}


