mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-29 08:49:30 +00:00
allow wesnoth.simulate_combat to have defenders not on the map.
just like it does for attackers.
This commit is contained in:
parent
d10c51feb1
commit
dccda8294b
@ -398,14 +398,16 @@ battle_context::battle_context(const unit_map& units,
|
|||||||
int defender_weapon,
|
int defender_weapon,
|
||||||
double aggression,
|
double aggression,
|
||||||
const combatant* prev_def,
|
const combatant* prev_def,
|
||||||
const unit* attacker_ptr)
|
const unit* attacker_ptr,
|
||||||
|
const unit* defender_ptr)
|
||||||
: attacker_stats_(nullptr)
|
: attacker_stats_(nullptr)
|
||||||
, defender_stats_(nullptr)
|
, defender_stats_(nullptr)
|
||||||
, attacker_combatant_(nullptr)
|
, attacker_combatant_(nullptr)
|
||||||
, defender_combatant_(nullptr)
|
, defender_combatant_(nullptr)
|
||||||
{
|
{
|
||||||
|
//TODO: maybe check before dereferencing units.find(attacker_loc),units.find(defender_loc) ?
|
||||||
const unit& attacker = attacker_ptr ? *attacker_ptr : *units.find(attacker_loc);
|
const unit& attacker = attacker_ptr ? *attacker_ptr : *units.find(attacker_loc);
|
||||||
const unit& defender = *units.find(defender_loc);
|
const unit& defender = defender_ptr ? *defender_ptr : *units.find(defender_loc);
|
||||||
const double harm_weight = 1.0 - aggression;
|
const double harm_weight = 1.0 - aggression;
|
||||||
|
|
||||||
if(attacker_weapon == -1) {
|
if(attacker_weapon == -1) {
|
||||||
|
@ -183,7 +183,8 @@ public:
|
|||||||
int defender_weapon = -1,
|
int defender_weapon = -1,
|
||||||
double aggression = 0.0,
|
double aggression = 0.0,
|
||||||
const combatant* prev_def = nullptr,
|
const combatant* prev_def = nullptr,
|
||||||
const unit* attacker_ptr = nullptr);
|
const unit* attacker_ptr = nullptr,
|
||||||
|
const unit* defender_ptr = nullptr);
|
||||||
|
|
||||||
/** Used by the AI which caches battle_context_unit_stats */
|
/** Used by the AI which caches battle_context_unit_stats */
|
||||||
battle_context(const battle_context_unit_stats& att, const battle_context_unit_stats& def);
|
battle_context(const battle_context_unit_stats& att, const battle_context_unit_stats& def);
|
||||||
|
@ -2626,6 +2626,7 @@ static void luaW_pushsimweapon(lua_State *L, const battle_context_unit_stats &bc
|
|||||||
* - Arg 2: optional weapon index.
|
* - Arg 2: optional weapon index.
|
||||||
* - Arg 3: defender userdata.
|
* - Arg 3: defender userdata.
|
||||||
* - Arg 4: optional weapon index.
|
* - Arg 4: optional weapon index.
|
||||||
|
*
|
||||||
* - Ret 1: attacker results.
|
* - Ret 1: attacker results.
|
||||||
* - Ret 2: defender results.
|
* - Ret 2: defender results.
|
||||||
* - Ret 3: info about the attacker weapon.
|
* - Ret 3: info about the attacker weapon.
|
||||||
@ -2644,7 +2645,7 @@ int game_lua_kernel::intf_simulate_combat(lua_State *L)
|
|||||||
++arg_num;
|
++arg_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unit& def = luaW_checkunit(L, arg_num, true);
|
const unit& def = luaW_checkunit(L, arg_num);
|
||||||
++arg_num;
|
++arg_num;
|
||||||
if (lua_isnumber(L, arg_num)) {
|
if (lua_isnumber(L, arg_num)) {
|
||||||
def_w = lua_tointeger(L, arg_num) - 1;
|
def_w = lua_tointeger(L, arg_num) - 1;
|
||||||
@ -2654,7 +2655,7 @@ int game_lua_kernel::intf_simulate_combat(lua_State *L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
battle_context context(units(), att.get_location(),
|
battle_context context(units(), att.get_location(),
|
||||||
def.get_location(), att_w, def_w, 0.0, nullptr, &att);
|
def.get_location(), att_w, def_w, 0.0, nullptr, &att, &def);
|
||||||
|
|
||||||
luaW_pushsimdata(L, context.get_attacker_combatant());
|
luaW_pushsimdata(L, context.get_attacker_combatant());
|
||||||
luaW_pushsimdata(L, context.get_defender_combatant());
|
luaW_pushsimdata(L, context.get_defender_combatant());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user