//--------- Begin of function UnitMarine::load_unit ---------// // // Load an unit to the ship. // // <int> unitRecno - recno of the unit to be loaded. // void UnitMarine::load_unit(int unitRecno) { if(unit_array.is_deleted(unitRecno)) return; Unit *unitPtr = unit_array[unitRecno]; if(unitPtr->hit_points<=0 || unitPtr->cur_action==SPRITE_DIE || unitPtr->action_mode2==ACTION_DIE) return; if( unit_count == MAX_UNIT_IN_SHIP ) return; unit_recno_array[unit_count++] = unitRecno; unitPtr->set_mode(UNIT_MODE_ON_SHIP, sprite_recno); // set unit mode if(unitPtr->selected_flag) { unitPtr->selected_flag = 0; unit_array.selected_count--; } unitPtr->deinit_sprite(); //--- if this marine unit is currently selected ---// if(unit_array.selected_recno==sprite_recno) { if(!remote.is_enable() || nation_recno==nation_array.player_recno || config.show_ai_info) disp_info(INFO_UPDATE); } }
int main(int argc, char *argv[]) { int BUF_FRAMES = 44100 * 600; GCA_T gca; SF_INFO sinfo; sf_count_t st_frame, ed_frame, cnt_frames; sf_count_t frames; int datasize; int optchar; int mode_info = 0; opterr = 0; memset(&gca, 0, sizeof(GCA_T)); while((optchar = getopt(argc, argv, "b:e:o:ih")) != -1) { switch(optchar) { case 'b': case 'e': if(check_frame_format(optarg) != 0) { fprintf(stderr, "\"%s\" is invalid format for -%c", optarg, optchar); exit(EXIT_FAILURE); } else { if (optchar == 'b') { gca.st = strdup(optarg); } else { gca.ed = strdup(optarg); } } break; case 'o': gca.fname = strdup(optarg); break; case 'i': mode_info = 1; break; case 'h': case '?': default: disp_help(); exit(EXIT_SUCCESS); break; } } if (argv[optind] == NULL) { fprintf(stderr, "File is not specified.\n"); exit(EXIT_FAILURE); } // open input sound file gca.sf = sf_open(argv[optind], SFM_READ, &sinfo); // decode frame st_frame = str2frame(gca.st, sinfo.samplerate); ed_frame = str2frame(gca.ed, sinfo.samplerate); cnt_frames = ed_frame - st_frame; if (cnt_frames < 0) { fprintf(stderr, "Begin frame is later than end.\n"); close_handles(&gca); exit(EXIT_FAILURE); } if (mode_info == 1) { disp_info(&sinfo); printf("Specified count of frames: %d\n", (int)cnt_frames); close_handles(&gca); exit(EXIT_SUCCESS); } // get buffer datasize = sizeof(short) * sinfo.channels * BUF_FRAMES; gca.audiodata = (short *)malloc(datasize); // seek frames sf_seek(gca.sf, st_frame, SEEK_SET); // open output sndfile if (gca.fname != NULL) { gca.fp = fopen(gca.fname, "w"); if (gca.fp == NULL) { fprintf(stderr, "%s\n", strerror(errno)); close_handles(&gca); exit(EXIT_FAILURE); } } else { gca.fp = stdout; } // read frame while(cnt_frames > 0) { frames = sf_readf_short(gca.sf, gca.audiodata, BUF_FRAMES); if (frames > cnt_frames) { fwrite(gca.audiodata, sizeof(short), cnt_frames * sinfo.channels, gca.fp); } else { fwrite(gca.audiodata, sizeof(short), frames * sinfo.channels, gca.fp); } cnt_frames -= frames; } close_handles(&gca); return 0; }