unit mini_map;

interface

uses path_map, OpenGL, units, vfm, variables;

type
  TMinimap = class
    pm : RPathMap;
    x, y : single;
    dx, dy : single;
    point_size : single;
  public
    constructor Create(pathmap : RPathMap; x0, y0, size, dx0, dy0 : single);
    procedure Redraw;
  end;

var
  minimap : TMinimap;

implementation

constructor TMinimap.Create(pathmap : RPathMap; x0, y0, size, dx0, dy0 : single);
begin
inherited Create;
pm := pathmap;
x := x0; y := y0;
if x < 0 then x := screen_width + x0 - pm.width * dx0;
if y < 0 then y := screen_height + y0 - pm.height * dy0;

point_size := size;
dx := dx0; dy := dy0;
end;

procedure TMinimap.Redraw;
var
i1, i2, o1, o2 : integer;
begin
glPushMatrix;
glTranslatef(x, y, 0);

glPointSize(point_size);
glDisable(GL_TEXTURE_2D);

glBegin(GL_POINTS);
with pm do
  for i1 := 1 to width do
    for i2 := 1 to height do
{for i1 := (world.camera.map_x - radar_radius) to
          (world.camera.map_x + radar_radius) do
  for i2 := (height - (world.camera.map_y + radar_radius)) to
            (height - (world.camera.map_y - radar_radius))  do
    if not((i1 < 1)or(i1 > width) or
           (i2 < 1)or(i2 > height)) then  
      if sqrt(sqr(world.camera.map_x - i1) +
         sqr(world.camera.map_y - height + i2)) < radar_radius then  } 
      
      with map[i1, height - i2 + 1] do
        begin
          glColor4f(1, 1, 1, minimap_opacity);

          if not walk then glColor4f(0, 0, 0.2, minimap_opacity);

          for o1 := -1 to 1 do
            for o2 := -1 to 1 do
              if map[i1 + o1, height - i2 + 1 + o2].child_type = 1 then
                glColor4f(0, 1, 0.5, minimap_opacity);

          for o1 := -1 to 0 do
            for o2 := -1 to 0 do
              if map[i1 + o1, height - i2 + 1 + o2].child_type = 2 then
                 glColor4f(0, 0.6, 0, minimap_opacity);

          case child_type of
            1 : glColor4f(0, 1, 0.5, minimap_opacity);
            2 : glColor4f(0, 0.6, 0, minimap_opacity);
            3 : glColor4f(1, 0, 0, minimap_opacity);
            4 : glColor4f(0, 0, 0.7, minimap_opacity);
          end;

          if (i1 < 2)or(i1 > width-1) or
             (i2 < 2)or(i2 > height-1) then
               glColor4f(0, 0, 0.2, minimap_opacity);

          glVertex2f(i1*dx, i2*dy);
        end;
glEnd;    

glPopMatrix;
end;

end.
