int my_list_proc( int msg, DIALOG* d, int c ) { STACKTRACE; int old_d1 = d->d1; Fleet *fleet = (Fleet*)d->dp3; int ret = d_list_proc2( msg, d, c ); if ( d->d1 != old_d1 || msg == MSG_START ) { ShipType* type = fleet->getShipType(d->d1); ASSERT(type != NULL); selectDialog[SELECT_DIALOG_TITLE].flags |= D_DIRTY; sprintf(selectTitleString, "%s\n%s\n%d of %d points", selectShipPrompt, (type != NULL) ? type->name : 0, (type != NULL) ? type->cost : 0, fleet->getCost()); BITMAP* panel = NULL; TW_DATAFILE* data = tw_load_datafile_object( type->data->file, "SHIP_P00_PCX" ); if ( data ) { BITMAP* bmp = (BITMAP*)data->dat; panel = create_bitmap_ex( bitmap_color_depth(screen), bmp->w, bmp->h ); blit( bmp, panel, 0, 0, 0, 0, bmp->w, bmp->h ); tw_unload_datafile_object( data ); data = tw_load_datafile_object( type->data->file, "SHIP_P01_PCX" ); bmp = (BITMAP*)data->dat; blit( bmp, panel, 0, 0, 4, 65, bmp->w, bmp->h ); tw_unload_datafile_object( data ); color_correct_bitmap( panel, 0 ); } if ( selectDialog[SELECT_DIALOG_PIC].dp ) destroy_bitmap( (BITMAP*)selectDialog[SELECT_DIALOG_PIC].dp ); selectDialog[SELECT_DIALOG_PIC].dp = panel; scare_mouse(); SEND_MESSAGE( &selectDialog[SELECT_DIALOG_PIC], MSG_DRAW, 0 ); unscare_mouse(); } return ret; }
void NormalGame::choose_new_ships() { STACKTRACE; char tmp[40]; int i; pause(); message.out("Selecting ships...", 1000); int *slot = new int[num_players]; //choose ships and send them across network for (i = 0; i < num_players; i += 1) { slot[i] = -2; if (player_control[i]->ship) { } else { // if (player_panel[i]) player_panel[i]->window->hide(); // player_panel[i] = NULL; sprintf (tmp, "Player%d", i+1); Fleet *fleet = player_fleet[i]; if (fleet->getSize() == 0) continue; char buffy[512]; if (strlen(fleet->getTitle()) != 0) sprintf(buffy, "%s\n%s\n", player_name[i], fleet->getTitle()); else sprintf(buffy, "%s\n", player_name[i]); slot[i] = player_control[i]->choose_ship(window, buffy, fleet); if (player_control[i]->channel != channel_none) { slot[i] = intel_ordering(slot[i]); log->buffer(player_control[i]->channel, &slot[i], sizeof(int)); log->flush(); //slot[i] = intel_ordering(slot[i]); } } } //recieve the ships that were chosen log->listen(); for (i = 0; i < num_players; i += 1) { if (slot[i] == -2) continue; if (player_control[i]->channel != channel_none) { log->unbuffer(player_control[i]->channel, &slot[i], sizeof(int)); slot[i] = intel_ordering(slot[i]); } } //create the ships that were chosen for (i = 0; i < num_players; i += 1) { if (slot[i] == -2) continue; sprintf (tmp, "Player%d", i+1); //fleet->load("./fleets.tmp", tmp); Fleet *fleet = player_fleet[i]; if (slot[i] == -1) slot[i] = random() % fleet->getSize(); if (slot[i] < 0 || slot[i] >= fleet->getSize()) {tw_error("trying to load invalid ship");} Ship *s = create_ship(fleet->getShipType(slot[i])->id, player_control[i], random(size), random(PI2), player_team[i]); if (!s) {tw_error("unable to create ship");} fleet->clear_slot(slot[i]); fleet->Sort(); //fleet->save("./fleets.tmp", tmp); s->locate(); add ( new WedgeIndicator ( s, 30, i+1 ) ); ShipPanel *panel = new ShipPanel(s); panel->window->init(window); panel->window->locate( 0, 0.9, 0, i * (100.0/480), 0, 0.1, 0, (100.0/480) ); add(panel); add(s->get_ship_phaser()); // add a healthbar for the ship, and also a team indicator. add(new HealthBar(s, &indhealthtoggle)); add(new TeamIndicator(s, &indteamtoggle)); // CHECK FILE SIZES !! to intercept desynch before they happen. int myfsize, otherfsize; myfsize = file_size_ex(s->type->data->file); otherfsize = myfsize; if (player_control[i]->channel != channel_none) { log_int(player_control[i]->channel, otherfsize); } if (otherfsize != myfsize) { // the player who loads the ship doesn't get this message, cause his own file is identical by default tw_error("DAT files have different size! This may cause a desynch. Press Retry to continue"); } } delete[] slot; message.out("Finished selecting ships...", 1500); unpause(); return; }