/*
    ANTLand simulation
    (C) 2004 justin_sane

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    Contact: justinsanemsu@msu.edu

    FILE: world.cpp
    Authors: justin_sane
*/

#ifndef worldH
#define worldH

#include <vector.h>

#include "ant.h"
#include "obstacle.h"

#define sim_x_size  100.0
#define sim_y_size  80.0


/* container class for all world objects */
class world_class
{
  public:

    __fastcall world_class(void);
    __fastcall ~world_class();


    void move(move_type move);



    void __fastcall reset( void );

    void __fastcall random_ant( unsigned int num );
    void __fastcall random_obstacle( unsigned int num );

    void __fastcall setup_vertex_set( void );

    void __fastcall clear( void );


    /* drawing related */

    void __fastcall draw_simarea(TPaintBox *buffer);



    /* 3d drawing */
    void __fastcall draw_visarea(TPaintBox *buffer);

    void __fastcall world_class::transform_vertices(point3d p, trig_data_type trig_data);

    void __fastcall sort_faces(void);
    void __fastcall draw_polygons(void);
    bool __fastcall face_towards_camera(face &f);


    /* end of drawing related */


    void __fastcall simarea_resize(int width, int height);
    void __fastcall visarea_resize(int width, int height);

    void __fastcall world_class::update( void );

    int __fastcall point_in_ant_num(point p);

    bool __fastcall okay_to_land(point pos, float dir);

    void world_class::check_selection(point p);

    void __fastcall toggle_sel_self_control( void );
    void __fastcall delete_selected( void );

    void get_sel_stat(char *stat);


    void update_trig_data( void );


  private:

    vector<ant_class *> ants;
    vector<obstacle_class> obstacles;
    vector<face>     faces;

    vector<point3d>  vert;

    point3d camera_pos;
    int camera_dir;
    int camera_y_dir;

    trig_data_type trig_data;

    int sel_ant_index;  // index of the selected ant
    ant_class *sel_ant; // pointer to the selected ant

    int sim_height, sim_width;
    int vis_height, vis_width;

    Graphics::TBitmap *sim_buffer;
    Graphics::TBitmap *vis_buffer;
};



#endif
