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

Password:

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

Ofaculta.cpp

Go to the documentation of this file.
00001 //Filename    : OFACULTA.CPP
00002 //Description : Faculty Array Class Definition
00003 
00004 #include <OSYS.H>
00005 #include <OFACULTY.H>
00006 
00007 //##### begin fred 0819 #####//
00008 #include <OPSCHOOL.H>
00009 #include <OFINANCE.H>
00010 #include <ODEPT.H>
00011 //##### end fred 0819 #####//
00012 #include <OMATH.H>                                //## chea 221199 init talent
00013 
00014 //----------- Begin of function FacultyArray Constructor -----//
00016 FacultyArray::FacultyArray() : DynArrayB(sizeof(Faculty), 100, DEFAULT_REUSE_INTERVAL_DAYS) {
00017     faculty_count = 0;
00018 
00019     memset(talent_teaching,0,sizeof(talent_teaching));
00020     memset(talent_scholarship,0,sizeof(talent_teaching));
00021     memset(talent_research,0,sizeof(talent_teaching));
00022 
00023     memset(performance_teaching,0,sizeof(talent_teaching));
00024     memset(performance_scholarship,0,sizeof(talent_teaching));
00025     memset(performance_research,0,sizeof(talent_teaching));
00026 
00027     memset(satisfaction_index,0,sizeof(satisfaction_index));
00028     memset(percent_research,0,sizeof(percent_research));
00029 
00030     memset(teaching_contact_hour,0,sizeof(teaching_contact_hour));
00031     memset(discretionary_hour_array, 0, sizeof(discretionary_hour_array));
00032 
00033 #if(GAME_VERSION>=200)
00034     time_shifted_scholarship = 0;
00035 #endif
00036 }
00037 
00038 //------------- End of function FacultyArray Constructor -----//
00039 
00040 //----------- Begin of function FacultyArray Destructor ------//
00042 FacultyArray::~FacultyArray() {
00043     //----------------------------------//
00044 
00045     for( int i=size() ; i>0 ; i-- ) {
00046         if( !is_deleted(i) )
00047 #if(GAME_VERSION>=200)
00048             del(i,1);
00049 #else
00050         del(i);
00051 #endif
00052     }
00053 
00054     //----------------------------------//
00055 }
00056 
00057 //------------- End of function FacultyArray Destructor ------//
00058 
00059 //--------- Begin of function FacultyArray::add ---------//
00060 
00061 int FacultyArray::add(int departmentRecno, int rankLevel, int genderEthnicGroup, int facultyAge, int startTeachingDate,
00062                       int facultySalary, int talentTeaching, int talentScholarship, int talentResearch) {
00063 
00064     //## chea 221199 init all talent here
00065     //## chea 221099 init talentTeaching here
00066     //## chea 021299 modifiled from math.get_random_snd(1.0f, 0.05f)
00067     int talent_Teaching;
00068     talent_Teaching = (int)(talentTeaching * math.get_random_snd(1.0f, 0.10f));
00069     if(talent_Teaching>=100)
00070         talent_Teaching =100;
00071     int talent_Scholarship = (int)(talentScholarship * math.get_random_snd(1.0f, 0.10f));
00072     if(talent_Scholarship>=100)
00073         talent_Scholarship =100;
00074     int talent_Research    = (int)(talentResearch * math.get_random_snd(1.0f, 0.10f));
00075     if(talent_Research>=100)
00076         talent_Research =100;
00077 
00078     Faculty faculty;
00079 
00080     faculty.init(departmentRecno, rankLevel, genderEthnicGroup, facultyAge, startTeachingDate, facultySalary, talent_Teaching, talent_Scholarship, talent_Research);
00081 
00082     linkin(&faculty);
00083 
00084     ((Faculty*) get())->faculty_recno = recno();
00085 
00086     faculty_count++;
00087 
00088 #if(GAME_VERSION>=200)
00089     // update display_faculty_array && display_faculty_count in department
00090     Department* deptPtr = department_array[departmentRecno];
00091 
00092     Faculty* orgPtr = this->operator [](recno());
00093 
00094     deptPtr->cur_faculty_array.linkin(orgPtr);
00095 
00096     Faculty* facPtr = (Faculty*) deptPtr->cur_faculty_array.get(deptPtr->cur_faculty_array.size());
00097 
00098     facPtr->employ_status = 0;                      // New Hire
00099 #endif
00100 
00101     return recno();
00102 }
00103 
00104 //----------- End of function FacultyArray::add -----------//
00105 
00106 //--------- Begin of function FacultyArray::del ---------//
00107 #if(GAME_VERSION>=200)
00108 void FacultyArray::del(int recNo, int isQuiting)
00109 #else
00110     void FacultyArray::del(int recNo)
00111 #endif
00112 {
00113 #if(GAME_VERSION>=200)
00114     Faculty*  orgPtr = operator[](recNo);
00115 
00116     // update display_faculty_array && display_faculty_count in department
00117     Department* deptPtr = department_array[orgPtr->department_recno];
00118 
00119     if (!isQuiting) {
00120         deptPtr->cur_faculty_array.linkin( orgPtr );
00121 
00122         int arraySize = deptPtr->cur_faculty_array.size();
00123 
00124         Faculty* facPtr = (Faculty*) deptPtr->cur_faculty_array.get(arraySize);
00125 
00126         facPtr->employ_status = 1;                    // Department
00127     }
00128 #endif
00129 
00130     faculty_count--;
00131 
00132     linkout(recNo);
00133 }
00134 
00135 //----------- End of function FacultyArray::del -----------//
00136 
00137 //------ Begin of function FacultyArray::avg_discretionary_hour -----//
00142 int FacultyArray::avg_discretionary_hour(int discretionaryType) {
00143     Faculty* facultyPtr;
00144 
00145     int totalHour=0;
00146 
00147     for( int i=size() ; i>0 ; i-- ) {
00148         if( is_deleted(i) )
00149             continue;
00150 
00151         facultyPtr = operator[](i);
00152 
00153         totalHour += facultyPtr->discretionary_hour_array[discretionaryType];
00154     }
00155 
00156     //##### begin fred 980813 #####//
00157     if ( faculty_count )
00158         return totalHour / faculty_count;
00159     else
00160         return 0;
00161     //##### end fred 980813 #####//
00162 }
00163 
00164 //--------- End of function FacultyArray::avg_discretionary_hour -----//
00165 
00166 //--------- Begin of function FacultyArray::next_day ---------//
00167 
00168 void FacultyArray::next_day() {
00169     //----- call individual faculty's next_day() function ----//
00170 
00171     if(info.prerun_year == 1 && info.game_date == 1722034)
00172         int fgdfg=0;
00173 
00174     for( int i=size() ; i>0 ; i-- ) {
00175         if( is_deleted(i) )
00176             continue;
00177 
00178         operator[](i)->next_day();
00179     }
00180 
00181     //##### begin fred 0819 #####//
00182     // start of a trimester
00183     if ( info.game_day == player_school.trimester_array[player_school.cur_trimester].start_day
00184          && info.game_month == player_school.trimester_array[player_school.cur_trimester].start_month ) {
00185         update_history(UPDATE_TRIMESTER);
00186         think_summer_teaching();
00187     }
00188 
00189     // start of a month
00190     if ( info.game_day == 1 ) {
00191         update_history(UPDATE_MONTH);
00192         sys.yield();
00193 
00194         // start of a year
00195         if ( info.game_month == finance.fiscal_year_start_month )
00196             update_history(UPDATE_YEAR);
00197     }
00198     //##### end fred 0819 #####//
00199 }
00200 
00201 //----------- End of function FacultyArray::next_day -----------//
00202 
00203 //--------- Begin of function FacultyArray::next_trimester ---------//
00204 
00205 void FacultyArray::next_trimester() {
00206     int i;
00207 
00208     // for Faculty::think_discretionary_time()
00209 
00210     Department* deptPtr = department_array[department_recno];
00211     int total=0;                                    // = 0;     990419
00212 
00213     for ( i=0; i < DISCRETIONARY_TYPE_COUNT; i++ )
00214         total += deptPtr->priority_discretionary_hour_array[i];
00215 
00216     if ( total > 0 ) {                              // 990531
00217         for ( i=0; i < DISCRETIONARY_TYPE_COUNT; i++ ) {
00218             deptPtr->relative_priority_discretionary_hour_array[i]
00219                 = deptPtr->priority_discretionary_hour_array[i] * 100.0f / total;
00220             err_when(deptPtr->relative_priority_discretionary_hour_array[i] < 0);
00221         }
00222     }
00223     else
00224         for ( i=0; i < DISCRETIONARY_TYPE_COUNT; i++ )
00225             deptPtr->relative_priority_discretionary_hour_array[i] = 0;
00226 
00227     err_if ( total < 0 )                            // 990531
00228         err_here();
00229 
00230     //----- call individual faculty's next_trimester() function ----//
00231 
00232     for( i=size() ; i>0 ; i-- ) {
00233         if( is_deleted(i) )
00234             continue;
00235 
00236         //err_when(operator[](i)->faculty_recno != i);
00237 
00238         operator[](i)->next_trimester();
00239 
00240         sys.yield();
00241     }
00242 }
00243 
00244 //----------- End of function FacultyArray::next_trimester -----------//
00245 
00246 //--------- Begin of function FacultyArray::is_deleted ---------//
00247 
00248 int FacultyArray::is_deleted(int recNo) {
00249     Faculty* facultyPtr = (Faculty*) get(recNo);
00250 
00251     if( facultyPtr == NULL )
00252         return 1;
00253 
00254     return facultyPtr->faculty_recno == 0;
00255 }
00256 
00257 //----------- End of function FacultyArray::is_deleted -----------//
00258 
00259 //-------- Begin of function FacultyArray::get_unpacked_person --------//
00264 Faculty* FacultyArray::get_unpacked_faculty(int recNo) {
00265     //----- filter out deleted facultys --------//
00266 
00267     int i, facultyCount=0;
00268 
00269     for( i=1 ; i<=size() ; i++ ) {
00270         if( !is_deleted(i) ) {
00271             if( ++facultyCount == recNo )
00272                 return operator[](i);
00273         }
00274     }
00275 
00276     // ## begin chwg 0911
00277     return operator[](size());
00278     // ## end chwg 0911
00279 
00280     err_now( "FacultyArray::get_unpacked_faculty" );
00281     return NULL;
00282 }
00283 
00284 //----------- End of static function get_unpacked_faculty -----------//
00285 
00286 //##### begin fred 0819 #####//
00287 //---------- Begin of function FacultyArray::update_history -----------//
00288 void FacultyArray::update_history(char update_flag) {
00289     switch (update_flag) {
00290     case UPDATE_MONTH:
00291         calc_history_monthly();
00292         break;
00293     case UPDATE_TRIMESTER:
00294         calc_history_trimester();
00295         break;
00296     case UPDATE_YEAR:
00297         break;
00298     case UPDATE_ALL:
00299         update_history(UPDATE_MONTH);
00300         update_history(UPDATE_TRIMESTER);
00301         update_history(UPDATE_YEAR);
00302         break;
00303     default:
00304         err_here();
00305         break;
00306     }
00307 }
00308 
00309 //---------- End of function FacultyArray::update_history -----------//
00310 
00311 //---------- Begin of function FacultyArray::calc_history_trimester -----------//
00312 void FacultyArray::calc_history_trimester() {
00313     int i,j;
00314 
00315     shift_history(talent_teaching,HISTORY_TRIMESTER_COUNT);
00316     shift_history(talent_scholarship,HISTORY_TRIMESTER_COUNT);
00317     shift_history(talent_research,HISTORY_TRIMESTER_COUNT);
00318 
00319     shift_history(performance_teaching,HISTORY_TRIMESTER_COUNT);
00320     shift_history(performance_scholarship,HISTORY_TRIMESTER_COUNT);
00321     shift_history(performance_research,HISTORY_TRIMESTER_COUNT);
00322     shift_history(percent_research,HISTORY_TRIMESTER_COUNT);
00323 
00324     shift_history(teaching_contact_hour,HISTORY_TRIMESTER_COUNT);
00325     for ( j=0; j<DISCRETIONARY_TYPE_COUNT_N_TOTAL; j++ )
00326         shift_history(discretionary_hour_array[j], HISTORY_TRIMESTER_COUNT);
00327 
00328     Faculty* facultyPtr;
00329     float total[8];
00330     // use int, not char
00331     int discretionaryHourTotal[DISCRETIONARY_TYPE_COUNT];
00332     int facCount = 0;
00333 
00334     memset(total, 0, sizeof(total));
00335     memset(discretionaryHourTotal, 0, sizeof(discretionaryHourTotal));
00336 #if(GAME_VERSION>=200)
00337     time_shifted_scholarship = 0;
00338     int regularFacCount = 0;
00339 #endif
00340 
00341     for( i=size() ; i>0 ; i-- ) {
00342         if( is_deleted(i) )
00343             continue;
00344 
00345         facultyPtr = operator[](i); facCount++;
00346 
00347 #if(GAME_VERSION>=200)
00348         // don't count adjunct in ver2
00349         if( facultyPtr->is_regular() ) {
00350 #endif
00351             total[0] += facultyPtr->talent_teaching;
00352             total[1] += facultyPtr->talent_scholarship;
00353             total[2] += facultyPtr->talent_research;
00354             total[3] += facultyPtr->performance_teaching;
00355             total[4] += facultyPtr->performance_scholarship;
00356             total[5] += facultyPtr->performance_research;
00357 #if(GAME_VERSION>=200)
00358             ++regularFacCount;
00359         }
00360 #endif
00361 
00362         total[6] += (facultyPtr->research_proposal_count) ? 1 : 0;
00363         total[7] += facultyPtr->teaching_contact_hour;
00364 
00365         for ( j=0; j<DISCRETIONARY_TYPE_COUNT; j++ )
00366             discretionaryHourTotal[j] += facultyPtr->discretionary_hour_array[j];
00367 
00368 #if(GAME_VERSION>=200)
00369         time_shifted_scholarship += facultyPtr->time_shifted_scholarship;
00370 #endif
00371     }
00372 
00373     if ( !facCount )
00374         return;
00375 
00376 #if(GAME_VERSION>=200)
00377     talent_teaching[THIS_TRIMESTER] = math.safe_divide(total[0], (float)regularFacCount);
00378     talent_scholarship[THIS_TRIMESTER] = math.safe_divide(total[1], (float)regularFacCount);
00379     talent_research[THIS_TRIMESTER] = math.safe_divide(total[2], (float)regularFacCount);
00380     performance_teaching[THIS_TRIMESTER] = math.safe_divide(total[3], (float)regularFacCount);
00381     performance_scholarship[THIS_TRIMESTER] = math.safe_divide(total[4], (float)regularFacCount);
00382     performance_research[THIS_TRIMESTER] = math.safe_divide(total[5], (float)regularFacCount);
00383 #else
00384     talent_teaching[THIS_TRIMESTER] = (total[0] / facCount);
00385     talent_scholarship[THIS_TRIMESTER] = (total[1] / facCount);
00386     talent_research[THIS_TRIMESTER] = (total[2] / facCount);
00387     performance_teaching[THIS_TRIMESTER] = (total[3] / facCount);
00388     performance_scholarship[THIS_TRIMESTER] = (total[4] / facCount);
00389     performance_research[THIS_TRIMESTER] = (total[5] / facCount);
00390 #endif
00391     percent_research[THIS_TRIMESTER] = char(total[6] * 100 / facCount);
00392     teaching_contact_hour[THIS_TRIMESTER] = (total[7] / facCount);
00393 
00394     // 990518
00395     j = THIS_TRIMESTER;
00396     if((player_school.cur_trimester == SUMMER) &&
00397        // TL_summer < TL_spring
00398        (teaching_contact_hour[j] < teaching_contact_hour[j-1]) )
00399         teaching_contact_hour[j] = teaching_contact_hour[j-1];
00400 
00401     // include teaching_contact_hour in TOTAL
00402     discretionary_hour_array[DISCRETIONARY_TYPE_COUNT_N_TOTAL-1][THIS_TRIMESTER] = (total[7] / facCount);
00403 
00404 #if(GAME_VERSION>=200)
00405     time_shifted_scholarship /= facCount;
00406     // include time shifted from scholarship
00407     discretionary_hour_array[DISCRETIONARY_TYPE_COUNT_N_TOTAL-1][THIS_TRIMESTER] += time_shifted_scholarship;
00408 #endif
00409 
00410     for ( j=0; j<DISCRETIONARY_TYPE_COUNT; j++ ) {
00411         discretionary_hour_array[j][THIS_TRIMESTER] = float(discretionaryHourTotal[j]) / facCount;
00412         discretionary_hour_array[DISCRETIONARY_TYPE_COUNT_N_TOTAL-1][THIS_TRIMESTER] += discretionary_hour_array[j][THIS_TRIMESTER];
00413     }
00414 
00415 }
00416 
00417 //---------- End of function FacultyArray::calc_history_trimester -----------//
00418 
00419 //---------- Begin of function FacultyArray::calc_history_monthly -----------//
00420 void FacultyArray::calc_history_monthly() {
00421     shift_history(satisfaction_index,HISTORY_MONTH_COUNT);
00422 
00423     Faculty *facultyPtr;
00424     float total = 0;
00425     int i, facCount = 0;
00426 
00427     for( i=size() ; i>0 ; i-- ) {
00428         if( is_deleted(i) )
00429             continue;
00430 
00431         facultyPtr = operator[](i); facCount++;
00432 
00433         total += facultyPtr->satisfaction_index;
00434 
00435     }
00436 
00437     if ( !facCount )
00438         return;
00439 
00440     satisfaction_index[THIS_MONTH] = total / facCount;
00441 }
00442 
00443 //---------- End of function FacultyArray::calc_history_monthly -----------//
00444 //##### end fred 0819 #####//
00445 
00446 // ##### begin Marco#### //
00447 #if(GAME_VERSION>=200)
00448 //---------- Begin of function FacultyArray::save_initial_data -----------//
00449 void FacultyArray::save_initial_data() {
00450     int i;
00451 
00452     initial_teaching_contact_hour = teaching_contact_hour[HISTORY_TRIMESTER_COUNT-1];
00453     //  a percentage from 0 to 100
00454     initial_talent_teaching = talent_teaching[HISTORY_TRIMESTER_COUNT-1];
00455     initial_talent_scholarship = talent_scholarship[HISTORY_TRIMESTER_COUNT-1];
00456     initial_talent_research = talent_research[HISTORY_TRIMESTER_COUNT-1];
00457     //  a percentage from 0 to 100
00458     initial_performance_teaching = performance_teaching[HISTORY_TRIMESTER_COUNT-1];
00459     initial_performance_scholarship = performance_scholarship[HISTORY_TRIMESTER_COUNT-1];
00460     // BUGHRE change to monthly as in Faculty::update_history()
00461     initial_performance_research = performance_research[HISTORY_TRIMESTER_COUNT-1];
00462 
00463     for (i = 0; i < DISCRETIONARY_TYPE_COUNT_N_TOTAL;i++) {
00464         initial_discretionary_hour_array[i] = discretionary_hour_array[i][HISTORY_TRIMESTER_COUNT-1];
00465     }
00466 
00467     initial_time_shifted_scholarship = time_shifted_scholarship;
00468 }
00469 
00470 //---------- End of function FacultyArray::save_initial_data -----------//
00471 #endif
00472 // ###### End Marco ###### //
00473 
00474 #ifdef DEBUG
00475 
00476 //------- Begin of function FacultyArray::operator[] -----//
00477 
00478 Faculty* FacultyArray::operator[](int recNo) {
00479     Faculty* FacultyPtr = (Faculty*) get(recNo);
00480 
00481     if( !FacultyPtr )
00482         err.run( "FacultyArray[] is deleted" );
00483 
00484     return FacultyPtr;
00485 }
00486 
00487 //--------- End of function FacultyArray::operator[] ----//
00488 #endif

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