Commit graph

187 commits

Author SHA1 Message Date
mattsc
972ecc2f56 AI helper: improve efficiency of get_unit functions
The old method is very slightly faster in some circumstances (e.g. for
simple filters and when all units have moves/attacks/etc. left), but we
are talking fractions of micro seconds. By contrast, depending on the
filter used, the new method can save large amounts of evaluation time
once some units have move or attacked.
2018-06-07 06:44:55 -07:00
mattsc
a6c0012689 Experimental AI recruiting: use math.huge instead of 9e99 2018-05-20 14:55:17 -07:00
mattsc
f810504306 Experimental AI: clear recruit cache when no recruit action found 2018-05-20 14:55:01 -07:00
mattsc
a65605c547 Fix Experimental AI not working without enemy units
An example are the first two turns of Dark Forecast.
2018-05-20 14:54:45 -07:00
mattsc
4b6681a300 Do not load helper.lua where it is not used any more 2018-05-13 20:53:01 -07:00
mattsc
1684e2f5da Remove unnecessary inclusions of helper.set_wml_action_metatable {} 2018-05-13 20:52:51 -07:00
mattsc
7c137e1a33 Lua code: replace deprecated helper.child_range() calls 2018-05-13 20:52:08 -07:00
mattsc
f0bb40590f Lua code: replace deprecated helper.get_child() calls 2018-05-13 20:51:56 -07:00
Charles Dang
3a90f86674 Addressed more whitespace issues from #2613
[ci skip]
2018-03-12 03:48:59 +11:00
Charles Dang
471c9e876a Addressed a large chunk of the whitespace issues from #2613
[ci skip]
2018-03-09 11:37:00 +11:00
Celtic Minstrel
dabf09fce1 Fix deprecation spam
This removes the Lua deprecation_message function in favour of exposing the C++ variant to Lua instead.
It also moves all deprecation messages to a separate logdomain, making them easily enabled en masse.
2018-03-04 21:21:33 -05:00
mattsc
3b2077fdc3 Fast Micro AI ai_helper functions: fix rarely occurring bug
When the AI moves a unit out of the way for another unit’s move, it is
occasionally possible for the former unit to use up all its movement
points (e.g. if it has few MP or on narrow crowded maps). If that unit
is on the list to be moved later during the same sequence, this caused
ai_helper.robust_move_and_attack() to return nil, which then made the
Fast Micro AI produce an error message.
2017-11-08 22:33:24 -08:00
Jozrael
e175bb1c7d Fix crash when unable to find closest enemy. 2017-10-02 14:43:16 -07:00
Celtic Minstrel
d192f07123 Implement standard deprecation system for Lua API
(as proposed by @DeFender1031)

All existing deprecation messages in the Lua code have been changed to
use the new deprecation system.

The goal is to eventually use an equivalent system for ALL areas of the API.
2017-08-14 12:36:09 -04:00
Celtic Minstrel
6efc5ae090 Replace helper.distance_between -> wesnoth.map.distance_between (fixes #1686) 2017-05-11 04:14:03 -04:00
Celtic Minstrel
0539a68eb4 Migrate ai_helper.LS_random_hex to location_set:random 2017-05-10 17:40:21 -04:00
Celtic Minstrel
f6c04e7dd1 Add functional.lua which implements higher-order functions
This covers all the main higher-order functions included in WFL, except zip.
The two already implemented in ai_helper have been replaced with redirection stubs.
2017-05-10 17:40:20 -04:00
Celtic Minstrel
9b635994e1 Add location_set.(of|to)_triples (migrated from ai_helper) 2017-05-10 17:40:14 -04:00
Celtic Minstrel
37f1c490a5 Lua: Use the second argument to error() where appropriate 2017-05-10 17:40:13 -04:00
Celtic Minstrel
8d4cf3cf62 Shorten requires where possible 2017-05-03 02:42:25 -04:00
mattsc
36b2b4e9a7 AI helper functions: consistently ignore shroud when path finding
This is the default Wesnoth AI behavior. It is done in a way that still
ignores hidden units.
2016-12-09 18:57:18 -08:00
mattsc
8d76ad32b0 ai_helper: new function find_path_with_shroud() 2016-12-09 18:53:40 -08:00
mattsc
70b9aea5a4 High-XP Attack CA: do not use AI leader for this type of attack
Otherwise it is too easy to exploit this by baiting the AI leader to
run into a trap, and it is too difficult for what it's worth to make
sure the attack location is safe. If only the side leader is left to do
such an attack, it's more often than not not a good idea to do so
anyway.
2016-11-01 06:27:38 -07:00
mattsc
fa48c9c2ac ai_helper: compare unit proxies directly, not by coordinate
This was not possible when this code was first written, but it is valid
syntax now.
2016-10-22 15:14:26 -07:00
mattsc
acecd77bb4 Lua AIs: use new syntax for iterating over attacks
This is both simpler and faster than the old syntax.
2016-10-22 13:54:32 -07:00
mattsc
1cef83b08a ai_helper: fix indentation 2016-10-21 21:09:54 -07:00
mattsc
cc6679159b ai_helper.robust_move_and_attack: return action result to calling function
This function is supposed to be able to deal with all kinds of rare and
weird events without throwing errors, but it should still return a
status table describing what happened. The vast majority of situations
will simply return the move_result tables. For all the strange stuff
that could also happen due to WML events etc., we set up dummy tables
with the same structure and (somewhat) descriptive error messages
instead.
2016-10-21 20:57:16 -07:00
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