736 Commits

Author SHA1 Message Date
mattsc
22ca458bfd Goto Micro AI: add [and] to a filter
Another efficiency improvement.  This ensures that the side of the unit
is checked first before the potentially complex rest of the filter is
evaluated.

(cherry-picked from commit 6c38b8ce934ea68bd11a3aa960a91fe6f9dbfb87)
2018-10-07 03:22:21 +00:00
mattsc
6a64e6e37e Goto Micro AI: change order of SLF and SUF evaluation
This is for efficiency reasons, as location filters do not necessarily
change throughout a side’s turn, while fewer and fewer units have moves
left.

(cherry-picked from commit 0dcbe1d0d0b1dda90a0fa649120348b7542f2644)
2018-10-07 03:22:21 +00:00
mattsc
674a39a43e 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.

(cherry-picked from commit 972ecc2f56c3cc1391db165518324b1a3757431d)
2018-10-07 03:22:20 +00:00
mattsc
0c707294cb Experimental AI recruiting: use math.huge instead of 9e99
(cherry-picked from commit a6c0012689b39d74e2d9578f17010a048ef7d296)
2018-10-07 03:21:29 +00:00
mattsc
f1eacc51ad Experimental AI: clear recruit cache when no recruit action found
(cherry-picked from commit f810504306f7b97bd5e532793b36591ada8ba671)
2018-10-07 03:21:29 +00:00
mattsc
9b6f933ded Fix Experimental AI not working without enemy units
An example are the first two turns of Dark Forecast.

(cherry-picked from commit a65605c54726a391cc05d1bb75761966a8088cac)
2018-10-07 03:21:29 +00:00
mattsc
1c88a6d8c8 Do not load helper.lua where it is not used any more
(cherry-picked from commit 4b6681a300f29eab3b5adcf3b12df8bc6ad455dd)
2018-10-07 03:21:10 +00:00
mattsc
cb1bc56478 Remove unnecessary inclusions of helper.set_wml_action_metatable {}
(cherry-picked from commit 1684e2f5daa6b84906186b101c83a6a017b07581)
2018-10-07 03:21:10 +00:00
mattsc
49b1ef9549 Lua code: remove deprecated helper.set_wml_var_metatable() call
It’s not needed here.

(cherry-picked from commit 08a000a7daabb74f6dd7370c1b2b95f3e83e5501)
2018-10-07 03:21:09 +00:00
mattsc
f48f566afd Lua code: replace deprecated helper.[gs]et_variable_array() calls
(cherry-picked from commit 3c792fc7d774c96ef467847a6267a71a2f731f96)
2018-10-07 03:21:09 +00:00
mattsc
4586e04eca Lua code: replace deprecated helper.child_range() calls
(cherry-picked from commit 7c137e1a336559acdd6f797192a9516135480b2e)
2018-10-07 03:21:09 +00:00
mattsc
58529e95f8 Lua code: replace deprecated helper.get_child() calls
(cherry-picked from commit f0bb40590fe1a9c2c6683157f9aa93b631848251)
2018-10-07 03:21:08 +00:00
mattsc
05d5afa6a9 Lua code: replace deprecated wesnoth.get_variable() calls
(cherry-picked from commit f1764d182fe33c4e29c6bd42761be2e946cd0c94)
2018-10-07 03:21:06 +00:00
mattsc
c98fad3791 MAI test scenarios: remove uses of deprecated MESSAGE macro
(cherry-picked from commit 5e5a9e69e5e3b0323e39ebfb090cc060347f4516)
2018-10-07 03:21:04 +00:00
Celtic Minstrel
c266b35528 Fix rabbits AI being broken by save-load 2018-03-17 17:16:22 -04:00
Celtic Minstrel
23aac4f72f Cleanup of fef953a48e258e5b07ff4559eeff5571103d58c1
- Fix the rabbit AI
- Enable invoke_synced_command to also call (some) built-in commands
  and give an error message in the case of an unknown command
- Remove some unnecessary implementation details
2018-03-17 16:48:00 -04:00
Charles Dang
134353f863 Further cleanup of deprecated Lua API usecases (inc. ones from fef953a)
[ci skip]
2018-03-17 00:41:32 +11:00
gfgtdf
fef953a48e remove ai.synced_command
fixes #1649 . ai.synced_command could easily be used to implement all types of
undeteced cheats so it was removed. As a replacement this commit adds a
[custom_command] synced command that just calls
wesnoth.game_events.on_synced_command which calls a lua handler that
must first be set.
2018-03-16 13:43:05 +01: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
Charles Dang
33725add8f Data/AI: wmlindent run
[ci skip]

