[Freeciv-Dev] (PR#576) Wishlist: alternating unit movement
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=576 >
The first thing we need to do is to separate start and end of *player*
turns versus *global* turns. So the logic (for the current code) should
become
do {
begin_turn();
player_begin_turn(NULL);
do_turn();
player_end_turn(NULL);
end_turn();
}
AI activities should go into player_***_turn. And of course all normal
player activies (city production, unit restore, goto execution) should
go into player_***_turn.
begin_turn and end_turn should be as small as possible. However some
things have to be done here: like advancing the year.
player_begin_turn is given NULL because it must begin the turn for all
players. It would be nice to do something like:
shuffled_players_iterate(pplayer) {
player_begin_turn(pplayer);
} shuffled_players_iterate_end;
but this probably won't work because of the dependencies involved (I'm
not 100% sure of this actually). So instead we pass NULL causing all
players to be handled here. Inside the function we can do
void player_begin_turn(pplayer_turn)
{
turn_players_iterate(pplayer_turn, pplayer) {
do_something(pplayer);
} turn_players_iterate_end;
/* ... etc. ... */
}
where turn_players_iterate is equivalent to shuffled_players_iterate if
pplayer_turn is NULL, or just has one case if pplayer_turn is non-null.
So later the loop becomes:
do {
begin_turn();
if (game.asynch_moves) {
player_begin_turn(NULL);
do_turn(pplayer_turn);
player_end_turn(NULL);
} else {
shuffled_players_iterate(pplayer_turn) {
player_begin_turn(pplayer_turn);
do_turn(pplayer_turn);
player_end_turn(pplayer_turn);
} shuffled_players_iterate_end;
}
end_turn();
}
do_turn() changes slightly. Currently it is just
while(sniff_packets() == 1) { }
but note that now AI players must be handled here. Something like:
if (!pplayer_turn->ai.ai_control) {
while (sniff_packets() == 1) { }
}
may suffice, but it's also possible the AI may want to use some of its
turn here (in a timeout game the AI may need to take advantage of its
time to do diplomacy).
Finally various packet handlers need to be changted. game.player_turn
should hold the player whose turn it is (or NULL). So a bunch of
packets (turn-end packet and unit movement packet) get handled a check like:
if (game.player_turn && game.player_turn != pplayer) {
return;
}
handle_unit_orders is changed in a similar way (the orders are still
recorded but not executed).
I think that's all. The hardest part is the first one: restructuring
the turn activities. This may (I'm not sure) have to wait for PR#725.
jason
|
|