56 Commits

Author SHA1 Message Date
Celtic Minstrel
9e79a627c3 [Lua] Fix some accidental global warnings 2024-08-13 08:54:04 -04: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
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
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
1f62eae3ce Replace uses of wesnoth.find_path 2021-06-19 15:43:33 -04:00
Celtic Minstrel
a03d59d7eb Lua: Add a new schedule module
The primary components of this are:
- wesnoth.current.schedule
- wesnoth.map.get_time_area()
- wesnoth.schedule module
2021-06-19 11:07:53 -04:00
Celtic Minstrel
1dccc3ad76 Update mainline content to use the mathx module 2021-05-08 17:20:49 -04:00
Celtic Minstrel
1fc31c23d0 Replace all uses of get_time_stamp -> ms_since_init 2021-05-08 17:20:49 -04: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
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
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
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
6a3015f0e2 battle_calcs.lua: fix bug in relative_damage_map() 2019-12-07 19:08:48 -08:00
Celtic Minstrel
aaa2dc4ece Rollback possibility of wesnoth.get_units matching recall list units
Now it's renamed to wesnoth.units.find_on_map.

wesnoth.units.find implements the case of finding units on either the map or a recall list.
2019-11-15 22:39:09 -05:00
Celtic Minstrel
977f05d77f Lua: Replace uses of deprecated (moved) unit functions
Also backtracked the removal of wesnoth.get_recall_units, which is now available as wesnoth.units.find_on_recall - it's just more convenient than passing x=recall to wesnoth.units.find
2019-11-15 22:39:08 -05:00
mattsc
bc956b3e7f Lua AIs: fix experience for killing level 0 units 2018-11-09 06:52:08 -08:00
mattsc
1856377d35 Lua AIs: distinguish between healing locations and villages
There are rating contributions for hexes which heal (not all of which are villages) and others for hexes that provide income (villages). Previously only villages were considered for both types of hexes.
2018-11-07 12:24:31 -08:00
mattsc
0c57ae16e4 Lua AIs: do not use hard-coded values for modifiable parameters 2018-11-05 20:22:11 -08:00
mattsc
37e83f1262 Lua AIs: use math.huge to initialize extrema variables
(cherry-picked from commit cb423b2fbd40fdf5e14549a301fee06237bf4626)
2018-10-07 03:24:40 +00:00
mattsc
6ad4c7e42d Lua AI utility functions: fix for chance-to-hit specials without id
All mainline chance-to-hit weapon specials have ids, but it is not required for UMC specials.

(cherry-picked from commit 5335a2af335ffdce65097e26359e96a0cbe2c733)
2018-10-07 03:24:39 +00:00
mattsc
3906d78abd Lua AIs: avoid using __cfg for accessing weapon specials
(cherry-picked from commit aa59ac54557bc24615cb3f990bcd1dbf6f5d1ea9)
2018-10-07 03:24:39 +00:00
mattsc
b5c8c60ad0 Lua AIs: get unit cost/level directly from proxy unit
These used to be accessible only through unit.__cfg or wesnoth.unit_types.  The Fast Micro AI is not included here as it requires a larger clean-up.

