00001 //Filename : OFPHOTO.CPP 00002 //Description : FacultyPhotoRes 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 <OFPHOTO.h> 00011 00012 //----------- Define constants -------------// 00013 00014 #define FACULTY_PHOTO_DB "FPHOTO" 00015 00016 //----------- Begin of function FacultyPhotoRes Constructor -----// 00018 FacultyPhotoRes::FacultyPhotoRes() { 00019 init_flag=0; 00020 } 00021 00022 //------------- End of function FacultyPhotoRes Constructor -----// 00023 00024 //----------- Begin of function FacultyPhotoRes Destructor ------// 00026 00027 FacultyPhotoRes::~FacultyPhotoRes() { 00028 deinit(); 00029 } 00030 00031 //------------- End of function FacultyPhotoRes Destructor ------// 00032 00033 //----------- Begin of function FacultyPhotoRes::init --------// 00035 void FacultyPhotoRes::init() { 00036 if( init_flag ) 00037 return; 00038 00039 //---- open faculty photo resource file ----// 00040 00041 String str; 00042 00043 str = DIR_RES; 00044 str += "I_FPHOTO.RES"; 00045 00046 res_photo.init_imported(str, 1); // 1-don't read all into buffer 00047 00048 //----- read info from FPHOTO.DBF ------// 00049 00050 load_info(); 00051 00052 //----------------------------------------// 00053 00054 init_flag=1; 00055 } 00056 00057 //------------- End of function FacultyPhotoRes::init --------// 00058 00059 //----------- Begin of function FacultyPhotoRes::deinit --------// 00061 void FacultyPhotoRes::deinit() { 00062 if( init_flag ) { 00063 mem_del(info_array); 00064 00065 res_photo.deinit(); 00066 00067 init_flag=0; 00068 } 00069 } 00070 00071 //------------- End of function FacultyPhotoRes::deinit --------// 00072 00073 //----------- Begin of function FacultyPhotoRes::load_info -------// 00077 void FacultyPhotoRes::load_info() { 00078 FacultyPhotoRec *photoRec; 00079 FacultyPhoto *photoInfo; 00080 Database *dbFacultyPhoto = game_set.open_db(FACULTY_PHOTO_DB); 00081 int bitmapOffset; 00082 00083 photo_count = (short) dbFacultyPhoto->rec_count(); 00084 info_array = (FacultyPhoto*) mem_add( sizeof(FacultyPhoto)*photo_count ); 00085 00086 //------ read in photo bitmap info array -------// 00087 00088 memset( info_array, 0, sizeof(FacultyPhoto) * photo_count ); 00089 00090 for( int i=0 ; i<photo_count ; i++ ) { 00091 photoRec = (FacultyPhotoRec*) dbFacultyPhoto->read(i+1); 00092 photoInfo = info_array+i; 00093 00094 switch( photoRec->nationality[0] ) { 00095 case 'A': // Asian 00096 case 'B': // Black 00097 if( photoRec->sex == 'M' ) 00098 photoInfo->gender_ethnic_group = MINORITY_MALE; 00099 else 00100 photoInfo->gender_ethnic_group = MINORITY_FEMALE; 00101 break; 00102 00103 case 'W': // Western 00104 if( photoRec->sex == 'M' ) 00105 photoInfo->gender_ethnic_group = NONMINORITY_MALE; 00106 else 00107 photoInfo->gender_ethnic_group = NONMINORITY_FEMALE; 00108 break; 00109 } 00110 00111 memcpy( &bitmapOffset, photoRec->bitmap_ptr, sizeof(long) ); 00112 00113 photoInfo->bitmap_ptr = res_photo.read_imported(bitmapOffset); 00114 00115 //## fred 00116 err_when( photoInfo->gender_ethnic_group < 0 || photoInfo->gender_ethnic_group >= GENDER_ETHNIC_TYPE_COUNT ); 00117 } 00118 } 00119 00120 //----------- End of function FacultyPhotoRes::load_info -------// 00121 00122 //---------- Begin of function FacultyPhotoRes::operator[] -----------// 00123 00124 FacultyPhoto* FacultyPhotoRes::operator[](int photoId) { 00125 err_if( photoId<1 || photoId>photo_count ) 00126 err_now( "FacultyPhotoRes::operator[]" ); 00127 00128 return info_array+photoId-1; 00129 } 00130 00131 //------------ End of function FacultyPhotoRes::operator[] -----------//