<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>AutoTeleporter</title><revhistory><revision><revnumber>2</revnumber><date>2014-03-18 17:00:03</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>1</revnumber><date>2014-03-18 16:59:42</date><authorinitials>Inanna</authorinitials></revision></revhistory></articleinfo><screen><![CDATA[// TELEPORT v0.04 (c) 2014 NeatPortal.com
// This script will check if all your cities are in the specified state, and do nothing if they are.
// Otherwise it will prepare and teleport cities as needed.
// Once all cities are in the right state the script with close the bot (allowing for clean restart by the director).
//
// Usage example: To teleport all cities to Tuscany run bot with these custom command line parameters:
//    -runscript Teleport.txt -teleport tuscany
]]><![CDATA[
if Config.teleport == null goto finish
state = Config.teleport.toUpperCase()
]]><![CDATA[
if state == GetZoneName(city.fieldId).toUpperCase() goto finish
]]><![CDATA[
config wartown:2,comfort:1
recallall
]]><![CDATA[
sleep 30
]]><![CDATA[
// sort by reachTime, descending
label checkArmies
army = city.selfArmies.toArray().sortOn("reachTime", 18)[0]
if army == null goto teleport
]]><![CDATA[
secondsLeft = ceil(TimeDiff(army.reachTime) / 1000) // time left in seconds, rounded up
if secondsLeft > 0 echo "Waiting for armies to return for " + secondsLeft + " seconds"
if secondsLeft > 0 execute "sleep " + secondsLeft
]]><![CDATA[
if city.selfArmies.length > 0 say "Still have armies"
if city.selfArmies.length > 0 goto checkArmies
]]><![CDATA[
label teleport
try = 0
say "Trying to teleport " + city.name + " to " + state
sleep 10
]]><![CDATA[
label tryteleport
try = try + 1
execute "teleport " + state
if !$error goto finalcheck
if try >= 5 goto giveup
say "Can't teleport " + city.name + " to " + state + ", will retry in 5 minutes"
sleep 5:00
goto tryteleport
]]><![CDATA[
label finalcheck
x = 0
label checkCities
if GetZoneName(cities[x].cityManager.fieldId).toUpperCase() != state goto continue
x = x + 1
if x < cities.length goto checkCities
say "All cities are now in " + state + ", will close in 10 seconds"
sleep 10
]]><![CDATA[
// assuming the director will restart the bot
exit
]]><![CDATA[
label giveup
say "Can't teleport " + city.name + " to " + state
]]><![CDATA[
label continue
loadgoals
]]><![CDATA[
label finish]]></screen><!--rule (<hr>) is not applicable to DocBook--><para> <ulink url="http://guide.neatportal.com/wiki/AutoTeleporter/wiki/ScriptExamples#">ScriptExamples</ulink> </para></article>