(cherry-picked from commit 8af988c6972abe75e985d0e43bd8186fe4826cb6)
2018-10-07 03:24:37 +00:00
mattsc
fbbbcfc67e Lua AIs: replace print() by std_print()
(cherry-picked from commit 3f54908b0ba69173442107105889caeb891b922d)
2018-10-07 03:24:36 +00:00
mattsc
98e5f0892e Lua AIs: remove unused debug output
(cherry-picked from commit 83c4ef24189c9986eae7535b10ba4babb921e3b8)
2018-10-07 03:24:36 +00:00
mattsc
25b2024ee8 Lua AIs: use unit methods instead of wesnoth functions
(cherry-picked from commit a6866390dfa64097fa4cb099b39736c3e2220ce4)
2018-10-07 03:24:36 +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
Celtic Minstrel
6efc5ae090 Replace helper.distance_between -> wesnoth.map.distance_between (fixes #1686) 2017-05-11 04:14:03 -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
05eb2d7620 Lua AI helper functions: modify a comment 2015-05-20 07:13:11 -07:00
mattsc
25e10121f5 Lua AIs: fix bug occurring when number= in an attack is set to zero
Apparently, when this is the case, the number key is not included at
all, rather than set to zero, when the Lua table containing the attack
information is retrieved.
2015-05-19 19:54:41 -07:00
mattsc
9e8ee00ad0 battle_calcs: provide default value for resistance modifiers
This is done for cases when the value cannot be read from the unit_info
table, which might happen in some UMC.  This fixes a rare bug affecting
the Fast Micro AI attack evaluation
2014-06-15 19:34:25 -07:00
mattsc
82e4ccad4d battle_calcs.attack_rating(): overhaul attack rating system
This was long overdue.  The return value is now much closer to
something describing the actual gain/loss (roughly) in units of gold.
2014-04-30 19:09:28 -07:00
mattsc
7623c5513a battle_calcs: do not use variance of attack in attack rating
This was an idea we tried so that we’d start with the most uncertain
attack first, but it did not work very well.
Keep the code for now, just comment it out.
2014-04-30 19:06:57 -07:00
mattsc
0218b88180 attack_combo_stats(): also cache intermediate battle outcomes
Speeds up some calculations significantly.
2014-04-30 19:05:08 -07:00
mattsc
2336921a81 simulate_combat_fake(): don't fill empty HP chances with zeros
That’s what wesnoth.simulate_combat() does, but is different from the
other functions in battle_calcs.  Only hp_chance[0] needs to be set,
even if it is zero.
2014-04-30 19:02:08 -07:00
mattsc
664eeae888 battle_calcs.lua: fix bug in get_attack_map_unit() for enemy units
Own units with MP left need to be taken off the map before enemy path
finding, not just added to the table.
2014-04-23 18:48:46 -07:00
mattsc
ddfdae5e52 battle_calcs.lua: fix a variable name 2014-04-22 16:46:49 -07:00
mattsc
e87240c67f battle_calcs.lua: avoid using formula= in SUFs
It’s slow for finding units with moves or attacks left. The alternative
method of getting all units and then looping over the table with a
condition is much faster.
2014-04-17 21:03:38 -07:00
mattsc
f6cdd85182 AI helper functions: code cleanup, first pass
These function libraries are still work in progress and change
frequently, so the code cleanup is mostly just to make sure the syntax
is consistent with that used in the Micro AIs.  Changes or improvements
to the algorithms might be made at a later time.
2014-04-17 21:03:38 -07:00
mattsc
ea915d36c2 battle_calcs.attack_rating: bug fix for when AI side has no leader
Check for AI side's leader's existence before trying to calculate
distance from leader.
2013-11-25 19:37:20 -08:00
mattsc
c6db6cd8d5 Lua AIs: Remove unnecessary arguments in call to wesnoth.put_unit() 2013-11-14 20:04:52 -08:00
mattsc
554a95749a battle_calcs.best_defense_map(): add parameter ignore_these_units
This is a table of enemy units whose ZoC is to be ignored for route
finding.  It is useful for determing where the enemy can move while
ignoring own units (enemies of the enemy) that have not moved yet.
2013-10-31 08:22:15 -07:00
mattsc
526debf3e9 battle_calcs.lua: remove some debug code 2013-10-31 08:17:47 -07:00
mattsc
019b6df9c4 Remove double spaces after periods
wmllint complains about this in WML.  This is all in Lua code, done for
consistency only.
2013-07-07 10:35:07 -07:00
mattsc
e7a71a51d7 battle_calcs library: add functions best_defense_map() and get_attack_combos_subset() 2013-05-03 07:06:22 -07:00