//--------- Begin of function UnitArray::update_selected_trade_unit_info ---------// // update trade information of trading units if these units are selected // void UnitArray::update_selected_trade_unit_info() { short playerNationRecno = nation_array.player_recno; Unit *unitPtr; UnitMarine *marinePtr; if(remote.is_enable()) { for(int i=size(); i>0; --i) { if(is_deleted(i)) continue; unitPtr = (Unit*)get_ptr(i); if(!unitPtr->is_visible()) continue; switch(unitPtr->unit_id) { case UNIT_CARAVAN: if(mp_is_selected_caravan(i)) ((UnitCaravan*) unitPtr)->update_stop_and_goods_info(); break; case UNIT_VESSEL: case UNIT_CARAVEL: case UNIT_GALLEON: marinePtr = ((UnitMarine*) unitPtr); if(marinePtr->auto_mode && mp_is_selected_ship(i)) marinePtr->update_stop_and_goods_info(); break; default: break; } } } else if(selected_recno && !is_deleted(selected_recno)) { unitPtr = (Unit*)get_ptr(selected_recno); if(unitPtr->nation_recno==playerNationRecno || config.show_ai_info) { switch(unitPtr->unit_id) { case UNIT_CARAVAN: ((UnitCaravan*) unitPtr)->update_stop_and_goods_info(); break; case UNIT_VESSEL: case UNIT_CARAVEL: case UNIT_GALLEON: marinePtr = ((UnitMarine*) unitPtr); if(marinePtr->auto_mode) marinePtr->update_stop_and_goods_info(); break; default: break; } } } }
//--------- Begin of function StudentArray::next_day ---------// //! void StudentArray::next_day() { //----- call individual student's next_day() function ----// for( int i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; operator[](i)->next_day(); } //##### begin fred 980819 #####// //----------------------------------------// // start of a month if ( info.game_day == 1 ) { //## 071299 chea 1.12.1 // update_history(UPDATE_MONTH); // start of a year if ( info.game_month == finance.fiscal_year_start_month ) update_history(UPDATE_YEAR); //## 071299 chea 1.12.1 else update_history(UPDATE_MONTH); } //##### end fred 980819 #####// }
void hmap_print(struct hmap *map) { unsigned long i, j; unsigned char *aux_key=map->keys, *aux_data=map->data; printf("Struct hmap at %p\n", (void *) map); printf("map_size=%lu key_size=%lu data_size=%lu\n", map->map_size, map->key_size, map->data_size); for (i=0; i<map->map_size; i++) { if (is_empty(aux_key+i*map->key_size, map->key_size)) printf("Block %lu: empty\n", i); else if (is_deleted(aux_key+i*map->key_size, map->key_size)) printf("Block %lu: deleted\n", i); else { printf("Block %lu: key = ", i); for (j=0; j<map->key_size; j++) printf("%u ", aux_key[i*map->key_size+j]); printf("data = "); for (j=0; j<map->key_size; j++) printf("%u ", aux_data[i*map->data_size+j]); printf("\n"); } } }
void hash_table_insert(struct hash_table* ht, hash_key_t k, hash_val_t v) { float load_factor = (float)ht->size / ht->capacity; if (load_factor >= HASH_TABLE_UPSIZE_LOAD_FACTOR) { size_t new_cap = ht->capacity * 2; hash_table_resize(ht, new_cap); } uint32_t hash = hash_key(ht, k); for (size_t i = 0; ; ++i) { size_t index = index_from_hash((hash + i), ht->capacity); uint32_t cur_hash = ht->hashes[index]; struct hash_entry* e = ht->table + index; /* Found empty or deleted slot, insert */ if (cur_hash == 0 || is_deleted(cur_hash)) { e->key = k; e->val = v; ht->hashes[index] = hash; ++ht->size; return; } /* Found occupied slot with same hash and key, replace value */ if (hash == cur_hash && ht->eql_fn(e->key, k)) { e->val = v; return; } } }
//--------- Begin of function UnitArray::stop_attack_obj ---------// // // stop all units that is attacking the specified unit // // <int> baseObjRecno - baseObjRecno // [int] nationRecno - if this is given, only units of this unit // will be ordered to stop attack. Otherwise, // stop all units. // void UnitArray::stop_attack_obj(int baseObjRecno, int nationRecno) { if( nation_hand_over_flag ) return; for(int i=size(); i>0; --i) { if(is_deleted(i)) continue; Unit* unitPtr = operator[](i); if( !unitPtr->is_visible() ) continue; if( nationRecno && nationRecno != unitPtr->nation_recno ) continue; if( unitPtr->cur_order.mode == UNIT_ATTACK && unitPtr->cur_order.para == baseObjRecno ) { unitPtr->stop_order(); } else if( unitPtr->pushed_order.mode == UNIT_ATTACK && unitPtr->pushed_order.para == baseObjRecno ) { unitPtr->stop_order(); } } }
//--------- Begin of function StudentArray::select_course ---------// //! //! All courses are selected during breaks between trimesters. //! //! [int] ignoreFaculty - if this is true, courses will be assigned //! without faculty constraints. This is for //! initialization only. //! (default: 0) //! void StudentArray::select_course(int ignoreFaculty) { //-- select courses for students in various student levels based on the priority set by the user --// // int studentCount = packed_size(); // 990302 BUGHERE should use size() instead int studentCount = size(); //## chea 300899 used size() instead // info.debug_enroll3 = packed_size(); //## chea 270899 for( int i=0 ; i<MAX_STUDENT_LEVEL ; i++ ) { int studentLevel = player_school.course_match_order[i]; int studentRecno = m.random(studentCount); for( int y=0 ; y<studentCount ; y++ ) { if( ++studentRecno > studentCount ) studentRecno = 1; if( is_deleted(studentRecno) ) continue; Student* studentPtr = operator[](studentRecno); if( studentPtr->student_level != studentLevel ) continue; studentPtr->file_course_id=0; studentPtr->select_course(ignoreFaculty); // info.debug_enroll2++; //## chea 270899 } } //--- reset counter variables after completing course selection for the trimester ---// // if this is the last trimester in a year, reset annual variables if( player_school.cur_trimester == LAST_TRIMESTER ) { for( int i=studentCount ; i>0 ; i-- ) { if( is_deleted(i) ) continue; Student* studentPtr = operator[](i); studentPtr->total_elective_course_this_year = 0; } } }
int tux_readdir(struct file *file, void *state, filldir_t filldir) { loff_t pos = file->f_pos; #ifdef __KERNEL__ struct inode *dir = file->f_dentry->d_inode; #else struct inode *dir = file->f_inode; #endif int revalidate = file->f_version != dir->i_version; struct sb *sb = tux_sb(dir->i_sb); unsigned blockbits = sb->blockbits; block_t block, blocks = dir->i_size >> blockbits; unsigned offset = pos & sb->blockmask; assert(!(dir->i_size & sb->blockmask)); for (block = pos >> blockbits ; block < blocks; block++) { struct buffer_head *buffer = blockread(mapping(dir), block); if (!buffer) return -EIO; void *base = bufdata(buffer); if (revalidate) { if (offset) { tux_dirent *entry = base + offset; tux_dirent *p = base + (offset & sb->blockmask); while (p < entry && p->rec_len) p = next_entry(p); offset = (void *)p - base; file->f_pos = (block << blockbits) + offset; } file->f_version = dir->i_version; revalidate = 0; } tux_dirent *limit = base + sb->blocksize - TUX_REC_LEN(1); for (tux_dirent *entry = base + offset; entry <= limit; entry = next_entry(entry)) { if (entry->rec_len == 0) { blockput(buffer); tux_zero_len_error(dir, block); return -EIO; } if (!is_deleted(entry)) { unsigned type = (entry->type < TUX_TYPES) ? filetype[entry->type] : DT_UNKNOWN; int lame = filldir( state, entry->name, entry->name_len, (block << blockbits) | ((void *)entry - base), be64_to_cpu(entry->inum), type); if (lame) { blockput(buffer); return 0; } } file->f_pos += tux_rec_len_from_disk(entry->rec_len); } blockput(buffer); offset = 0; } return 0; }
FirmDie *FirmDieArray::operator[](int recNo) { FirmDie* firmDiePtr = (FirmDie*) get(recNo); if( !firmDiePtr || is_deleted(recNo) ) err.run( "FirmDieArray[] is deleted" ); return firmDiePtr; }
static inline int tux_match(tux_dirent *entry, const char *const name, unsigned len) { if (len != entry->name_len) return 0; if (is_deleted(entry)) return 0; return !memcmp(name, entry->name, len); }
//----------- Begin of function StudentArray Destructor ------// //! StudentArray::~StudentArray() { //----------------------------------// for( int i=size() ; i>0 ; i-- ) { if( !is_deleted(i) ) del(i); } //----------------------------------// }
//--------- Begin of function UnitArray::stop_all_war ---------// // // Stop all the units that is in war with the specified nation // and stop all the units of the specified nation that is in war // with other nations // // <short> stopNationRecno - the nation_renco of the specified nation // void UnitArray::stop_all_war(short stopNationRecno) { for( int i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; Unit* unitPtr = operator[](i); if( !unitPtr->is_visible() ) continue; //---- if this unit is attacking somebody ------/ if( unitPtr->cur_order.mode == UNIT_ATTACK ) { if( unitPtr->nation_recno == stopNationRecno ) { unitPtr->stop_order(); continue; } //--- if the target is already killed ---// if( !base_obj_array.is_deleted(unitPtr->cur_order.para) && base_obj_array[unitPtr->cur_order.para]->nation_recno == stopNationRecno ) { unitPtr->stop_order(); continue; } } //--- if this unit has a pushed order, also check it ----// if( !unitPtr->has_pushed_order() ) continue; if( unitPtr->pushed_order.mode == UNIT_ATTACK ) { if( unitPtr->nation_recno == stopNationRecno ) { unitPtr->stop_order(); continue; } //--- if the target is already killed ---// if( !base_obj_array.is_deleted(unitPtr->pushed_order.para) && base_obj_array[unitPtr->pushed_order.para]->nation_recno == stopNationRecno ) { unitPtr->stop_order(); continue; } } } }
//--------- Begin of function UnitArray::stop_war_between ---------// // // Stop the war between the two nations specified // // <short> nationReno1 - the nation_renco of one of the nation // <short> nationReno2 - the nation_renco of the other nation // if it is 0, then stop wars between the // specific nation and any other nation. // void UnitArray::stop_war_between(short nationRecno1, short nationRecno2) { for( int i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; Unit* unitPtr = operator[](i); if( !unitPtr->is_visible() ) continue; if( unitPtr->nation_recno != nationRecno1 && unitPtr->nation_recno != nationRecno2 ) { continue; } //---- if this unit is attacking somebody ------/ if( unitPtr->cur_order.mode == UNIT_ATTACK ) { if( !base_obj_array.is_deleted(unitPtr->cur_order.para) ) { int targetNationRecno = base_obj_array[unitPtr->cur_order.para]->nation_recno; if( targetNationRecno == nationRecno1 || targetNationRecno == nationRecno2 ) { unitPtr->stop_order(); continue; } } } //--- if this unit has a pushed order, also check it ----// if( !unitPtr->has_pushed_order() ) continue; if( unitPtr->pushed_order.mode == UNIT_ATTACK ) { if( !base_obj_array.is_deleted(unitPtr->pushed_order.para) ) { int targetNationRecno = base_obj_array[unitPtr->pushed_order.para]->nation_recno; if( targetNationRecno == nationRecno1 || targetNationRecno == nationRecno2 ) { unitPtr->stop_order(); continue; } } } } }
//--------- Begin of function NationArray::deinit ---------// // // Called by ~NationArray when game terminate // and NationArray::read_file() when loading game // void NationArray::deinit() { int i; // can't call the destructor of Firm, must call deinit() for( i=size() ; i>0 ; i-- ) { if( !is_deleted(i) ) del_nation(i); } zap(); // clean up the array }
struct hash_entry* hash_table_next_entry(struct hash_table* ht, struct hash_entry* entry) { struct hash_entry* e = 0; size_t index = !entry ? 0 : ((entry - ht->table) + 1); for (; index < ht->capacity; ++index) { uint32_t cur_hash = ht->hashes[index]; if ((cur_hash != 0 && !is_deleted(cur_hash))) { e = ht->table + index; break; } } return e; }
static inline size_t lookup_index(struct hash_table* ht, hash_key_t k) { uint32_t hash = hash_key(ht, k); for(size_t i = 0; ; ++i) { size_t index = index_from_hash((hash + i), ht->capacity); uint32_t cur_hash = ht->hashes[index]; if (cur_hash == 0) break; if (!is_deleted(cur_hash) && hash == cur_hash && ht->eql_fn(ht->table[index].key, k)) return index; } return -1; }
void Surface_mesh:: update_vertex_normals() { if (!vnormal_) vnormal_ = vertex_property<Normal>("v:normal"); Vertex_iterator vit, vend=vertices_end(); for (vit=vertices_begin(); vit!=vend; ++vit) { if (!is_deleted(vit)) vnormal_[vit] = compute_vertex_normal(vit); } }
void Surface_mesh:: update_face_normals() { if (!fnormal_) fnormal_ = face_property<Normal>("f:normal"); Face_iterator fit, fend=faces_end(); for (fit=faces_begin(); fit!=fend; ++fit) { if (!is_deleted(fit)) fnormal_[fit] = compute_face_normal(fit); } }
int post_record_read(record_t *rec, int base, post_info_t *buf, int size, post_list_type_e type) { if (record_seek(rec, base, RECORD_SET) < 0) return 0; int records = 0; if (is_deleted(type)) { POST_RECORD_READ_HELPER(post_record_extended_t, POST_TRASH_BUF_SIZE, post_record_extended_to_info); } else { POST_RECORD_READ_HELPER(post_record_t, POST_BOARD_BUF_SIZE, post_record_to_info); } return records; }
//--------- Begin of function StudentArray::next_trimester ---------// //! //! This function is called when a new school year begins. //! void StudentArray::next_trimester() { for( int i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; operator[](i)->next_trimester(); sys.yield(); } //----- select courses for the new trimester ------// //### fred 980916 ###// // select_cours() runs after next_trimester() which handle change of major and drop out// //select_cours(); // remove this because it should be called after enrollment }
// ###### begin Gilbert 15/3 #######// // ---------- Begin of function NationArray::get_campaign_nation --------// // Nation* NationArray::get_campaign_nation(int campaignNationRecno) { if( !campaignNationRecno ) return NULL; for(int i = 1; i <= size(); ++i ) { if( is_deleted(i) ) continue; Nation *nationPtr = operator[](i); if( nationPtr->campaign_nation_recno == campaignNationRecno ) return nationPtr; } return NULL; }
void FirmDieArray::process() { int i, j; for( i=1, j=size(); j; --j, ++i) { if( is_deleted(i) ) continue; FirmDie *firmDiePtr = this->operator[](i); if( firmDiePtr->process() ) { del(i); continue; } } }
virtual const zim::writer::Article* getNextArticle() { //Add all articles in File_1 that have not ben deleted. if(index<start_file.getFileheader().getArticleCount()) //Meaning still on file_1 { zim::Article tmpAr=start_file.getArticle(index); while(is_deleted(tmpAr.getLongUrl())) { index++; tmpAr=start_file.getArticle(index); } tempArticle=Article(tmpAr,index); //If the article is also present in file_2 if(diff_file.getArticleByUrl(tmpAr.getLongUrl()).getIndex()!=4294967295) { zim::Article tmp=diff_file.getArticleByUrl(tmpAr.getLongUrl()); tmpAr=tmp; tempArticle=Article(tmpAr,start_file.getFileheader().getArticleCount()+diff_file.getArticleByUrl(tmpAr.getLongUrl()).getIndex()); } index++; return &tempArticle; } //Now adding new articles in file_2 if(index<(start_file.getFileheader().getArticleCount()+diff_file.getFileheader().getArticleCount())) { zim::Article tmpAr=diff_file.getArticle(index-start_file.getFileheader().getArticleCount()); //If the article is already in file_1, it has been added. while(start_file.getArticleByUrl(tmpAr.getLongUrl()).getIndex()!=4294967295||isAdditionalMetadata(tmpAr.getLongUrl())) { index++; if(index>=(start_file.getFileheader().getArticleCount()+diff_file.getFileheader().getArticleCount())) break; tmpAr=diff_file.getArticle(index-start_file.getFileheader().getArticleCount()); } if(index<(start_file.getFileheader().getArticleCount()+diff_file.getFileheader().getArticleCount())) { tempArticle=Article(tmpAr,index); index++; return &tempArticle; } } return 0; }
//--------- Begin of function SpyArray::deinit ----------// // void SpyArray::deinit() { if( size()==0 ) return; // ####### begin Gilbert 22/3 #######// //----- delete units ------// for( int i=1 ; i<=size() ; i++ ) { if( is_deleted(i) ) continue; del_spy(i); } // ####### end Gilbert 22/3 #######// //-------- zap the array -----------// zap(); }
int tux_dir_is_empty(struct inode *dir) { struct sb *sb = tux_sb(dir->i_sb); block_t block, blocks = dir->i_size >> sb->blockbits; __be64 self = cpu_to_be64(tux_inode(dir)->inum); struct buffer_head *buffer; for (block = 0; block < blocks; block++) { buffer = blockread(mapping(dir), block); if (!buffer) return -EIO; tux_dirent *entry = bufdata(buffer); tux_dirent *limit = bufdata(buffer) + sb->blocksize - TUX_REC_LEN(1); for (; entry <= limit; entry = next_entry(entry)) { if (!entry->rec_len) { blockput(buffer); tux_zero_len_error(dir, block); return -EIO; } if (is_deleted(entry)) continue; if (entry->name[0] != '.') goto not_empty; if (entry->name_len > 2) goto not_empty; if (entry->name_len < 2) { if (entry->inum != self) goto not_empty; } else if (entry->name[1] != '.') goto not_empty; } blockput(buffer); } return 0; not_empty: blockput(buffer); return -ENOTEMPTY; }
int sbox_is_deleted(char *path) { return is_deleted(os_deleted_fs, path); }
//---------- Begin of function StudentArray::calc_degree_awarded -----------// void StudentArray::calc_degree_awarded() { //-----------------------------------------// shift_history(bachelor_degree, HISTORY_YEAR_COUNT); shift_history(non_ug_bachelor_degree, HISTORY_YEAR_COUNT ); shift_history(master_degree, HISTORY_YEAR_COUNT); shift_history(doctor_degree, HISTORY_YEAR_COUNT); for (int y=0; y<DEGREE_TYPE_COUNT; y++) { shift_history(time_to_degree[y], HISTORY_YEAR_COUNT); shift_history(fake_disp_time_to_degree[y], HISTORY_YEAR_COUNT); shift_history(dropout_rate[y], HISTORY_YEAR_COUNT); } //-----------------------------------------// // // The [THIS_YEAR] element in all historical array // is always the latest obtainable value of the // variables. Some will have values for the // current year, some will have values for the // last year. So THIS_YEAR does not mean the // current year. // // As for the graduation rate, the value is // graduation rate of the last year as the value // for the current year hasn't been known yet. // //-----------------------------------------// bachelor_degree[THIS_YEAR] = cur_bachelor_degree; non_ug_bachelor_degree[THIS_YEAR] = cur_non_ug_bachelor_degree; master_degree [THIS_YEAR] = cur_master_degree; doctor_degree [THIS_YEAR] = cur_doctor_degree; //---- special handling: the first year, the master & doctor degrees are too low, artificially increase them ---// if( info.prerun_year && info.game_year == 1 ) { //--- count the number of master & doctor students in this department ---// int masterCount=0, doctorCount=0; for( int i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; Student* stuPtr = operator[](i); if( stuPtr->student_level == MASTER ) masterCount++; else if( stuPtr->student_level == DOCTOR ) doctorCount++; } // divided by the average # of years to get a degree master_degree[THIS_YEAR] = int( (float) masterCount / 1.6f); doctor_degree [THIS_YEAR] = doctorCount/5; } //---- see design note 0919 section 6 -----// time_to_degree[BACHELOR_DEGREE][THIS_YEAR] = math.safe_divide(time_to_degree_cumm[BACHELOR_DEGREE], cur_bachelor_degree); time_to_degree[MASTER_DEGREE][THIS_YEAR] = math.safe_divide(time_to_degree_cumm[MASTER_DEGREE], cur_master_degree); time_to_degree[DOCTOR_DEGREE][THIS_YEAR] = math.safe_divide(time_to_degree_cumm[DOCTOR_DEGREE], cur_doctor_degree); //--- special case handling: smooth the graph for bachelor Time to Degree ---// fake_disp_time_to_degree[BACHELOR_DEGREE][THIS_YEAR] = m.fmax( time_to_degree[BACHELOR_DEGREE][THIS_YEAR], math.get_random_snd(4.3f, 0.07f) ); //-----------------------------------------// int curSize[DEGREE_TYPE_COUNT]; // new student count this year const char degMap[MAX_STUDENT_LEVEL] = { BACHELOR_DEGREE, -1, MASTER_DEGREE, DOCTOR_DEGREE, -1}; memset(curSize,0,sizeof(curSize)); for (int i=size(); i>0; i--) { if ( is_deleted(i) ) continue; Student* stuPtr = operator[](i); // assume called after next_trimester and then enrollment if ( stuPtr->year_in_program == 1 ) { char deg = degMap[stuPtr->student_level]; if (deg >= 0) curSize[deg]++; } } const float lamda[] = { 0.775f, 0.1f, 0.8f }; for (int y=0; y<DEGREE_TYPE_COUNT; y++) { //990408 ave_entering_class[y] = math.latency_func(lamda[y], (float) curSize[y], ave_entering_class[y]); //990408 dropout_rate[y][THIS_YEAR] = math.safe_divide((float)cur_dropout[y], ave_entering_class[y]); dropout_rate[y][THIS_YEAR] = (float) cur_dropout[y]; } //-----------------------------------------// cur_bachelor_degree = 0; // reset it, it will be incremented as students graduate cur_non_ug_bachelor_degree = 0; cur_master_degree = 0; cur_doctor_degree = 0; for (int y=0; y<DEGREE_TYPE_COUNT; y++) { time_to_degree_cumm[y] = 0; cur_dropout[y] = 0; last_year_dropout[y]=0; last_year_dropout[y+1]=0; last_year_degree[y]=0; last_year_degree[y+1]=0; } ave_time_to_graduation_for_ug = 0; }
//---------- Begin of function StudentArray::calc_student_performance -----------// //! void StudentArray::calc_student_performance() { shift_history(talent_academic, HISTORY_MONTH_COUNT); shift_history(talent_extracurricular, HISTORY_MONTH_COUNT); shift_history(talent_athletics, HISTORY_MONTH_COUNT); shift_history(satisfaction_academic, HISTORY_MONTH_COUNT); shift_history(satisfaction_student_life, HISTORY_MONTH_COUNT); shift_history(satisfaction_athletics, HISTORY_MONTH_COUNT); shift_history(satisfaction_overall, HISTORY_MONTH_COUNT); for (int d=0; d<DEGREE_TYPE_COUNT; d++) shift_history(talent_academic_all[d], HISTORY_MONTH_COUNT); shift_history(performance_academic_ug, HISTORY_MONTH_COUNT); //-----------------// Student *stuPtr; const char AVG_VAR_COUNT = 11; int total[AVG_VAR_COUNT]; int i, ugtStuCount=0, ugAllCount=0, stuCount = 0, docCount=0, masCount=0; memset(total, 0, sizeof(total)); for( i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; stuPtr = operator[](i); if ( stuPtr->student_level == UG_TRADITION ) { total[0] += stuPtr->talent_academic; total[1] += stuPtr->talent_extracurricular; total[2] += stuPtr->talent_athletics; total[3] += stuPtr->satisfaction_academic; total[4] += stuPtr->satisfaction_student_life; total[5] += stuPtr->satisfaction_athletics; total[6] += stuPtr->satisfaction_overall; ugtStuCount++; } if ( (stuPtr->student_level) == UG_TRADITION ) { total[7] += (int) stuPtr->academic_achievement; total[8] += stuPtr->talent_academic; //ugtCount++; } else if ( stuPtr->student_level == MASTER ) { total[9] += stuPtr->talent_academic; masCount++; } else if ( stuPtr->student_level == DOCTOR ) { total[10] += stuPtr->talent_academic; docCount++; } stuCount++; } if (!stuCount) return; if ( ugtStuCount ) { //## 071299 chea 1.12.1 talent_academic[THIS_MONTH] = char(total[0] / ugtStuCount); talent_extracurricular [THIS_MONTH] = char(total[1] / ugtStuCount); talent_athletics [THIS_MONTH] = char(total[2] / ugtStuCount); satisfaction_academic [THIS_MONTH] = char(total[3] / ugtStuCount); satisfaction_student_life [THIS_MONTH] = char(total[4] / ugtStuCount); satisfaction_athletics [THIS_MONTH] = char(total[5] / ugtStuCount); satisfaction_overall [THIS_MONTH] = char(total[6] / ugtStuCount); // talent_academic[THIS_MONTH] = char(total[0] / stuCount); // talent_extracurricular [THIS_MONTH] = char(total[1] / stuCount); // talent_athletics [THIS_MONTH] = char(total[2] / stuCount); // satisfaction_academic [THIS_MONTH] = char(total[3] / stuCount); // satisfaction_student_life [THIS_MONTH] = char(total[4] / stuCount); // satisfaction_athletics [THIS_MONTH] = char(total[5] / stuCount); // satisfaction_overall [THIS_MONTH] = char(total[6] / stuCount); } if ( ugtStuCount ) { performance_academic_ug[THIS_MONTH] = char(total[7] / ugtStuCount); talent_academic_all[BACHELOR_DEGREE][THIS_MONTH] = char(total[8] / ugtStuCount); } if ( masCount ) talent_academic_all[MASTER_DEGREE][THIS_MONTH] = char(total[9] / masCount); if ( docCount ) talent_academic_all[DOCTOR_DEGREE][THIS_MONTH] = char(total[10] / docCount); /* talent_academic talent_extracurricular talent_athletics satisfaction_academic satisfaction_student_life satisfaction_athletics */ }
//---------- Begin of function StudentArray::update_history -----------// void StudentArray::update_history(char update_flag) { //----- for calc performance indicator -----// // called before next day? // should this be put in player school Student *studentPtr; int i, sl; int studentCount[MAX_STUDENT_LEVEL]; memset(studentCount, 0, sizeof(studentCount)); memset(ave_satisfaction_student_life, 0, sizeof(ave_satisfaction_student_life)); for( i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; studentPtr = operator[](i); sl = studentPtr->student_level; err_when(sl<0 || sl>=MAX_STUDENT_LEVEL); if ( sl != UG_TRADITION ) continue; studentCount[sl]++; ave_satisfaction_student_life[sl] += studentPtr->satisfaction_student_life; } for (i=0; i<MAX_STUDENT_LEVEL; i++) { if ( studentCount[i] ) ave_satisfaction_student_life[i] /= studentCount[i]; else err_when( ave_satisfaction_student_life[i] != 0 ); } //----------------------------------------// PeerSchool *player; switch (update_flag) { case UPDATE_MONTH: calc_student_performance(); break; case UPDATE_TRIMESTER: break; case UPDATE_YEAR: calc_degree_awarded(); break; case UPDATE_ALL: // UPDATE_ALL: assumed called only once for each battle // update degree info for last year(97-98) player = school_res.player_peer_school; // since there's a bug in course selection, too few degrees awarded during game, hence the graphs are not "good" looking cur_bachelor_degree = player->total_bach_degrees / department_array.department_count; cur_master_degree = player->total_masters_and_prof_degree / department_array.department_count; cur_doctor_degree = player->total_doctoral_degrees / department_array.department_count; /* { // 990416 char y; int stuCount[MAX_STUDENT_LEVEL][MAX_GRADUATE_YEARS]; memset(stuCount, 0, sizeof(stuCount)); for (i=size(); i>0; i--) { if ( is_deleted(i) ) continue; Student* stuPtr = operator[](i); y = min(MAX_GRADUATE_YEARS, stuPtr->year_in_program); stuCount[stuPtr->student_level][y]++; } //--// cur_bachelor_degree = 0; cur_master_degree = 0; cur_doctor_degree = 0; for (char sl=0; sl<MASTER; sl++) for (i=0; i<MAX_GRADUATE_YEARS; i++) cur_bachelor_degree += int(player_school.grad_trans_prob[sl][i] * stuCount[sl][i]); sl = MASTER; for (i=0; i<MAX_GRADUATE_YEARS; i++) cur_master_degree += int(player_school.grad_trans_prob[sl][i] * stuCount[sl][i]); sl = DOCTOR; DepartmentInfo* deptInfo = department_res[department_array[department_recno]->department_id]; for (i=0; i<MAX_GRADUATE_YEARS; i++) cur_doctor_degree += int(deptInfo->doctor_graduate_trans_prob[i] * stuCount[sl][i]); sl = DISTANCE_LEARN; for (i=0; i<MAX_GRADUATE_YEARS; i++) cur_bachelor_degree += int(player_school.grad_trans_prob[UG_NONTRADITION][i] * stuCount[sl][i]); } */ update_history(UPDATE_MONTH); update_history(UPDATE_TRIMESTER); update_history(UPDATE_YEAR); //-----------// for (i=0; i<DEGREE_TYPE_COUNT; i++) { // see 0919 noets Q6. // from db time_to_degree[BACHELOR_DEGREE][THIS_YEAR] = 4.37f; // from db time_to_degree[MASTER_DEGREE][THIS_YEAR] = 1.05f; //## chea 281099 student no. time_to_degree[DOCTOR_DEGREE][THIS_YEAR] = player->doc_time_to_degree; /* dropout_rate[BACHELOR_DEGREE][THIS_YEAR] = 100-100*(player->target_grad_rate_sl[UG_TRADITION] / 100.0f + ( 1-player->target_grad_rate_sl[UG_TRADITION] / 100.0f ) * ( 1-0.9f )); // 0.9f: from db dropout_rate[MASTER_DEGREE][THIS_YEAR] = 100 - player->target_grad_rate_sl[MASTER]; dropout_rate[DOCTOR_DEGREE][THIS_YEAR] = 100 - player->target_grad_rate_sl[DOCTOR]; BUGHERE 990408 */ } break; default: err_here(); break; } }
//-------- Begin of function SpyArray::catch_spy ------// // // <int> spyPlace - either SPY_TOWN or SPY_FIRM // <int> spyPlacePara - town_recno or firm_recno // int SpyArray::catch_spy(int spyPlace, int spyPlacePara) { int nationRecno, totalPop; if( spyPlace == SPY_TOWN ) { Town* townPtr = town_array[spyPlacePara]; nationRecno = townPtr->nation_recno; totalPop = townPtr->population; } else if( spyPlace == SPY_FIRM ) { Firm* firmPtr = firm_array[spyPlacePara]; nationRecno = firmPtr->nation_recno; if( firmPtr->cast_to_FirmCamp() ) { FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp(); totalPop = firmCamp->soldier_count + (firmCamp->overseer_recno>0); } else if( firmPtr->cast_to_FirmWork() ) { FirmWork *firmWork = firmPtr->cast_to_FirmWork(); totalPop = firmWork->worker_count; } else if( firmPtr->cast_to_FirmTrain() ) { totalPop = firmPtr->cast_to_FirmTrain()->trainee_count; return 0; // don't catch spy } else if( firmPtr->cast_to_FirmInn() ) { totalPop = firmPtr->cast_to_FirmInn()->inn_unit_count; return 0; // don't catch spy } else if( firmPtr->cast_to_FirmMarket() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmMonsterTrain() ) { totalPop = firmPtr->cast_to_FirmMonsterTrain()->trainee_count; return 0; // don't catch spy } else if( firmPtr->cast_to_FirmMonsterAlchemy() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmLishorr() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmMonsterFortress() ) { FirmMonsterFortress *firmMonsterFortress = firmPtr->cast_to_FirmMonsterFortress(); totalPop = firmMonsterFortress->archer_count + firmMonsterFortress->extra_builder_count; } else if( firmPtr->cast_to_FirmAnimal() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmIncubator() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmMagic() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmOffensive() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmOffensive2() ) { totalPop = 0; return 0; } else { err_here(); totalPop = 0; } } else err_here(); //--- calculate the total of anti-spy skill in this town ----// int enemySpyCount=0, counterSpySkill=0; Spy* spyPtr; int techLevel = 0; if( nationRecno ) techLevel = tech_res[TECH_COUNTER_SPY]->get_nation_tech_level(nationRecno); int i; for( i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; spyPtr = spy_array[i]; if( spyPtr->spy_place == spyPlace && spyPtr->spy_place_para == spyPlacePara ) { if( spyPtr->true_nation_recno == nationRecno ) counterSpySkill += spyPtr->spy_skill + spyPtr->spy_skill * techLevel / 2; else enemySpyCount++; } } //----- if all citizens are enemy spies ----// if( enemySpyCount == totalPop ) return 0; err_when( enemySpyCount > totalPop ); //-------- try to catch enemy spies now ------// for( i=spy_array.size() ; i>0 ; i-- ) { if( spy_array.is_deleted(i) ) continue; spyPtr = spy_array[i]; if( spyPtr->action_mode == SPY_IDLE ) // it is very hard to get caught in sleep mode continue; if( spyPtr->spy_place == spyPlace && spyPtr->spy_place_para == spyPlacePara && spyPtr->true_nation_recno != nationRecno ) // doesn't get caught in sleep mode { int escapeChance = 100 + spyPtr->spy_skill - counterSpySkill; escapeChance = max( spyPtr->spy_skill/10, escapeChance ); if( m.random(escapeChance) == 0 ) { spyPtr->get_killed(); // only catch one spy per calling return 1; } } } return 0; }
//--------- Begin of function FirmArray::process ---------// // // Process all firm in firm_array for action and movement for next frame // // Return : 1 - all firm in the FirmArray has been processed // 0 - only some has been processed, not all // int FirmArray::process() { int i; Firm *firmPtr; // ####### begin Gilbert 19/11 ######// if( sys.day_frame_count == 0 ) { god_res.update_prayer_count(); // count no. of prayer of each god, each nation } // ####### end Gilbert 19/11 ######// //----- each time process some firm only ------// for( i=1 ; i<=size() ; i++ ) { firmPtr = (Firm*) get_ptr(i); if( !firmPtr ) // the firm has been deleted continue; err_when(firmPtr->firm_recno!=i); //-------- system yield ---------// if( i%20==1 ) sys.yield(); #if defined(ENABLE_LOG) String logStr; logStr = "begin process firm "; logStr += firmPtr->firm_recno; logStr += " nation="; logStr += firmPtr->nation_recno; LOG_MSG(logStr); #endif if(i==50) { FirmMarket *mPtr = (FirmMarket*) firmPtr; MarketGoods *marketGoods = mPtr->market_goods_array; marketGoods++; if(marketGoods->stock_qty) int debug = 0; } // ##### begin Gilbert 18/5 ########// //-------- process visibility -----------// if( i%FRAMES_PER_DAY == int(sys.frame_count%FRAMES_PER_DAY) ) // only process each firm once per day { // before under construction checking if( firmPtr->explore_for_player() ) { world.visit( firmPtr->loc_x1, firmPtr->loc_y1, firmPtr->loc_x2, firmPtr->loc_y2, EXPLORE_RANGE-1 ); } } // ##### begin Gilbert 18/5 ########// //------ if the firm is under construction ------// if( firmPtr->under_construction ) { LOG_MSG(" process_construction"); firmPtr->process_construction(); LOG_MSG(m.get_random_seed() ); continue; } //------ if the firm is being upgrade ------// if( firmPtr->upgrading_firm_id ) { if( firmPtr->process_upgrade() ) continue; } // ###### begin Gilbert 4/1 #######// firmPtr->process(); // ###### end Gilbert 4/1 #######// //--------- process and process_ai firms ----------// if( i%FRAMES_PER_DAY == int(sys.frame_count%FRAMES_PER_DAY) ) // only process each firm once per day { #ifdef DEBUG unsigned long profileStartTime = m.get_time(); #endif // //-------- process visibility -----------// // // if( firmPtr->explore_for_player() ) // { // world.visit( firmPtr->loc_x1, firmPtr->loc_y1, firmPtr->loc_x2, firmPtr->loc_y2, EXPLORE_RANGE-1 ); // } LOG_MSG(" next_day"); firmPtr->next_day(); LOG_MSG(m.get_random_seed() ); #ifdef DEBUG firm_profile_time += m.get_time() - profileStartTime; #endif //-- if the hit points drop to zero, the firm should be deleted --// if( firmPtr->hit_points <=0 ) { se_res.sound( firmPtr->center_x, firmPtr->center_y, 1, 'F', firmPtr->firm_id, "DEST" ); del_firm( firmPtr->firm_recno ); continue; } //--------- process AI ------------// #ifdef DEBUG if( config.disable_ai_flag==0 && firmPtr->is_ai ) #else if( firmPtr->is_ai ) #endif { LOG_MSG(" process_common_ai"); firmPtr->process_common_ai(); LOG_MSG(m.get_random_seed() ); #ifdef DEBUG unsigned long profileAiStartTime = m.get_time(); #endif LOG_MSG(" process_ai"); firmPtr->process_ai(); LOG_MSG(m.get_random_seed()); #ifdef DEBUG firm_ai_profile_time += m.get_time() - profileAiStartTime; #endif if( is_deleted(i) ) // the firm may have been deleted in process_ai() continue; } } //-------- process animation ---------// LOG_MSG(" process_animation"); firmPtr->process_animation(); LOG_MSG( m.get_random_seed() ); //-------- process monster firm ---------// LOG_MSG(" process_animation"); firmPtr->process_monster_firm(); LOG_MSG( m.get_random_seed() ); } return 0; }