Difference between revisions of "LuaAI"

From The Battle for Wesnoth Wiki
Line 36: Line 36:
 
  attack_depth                                // int
 
  attack_depth                                // int
 
  caution                                      // double
 
  caution                                      // double
 +
grouping                                    // string
 
  leader_aggression                            // double
 
  leader_aggression                            // double
 
  leader_value                                // double
 
  leader_value                                // double
Line 43: Line 44:
 
  recruitment_ignore_bad_combat                // bool
 
  recruitment_ignore_bad_combat                // bool
 
  recruitment_ignore_bad_movement              // bool
 
  recruitment_ignore_bad_movement              // bool
 +
recruitment_pattern                          // string[]
 
  scout_village_targeting                      // double
 
  scout_village_targeting                      // double
 
  simple_targeting                            // bool
 
  simple_targeting                            // bool

Revision as of 10:12, 8 June 2011

A page containing information on configuring the AI using Lua. NB: previous contents of the page moved to http://wiki.wesnoth.org/LuaAI(old)

Aspects

Patch r49721 enabled users to write aspects using Lua. This simplifies the definition of aspects that are meant to change depending on the game state. A good example could be aggression, which changes depending on the time of the day(since ToD affects the actual battle performance of your forces).
Static aggression:

[aspect]
	id="aggression"
	engine="lua"
	value="0.3"
[/aspect]

Dynamic aggression:

[aspect]
	id=aggression
	engine=lua
	     
	code=<<
		wesnoth.fire("store_time_of_day")
		local value = 0
		tod = tostring(wesnoth.get_variable('time_of_day').name) 
		if (tod == 'Morning') then
			value = 0.2
		else
			value = 1
		end
	
		wesnoth.fire("clear_variable", {name = "time_of_day"})
		return value
	>>      
[/aspect]

Note: the way of getting the ToD is hacky here, but I will create a more elegant method soon(Nephro).
Also note the difference between 'code' and 'value' attributes, this is important.

At the moment, it is possible to create the following aspects using Lua(the list will be constantly updated):

aggression                                   // double
attack_depth                                 // int
caution                                      // double
grouping                                     // string
leader_aggression                            // double
leader_value                                 // double
number_of_possible_recruits_to_force_recruit // double
passive_leader                               // bool
passive_leader_shares_keep                   // bool
recruitment_ignore_bad_combat                // bool
recruitment_ignore_bad_movement              // bool
recruitment_pattern                          // string[]
scout_village_targeting                      // double
simple_targeting                             // bool
support_villages                             // bool
village_value                                // double
villages_per_scout                           // int



Note: simple numeric, bool and string aspect creation can be enabled just by adding a specific factory to registry.cpp, this will also soon be done.

Stages

Candidate actions