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

Password:

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

Ofirm.cpp

Go to the documentation of this file.
00001 //Filename   : OFIRM.CPP
00002 //Description: Class Firm functions
00003 //owner         : ho
00004 #include <OINFO.H>
00005 #include <OWORLD.H>
00006 #include <OAUDIO.H>
00007 #include <OCONFIG.H>
00008 #include <OSYS.H>
00009 #include <ODEPT.H>
00010 #include <ODEPTRES.H>
00011 #include <OFIRMRES.H>
00012 #include <OFIRM.H>
00013 #include <OBOX.H>
00014 //#include <OAUDIO.H>
00015 //#include <OCONFIG.H>
00016 
00017 #if(GAME_VERSION>=200)
00018 char* chapel_display_array[] = {
00019     "Praying for a win on Saturday, are we?",
00020     "The parking situation around here needs a few prayers!",
00021     "Praying should help but there are more ways to raise faculty morale!",
00022     "Welcome to the Chapel, peace can be found here.",
00023     "Asking for some help from above?"
00024 };
00025 static chapel_display_count = 5;
00026 #endif
00027 
00028 //--------- Begin of function Firm::init --------//
00033 void Firm::init(int xLoc, int yLoc, int firmId) {
00034     firm_id     = firmId;
00035     setup_date = info.game_date;
00036 
00037     department_recno = 0;
00038 
00039     //----- set the firm's location & absolute positions on the map -----//
00040 
00041     FirmInfo* firmInfo = firm_res[firmId];
00042 
00043     loc_x1 = xLoc;
00044     loc_y1 = yLoc;
00045     loc_x2 = loc_x1 + firmInfo->loc_width - 1;
00046     loc_y2 = loc_y1 + firmInfo->loc_height - 1;
00047 
00048     //  firm_width=firmInfo->loc_width;
00049     //  firm_height=firmInfo->loc_height;
00050 
00051     init_abs(ZOOM_SMALL , MAP_LOC_WIDTH  , MAP_LOC_HEIGHT);
00052     init_abs(ZOOM_MEDIUM, ZOOM1_LOC_WIDTH, ZOOM1_LOC_HEIGHT);
00053     init_abs(ZOOM_LARGE , ZOOM2_LOC_WIDTH, ZOOM2_LOC_HEIGHT);
00054 
00055     //------ init loc_matrix --------//
00056 
00057     init_matrix();
00058 
00059     //-------- init derived ---------//
00060 
00061     //  init_derived();
00062 }
00063 
00064 //----------- End of function Firm::init ---------//
00065 
00066 //--------- Begin of function Firm::deinit --------//
00068 void Firm::deinit() {
00069     deinit_matrix();
00070 }
00071 
00072 //----------- End of function Firm::deinit ---------//
00073 
00074 //--------- Begin of function Firm::init_abs ---------//
00076 void Firm::init_abs(int zoomLevel, int locWidth, int locHeight) {
00077     Rect* rectPtr = abs_rect+zoomLevel;
00078 
00079     FirmInfo* firmInfo = firm_res[firm_id];
00080 
00081     int bmpWidth  = *( (short*)firmInfo->bitmap_ptr[zoomLevel] );
00082     int bmpHeight = *( ((short*)firmInfo->bitmap_ptr[zoomLevel])+1 );
00083 
00084     rectPtr->x1 = (locWidth/2) * (loc_x1 + loc_y1);
00085     rectPtr->x2 = rectPtr->x1 + bmpWidth - 1;
00086 
00087     rectPtr->y2 = (MAX_WORLD_Y_LOC / 2 * locHeight) + ((locHeight/2) * (-loc_x1 + loc_y2 + 1 ) - 1);
00088     rectPtr->y1 = rectPtr->y2 - bmpHeight + 1;
00089 }
00090 
00091 //----------- End of function Firm::init_abs ---------//
00092 
00093 //--------- Begin of function Firm::init_matrix --------//
00095 void Firm::init_matrix() {
00096     //  for( int yLoc=max(1,loc_y1-1) ; yLoc<=min(MAX_WORLD_Y_LOC,loc_y2+1) ; yLoc++ )
00097     for( int yLoc=max(1,loc_y1-1) ; yLoc<=loc_y2 ; yLoc++ ) {
00098         //              for( int xLoc=max(1,loc_x1-1) ; xLoc<=min(MAX_WORLD_X_LOC,loc_x2+1) ; xLoc++ )
00099         for( int xLoc=loc_x1 ; xLoc<=min(MAX_WORLD_X_LOC,loc_x2+1) ; xLoc++ ) {
00100             if(!world.get_loc(xLoc,yLoc)->is_road())
00101                 if(!world.get_loc(xLoc,yLoc)->is_road_sub())
00102                     world.get_loc(xLoc,yLoc)->set_firm(firm_recno);
00103         }
00104     }
00105 
00106     // ##begin chwg0705
00107     // avoid invalid display of tree
00108 
00109     int w=loc_x2-loc_x1+1;
00110     int h=loc_y2-loc_y1+1;
00111     if(w>h) {
00112         int d=(w-h)/2;
00113         int c;
00114         for(c=2, yLoc=max(1,loc_y1-d) ; yLoc<loc_y1 ; yLoc++ ,c++) {
00115             for(int xLoc=loc_x1 ; xLoc<=loc_x1+c ; xLoc++ ) {
00116                 if(!world.get_loc(xLoc,yLoc)->is_road())
00117                     if(!world.get_loc(xLoc,yLoc)->is_road_sub())
00118                         world.get_loc(xLoc,yLoc)->set_firm(firm_recno);
00119             }
00120         }
00121         for(c=0, yLoc=loc_y2+1 ; yLoc<=min(MAX_WORLD_Y_LOC,loc_y2+d) ; yLoc++ ,c++) {
00122             for(int xLoc=loc_x2-d+c ; xLoc<=loc_x2 ; xLoc++ ) {
00123                 if(!world.get_loc(xLoc,yLoc)->is_road())
00124                     if(!world.get_loc(xLoc,yLoc)->is_road_sub())
00125                         world.get_loc(xLoc,yLoc)->set_firm(firm_recno);
00126             }
00127         }
00128     }
00129 
00130     // ##end chwg0705
00131 
00132 }
00133 
00134 //----------- End of function Firm::init_matrix --------//
00135 
00136 //--------- Begin of function Firm::deinit_matrix --------//
00138 void Firm::deinit_matrix() {
00139     for( int yLoc=max(1,loc_y1-2) ; yLoc<=min(MAX_WORLD_Y_LOC,loc_y2+2) ; yLoc++ ) {
00140         //      for( int yLoc=loc_y1 ; yLoc<=loc_y2 ; yLoc++ )
00141         for( int xLoc=max(1,loc_x1-2) ; xLoc<=min(MAX_WORLD_X_LOC,loc_x2+2) ; xLoc++ ) {
00142             //          for( int xLoc=loc_x1 ; xLoc<=loc_x2 ; xLoc++ )
00143             if(world.get_loc(xLoc,yLoc)->is_firm())
00144                 world.get_loc(xLoc,yLoc)->remove_firm();
00145         }
00146     }
00147 }
00148 
00149 //---------- End of function Firm::deinit_matrix ---------//
00150 
00151 //--------- Begin of function Firm::name --------//
00153 char* Firm::name() {
00154     static String str;
00155 
00156     if( department_recno ) {
00157         int deptId = department_array[department_recno]->department_id;
00158 
00159         str  = department_res[deptId]->name;
00160         str += " Department";
00161     }
00162     else {
00163         str = firm_res[firm_id]->name;
00164     }
00165 
00166     return str;
00167 }
00168 
00169 //---------- End of function Firm::name ---------//
00170 
00171 #if(GAME_VERSION>=200)
00172 
00173 //--------- Begin of function Firm::name_on_map --------//
00178 char* Firm::name_on_map() {
00179     if( department_recno ) {
00180         int deptId = department_array[department_recno]->department_id;
00181         return department_res[deptId]->name;
00182     }
00183     else {
00184         return firm_res[firm_id]->name;
00185     }
00186     return NULL;
00187 }
00188 
00189 //--------- End of function Firm::name_on_map --------//
00190 #endif
00191 
00192 //--------- Begin of function Firm::double_click_firm --------//
00196 void Firm::double_click_firm() {
00197     int viewMode=0;
00198 
00199     if( firm_id < FIRST_NONDEPARTMENTAL_FIRM_ID ) { // if it's a departmental building
00200         viewMode = MODE_PERFORMANCE_REPORT;
00201         enum {
00202             MODE_INSTITUTION  = 0,
00203             MODE_DEPARTMENT = 1,
00204             MODE_RANK     = 2,
00205         };
00206         department_array.current_data_mode=MODE_DEPARTMENT;
00207     }
00208     else {
00209         switch(firm_id) {
00210         case FIRM_STUDENT:                          // Student Union
00211             viewMode = MODE_STUDENT_REPORT;
00212             break;
00213 
00214         case FIRM_PRESIDENT: {                      // ## chwg0707
00215             if(info.year_passed<=1) {
00216                 viewMode = MODE_WELCOME_LETTER;
00217             }
00218             else {
00219                 viewMode = MODE_EVALUATION_LETTER;
00220             }
00221         }
00222         break;
00223 
00224         case FIRM_TOWER:                            // ## chwg0707
00225             viewMode = MODE_SCORE_REPORT;
00226             break;
00227 
00228         case FIRM_OLD_MAIN:
00229         case FIRM_POLICE:
00230         case FIRM_PARK_LOTS:
00231         case FIRM_PARK_STRUCTURE:
00232         case FIRM_ADMISSIONS:
00233         case FIRM_DEVELOPMENT:
00234         case FIRM_FACILITIES:
00235         case FIRM_LIBRARY:
00236         case FIRM_STADIUM:
00237         case FIRM_RESIDENCE:                        // ## chwg0930
00238         case FIRM_PLAY_FIELD:
00239         case FIRM_INDOOR_SPORTS:
00240             // if is not a departmental building
00241             viewMode = MODE_FIRST_NONDEPARTMENTAL_FIRM+
00242                 firm_id-FIRST_NONDEPARTMENTAL_FIRM_ID;
00243             break;
00244 #if(GAME_VERSION>=200)
00245         case FIRM_CHAPEL:
00246             int randomMsg = m.random( chapel_display_count );
00247             box.msg( chapel_display_array[randomMsg] );
00248             break;
00249 #endif
00250         }
00251     }
00252 
00253     if( viewMode ) {
00254         sys.set_view_mode(viewMode, 0);               // 0-don't play sound as it is played in FirmArray::select_firm() already
00255     }
00256 }
00257 
00258 //---------- End of function Firm::double_click_firm ---------//

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