Skip to content

Commit

Permalink
Merge pull request #1806 from wesnoth/wfl_filters
Browse files Browse the repository at this point in the history
Use WFL formulas instead of Lua for leadership, backstab, and teleport abilities
  • Loading branch information
CelticMinstrel committed Jun 25, 2017
2 parents b244db3 + c47b3f3 commit 9015d9b
Show file tree
Hide file tree
Showing 26 changed files with 875 additions and 640 deletions.
17 changes: 17 additions & 0 deletions changelog
Expand Up @@ -15,6 +15,9 @@ Version 1.13.8+dev:
* Warnings for using deprecated Lua functions now only appear in debug mode.
* wesnoth.game_config is now accessible in application and mapgen kernels,
though some of its contents are missing.
* New extra argument to wesnoth.match_location and wesnoth.get_locations
allows specifying the teleport_unit.
* Support the extra wesnoth.match_unit arguments also in wesnoth.get_units
* Multiplayer:
* When set to remember your password, Wesnoth now encrypts it. It is still
possible to obtain the password from preferences, but it's no longer as
Expand All @@ -32,6 +35,18 @@ Version 1.13.8+dev:
* Miscellaneous and Bug Fixes:
* Add --report/-R command line switch for printing the same report from the
Game Version dialog's clipboard function to stdout.
* WFL Engine
* Add owner key to terrain space callable, for villages
* Location formulas in [tunnel] now have a teleport_unit variable
* Fix a crash when attempting to call a non-existent function
* The following previously FormulaAI-exclusive functions are now also available
in filter formulas (SUF, SLF, SSF, SWF):
adjacent_locs, location_in_radius, get_unit_type, unit_at, defense_on,
chance_to_hit, movement_cost
* New builtin functions for manipulating locations (available to all formulas):
adjacent_locs, are_adjacent, relative_dir, direction_from, rotate_loc_around
* New enemy_of function checks if its second argument is an enemy of the first
Arguments can be side or unit objects, or integer side indices (1..n)
* WML Engine
* If ai_algorithm is used in [modify_side][ai], it now replaces the whole AI
with the contents of [modify_side][ai], instead of appending these parameters.
Expand All @@ -46,6 +61,8 @@ Version 1.13.8+dev:
* Fix some hotkeys not working (issues #1737 and #1769)
* New vision_cost and jamming_cost keys in SUF
* Integer SUF keys (eg level) now accept a list of ranges
* Fix $other_unit variable in SUF not being available in nested [and] [or] [not]
* Unit ability values can now be specified with WFL

Version 1.13.8:
* Campaigns:
Expand Down
60 changes: 2 additions & 58 deletions data/campaigns/The_Hammer_of_Thursagan/utils/abilities.cfg
Expand Up @@ -6,73 +6,17 @@ _" The presence of this unit inspires own units next to it to deal more damage i
#define ABILITY_INSPIRE
# Canned definition of the Inspire ability to be included in an
# [abilities] clause.
# Note: Works only on units of level 0-5
[leadership]
id=inspire
value=150
value="(25 * (level - other.level + 1))"
cumulative=no
name= _ "inspire"
female_name= _ "female^inspire"
description= _ "This unit can inspire own units that are next to it, making them fight better. Adjacent own units of lower or equal level will deal 25% more damage plus 25% for each level they are below the inspiring unit."
affect_self=no
[affect_adjacent]
[filter]
level=$($other_unit.level - 5)
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=inspire
value=125
cumulative=no
affect_self=no
[affect_adjacent]
[filter]
level=$($other_unit.level - 4)
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=inspire
value=100
cumulative=no
affect_self=no
[affect_adjacent]
[filter]
level=$($other_unit.level - 3)
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=inspire
value=75
cumulative=no
affect_self=no
[affect_adjacent]
[filter]
level=$($other_unit.level - 2)
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=inspire
value=50
cumulative=no
affect_self=no
[affect_adjacent]
[filter]
level=$($other_unit.level - 1)
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=inspire
value=25
cumulative=no
affect_self=no
[affect_adjacent]
[filter]
level=$other_unit.level
formula="level <= other.level"
[/filter]
[/affect_adjacent]
[/leadership]
Expand Down
1 change: 0 additions & 1 deletion data/core/_main.cfg
Expand Up @@ -8,7 +8,6 @@
wesnoth.dofile 'lua/backwards-compatibility.lua'
wesnoth.dofile 'lua/wml-tags.lua'
wesnoth.dofile 'lua/feeding.lua'
wesnoth.dofile 'lua/teleport_filter.lua'
>>
[/lua]

Expand Down
64 changes: 13 additions & 51 deletions data/core/macros/abilities.cfg
Expand Up @@ -99,10 +99,9 @@ This ability will not cure an affected unit of poison, however, only delay its e
#define ABILITY_LEADERSHIP
# Canned definition of the Leadership ability to be included in an
# [abilities] clause.
# Note: Works only on units of level 1-5
[leadership]
id=leadership
value=125
value="(25 * (level - other.level))"
cumulative=no
name= _ "leadership"
female_name= _ "female^leadership"
Expand All @@ -112,51 +111,7 @@ Adjacent own units of lower level will do more damage in battle. When a unit adj
affect_self=no
[affect_adjacent]
[filter]
lua_function="leadership_receiver_filter_5"
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=leadership
value=100
cumulative=no
affect_self=no
[affect_adjacent]
[filter]
lua_function="leadership_receiver_filter_4"
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=leadership
value=75
cumulative=no
affect_self=no
[affect_adjacent]
[filter]
lua_function="leadership_receiver_filter_3"
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=leadership
value=50
cumulative=no
affect_self=no
[affect_adjacent]
[filter]
lua_function="leadership_receiver_filter_2"
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=leadership
value=25
cumulative=no
affect_self=no
[affect_adjacent]
[filter]
lua_function="leadership_receiver_filter_1"
formula="level < other.level"
[/filter]
[/affect_adjacent]
[/leadership]
Expand Down Expand Up @@ -201,15 +156,18 @@ Any units adjacent to this unit will fight as if it were dusk when it is night,
description= _ "This unit may teleport between any two empty villages owned by its side using one of its moves."
[tunnel]
id=village_teleport

[source]
terrain=*^V*
lua_function="teleport_source_filter"
formula="
owner = teleport_unit.side and (unit = teleport_unit or not unit)
where
unit = unit_at(loc)
"
[/source]

[target]
terrain=*^V*
lua_function="teleport_target_filter"
formula="owner = teleport_unit.side and not unit_at(loc)"
[/target]

[filter]
Expand Down Expand Up @@ -349,7 +307,11 @@ Enemy units cannot see this unit while it is in deep water, except if they have
multiply=2
active_on=offense
[filter_opponent]
lua_function="backstab_defender_filter"
formula="
enemy_of(self, flanker) and not flanker.petrified
where
flanker = unit_at(direction_from(loc, other.facing))
"
[/filter_opponent]
[/damage]
#enddef
Expand Down
58 changes: 0 additions & 58 deletions data/lua/teleport_filter.lua

This file was deleted.

7 changes: 7 additions & 0 deletions projectfiles/VC12/wesnoth.vcxproj
Expand Up @@ -1088,6 +1088,12 @@
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Formula\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Formula\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\formula\function_gamestate.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Formula\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Formula\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Formula\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Formula\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\formula\string_utils.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Formula\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Formula\</ObjectFileName>
Expand Down Expand Up @@ -3596,6 +3602,7 @@
<ClInclude Include="..\..\src\formula\debugger_fwd.hpp" />
<ClInclude Include="..\..\src\formula\formula.hpp" />
<ClInclude Include="..\..\src\formula\formula_fwd.hpp" />
<ClInclude Include="..\..\src\formula\function_gamestate.hpp" />
<ClInclude Include="..\..\src\formula\function.hpp" />
<ClInclude Include="..\..\src\formula\string_utils.hpp" />
<ClInclude Include="..\..\src\formula\tokenizer.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions projectfiles/VC12/wesnoth.vcxproj.filters
Expand Up @@ -1538,6 +1538,9 @@
<ClCompile Include="..\..\src\preferences\lobby.cpp">
<Filter>Preferences</Filter>
</ClCompile>
<ClCompile Include="..\..\src\formula\function_gamestate.cpp">
<Filter>Formula</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\addon\client.hpp">
Expand Down Expand Up @@ -2982,6 +2985,9 @@
<ClInclude Include="..\..\src\preferences\lobby.hpp">
<Filter>Preferences</Filter>
</ClInclude>
<ClInclude Include="..\..\src\formula\function_gamestate.hpp">
<Filter>Formula</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\src\tests\test_sdl_utils.hpp">
Expand Down
1 change: 1 addition & 0 deletions source_lists/wesnoth
Expand Up @@ -108,6 +108,7 @@ formula/debugger.cpp
formula/debugger_fwd.cpp
formula/formula.cpp
formula/function.cpp
formula/function_gamestate.cpp
formula/string_utils.cpp
formula/tokenizer.cpp
formula/variant.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/ai/formula/ai.cpp
Expand Up @@ -534,7 +534,7 @@ variant formula_ai::get_value(const std::string& key) const
return get_keeps();
} else if(key == "map")
{
return variant(std::make_shared<gamemap_callable>(resources::gameboard->map()));
return variant(std::make_shared<gamemap_callable>(*resources::gameboard));
} else if(key == "villages")
{
return villages_from_set(resources::gameboard->map().villages());
Expand Down

0 comments on commit 9015d9b

Please sign in to comment.