fixed problem loading games
This commit is contained in:
parent
143f78dfbc
commit
e41c034335
3 changed files with 26 additions and 24 deletions
|
@ -123,6 +123,8 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
|
||||
bool replaying = (recorder.empty() == false);
|
||||
|
||||
const int start_command = recorder.ncommands();
|
||||
|
||||
std::cout << "starting main loop\n";
|
||||
for(bool first_time = true; true; first_time = false) {
|
||||
try {
|
||||
|
@ -174,7 +176,8 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
if(network::nconnections() > 0) {
|
||||
config cfg;
|
||||
cfg.children["turn"].push_back(
|
||||
new config(recorder.get_last_turn(1)));
|
||||
new config(recorder.get_data_range(start_command,
|
||||
recorder.ncommands())));
|
||||
network::send_data(cfg);
|
||||
}
|
||||
|
||||
|
@ -185,10 +188,11 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
display::clear_debug_highlights();
|
||||
|
||||
if(network::nconnections() > 0) {
|
||||
config cfg;
|
||||
cfg.children["turn"].push_back(
|
||||
new config(recorder.get_last_turn(2)));
|
||||
network::send_data(cfg);
|
||||
config cfg;
|
||||
cfg.children["turn"].push_back(
|
||||
new config(recorder.get_data_range(start_command,
|
||||
recorder.ncommands())));
|
||||
network::send_data(cfg);
|
||||
}
|
||||
|
||||
} else if(!replaying && team_it->is_ai()) {
|
||||
|
@ -198,7 +202,8 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
if(network::nconnections() > 0) {
|
||||
config cfg;
|
||||
cfg.children["turn"].push_back(
|
||||
new config(recorder.get_last_turn(2)));
|
||||
new config(recorder.get_data_range(start_command,
|
||||
recorder.ncommands())));
|
||||
network::send_data(cfg);
|
||||
}
|
||||
|
||||
|
|
|
@ -208,29 +208,18 @@ void replay::end_turn()
|
|||
cmd->children["end_turn"].push_back(new config());
|
||||
}
|
||||
|
||||
config replay::get_last_turn(int num_turns)
|
||||
config replay::get_data_range(int cmd_start, int cmd_end)
|
||||
{
|
||||
log_scope("get_last_turn\n");
|
||||
//back up from the end, finding the position we're looking for
|
||||
std::vector<config*>& cmd = commands();
|
||||
std::vector<config*>::reverse_iterator i;
|
||||
for(i = cmd.rbegin(); i != cmd.rend() && num_turns > 0; ++i) {
|
||||
if((*i)->children["end_turn"].size() > 0) {
|
||||
--num_turns;
|
||||
}
|
||||
}
|
||||
|
||||
//if we reached an end turn, we have to move one step forward so
|
||||
//that we don't include the end turn
|
||||
const int adjust = num_turns == 0 ? 1 : 0;
|
||||
log_scope("get_data_range\n");
|
||||
|
||||
config res;
|
||||
|
||||
for(std::vector<config*>::const_iterator fi = i.base()+adjust;
|
||||
fi != cmd.end(); ++fi) {
|
||||
res.children["command"].push_back(new config(**fi));
|
||||
std::vector<config*>& cmd = commands();
|
||||
while(cmd_start < cmd_end) {
|
||||
res.children["command"].push_back(new config(*cmd[cmd_start]));
|
||||
++cmd_start;
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -248,6 +237,11 @@ std::vector<config*>& replay::commands()
|
|||
return cfg_.children["command"];
|
||||
}
|
||||
|
||||
int replay::ncommands()
|
||||
{
|
||||
return commands().size();
|
||||
}
|
||||
|
||||
config* replay::add_command()
|
||||
{
|
||||
config* const cmd = new config();
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
void choose_option(int index);
|
||||
void end_turn();
|
||||
|
||||
config get_data_range(int cmd_start, int cmd_end);
|
||||
config get_last_turn(int num_turns=1);
|
||||
|
||||
void undo();
|
||||
|
@ -58,6 +59,8 @@ public:
|
|||
|
||||
void add_config(const config& cfg);
|
||||
|
||||
int ncommands();
|
||||
|
||||
struct error {};
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue