Commit graph

360 commits

Author SHA1 Message Date
Celtic Minstrel
233237be1e [Lua] Add some TODO notes on things to come back to later. 2024-08-13 08:54:04 -04:00
Celtic Minstrel
a277073e36 [Lua] Remove some internal implementation functions from the external ai_helper interface.
There are no callers in mainline. The functions are not meant to be called directly at all – for each, there are wrapper functions that are intended to be called instead, which are still exposed.
2024-08-13 08:54:04 -04:00
Celtic Minstrel
9e79a627c3 [Lua] Fix some accidental global warnings 2024-08-13 08:54:04 -04:00
Celtic Minstrel
dd24051c17 [Lua] Mark location_set.values as private 2024-08-13 08:54:04 -04:00
Celtic Minstrel
8d5ca809f4 [Lua] Update obsolete location functions in ai_helper to return a proper named tuple and access locations as x,y instead of [1],[2] 2024-05-19 12:54:35 -04:00
Celtic Minstrel
058d0502e5 [Lua] Update obsolete use of [1],[2] to refer to locations, and simplify some code by leveraging the fact that any object with x,y qualifies as a location; also use moves_left for reachmaps instead of [3] 2024-05-19 12:54:35 -04:00
Celtic Minstrel
0f6fe67477 [Lua] Use wml.tag to construct WML tables 2024-05-19 12:54:35 -04:00
Celtic Minstrel
a2c9d2627e [Lua] Fix obviously broken functions in ai_helper.
These functions are not used anywhere, and they have other issues besides the one fixed in this commit – they're implied to return all moves, but they only return one move for each possibly destination hex. However, this will make them at least be minimally usable.
2024-02-26 13:24:38 -05:00
Celtic Minstrel
c2f50062d2 [Lua] Suppress nodiscard warning 2024-02-26 13:24:38 -05:00
Celtic Minstrel
8276fd2e4b [Lua] Fix incorrect function name 2024-02-26 13:24:37 -05:00
Celtic Minstrel
1fd17d94ba [Lua] Fix missing parameter warning when passing empty filter 2024-02-26 13:24:37 -05:00
Celtic Minstrel
1efc2fbe4d [Lua] Avoid reusing no-longer-needed variables for different meanings
This raises Lua warnings about mismatched types
2024-02-26 13:24:36 -05:00
Toom
0e99d4b38b Revert renaming of ai_helper.checked_move_core
@CelticMinstrel #fixes #8412
2024-02-16 15:32:00 +01:00
Celtic Minstrel
f7ef5e1362 [LuaDoc] Convert all the ai_helper documentation to LuaDoc format, and add LuaDoc for all previously-undocumented functions. 2024-02-13 19:29:21 -05:00
Celtic Minstrel
94adca0fff [LuaDoc] Fix some non-nullable warnings by adding explicit type annotations on local variables 2024-02-13 19:29:21 -05:00
Celtic Minstrel
4b5a8e25e8 [LuaDoc] Suppress some diagnostics 2024-02-13 19:29:21 -05:00
Celtic Minstrel
a9c0d37525
[Lua] Prevent divide by 0 in rushers recruit AI 2024-02-07 20:13:13 -05:00
Celtic Minstrel
d19858a150 [Lua] Fix missing parentheses in rusher recruit AI
Fixes #8297
2024-02-07 19:06:47 -05:00
Celtic Minstrel
9eefcda17a Deprecate ai_helper.split
I used level 3 deprecation because this is something that was intended for internal use in the ai_helper module, and the ai_helper module itself is not an officially stable API
2024-02-04 13:28:19 -05:00
gfgtdf
e08676d6a8 Fix Lua errors when checking abilities #7890
Nowdays ability.value and similar attributes can also contain formulas
(That for example make a heal amount dependent on the remaining hitpointsthe unit has
)
With this the lua ai code should no longer crash in these cases.
2023-12-24 00:51:57 +01:00
mattsc
507aa62e83 Lua AI: speed up battle_calcs.battle_outcome in extreme cases
The method used in the battle_outcome() function is somewhat simplified compared to the default engine calculation and faster in the vast majority of cases, but it can become extremely slow when the combined number of strikes of the attacker and defender is very large.
2022-08-31 12:42:10 -07:00
mattsc
c7b3393a9d ai_helper: add handle_user_interact calls 2022-07-12 22:57:16 -04:00
mattsc
b1b521f582 Lua AI CAs: add handle_user_interact calls
Insert these calls in loops that do expensive calculations for the CAs of the default and experimental AIs.
2022-07-12 22:57:16 -04:00
mattsc
6ed684af73 move-to-any-enemy CA: stop eval if no enemies
Otherwise there is an error caused by one of the sort functions later in the code.
2022-07-03 06:48:47 -07:00
mattsc
90f1c01f41 AI: improve efficiency of move-to-any-enemy CA
The new method avoids a lot of path finding that the previous method did, esp. on large maps with many units and/or enemies, leading to significant speed improvements in some cases.

