/* Display results */ static void display_results(dyno_result *results, int nb) { int i; int max_power_i = 0; int max_power = 0; int max_torque_i = 0; int max_torque = 0; for (i=0; i<nb; i++) { printf("%d:\tRPM=%d\t\tpower=%d W (%d ch)\ttorque=%d Nm\n", i, results[i].rpm, results[i].power, results[i].power_ch, results[i].torque); if (results[i].power > max_power) { max_power = results[i].power; max_power_i = i; } if (results[i].torque > max_torque) { max_torque = results[i].torque; max_torque_i = i; } if (((i+1) % 22) == 0) { wait_enter("Press ENTER to continue... "); } } printf("\n"); printf("Max power : %d ch (at %d RPM)\n", results[max_power_i].power_ch, results[max_power_i].rpm); printf("Max torque : %d Nm (at %d RPM)\n", results[max_torque_i].torque, results[max_torque_i].rpm); printf("\n"); }
/*! \brief Give the bounded area a new background tile number * * \param box - Which box to assign the value to */ void rename_bound_tile (s_bound *box) { int response, done; int selected_tile = 0; make_rect (double_buffer, 2, 32); sprintf (strbuf, "Tile: %d", box->btile); print_sfont (6, 6, strbuf, double_buffer); print_sfont (6, 12, ">", double_buffer); done = 0; while (!done) { blit2screen (); response = get_line (12, 12, strbuf, 4); /* If the user hits ESC, break out of the function entirely */ if (response == 0) return; /* Make sure this line isn't blank */ if (strlen (strbuf) > 0) { selected_tile = atoi (strbuf); /* Make sure the value is valid */ if (selected_tile < 0 || selected_tile >= ICONSET_SIZE * max_sets) { sprintf (strbuf, "Invalid tile: %d", selected_tile); cmessage (strbuf); wait_enter (); } else { done = 1; } } } box->btile = selected_tile; } /* rename_bound_tile () */
/* Display graphs */ static void display_graphs(dyno_result *results, int nb) { int row, col, step; int max_power_i = 0; int max_power = 0; int max_torque_i = 0; int max_torque = 0; /* Detect maximums */ for (col=0; col<nb; col++) { if (results[col].power > max_power) { max_power = results[col].power; max_power_i = col; } if (results[col].torque > max_torque) { max_torque = results[col].torque; max_torque_i = col; } } /* 80 columns max */ step = (nb / 80) + 1; /* Displaying torque */ printf("Torque :\n"); for (row=DYNO_GRAPH_HEIGHT-1; row>=0; row--) { for (col=0; col<nb; col+=step) { if (results[col].torque * DYNO_GRAPH_HEIGHT > results[max_torque_i].torque * row) { printf("*"); } else { printf(" "); } } printf("\n"); } printf("\n"); /* Pause */ wait_enter("Press ENTER to continue... "); printf("\n"); /* Displaying power */ printf("Power :\n"); for (row=DYNO_GRAPH_HEIGHT-1; row>=0; row--) { for (col=0; col<nb; col+=step) { if (results[col].power * DYNO_GRAPH_HEIGHT > results[max_power_i].power * row) { printf("*"); } else { printf(" "); } } printf("\n"); } printf("\n"); }
int k2pdfopt_usage(void) { int nl; nl=get_ttyrows(); if (nl < 20) nl=20; prlines(usageintro,nl-4); if (wait_enter()<0) return(0); prlines(usageenv,nl-1); if (wait_enter()<0) return(0); if (!prcmdopts(k2pdfopt_options,nl)) return(0); return(1); }
int main() { clear_screen(); copy_file(INPUT_FILE, OUTPUT_FILE); write2console(OUTPUT_FILE); write2printer(OUTPUT_FILE); write2serial(OUTPUT_FILE); truncate_file(OUTPUT_FILE); write_midi(); wait_enter(); return 0; }
/* Display given measures */ static void display_measures(dyno_measure *measures, int nb_measures) { int i; for (i=0; i<nb_measures; i++) { printf("measure %d:\t%3.3f s. \tRPM: %d\t%3.3f m/s\t%3.2f km/h\n", (i+1), measures[i].millis/1000.0, measures[i].rpm, dyno_get_speed_from_rpm(measures[i].rpm)/1000.0, dyno_get_speed_from_rpm(measures[i].rpm)*3.6/1000.0); if (((i+1) % 22) == 0) { wait_enter("Press ENTER to continue... "); } } }
/*! \brief Enemies defeated the player * \author Josh Bolduc * \date created ???????? * \date updated * * Play some sad music and set the dead flag so that the game * will return to the main menu. */ static void enemies_win (void) { play_music ("rain.s3m", 0); battle_render (0, 0, 0); /* RB FIXME: rest()? */ blit2screen (0, 0); kq_wait (1000); sprintf (strbuf, _("%s was defeated!"), party[pidx[0]].name); menubox (double_buffer, 152 - (strlen (strbuf) * 4), 48, strlen (strbuf), 1, BLUE); print_font (double_buffer, 160 - (strlen (strbuf) * 4), 56, strbuf, FNORMAL); blit2screen (0, 0); wait_enter (); do_transition (TRANS_FADE_OUT, 4); alldead = 1; }
static int prcmdopts(char *s,int nl) { int i,ll,c; for (i=0;1;i++) { if (i==0) aprintf(TTEXT_BOLD "Command Line Options\n" "--------------------\n" TTEXT_NORMAL); else aprintf(TTEXT_BOLD "Command Line Options (cont'd)\n" "-----------------------------\n" TTEXT_NORMAL); ll=!i ? nl-3 : nl-2; c=0; while (1) { int nlo; nlo=cmdoplines(s); if (ll-2-nlo<0 && c==0) nlo=ll-2; c++; if (s[0]=='\0' || ll-2-nlo<0) break; s=pr1cmdopt(s,ll-2); ll-=nlo; } while (ll>1) { aprintf("\n"); ll--; } if (!i) aprintf("\n"); if (wait_enter()<0) return(0); if (s[0]=='\0') break; } return(1); }
/*! \brief Player defeated the enemies * \author Josh Bolduc * \date Created ???????? * \date Updated * * Distribute the booty! */ static void heroes_win (void) { int tgp = 0; int index; int b; int c; int z; int nc = 0; int txp = 0; int found_item = 0; int nr = 0; int ent = 0; s_fighter t1; s_fighter t2; play_music ("rend5.s3m", 0); kq_wait (500); revert_equipstats (); for (index = 0; index < numchrs; index++) fighter[index].aframe = 4; battle_render (0, 0, 0); blit2screen (0, 0); kq_wait (250); for (index = 0; index < numchrs; index++) { if ((fighter[index].sts[S_STONE] == 0) && (fighter[index].sts[S_DEAD] == 0)) nc++; ta[index] = 0; } for (index = PSIZE; index < PSIZE + numens; index++) { txp += fighter[index].xp; tgp += fighter[index].gp; } /* JB: nc should never be zero if we won, but whatever */ if (nc > 0) txp /= nc; gp += tgp; if (tgp > 0) sprintf (strbuf, _("Gained %d xp and found %d gp."), txp, tgp); else sprintf (strbuf, _("Gained %d xp."), txp); menubox (double_buffer, 152 - (strlen (strbuf) * 4), 8, strlen (strbuf), 1, BLUE); print_font (double_buffer, 160 - (strlen (strbuf) * 4), 16, strbuf, FNORMAL); blit2screen (0, 0); blit (double_buffer, back, 0, 0, 0, 0, 352, 280); for (index = 0; index < numens; index++) { /* PH bug: (?) should found_item be reset to zero at the start of this loop? * If you defeat 2 enemies, you should (possibly) get 2 items, right? */ if ((rand () % 100) < fighter[index + PSIZE].dip) { if (fighter[index + PSIZE].defeat_item_common > 0) found_item = fighter[index + PSIZE].defeat_item_common; if (fighter[index + PSIZE].defeat_item_rare > 0) { if ((rand () % 100) < 5) found_item = fighter[index + PSIZE].defeat_item_rare; } if (found_item > 0) { if (check_inventory (found_item, 1) != 0) { sprintf (strbuf, _("%s found!"), items[found_item].name); menubox (double_buffer, 148 - (strlen (strbuf) * 4), nr * 24 + 48, strlen (strbuf) + 1, 1, BLUE); draw_icon (double_buffer, items[found_item].icon, 156 - (strlen (strbuf) * 4), nr * 24 + 56); print_font (double_buffer, 164 - (strlen (strbuf) * 4), nr * 24 + 56, strbuf, FNORMAL); nr++; } } } } if (nr > 0) { blit2screen (0, 0); wait_enter (); blit (back, double_buffer, 0, 0, 0, 0, 352, 280); } nr = 0; for (c = 0; c < numchrs; c++) { if ((party[pidx[c]].sts[S_STONE] == 0) && (party[pidx[c]].sts[S_DEAD] == 0)) { b = c * 160; player2fighter (pidx[c], &t1); if (give_xp (pidx[c], txp, 0) == 1) { menubox (double_buffer, b, 40, 18, 9, BLUE); player2fighter (pidx[c], &t2); print_font (double_buffer, b + 8, 48, _("Level up!"), FGOLD); print_font (double_buffer, b + 8, 56, _("Max HP"), FNORMAL); print_font (double_buffer, b + 8, 64, _("Max MP"), FNORMAL); print_font (double_buffer, b + 8, 72, _("Strength"), FNORMAL); print_font (double_buffer, b + 8, 80, _("Agility"), FNORMAL); print_font (double_buffer, b + 8, 88, _("Vitality"), FNORMAL); print_font (double_buffer, b + 8, 96, _("Intellect"), FNORMAL); print_font (double_buffer, b + 8, 104, _("Sagacity"), FNORMAL); sprintf (strbuf, "%3d>", t1.mhp); print_font (double_buffer, b + 96, 56, strbuf, FNORMAL); sprintf (strbuf, "%3d", t2.mhp); print_font (double_buffer, b + 128, 56, strbuf, FGREEN); sprintf (strbuf, "%3d>", t1.mmp); print_font (double_buffer, b + 96, 64, strbuf, FNORMAL); sprintf (strbuf, "%3d", t2.mmp); print_font (double_buffer, b + 128, 64, strbuf, FGREEN); for (z = 0; z < 5; z++) { sprintf (strbuf, "%3d>", t1.stats[z]); print_font (double_buffer, b + 96, z * 8 + 72, strbuf, FNORMAL); sprintf (strbuf, "%3d", t2.stats[z]); if (t2.stats[z] > t1.stats[z]) print_font (double_buffer, b + 128, z * 8 + 72, strbuf, FGREEN); else print_font (double_buffer, b + 128, z * 8 + 72, strbuf, FNORMAL); } nr++; } else menubox (double_buffer, b, 104, 18, 1, BLUE); sprintf (strbuf, _("Next level %7d"), party[pidx[c]].next - party[pidx[c]].xp); print_font (double_buffer, b + 8, 112, strbuf, FGOLD); } } blit2screen (0, 0); for (c = 0; c < numchrs; c++) if ((party[pidx[c]].sts[S_STONE] == 0) && (party[pidx[c]].sts[S_DEAD] == 0)) ent += learn_new_spells (pidx[c]); if (ent == 0) wait_enter (); }
static int cmd_dyno_run(UNUSED(int argc), UNUSED(char **argv)) { ecu_data *ep; int speed; /* measured speed */ int rpm; /* measured rpm */ int rpm_previous = 0; /* previous rpm */ unsigned long tv0, tv; /* measuring time */ int elapsed; /* elapsed time (ms) */ int i, length = 0; /* length of printed string */ int nb = 0; /* number of measures */ //make sure we're connected ! if (global_l3_conn == NULL) { fprintf(stderr, FLFMT "No active L3 connection !\n", FL); return CMD_FAILED; } /* Check mass */ if (dyno_get_mass() <= 0) { printf("The mass of the vehicle has not been set, please set the mass first\n"); return CMD_OK; } /* Check mass */ if (dyno_loss_done <= 0) { printf("The loss determination has not been done, please use command loss or setloss first\n"); return CMD_OK; } /* Show instructions */ printf("To proceed dyno, do a full-throttle acceleration run\n"); printf("in a single gear from a rolling start.\n"); printf("The run ends automatically when RPM begins to decrease.\n"); printf("\n"); wait_enter("Press ENTER when ready... "); printf("\n"); /* Reset data */ dyno_reset(); /* dyno data */ reset_results(); tv0=diag_os_getms(); /* initial time */ ep = ecu_info; /* ECU data */ /* Measures */ while (1) { /* measure RPM */ rpm = RUN_MEASURE_DATA(RPM_PID, ep); if (rpm < 0) { printf("invalid RPM !\n"); break; } if (rpm_previous == 0) { /* this is the first measure */ printf("Starting dyno (min rpm=%d)\n", rpm); printf("Number of measures : "); } /* if RPM starts decreasing, stop run */ if (rpm < rpm_previous) { printf(" (max rpm=%d)\n", rpm_previous); break; } /* get elapsed time */ tv=diag_os_getms(); elapsed = (int) (tv - tv0); /* Add measure */ dyno_add_measure(elapsed, rpm); /* Display number of measures */ nb++; for (i = 0; i < length; i++) { printf(""); } length = printf("%d (%d RPM) ", nb, rpm); fflush(stdout); /* force displaying now (may slow down dyno...) */ rpm_previous = rpm; } /* measure gear ratio */ rpm_previous = rpm; speed = RUN_MEASURE_DATA(SPEED_PID, ep); /* m/s * 1000 */ rpm = RUN_MEASURE_DATA(RPM_PID, ep); if ((speed < 0) || (rpm < 0)) { printf("invalid RUN_MEASURE_DATA result !\n"); return CMD_FAILED; } dyno_set_gear(speed, (rpm_previous + rpm) / 2); /* display dyno time */ tv=diag_os_getms(); elapsed = (int) (tv - tv0); printf("Dyno time : %ds.\n", (elapsed/1000)); printf("\n"); return CMD_OK; }
static int cmd_dyno_loss(UNUSED(int argc), UNUSED(char **argv)) { ecu_data *ep; int speed; /* measured speed */ int speed_previous = 0; /* previous speed */ unsigned long tv0, tv; int elapsed; /* elapsed time */ int i, length; /* length of printed string */ int nb = 0; /* number of measures */ //make sure we have an L3 connection first ! if (global_l3_conn == NULL) { fprintf(stderr, FLFMT "Error: there must be an active L3 connection!\n", FL); return CMD_FAILED; } /* Check mass */ if (dyno_get_mass() <= 0) { printf("The mass of the vehicle has not been set, please set the mass first\n"); return CMD_OK; } /* Show instructions */ printf("To proceed loss determination, reach the maximum speed you will reach during\n"); printf("dyno, then push in the clutch, leaving the car in gear. Allow the car to coast\n"); printf("down to the lowest possible speed. Press ENTER when finished.\n"); printf("\n"); wait_enter("Press ENTER when ready... "); printf("\n"); /* Reset data */ dyno_loss_reset(); /* dyno data */ reset_results(); tv0=diag_os_getms(); /* initial time */ ep = ecu_info; /* ECU data */ /* exclude 1st measure */ speed_previous = LOSS_MEASURE_DATA(SPEED_PID, ep); /* m/s * 1000 */ if (speed_previous < 0) { printf("invalid speed !\n"); return CMD_FAILED; } printf("Starting loss determination (max speed=%d km/h)\n", SPEED_ISO_TO_KMH(speed_previous)); printf("Number of measures : 0"); length = 1; /* loss measures */ while (1) { /* measure speed */ speed = LOSS_MEASURE_DATA(SPEED_PID, ep); /* m/s * 1000 */ if (speed < 0) { printf("invalid speed !\n"); break; } /* get elapsed time */ tv=diag_os_getms(); elapsed = (int) (tv - tv0); if (speed < speed_previous) { /* Add measure */ dyno_loss_add_measure(elapsed, speed); nb++; speed_previous = speed; } if (pressed_enter() != 0) { /* ENTER pressed : stops */ printf("Number of measures : %d (min speed=%d km/h)\n", nb, SPEED_ISO_TO_KMH(speed)); break; } if (speed_previous == speed) { /* measure added: update display */ /* erase previous measure */ for (i = 0; i < length; i++) { printf(""); } /* Display new measure */ length = printf("%d (speed=%d km/h, d=%5.5f, f=%4.2f)\t ", nb, SPEED_ISO_TO_KMH(speed), dyno_loss_get_d(), dyno_loss_get_f()); fflush(stdout); /* force displaying now (may slow down dyno...) */ } } /* display dyno time */ //elapsed = MILLIS(tv) - MILLIS(tv0); tv=diag_os_getms(); elapsed= (int) (tv - tv0); printf("d=%5.5f, f=%4.2f\n", dyno_loss_get_d(), dyno_loss_get_f()); printf("Loss determination time : %ds.\n", (elapsed/1000)); printf("\n"); /* now dyno loss has been done */ dyno_loss_done = 1; return CMD_OK; }