Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

Oworld.cpp Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Oworld.cpp

Go to the documentation of this file.
00001 //Filename    : OWORLD.CPP
00002 //Description : class World functions
00003 
00004 #include <OVGA.H>
00005 #include <OMOUSE.H>
00006 #include <OMOUSECR.H>
00007 #include <OSYS.H>
00008 #include <OCONFIG.H>
00009 #include <OTERRAIN.H>
00010 #include <OWORLD.H>
00011 
00012 //----------- Begin of function World::World ----------//
00013 
00014 World::World() {
00015     loc_matrix = NULL;
00016 }
00017 
00018 //------------- End of function World::World -----------//
00019 
00020 //----------- Begin of function World::~World ----------//
00021 
00022 World::~World() {
00023     deinit();
00024 }
00025 
00026 //------------- End of function World::~World -----------//
00027 
00028 //----------- Begin of function World::init ------------//
00030 void World::init() {
00031     //----------- initialize loc_matrix -----------//
00032 
00033     loc_matrix = (Location*) mem_add( sizeof(Location) * MAX_WORLD_X_LOC * MAX_WORLD_Y_LOC );
00034 
00035     memset( loc_matrix, 0, sizeof(Location) * MAX_WORLD_X_LOC * MAX_WORLD_Y_LOC );
00036 
00037     max_x_loc = MAX_WORLD_X_LOC;
00038     max_y_loc = MAX_WORLD_Y_LOC;
00039 
00040     //---------- initialize matrix classes --------//
00041 
00042     map_matrix.init( MAP_X1, MAP_Y1, MAP_X2, MAP_Y2,
00043                      MAP_LOC_WIDTH, MAP_LOC_HEIGHT,
00044                      // 1-use image buffer
00045                      loc_matrix, max_x_loc, max_y_loc, ZOOM_SMALL, 1 );
00046 
00047     zoom1_matrix.init( ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2,
00048                        ZOOM1_LOC_WIDTH, ZOOM1_LOC_HEIGHT,
00049                        loc_matrix, max_x_loc, max_y_loc, ZOOM_MEDIUM );
00050 
00051     zoom2_matrix.init( ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2,
00052                        ZOOM2_LOC_WIDTH, ZOOM2_LOC_HEIGHT,
00053                        loc_matrix, max_x_loc, max_y_loc, ZOOM_LARGE );
00054 
00055     //------- initialize vars -----------//
00056 
00057     show_map = 1;
00058 
00059     set_zoom_level(1);                              // set the zoom level to 1
00060 
00061     //-------- init terrain ---------//
00062 
00063     init_terrain();
00064 }
00065 
00066 //------------ End of function World::init -------------//
00067 
00068 //----------- Begin of function World::deinit ------------//
00070 void World::deinit() {
00071     if( loc_matrix ) {
00072         mem_del( loc_matrix );
00073         loc_matrix = NULL;
00074     }
00075 
00076     //  Matrix::disp_sort_array.deinit();
00077 }
00078 
00079 //------------ End of function World::deinit -------------//
00080 
00081 //----------- Begin of function World::set_zoom_level ------------//
00083 void World::set_zoom_level(int newZoomLevel) {
00084     zoom_level = newZoomLevel;
00085 
00086     if( zoom_level==1 )
00087         active_zoom_matrix = &zoom1_matrix;
00088     else
00089         active_zoom_matrix = &zoom2_matrix;
00090 
00091     sys.redraw_zoom_flag = 1;
00092 }
00093 
00094 //----------- End of function World::set_zoom_level ------------//
00095 
00096 //----------- Begin of function World::set_show_map ------------//
00098 void World::set_show_map(int showMapFlag) {
00099     show_map = showMapFlag;
00100 
00101     sys.redraw_all_flag = 1;
00102 }
00103 
00104 //----------- End of function World::set_show_map ------------//
00105 
00106 //----------- Begin of function World::init_terrain ------------//
00108 void World::init_terrain() {
00109     int terrainTypeCount = terrain_res.terrain_count;
00110 
00111     for( int i=0 ; i<MAX_WORLD_X_LOC*MAX_WORLD_Y_LOC ; i++ ) {
00112         loc_matrix[i].set_terrain(m.random(terrainTypeCount)+1);
00113     }
00114 }
00115 
00116 //----------- End of function World::init_terrain ------------//
00117 
00118 //----------- Begin of function World::draw_all ------------//
00120 void World::draw_all() {
00121     active_zoom_matrix->draw_all();
00122 
00123     if( show_map ) {
00124         vga_back.bar( MAP_X1, MAP_Y1, MAP_X2, MAP_Y2, V_WHITE );
00125 
00126         vga_back.rect( MAP_X1-MAP_BORDER_WIDTH, MAP_Y1-MAP_BORDER_HEIGHT,
00127                        MAP_X2+MAP_BORDER_WIDTH, MAP_Y2+MAP_BORDER_HEIGHT, 2, V_BLACK );
00128 
00129         map_matrix.draw_all();
00130     }
00131 }
00132 
00133 //----------- End of function World::draw_all ------------//
00134 
00135 //----------- Begin of function World::draw_update ------------//
00137 void World::draw_update() {
00138     active_zoom_matrix->draw_update();
00139 
00140     if( show_map )
00141         map_matrix.draw_update();
00142 }
00143 
00144 //----------- End of function World::draw_update ------------//
00145 
00146 //----------- Begin of function World::detect ------------//
00153 int World::detect() {
00154     //---------- detect map -----------//
00155 
00156     if( show_map ) {
00157         if( map_matrix.detect() )
00158             return 1;
00159     }
00160 
00161     //------- detect zoom view --------//
00162 
00163     if( active_zoom_matrix->detect() )
00164         return 1;
00165 
00166     return 0;
00167 }
00168 
00169 //----------- End of function World::detect ------------//
00170 
00171 //--------- Begin of function World::get_loc --------//
00173 Location* World::get_loc(int xLoc, int yLoc) {
00174     err_when( xLoc<0 || xLoc>=MAX_WORLD_X_LOC );
00175     err_when( yLoc<0 || yLoc>=MAX_WORLD_Y_LOC );
00176 
00177     return loc_matrix + MAX_WORLD_X_LOC * yLoc + xLoc;
00178 }
00179 
00180 //----------- End of function World::get_loc --------//
00181 
00182 //--------- Begin of function World::is_loc_valid --------//
00184 Location* World::get_valid_loc(int xLoc, int yLoc) {
00185     if ( xLoc>=0 && xLoc<MAX_WORLD_X_LOC
00186          && yLoc>=0 && yLoc<MAX_WORLD_Y_LOC) {
00187         return loc_matrix + MAX_WORLD_X_LOC * yLoc + xLoc;
00188     }
00189     else
00190         return NULL;
00191 }
00192 
00193 //----------- End of function World::is_loc_valid --------//

Generated on Fri Aug 23 01:38:36 2002 for VirtualU by doxygen1.2.17