Unify the Lua and WFL interfaces to the movement type
See changelog for details.
This commit is contained in:
parent
0ecae9de17
commit
153680400d
5 changed files with 293 additions and 56 deletions
|
@ -60,6 +60,13 @@
|
|||
* Functions that previously only took a side index as the first parameter now also accept the side proxy userdata.
|
||||
* The wesnoth.sides module acts like a metatable for the side userdata.
|
||||
* Added `__tostring` functions to a number of Wesnoth userdata types.
|
||||
* Unit movetype functions renamed (defense_on, movement_on, vision_on, jamming_on, resistance_against).
|
||||
The defense_on and resistance_against functions return the actual values, rather than the raw WML values.
|
||||
* New function wesnoth.units.chance_to_be_hit is equivalent to deprecated wesonth.units.defense but conveys the meaning better.
|
||||
* Unit movetype functions (excluding resistance) can take a location instead of a terrain code, for convenience
|
||||
### WFL engine
|
||||
* New functions resistance_on(), vision_cost(), jamming_cost() that work in gameplay contexts (eg filters)
|
||||
* Unit object now has resistance, defense, movement_cost, vision_cost, jamming_cost, flying variables
|
||||
### WML engine
|
||||
* Support upkeep in StandardUnitFilter
|
||||
* [effect]apply_to=variation now supports heal_full
|
||||
|
|
|
@ -523,6 +523,15 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
|
|||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function wesnoth.units.chance_to_be_hit(...)
|
||||
return 100 - wesnoth.units.defense_on(...)
|
||||
end
|
||||
|
||||
-- Deprecated function
|
||||
function wesnoth.units.resistance(...)
|
||||
return 100 - wesnoth.units.resistance_against(...)
|
||||
end
|
||||
|
||||
--[========[Sides module]========]
|
||||
|
||||
|
@ -618,11 +627,16 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
|
|||
wesnoth.advance_unit = wesnoth.deprecate_api('wesnoth.advance_unit', 'wesnoth.units.advance', 1, nil, wesnoth.units.advance)
|
||||
wesnoth.add_modification = wesnoth.deprecate_api('wesnoth.add_modification', 'wesnoth.units.add_modification', 1, nil, wesnoth.units.add_modification)
|
||||
wesnoth.remove_modifications = wesnoth.deprecate_api('wesnoth.remove_modifications', 'wesnoth.units.remove_modifications', 1, nil, wesnoth.units.remove_modifications)
|
||||
wesnoth.unit_resistance = wesnoth.deprecate_api('wesnoth.unit_resistance', 'wesnoth.units.resistance', 1, nil, wesnoth.units.resistance)
|
||||
wesnoth.unit_defense = wesnoth.deprecate_api('wesnoth.unit_defense', 'wesnoth.units.defense', 1, nil, wesnoth.units.defense)
|
||||
wesnoth.unit_movement_cost = wesnoth.deprecate_api('wesnoth.unit_movement_cost', 'wesnoth.units.movement', 1, nil, wesnoth.units.movement)
|
||||
wesnoth.unit_vision_cost = wesnoth.deprecate_api('wesnoth.unit_vision_cost', 'wesnoth.units.vision', 1, nil, wesnoth.units.vision)
|
||||
wesnoth.unit_jamming_cost = wesnoth.deprecate_api('wesnoth.unit_jamming_cost', 'wesnoth.units.jamming', 1, nil, wesnoth.units.jamming)
|
||||
wesnoth.unit_resistance = wesnoth.deprecate_api('wesnoth.unit_resistance', 'wesnoth.units.resistance_against', 1, nil, wesnoth.units.resistance)
|
||||
wesnoth.unit_defense = wesnoth.deprecate_api('wesnoth.unit_defense', 'wesnoth.units.defense_on', 1, nil, wesnoth.units.chance_to_be_hit)
|
||||
wesnoth.unit_movement_cost = wesnoth.deprecate_api('wesnoth.unit_movement_cost', 'wesnoth.units.movement_on', 1, nil, wesnoth.units.movement_on)
|
||||
wesnoth.unit_vision_cost = wesnoth.deprecate_api('wesnoth.unit_vision_cost', 'wesnoth.units.vision_on', 1, nil, wesnoth.units.vision_on)
|
||||
wesnoth.unit_jamming_cost = wesnoth.deprecate_api('wesnoth.unit_jamming_cost', 'wesnoth.units.jamming_on', 1, nil, wesnoth.units.jamming_on)
|
||||
wesnoth.units.resistance = wesnoth.deprecate_api('wesnoth.units.resistance', 'wesnoth.units.resistance_against', 1, nil, wesnoth.units.resistance)
|
||||
wesnoth.units.defense = wesnoth.deprecate_api('wesnoth.units.defense', 'wesnoth.units.defense_on', 1, nil, wesnoth.units.chance_to_be_hit)
|
||||
wesnoth.units.movement_cost = wesnoth.deprecate_api('wesnoth.units.movement_cost', 'wesnoth.units.movement_on', 1, nil, wesnoth.units.movement_on)
|
||||
wesnoth.units.vision_cost = wesnoth.deprecate_api('wesnoth.units.vision_cost', 'wesnoth.units.vision_on', 1, nil, wesnoth.units.vision_on)
|
||||
wesnoth.units.jamming_cost = wesnoth.deprecate_api('wesnoth.units.jamming_cost', 'wesnoth.units.jamming_on', 1, nil, wesnoth.units.jamming_on)
|
||||
wesnoth.unit_ability = wesnoth.deprecate_api('wesnoth.unit_ability', 'wesnoth.units.ability', 1, nil, wesnoth.units.ability)
|
||||
wesnoth.transform_unit = wesnoth.deprecate_api('wesnoth.transform_unit', 'wesnoth.units.transform', 1, nil, wesnoth.units.transform)
|
||||
wesnoth.select_unit = wesnoth.deprecate_api('wesnoth.select_unit', 'wesnoth.units.select', 1, nil, wesnoth.units.select)
|
||||
|
|
|
@ -260,6 +260,35 @@ variant unit_callable::get_value(const std::string& key) const
|
|||
return variant(u_.alignment().to_string());
|
||||
} else if(key == "facing") {
|
||||
return variant(map_location::write_direction(u_.facing()));
|
||||
} else if(key == "resistance" || key == "movement_cost" || key == "vision_cost" || key == "jamming_cost" || key == "defense") {
|
||||
const auto& mt = u_.movement_type();
|
||||
config cfg;
|
||||
bool needs_flip = false;
|
||||
if(key == "resistance") {
|
||||
mt.get_resistances().write(cfg);
|
||||
needs_flip = true;
|
||||
} else if(key == "movement_cost") {
|
||||
mt.get_movement().write(cfg);
|
||||
} else if(key == "vision_cost") {
|
||||
mt.get_vision().write(cfg);
|
||||
} else if(key == "jamming_cost") {
|
||||
mt.get_vision().write(cfg);
|
||||
} else if(key == "defense") {
|
||||
mt.get_defense().write(cfg);
|
||||
needs_flip = true;
|
||||
}
|
||||
std::map<variant, variant> res;
|
||||
for(const auto& p : cfg.attribute_range()) {
|
||||
int val = p.second;
|
||||
if(needs_flip) {
|
||||
val = 100 - val;
|
||||
}
|
||||
res.emplace(p.first, val);
|
||||
}
|
||||
|
||||
return variant(res);
|
||||
} else if(key == "flying") {
|
||||
return variant(u_.is_flying());
|
||||
} else if(key == "vars") {
|
||||
if(u_.formula_manager().formula_vars()) {
|
||||
return variant(u_.formula_manager().formula_vars());
|
||||
|
@ -317,6 +346,12 @@ void unit_callable::get_inputs(formula_input_vector& inputs) const
|
|||
add_input(inputs, "zoc");
|
||||
add_input(inputs, "alignment");
|
||||
add_input(inputs, "facing");
|
||||
add_input(inputs, "resistance");
|
||||
add_input(inputs, "movement_cost");
|
||||
add_input(inputs, "vision_cost");
|
||||
add_input(inputs, "jamming_cost");
|
||||
add_input(inputs, "defense");
|
||||
add_input(inputs, "flying");
|
||||
add_input(inputs, "vars");
|
||||
add_input(inputs, "wml_vars");
|
||||
}
|
||||
|
|
|
@ -110,32 +110,40 @@ DEFINE_WFL_FUNCTION(defense_on, 2, 2)
|
|||
|
||||
auto u_call = u.try_convert<unit_callable>();
|
||||
auto u_type = u.try_convert<unit_type_callable>();
|
||||
const map_location& loc = loc_var.convert_to<location_callable>()->loc();
|
||||
|
||||
const auto& tdata = resources::gameboard->map().tdata();
|
||||
t_translation::terrain_code ter;
|
||||
|
||||
if(loc_var.is_string()) {
|
||||
ter = t_translation::read_terrain_code(loc_var.as_string());
|
||||
} else if(auto tc = loc_var.try_convert<terrain_callable>()) {
|
||||
const std::string id = tc->get_value("id").as_string();
|
||||
auto iter = std::find_if(tdata->map().begin(), tdata->map().end(), [id](const std::pair<t_translation::terrain_code, terrain_type>& p) {
|
||||
return id == p.second.id();
|
||||
});
|
||||
if(iter == tdata->map().end()) {
|
||||
return variant();
|
||||
}
|
||||
ter = iter->first;
|
||||
} else if(auto loc = loc_var.try_convert<location_callable>()) {
|
||||
if(!resources::gameboard->map().on_board(loc->loc())) {
|
||||
return variant();
|
||||
}
|
||||
ter = resources::gameboard->map().get_terrain(loc->loc());
|
||||
} else {
|
||||
return variant();
|
||||
}
|
||||
|
||||
if(u_call) {
|
||||
const unit& un = u_call->get_unit();
|
||||
|
||||
if(un.total_movement() < un.movement_cost((resources::gameboard->map())[loc]))
|
||||
return variant();
|
||||
|
||||
if(!resources::gameboard->map().on_board(loc)) {
|
||||
return variant();
|
||||
}
|
||||
|
||||
return variant(100 - un.defense_modifier((resources::gameboard->map())[loc]));
|
||||
return variant(100 - un.defense_modifier(ter));
|
||||
}
|
||||
|
||||
if(u_type) {
|
||||
const unit_type& un = u_type->get_unit_type();
|
||||
|
||||
if(un.movement() < un.movement_type().movement_cost((resources::gameboard->map())[loc]))
|
||||
return variant();
|
||||
|
||||
if(!resources::gameboard->map().on_board(loc)) {
|
||||
return variant();
|
||||
}
|
||||
|
||||
return variant(100 - un.movement_type().defense_modifier((resources::gameboard->map())[loc]));
|
||||
return variant(100 - un.movement_type().defense_modifier(ter));
|
||||
}
|
||||
|
||||
return variant();
|
||||
|
@ -151,26 +159,40 @@ DEFINE_WFL_FUNCTION(chance_to_hit, 2, 2)
|
|||
|
||||
auto u_call = u.try_convert<unit_callable>();
|
||||
auto u_type = u.try_convert<unit_type_callable>();
|
||||
const map_location& loc = loc_var.convert_to<location_callable>()->loc();
|
||||
|
||||
const auto& tdata = resources::gameboard->map().tdata();
|
||||
t_translation::terrain_code ter;
|
||||
|
||||
if(loc_var.is_string()) {
|
||||
ter = t_translation::read_terrain_code(loc_var.as_string());
|
||||
} else if(auto tc = loc_var.try_convert<terrain_callable>()) {
|
||||
const std::string id = tc->get_value("id").as_string();
|
||||
auto iter = std::find_if(tdata->map().begin(), tdata->map().end(), [id](const std::pair<t_translation::terrain_code, terrain_type>& p) {
|
||||
return id == p.second.id();
|
||||
});
|
||||
if(iter == tdata->map().end()) {
|
||||
return variant();
|
||||
}
|
||||
ter = iter->first;
|
||||
} else if(auto loc = loc_var.try_convert<location_callable>()) {
|
||||
if(!resources::gameboard->map().on_board(loc->loc())) {
|
||||
return variant();
|
||||
}
|
||||
ter = resources::gameboard->map().get_terrain(loc->loc());
|
||||
} else {
|
||||
return variant();
|
||||
}
|
||||
|
||||
if(u_call) {
|
||||
const unit& un = u_call->get_unit();
|
||||
|
||||
if(!resources::gameboard->map().on_board(loc)) {
|
||||
return variant();
|
||||
}
|
||||
|
||||
return variant(un.defense_modifier((resources::gameboard->map())[loc]));
|
||||
return variant(un.defense_modifier((ter)));
|
||||
}
|
||||
|
||||
if(u_type) {
|
||||
const unit_type& un = u_type->get_unit_type();
|
||||
|
||||
if(!resources::gameboard->map().on_board(loc)) {
|
||||
return variant();
|
||||
}
|
||||
|
||||
return variant(un.movement_type().defense_modifier((resources::gameboard->map())[loc]));
|
||||
return variant(un.movement_type().defense_modifier((ter)));
|
||||
}
|
||||
|
||||
return variant();
|
||||
|
@ -186,26 +208,138 @@ DEFINE_WFL_FUNCTION(movement_cost, 2, 2)
|
|||
//we can pass to this function either unit_callable or unit_type callable
|
||||
auto u_call = u.try_convert<unit_callable>();
|
||||
auto u_type = u.try_convert<unit_type_callable>();
|
||||
const map_location& loc = loc_var.convert_to<location_callable>()->loc();
|
||||
|
||||
const auto& tdata = resources::gameboard->map().tdata();
|
||||
t_translation::terrain_code ter;
|
||||
|
||||
if(loc_var.is_string()) {
|
||||
ter = t_translation::read_terrain_code(loc_var.as_string());
|
||||
} else if(auto tc = loc_var.try_convert<terrain_callable>()) {
|
||||
const std::string id = tc->get_value("id").as_string();
|
||||
auto iter = std::find_if(tdata->map().begin(), tdata->map().end(), [id](const std::pair<t_translation::terrain_code, terrain_type>& p) {
|
||||
return id == p.second.id();
|
||||
});
|
||||
if(iter == tdata->map().end()) {
|
||||
return variant();
|
||||
}
|
||||
ter = iter->first;
|
||||
} else if(auto loc = loc_var.try_convert<location_callable>()) {
|
||||
if(!resources::gameboard->map().on_board(loc->loc())) {
|
||||
return variant();
|
||||
}
|
||||
ter = resources::gameboard->map().get_terrain(loc->loc());
|
||||
} else {
|
||||
return variant();
|
||||
}
|
||||
|
||||
if(u_call) {
|
||||
const unit& un = u_call->get_unit();
|
||||
|
||||
if(!resources::gameboard->map().on_board(loc)) {
|
||||
return variant();
|
||||
}
|
||||
|
||||
return variant(un.movement_cost((resources::gameboard->map())[loc]));
|
||||
return variant(un.movement_cost(ter));
|
||||
}
|
||||
|
||||
if(u_type) {
|
||||
const unit_type& un = u_type->get_unit_type();
|
||||
|
||||
if(!resources::gameboard->map().on_board(loc)) {
|
||||
return variant(un.movement_type().movement_cost(ter));
|
||||
}
|
||||
|
||||
return variant();
|
||||
}
|
||||
|
||||
DEFINE_WFL_FUNCTION(vision_cost, 2, 2)
|
||||
{
|
||||
variant u = args()[0]->evaluate(variables, add_debug_info(fdb, 0, "vision_cost:unit"));
|
||||
variant loc_var = args()[1]->evaluate(variables, add_debug_info(fdb, 0, "vision_cost:location"));
|
||||
if(u.is_null() || loc_var.is_null()) {
|
||||
return variant();
|
||||
}
|
||||
//we can pass to this function either unit_callable or unit_type callable
|
||||
auto u_call = u.try_convert<unit_callable>();
|
||||
auto u_type = u.try_convert<unit_type_callable>();
|
||||
|
||||
const auto& tdata = resources::gameboard->map().tdata();
|
||||
t_translation::terrain_code ter;
|
||||
|
||||
if(loc_var.is_string()) {
|
||||
ter = t_translation::read_terrain_code(loc_var.as_string());
|
||||
} else if(auto tc = loc_var.try_convert<terrain_callable>()) {
|
||||
const std::string id = tc->get_value("id").as_string();
|
||||
auto iter = std::find_if(tdata->map().begin(), tdata->map().end(), [id](const std::pair<t_translation::terrain_code, terrain_type>& p) {
|
||||
return id == p.second.id();
|
||||
});
|
||||
if(iter == tdata->map().end()) {
|
||||
return variant();
|
||||
}
|
||||
ter = iter->first;
|
||||
} else if(auto loc = loc_var.try_convert<location_callable>()) {
|
||||
if(!resources::gameboard->map().on_board(loc->loc())) {
|
||||
return variant();
|
||||
}
|
||||
ter = resources::gameboard->map().get_terrain(loc->loc());
|
||||
} else {
|
||||
return variant();
|
||||
}
|
||||
|
||||
return variant(un.movement_type().movement_cost((resources::gameboard->map())[loc]));
|
||||
if(u_call) {
|
||||
const unit& un = u_call->get_unit();
|
||||
|
||||
return variant(un.vision_cost(ter));
|
||||
}
|
||||
|
||||
if(u_type) {
|
||||
const unit_type& un = u_type->get_unit_type();
|
||||
|
||||
return variant(un.movement_type().vision_cost(ter));
|
||||
}
|
||||
|
||||
return variant();
|
||||
}
|
||||
|
||||
DEFINE_WFL_FUNCTION(jamming_cost, 2, 2)
|
||||
{
|
||||
variant u = args()[0]->evaluate(variables, add_debug_info(fdb, 0, "jamming_cost:unit"));
|
||||
variant loc_var = args()[1]->evaluate(variables, add_debug_info(fdb, 0, "jamming_cost:location"));
|
||||
if(u.is_null() || loc_var.is_null()) {
|
||||
return variant();
|
||||
}
|
||||
//we can pass to this function either unit_callable or unit_type callable
|
||||
auto u_call = u.try_convert<unit_callable>();
|
||||
auto u_type = u.try_convert<unit_type_callable>();
|
||||
|
||||
const auto& tdata = resources::gameboard->map().tdata();
|
||||
t_translation::terrain_code ter;
|
||||
|
||||
if(loc_var.is_string()) {
|
||||
ter = t_translation::read_terrain_code(loc_var.as_string());
|
||||
} else if(auto tc = loc_var.try_convert<terrain_callable>()) {
|
||||
const std::string id = tc->get_value("id").as_string();
|
||||
auto iter = std::find_if(tdata->map().begin(), tdata->map().end(), [id](const std::pair<t_translation::terrain_code, terrain_type>& p) {
|
||||
return id == p.second.id();
|
||||
});
|
||||
if(iter == tdata->map().end()) {
|
||||
return variant();
|
||||
}
|
||||
ter = iter->first;
|
||||
} else if(auto loc = loc_var.try_convert<location_callable>()) {
|
||||
if(!resources::gameboard->map().on_board(loc->loc())) {
|
||||
return variant();
|
||||
}
|
||||
ter = resources::gameboard->map().get_terrain(loc->loc());
|
||||
} else {
|
||||
return variant();
|
||||
}
|
||||
|
||||
if(u_call) {
|
||||
const unit& un = u_call->get_unit();
|
||||
|
||||
return variant(un.jamming_cost(ter));
|
||||
}
|
||||
|
||||
if(u_type) {
|
||||
const unit_type& un = u_type->get_unit_type();
|
||||
|
||||
return variant(un.movement_type().jamming_cost(ter));
|
||||
}
|
||||
|
||||
return variant();
|
||||
|
@ -242,6 +376,26 @@ DEFINE_WFL_FUNCTION(enemy_of, 2, 2)
|
|||
return variant(resources::gameboard->get_team(self).is_enemy(other) ? 1 : 0);
|
||||
}
|
||||
|
||||
DEFINE_WFL_FUNCTION(resistance_on, 3, 4)
|
||||
{
|
||||
variant u = args()[0]->evaluate(variables, add_debug_info(fdb, 0, "resistance_on:unit"));
|
||||
variant loc_var = args()[1]->evaluate(variables, add_debug_info(fdb, 1, "resistance_on:location"));
|
||||
if(u.is_null() || loc_var.is_null()) {
|
||||
return variant();
|
||||
}
|
||||
std::string type = args()[2]->evaluate(variables, add_debug_info(fdb, 2, "resistance_on:type")).as_string();
|
||||
bool attacker = args().size() > 3 ? args()[3]->evaluate(variables, add_debug_info(fdb, 3, "resistance_on:attacker")).as_bool() : false;
|
||||
const map_location& loc = loc_var.convert_to<location_callable>()->loc();
|
||||
|
||||
if(auto u_call = u.try_convert<unit_callable>()) {
|
||||
const unit& un = u_call->get_unit();
|
||||
|
||||
return variant(100 - un.resistance_against(type, attacker, loc));
|
||||
}
|
||||
|
||||
return variant();
|
||||
}
|
||||
|
||||
} // namespace gamestate
|
||||
|
||||
gamestate_function_symbol_table::gamestate_function_symbol_table(std::shared_ptr<function_symbol_table> parent) : function_symbol_table(parent) {
|
||||
|
@ -249,9 +403,12 @@ gamestate_function_symbol_table::gamestate_function_symbol_table(std::shared_ptr
|
|||
function_symbol_table& functions_table = *this;
|
||||
DECLARE_WFL_FUNCTION(get_unit_type);
|
||||
DECLARE_WFL_FUNCTION(unit_at);
|
||||
DECLARE_WFL_FUNCTION(resistance_on);
|
||||
DECLARE_WFL_FUNCTION(defense_on);
|
||||
DECLARE_WFL_FUNCTION(chance_to_hit);
|
||||
DECLARE_WFL_FUNCTION(movement_cost);
|
||||
DECLARE_WFL_FUNCTION(vision_cost);
|
||||
DECLARE_WFL_FUNCTION(jamming_cost);
|
||||
DECLARE_WFL_FUNCTION(adjacent_locs); // This is deliberately duplicated here; this form excludes off-map locations, while the core form does not
|
||||
DECLARE_WFL_FUNCTION(locations_in_radius);
|
||||
DECLARE_WFL_FUNCTION(enemy_of);
|
||||
|
|
|
@ -2412,7 +2412,7 @@ static int intf_unit_resistance(lua_State *L)
|
|||
loc = luaW_checklocation(L, 3);
|
||||
}
|
||||
|
||||
lua_pushinteger(L, u.resistance_against(m, a, loc));
|
||||
lua_pushinteger(L, 100 - u.resistance_against(m, a, loc));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -2425,8 +2425,14 @@ static int intf_unit_resistance(lua_State *L)
|
|||
static int intf_unit_movement_cost(lua_State *L)
|
||||
{
|
||||
const unit& u = luaW_checkunit(L, 1);
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t_translation::terrain_code t = t_translation::read_terrain_code(m);
|
||||
t_translation::terrain_code t;
|
||||
map_location loc;
|
||||
if(luaW_tolocation(L, 2, loc)) {
|
||||
t = resources::gameboard->map()[loc];
|
||||
} else if(lua_isstring(L, 2)) {
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t = t_translation::read_terrain_code(m);
|
||||
} else return luaW_type_error(L, 2, "location or terrain string");
|
||||
lua_pushinteger(L, u.movement_cost(t));
|
||||
return 1;
|
||||
}
|
||||
|
@ -2440,8 +2446,14 @@ static int intf_unit_movement_cost(lua_State *L)
|
|||
static int intf_unit_vision_cost(lua_State *L)
|
||||
{
|
||||
const unit& u = luaW_checkunit(L, 1);
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t_translation::terrain_code t = t_translation::read_terrain_code(m);
|
||||
t_translation::terrain_code t;
|
||||
map_location loc;
|
||||
if(luaW_tolocation(L, 2, loc)) {
|
||||
t = resources::gameboard->map()[loc];
|
||||
} else if(lua_isstring(L, 2)) {
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t = t_translation::read_terrain_code(m);
|
||||
} else return luaW_type_error(L, 2, "location or terrain string");
|
||||
lua_pushinteger(L, u.vision_cost(t));
|
||||
return 1;
|
||||
}
|
||||
|
@ -2455,8 +2467,14 @@ static int intf_unit_vision_cost(lua_State *L)
|
|||
static int intf_unit_jamming_cost(lua_State *L)
|
||||
{
|
||||
const unit& u = luaW_checkunit(L, 1);
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t_translation::terrain_code t = t_translation::read_terrain_code(m);
|
||||
t_translation::terrain_code t;
|
||||
map_location loc;
|
||||
if(luaW_tolocation(L, 2, loc)) {
|
||||
t = resources::gameboard->map()[loc];
|
||||
} else if(lua_isstring(L, 2)) {
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t = t_translation::read_terrain_code(m);
|
||||
} else return luaW_type_error(L, 2, "location or terrain string");
|
||||
lua_pushinteger(L, u.jamming_cost(t));
|
||||
return 1;
|
||||
}
|
||||
|
@ -2470,9 +2488,15 @@ static int intf_unit_jamming_cost(lua_State *L)
|
|||
static int intf_unit_defense(lua_State *L)
|
||||
{
|
||||
const unit& u = luaW_checkunit(L, 1);
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t_translation::terrain_code t = t_translation::read_terrain_code(m);
|
||||
lua_pushinteger(L, u.defense_modifier(t));
|
||||
t_translation::terrain_code t;
|
||||
map_location loc;
|
||||
if(luaW_tolocation(L, 2, loc)) {
|
||||
t = resources::gameboard->map()[loc];
|
||||
} else if(lua_isstring(L, 2)) {
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
t = t_translation::read_terrain_code(m);
|
||||
} else return luaW_type_error(L, 2, "location or terrain string");
|
||||
lua_pushinteger(L, 100 - u.defense_modifier(t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -4308,11 +4332,11 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
|
|||
{"transform", &intf_transform_unit},
|
||||
|
||||
{"ability", &dispatch<&game_lua_kernel::intf_unit_ability>},
|
||||
{"defense", &intf_unit_defense},
|
||||
{"jamming", &intf_unit_jamming_cost},
|
||||
{"movement", &intf_unit_movement_cost},
|
||||
{"resistance", intf_unit_resistance},
|
||||
{"vision", &intf_unit_vision_cost},
|
||||
{"defense_on", &intf_unit_defense},
|
||||
{"jamming_on", &intf_unit_jamming_cost},
|
||||
{"movement_on", &intf_unit_movement_cost},
|
||||
{"resistance_against", intf_unit_resistance},
|
||||
{"vision_on", &intf_unit_vision_cost},
|
||||
|
||||
{"add_modification", &intf_add_modification},
|
||||
{"remove_modifications", &intf_remove_modifications},
|
||||
|
|
Loading…
Add table
Reference in a new issue