Hi guys, I am trying to select multiple entities and then display a circle entity under the selected entities. Something like in a strategy game. So far I am only able to do it for one entity and not sure why it will not work for multiple entities.

Code:
#define WIN32_LEAN_AND_MEAN		
#include <windows.h>
#include <stdio.h>

//includes the engine data types, variables, and functions
#include "init_engine.h"



BMAP* gBlueCursorBmp = NULL;      //pointer to blue cursor image
BMAP* gRedCursorBmp = NULL;       //pointer to red cursor image
ENTITY* gCircle;           //pointer to select circle entity


ENTITY* cbabe = NULL;
ENTITY* rob = NULL;
ENTITY* rob2 = NULL;
ENTITY* rob3 = NULL;



void handle_circle(ENTITY* e)
{
  //rotate circle based on frame rate
  e->pan += v(time_step);
  
  //keep angle within 0 - 360 degrees
  if(e->pan > _VAR(360))
    e->pan = _VAR(0);
}


void init_circle(ENTITY* e)
{
  //initialize select circle entity's properties
  e->flags |= INVISIBLE;
  e->tilt = _VAR(90);
  e->emask |= ENABLE_FRAME;
  e->event = (EVENT)handle_circle;
}



void handleGroupSelect()
{
  static bool select_rect = false;
  static VECTOR mouse_position1 = {_VAR(0), _VAR(0), _VAR(0)};
  static VECTOR mouse_position2 = {_VAR(0), _VAR(0), _VAR(0)};
  static COLOR rect_colour = {_VAR(255), _VAR(255), _VAR(255)};

  VECTOR temp_vec = {_VAR(0), _VAR(0), _VAR(0)};
  ENTITY* temp_ent = NULL;
  var temp_var = 0;

  if(INTV(mouse_left))
  {
    if(select_rect)
    {
      mouse_position2.x = v(mouse_cursor).x;
      mouse_position2.y = v(mouse_cursor).y;
        
      //restrict select rectangle to be within main game window
     if(mouse_position2.y > v(screen_size).y) 
        mouse_position2.y = v(screen_size).y - _VAR(1);	//if mouse cursor below main game window
     if(mouse_position2.y < _VAR(0))
        mouse_position2.y = _VAR(0);						//if mouse cursor above main game window
	 if(mouse_position2.x < _VAR(0))
        mouse_position2.x = _VAR(0);						//if mouse cursor left of main game window
	 if(mouse_position2.x > v(screen_size).x) 
        mouse_position2.x = v(screen_size).x - _VAR(1);	//if mouse cursor right of main game window
        
      draw_line(&mouse_position1, NULL, _VAR(100));																//move draw position to initial cursor position
      draw_line(_vec(_FLOAT(mouse_position2.x), _FLOAT(mouse_position1.y), 0), &rect_colour, _VAR(100));	//draw line in horizontal direction to current cursor's horizontal position
      draw_line(&mouse_position2, &rect_colour, _VAR(100));												//draw line in vertical direction to current cursor position
      draw_line(_vec(_FLOAT(mouse_position1.x), _FLOAT(mouse_position2.y), 0), &rect_colour, _VAR(100));	//draw line in horizontal direction to initial cursor's horizontal position
      draw_line(&mouse_position1, &rect_colour, _VAR(100));												//draw line in vertical direction back to initial cursor's position
    }
    else
    {
      mouse_position1.x = v(mouse_cursor).x;
      mouse_position1.y = v(mouse_cursor).y;
      select_rect = true;
    }
  }
  else if(!INTV(mouse_left) && select_rect)
  {
    temp_ent = ent_next(NULL); 	//get pointer to first entity
    
    while(temp_ent != NULL)
    {
      vec_set(&temp_vec, (VECTOR*)&temp_ent->x);
       
      if(vec_to_screen(&temp_vec, &v(camera)) != NULL)
      {
        if(temp_vec.x > minv(mouse_position1.x, mouse_position2.x) && temp_vec.x < maxv(mouse_position1.x, mouse_position2.x)
          && temp_vec.y > minv(mouse_position1.y, mouse_position2.y) && temp_vec.y < maxv(mouse_position1.y, mouse_position2.y)
          && (temp_ent->flags2 & (UNTOUCHABLE)) == 0)
        {
	      temp_ent->ambient = _VAR(100);	//set entity's ambient value to 100
	      temp_ent->skill[0] = 1;//selected 
        }
        else
        {
          temp_ent->ambient = _VAR(0);	//reset entity's ambient value to 0      
          temp_ent->skill[0] = 0;//not selected
        }    
      }
      temp_ent = ent_next(temp_ent);
    }
    select_rect = false;
  }
}


