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

Password:

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

OGFILE3.CPP

Go to the documentation of this file.
00001 //Filename    : OGFILE3.CPP
00002 //Description : Object Game file, save game and restore game, part 3.1
00003 
00004 //=================================================================================//
00005 // for write_file_1
00006 
00007 #include <ODEPTRES.H>
00008 #include <OPEERSCH.H>
00009 #include <OSCHLRES.H>
00010 #include <OENROLL.H>
00011 #include <OLETTER.H>                              //## chea 990519
00012 #include <OFACURES.H>                             //## chea 090699
00013 
00014 //=================================================================================//
00015 // for write_file_2
00016 
00017 #include <OCONFIG.H>
00018 #include <OGAME.H>
00019 #include <OINFO.H>
00020 #include <OFINANCE.H>
00021 #include <OPSCHOOL.H>
00022 
00023 //=================================================================================//
00024 // for write_file_3
00025 
00026 #include <ODEPT.H>
00027 #include <ONEWS.H>
00028 #include <OTASK.H>
00029 #include <OCHANCE.H>
00030 
00031 #include <OATHLETI.H>
00032 #include <ODEVELOP.H>
00033 #include <OFACILIT.H>
00034 #include <OLIBTECH.H>
00035 #include <OINVEST.H>
00036 #include <OSTUOFF.H>
00037 
00038 //=================================================================================//
00039 #include <OGFILE.H>
00040 
00041 //=================================================================================//
00042 //============================ section 1/3 ========================================//
00043 //=================================================================================//
00044 
00045 //--------- Begin of function DepartmentRes::write_file ---------------//
00046 int DepartmentRes::write_file(File* filePtr) {
00047     //char                      init_flag;
00048 
00049     //short                     department_count;
00050     //DepartmentInfo*   info_array;
00051 
00052     //DepartmentInfo            general_dept_info;      // = general_education_department, although we just need GeneralDepartmentInfo, we still use DepartmentInfo for ease of programming
00053     //GeneralDepartment general_dept;                   // year 1 ug student without major
00054 
00055     int rc;
00056 
00057     rc = filePtr->file_put_short(init_flag);
00058     rc &= filePtr->file_put_short(department_count);
00059 
00060     if ( !rc )
00061         return 0;
00062 
00063     err_when(!info_array);
00064 
00065     if( !filePtr->file_write( info_array, department_count*sizeof(DepartmentInfo) ) )
00066         return 0;
00067 
00068     if( !filePtr->file_write(&general_dept_info, sizeof(general_dept_info)) )
00069         return 0;
00070 
00071     return general_dept.write_file(filePtr);
00072 }
00073 
00074 int DepartmentRes::read_file(File* filePtr) {
00075     init_flag = (char) filePtr->file_get_short();
00076     department_count = filePtr->file_get_short();
00077 
00078     err_when(!info_array);
00079 
00080     if( !filePtr->file_read( info_array, department_count*sizeof(DepartmentInfo) ) )
00081         return 0;
00082 
00083     if( !filePtr->file_read(&general_dept_info, sizeof(general_dept_info)) )
00084         return 0;
00085 
00086     return general_dept.read_file(filePtr);
00087 }
00088 
00089 //--------- End of function DepartmentRes::write_file ---------------//
00090 
00091 //## chea 090699 begin try to save the FacultyRes()
00092 //--------- Begin of function FacultyRes::write_file ---------------//
00093 int FacultyRes::write_file(File* filePtr) {
00094 
00095     //char                init_flag;
00096     //short                      faculty_template_count;
00097     //FacultyTemplate* faculty_template_array;
00098 
00099     int rc;
00100 
00101     rc = filePtr->file_put_short(init_flag);
00102     rc &= filePtr->file_put_short(faculty_template_count);
00103 
00104     if ( !rc )
00105         return 0;
00106 
00107     err_when(!faculty_template_array);
00108 
00109     if( !filePtr->file_write( faculty_template_array, faculty_template_count*sizeof(FacultyTemplate) ) )
00110         return 0;
00111 
00112     return 1;
00113 }
00114 
00115 int FacultyRes::read_file(File* filePtr) {
00116     init_flag = (char) filePtr->file_get_short();
00117     faculty_template_count = filePtr->file_get_short();
00118 
00119     err_when(!faculty_template_array);
00120 
00121     if( !filePtr->file_read( faculty_template_array, faculty_template_count*sizeof(FacultyTemplate) ) )
00122         return 0;
00123 
00124     return 1;
00125 }
00126 
00127 //--------- End of function FacultyRes::write_file ---------------//
00128 //## chea 090699 end try to save the FacultyRes()
00129 
00130 //--------- Begin of function SchoolRes::write_file ---------------//
00131 int SchoolRes::write_file(File* filePtr) {
00132     err_when(db_school_array);
00133     err_when(peer_info_array);
00134 
00135     //PeerSchool*                       player_peer_school;
00136     //short                                     peer_school_count;
00137     //PeerSchool*                       peer_school_array;      // includes player_peer_school after battle.create_object()
00138 
00139     if ( !filePtr->file_write(this, sizeof(SchoolRes)) )
00140         return 0;
00141 
00142     //-------------------//
00143 
00144     err_when(!peer_school_array);
00145 
00146     if( !filePtr->file_write( peer_school_array, peer_school_count*sizeof(PeerSchool) ) )
00147         return 0;
00148 
00149     //-------------------//
00150 
00151     short playerPeerIndex = -1;
00152 
00153     for (int i=0; i<peer_school_count; i++)
00154         if ( peer_school_array+i == player_peer_school ) {
00155             playerPeerIndex = i;
00156             break;
00157         }
00158 
00159     err_when(playerPeerIndex <0);
00160 
00161     filePtr->file_put_short(playerPeerIndex);
00162 
00163     //-------------------//
00164     // write PeerSchool::
00165     // static float pref_vars_average_array[PREFERECNE_COUNT2];
00166     // static float pref_vars_average_array_last[PREFERECNE_COUNT2];
00167     // static int       average_faculty_salary[MAX_RANK_AGE_GROUP];             // not $000
00168 
00169     if( !filePtr->file_write(PeerSchool::pref_vars_average_array, sizeof(PeerSchool::pref_vars_average_array) ) )
00170         return 0;
00171 
00172     if( !filePtr->file_write(PeerSchool::pref_vars_average_array_last, sizeof(PeerSchool::pref_vars_average_array_last) ) )
00173         return 0;
00174 
00175     if( !filePtr->file_write(PeerSchool::average_faculty_salary, sizeof(PeerSchool::average_faculty_salary) ) )
00176         return 0;
00177 
00178     return 1;
00179 }
00180 
00181 //-------------------//
00182 int SchoolRes::read_file(File* filePtr) {
00183     free_db_info();
00184 
00185 #if(GAME_VERSION>=200)
00186     School* schoolPtr = desired_school_array;
00187     int   schoolCount = desired_school_count;
00188 #endif
00189 
00190     //-------------------//
00191 
00192     if ( !filePtr->file_read(this, sizeof(SchoolRes)) )
00193         return 0;
00194 
00195 #if(GAME_VERSION>=200)
00196     desired_school_array = schoolPtr;
00197     desired_school_count = schoolCount;
00198 #endif
00199 
00200     //-------------------//
00201 
00202     peer_school_array = (PeerSchool *) mem_add(peer_school_count*sizeof(PeerSchool));
00203 
00204     if( !filePtr->file_read( peer_school_array, peer_school_count*sizeof(PeerSchool) ) )
00205         return 0;
00206 
00207     //-------------------//
00208 
00209     short playerPeerIndex = -1;
00210 
00211     playerPeerIndex = filePtr->file_get_short();
00212 
00213     err_when(playerPeerIndex < 0 || playerPeerIndex >= peer_school_count);
00214 
00215     player_peer_school = peer_school_array+playerPeerIndex;
00216 
00217     //-------------------//
00218 
00219     if( !filePtr->file_read(PeerSchool::pref_vars_average_array, sizeof(PeerSchool::pref_vars_average_array) ) )
00220         return 0;
00221 
00222     if( !filePtr->file_read(PeerSchool::pref_vars_average_array_last, sizeof(PeerSchool::pref_vars_average_array_last) ) )
00223         return 0;
00224 
00225     if( !filePtr->file_read(PeerSchool::average_faculty_salary, sizeof(PeerSchool::average_faculty_salary) ) )
00226         return 0;
00227 
00228     return 1;
00229 }
00230 
00231 //--------- End of function SchoolRes::write_file ---------------//
00232 
00233 //--------- Begin of function EnrollRes::write_file ---------------//
00234 int EnrollRes::write_file(File* filePtr) {
00235     return filePtr->file_write(this, sizeof(EnrollRes));
00236 }
00237 
00238 int EnrollRes::read_file(File* filePtr) {
00239     return filePtr->file_read(this, sizeof(EnrollRes));
00240 }
00241 
00242 //--------- End of function EnrollRes::write_file ---------------//
00243 
00244 //--------- Begin of function EnrollRes::write_file ---------------//  //## chea begin 990519
00245 int Letter::write_file(File* filePtr) {
00246     return filePtr->file_write(this, sizeof(Letter));
00247 }
00248 
00249 int Letter::read_file(File* filePtr) {
00250     return filePtr->file_read(this, sizeof(Letter));
00251 }
00252 
00253 //--------- End of function EnrollRes::write_file ---------------//    //## chea end 990519
00254 
00255 //=================================================================================//
00256 //============================ section 2/3 ========================================//
00257 //=================================================================================//
00258 
00259 //--------- Begin of function Config::write_file ---------------//
00260 int Config::write_file(File* filePtr) {
00261     return filePtr->file_write(this, sizeof(Config));
00262 }
00263 
00264 // keepSysSettings:     default = 1
00265 //
00266 int Config::read_file(File* filePtr, int keepSavedSysSettings) {
00267     if ( keepSavedSysSettings )
00268         return filePtr->file_read(this, sizeof(Config));
00269     else {
00270         default_game_setting();
00271         return 1;
00272     }
00273 }
00274 
00275 //--------- End of function Config::write_file ---------------//
00276 
00277 //--------- Begin of function Info::write_file ---------------//
00278 int Info::write_file(File* filePtr) {
00279 
00280     random_seed_4_save = m.random_seed;             //## chea 210899 to save the random seed before save
00281 
00282     int writeSize = (char*)(&last_write_offset) - (char*)(this);
00283 
00284     //---------- write the info data -----------//
00285 
00286     return filePtr->file_write( this, writeSize );
00287 }
00288 
00289 int Info::read_file(File* filePtr) {
00290     int readSize = (char*)(&last_write_offset) - (char*)(this);
00291 
00292     //------- read the info data ----------//
00293 
00294     return filePtr->file_read( this, readSize );
00295 }
00296 
00297 //--------- End of function Info::write_file ---------------//
00298 
00299 //--------- Begin of function Info::write_file ---------------//
00300 int Game::write_file(File* filePtr) {
00301     return filePtr->file_write( this, sizeof(Game) );
00302 }
00303 
00304 int Game::read_file(File* filePtr) {
00305     return filePtr->file_read( this, sizeof(Game) );
00306 }
00307 
00308 //--------- End of function Info::write_file ---------------//
00309 
00310 //--------- Begin of function Finance::write_file ---------------//
00311 int Finance::write_file(File* filePtr) {
00312     return filePtr->file_write( this, sizeof(Finance) );
00313 }
00314 
00315 int Finance::read_file(File* filePtr) {
00316     return filePtr->file_read( this, sizeof(Finance) );
00317 }
00318 
00319 //--------- End of function Finance::write_file ---------------//
00320 
00321 //--------- Begin of function PlayerSchool::write_file ---------------//
00322 int PlayerSchool::write_file(File* filePtr) {
00323     return filePtr->file_write( this, sizeof(PlayerSchool) );
00324 }
00325 
00326 int PlayerSchool::read_file(File* filePtr) {
00327     return filePtr->file_read( this, sizeof(PlayerSchool) );
00328 }
00329 
00330 //--------- End of function PlayerSchool::write_file ---------------//
00331 
00332 //=================================================================================//
00333 //============================ section 3/3 ========================================//
00334 //=================================================================================//
00335 
00336 //--------- Begin of function NewsArray::write_file ---------------//
00337 int NewsArray::write_file(File* filePtr) {
00338     //------ write info in NewsArray ------//
00339 
00340     if( !filePtr->file_write( (char*) this + sizeof(DynArray), sizeof(NewsArray)-sizeof(DynArray) ) )
00341         return 0;
00342 
00343     return DynArray::write_file( filePtr );
00344 }
00345 
00346 int NewsArray::read_file(File* filePtr) {
00347     if( !filePtr->file_read( (char*) this + sizeof(DynArray), sizeof(NewsArray)-sizeof(DynArray) ) )
00348         return 0;
00349 
00350     return DynArray::read_file( filePtr );
00351 }
00352 
00353 //--------- End of function NewsArray::write_file ---------------//
00354 
00355 //--------- Begin of function TaskArray::write_file ---------------//
00356 int TaskArray::write_file(File* filePtr) {
00357     if( !filePtr->file_write( (char*) this + sizeof(DynArray), sizeof(TaskArray)-sizeof(DynArray) ) )
00358         return 0;
00359 
00360     return DynArray::write_file( filePtr );
00361 }
00362 
00363 int TaskArray::read_file(File* filePtr) {
00364     if( !filePtr->file_read( (char*) this + sizeof(DynArray), sizeof(TaskArray)-sizeof(DynArray) ) )
00365         return 0;
00366 
00367     return DynArray::read_file( filePtr );
00368 }
00369 
00370 //--------- End of function TaskArray::write_file ---------------//
00371 
00372 //--------- Begin of function ChanceEvent::write_file ---------------//
00373 int ChanceEvent::write_file(File* filePtr) {
00374     return filePtr->file_write(this, sizeof(ChanceEvent));
00375 }
00376 
00377 int ChanceEvent::read_file(File* filePtr) {
00378     return filePtr->file_read(this, sizeof(ChanceEvent));
00379 }
00380 
00381 //--------- End of function ChanceEvent::write_file ---------------//
00382 
00383 //--------- Begin of function Development::write_file ---------------//
00384 int Development::write_file(File* filePtr) {
00385     return filePtr->file_write(this, sizeof(Development));
00386 }
00387 
00388 int Development::read_file(File* filePtr) {
00389     return filePtr->file_read(this, sizeof(Development));
00390 }
00391 
00392 //--------- End of function Development::write_file ---------------//
00393 
00394 //--------- Begin of function Athletics::write_file ---------------//
00395 int Athletics::write_file(File* filePtr) {
00396     return filePtr->file_write(this, sizeof(Athletics));
00397 }
00398 
00399 int Athletics::read_file(File* filePtr) {
00400     return filePtr->file_read(this, sizeof(Athletics));
00401 }
00402 
00403 //--------- End of function Athletics::write_file ---------------//
00404 
00405 //--------- Begin of function LibTech::write_file ---------------//
00406 int LibTech::write_file(File* filePtr) {
00407     return filePtr->file_write(this, sizeof(LibTech));
00408 }
00409 
00410 int LibTech::read_file(File* filePtr) {
00411     return filePtr->file_read(this, sizeof(LibTech));
00412 }
00413 
00414 //--------- End of function LibTech::write_file ---------------//
00415 
00416 //--------- Begin of function Facility::write_file ---------------//
00417 int Facility::write_file(File* filePtr) {
00418     return filePtr->file_write(this, sizeof(Facility));
00419 }
00420 
00421 int Facility::read_file(File* filePtr) {
00422     return filePtr->file_read(this, sizeof(Facility));
00423 }
00424 
00425 //--------- End of function Facility::write_file ---------------//
00426 
00427 //--------- Begin of function Facility::write_file ---------------//
00428 int Investment::write_file(File* filePtr) {
00429     return filePtr->file_write(this, sizeof(Investment));
00430 }
00431 
00432 int Investment::read_file(File* filePtr) {
00433     return filePtr->file_read(this, sizeof(Investment));
00434 }
00435 
00436 //--------- End of function Facility::write_file ---------------//
00437 
00438 //--------- Begin of function Facility::write_file ---------------//
00439 int StudentOffice::write_file(File* filePtr) {
00440     return filePtr->file_write(this, sizeof(StudentOffice));
00441 }
00442 
00443 int StudentOffice::read_file(File* filePtr) {
00444     return filePtr->file_read(this, sizeof(StudentOffice));
00445 }
00446 
00447 //--------- End of function Facility::write_file ---------------//

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