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

Password:

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

OCOURRES.CPP

Go to the documentation of this file.
00001 //Filename    : OCOURRES.CPP
00002 //Description : course Resource object
00003 //Owner                 : Fred
00004 
00005 // see req29b and HE.gdb.init.xls:course_template
00006 
00007 #include <OGAMESET.H>
00008 #include <OCOURRES.H>
00009 #include <OCourse.H>
00010 //#include <ODept.H>
00011 #include <ODeptres.H>
00012 
00013 //---------- #define constant ------------//
00014 
00015 #define COURSE_TEMPLATE_DB    "COU_TMPL"
00016 #define SUMMER_COURSE_DB    "SUMMER"
00017 
00018 //---------- Begin of function CourseRes::init -----------//
00022 void CourseRes::init() {
00023     deinit();
00024 
00025     //------- load database information --------//
00026 
00027     memset( this, 0, sizeof(CourseRes) );
00028 
00029     load_template();
00030     load_summer_db();
00031 
00032     init_flag=1;
00033 }
00034 
00035 //---------- End of function CourseRes::init -----------//
00036 
00037 //---------- Begin of function CourseRes::deinit -----------//
00038 
00039 void CourseRes::deinit() {
00040     if( init_flag ) {
00041         if( course_template_count > 0 )
00042             free_template();
00043 
00044         init_flag=0;
00045     }
00046 }
00047 
00048 //---------- End of function CourseRes::deinit -----------//
00049 
00050 //------- Begin of function CourseRes::load_template -------//
00052 
00053 void CourseRes::change_course_templ_code(char* code) {
00054     switch (code[0]) {
00055     case 'A':
00056         code[0] = 'A';
00057         break;
00058     case 'B':
00059         code[0] = 'B';
00060         break;
00061     case 'E':
00062         code[0] = 'C';
00063         break;
00064     case 'F':
00065         code[0] = 'D';
00066         break;
00067     case 'H':
00068         code[0] = 'E';
00069         break;
00070     case 'S':
00071         if ( code[1] == 'C' )
00072             code[0] = 'F';
00073         else
00074             code[0] = 'H';
00075         break;
00076     case 'M':
00077         code[0] = 'G';
00078         break;
00079     default:
00080         err_here();
00081         break;
00082     }
00083 
00084     code[1] = '\0';
00085 }
00086 
00087 void CourseRes::load_template() {
00088     //course_template_count = 1;
00089 
00090     CourseTemplateRec   *templRec;
00091     CourseTemplate      *templPtr;
00092     Database        *dbTemplate = game_set.open_db(COURSE_TEMPLATE_DB);
00093 
00094     course_template_count = (short) dbTemplate->rec_count();
00095 
00096     err_when( course_template_array );              // to prevent double allocations
00097     err_when( course_template_count%3 != 0 || course_template_count == 0);
00098 
00099     course_template_count /= 3;                     // 3 = COURSE_PREFERENCE_COUNT
00100 
00101     course_template_array = (CourseTemplate*) mem_add( sizeof(CourseTemplate)*course_template_count );
00102 
00103     //------ read in course information array -------//
00104 
00105     memset( course_template_array, 0, sizeof(CourseTemplate) * course_template_count );
00106 
00107     templPtr = course_template_array;
00108 
00109     for( int i=0, type=0 ; i<course_template_count*3 ;) {
00110         templRec  = (CourseTemplateRec*) dbTemplate->read(i+1);
00111 
00112         change_course_templ_code(templRec->template_code);
00113         templPtr->template_code = templRec->template_code[0];
00114 
00115         templPtr->target_preference[type] = char(100 * m.atof( templRec->target_preference, 9 ));
00116         templPtr->normal_class_size[type] = m.atoi( templRec->normal_class_size, 9 );
00117 
00118         type = (type+1)%3;
00119 
00120         if ( ++i%3 == 0 )
00121             templPtr++;
00122 
00123         //----------//
00124         /*
00125           templatePtr->target_preference[P_SEMINAR] = 11;       // 99->99%
00126           templatePtr->target_preference[P_CLASS_WITH_BREAKOUTS] = 27;
00127           templatePtr->target_preference[P_OTHER] = 62;
00128 
00129           //short       normal_class_size= (float) m.atof(templateRec->rank_age_multiplier, 9);
00130           templatePtr->normal_class_size[P_SEMINAR] = 12;
00131           templatePtr->normal_class_size[P_CLASS_WITH_BREAKOUTS] = 19;
00132           templatePtr->normal_class_size[P_OTHER] = 20;
00133         */
00134     }
00135 
00136     for( i=0; i<course_template_count; i++) {
00137         templPtr = course_template_array + i;
00138 
00139         int tmp = templPtr->target_preference[0] + templPtr->target_preference[1];
00140 
00141         templPtr->target_preference[2] = 100 - tmp;
00142     }
00143 }
00144 
00145 //--------- End of function CourseRes::load_template ---------//
00146 
00147 //------- Begin of function CourseRes::free_template -------//
00149 void CourseRes::free_template() {
00150     err_when( course_template_count == 0 );
00151 
00152     mem_del(course_template_array);
00153     course_template_count = 0;
00154 }
00155 
00156 //--------- End of function CourseRes::free_template ---------//
00157 
00158 //------- Begin of function CourseRes::get_course_template -------//
00160 CourseTemplate* CourseRes::get_template(char* templateCode) {
00161     int offset = templateCode[0] - FIRST_COURSE_TEMPLATE_CODE;
00162 
00163     err_when(offset >= course_template_count);
00164     return course_template_array + offset;
00165 }
00166 
00167 //--------- End of function CourseRes::get_course_template ---------//
00168 
00169 //------- Begin of function CourseRes::get_course_template -------//
00171 CourseTemplate* CourseRes::get_template(int deptId) {
00172     return get_template(department_res[deptId]->template_course_type);
00173 }
00174 
00175 //--------- End of function CourseRes::get_course_template ---------//
00176 
00177 //------- Begin of function CourseRes::get_normal_class_size -------//
00179 int CourseRes::get_normal_class_size(char* templateCode, char teachingMethod) {
00180     err_when(teachingMethod >= MAX_TEACHING_METHOD);
00181 
00182     //-------------------------------------------//
00183 
00184     // map TM in course.h to TM in courres.h
00185     // c.h      SEMINAR, DISTANCE_LEARN_COURSE, CLASS_WITH_BREAKOUT, BREAKOUT_LAB, GENERAL,
00186     // cr.h     P_SEMINAR=0, P_CLASS_WITH_BREAKOUTS, P_OTHER,
00187 
00188     static const char remap[MAX_TEACHING_METHOD]
00189         = { P_SEMINAR, -1, P_CLASS_WITH_BREAKOUTS, P_SEMINAR, P_OTHER };
00190 
00191     teachingMethod = remap[teachingMethod];
00192     err_when(teachingMethod == -1);                 // this case handled at the beginning
00193 
00194     CourseTemplate* templ = get_template(templateCode);
00195 
00196     return templ->normal_class_size[teachingMethod];
00197 }
00198 
00199 //--------- End of function CourseRes::get_normal_class_size ---------//
00200 
00201 //------- Begin of function CourseRes::get_course_pref -------//
00203 void CourseRes::get_course_pref(char* templateCode, char* pref) {
00204     err_here();
00205 
00206     CourseTemplate* templ = get_template(templateCode);
00207 
00208     const char remap[MAX_TEACHING_METHOD]
00209         = { templ->target_preference[P_SEMINAR], 0, templ->target_preference[P_CLASS_WITH_BREAKOUTS], 0, templ->target_preference[P_OTHER] };
00210 
00211     for( int i=0 ; i<MAX_TEACHING_METHOD; i++ ) {
00212         pref[i] = remap[i];
00213     }
00214 }
00215 
00216 //--------- End of function CourseRes::get_course_pref ---------//
00217 
00218 //------- Begin of function CourseRes::load_summer_db -------//
00220 void CourseRes::load_summer_db() {
00221     SummerRec *sumRec;
00222     Database    *dbsummer = game_set.open_db(SUMMER_COURSE_DB);
00223 
00224     //------ read in course information array -------//
00225 
00226     memset( summer_course_pref, 0, sizeof(summer_course_pref) );
00227 
00228     // summer_course_pref[MAX_STUDENT_LEVEL][SUMMER_PERF_COUNT][SUMMER_COURSE_COUNT];                           // 99->99%
00229 
00230     for( int sl=0, x=1; sl<MAX_STUDENT_LEVEL; sl++ ) {
00231         for( int e=0; e<SUMMER_PERF_COUNT; e++ ) {
00232             sumRec  = (SummerRec*) dbsummer->read(x);
00233 
00234             int prob=0;
00235             for( int c=0; c<SUMMER_COURSE_COUNT; c++ ) {
00236                 summer_course_pref[sl][e][c] = int( 100 * m.atof(sumRec->course_pref[c], 9) );
00237 
00238                 prob += summer_course_pref[sl][e][c];
00239 
00240                 err_when(summer_course_pref[sl][e][c] > 100 || summer_course_pref[sl][e][c] < 0);
00241             }
00242             x++;
00243 
00244             err_when(prob<90 || prob>110);
00245         }
00246         x++;
00247     }
00248 }
00249 
00250 //--------- End of function CourseRes::load_summer_db ---------//

Generated on Fri Aug 23 01:37:19 2002 for VirtualU by doxygen1.2.17