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

Password:

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

OBATTLE.CPP

Go to the documentation of this file.
00001 //Filename    : OBATTLE.CPP
00002 //Description : Battle Object
00003 //Owner       : Fred
00004 
00005 #include <OBATTLE.H>
00006 #include <OMUSIC.H>
00007 #include <OBOX.H>
00008 #include <OGAME.H>
00009 #include <OINFO.H>
00010 #include <OMISC.H>
00011 #include <OMOUSE.H>
00012 #include <OMOUSECR.H>
00013 #include <OSCHLRES.H>
00014 #include <ODEPT.H>
00015 #include <OSYS.H>
00016 #include <OWORLD.H>
00017 #include <ORECT.h>
00018 #include <OFIRM.H>
00019 #include <OROAD.H>
00020 #include <OPLANT.H>
00021 #include <OFIRMRES.H>
00022 #include <OLETTER.H>
00023 //#include <OSPRITEA.H>
00024 #include <OSPRITE.H>
00025 #include <OPSCHOOL.H>
00026 #include <OPEERSCH.H>                             // enrollment
00027 #include <OFINANCE.H>
00028 //##### begin fred 980824 #####//
00029 #include <OFACULTY.H>
00030 #include <OSTUDENT.H>
00031 #include <ODEPTRES.H>
00032 
00033 #include <OOPT.H>
00034 #include <OATHLETI.H>
00035 #include <ODEVELOP.H>
00036 #include <OFacilit.H>                             //##### fred 980810 #####//
00037 #include <OLibtech.H>                             //##### fred 980828 #####//
00038 #include <OStuOff.H>                              //##### fred 980918 #####//
00039 #include <OINVEST.H>                              //##### fred 980923 #####//
00040 #include <OMATH.H>
00041 //##### end fred 980824 #####//
00042 #include <ALL.H>
00043 
00044 //#define DEBUG_LOG_LOCAL 1
00045 //#include <OLOG.H>
00046 
00047 static void init_doctoral_target();
00048 
00049 //-------- Begin of function Battle::init --------//
00051 void Battle::init() {
00052 }
00053 
00054 //-------- End of function Battle::init --------//
00055 
00056 //-------- Begin of function Battle::deinit --------//
00058 void Battle::deinit() {
00059 }
00060 
00061 //-------- End of function Battle::deinit --------//
00062 
00063 //-------- Begin of function Battle::run --------//
00068 void Battle::run(int scenId) {
00069     //DEBUG_LOG("Battle:: run()");
00070 
00071     // ## begin chwg072999
00072     for (int k = 0; k < REVENUE_POLICY_COUNT + EXPENSE_POLICY_COUNT; k++) {
00073         if(optimization.opt1_button_group_array[k]!=NULL)
00074             optimization.opt1_button_group_array[k]->button_pressed=1;
00075         if(optimization.opt1_slider_group[k].init_flag!=0)
00076             optimization.opt1_slider_group[k].enable_flag=1;
00077     }
00078     for (k = 0; k < COST_RISE_POLICY_COUNT; k++) {
00079         if(optimization.opt2_button_group_array[k]!=NULL)
00080             optimization.opt2_button_group_array[k]->button_pressed=1;
00081         if(optimization.opt2_slider_group[k].init_flag!=0)
00082             optimization.opt2_slider_group[k].enable_flag=1;
00083     }
00084     // ## end chwg072999
00085 
00086     int oldCursor = mouse_cursor.get_icon();
00087 
00088     mouse_cursor.set_icon(CURSOR_WAITING);
00089 
00090     info.prerun_year=1;                             //## chea 150799 start prerun year here
00091 
00092     info.init_random_seed(0);
00093 
00094     switch( scenId ) {
00095     case 0:
00096     default:
00097         create_pregame_object();
00098         //              letter.init_welcome_letter();                   //## chea 130899 move to info.next_day
00099 
00100         /*              break;
00101                         case 1:
00102                         create_pregame_object_scenario1();
00103                         break;
00104         */
00105 
00106         //      err_here();
00107         break;
00108     }
00109 
00110     if ( info.prerun_year==1)                       //## chea 150799 for going out of the prerun
00111         mouse_cursor.set_icon(CURSOR_WAITING);
00112 
00113     mouse_cursor.restore_icon(oldCursor);
00114 
00115     //  int songId = music.random_bgm_track();
00116     //  music.play(songId, sys.cdrom_drive ? MUSIC_PLAY_CD : 0 );
00117 
00118     //DEBUG_LOG("Battle:: going to call sys.run()");
00119 
00120     //--- give the control to the system main loop, start the game now ---//
00121 
00122     sys.run();
00123 }
00124 
00125 //--------- End of function Battle::run ---------//
00126 
00127 //-------- Begin of function Battle::create_static_game_object --------//
00131 void Battle::create_static_game_object() {
00132     //---- generate roads ----//
00133 
00134     generate_road();
00135 
00136     //---- generate firms ----//
00137 
00138     generate_firm();
00139 
00140     //---- generate sprites ----//
00141 
00142     //  generate_sprite();
00143 
00144     //---- generate plant ----//
00145 
00146     generate_plant();
00147 
00148 }
00149 
00150 //-------- Begin of function Battle::create_static_game_object --------//
00151 
00152 //-------- Begin of function Battle::generate_road ---------//
00153 
00154 void Battle::generate_road() {
00155     int blockWidth=10, blockHeight=8;
00156     int firmId=0;
00157 
00158     //------- lay horizontal roads -------//
00159 
00160     // only 3/4 of the area has roads - so that we can have a big area for placing stadium
00161     for( int yLoc=0 ; yLoc+blockHeight<=MAX_WORLD_Y_LOC*3/4 ; yLoc+=blockHeight ) {
00162         road_res.build_road(0, yLoc, MAX_WORLD_X_LOC-2, yLoc );
00163     }
00164 
00165     //------- lay vertical roads -------//
00166 
00167     for( int xLoc=0 ; xLoc+blockWidth<=MAX_WORLD_X_LOC ; xLoc+=blockWidth ) {
00168         road_res.build_road(xLoc, 0, xLoc, MAX_WORLD_Y_LOC-32 );
00169     }
00170 }
00171 
00172 //--------- End of function Battle::generate_road ---------//
00173 
00174 //-------- Begin of function Battle::generate_firm ---------//
00176 void Battle::generate_firm() {
00177     int    blockWidth=10, blockHeight=8;
00178     int    firmId=0;
00179     FirmInfo* firmInfo;
00180 
00181     while(1) {
00182         if( ++firmId > firm_res.firm_count )
00183             break;                                      // complete creating all needed buildings
00184 
00185         firmInfo = firm_res[firmId];
00186 
00187         // don't add departmental buildings as they will be added in Battle::create_pregame_objects()
00188         if( !firmInfo->field_id && firmInfo->is_available() ) {
00189             create_firm(firmId);
00190         }
00191     }
00192 
00193     //----- add stadium, hard code because it will display across the border ---//
00194 
00195     //  firm_array.add_firm( 13, MAX_WORLD_Y_LOC-29, FIRM_PLAY_FIELD );         // play field
00196     // stadium
00197     firm_array.add_firm( 28, MAX_WORLD_Y_LOC-29, FIRM_STADIUM );
00198     // indoor sports center
00199     firm_array.add_firm( 48, MAX_WORLD_Y_LOC-29, FIRM_INDOOR_SPORTS );
00200 }
00201 
00202 //--------- End of function Battle::generate_firm ---------//
00203 
00204 //-------- Begin of function Battle::create_firm ---------//
00205 
00206 void Battle::create_firm(int firmId) {
00207     int    blockWidth=10, blockHeight=8;
00208     FirmInfo* firmInfo = firm_res[firmId];
00209 
00210     for( int yLoc=2, yCount=0 ; yLoc+blockHeight<=MAX_WORLD_Y_LOC ; yLoc+=blockHeight, yCount++ ) {
00211         for( int xLoc=2, xCount=0 ; xLoc+blockWidth<=MAX_WORLD_X_LOC ; xLoc+=blockWidth, xCount++ ) {
00212             if( firmInfo->loc_width > blockWidth-ROAD_WIDTH ||
00213                 firmInfo->loc_height > blockHeight-ROAD_HEIGHT ) {
00214                 continue;
00215             }
00216 
00217             int buildXLoc = xLoc + (blockWidth-ROAD_WIDTH-firmInfo->loc_width)/2;
00218             int buildYLoc = yLoc + (blockHeight-ROAD_HEIGHT-firmInfo->loc_height)/2;
00219 
00220             if( firmInfo->can_build(buildXLoc, buildYLoc) ) {
00221                 firm_array.add_firm( buildXLoc, buildYLoc, firmId );
00222                 return;
00223             }
00224         }
00225     }
00226 }
00227 
00228 //--------- End of function Battle::create_firm ---------//
00229 
00230 //-------- Begin of function Battle::generate_plant ---------//
00231 
00232 void Battle::generate_plant() {
00233     for( int yLoc=0 ; yLoc<MAX_WORLD_Y_LOC ; yLoc++ ) {
00234         for( int xLoc=0 ; xLoc<MAX_WORLD_X_LOC ; xLoc++ ) {
00235             Location* locPtr = world.get_loc(xLoc, yLoc);
00236 
00237             if( !locPtr->is_empty() )
00238                 continue;
00239 
00240             if( m.random(3)==0 ) {
00241                 int plantId = m.random(plant_res.plant_count)+1;
00242 
00243                 locPtr->set_plant(plantId, m.random(25), 75+m.random(25));
00244             }
00245         }
00246     }
00247 }
00248 
00249 //--------- End of function Battle::generate_plant ---------//
00250 
00251 //--------- Begin of function Battle::generate_sprite --------//
00253 void Battle::generate_sprite() {
00254     int unitId = 1;
00255     int xLoc, yLoc;
00256 
00257     //TO only put sprite within the viewable area (area within mapview) but not the world
00258     //i.e. refer to Matrix::draw_objects()
00259     //
00260     for( xLoc=0 ; xLoc<MAX_WORLD_X_LOC ; xLoc++ ) {
00261         for( yLoc=0 ; yLoc<MAX_WORLD_Y_LOC ; yLoc++ ) {
00262             Location* locPtr = world.get_loc(xLoc, yLoc);
00263 
00264             if( !locPtr->is_road() )                    // place sprite on road
00265                 continue;
00266 
00267             //temp: only road is set to be walkable
00268             err_when( locPtr->is_walkable() && !locPtr->is_road() );
00269 
00270             if( !m.random(6) ) {
00271                 locPtr->set_sprite(unitId);
00272                 //                              Sprite* spritePtr = new Sprite;
00273                 //                              spritePtr->init( unitId, xLoc, yLoc, 0, 0 );
00274                 //                              sprite_array.add(spritePtr);
00275                 unitId++;
00276             }
00277 
00278         }                                             // for yLoc
00279     }
00280 
00281     /*
00282       for( xLoc=0 ; xLoc<MAX_WORLD_X_LOC ; xLoc++ )
00283       {
00284       for( yLoc=0 ; yLoc<MAX_WORLD_Y_LOC ; yLoc++ )
00285       {
00286       Location* locPtr = world.get_loc(xLoc, yLoc);
00287 
00288       if ( locPtr->has_sprite() )
00289       {
00290       //        sprite_array[locPtr->sprite_recno()]
00291       }
00292       }
00293       }*/
00294 #ifdef DEBUG
00295     debug_msg("generate_sprite end: %d", unitId);
00296 #endif
00297 }
00298 
00299 //---------- End of function Battle::generate_sprite ---------//
00300 
00301 //--------- Begin of function Battle::run_loaded --------//
00303 void Battle::run_loaded() {
00304 }
00305 
00306 //---------- End of function Battle::run_loaded ---------//
00307 
00308 //--------- Begin of function Battle::init_performance_indicator --------//
00310 void Battle::init_performance_indicator() {
00311     int i,j;
00312     StudentArray* stuArr;
00313     Department* deptPtr;
00314 
00315     for ( i=department_array.size(); i>0; i-- ) {
00316         if (department_array.is_deleted(i) )
00317             continue;
00318 
00319         deptPtr = department_array[i];
00320 
00321         // loop faculty
00322         for ( j=deptPtr->faculty_array.faculty_count; j>0; j-- ) {
00323             deptPtr->faculty_array[j]->update_history(UPDATE_ALL);
00324         }
00325         deptPtr->faculty_array.update_history(UPDATE_ALL);
00326 
00327         // loop student
00328         stuArr = &(department_array[i]->student_array);
00329 
00330         for (j=stuArr->size(); j>0; j--) {
00331             //##        begin zhoubin 000329
00332             if ( stuArr->is_deleted(j) )
00333                 continue;
00334             //##        end     zhoubin 000329
00335             stuArr->operator[](j)->update_history(UPDATE_ALL);
00336         }
00337         deptPtr->student_array.update_history(UPDATE_ALL);
00338 
00339         deptPtr->course_array.update_history();
00340 
00341         deptPtr->update_history(UPDATE_ALL);
00342     }
00343 
00344     department_array.update_history(UPDATE_ALL);
00345 
00346     // special case for ug yr1 student:
00347     //
00348     stuArr = &(department_res.general_dept.student_array);
00349     for (j=stuArr->size(); j>0; j--) {
00350         //##    begin zhoubin 000329
00351         if ( stuArr->is_deleted(j) )
00352             continue;
00353         //##    end     zhoubin 000329
00354         stuArr->operator[](j)->update_history(UPDATE_ALL);
00355     }
00356 
00357     // calc institutional-wide vars
00358     //
00359     //----------------//
00360 
00361     for (i=0; i<school_res.peer_school_count; i++) {
00362         //min & max bug chea
00363         school_res.peer_school_array[i].game_score = (float)m.fmax(20, math.get_random_snd(40,8));
00364     }
00365 
00366     //---------------//
00367     player_school.init_game_score = 0;
00368     player_school.cur_game_score = 0;
00369     player_school.ultimate_game_score = 0;
00370 
00371     player_school.init_pi();
00372     player_school.update_history(UPDATE_ALL);
00373 }
00374 
00375 //---------- End of function Battle::init_performance_indicator ---------//
00376 
00377 //---------- Begin of function Battle::init_doctoral_target() ---------//
00379 void init_doctoral_target() {
00380     int i,j;
00381     CourseArray* courArr;
00382     Department* deptPtr;
00383 
00384     for ( i=department_array.size(); i>0; i-- ) {
00385         if (department_array.is_deleted(i) )
00386             continue;
00387 
00388         deptPtr = department_array[i];
00389 
00390         //-------- PART 1 of 2   //0405
00391         // deptPtr->init_doctor_count = deptPtr->student_level_history[DOCTOR][THIS_YEAR];
00392 
00393         float doctorPct = 0; {
00394             char s = DOCTOR;
00395             doctorPct = player_school.student_level_pct[s] - player_school.student_level_pct[MASTER];
00396         }
00397 
00398         // "/4" means 4 year to graduate for DOCTOR in average
00399         deptPtr->init_doctor_count = (int) (player_school.get_player_expected_student_count() * doctorPct / 4);
00400 
00401         //-------- PART 2 of 2
00402 
00403         deptPtr->calc_research_dollar();
00404         deptPtr->doctors_per_research_dollar = math.safe_divide( deptPtr->init_doctor_count, deptPtr->total_research_dollar_direct*1000);
00405 
00406         //-------- PART B
00407 
00408         int totalBreakoutSections = 0;
00409         courArr = &(department_array[i]->course_array);
00410 
00411         for (j=courArr->size(); j>0; j--) {
00412             if ( courArr->operator[](j)->teaching_method == BREAKOUT_LAB )
00413                 totalBreakoutSections++;
00414         }
00415 
00416         deptPtr->init_breakout_section_count = totalBreakoutSections;
00417         //min & max bug chea
00418         deptPtr->breakout_section_by_doctor = (float) min((float)(totalBreakoutSections*TRIMESTER_PER_YEAR), (float)(DOCTORAL_AVERAGE_TEACHING_BREAKOUT_SECTIONS * deptPtr->init_doctor_count));
00419     }
00420 }
00421 
00422 //---------- End of function Battle::init_doctoral_target() ---------//
00423 
00424 //-------- Begin of function Battle::create_pregame_object --------//
00425 /*
00426 
00427 a) generate player school using game settings,
00428 b) generate DEPARTMENTS
00429 c) generate non-year-one STUDENT sims
00430 d) finance.init_data_pre_enroll()
00431 e) enrollment management: init_data() and enroll_main()
00432 f) course enrollment for old and newly matriculated students.
00433 f2) ini.talent for sl1  //later
00434 g1) generate FACULTY sims
00435 g2) simulate one-year research progress for FACULTY sims        // 990415
00436 h) facility_office.init_data_pre_finance()
00437 i) finance
00438 j) other small offices
00439 k) calc statistics: student/faculty count
00440 
00441 */
00442 //
00443 // Initialize pre-game objects - departments, students, etc
00444 //
00445 void Battle::create_pregame_object() {
00446     int i;
00447 
00448     //--------------------------------------//
00449     //special case:
00450 
00451     //  box.progress_update(14);
00452 
00453     //chwg0111
00454     sys.report_before_morerpt_or_deptlist=MODE_NORMAL;
00455     sys.report_before_help=MODE_NORMAL;             //chwg0713
00456 
00457     memset(&athletics_office, 0, sizeof(Athletics));
00458 
00459     athletics_office.last_ncaa_level_input = player_school.athletic_program_intensity;
00460     // assumed called before school_res.init_game()
00461     athletics_office.input_2_ncaa_level(player_school.athletic_program_intensity);
00462 
00463     school_res.init_game();                         // initialize school_res.player_peer_school and school_res.peer_school_array[]
00464 
00465     //---- generate testing departments ----//
00466 
00467     create_static_game_object();
00468 
00469     for (i=0; i<MAX_DEPARTMENT; i++) {
00470         int deptId = player_school.selected_department_list[i];
00471         if ( deptId <= 0 )
00472             break;
00473         else
00474             department_array.add(deptId);
00475     }
00476 
00477     department_array.init_data();
00478 
00479     department_res.calc_total_elective_course_pref();
00480 
00481     //----------------------------//
00482     //special case:
00483     athletics_office.init_data_pre_finance();
00484 
00485     //---- generate students ----//
00486 
00487     for( i=department_array.size() ; i>0 ; i--) {
00488         if( department_array.is_deleted(i) )
00489             continue;
00490 
00491         // clear course data in last trimester
00492         department_array[i]->course_array.next_trimester();
00493         sys.yield();
00494     }
00495 
00496     box.progress_update(14);                        //## chea 150799 start prerun year here
00497 
00498     player_school.generate_student();               // must after deparment_array.add(); this will select courses taken
00499 
00500     //----- Enrollment model -----//
00501     // must run after school_res.build_peer_school_array()
00502     // must run after player_school.generate_student to calc student_count
00503 
00504     finance.init_data_pre_enroll();
00505 
00506     enroll_res.init_data();
00507 
00508     //---------------------------//
00509     // whether do this serval times or not???
00510     //td3.4 section 2.6: overall model initialization
00511 
00512     init_doctoral_target();                         // before enroll_main
00513     enroll_res.enroll_main(80);                     // GENERATE student; required for athletics_office.init_data        //1: init_data
00514 
00515     //---------------------------------------//
00516 
00517     // g1) generate_faculty() called after course enrollment; see email req42_misc.txt
00518 
00519     for( i=department_array.size(); i>0; i--) {
00520         if( department_array.is_deleted(i) )
00521             continue;
00522 
00523         Department* deptPtr = department_array[i];
00524 
00525         deptPtr->generate_faculty();                  // GENERATE faculty
00526         deptPtr->init_hiring();                       // must after generate_faculty()
00527     }
00528 
00529     // g2) simulate one-year research progress for all FACULTY sims     // 990421
00530 
00531     department_array.init_research();               // 990421
00532 
00533     //---------------------------------------//
00534 
00535     //----- Financial model -----//
00536 
00537     facility_office.init_data_pre_finance();        // 0119 calc normal onm; after course enroll and faculty gen.
00538 
00539     finance.init_data();                            // after generate faculty and student; also after enroll since requires enroll_res.total_student_count
00540 
00541     //---------------------------------------//
00542 
00543     // offices must called after finance.init_data
00544     development_office.init_data();
00545     athletics_office.init_data();                   // after enroll also
00546 
00547     library_tech_office.init_data();
00548 
00549     student_office.init_data();
00550 
00551     investment_office.init_data();
00552 
00553     //--- post init ------------------------------------//
00554 
00555     init_performance_indicator();                   // must after finance and enroll
00556 
00557 #if(GAME_VERSION>=200)
00558     info.update_distance_learning_variables(1);     // need call this function after init_performance_indicator
00559 #endif
00560 
00561     library_tech_office.init_data();                // 990508 // after init_performance_indicator
00562 
00563     facility_office.init_data();                    // after department_array.add() and department_array.update_history(UPDATE_ALL);
00564 
00565     // must after finance and enroll
00566     finance.post_init_data();                       // 0218
00567 
00568     //-----------------//
00569     // 0130 scenario
00570 
00571 #ifdef DEBUG
00572     for (i=department_array.size(); i>0; i--) {
00573         Department *deptPtr;
00574 
00575         deptPtr = department_array[i];
00576         err_when(i != deptPtr->department_recno);
00577     }
00578 #endif
00579 
00580 #if(GAME_VERSION>=200)
00581     for ( i=department_array.size(); i>0; i-- ) {
00582         if (department_array.is_deleted(i))
00583             continue;
00584 
00585         Department* deptPtr = department_array[i];
00586 
00587         int arraySize = deptPtr->cur_faculty_array.size();
00588 
00589         if ( arraySize != 0 )
00590             deptPtr->cur_faculty_array.zap();
00591     }
00592 #endif
00593 
00594     box.progress_update(28);                        //## chea 150799 start prerun year here
00595 }
00596 
00597 //-------- End of function Battle::create_pregame_object --------//
00598 
00599 //-------- Begin of function Battle::create_pregame_object_scenario1 --------//
00603 void Battle::create_pregame_object_scenario1() {
00604     create_pregame_object();
00605 }
00606 
00607 //-------- End of function Battle::create_pregame_object_scenario1 --------//

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