Commit graph

360 commits

Author SHA1 Message Date
mattsc
bd1b45e814 ai_helper checked actions: move error string into call to error()
… rather than making it a separate message.
2016-10-21 17:25:11 -07:00
mattsc
74792845d7 ai_helper.movefull_stopunit: return action result to calling function 2016-10-21 07:26:26 -07:00
mattsc
13d2cdfc29 ai_helper checked actions: return action result to calling function 2016-10-21 07:22:45 -07:00
mattsc
204ccb0584 ai_helper: move checks for incomplete/empty moves to functions 2016-10-21 07:04:02 -07:00
mattsc
022d2cd725 ai_helper checked actions: some modifications to error messages 2016-10-21 06:46:41 -07:00
mattsc
f2406ac829 Experimental AI: correctly deal with hidden and petrified units 2016-10-19 07:37:19 -07:00
Charles Dang
e8a499fcec Merge pull request #822 from GregoryLundberg/GL_Upgrade_Lua
Upgrade to Lua 5.3.3+
2016-10-18 12:58:12 +11:00
mattsc
1bed30c8c3 High XP Attack CA: respect the attacks aspect 2016-10-17 17:59:03 -07:00
mattsc
a333b9a5b7 High XP Attack CA: correctly deal with hidden and petrified units 2016-10-17 17:59:03 -07:00
Celtic Minstrel
e81131fcc5 Add deprecation messages for old AI aspect fetchers
This commit also updates uses of these fetchers in mainline Lua code.
2016-10-17 14:24:51 -04:00
Gregory A Lundberg
fc6774289e Upgrade deprecated Lua
loadstring was removed, load does the same thing.
atan2 was remvoed, atan works instead
2016-10-17 10:34:43 -05:00
mattsc
5770fa74f0 ai_helper: check variable type when viewing_side is required parameter
This is done because the code will not complain but silently produce
non-sensical results if, for example, the filter is passed as the first
argument to get_visible_units().
2016-10-12 07:42:33 -07:00
mattsc
c91a65dde4 ai_helper check unit functions: also check if unit exists 2016-10-10 07:43:38 -07:00
mattsc
f28d4336bf ai_helper.move_unit_out_of_way: normalize dx/dy here
Instead of making it a requirement that they should be normalized by
the calling function.
2016-10-09 14:25:15 -07:00
mattsc
1a5e9051a8 ai_helper: correctly and consistently deal with invisible units
Previously, some functions saw invisible units, while others did not.
Moreover, this behavior could be triggered on and off for some
functions, but not for others, and the parameter to do so was not the
same in all cases.

Now, the default setting for all ai_helper functions is to ignore
invisible units and this can be turned on and off with the same
parameter, viewing_side, with the same syntax and meaning as for the
built-in functions wesnoth.find_path() and wesnoth.find_reach(). This
means hat it can be passed directly between those functions and all the
ai_helper functions.
2016-10-09 08:51:13 -07:00
mattsc
8ad055e77f ai_helper: remove double spaces after punctuation 2016-10-05 19:30:47 -07:00
mattsc
e65a460342 ai_helper: add E_FAILED_TELEPORT to list of non-fatal move errors 2016-10-05 19:28:52 -07:00
mattsc
75817d3ba4 ai_helper: new function robust_move_and_attack() 2016-10-05 19:19:25 -07:00
mattsc
e38dd8ff16 ai_helper: new utility functions to find attackable enemies
Attackable enemies are defined as visible (can’t attack it if I can’t
see it) and not petrified.

This is in preparation for making the Micro AIs deal correctly with
hidden and petrified enemies.
2016-10-04 17:17:16 -07:00
mattsc
b00e6d5d96 ai_helper.LS_to_triples: fix function name
For consistency with LS_of_triples.
2016-10-04 17:17:16 -07:00
mattsc
52826a3824 High XP attack CA: do not try to attack petrified enemies 2016-10-02 09:13:54 -07:00
mattsc
371b9b67ec Lua AI helper functions: remove attacks/moves on failed action
If this is not done, there are some rare cases in which a Lua AI might
get caught in an infinite loop by trying the same failed action over
and over again.
2016-10-02 09:13:54 -07:00
mattsc
3d0c29b7fc Experimental AI: do not let AI try to recruit on fogged/shrouded hexes
The engine will refuse to recruit on shrouded hexes, which will result
in part or all of the rest of the AI actions to be disabled.  Fogged
hexes may cause problems also if there is an enemy unit on them.

