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

Password:

OPLANT.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

OPLANT.CPP

Go to the documentation of this file.
00001 //Filename    : OPLANT.CPP
00002 //Description : PlantRes Class Definition
00003 
00004 #include <All.h>
00005 #include <OVGA.H>
00006 #include <OSYS.H>
00007 #include <OSTR.h>
00008 #include <OMISC.h>
00009 #include <OGAMESET.H>
00010 #include <OPLANT.h>
00011 
00012 //----------- Define constants -------------//
00013 
00014 #define PLANT_DB      "PLANT"
00015 
00016 //----------- Begin of function PlantRes Constructor -----//
00018 PlantRes::PlantRes() {
00019     init_flag=0;
00020 }
00021 
00022 //------------- End of function PlantRes Constructor -----//
00023 
00024 //----------- Begin of function PlantRes Destructor ------//
00026 
00027 PlantRes::~PlantRes() {
00028     deinit();
00029 }
00030 
00031 //------------- End of function PlantRes Destructor ------//
00032 
00033 //----------- Begin of function PlantRes::init --------//
00035 void PlantRes::init() {
00036     if ( init_flag )
00037         return;
00038 
00039     //----- read info from PLANT.DBF ------//
00040 
00041     load_info();
00042 
00043     //---- open bitmap resource of different resolutions ----//
00044 
00045     load_res( ZOOM_SMALL , "PLANT", "S" );
00046     load_res( ZOOM_MEDIUM, "PLANT", "M" );
00047     load_res( ZOOM_LARGE , "PLANT", "L" );
00048 
00049     //----------------------------------------//
00050 
00051     init_flag=1;
00052 }
00053 
00054 //------------- End of function PlantRes::init --------//
00055 
00056 //----------- Begin of function PlantRes::deinit --------//
00058 void PlantRes::deinit() {
00059     if( init_flag ) {
00060         for( int i=0 ; i<MAX_ZOOM_LEVEL ; i++ )
00061             res_bitmap[i].deinit();
00062 
00063         mem_del(info_array);
00064 
00065         init_flag=0;
00066     }
00067 }
00068 
00069 //------------- End of function PlantRes::deinit --------//
00070 
00071 //----------- Begin of function PlantRes::load_info -------//
00075 void PlantRes::load_info() {
00076     PlantRec  *plantRec;
00077     PlantInfo *plantInfo;
00078     int      i;
00079     Database *dbPlant = game_set.open_db(PLANT_DB);
00080 
00081     plant_count = (short) dbPlant->rec_count();
00082     info_array = (PlantInfo*) mem_add( sizeof(PlantInfo)*plant_count );
00083 
00084     //------ read in plant bitmap info array -------//
00085 
00086     memset( info_array, 0, sizeof(PlantInfo) * plant_count );
00087 
00088     for( i=0 ; i<plant_count ; i++ ) {
00089         plantRec  = (PlantRec*) dbPlant->read(i+1);
00090         plantInfo = info_array+i;
00091 
00092         m.rtrim_fld( plantInfo->file_name, plantRec->file_name, plantRec->FILE_NAME_LEN );
00093     }
00094 }
00095 
00096 //----------- End of function PlantRes::load_info -------//
00097 
00098 //----------- Begin of function PlantRes::load_res --------//
00100 void PlantRes::load_res(int zoomLevel, char* namePrefix, char* nameSuffix) {
00101     //------ read bitmaps into memory -----//
00102 
00103     String str2;
00104 
00105     str2  = DIR_RES;
00106     str2 += namePrefix;
00107     str2 += "_";
00108     str2 += nameSuffix;
00109 
00110     str2 += ".RES";
00111 
00112     res_bitmap[zoomLevel].init( str2, 1 );          // 1-read all bitmaps into memory
00113 
00114     //-------- set PlantInfo::bitmap_ptr[] --------//
00115 
00116     char* bmpPtr;
00117 
00118     for( int i=0 ; i<plant_count ; i++ ) {
00119         bmpPtr = res_bitmap[zoomLevel].read( info_array[i].file_name );
00120 
00121         info_array[i].bitmap_ptr[zoomLevel] = bmpPtr;
00122     }
00123 }
00124 
00125 //------------- End of function PlantRes::load_res --------//
00126 
00127 //---------- Begin of function PlantRes::operator[] -----------//
00128 
00129 PlantInfo* PlantRes::operator[](int plantId) {
00130     err_if( plantId<1 || plantId>plant_count )
00131         err_now( "PlantRes::operator[]" );
00132 
00133     return info_array+plantId-1;
00134 }
00135 
00136 //------------ End of function PlantRes::operator[] -----------//

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