extracted lua ai code into external .lua files
This commit is contained in:
parent
9d9b045238
commit
b873f11333
3 changed files with 46 additions and 14 deletions
|
@ -1,25 +1,15 @@
|
|||
#textdomain wesnoth
|
||||
[ai]
|
||||
id=ai_lua
|
||||
description=Lua Test AI version 3
|
||||
id=ai_lua_simple
|
||||
description=Lua Simple AI
|
||||
version=10710
|
||||
[engine]
|
||||
name="lua"
|
||||
code= << local side = ... return {
|
||||
side = side,
|
||||
move_full = function(FROM,TO) wesnoth.ai_execute_move(side,FROM.x,FROM.y,TO.x,TO.y,1) end,
|
||||
move = function(FROM,TO) wesnoth.ai_execute_move(side,FROM.x,FROM.y,TO.x,TO.y,0) end,
|
||||
attack_simple = function(ATT,DEF) wesnoth.ai_execute_attack(side,ATT.x,ATT.y,DEF.x,DEF.y,-1,0.5) end,
|
||||
recruit = function(UNIT_NAME,LOC) wesnoth.ai_execute_recruit(side,UNIT_NAME,LOC.x,LOC.y) end,
|
||||
recall = function(UNIT_ID,LOC) wesnoth.ai_execute_recall(side,UNIT_ID,LOC.x,LOC.y) end,
|
||||
stop = function(LOC,MOVES,ATTACKS) wesnoth.ai_execute_stopunit(side,LOC.x,LOC.y,MOVES,ATTACKS) end
|
||||
}
|
||||
>>
|
||||
code="side = ... local ai = wesnoth.dofile('ai/lua/simple_ai.lua') return ai"
|
||||
[/engine]
|
||||
[stage]
|
||||
engine="lua"
|
||||
code= << local ai = ... ai.move_full({x=15, y=2},{x=11, y=4})
|
||||
>>
|
||||
code= "(...):play_turn()"
|
||||
[/stage]
|
||||
[/ai]
|
||||
|
||||
|
|
33
data/ai/lua/ai.lua
Normal file
33
data/ai/lua/ai.lua
Normal file
|
@ -0,0 +1,33 @@
|
|||
local ai = { side = side }
|
||||
|
||||
--! do a full move from FROM to TO. Unit's movement points are set to 0 after a move
|
||||
function ai:move_full(FROM,TO)
|
||||
wesnoth.ai_execute_move(self.side,FROM.x,FROM.y,TO.x,TO.y,1)
|
||||
end
|
||||
|
||||
--! do a partial move from FROM to TO.
|
||||
function ai:move(FROM,TO)
|
||||
wesnoth.ai_execute_move(self.side,FROM.x,FROM.y,TO.x,TO.y,0)
|
||||
end
|
||||
|
||||
--! do a simple attack using aggression 0.5 and choosing best weapon
|
||||
function ai:attack_simple(ATT,DEF)
|
||||
wesnoth.ai_execute_attack(self.side,ATT.x,ATT.y,DEF.x,DEF.y,-1,0.5)
|
||||
end
|
||||
|
||||
--! recruit a UNIT_NAME on LOC
|
||||
function ai:recruit(UNIT_NAME,LOC)
|
||||
wesnoth.ai_execute_recruit(self.side,UNIT_NAME,LOC.x,LOC.y)
|
||||
end
|
||||
|
||||
--! recall a UNIT_ID at LOC
|
||||
function ai:recall(UNIT_ID,LOC)
|
||||
wesnoth.ai_execute_recall(self.side,UNIT_ID,LOC.x,LOC.y)
|
||||
end
|
||||
|
||||
--! stop a unit at LOC - remove MOVES and/or remove ATTACK
|
||||
function ai:stop(LOC,MOVES,ATTACKS)
|
||||
wesnoth.ai_execute_stopunit(self.side,LOC.x,LOC.y,MOVES,ATTACKS)
|
||||
end
|
||||
|
||||
return ai
|
9
data/ai/lua/simple_ai.lua
Normal file
9
data/ai/lua/simple_ai.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
local ai = wesnoth.dofile('ai/lua/ai.lua')
|
||||
|
||||
function ai:play_turn()
|
||||
--! only a few thousands lines have to be added here to complete the ai
|
||||
my_leader = wesnoth.get_units( {canrecruit="yes", side=self.side})[1]
|
||||
self:move_full(my_leader,{x=11, y=4})
|
||||
end
|
||||
|
||||
return ai
|
Loading…
Add table
Reference in a new issue