Addresses some of the whitespace issues noted in #2613.
2018-03-09 11:07:23 +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
Charles Dang
4bf5c9341f Revert "Remove invalid attribute from idle AI"
This reverts commit 1d84d83c6c6c70e3c25de6e3d443a7ec17936711.

I had introduced use of the hidden= key in b2df837d8e7a95ae2e15dcbdffbd0653ab481443, but
apparently didn't add them to the valid list of non-aspect keys.
2018-02-22 12:21:20 +11:00
Jyrki Vesterinen
1d84d83c6c Remove invalid attribute from idle AI
It was interpreted as a simplified aspect, resulting in a warning when
loading a replay.

Found with WML unit tests.
2018-02-21 22:34:11 +02:00
mattsc
85b46f34b0 Fast Micro AI: make code robust against events removing units
The previous version caused errors under some circumstances when an
event removed units other than the attacker during or immediately after
an AI attack.
2018-02-11 08:05:58 -08:00
Matthias Krüger
b11d3fdcbe fix a bunch of typos found by codespell in data directory.
https://github.com/lucasdemarchi/codespell
2018-02-06 23:03:06 +11:00
mattsc
b7efaadec4 Protect Unit Micro AI: fix typo/bug in AI aspect change 2017-11-27 06:54:14 -08: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
Charles Dang
b2df837d8e Hide AIs with hidden=yes from list of available AI options (fixes #2095)
This is enough to hide them as AI options in the UI, but I don't know if other parts of the AI
engine need to know about this key.
2017-10-11 08:41:38 +11:00
mattsc
70bd919631 Idle AI: remove from data/ai/dev after all
It was left there in cfb2aa8050 for backward compatibility. However,
this causes a “duplicate AI” error at start-up in debug mode.
Furthermore, the file is not included in any current 1.12 or 1.13
add-on, so it should be safe to remove it. Using
[ai]ai_algorithm=idle_ai is the preferred option to include the Idle AI.
2017-10-05 08:34:37 -07:00
mattsc
f097c3d7f6 Idle AI: add to comment on when empty [stage] tag is needed 2017-10-04 16:48:08 -07:00
mattsc
cfb2aa8050 AIs: idle_ai is not a "Dev AI", fixes #1955
As indicated in the comment of the idle_ai config file, an AI needs to
contain at least one stage, otherwise the default AI will be injected
under certain circumstances. Unlike indicated in the comment, this now
also applies to loading a mid-scenario save. (I will add that to the
comment in the next commit.)

As this AI was in data/ai/dev/, it was previously only loaded when
Wesnoth was started in debug mode. The config was thus not available
when playing in no-debug mode, causing the default AI to be injected on
reload. This caused issue #1955.

While not strictly necessary, we keep a redirect in data/ai/dev for
backward compatibility, in case the file is included in add-ons.
2017-10-04 16:48:08 -07:00
mattsc
d53243daa9 Fast Micro AI: fix typo from commit 6efc5ae090 2017-10-03 20:55:34 -07:00
Jozrael
e175bb1c7d Fix crash when unable to find closest enemy. 2017-10-02 14:43:16 -07:00
mattsc
a673e64d44 FAI files: remove trailing whitespaces 2017-10-01 13:43:27 -07:00
mattsc
6751172282 Poisoner FAI: prevent passing empty list to min(), fixes #1999
The WFL min() function was changed from returning zero to returning an
error when an empty list is passed as argument (commits eccd3d8e and
fd9f1153).  This adapts the Poisoner FAI code to deal with that
correctly.
2017-10-01 13:41:35 -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
4b8e37044c Micro AIs: Fix Lua error in AIs that use unit variables 2017-05-11 16:00:51 -04:00
mattsc
24891d85e2 Lua AIs: remove unused library inclusions after distance_between change
Follow-up to 6efc5ae090
2017-05-11 10:22:00 -07: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
e945755793 Accidentally committed this 2017-05-08 13:52:31 -04:00
Celtic Minstrel
5da2d71a20 Move [micro_ai] implementation to data/lua/wml 2017-05-03 02:45:54 -04:00
Celtic Minstrel
8d4cf3cf62 Shorten requires where possible 2017-05-03 02:42:25 -04:00
Celtic Minstrel
f45d795134 fixup 0f01f97b (GNA25615) 2017-03-23 17:00:51 -04:00
Celtic Minstrel
0f01f97b30 Update Micro AIs to use new Lua API functions for altering AI 2017-03-20 12:00:21 +11:00
mattsc
3236a4b085 Micro AIs: fix some MAIs not working under shroud
This is done by ignoring shroud for path finding (while still taking
hidden units into account correctly), consistent with default Wesnoth
AI behavior.
2016-12-09 18:59:52 -08:00