This fixes at least part of bug #25112.
2016-09-24 19:17:39 -07:00
mattsc
20a8a2f456 High XP attack CA: fix rare case of AI choosing wrong weapon
Because the attack simulation during CA evaluation is done with enemy
XP set to zero, the AI previously sometimes chose a different weapon
during execution than what was used for evaluation. This resulted, for
example, in archers sometimes attacking an enemy without ranged attacks
with their melee attack when aggression=1.
2016-09-23 08:32:34 -07:00
mattsc
d3a3825a26 High XP attack CA: don't attack hidden enemies 2016-09-23 07:54:29 -07:00
mattsc
0e87d7fd43 High XP attack CA: respect the default 'avoid' aspect 2016-09-17 16:41:41 -07:00
mattsc
c03bd5411f Various Lua AI code: use simpler and faster new syntax
No change in behavior.
2016-09-04 18:54:26 -07:00
mattsc
f76e2d0c59 High XP attack CA: remove a debug message
Also remove a related message from the test scenario.
2016-09-03 16:47:15 -07:00
mattsc
390d1fdc10 High XP CA: simplify attack conditions with 1.13 syntax 2016-09-03 07:03:00 -07:00
mattsc
6950ee1dd0 New high_xp_attack candidate action for default AI
This CA performs attacks on enemy units so close to leveling that the
default AI's combat CA would not attack them (with some exceptions).
This is meant to keep players from being able to exploit this known
weakness of the default AI.
2016-09-02 20:22:17 -07:00
mattsc
3f2df87bed Recruit rushers AIs: adapt syntax to recent AI changes
This caused an error message and recruiting to be abandoned when the
recruit rushers Micro AI was used for two different sides in the same
scenario.  It was only presents since the AI refactoring done during
1.13.4+dev and did not affect any release.
2016-07-27 19:58:22 -07:00
Celtic Minstrel
c79874086d MicroAIs: Update all to use the new [args] syntax
Except for Protect Unit, all of them seem to still work correctly.
2016-03-27 15:13:21 -04:00
Celtic Minstrel
d48060bc00 Fix external Lua CA example for new syntax 2016-03-24 17:49:02 -04:00
mattsc
c04f406bd8 Old patrol.lua: fix indenting and add deprecation message 2016-03-24 12:57:35 -07:00
mattsc
961d134ee2 Fix and simplify Lua AI test scenario 2016-03-24 08:07:01 -07:00
Celtic Minstrel
1d7c1c74f6 Improve backwards compatibility for Lua AI
This changes the following:
- Fixes the experimental AI, without changing any of its code except for that in the [engine] tag
- Returns a dummy self from the dummy Lua engine, so that external CAs are more easily switched to using [params]
- Changes the order in which parameters are passed to AI component code. The order is now:
        state/self,    params,    data
2016-03-22 07:22:22 -07:00
Celtic Minstrel
f8f5557eb0 Huge refactor of Lua AI engine
This commit potentially breaks any Lua AI customization, except for external Lua candidate actions.
In practice, though, Lua aspects and goals will probably continue to work for the most part.

- The ai table now has a read_only attribute.
  If true, functions that change the game state will be missing from the table.
  The read_only attribute is false in CA execution and in stages.
  It is true everywhere else.
- Every Lua AI component now supports a [args] subtag.
  The contents of this tag are passed as parameters to the component code.
  This data is immutable; components cannot alter its contents.
  (External Lua candidate actions do not receive this data.)
- Accessing the persistent engine data is now supported in all Lua components.

When calling a Lua component, the Lua engine now passes two parameters:
1. The contents of the [args] tag in the specific component.
2. The contents of the [data] tag in the Lua [engine].

The return value of the [engine] code, if any, is stored for later used.
It will be passed as the third parameter to any other Lua component.
This data can be changed, but will not be saved.
The default engine does not return any such data.
2016-03-22 07:22:22 -07:00
mattsc
05eb2d7620 Lua AI helper functions: modify a comment 2015-05-20 07:13:11 -07:00
mattsc
25e10121f5 Lua AIs: fix bug occurring when number= in an attack is set to zero
Apparently, when this is the case, the number key is not included at
all, rather than set to zero, when the Lua table containing the attack
information is retrieved.
2015-05-19 19:54:41 -07:00
aquileia
504fd44747 Fixup and expand cc8ec3a934
[skip ci]
2015-01-29 01:36:34 +01:00
mattsc
ada80cfd34 Micro AIs: only display on-screen error messages when in debug mode 2014-11-01 07:45:15 -07:00
mattsc
156726a6a4 ai_helper.move_unit_out_of_way: fix direction rating
This is supposed to be a minor rating, secondary to the main rating.
2014-06-16 08:08:01 -07:00
mattsc
9e8ee00ad0 battle_calcs: provide default value for resistance modifiers
This is done for cases when the value cannot be read from the unit_info
table, which might happen in some UMC.  This fixes a rare bug affecting
the Fast Micro AI attack evaluation
2014-06-15 19:34:25 -07:00
mattsc
faeaf5e47c ai_helper.get_attacks: improve check for units in the way
Check whether the unit in the way has an unoccupied hex to move to.
Previously, it was only checked whether its reach was >1, which
sometimes can include only hexes occupied by units on its own side,
making the actual move impossible.
2014-06-15 14:22:18 -07:00
mattsc
03c1b97802 next_hop(): bug fix for ignoring units when ignore_units=true is set
A bug in the previous version let to them not being ignored when  the
were on the last hex of the next hop.
2014-05-02 19:29:37 -07:00
mattsc
82e4ccad4d battle_calcs.attack_rating(): overhaul attack rating system
This was long overdue.  The return value is now much closer to
something describing the actual gain/loss (roughly) in units of gold.
2014-04-30 19:09:28 -07:00
mattsc
7623c5513a battle_calcs: do not use variance of attack in attack rating
This was an idea we tried so that we’d start with the most uncertain
attack first, but it did not work very well.
Keep the code for now, just comment it out.
2014-04-30 19:06:57 -07:00
mattsc
0218b88180 attack_combo_stats(): also cache intermediate battle outcomes
Speeds up some calculations significantly.
2014-04-30 19:05:08 -07:00
mattsc
2336921a81 simulate_combat_fake(): don't fill empty HP chances with zeros
That’s what wesnoth.simulate_combat() does, but is different from the
other functions in battle_calcs.  Only hp_chance[0] needs to be set,
even if it is zero.
2014-04-30 19:02:08 -07:00
mattsc
f0c7ddcab1 ai_helper: make AI move error messages more descriptive 2014-04-30 18:59:25 -07:00