本文整理汇总了C++中Fleet::Sort方法的典型用法代码示例。如果您正苦于以下问题:C++ Fleet::Sort方法的具体用法?C++ Fleet::Sort怎么用?C++ Fleet::Sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fleet
的用法示例。
在下文中一共展示了Fleet::Sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: choose_new_ships
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;
}