The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
replay_helper.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 #include "replay_helper.hpp"
15 
16 #include <string>
17 #include <cassert>
18 #include "map/location.hpp"
19 #include "time_of_day.hpp"
20 #include "resources.hpp"
21 #include "play_controller.hpp"
22 
23 config replay_helper::get_recruit(const std::string& type_id, const map_location& loc, const map_location& from)
24 {
25  config val;
26  val["type"] = type_id;
27  loc.write(val);
28  config& leader_position = val.add_child("from");
29  from.write(leader_position);
30 
31  return val;
32 }
33 
34 config replay_helper::get_recall(const std::string& unit_id, const map_location& loc, const map_location& from)
35 {
36 
37  config val;
38  val["value"] = unit_id;
39  loc.write(val);
40  config& leader_position = val.add_child("from");
41  from.write(leader_position);
42 
43  return val;
44 }
45 
47 {
48  config val;
49 
50  val["value"] = unit_id;
51 
52  return val;
53 }
54 
55 
56 /**
57  * Records a move that follows the provided @a steps.
58  * This should be the steps to be taken this turn, ending in an
59  * apparently-unoccupied (from the moving team's perspective) hex.
60  */
61 config replay_helper::get_movement(const std::vector<map_location>& steps, bool skip_sighted, bool skip_ally_sighted)
62 {
63  assert(!steps.empty());
64 
65  config move;
66  if(skip_sighted)
67  {
68  //note, that skip_ally_sighted has no effect if skip_sighted is true
69  move["skip_sighted"] = "all";
70  }
71  else if(skip_ally_sighted && !skip_sighted)
72  {
73  move["skip_sighted"] = "only_ally";
74  }
75  else
76  {
77  //leave it empty
78  }
79  write_locations(steps, move);
80 
81  return move;
82 }
83 
84 
85 
87  int att_weapon, int def_weapon, const std::string& attacker_type_id,
88  const std::string& defender_type_id, int attacker_lvl,
89  int defender_lvl, const size_t turn, const time_of_day &t)
90 {
91 
92  config move, src, dst;
93  a.write(src);
94  b.write(dst);
95 
96  move.add_child("source",src);
97  move.add_child("destination",dst);
98 
99 
100  move["weapon"] = att_weapon;
101  move["defender_weapon"] = def_weapon;
102  move["attacker_type"] = attacker_type_id;
103  move["defender_type"] = defender_type_id;
104  move["attacker_lvl"] = attacker_lvl;
105  move["defender_lvl"] = defender_lvl;
106  move["turn"] = int(turn);
107  move["tod"] = t.id;
108  /*
109  add_unit_checksum(a,current_);
110  add_unit_checksum(b,current_);
111  */
112  return move;
113 }
114 
115 /**
116  * Records that the player has toggled automatic shroud updates.
117  */
119 {
120  config child;
121  child["active"] = turned_on;
122  return child;
123 }
124 
125 /**
126  * Records that the player has manually updated fog/shroud.
127  */
129 {
130  return config();
131 }
132 
133 
135 {
136  config init_side;
137  init_side["side_number"] = resources::controller->current_side();
138  return init_side;
139 }
140 
141 config replay_helper::get_event(const std::string& name, const map_location& loc, const map_location* last_select_loc)
142 {
143  config ev;
144  ev["raise"] = name;
145  if(loc.valid()) {
146  config& source = ev.add_child("source");
147  loc.write(source);
148  }
149  if(last_select_loc != nullptr && last_select_loc->valid())
150  {
151  config& source = ev.add_child("last_select");
152  last_select_loc->write(source);
153  }
154  return ev;
155 }
156 
158 {
159  config child;
160  child["code"] = lua_code;
161  return child;
162 }
static config get_lua_ai(const std::string &lua_code)
play_controller * controller
Definition: resources.cpp:21
static config get_recall(const std::string &unit_id, const map_location &loc, const map_location &from)
std::string id
Definition: time_of_day.hpp:77
GLuint const GLfloat * val
Definition: glew.h:2614
static config get_auto_shroud(bool turned_on)
Records that the player has toggled automatic shroud updates.
static config get_movement(const std::vector< map_location > &steps, bool skip_sighted, bool skip_ally_sighted)
Records a move that follows the provided steps.
GLenum src
Definition: glew.h:2392
GLdouble GLdouble t
Definition: glew.h:1366
static config get_update_shroud()
Records that the player has manually updated fog/shroud.
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:48
int current_side() const
Returns the number of the side whose turn it is.
bool valid() const
Definition: location.hpp:69
GLenum GLenum dst
Definition: glew.h:2392
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
config & add_child(const std::string &key)
Definition: config.cpp:743
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
void write(config &cfg) const
Definition: location.cpp:205
Encapsulates the map of the game.
Definition: location.hpp:38
static config get_disband(const std::string &unit_id)
GLuint const GLchar * name
Definition: glew.h:1782
static config get_recruit(const std::string &type_id, const map_location &loc, const map_location &from)
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)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
static config get_event(const std::string &name, const map_location &loc, const map_location *last_select_loc)
GLsizei const GLcharARB ** string
Definition: glew.h:4503
GLsizei GLsizei GLchar * source
Definition: glew.h:1800
static config get_init_side()
void write_locations(const std::vector< map_location > &locs, config &cfg)
Write a vector of locations into a config adding keys x=x1,x2,..,xn and y=y1,y2,..,yn.
Definition: location.cpp:425