#textdomain wesnoth-ai [test] id=goto name= _ "Goto" next_scenario=micro_ai_test map_data="{ai/micro_ais/maps/goto.map}" {DEFAULT_SCHEDULE} turns=-1 victory_when_enemies_defeated=no # wmllint: local spellings Minry Aethubry Gadoc Senvan AIs [side] side=1 controller=human hidden=no name=Vaddan id=Vaddan type=Outlaw persistent=no team_name=Vaddan,humans user_team_name= _ "Vaddan" canrecruit=yes recruit=Ruffian,Footpad,Thug,Poacher gold=0 [/side] [side] side=2 controller=ai type=General id=leader2 name=Minry persistent=no team_name=humans,hum_wood user_team_name= _ "Humans" scroll_to_leader=no canrecruit=yes recruit=Spearman,Bowman gold=0 income=-2 [/side] [side] side=3 controller=ai type=Poacher id=leader3 persistent=no team_name=woodsmen,hum_wood user_team_name= _ "Woodsmen" canrecruit=yes recruit=Woodsman gold=0 income=-2 [/side] [side] side=4 controller=ai type=Saurian Flanker id=leader4 persistent=no team_name=saurians,Vaddan,woodsmen user_team_name= _ "Saurians" canrecruit=yes recruit=Saurian Augur,Saurian Skirmisher gold=50 income=12 [/side] [side] side=5 controller=ai type=Lieutenant name=Gadoc id=leader5 persistent=no team_name=humans,hum_wood user_team_name= _ "Humans" canrecruit=yes recruit=Spearman,Bowman gold=50 income=8 [/side] [side] side=6 controller=ai type=Lieutenant name=Senvan id=leader6 persistent=no team_name=humans,hum_wood user_team_name= _ "Humans" canrecruit=yes recruit=Spearman,Bowman gold=50 income=8 [/side] [side] side=7 controller=ai no_leader=yes persistent=no team_name=Vaddan,hum_wood,saurians user_team_name= _ "team_name^Animals" gold=0 income=-2 [/side] [side] side=8 controller=ai no_leader=yes persistent=no team_name=saurians user_team_name= _ "team_name^Ghosts" gold=0 income=-2 [/side] [side] # This side is only here because we need one persistent side for the game to go on side=9 controller=null persistent=yes save_id=Grnk hidden=yes [/side] # Put all the units and markers out there [event] name=prestart {VARIABLE scenario_name goto} # Put all the units out there # The Side 2 Messengers [unit] side=2 type=Spearman id=messenger1 x,y=40,4 random_traits=no [/unit] [unit] side=2 type=Bowman id=messenger2 x,y=41,4 random_traits=no [/unit] # Side 3 guardians {UNIT 3 Woodsman 15 10 id=guard1} {UNIT 3 Woodsman 13 12 id=guard2} # Side 7 bats {REPEAT 4 {UNIT 7 (Vampire Bat) 35 13 ()}} # The River Fort commander {UNIT 5 Sergeant 12 30 (id,name=fort_commander,Aethubry)} # Labels {SET_LABEL 7 3 _"General Minry"} {SET_LABEL 4 21 _"Lieutenant Gadoc"} {SET_LABEL 14 16 _"Lieutenant Senvan"} {SET_LABEL 12 30 _"Sergeant Aethubry"} # Now activate the Micro AIs # Set up the Goto Micro AI for the two messengers with ca_score set # so that messenger2 always goes first [micro_ai] side=2 ai_type=goto action=add ca_id=messenger1 [filter] id=messenger1 [/filter] [filter_location] x,y=6-7,2-4 terrain=C* [/filter_location] ca_score=210001 [/micro_ai] [micro_ai] side=2 ai_type=goto action=add ca_id=messenger2 [filter] id=messenger2 [/filter] [filter_location] x,y=6-7,2-4 terrain=C* [/filter_location] ca_score=210002 [/micro_ai] # The two Side 3 guardians don't move unless a Side 1 unit is within 8 hexes [micro_ai] side=3 ai_type=goto action=add [filter] id=guard1 [/filter] [filter_location] [filter] id=guard1 [/filter] [not] [filter] side=1 [/filter] radius=8 [/not] [/filter_location] [/micro_ai] [micro_ai] side=3 ai_type=goto action=add [filter] id=guard2 [/filter] [filter_location] [filter] id=guard2 [/filter] [not] [filter] side=1 [/filter] radius=8 [/not] [/filter_location] [/micro_ai] # Send the Side 5 and 6 recruits to the River Fort [micro_ai] side=5 ai_type=goto action=add [filter] type=Spearman,Bowman [/filter] [filter_location] x,y=11-13,29-30 terrain=C* [/filter_location] release_unit_at_goal=yes [/micro_ai] [micro_ai] side=6 ai_type=goto action=add [filter] type=Spearman,Bowman [/filter] [filter_location] x,y=12,30 radius=1 [/filter_location] release_all_units_at_goal=yes [/micro_ai] # Make the bats go to the corners of the map [micro_ai] side=7 ai_type=goto action=add [filter_location] x=1,1,44,44 y=1,33,1,33 [/filter_location] unique_goals=yes [/micro_ai] # The ghost move to the southern edge of the map, avoiding enemies [micro_ai] side=8 ai_type=goto action=add [filter_location] y=33 [/filter_location] avoid_enemies=1 [/micro_ai] # Make the saurians behave like swamp lurkers [micro_ai] side=4 ai_type=lurkers action=add [filter] type=Saurian Skirmisher,Saurian Augur [/filter] [filter_location] terrain=S* [/filter_location] [/micro_ai] # The right-click menu items [set_menu_item] id=m01_new_footpad description= _ "Place Side 1 Footpad" image=units/human-outlaws/footpad.png~CROP(26,17,24,24) [show_if] {VARIABLE_CONDITIONAL scenario_name equals goto} [/show_if] [command] {UNIT 1 Footpad $x1 $y1 ()} [/command] [/set_menu_item] [set_menu_item] id=m02_kill_unit description= _ "Kill Unit under Cursor" image=items/potion-poison.png~CROP(24,29,24,24) [show_if] {VARIABLE_CONDITIONAL scenario_name equals goto} [/show_if] [command] [kill] x,y=$x1,$y1 [/kill] [/command] [/set_menu_item] [set_menu_item] id=m03_null_control description= _ "Turn off human control of Side 1" image=items/ring-gold.png~CROP(26,26,20,20) [show_if] {VARIABLE_CONDITIONAL scenario_name equals goto} [/show_if] [command] [modify_side] side=1 controller=null [/modify_side] [end_turn] [/end_turn] [/command] [/set_menu_item] [set_menu_item] id=m04_end_animals description= _ "End Scenario" image=items/ring-red.png~CROP(26,26,20,20) [show_if] {VARIABLE_CONDITIONAL scenario_name equals goto} [/show_if] [command] # So that game goes on to next scenario [modify_side] side=9 controller=human [/modify_side] {MESSAGE narrator "wesnoth-icon.png" "" _"Well, that was that."} [endlevel] result=victory bonus=no carryover_percentage=0 carryover_report=no linger_mode=no [/endlevel] [/command] [/set_menu_item] [/event] [event] name=start #{MESSAGE narrator "wesnoth-icon.png" "" _"Text"} # wmllint: unbalanced-on {MESSAGE narrator "wesnoth-icon.png" "" _"This scenario demonstrates a variety of different uses of the Goto Micro AI. All AI sides are controlled by this MAI in one way or another (except for the saurians, which are run by the Lurkers Micro AI). Messages will be displayed throughout the scenario to point out what the units are doing. The player controls Side 1. There are right-click context menu options for adding Side 1 units to the map and for taking them off again. This is useful mostly for testing how the Side 3 guardians react. Note: The Goto 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: unbalanced-off [objectives] side=1 summary= _ "Watch the AI units do their things" [objective] description= _ "Use right-click option" condition=win [/objective] [objective] description= _ "Death of Vaddan" condition=lose [/objective] [note] description= _ "Check out the right-click menu options for additional actions" [/note] [/objectives] [/event] # Dialog involving the messengers [event] name=side 2 turn [message] speaker=messenger1 message= _ "The bridge is out. What do we do now?" [/message] [message] speaker=messenger2 message= _ "Looks like we need to take the long way around to get to General Minry." [/message] [/event] [event] name=side 3 turn [message] speaker=leader3 message= _ "Chaps, ignore everybody except for that swindler Vaddan and his men. Stay in place until any of his units gets within 8 hexes of you. Note: This is a demonstration of how the Goto Micro AI can be used to code guardian units, although one of the dedicated Guardian Micro AIs will often be better suited for that purpose." [/message] [/event] [event] name=side 7 turn [message] side=7 type=Vampire Bat message= _ "Us four bats switch between running off to the corners of the map (each one to a different corner), and getting back in a group right here. Either behavior is set up with a single [micro_ai] tag, one with 'unique_goals=yes', the other without." # wmllint: no spellcheck [/message] [/event] [event] name=side 8 turn {UNIT 8 Ghost 29 1 id=ghost1} {MESSAGE ghost1 "" "" _"Aaiiieeeeeee !!!"} {MESSAGE messenger2 "" "" _"O no, a ghost!"} {MESSAGE messenger1 "" "" _"Don't worry, those are really shy ghosts. Nobody knows why, but they always appear in the north this time of year and move through to the south. Also, very unusually for ghosts, they seem to be scared of everybody and avoid other units as much as possible -- except for the bats and saurians, with which they seem to get along just fine for some reason. So as long as we don't corner them, they'll leave us alone."} [event] name=side 8 turn first_time_only=no {RANDOM 0..99} [if] [have_unit] side=8 count=0-2 [/have_unit] [variable] name=random less_than=50 [/variable] [then] {UNIT 8 Ghost 29 1 ()} [/then] [/if] {CLEAR_VARIABLE random} [/event] # Remove ghosts that have made it all the way south [event] name=side 8 turn end first_time_only=no [store_unit] [filter] side=8 y=33 [/filter] variable=stored_ghosts [/store_unit] {FOREACH stored_ghosts i_g} [kill] id=$stored_ghosts[$i_g].id [/kill] {NEXT i_g} {CLEAR_VARIABLE stored_ghosts} [/event] [/event] # When the messengers get across the river, send them on separate paths [event] name=moveto [filter] id=messenger1,messenger2 x=28-34 [/filter] [message] speaker=messenger2 message= _ "I'll take the route straight through the mountains. It's much shorter than following the trail all the way around in the south." [/message] [message] speaker=messenger1 message= _ "You're crazy. It might be shorter as the crow flies, but it will take you forever to get through those mountains. Note: The messengers are controlled by Goto Micro AI definitions that differ by a single line, 'use_straight_line=yes/no'." # wmllint: no spellcheck [/message] [micro_ai] side=2 ai_type=goto action=change ca_id=messenger2 [filter] id=messenger2 [/filter] [filter_location] x,y=6-7,2-4 terrain=C* [/filter_location] use_straight_line=yes ca_score=210002 [/micro_ai] [/event] # When the first messenger gets to the castle [event] name=moveto [filter] id=messenger1,messenger2 x,y=6-7,2-4 terrain=C* [/filter] [message] speaker=unit message= _ "I told you so!" [/message] [/event] # Dialog involving the River Fort [event] name=side 5 turn 2 [message] speaker=leader5 message= _ "Men, head down to the River Fort and get your orders from Sergeant Aethubry. I want each and every one of you to report to him before going east to fight those saurians." [/message] [/event] [event] name=side 6 turn 2 [message] speaker=leader6 message= _ "Hah, that's that pencil pusher Gadoc for you! Men, I want you to move toward the River Fort as well, but it's good enough for one of you to report to Sergeant Aethubry. Once that has happened, the rest of you can head into battle directly." [/message] [/event] # When the Side 5 units make it to Aethubry [event] name=moveto first_time_only=no [filter] side=5 [filter_location] x,y=11-13,29-30 terrain=C* [/filter_location] [/filter] [message] speaker=unit message= _ "$unit.language_name $unit.name from Lieutenant Gadoc's squadron reporting for duty, sir." [/message] [fire_event] name=sergeant_replies [primary_unit] id=$unit.id [/primary_unit] [/fire_event] [/event] [event] name=sergeant_replies [message] speaker=fort_commander message= _ "Ready to fight those saurians, soldier?" [/message] [message] speaker=unit message= _ "Yes, sir." [/message] [event] name=sergeant_replies [message] speaker=fort_commander message= _ "Very good, $unit.language_name. Now go help your comrade get rid of that saurian infestation in the swamps." [/message] [event] name=sergeant_replies [message] speaker=fort_commander message= _ "Maybe if I ignore them, they'll just go away?" [/message] [/event] [/event] [/event] # When the first Side 6 unit makes it to Aethubry [event] name=moveto [filter] side=6 [filter_location] x,y=12,30 radius=1 [/filter_location] [/filter] [message] speaker=unit message= _ "Lieutenant Senvan's men reporting for duty, sir." [/message] [message] speaker=fort_commander message= _ "Ah, Lieutenant Senvan... Is every single one of you going to bother me individually as well?" [/message] [message] speaker=unit message= _ "No, sir. Lieutenant Senvan ordered us to head into battle as soon as I have reported to you." [/message] [message] speaker=fort_commander message= _ "Well, that's a relief. Somebody knows how to use his ... I mean, very well, off you go then. " + {WHISPER _"I wouldn't say anything negative about one of my superior officers now, would I?"} [/message] [/event] # When the bats make it to the 4 corners, make then move into a group again [event] name=moveto [filter] side=7 type=Vampire Bat [/filter] first_time_only=no [if] [have_unit] side=7 type=Vampire Bat x,y=1,1 [/have_unit] [have_unit] side=7 type=Vampire Bat x,y=1,33 [/have_unit] [have_unit] side=7 type=Vampire Bat x,y=44,1 [/have_unit] [have_unit] side=7 type=Vampire Bat x,y=44,33 [/have_unit] [then] [message] side=7 type=Vampire Bat message= _ "We've all made it to the corners, let's get back together again." [/message] # Send the bats back to their starting point [micro_ai] side=7 ai_type=goto action=change [filter_location] x,y=35,13 [/filter_location] [/micro_ai] [/then] [/if] [/event] # When the bats are back together, make them go to the corners again [event] name=moveto [filter] side=7 type=Vampire Bat [/filter] first_time_only=no [if] [have_unit] side=7 type=Vampire Bat count=4 [filter_location] x,y=35,13 radius=2 [/filter_location] [/have_unit] [then] [message] side=7 type=Vampire Bat message= _ "We're back together, let's head out to the corners again." [/message] # Make the bats go to the corners of the map [micro_ai] side=7 ai_type=goto action=change [filter_location] x=1,1,44,44 y=1,33,1,33 [/filter_location] unique_goals=yes [/micro_ai] [/then] [/if] [/event] # The River Fort commander never moves [event] name=side 5 turn refresh first_time_only=no {MODIFY_UNIT id=fort_commander moves 0} [/event] [/test]