Commit graph

253 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
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
94adca0fff [LuaDoc] Fix some non-nullable warnings by adding explicit type annotations on local variables 2024-02-13 19:29:21 -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
2424d5705f Micro AI CAs: add handle_user_interact calls 2022-07-12 22:57:16 -04: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
84531b834e Bottleneck Micro AI: fix bug involving units without moves
An integral part of this MAI is that it moves weaker units out of the way for stronger ones.  Units without moves are taken into account by giving them a very high rating.  This was previously only done on what's considered the AI's territory (the AI side of the bottleneck) which works fine most of the time since the AI does not try to move onto enemy territory.  However, it breaks down on more open maps, where there are way for units to move around the bottleneck, as AI territory is not always well defined on them.  However, there is no need to restrict this to AI territory only.

This fixes #6599.
2022-06-09 06:29:14 -07:00
mattsc
7746f75f11 Wolves multipack MAI: prevent potential for infinite loop
The MAI was set up to be blacklisted if no attacks were found, but that did not always work. In addition, removing attacks from the wolves also means that no other CA can use them for other attacks instead.
2021-12-28 18:31:19 +01: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
9fdaea5893 AI: Fix error in stationed_guardian 2021-09-04 22:20:28 -04:00
mattsc
b73078884c Messenger MAI: fix bug of own units blocking waypoint
ignore_own_units=true was accidentally dropped when adding [avoid] tag functionality to the Micro AI in a60736b6c7
2021-09-01 08:49:54 -07:00
Celtic Minstrel
4ec60b99d9 Lua: Update all mainline references to the helper module 2021-07-07 01:32:05 -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
7f162cbd24 Lua: Rename find_vacant_tile to find_vacant_hex for naming consistency 2021-06-19 17:09:31 -04:00
Celtic Minstrel
1f62eae3ce Replace uses of wesnoth.find_path 2021-06-19 15:43:33 -04:00
Celtic Minstrel
5a1e38e99b
Add wesnoth.sync module for the synchronization-related commands (#5862) 2021-06-19 15:39:10 -04:00
Celtic Minstrel
e8381ea9da Update uses of eval_conditional 2021-05-11 14:52:20 -04:00
mattsc
f1c37f64ac
Merge pull request #5630 from mattsc/remove_fai_uses
Remove Formula AI uses
2021-03-24 08:04:47 -07:00
mattsc
8d03d3ef08 Swarm Micro AI: add optional parameter [filter] 2021-03-22 09:09:30 -07:00
mattsc
4fe45bf22a Patrol Micro AI: add two optional parameters
attack_range: the patrol interrupts its route to attack enemies within this distance, not just enemies that it happens to end up next to

attack_invisible_enemies: include invisible enemies when considering whether there are enemies within attack_range

The default behavior is unchanged.
2021-03-21 14:56:37 -07:00
mattsc
a60736b6c7 Messenger Micro AI: add [avoid] tag functionality 2021-03-13 17:20:09 -08:00
mattsc
cadb233d6c Update some deprecated Lua uses 2021-03-06 15:08:54 -08:00
Celtic Minstrel
a2d7a26365
Fix several Lua issues, mostly unintentional globals (#5587) 2021-03-06 17:01:53 -05:00
mattsc
d9e8f69718 Lua AIs: fix some incorrectly used variables
Fixes #5586
2021-03-06 09:53:53 -08:00
Celtic Minstrel
93398ae3a4
Fix another syntax error 2021-03-04 23:43:24 -05:00
Celtic Minstrel
3a7eef0310 Merge pull request #4580 from wesnoth/lua_gamemap
Refactor the game map to permit exposing it to Lua
2021-03-04 14:00:43 -05:00
mattsc
28ea6e82c6 Multipack Wolves MAI: fix error when a wolf is surrounded 2021-03-03 17:41:41 -08:00
mattsc
ea4657c6d4 Goto Micro AI: add remove_movement option
By default, the MAI removes movement points from units even when they cannot find a hex to move to.  When this option is set to 'no' (default is 'yes'), this step is skipped, so that other candidate actions can take over.

This implements feature request #5580
2021-03-03 12:49:35 -08:00
mattsc
043ee7a80b Protect Unit Micro AI: ensure units are on AI side
In general, the units specified in the MAI setup should be on the AI side.  However, that might change during a scenario, for example when there is an event that switches units to other sides.
2021-03-03 08:14:46 -08:00
Celtic Minstrel
9d3bf196b0 Update everything to use the new wesnoth.map module
- get_terrain and set_terrain replaced with direct indexing operations
- get_map_size mostly replaced with either the iterator or an on_board call.
  Only a few cases really needed to know the size of the map for some other purpose.
- shroud and fog operations, village owner, time areas, and location filters
- get_terrain_info replaced with terrain_types table
- Map generation functions create_map and create_filter
2021-02-28 18:16:33 -05:00
mattsc
287530a43f Goto Micro AI: change how avoid_map is taken into account
There were two issues with the previous method:
- ai_helper.get_avoid_map() never returns nil, but at most an empty location set. Thus, the 'else' clause in that conditional was never reached.
- The presence of an [avoid] tag should not prevent the keys ignoring enemies from taking effect. Instead, [avoid] needs to be taken into account for all possible code paths.
2021-02-28 10:22:11 -08:00
mattsc
94bd2ec993 Goto Micro AI: fix possible error when ignoring enemies
The final determination of the hex to move to must take enemies into account, otherwise the MAI might try to move the unit to a hex it cannot actually reach.
2021-02-28 10:15:07 -08:00
mattsc
fd0c00cfb0 Goto Micro AI: fix checks of avoid_enemies key
Numerical values are sometimes transferred from WML to Lua using the string type. This applies, for example, to very small numbers, such as 0.0000000000001. This needs to be taken into account when checking whether avoid_enemies is a number.
2021-02-28 10:11:49 -08:00
Celtic Minstrel
56bdd42815
Fix segfaults and a few other issues in wesnoth.find_path
Co-authored-by: mattsc
2021-02-18 22:15:31 -06:00
mattsc
0905ee1fe7 Fast Micro AI: fix variable name
This wouldn't have been an issue, if there weren't also a local variable of the same name in the evaluation function. The way it was though, it caused an error when trying to execute an attack by the AI leader.
2021-01-18 19:29:55 -08:00
mattsc
1c5a044078 Forest Animals Micro AI: exclude rabbit holes on map border
Previously, a rabbit hole item on the map border could be selected for spawning a new rabbit, resulting in an error message on screen and abandoning the CA for the rest of the turn.
2020-01-23 18:37:40 -08:00
mattsc
5f05ae31d6 ai_helper: deprecate has_ability() 2020-01-01 20:50:32 -08:00
mattsc
a78150e366 Bottleneck Micro AI: add [filter] as optional parameter 2019-12-19 07:33:25 -08:00
mattsc
68bb48ddf1 Lua AIs: fix uses of new unit functions
I switched to using defense_on() and resistance_against() incorrectly in 55478e20. I had tested these, but apparently for cases when it does not make a difference ...

The change for movement_on() is for convenience and consistency with other code only.
2019-12-18 09:23:23 -08:00
mattsc
f2df220579 Lua AIs: eliminate usages of __cfg
These are cases for which the respective variable was not accessible otherwise when the code was originally written.
2019-12-18 07:21:33 -08:00
mattsc
55478e20ad Lua AI code: update deprecated functions 2019-12-17 07:34:48 -08:00
mattsc
09cffab77b Bottleneck Micro AI: bug fix for units in front of bottleneck
Previously, units so far in front of the bottleneck that they could not get behind it in one move were left stranded. Now they are moved toward it.
2019-12-16 08:45:47 -08:00
mattsc
d650a8336d
Merge pull request #4600 from mattsc/expai_ca_merge
Merge Experimental AI candidate actions into the default AI
2019-12-15 14:15:55 -08:00
mattsc
64e969af11 AI: ensure all CAs respect passive_leader aspect
Most of the former Experimental AI CAs did already (or don't use the leader in the first place), but not quite all of them.
2019-12-06 08:18:47 -08:00
Celtic Minstrel
732b7942bb Replace all references to deprecated functions in the helper module
(and remove the require if this meant it was no longer used)
2019-12-02 01:10:34 -05:00
mattsc
3e70358d8d AI: ensure all CAs respect unit guardian status
This adds the correct behavior for the castle_switch, move_to_any_enemy and place_healers CAs.  It was already in place for the other former ExpAI CAs (except for recruiting and spread_poison, for which it does not apply).

This automatically also adds this behavior to the Healer Support Micro AI.
2019-11-29 19:22:56 -08:00
Celtic Minstrel
3734bce276 Lua: Replace uses of deprecated (moved) sides functions 2019-11-23 14:41:03 -05:00
Celtic Minstrel
24b11221cf Use wml.array_variables instead of wml.array_access.get/set 2019-11-16 13:09:04 -05:00