mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-15 17:25:32 +00:00
fix wose death anim, fix WML being broken.
I will port the wose fix to 1.2 myself if it is needed
This commit is contained in:
parent
4104f39b00
commit
16771cd619
@ -136,7 +136,7 @@ bool animated<T,T_void_value>::need_update() const
|
||||
if(!started_) {
|
||||
return false;
|
||||
}
|
||||
if(current_ticks > (unsigned int)(get_current_frame_end_time()/acceleration_+start_tick_)){
|
||||
if(current_ticks > (int)(get_current_frame_end_time()/acceleration_+start_tick_)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -149,7 +149,7 @@ bool animated<T,T_void_value>::animation_would_finish() const
|
||||
return true;
|
||||
if(!started_)
|
||||
return true;
|
||||
if(!cycles_ && (current_ticks > (unsigned int)(get_end_time()/acceleration_+start_tick_)))
|
||||
if(!cycles_ && (current_ticks > (int)(get_end_time()/acceleration_+start_tick_)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -649,10 +649,11 @@ void config::debug() const{
|
||||
i--;
|
||||
}
|
||||
|
||||
const t_string& config::get_variable_const(const std::string& key)
|
||||
const t_string& config::get_variable_const(const std::string& key) const
|
||||
{
|
||||
const std::string::const_iterator itor = std::find(key.begin(),key.end(),'.');
|
||||
size_t MaxLoop= 1024;
|
||||
size_t MaxLoop= 1024;
|
||||
static t_string empty = "";
|
||||
if(itor != key.end()) {
|
||||
std::string element(key.begin(),itor);
|
||||
std::string sub_key(itor+1,key.end());
|
||||
@ -687,15 +688,14 @@ const t_string& config::get_variable_const(const std::string& key)
|
||||
}
|
||||
}
|
||||
|
||||
while(get_children(element).size() <= index) {
|
||||
add_child(element);
|
||||
if(get_children(element).size() <= index) {
|
||||
return empty;
|
||||
}
|
||||
return (*get_children(element)[index]).get_variable_const(sub_key);
|
||||
} else {
|
||||
if(values.find(key) != values.end()){
|
||||
return values.find(key)->second;
|
||||
}else {
|
||||
static t_string empty = "";
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public:
|
||||
void reset_translation() const;
|
||||
|
||||
// allow any WML to be used to interpolate variables
|
||||
const t_string& get_variable_const(const std::string& id) ;
|
||||
const t_string& get_variable_const(const std::string& id) const;
|
||||
|
||||
//all the attributes of this node.
|
||||
string_map values;
|
||||
|
@ -153,48 +153,48 @@ bool conditional_passed(const unit_map* units,
|
||||
for(vconfig::child_list::const_iterator var = variables.begin(); var != variables.end(); ++var) {
|
||||
const vconfig& values = *var;
|
||||
|
||||
const std::string name = values["name"];
|
||||
const std::string& name = values["name"];
|
||||
wassert(state_of_game != NULL);
|
||||
const std::string& value = state_of_game->get_variable(name);
|
||||
|
||||
const double num_value = atof(value.c_str());
|
||||
|
||||
const std::string equals = values["equals"];
|
||||
const std::string& equals = values["equals"];
|
||||
if(values.get_attribute("equals") != "" && value != equals) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string numerical_equals = values["numerical_equals"];
|
||||
const std::string& numerical_equals = values["numerical_equals"];
|
||||
if(values.get_attribute("numerical_equals") != "" && atof(numerical_equals.c_str()) != num_value){
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string not_equals = values["not_equals"];
|
||||
const std::string& not_equals = values["not_equals"];
|
||||
if(values.get_attribute("not_equals") != "" && not_equals == value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string numerical_not_equals = values["numerical_not_equals"];
|
||||
const std::string& numerical_not_equals = values["numerical_not_equals"];
|
||||
if(values.get_attribute("numerical_not_equals") != "" && atof(numerical_not_equals.c_str()) == num_value){
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string greater_than = values["greater_than"];
|
||||
const std::string& greater_than = values["greater_than"];
|
||||
if(values.get_attribute("greater_than") != "" && atof(greater_than.c_str()) >= num_value){
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string less_than = values["less_than"];
|
||||
const std::string& less_than = values["less_than"];
|
||||
if(values.get_attribute("less_than") != "" && atof(less_than.c_str()) <= num_value){
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string greater_than_equal_to = values["greater_than_equal_to"];
|
||||
const std::string& greater_than_equal_to = values["greater_than_equal_to"];
|
||||
if(values.get_attribute("greater_than_equal_to") != "" && atof(greater_than_equal_to.c_str()) > num_value){
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string less_than_equal_to = values["less_than_equal_to"];
|
||||
const std::string& less_than_equal_to = values["less_than_equal_to"];
|
||||
if(values.get_attribute("less_than_equal_to") != "" && atof(less_than_equal_to.c_str()) < num_value) {
|
||||
return false;
|
||||
}
|
||||
@ -864,28 +864,28 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
else if(cmd == "set_variable") {
|
||||
wassert(state_of_game != NULL);
|
||||
|
||||
const std::string name = utils::interpolate_variables_into_string(
|
||||
const std::string& name = utils::interpolate_variables_into_string(
|
||||
cfg.get_attribute("name"), *state_of_game);
|
||||
t_string& var = state_of_game->get_variable(name);
|
||||
|
||||
const t_string value = cfg["value"];
|
||||
const t_string& value = cfg["value"];
|
||||
if(value.empty() == false) {
|
||||
var = value;
|
||||
}
|
||||
|
||||
const std::string format = utils::interpolate_variables_into_string(
|
||||
const std::string& format = utils::interpolate_variables_into_string(
|
||||
cfg.get_attribute("format"), *state_of_game);
|
||||
if(format.empty() == false) {
|
||||
var = format;
|
||||
}
|
||||
|
||||
const std::string to_variable = utils::interpolate_variables_into_string(
|
||||
const std::string& to_variable = utils::interpolate_variables_into_string(
|
||||
cfg.get_attribute("to_variable"), *state_of_game);
|
||||
if(to_variable.empty() == false) {
|
||||
var = state_of_game->get_variable(to_variable);
|
||||
}
|
||||
|
||||
const std::string add = cfg["add"];
|
||||
const std::string& add = cfg["add"];
|
||||
if(add.empty() == false) {
|
||||
int value = int(atof(var.c_str()));
|
||||
value += atoi(add.c_str());
|
||||
@ -894,7 +894,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
var = buf;
|
||||
}
|
||||
|
||||
const std::string multiply = cfg["multiply"];
|
||||
const std::string& multiply = cfg["multiply"];
|
||||
if(multiply.empty() == false) {
|
||||
int value = int(atof(var.c_str()));
|
||||
value = int(double(value) * atof(multiply.c_str()));
|
||||
@ -903,7 +903,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
var = buf;
|
||||
}
|
||||
|
||||
const std::string divide = cfg["divide"];
|
||||
const std::string& divide = cfg["divide"];
|
||||
if(divide.empty() == false) {
|
||||
int value = int(atof(var.c_str()));
|
||||
double divider = atof(divide.c_str());
|
||||
@ -918,7 +918,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
}
|
||||
}
|
||||
|
||||
const std::string modulo = cfg["modulo"];
|
||||
const std::string& modulo = cfg["modulo"];
|
||||
if(modulo.empty() == false) {
|
||||
int value = atoi(var.c_str());
|
||||
int divider = atoi(modulo.c_str());
|
||||
@ -936,7 +936,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
// Each element in the list will be considered a separate choice,
|
||||
// unless it contains "..". In this case, it must be a numerical
|
||||
// range. (i.e. -1..-10, 0..100, -10..10, etc)
|
||||
const std::string random = cfg["random"];
|
||||
const std::string& random = cfg["random"];
|
||||
if(random.empty() == false) {
|
||||
std::string random_value;
|
||||
//if we're not replaying create a random number
|
||||
@ -1689,8 +1689,8 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
if(filter.null())
|
||||
filter = &empty_filter;
|
||||
|
||||
const std::string variable = cfg["variable"];
|
||||
const std::string mode = cfg["mode"];
|
||||
const std::string& variable = cfg["variable"];
|
||||
const std::string& mode = cfg["mode"];
|
||||
bool cleared = false;
|
||||
|
||||
config& vars = state_of_game->variables;
|
||||
@ -1893,19 +1893,19 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
||||
|
||||
//command to remove a variable
|
||||
else if(cmd == "clear_variable") {
|
||||
const std::string name = utils::interpolate_variables_into_string(
|
||||
const std::string& name = utils::interpolate_variables_into_string(
|
||||
cfg.get_attribute("name"), *state_of_game);
|
||||
state_of_game->clear_variable(name);
|
||||
}
|
||||
|
||||
else if(cmd == "endlevel") {
|
||||
const std::string next_scenario = utils::interpolate_variables_into_string(
|
||||
const std::string& next_scenario = utils::interpolate_variables_into_string(
|
||||
cfg.get_attribute("next_scenario"), *state_of_game);
|
||||
if(next_scenario.empty() == false) {
|
||||
state_of_game->scenario = next_scenario;
|
||||
}
|
||||
|
||||
const std::string result = utils::interpolate_variables_into_string(
|
||||
const std::string& result = utils::interpolate_variables_into_string(
|
||||
cfg.get_attribute("result"), *state_of_game);
|
||||
if(result.empty() || result == "victory") {
|
||||
const bool bonus = utils::string_bool(cfg["bonus"],true);
|
||||
@ -2076,8 +2076,8 @@ bool filter_loc_impl(const gamemap::location& loc, const std::string& xloc,
|
||||
|
||||
bool filter_loc(const gamemap::location& loc, const vconfig cfg)
|
||||
{
|
||||
const std::string xloc = cfg["x"];
|
||||
const std::string yloc = cfg["y"];
|
||||
const std::string& xloc = cfg["x"];
|
||||
const std::string& yloc = cfg["y"];
|
||||
|
||||
return filter_loc_impl(loc,xloc,yloc);
|
||||
}
|
||||
|
@ -991,6 +991,68 @@ namespace {
|
||||
const size_t MaxLoop = 1024;
|
||||
}
|
||||
|
||||
void game_state::get_variable_internal_const(const std::string& key, const config& cfg,
|
||||
const t_string** varout) const
|
||||
{
|
||||
//we get the variable from the [variables] section of the game state. Variables may
|
||||
//be in the format
|
||||
const std::string::const_iterator itor = std::find(key.begin(),key.end(),'.');
|
||||
if(itor != key.end()) {
|
||||
std::string element(key.begin(),itor);
|
||||
std::string sub_key(itor+1,key.end());
|
||||
|
||||
size_t index = 0;
|
||||
const std::string::iterator index_start = std::find(element.begin(),element.end(),'[');
|
||||
const bool explicit_index = index_start != element.end();
|
||||
|
||||
if(explicit_index) {
|
||||
const std::string::iterator index_end = std::find(index_start,element.end(),']');
|
||||
const std::string index_str(index_start+1,index_end);
|
||||
index = size_t(atoi(index_str.c_str()));
|
||||
if(index > MaxLoop) {
|
||||
LOG_NG << "get_variable_internal: index greater than " << MaxLoop
|
||||
<< ", truncated\n";
|
||||
index = MaxLoop;
|
||||
}
|
||||
|
||||
element = std::string(element.begin(),index_start);
|
||||
}
|
||||
|
||||
const config::child_list& items = cfg.get_children(element);
|
||||
|
||||
//special case -- '.length' on an array returns the size of the array
|
||||
if(explicit_index == false && sub_key == "length") {
|
||||
if(items.empty()) {
|
||||
if(varout != NULL) {
|
||||
static t_string zero_str = "";
|
||||
*varout = &zero_str;
|
||||
}
|
||||
} else {
|
||||
int size = minimum<int>(MaxLoop,int(items.size()));
|
||||
(*items.back())["__length"] = lexical_cast<std::string>(size);
|
||||
|
||||
if(varout != NULL) {
|
||||
*varout = &(*items.back())["__length"];
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(cfg.get_children(element).size() <= index) {
|
||||
static t_string empty_str = "";
|
||||
*varout = &empty_str;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
get_variable_internal_const(sub_key,*cfg.get_children(element)[index],varout);
|
||||
} else {
|
||||
if(varout != NULL) {
|
||||
*varout = &cfg[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
void game_state::get_variable_internal(const std::string& key, config& cfg,
|
||||
t_string** varout, config** cfgout)
|
||||
{
|
||||
@ -1024,7 +1086,7 @@ void game_state::get_variable_internal(const std::string& key, config& cfg,
|
||||
if(explicit_index == false && sub_key == "length") {
|
||||
if(items.empty()) {
|
||||
if(varout != NULL) {
|
||||
static t_string zero_str = "0";
|
||||
static t_string zero_str = "";
|
||||
*varout = &zero_str;
|
||||
}
|
||||
} else {
|
||||
@ -1068,9 +1130,16 @@ t_string& game_state::get_variable(const std::string& key)
|
||||
return empty_string;
|
||||
}
|
||||
|
||||
const t_string& game_state::get_variable_const(const std::string& key)
|
||||
const t_string& game_state::get_variable_const(const std::string& key) const
|
||||
{
|
||||
return get_variable(key);
|
||||
const t_string* res = NULL;
|
||||
get_variable_internal_const(key, variables, &res);
|
||||
if(res != NULL) {
|
||||
return *res;
|
||||
}
|
||||
|
||||
static t_string empty_string;
|
||||
return empty_string;
|
||||
}
|
||||
|
||||
config& game_state::get_variable_cfg(const std::string& key)
|
||||
|
@ -84,7 +84,7 @@ public:
|
||||
|
||||
//Variable access
|
||||
t_string& get_variable(const std::string& varname);
|
||||
virtual const t_string& get_variable_const(const std::string& varname);
|
||||
virtual const t_string& get_variable_const(const std::string& varname)const ;
|
||||
|
||||
config& get_variable_cfg(const std::string& varname);
|
||||
void set_variable(const std::string& varname, const t_string& value);
|
||||
@ -108,6 +108,8 @@ public:
|
||||
private:
|
||||
void get_variable_internal(const std::string& key, config& cfg,
|
||||
t_string** varout, config** cfgout);
|
||||
void get_variable_internal_const(const std::string& key, const config& cfg,
|
||||
const t_string** varout) const;
|
||||
};
|
||||
|
||||
//class which contains the global status of the game -- namely
|
||||
|
@ -34,7 +34,7 @@ namespace {
|
||||
|
||||
bool two_dots(char a, char b) { return a == '.' && b == '.'; }
|
||||
|
||||
std::string do_interpolation(const std::string &str, variable_set& set)
|
||||
std::string do_interpolation(const std::string &str, const variable_set& set)
|
||||
{
|
||||
std::string res = str;
|
||||
//this needs to be able to store negative numbers to check for the while's condition
|
||||
@ -297,7 +297,7 @@ class string_map_variable_set : public variable_set
|
||||
public:
|
||||
string_map_variable_set(const string_map& map) : map_(map) {};
|
||||
|
||||
virtual const t_string& get_variable_const(const std::string& key)
|
||||
virtual const t_string& get_variable_const (const std::string& key) const
|
||||
{
|
||||
static const t_string empty_string = "";
|
||||
|
||||
@ -319,7 +319,7 @@ std::string interpolate_variables_into_string(const std::string &str, const stri
|
||||
return do_interpolation(str, set);
|
||||
}
|
||||
|
||||
std::string interpolate_variables_into_string(const std::string &str, variable_set& variables)
|
||||
std::string interpolate_variables_into_string(const std::string &str, const variable_set& variables)
|
||||
{
|
||||
return do_interpolation(str, variables);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class variable_set
|
||||
public:
|
||||
virtual ~variable_set();
|
||||
|
||||
virtual const t_string& get_variable_const(const std::string& id) = 0;
|
||||
virtual const t_string& get_variable_const(const std::string& id) const = 0;
|
||||
};
|
||||
|
||||
//the type we use to represent Unicode strings.
|
||||
@ -71,7 +71,7 @@ typedef std::map< std::string, t_string > string_map;
|
||||
// the equivalent symbols in the given symbol table. If 'symbols' is NULL, then game event
|
||||
// variables will be used instead
|
||||
std::string interpolate_variables_into_string(std::string const &str, string_map const *symbols);
|
||||
std::string interpolate_variables_into_string(std::string const &str, variable_set& variables);
|
||||
std::string interpolate_variables_into_string(std::string const &str, const variable_set& variables);
|
||||
|
||||
//functions for converting Unicode wide-char strings to UTF-8 encoded
|
||||
//strings, back and forth
|
||||
|
@ -112,18 +112,18 @@ const attack_animation& attack_type::animation(const display& disp, const gamema
|
||||
|
||||
bool attack_type::matches_filter(const config& cfg,bool self) const
|
||||
{
|
||||
const std::string& filter_range = cfg["range"];
|
||||
const t_string& filter_name = cfg["name"];
|
||||
const std::string& filter_type = cfg["type"];
|
||||
const std::string& filter_special = cfg["special"];
|
||||
const std::vector<std::string>& filter_range = utils::split(cfg["range"]);
|
||||
const std::vector<std::string> filter_name = utils::split(cfg["name"]);
|
||||
const std::vector<std::string> filter_type = utils::split(cfg["type"]);
|
||||
const std::string filter_special = cfg["special"];
|
||||
|
||||
if(filter_range.empty() == false && filter_range != range())
|
||||
if(filter_range.empty() == false && std::find(filter_range.begin(),filter_range.end(),range()) == filter_range.end())
|
||||
return false;
|
||||
|
||||
if(filter_name.empty() == false && filter_name != name())
|
||||
if(filter_name.empty() == false && std::find(filter_name.begin(),filter_name.end(),name()) == filter_name.end())
|
||||
return false;
|
||||
|
||||
if(filter_type.empty() == false && filter_type != type())
|
||||
if(filter_type.empty() == false && std::find(filter_type.begin(),filter_type.end(),type()) == filter_type.end())
|
||||
return false;
|
||||
|
||||
if(!self && filter_special.empty() == false && !get_special_bool(filter_special,true))
|
||||
|
@ -98,45 +98,44 @@ vconfig vconfig::child(const std::string& key) const
|
||||
return tmp;
|
||||
}
|
||||
|
||||
const t_string vconfig::operator[](const std::string& key) const
|
||||
const t_string &vconfig::operator[](const std::string& key) const
|
||||
{
|
||||
return expand(key);
|
||||
}
|
||||
|
||||
const t_string vconfig::expand(const std::string& key) const
|
||||
const t_string &vconfig::expand(const std::string& key) const
|
||||
{
|
||||
const t_string& val = (*cfg_)[key];
|
||||
|
||||
if(!val.str().empty() && val.str()[0] == '$') {
|
||||
std::string tmp = val.str();
|
||||
// stupid const
|
||||
config grr = local_vars_;
|
||||
// first expand local variables
|
||||
tmp = utils::interpolate_variables_into_string(val.str(),grr);
|
||||
if(tmp.empty()) tmp = val.str();
|
||||
// now expand global variables
|
||||
if(repos != NULL && !tmp.empty() && tmp[0] == '$') {
|
||||
tmp = repos->get_variable(tmp.substr(1));
|
||||
if(tmp.empty()) tmp = val.str();
|
||||
// we didn't find the variable in global, look in local
|
||||
const t_string &tmp = local_vars_.get_variable_const(val.str().substr(1));
|
||||
if(!tmp.str().empty()) {
|
||||
return tmp;
|
||||
}
|
||||
// now expand global variables
|
||||
if(repos != NULL ) {
|
||||
const t_string &tmp2 = repos->get_variable_const(val.str().substr(1));
|
||||
if(!tmp2.str().empty()) {
|
||||
return tmp2;
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
const t_string vconfig::get_attribute(const std::string& key) const
|
||||
const t_string &vconfig::get_attribute(const std::string& key) const
|
||||
{
|
||||
return (*cfg_)[key];
|
||||
}
|
||||
|
||||
void vconfig::add_local_var(std::string var_name, config& var)
|
||||
{
|
||||
local_vars_.add_child(var_name,var);
|
||||
local_vars_.variables.add_child(var_name,var);
|
||||
}
|
||||
void vconfig::rem_local_var(std::string var_name)
|
||||
{
|
||||
local_vars_.clear_children(var_name);
|
||||
local_vars_.variables.clear_children(var_name);
|
||||
}
|
||||
namespace variable
|
||||
{
|
||||
|
@ -19,8 +19,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
class t_string;
|
||||
struct game_state;
|
||||
|
||||
/**
|
||||
* A variable-expanding proxy for the config class. This class roughly behaves
|
||||
@ -43,15 +43,15 @@ public:
|
||||
child_list get_children(const std::string& key) const;
|
||||
vconfig child(const std::string& key) const;
|
||||
|
||||
const t_string operator[](const std::string&) const;
|
||||
const t_string expand(const std::string&) const; /** < Synonym for operator[] */
|
||||
const t_string get_attribute(const std::string&) const;
|
||||
const t_string& operator[](const std::string&) const;
|
||||
const t_string& expand(const std::string&) const; /** < Synonym for operator[] */
|
||||
const t_string& get_attribute(const std::string&) const;
|
||||
void add_local_var(std::string var_name, config& var);
|
||||
void rem_local_var(std::string var_name);
|
||||
|
||||
private:
|
||||
const config* cfg_;
|
||||
config local_vars_;
|
||||
game_state local_vars_;
|
||||
};
|
||||
|
||||
namespace variable
|
||||
|
Loading…
x
Reference in New Issue
Block a user