00001
00002
00003
00004 #include <OSYS.H>
00005 #include <OFACULTY.H>
00006
00007
00008 #include <OPSCHOOL.H>
00009 #include <OFINANCE.H>
00010 #include <ODEPT.H>
00011
00012 #include <OMATH.H>
00013
00014
00016
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
00039
00040
00042
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
00058
00059
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
00065
00066
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
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;
00099 #endif
00100
00101 return recno();
00102 }
00103
00104
00105
00106
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
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;
00127 }
00128 #endif
00129
00130 faculty_count--;
00131
00132 linkout(recNo);
00133 }
00134
00135
00136
00137
00142
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
00157 if ( faculty_count )
00158 return totalHour / faculty_count;
00159 else
00160 return 0;
00161
00162 }
00163
00164
00165
00166
00167
00168 void FacultyArray::next_day() {
00169
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
00182
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
00190 if ( info.game_day == 1 ) {
00191 update_history(UPDATE_MONTH);
00192 sys.yield();
00193
00194
00195 if ( info.game_month == finance.fiscal_year_start_month )
00196 update_history(UPDATE_YEAR);
00197 }
00198
00199 }
00200
00201
00202
00203
00204
00205 void FacultyArray::next_trimester() {
00206 int i;
00207
00208
00209
00210 Department* deptPtr = department_array[department_recno];
00211 int total=0;
00212
00213 for ( i=0; i < DISCRETIONARY_TYPE_COUNT; i++ )
00214 total += deptPtr->priority_discretionary_hour_array[i];
00215
00216 if ( total > 0 ) {
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 )
00228 err_here();
00229
00230
00231
00232 for( i=size() ; i>0 ; i-- ) {
00233 if( is_deleted(i) )
00234 continue;
00235
00236
00237
00238 operator[](i)->next_trimester();
00239
00240 sys.yield();
00241 }
00242 }
00243
00244
00245
00246
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
00258
00259
00264
00265
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
00277 return operator[](size());
00278
00279
00280 err_now( "FacultyArray::get_unpacked_faculty" );
00281 return NULL;
00282 }
00283
00284
00285
00286
00287
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
00310
00311
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
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
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
00395 j = THIS_TRIMESTER;
00396 if((player_school.cur_trimester == SUMMER) &&
00397
00398 (teaching_contact_hour[j] < teaching_contact_hour[j-1]) )
00399 teaching_contact_hour[j] = teaching_contact_hour[j-1];
00400
00401
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
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
00418
00419
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
00444
00445
00446
00447 #if(GAME_VERSION>=200)
00448
00449 void FacultyArray::save_initial_data() {
00450 int i;
00451
00452 initial_teaching_contact_hour = teaching_contact_hour[HISTORY_TRIMESTER_COUNT-1];
00453
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
00458 initial_performance_teaching = performance_teaching[HISTORY_TRIMESTER_COUNT-1];
00459 initial_performance_scholarship = performance_scholarship[HISTORY_TRIMESTER_COUNT-1];
00460
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
00471 #endif
00472
00473
00474 #ifdef DEBUG
00475
00476
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
00488 #endif