#textdomain wesnoth-ai [test] id=protect_unit name= _ "Protect Unit" next_scenario=micro_ai_test map_data="{ai/micro_ais/maps/protect_unit.map}" {DEFAULT_SCHEDULE} turns=-1 victory_when_enemies_defeated=no [side] side=1 controller=ai name= _ "Langzhar" id=Langzhar type=Lieutenant persistent=no team_name=Langzhar user_team_name= _ "team_name^Langzhar" recruit=Spearman,Bowman gold=200 [/side] [side] side=2 controller=ai name= _ "Koorzhar" id=Koorzhar type=Lieutenant persistent=no defeat_condition=no_units_left team_name=Koorzhar user_team_name= _ "team_name^Koorzhar" recruit=Spearman,Bowman gold=175 [ai] [goal] [criteria] id=Rossauba [/criteria] value=100 [/goal] [/ai] {ai/aliases/stable_singleplayer.cfg} [ai] version=10710 [engine] name="lua" code= << local ai = ... return wesnoth.require("ai/micro_ais/engines/priority_target_engine.lua").init(ai) >> [/engine] [modify_ai] side=2 action=add # wmllint: unbalanced-on path=stage[main_loop].candidate_action[] # wmllint: unbalanced-off [candidate_action] engine=lua name=change_attacks_aspect id=change_attacks_aspect max_score=999999 evaluation="return (...):change_attacks_aspect('Rossauba')" execution="(...):change_attacks_aspect()" [/candidate_action] [/modify_ai] [/ai] [/side] [side] # This side is only here because we need one persistent side for the game to go on side=3 controller=null persistent=yes save_id=Grnk hidden=yes [/side] # Prestart actions [event] name=prestart {VARIABLE scenario_name protect_unit} [micro_ai] # Required keys of [micro_ai] tag side=1 ai_type=protect_unit action=add [unit] id=Rossauba goal_x,goal_y=1,1 [/unit] [/micro_ai] # Put the mage out there [unit] type=Elder Mage id=Rossauba name=Rossauba side=1 x,y=20,9 upkeep=loyal overlays=misc/hero-icon.png [/unit] # Goal signpost for Rossauba {PLACE_IMAGE "scenery/signpost.png" 1 1} {SET_LABEL 1 1 _"Move Rossauba here"} [/event] [event] name=start {STORE_UNIT_VAR id=Koorzhar profile profile} {MESSAGE Koorzhar "$profile~FL()~RIGHT()" "" _"There's that traitor wizard. Let's get him."} {CLEAR_VARIABLE profile} {MESSAGE Langzhar "" "" _"Men, you know the deal. We must protect Rossauba under all circumstances. Even my survival is not as important."} {MESSAGE Rossauba "" "" _"That's very kind of you, but ..."} {MESSAGE Langzhar "" "" _"No buts! You stay behind the lines and do not engage in battle unless there is no risk to your life, is that understood? And get to that signpost in the northwest if it is safe."} [message] speaker=narrator caption= _ "Question for the Player" image=wesnoth-icon.png # wmllint: unbalanced-on message= _ "In this scenario, the AI playing the humans in the east (Langzhar) is instructed to protect the wizard Rossauba, while moving him safely to the signpost. On the other side, Koorzhar's units (in the west) will primarily attack Rossauba, even if a better target is available. Do you want to play either of the sides or let the AIs battle it out among themselves? Note: The Protect Unit AI is coded as a Micro AI. A Micro AI can be added and adapted to the need of a scenario easily using only WML and the [micro_ai] tag. Check out the Micro AI wiki page at http://wiki.wesnoth.org/Micro_AIs for more information." # wmllint: no spellcheck # wmllint: unbalanced-off [option] message= _ "I'll watch the two AIs fight it out" # wmllint: no spellcheck [/option] [option] message= _ "I'll play Langzhar's side (to see how Koorzhar's units target Rossauba)" [command] [modify_side] side=1 controller=human [/modify_side] [/command] [/option] [option] message= _ "I'll play Koorzhar's side (to see how Langzhar's units protect Rossauba)" [command] [modify_side] side=2 controller=human [/modify_side] [/command] [/option] [/message] [objectives] side=1 summary= _ "Protect Rossauba while moving him to the signpost" [objective] description= _ "Rossauba makes it to the signpost" condition=win [/objective] [objective] description= _ "Death of Rossauba" condition=lose [/objective] [objective] description= _ "Death of Langzhar" condition=lose [/objective] [/objectives] [objectives] side=2 summary= _ "Get rid of that traitor wizard Rossauba" [objective] description= _ "Defeat Rossauba" condition=win [/objective] [objective] description= _ "Rossauba makes it to the signpost" condition=lose [/objective] [objective] description= _ "Death of Koorzhar" condition=lose [/objective] [/objectives] [/event] # Delay Rossauba by one turn [event] name=side 1 turn 1 refresh {MODIFY_UNIT id=Rossauba moves 0} [/event] # All the end scenario events involving Rossauba are treated as victories # (since the player could play either side) # -> only defeat: when side leaders die in human-controlled mode # When Rossauba dies: [event] name=last breath [filter] id=Rossauba [/filter] {MESSAGE Rossauba "" "" _"I held out for as long as I could."} [fire_event] name=end_scenario [/fire_event] [/event] # When Rossauba makes it to the signpost: [event] name=moveto [filter] id=Rossauba x,y=1,1 [/filter] {MESSAGE Rossauba "" "" _"I made it"} [fire_event] name=end_scenario [/fire_event] [/event] [event] name=end_scenario # So that game goes on to next scenario [modify_side] side=3 controller=human [/modify_side] [endlevel] result=victory bonus=no carryover_percentage=0 carryover_report=no linger_mode=no [/endlevel] [/event] [/test]