void Text::drag(const Event& event) { if (event.left_is_down()) { unsigned line = selection_.line2(); unsigned column = selection_.column2(); if (snap(event, line, column) && ((line > selection_.line1()) || ((line == selection_.line1()) && (column >= selection_.column1())))) { TextRegion area; if (selection_.line2() < line) { area.line1(selection_.line2()); area.column1(selection_.column2()); area.line2(line); area.column2(column); } else { area.line1(line); area.column1(column); area.line2(selection_.line2()); area.column2(selection_.column2()); } selection_.line2(line); selection_.column2(column); repair(); damage(area); repair(); } } else if (event.right_is_down()) { TextLocation old = insertion_; if (snap(event, insertion_.line_, insertion_.column_)) { repair(); damage(old); repair(); damage(insertion_); repair(); } } }
void LevelDB::open(StepFunction stepF, MessageFunction messageF) throw(DbException) { bool forceRepair = Util::fileExists(getRepairFlag()); if (forceRepair) { repair(stepF, messageF); File::deleteFile(getRepairFlag()); } auto ret = leveldb::DB::Open(defaultOptions, Text::fromUtf8(dbPath), &db); if (!ret.ok()) { if (ret.IsIOError()) { // most likely there's another instance running or the permissions are wrong messageF(STRING_F(DB_OPEN_FAILED_IO, getNameLower() % Text::toUtf8(ret.ToString()) % APPNAME % dbPath % APPNAME), false, true); throw DbException(); } else if (!forceRepair) { // the database is corrupted? messageF(STRING_F(DB_OPEN_FAILED_REPAIR, getNameLower() % Text::toUtf8(ret.ToString()) % APPNAME), false, false); repair(stepF, messageF); // try it again ret = leveldb::DB::Open(defaultOptions, Text::fromUtf8(dbPath), &db); } } if (!ret.ok()) { messageF(STRING_F(DB_OPEN_FAILED, getNameLower() % Text::toUtf8(ret.ToString()) % APPNAME), false, true); throw DbException(); } }
/* --------------------------------- Jacobi ---------------------------------- */ void jacobi( Matrix *m, int num_of_file ) { Matrix *eigen_values = m , *eigen_vectors = generateIdentityMatrix( m->height ) , old ; Coordinate position; char fname[256]; double theta; int count = 0; while(1) { position = locateMaxValue( eigen_values ); if ( position.value < THRESHOLD ) break; printf("%d回目 : %lf\n", count++, position.value ); theta = calcAngle( m, position ); eigen_values = rotate( eigen_values, position, theta ); eigen_vectors = append( eigen_vectors, position, theta ); repair( eigen_values ); } sprintf( fname, "EigenValues%02d.txt", num_of_file ); printMatrixToFile( fname, eigen_values ); sprintf( fname, "EigenVectors%02d.txt", num_of_file ); printMatrixToFile( fname, eigen_vectors ); }
void GeneticClass::Crossover(int parent1, int parent2, vector<int> &child1, vector<int> &child2){ int child1Size, child2Size, cutpoint1, cutpoint2; int parsiz1 = chromosom[parent1].size(); int parsiz2 = chromosom[parent2].size(); do { cutpoint1 = rand() % chromosom[parent1].size(); cutpoint2 = rand() % chromosom[parent2].size(); child1Size = cutpoint1 + chromosom[parent2].size() - cutpoint2; child2Size = cutpoint2 + chromosom[parent1].size() - cutpoint1; } while ((child2Size > GraphClass::vertex) || (child1Size > GraphClass::vertex)); child1.resize(GraphClass::vertex); child2.resize(GraphClass::vertex); copy(chromosom[parent1].begin(), chromosom[parent1].begin() + cutpoint1, child1.begin()); copy(chromosom[parent2].begin() + cutpoint2, chromosom[parent2].end(), child1.begin() + cutpoint1); copy(chromosom[parent2].begin(), chromosom[parent2].begin() + cutpoint2, child2.begin()); copy(chromosom[parent1].begin() + cutpoint1, chromosom[parent1].end(), child2.begin() + cutpoint2); child1.resize(cutpoint1 + chromosom[parent2].size() - cutpoint2); child2.resize(cutpoint2 + chromosom[parent1].size() - cutpoint1); repair(child1, child2); }
int main() { char str[SIZE]= {}, str1[SIZE]= {}, str2[SIZE]= {}, str_buf[SIZE]= {}; char* p=NULL;//указатель на знак в строке char signs[]="+-*/"; char sgn; int len, len1, len2; double dig1, dig2; cout<<"\tКалькулятор, введите выражение\n"; scanf("%s", &str); len=strlen(str);//общая длина строки //убираем из строки все левые знаки repair(str, str_buf, len); //цикл ищет знак действия if(p=strpbrk(str_buf, signs)) { //функция ищет в строке str_buf первое вхождение любого символа из строки signs, возвращая указатель на это вохождение sgn=*p;//разыменовываем указатель на занк и записываем сам знак действия в перменную sgn } //проверка наличия знака действия if(p!=NULL) { len2=strlen(p)-1;//длина строки после знака + - * / это и будет длина второго числа len1=len-len2-1;//длина первого числа strncpy(str1,str_buf,len1);//копирование строки с первой цифрой strncpy(str2, p+1 ,len2);//копирование строки со второй цифрой dig1=atof(str1); dig2=atof(str2); calculate(dig1, dig2, sgn); } else { cout<<"\tВы пропустили ввод знака действия, повторите ввод\n"; } return 0; }
void process(FILE *fp) { char buf[BUFSIZ]; char *cp; int count; while (fgets(buf, sizeof buf, fp) != NULL) { Line++; cp = strchr(buf, '@'); if (cp == NULL) { fputs(buf, stdout); continue; } do { count = isref(cp); if (count == 0) { cp++; cp = strchr(cp, '@'); if (cp == NULL) { fputs(buf, stdout); goto next; } continue; } /* got one */ repair(buf, cp, count); break; } while (cp != NULL); next: ; } }
void repair(int index) { if(index==1)return; int father=index>>1; if(graf[kopiec[father]].minkoszt>graf[kopiec[index]].minkoszt) { swap(index,father); repair(father); } }
void repair(node n) { if (n->left != NULL) { n->left->x = n->x - n->r / 2; n->left->y = n->y + 30; n->left->r = n->r / 2; repair(n->left); } if (n->right != NULL) { n->right->x = n->x + n->r / 2; n->right->y = n->y + 30; n->right->r = n->r / 2; repair(n->right); } }
void insert(int key) { Node* n = add(key); repair(n); // dump(_root); cout << endl; check(_root); checkColor(_root); }
void Text::backspace() { if ((insertion_.column_ <= 0) && (insertion_.line_ > 0)) { --insertion_.line_; if (insertion_.line_ >= text_->Height()) { insertion_.column_ = 0; } else { // --- update insertion point --- int index = text_->LineIndex(insertion_.line_); //insertion_.column_ = text_->LineOffset(index); // ---- delete the character ---- int delIndex = text_->EndOfLine(index); insertion_.column_ = delIndex - index; text_->Delete(delIndex, 1); } needWidth_ = true; notify_all(); damage(); // !!! could only damage from insertion to end of window } else if (insertion_.column_ > 0) { int oldWidth = text_->Width(); int index = text_->LineIndex(insertion_.line_); // ---- delete the text --- text_->Delete(index + insertion_.column_ - 1, 1); --insertion_.column_; if (text_->Width() != oldWidth) { needWidth_ = true; notify_all(); } repair(); damage(insertion_); repair(); } }
bool T64File::readFromBuffer(const uint8_t *buffer, size_t length) { if (!AnyC64File::readFromBuffer(buffer, length)) return false; // Some T64 archives contain incosistencies. We fix them asap (void)repair(); return true; }
void piramidalSorting(Workers *mass, int N,Ptf cmp, int order) { build (mass, N,cmp, order); for ( int i=N-1; i>=1; --i) { swap(mass[0],mass[i]); --N; repair (mass, 0, N,cmp, order); } }
void Text::insertChars(const char* txt, unsigned count) { TextBuffer text(txt, count, count); // ---- insert the text info the buffer ---- text_->Insert(text_->LineIndex(insertion_.line_) + insertion_.column_, txt, count); dirty(true); if (text.Height() > 1) { TextRegion area; area.line1(insertion_.line_); area.column1(0); area.line2(insertion_.line_ + text.Height() - 1); area.column2(0); insertion_.line_ += text.Height() - 1; insertion_.column_ = 0; damage(); // !!! could only damage from insertion to end of window for (unsigned i = 0; i < text.Height(); ++i) { width_ = Math::max(width_, width(text.getNth(i))); } notify_all(); } else { TextLocation old = insertion_; insertion_.column_ += count; Coord newWidth = width(text_->getNth(insertion_.line_)); if (newWidth >= width_) { width_ = Math::max(width_, newWidth); notify_all(); } repair(); damage(old); repair(); } }
void Text::press(const Event& event) { // if (event.pointer_button() == Event::left) { context_key(0); if (event.pointer_button() != Event::middle) { TextRegion old = selection_; unsigned line1 = selection_.line1(); unsigned column1 = selection_.column1(); snap(event, line1, column1); selection_.line1(line1); selection_.column1(column1); selection_.line2(line1); selection_.column2(column1); repair(); damage(old); repair(); // } else if (event.pointer_button() == Event::right) { TextLocation oldi = insertion_; snap(event, insertion_.line_, insertion_.column_); repair(); damage(oldi); repair(); damage(insertion_); repair(); } else if (event.pointer_button() == Event::middle) { unsigned line = 0; unsigned column = 0; snap(event, line, column); for (int i = 0; i < annotation_.count(); ++i) { TextAnnotation& a = *annotation_.item(i); if (a.line1() <= line && line <= a.line2()) { if (!((a.line1() == line && a.column1() > column) || (a.line2() == line && a.column2() < column))) { a.execute(); break; } } } } }
void Text::eraseLine() { if (insertion_.line_ < text_->Height()) { int oldWidth = text_->Width(); int index0 = text_->LineIndex(insertion_.line_); int index1 = text_->BeginningOfNextLine(index0); // ---- delete the text ---- text_->Delete(index0, index1 - index0); // --- check for width change ---- if (text_->Width() != oldWidth) { needWidth_ = true; notify_all(); } } insertion_.column_ = 0; repair(); damage(insertion_); repair(); }
void rotate_left(GtkWidget *darea, rbtree t, node n) { if (rotation) print_left_arrow(darea, n->right->x, n->right->y, 20); node R = n->right; replace_node(t, n, R); n->right = R->left; if (R->left != NULL) R->left->parent = n; R->left = n; n->parent = R; repair(R); }
void rotate_right(GtkWidget *darea, rbtree t, node n) { if (rotation) print_right_arrow(darea, n->left->x, n->left->y, 20); node L = n->left; replace_node(t, n, L); n->left = L->right; if (L->right != NULL) L->right->parent = n; L->right = n; n->parent = L; repair(L); }
bool mpkg::repair(string fname) { SQLRecord sqlSearch; sqlSearch.addField("package_name", &fname); sqlSearch.addField("package_installed", 1); PACKAGE_LIST p; get_packagelist(&sqlSearch, &p); if (p.size()==1) { return repair(p.get_package(0)); } else { say(_("Cannot repair or reinstall package %s: it is not installed\n"), fname.c_str()); return false; } }
struct rcps_population *new_population(struct rcps_solver *s, struct rcps_problem *problem) { struct rcps_population *pop; struct rcps_individual *ind; int i; int lcount = 0; struct rcps_fitness best_fitness; best_fitness.group = FITNESS_MAX_GROUP; best_fitness.weight = 0; pop = (struct rcps_population*)malloc(sizeof(struct rcps_population)); pop->individuals = slist_new(individual_cmp); pop->size = 0; for (i = 0; i < s->pop_size; i++) { ind = (struct rcps_individual*)malloc(sizeof(struct rcps_individual)); initial(problem, &ind->genome); if (repair(problem, &ind->genome)) { struct rcps_phenotype *pheno = decode(s, problem, &ind->genome); ind->fitness = fitness(problem, &ind->genome, pheno); if (rcps_fitness_cmp(&(ind->fitness), &best_fitness) < 0) { best_fitness = ind->fitness; } add_individual(ind, pop); } else { // XXX somehow track this and abort with an error if we never add a // valid individual free(ind->genome.schedule); free(ind->genome.modes); free(ind->genome.alternatives); free(ind); i--; } if (s->progress_callback) { if (i >= (lcount + s->cb_steps)) { if (s->progress_callback(0, best_fitness, s->cb_arg)) { return pop; } lcount = i; } } } return pop; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); View w; Model m; controller c(m); c.setplugdir(argv[0]); QObject::connect(&w, SIGNAL(ImageUpload(QString)), &c, SLOT(loadImage(QString))); QObject::connect(&m, SIGNAL(SayAboutEvent(string)), &w, SLOT(Log(string))); QObject::connect(&w, SIGNAL(on_repair_triggered()), &c, SLOT(repair())); QObject::connect(&m, SIGNAL(ResultsOfWork(tuple<int,vector<shared_ptr<IObject> >,Image>)), &w, SLOT(print_results(tuple<int,vector<shared_ptr<IObject> >,Image>))); QObject::connect(&m, SIGNAL(Plugindone(Image)), &w, SLOT(refreshImage(Image))); QObject::connect(&w, SIGNAL(on_refresh_plugins_triggered()), &c, SLOT(refresh_plugins())); QObject::connect(&m, SIGNAL(newPlugin(const char*,int)), &w, SLOT(addPlugin(const char*,int))); QObject::connect(&w, SIGNAL(applyPlugin(int)), &c, SLOT(PluginCall(int))); QObject::connect(&m, SIGNAL(Pluginsdelete()), &w, SLOT(erasePluginAct())); w.setPlugin(); w.show(); return a.exec(); }
void repair (Workers *mass,int i, int N,Ptf cmp, int order) { int l=2*i+1; int r=2*i+2; int larg=i; if ( order==1) { if(l<N && cmp(mass[l],mass[i])>0)larg=l; if(r<N && cmp(mass[r], mass[larg])>0)larg=r; } else { if(l<N && cmp(mass[l],mass[i])<0)larg=l; if(r<N && cmp(mass[r], mass[larg])<0)larg=r; } if(larg!=i) { swap(mass[larg],mass[i]); repair(mass,larg,N,cmp,order); } }
/* * worker function that checks and repairs incosistency errors */ void chkerr(struct direntry* dirent, char* filename, uint8_t *image_buf, struct bpb33* bpb) { int num_clusters = count_clusters(dirent, image_buf, bpb); uint32_t entry_size = getulong(dirent->deFileSize); // remove empty files if (entry_size == 0) { if (dirent->deAttributes == ATTR_NORMAL && dirent->deName[0] != SLOT_EMPTY && dirent->deName[0] != SLOT_DELETED) { printf("Empty file found... removing. \n\n"); dirent->deName[0] = SLOT_DELETED; } } // fix size inconsistencies if (num_clusters != 0 && entry_size < num_clusters - 512 ) { // take entry to be right printf("OUT OF BOUNDS: \n\tFilename: %s \n\t\tsize in directory entry: %d, size in FAT chain: %d.) \n\n", filename, entry_size, num_clusters); repair(dirent, image_buf, bpb, entry_size); } else if (entry_size > num_clusters) { // take FAT to be right printf("OUT OF BOUNDS: \n\tFilename: %s \n\t\tsize in directory entry: %d, size in FAT chain: %d \n\n", filename, entry_size, num_clusters); putulong(dirent->deFileSize, num_clusters); } }
/* --------------------------------- Jacobi ---------------------------------- */ void jacobi( Matrix *m, int num_of_file ) { Matrix *eigen_values = m , *eigen_vectors = generateIdentityMatrix( m->height ) ; Coordinate position; Trigonometry angle; int count = 0 , not_change = 0 ; double previous = 0; while(1) { position = locateMaxValue( eigen_values ); if ( position.value < THRESHOLD ) break; if ( position.value == previous ) not_change++; else not_change = 0; if ( not_change == 100 ) break; previous = position.value; // printf("%d回目 : %lf\n", count++, position.value ); angle = calcAngle( eigen_values, position ); rotate( eigen_values, position, angle ); append( eigen_vectors, position, angle ); repair( eigen_values ); } printEigen( eigen_values, eigen_vectors, num_of_file ); }
addtocox(long id, copiec & c) { c.incox++; c.cox[c.incox]=id; repair(c, c.incox); }
void opTick() { repair(10); addop(L_SHIELDS, 10); }
static void test_repair(struct s_sndfile *sf_out, codec_id_t cid, repair_id_t repair_type, struct s_sndfile *sf_in) { codec_state *encoder; struct s_codec_state_store *decoder_states; media_data *md_prev, *md_cur; coded_unit *cu; int32_t consec_lost = 0, total_lost, total_done; const codec_format_t *cf; uint16_t i; repair_id_t repair_none; for (i = 0; i < repair_get_count(); i++) { const repair_details_t *rd; rd = repair_get_details(i); if (strcasecmp(rd->name, "none") == 0) { repair_none = rd->id; break; } } codec_encoder_create(cid, &encoder); codec_state_store_create(&decoder_states, DECODER); cf = codec_get_format(cid); /* Read and write one unit to kick off with */ media_data_create(&md_cur, 1); read_and_encode(md_cur->rep[0], encoder, sf_in); decode_and_write(sf_out, decoder_states, md_cur); /* Initialize next reading cycle */ md_prev = md_cur; md_cur = NULL; media_data_create(&md_cur, 1); total_lost = total_done = 0; while(read_and_encode(md_cur->rep[0], encoder, sf_in)) { total_done++; if (do_drop()) { total_lost++; media_data_destroy(&md_cur, sizeof(media_data)); media_data_create(&md_cur, 0); cu = (coded_unit*)block_alloc(sizeof(coded_unit)); assert(cu != NULL); memset(cu, 0, sizeof(coded_unit)); /* Loss happens - invoke repair */ if (repair_type != repair_none) { cu->id = cid; repair(repair_type, consec_lost, decoder_states, md_prev, cu); } else { /* Create a silent unit */ cu->id = codec_get_native_coding((uint16_t)cf->format.sample_rate, (uint16_t)cf->format.channels); cu->state = NULL; cu->state_len = 0; cu->data = (u_char*)block_alloc(cf->format.bytes_per_block); cu->data_len = cf->format.bytes_per_block; memset(cu->data, 0, cu->data_len); } /* Add repaired audio to frame */ md_cur->rep[md_cur->nrep] = cu; md_cur->nrep++; consec_lost++; } else { consec_lost = 0; } decode_and_write(sf_out, decoder_states, md_cur); media_data_destroy(&md_prev, sizeof(media_data)); md_prev = md_cur; md_cur = NULL; media_data_create(&md_cur, 1); } printf("# Dropped %d frames out of %d (%f loss %%)\n", total_lost, total_done, 100.0 * total_lost / (double)total_done); media_data_destroy(&md_cur, sizeof(media_data)); media_data_destroy(&md_prev, sizeof(media_data)); codec_encoder_destroy(&encoder); codec_state_store_destroy(&decoder_states); }
/** * The settle function computes the steady state nearest the initial * conditions. */ void SteadyState::settle( bool forceSetup ) { #ifdef USE_GSL gsl_set_error_handler_off(); if ( !isInitialized_ ) { cout << "Error: SteadyState object has not been initialized. No calculations done\n"; return; } if ( forceSetup || isSetup_ == 0 ) { setupSSmatrix(); } // Setting up matrices and vectors for the calculation. unsigned int nConsv = numVarPools_ - rank_; double * T = (double *) calloc( nConsv, sizeof( double ) ); unsigned int i, j; Id ksolve = Field< Id >::get( stoich_, "ksolve" ); struct reac_info ri; ri.rank = rank_; ri.num_reacs = nReacs_; ri.num_mols = numVarPools_; ri.T = T; ri.Nr = Nr_; ri.gamma = gamma_; ri.stoich = stoich_; ri.nVec = LookupField< unsigned int, vector< double > >::get( ksolve,"nVec", 0 ); ri.convergenceCriterion = convergenceCriterion_; // Fill up boundary condition values if ( reassignTotal_ ) { // The user has defined new conservation values. for ( i = 0; i < nConsv; ++i ) T[i] = total_[i]; reassignTotal_ = 0; } else { for ( i = 0; i < nConsv; ++i ) for ( j = 0; j < numVarPools_; ++j ) T[i] += gsl_matrix_get( gamma_, i, j ) * ri.nVec[ j ]; total_.assign( T, T + nConsv ); } vector< double > repair( numVarPools_, 0.0 ); for ( unsigned int j = 0; j < numVarPools_; ++j ) repair[j] = ri.nVec[j]; int status = iterate( gsl_multiroot_fsolver_hybrids, &ri, maxIter_ ); if ( status ) // It failed. Fall back with the Newton method status = iterate( gsl_multiroot_fsolver_dnewton, &ri, maxIter_ ); status_ = string( gsl_strerror( status ) ); nIter_ = ri.nIter; if ( status == GSL_SUCCESS ) { solutionStatus_ = 0; // Good solution LookupField< unsigned int, vector< double > >::set( ksolve,"nVec", 0, ri.nVec ); classifyState( T ); /* * Should happen in the ss_func. for ( i = 0; i < numVarPools_; ++i ) s_->S()[i] = gsl_vector_get( op( solver->x ), i ); */ } else { cout << "Warning: SteadyState iteration failed, status = " << status_ << ", nIter = " << nIter_ << endl; // Repair the mess for ( unsigned int j = 0; j < numVarPools_; ++j ) ri.nVec[j] = repair[j]; solutionStatus_ = 1; // Steady state failed. LookupField< unsigned int, vector< double > >::set( ksolve,"nVec", 0, ri.nVec ); } // Clean up. free( T ); #endif }
double ImuInterface::read() { int16_t x = (((int16_t)wiringPiI2CReadReg8(handle, i2c_register+1) << 8) | wiringPiI2CReadReg8(handle, i2c_register)) & 0xFFFF; x/= 16; return repair(x, 360, 2048); }
void main (int argc, char **argv) { char fname[1024]; FILE *Tf,*Rf,*Cf; int i,len; struct stat s; if ((argc < 2) || (argc > 3)) { fprintf (stderr,"Usage: %s <filename> [<ratio-break-repair [def=0.0 = no-break]>]\n" "Compresses <filename> with repair and creates " "<filename>.ext compressed files\n" "This is a version for sequences of integers\n\n", argv[0]); exit(1); } if (argc==3) { CORTE_REPAIR = atof(argv[2]); printf("\n CORTE_REPAIR set to %2.15f\n", CORTE_REPAIR); } else printf("\n CORTE_REPAIR set to %1.1f: Repair is not broken up to the end\n", CORTE_REPAIR); if (stat (argv[1],&s) != 0) { fprintf (stderr,"Error: cannot stat file %s\n",argv[1]); exit(1); } len = s.st_size/sizeof(int); Tf = fopen (argv[1],"r"); if (Tf == NULL) { fprintf (stderr,"Error: cannot open file %s for reading\n",argv[1]); exit(1); } C = (void*)malloc(len*sizeof(int)); if (fread(C,sizeof(int),len,Tf) != len) { fprintf (stderr,"Error: cannot read file %s\n",argv[1]); exit(1); } fclose(Tf); prepare (len); strcpy(fname,argv[1]); strcat(fname,".R"); Rf = fopen (fname,"w"); if (Rf == NULL) { fprintf (stderr,"Error: cannot open file %s for writing\n",fname); exit(1); } if (repair(Rf) != 0) { fprintf (stderr,"Error: cannot write file %s\n",fname); exit(1); } if (fclose(Rf) != 0) { fprintf (stderr,"Error: cannot close file %s\n",fname); exit(1); } strcpy(fname,argv[1]); strcat(fname,".C"); Cf = fopen (fname,"w"); if (Cf == NULL) { fprintf (stderr,"Error: cannot open file %s for writing\n",fname); exit(1); } i = 0; while (i<u) { if (fwrite(C+i,sizeof(int),1,Cf) != 1) { fprintf (stderr,"Error: cannot write file %s\n",fname); exit(1); } i++; if ((i < u) && (C[i] < 0)) i = -C[i]-1; } if (fclose(Cf) != 0) { fprintf (stderr,"Error: cannot close file %s\n",fname); exit(1); } fprintf (stderr,"RePair succeeded\n\n"); fprintf (stderr," Original ints: %i\n",len); fprintf (stderr," Number of rules: %i\n",n-alph); fprintf (stderr," Final sequence length: %i\n",c); fprintf (stderr," Compression ratio: %0.2f%%\n", (2.0*(n-alph)+c)*(float)blog(n-1)/(float)(len*blog(alph-1))*100.0); fprintf (stderr," Compression ratio: %0.2f%%\n", 100.0*c/INI_c); exit(0); }
void NeutralSystem::special() { System::special(); utilities::clear_display(); // always an ambush FightEvent fe(player, 5, 3); fe.run(); utilities::wait_for_user(); utilities::clear_display(); // game is over if (player->is_dead()) return; // 15% chance of finding money if (rand() % 100 < 15) { MonetaryEvent me(player); me.run(); utilities::wait_for_user(); utilities::clear_display(); } // 15% chance of being taxed if (rand() % 100 < 15) { TaxEvent te(player); te.run(); utilities::wait_for_user(); } // user done with menu bool done = false; // user already asked for info? bool asked = false; while (!done) { utilities::clear_display(); make_menu(); int num_ops = static_cast<int>(system_menu.get_num_options()); system_menu.display(); std::cout << "What would you like to do?\n"; int choice = utilities::get_valid_int_in_range(1, num_ops); utilities::clear_display(); std::string map_header = std::string("========== Map - Current System: ") + player->get_cur_system()->get_name() + " ==========\n\n"; switch (choice) { case 1: done = true; break; case 2: player->print_status("========== Status ==========\n\n"); break; case 3: std::cout << map_header; view_map(); break; case 4: open_store(); break; case 5: sell(); break; case 6: refuel(); break; case 7: repair(); break; case 8: buy_ship(); break; case 9: { if (!asked) { ask_info(); asked = true; } else std::cout << "You have already gotten all the information you can get right now!\n\n"; break; } default: jump_to(choice); done = true; // wants to jump } utilities::wait_for_user(); } }