This fixes #6504
2022-07-01 18:56:00 -07:00
mattsc
21475ced4f Micro AIs: add error messages if parameters are of wrong type
Fixes #6408.
2022-06-27 20:20:06 -07:00
mattsc
a70ecf1ff5
Merge pull request #6783 from mattsc/expai_updates
Some fixes to the Experimental AI
2022-06-24 16:37:59 -07:00
mattsc
6796ac3d56
Merge pull request #6792 from mattsc/retreat_allied_villages
Fix retreat injured CA taking allied villages
2022-06-24 16:31:15 -07:00
mattsc
b55148ce91 Retreat injured CA: fix for regenerate ability without value key
The ability does not need to contain a value key if it only heals poison.
2022-06-24 16:03:51 -07:00
mattsc
c1d1ff517a ExpAI recruit rushers: include unit types from extra_recruit
This fixes #4924. Note, however, that the recruit rushers CA is set up for single-leader sides and does not work with multiple leaders, so this is of limited use.
2022-06-22 16:31:39 -07:00
mattsc
7877218158 Deprecate generic_recruit_engine.lua 2022-06-22 16:31:39 -07:00
mattsc
45ac8de582 ExpAI recruit rushers: new parameter reset_cache_each_turn
Many of the operations of the recruit rushers CA are expensive and are therefore cached. For the most part, this cache can be kept from turn to turn, but in case there are events that change, for example, the map or the recruit list, this parameter can be used to force a reset of the cache each turn.
2022-06-22 16:31:39 -07:00
mattsc
561314b0f6 ExpAI recruit rushers: do not parse side __cfg each eval 2022-06-22 16:31:38 -07:00
mattsc
dfde09c174 ExpAI recruit rushers: reset recruit_data.recruit each turn
While most data in recruit_data can stay persistent from turn to turn, some of recruit_data.recruit, such as enemy_types, needs to be updated each turn.
2022-06-22 16:31:38 -07:00
mattsc
e4b776cbb8 ExpAI: do not use generic_recruit_engine
This removes the need for the Generic Recruit Engine and makes Recruit Rushers a "clean" candidate action.  In the process, it fixes a bug of data leakage between the Experimental AIs of different sides.
2022-06-22 16:31:28 -07:00
mattsc
b9506ff795 Retreat injured CA: allow taking ally villages when aspect is set 2022-06-22 08:16:31 -07:00
mattsc
2b3824f44c Retreat injured CA: do not take villages from ally 2022-06-22 07:51:46 -07:00
mattsc
fdb931bb16 Remove Lua AI code deprecated at level 3 in 1.15 2022-06-21 19:15:00 -07:00
mattsc
fe0b375fca ExpAI castle switch CA: fix error when stored leader has been killed
The castle switch CA stores the leader move because the evaluation is expensive.  If the leader was killed in between storing and reevaluation of the CA, this would previously cause an on-screen error message and the CA to be blacklisted for the turn.

This fixes #6440.
2022-06-09 07:51:33 -07:00
mattsc
768b930fc4 ai_helper: fix visibility bug in get_attackable_enemies()
The passed filter needs to be enclosed in an [and] tag, otherwise the check for visibility might not work correctly, for example if the filter contains a top level [or] tag.
2022-06-04 09:13:53 -07:00
Celtic Minstrel
759b040069 fix whitespace
The whitespace-fixing script seems to be slightly different depending on the platform.
Even though it produces no effect in the CI, it made these changes locally on my Mac.
I'm committing them now so as to avoid unrelated files being changed in other pull requests.
2022-02-06 00:05:09 -05:00
Pentarctagon
370d03ccb7 Fix luacheck warnings and add to CI.
Note the `exclude_files` in .luacheckrc should be deleted once the eventual Ubuntu 22.04 base image has an updated luacheck that supports lua 5.4.
2021-11-28 14:26:02 -06:00
Pentarctagon
254716e41e Expand lua whitespace check. 2021-11-28 14:26:02 -06:00
Celtic Minstrel
2d95c0f7d3 AI: Convert the FormulaAI example scenario to do all the same things using Lua
- Unit formulas are replaced by inline MicroAIs or candidate actions placed in the unit's [ai] tag.
  - The stationed_guardian MicroAI was chosen as the closest match to the guardian FormulaAI. It's not a perfect fit, but it's pretty close.
  - The goto and patrol MicroAIs are fairly obvious substitutes for the respective unit formulas.
  - The priority test in unit formulas is replaced by fairly basic inline non-external CAs with differing scores.
- The side formulas (opening.fai) have been converted to a separate Lua stage using a new opening.lua. However, that's only a partial conversion. The move and attack functionalities of opening.fai are missing from opening.lua; instead the built-in move, move leader to keep, and combat CAs are used.
- The scouting FormulaAI CA has been ported to Lua. It remains a very basic AI, probably not well-suited to genera use.
- The level up attack FormulaAI CA has been ported to Lua. Like the new scouting CA, this is mostly intended to serve as an example.
2021-09-04 22:20:28 -04:00
Celtic Minstrel
5d70dd9aca Lua: Add a new ai_helper debug function to print a simulate_combat HP distribution more succinctly 2021-09-04 22:20:28 -04:00
Celtic Minstrel
632941b03d Lua AI: Fix a typo 2021-07-30 19:22:57 -04:00
Celtic Minstrel
4ec60b99d9 Lua: Update all mainline references to the helper module 2021-07-07 01:32:05 -04:00
Celtic Minstrel
9c2689ac9e Lua AI: Move the deprecation messages to Lua so that the deprecated functions get nulled out with --strict-lua 2021-07-02 14:04:53 -04:00
Celtic Minstrel
91f6bf93a4 Fix a broken deprecation and replace some deprecated uses
Fixes #5877
2021-06-20 00:59:59 -04:00
Celtic Minstrel
1f62eae3ce Replace uses of wesnoth.find_path 2021-06-19 15:43:33 -04:00