add replay_helper class
the main intention was to make the file replay.cpp smaller during writing pr 121. also in order to use synced_context::run_in_synced_context this is useful. (replay_helper.cpp was already accidently moved into makelist.txt in a pevious commit (add new rng))
This commit is contained in:
parent
bf4935da84
commit
ea7521af2b
3 changed files with 209 additions and 0 deletions
|
@ -482,6 +482,7 @@ wesnoth_sources = Split("""
|
|||
random_new_deterministic.cpp
|
||||
random_new_synced.cpp
|
||||
replay.cpp
|
||||
replay_helper.cpp
|
||||
replay_controller.cpp
|
||||
resources.cpp
|
||||
save_blocker.cpp
|
||||
|
|
156
src/replay_helper.cpp
Normal file
156
src/replay_helper.cpp
Normal file
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
#include "replay_helper.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include "map_location.hpp"
|
||||
#include "time_of_day.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "play_controller.hpp"
|
||||
|
||||
//void replay::add_recruit(const std::string& type_id, const map_location& loc, const map_location& from)
|
||||
config replay_helper::get_recruit(const std::string& type_id, const map_location& loc, const map_location& from)
|
||||
{
|
||||
config val;
|
||||
val["type"] = type_id;
|
||||
loc.write(val);
|
||||
config& leader_position = val.add_child("from");
|
||||
from.write(leader_position);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
config replay_helper::get_recall(const std::string& unit_id, const map_location& loc, const map_location& from)
|
||||
{
|
||||
|
||||
config val;
|
||||
val["value"] = unit_id;
|
||||
loc.write(val);
|
||||
config& leader_position = val.add_child("from");
|
||||
from.write(leader_position);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
config replay_helper::get_disband(const std::string& unit_id)
|
||||
{
|
||||
config val;
|
||||
|
||||
val["value"] = unit_id;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Records a move that follows the provided @a steps.
|
||||
* This should be the steps to be taken this turn, ending in an
|
||||
* apparently-unoccupied (from the moving team's perspective) hex.
|
||||
*/
|
||||
config replay_helper::get_movement(const std::vector<map_location>& steps)
|
||||
{
|
||||
assert(!steps.empty());
|
||||
|
||||
config move;
|
||||
write_locations(steps, move);
|
||||
|
||||
return move;
|
||||
}
|
||||
|
||||
|
||||
|
||||
config replay_helper::get_attack(const map_location& a, const map_location& b,
|
||||
int att_weapon, int def_weapon, const std::string& attacker_type_id,
|
||||
const std::string& defender_type_id, int attacker_lvl,
|
||||
int defender_lvl, const size_t turn, const time_of_day &t)
|
||||
{
|
||||
|
||||
config move, src, dst;
|
||||
a.write(src);
|
||||
b.write(dst);
|
||||
|
||||
move.add_child("source",src);
|
||||
move.add_child("destination",dst);
|
||||
|
||||
|
||||
move["weapon"] = att_weapon;
|
||||
move["defender_weapon"] = def_weapon;
|
||||
move["attacker_type"] = attacker_type_id;
|
||||
move["defender_type"] = defender_type_id;
|
||||
move["attacker_lvl"] = attacker_lvl;
|
||||
move["defender_lvl"] = defender_lvl;
|
||||
move["turn"] = int(turn);
|
||||
move["tod"] = t.id;
|
||||
/*
|
||||
add_unit_checksum(a,current_);
|
||||
add_unit_checksum(b,current_);
|
||||
*/
|
||||
return move;
|
||||
}
|
||||
|
||||
/**
|
||||
* Records that the player has toggled automatic shroud updates.
|
||||
*/
|
||||
config replay_helper::get_auto_shroud(bool turned_on)
|
||||
{
|
||||
config child;
|
||||
child["active"] = turned_on;
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Records that the player has manually updated fog/shroud.
|
||||
*/
|
||||
config replay_helper::get_update_shroud()
|
||||
{
|
||||
return config();
|
||||
}
|
||||
|
||||
|
||||
config replay_helper::get_init_side()
|
||||
{
|
||||
config init_side;
|
||||
init_side["side_number"] = resources::controller->current_side();
|
||||
return init_side;
|
||||
}
|
||||
/*
|
||||
void replay::end_turn()
|
||||
{
|
||||
config* const cmd = add_command();
|
||||
cmd->add_child("end_turn");
|
||||
}*/
|
||||
|
||||
config replay_helper::get_event(const std::string& name, const map_location& loc, const map_location* last_select_loc)
|
||||
{
|
||||
config ev;
|
||||
ev["raise"] = name;
|
||||
if(loc.valid()) {
|
||||
config& source = ev.add_child("source");
|
||||
loc.write(source);
|
||||
}
|
||||
if(last_select_loc != NULL && last_select_loc->valid())
|
||||
{
|
||||
config& source = ev.add_child("last_select");
|
||||
last_select_loc->write(source);
|
||||
}
|
||||
//(*cmd)["undo"] = false;
|
||||
return ev;
|
||||
}
|
||||
|
||||
config replay_helper::get_lua_ai(const std::string& lua_code)
|
||||
{
|
||||
config child;
|
||||
child["code"] = lua_code;
|
||||
return child;
|
||||
}
|
52
src/replay_helper.hpp
Normal file
52
src/replay_helper.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
#ifndef REPLAY_HELPER_H_INCLUDED
|
||||
#define REPLAY_HELPER_H_INCLUDED
|
||||
|
||||
|
||||
#include "config.hpp"
|
||||
#include <string>
|
||||
struct map_location;
|
||||
struct time_of_day;
|
||||
|
||||
class replay_helper
|
||||
{
|
||||
public:
|
||||
static config get_recruit(const std::string& type_id, const map_location& loc, const map_location& from);
|
||||
|
||||
static config get_recall(const std::string& unit_id, const map_location& loc, const map_location& from);
|
||||
|
||||
static config get_disband(const std::string& unit_id);
|
||||
//TODO: add some additional checkup (unit checksum) here.
|
||||
static config get_movement(const std::vector<map_location>& steps);
|
||||
|
||||
static config get_attack(const map_location& a, const map_location& b,
|
||||
int att_weapon, int def_weapon, const std::string& attacker_type_id,
|
||||
const std::string& defender_type_id, int attacker_lvl,
|
||||
int defender_lvl, const size_t turn, const time_of_day &t);
|
||||
|
||||
static config get_auto_shroud(bool turned_on);
|
||||
|
||||
static config get_update_shroud();
|
||||
|
||||
static config get_init_side();
|
||||
/*
|
||||
|
||||
*/
|
||||
static config get_event(const std::string& name, const map_location& loc, const map_location* last_select_loc);
|
||||
|
||||
static config get_lua_ai(const std::string& lua_code);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue