Commit graph

1020 commits

Author SHA1 Message Date
mattsc
51e4b56a1e ai_helper.lua: fix a typo 2021-03-06 15:35:43 -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
mattsc
cab4446580 Lua AI helper functions: remove trailing spaces 2021-03-06 09:53:27 -08:00
Celtic Minstrel
93398ae3a4
Fix another syntax error 2021-03-04 23:43:24 -05:00
Celtic Minstrel
86c3c30c46
Fix a syntax error 2021-03-04 23:33:33 -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
7e8cedaea8
Merge pull request #5573 from mattsc/ca_retreat_injured
AI: Improve behavior of the retreat_injured CA
2021-03-03 08:22:21 -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
mattsc
f67a5b269e AI retreat_injured CA: fix retreat_enemy_weight use
Only enemy threats are to be multiplied by this factor, not the ally support.
2021-02-27 08:56:14 -08:00
mattsc
f799269fa1 AI retreat_injured CA: improve retreat location evaluation
This includes several improvements to the retreat hex evaluation:
- Enemy threats are not the dominant rating contribution any more
- Enemy threats are based mostly on HP balance, rather than simply enemy number
- Enemy threat assessment can be modified with the retreat_enemy_weight aspect
- By default, only healing locations are considered as retreat locations, but this can be overridden with the retreat_enemy_weight aspect
2021-02-26 17:03:06 -08:00
mattsc
663a0ef8ec AI retreat_injured CA: fix bug in finding hexes next to healers
The CA was supposed to mark hexes next to healers as potential healing locations, but because of this bug that did not work.
2021-02-26 16:27:43 -08:00
mattsc
fe316aec3a Add new AI aspect retreat_enemy_weight 2021-02-26 13:57:13 -08:00
mattsc
903e03d68a AI retreat_injured CA: improve retreat threshold calculation
The main problem was that the previous calculation was based on the 'caution' aspect. While that is not technically wrong, caution is also used for other purposes and there are mainline (and presumably UMC) scenarios that use large values for caution. In those cases, units retreated that were barely injured. This, again, might even be desirable for some use cases, but it needs to be decoupled from the other uses of caution. Thus, the new 'retreat_factor' aspect is used now.

In addition, the calculation is now based on a unit's maximum hitpoints, rather than its level.
2021-02-26 06:49:37 -08:00
mattsc
efe5a4d497 Add new AI aspect retreat_factor 2021-02-25 20:25:16 -08:00
Celtic Minstrel
0802779f9e Found a deprecated thing not in WC 2021-02-20 16:12:49 -05: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
gfgtdf
b21c110f30 run wmlindent 2020-10-19 23:53:52 +02:00
Steve Cotton
97c87443c1 Use the new animals in the "animals" micro-ai demo
Several new animals were added in PR #5039's
cbad6f4249.

The micro-ai demo can be accessed by starting Wesnoth with the command-line
arguments `--test animals`. The scenario uses some stand-ins for animals that
weren't in mainline; the new bears and tuskers fit straight in. For the sheep,
the icemonax's graphics are a bit more sheep-shaped than the troll whelp's.

This demo doesn't need to be balanced, the changed unit stats are no problem.

UtBS's dustboks aren't in core, otherwise I'd use them as the deer stand-in.
2020-10-03 15:09:32 +02:00
Steve Cotton
a42600ffbe Remove the wesnoth-ai textdoman, move a few strings to wesnoth-lib (#4669)
This whole textdomain is dedicated to localized strings revolving around the
game's AI engine and the AI demos/test scenarios, with around 370 strings in
it.

Other than a few strings near the start of the catalogue template, none of these
have any value for regular players since they are sourced from AI demos and
test scenarios in data/ai/micro_ais/ and data/ai/scenarios/. None of them will
be displayed to people who aren't tinkering with WML or contributing to AI
development as part of the Wesnoth dev team, and some of the language used in
them is very technical in nature.

This commit leaves the "#textdomain wesnoth-ai" lines in the AI demos, but
drops the .po and .pot catalogues for wesnoth-ai. The few strings that are
seen by regular players move to the wesnoth-lib textdomain.
2020-10-01 10:29:39 +02:00
Steve Cotton
1d60c8d6e4 Rename old AI to "Old Default AI (1.14 version)" 2020-10-01 10:29:39 +02:00
mattsc
d80214d9fc ai_helper.get_closest_location: bug fix for border hexes
If a unit is passed as the last argument to this function, the returned hex is supposed to be passable for that unit. Hexes on the map border need to be excluded in this case.

This specifically also fixes a bug in the Messenger Escort Micro AI. Previously, waypoints right at the map border could sometimes lead to the AI showing an on-screen error message and becoming inactive.
2020-09-26 14:02:19 -07:00
Pentarctagon
5af1f129cd Mass convert of *^Uf terrain for SP. 2020-09-15 09:26:00 -05:00
mattsc
c72537687e Experimental AI: always show up in MP menu
This reverts 24af20cf83, which made it available in debug mode only, as there remain more differences to the new default AI than initially envisioned. This takes care of Issue #4997.
2020-07-19 11:05:01 -07:00
mattsc
a666a34055 ai_helper.next_hop: fix bug in fan-out code
This fixes the case when the unit cannot reach the previously found next_hop location from the ideal next_hop location in the part of the code that tries to keep units from moving in single file.
2020-07-07 20:14:11 -07:00
mattsc
76c01694d4 Micro AI test scenarios: add missing side controllers
Fixes #4890
2020-06-07 08:56:37 -07:00
mattsc
fefe431360 AI: fix remove castle_switch CA from default AI 2020-03-04 06:55:35 -08:00
mattsc
396b258203 AI retreat CA: bug fix for cure-only abilities
That is, those that cure poison, but do not provide any healing.
2020-02-11 12:10:43 -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
800c943221 ai_helper.has_ability: restore previous functionality
Before the recent change, the ability type (tag name) was checked. It then got changed to ability id. This commit changes it back to the old behavior.

For the record, there are situation when either the id or the type is needed. In addition, one sometimes wants to check wheter the ability is active (or will be active). Thus, no matter how this is done, neither will serve all purposes and sometimes other functions/functionality should be used. This commit does, however, restore the previous behavior and thus preserves backward compatibilty.
2020-01-01 20:33:59 -08:00
mattsc
34e3c9103f AI: convert leader related aspects to variants 2019-12-31 20:33:19 -08:00
mattsc
926662216a AI: allow list of ids for two passive leader aspects
In addition to 'yes' and 'no', comma separated lists of leader ids are now also accepted as values for these aspects. This allows setting the behavior only for specific leaders.
2019-12-30 19:43:28 -08:00
mattsc
c81ecca23b Experimental AI: do not target units without advancements in high_xp_attack CA 2019-12-30 19:43:28 -08:00
mattsc
a78150e366 Bottleneck Micro AI: add [filter] as optional parameter 2019-12-19 07:33:25 -08:00
mattsc
a90964fd41 ai_helper: deprecate has_weapon_special() 2019-12-19 07:09:13 -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
f1e8807330 ai_helper.has_ability: add optional parameter 'exact_match'
The default behavior is unchanged.
2019-12-18 07:40:16 -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