void handleMouseLeft(ENTITY* e)
{
  if(ev->mouse_ent == NULL)
     gCircle->flags |= INVISIBLE;
}


void handle_entity(ENTITY* e)
{

  //switch to red cursor image when cursor is on the entity
  if(INTV(event_type) == EVENT_TOUCH)
    ev->mouse_map = gRedCursorBmp;
  //switch to blue cursor image when cursor moves away from the entity
  if(INTV(event_type) == EVENT_RELEASE)
    ev->mouse_map = gBlueCursorBmp;
  //turn on select circle entity when entity is clicked
  if(INTV(event_type) == EVENT_CLICK || INTV(event_type) == EVENT_RIGHTCLICK || e->skill[0] == 1 )
  {
                       
    gCircle->x = e->x;        
    gCircle->y = e->y;
    gCircle->z = _VAR(20);
    gCircle->flags &= ~INVISIBLE;
  }

}


//main entry point
int APIENTRY WinMain(HINSTANCE hInstance,	
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,	
                     int       nCmdShow)	
{
  engine_init();

  BMAP* blueCursorBmp = bmap_create("arrow_blue.pcx");
  ev->mouse_map = blueCursorBmp;
  SETV(mouse_mode, 4);    //display mouse

  //initialise camera position and angle
  //x axis to the right, looking down the y axis, z is up
  v(camera).pan = _VAR(90);                            //pan of 90 means looking down the y axis
  v(camera).tilt = _VAR(-30);                          //add a slight camera tilt

  rob = ent_create("robby.mdl", _vec(-100, 0, 50), NULL);
  rob2 = ent_create("robby.mdl", _vec(0, 100, 50), NULL);
  rob3 = ent_create("robby.mdl", _vec(100, 0, 50), NULL);
  rob->emask |= ENABLE_TOUCH|ENABLE_CLICK|ENABLE_RIGHTCLICK|ENABLE_RELEASE;
  rob->event = (EVENT)handle_entity;
  rob2->emask |= ENABLE_TOUCH|ENABLE_CLICK|ENABLE_RIGHTCLICK|ENABLE_RELEASE;
  rob2->event = (EVENT)handle_entity;
  rob3->emask |= ENABLE_TOUCH|ENABLE_CLICK|ENABLE_RIGHTCLICK|ENABLE_RELEASE;
  rob3->event = (EVENT)handle_entity;

  ENTITY* crate = ent_create("crate.mdl", _vec(0, -50, 15), NULL);
  crate->flags2 |= UNTOUCHABLE;

  gCircle = ent_create("circle.bmp", NULL, (EVENT)init_circle);  

  //initialise camera position and angle
  //x axis to the right, looking down the y axis, z is up
  v(camera).pan = _VAR(90);                            //pan of 90 means looking down the y axis
  v(camera).tilt = _VAR(-20);                          //add a slight camera tilt
  vec_set((VECTOR*)&v(camera).x, _vec(0, 0, 100));     //set initial camera position

  gBlueCursorBmp = bmap_create("arrow_blue.pcx");
  gRedCursorBmp = bmap_create("arrow_red.pcx");
  ev->mouse_map = gBlueCursorBmp;
  SETV(mouse_mode, 4);    //display mouse

  SETV(mouse_range, 5000);

  cbabe = ent_create("cbabe.mdl", _vec(0, 0, 50), NULL);
  cbabe->emask |= ENABLE_TOUCH|ENABLE_CLICK|ENABLE_RIGHTCLICK|ENABLE_RELEASE;
  cbabe->event = (EVENT)handle_entity;
//  cbabe->flags2 |= UNTOUCHABLE;

      

  v(on_mouse_left) = (EVENT)handleMouseLeft;

  //main rendering loop, this will loop once every frame until you quit
  while(engine_frame()) 
  {
    //rtsCamera();
     
    if(!INTV(mouse_left))
      rtsCamera();

    handleGroupSelect();

    //update debug text display
    update_debug_text();
  }
  
  engine_close();     //engine frees all created entities, bitmaps and sounds automatically when closing
  return 0;
}