LuaAI: fixed bug that always cause ai.attack() to use -1 as the weapon
This commit is contained in:
parent
d2ca37420b
commit
d7f6b2c26e
2 changed files with 8 additions and 5 deletions
|
@ -303,7 +303,7 @@ function my_ai:do_moves()
|
|||
--! full move. note that the my_leader still can be used altrough x and y are now different.
|
||||
--ai.check_move(my_leader, 11, 23)
|
||||
--! attack with auto weapon/aggression
|
||||
ai.attack(2, 12, 3, 12, 2)
|
||||
ai.attack(2, 12, 3, 12, 4, 10)
|
||||
--! attack with weapon selected
|
||||
ai.check_attack(3, 11, 3, 12, 1)
|
||||
--! attack with different aggression
|
||||
|
|
|
@ -220,16 +220,19 @@ static int ai_attack(lua_State *L, bool exec)
|
|||
int attacker_weapon = -1;//-1 means 'select what is best'
|
||||
double aggression = context.get_aggression();//use the aggression from the context
|
||||
|
||||
if (!lua_isnoneornil(L, index + 1) && attacker_weapon != -1) {
|
||||
attacker_weapon = lua_tointeger(L, index + 1) - 1; // Done for consistency of the Lua style
|
||||
if (!lua_isnoneornil(L, index)) {
|
||||
attacker_weapon = lua_tointeger(L, index);
|
||||
if (attacker_weapon != -1) {
|
||||
attacker_weapon--; // Done for consistency of the Lua style
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Right now, aggression is used by the attack execution functions to determine the weapon to be used.
|
||||
// If a decision is made to expand the function that determines the weapon, this block must be refactored
|
||||
// to parse aggression if a single int is on the stack, or create a table of parameters, if a table is on the
|
||||
// stack.
|
||||
if (!lua_isnoneornil(L, index) && lua_isnumber(L,index)) {
|
||||
aggression = lua_tonumber(L, index);
|
||||
if (!lua_isnoneornil(L, index + 1) && lua_isnumber(L,index + 1)) {
|
||||
aggression = lua_tonumber(L, index + 1);
|
||||
}
|
||||
|
||||
ai::attack_result_ptr attack_result = ai::actions::execute_attack_action(side,exec,attacker,defender,attacker_weapon,aggression);
|
||||
|
|
Loading…
Add table
Reference in a new issue