--Prevent standalone execution: if not TRAINSPORTED then print("To prevent players from harm, this file may only be executed by the trAInsported game.") return end --AI by AlienJoker: -- Daniels kleine KI remPositions = {} passengers={} trainDest={} passNo=1 posNo=1 ovl=0 pname="" cache=750 function ai.init(map, money, maximumTrains) buyTrain(map.height/2,map.width/2, "E") end function ai.newPassenger(name, x, y, destX, destY, vipTime) money=getMoney() if(money>24) then buyTrain(x,y, "E") end passengers[passNo]={name=name,x=x,y=y} passNo=passNo+1 end function ai.blocked(train, possibleDirections, prevDirection) dir=randomDir(train) return end function ai.passengerBoarded(train, passenger) delPass(passenger.Name) --remove from trainDestList i=1 while i<=#trainDest do if trainDest[i]==true then if trainDest[i].name==passenger.name then table.remove (trainDest,i) return end end i=i+1 end end function ai.enoughMoney() buyTrain(passengers[passNo-1].x,passengers[passNo-1].y) end function ai.foundPassengers(train,passengers) dist=100 pass=nil cPass=1 if train.passenger==nil then while cPass <= #passengers do cDist=newDistance(train,passengers[cPass]) if cDist0) then prefDirX = "E" end if (destY>0) then prefDirY="S" end dir=calcDirection(train,destX,destY,directions,prefDirX,prefDirY) dir=checkBadOption(train,directions,dir) storeChoice(train,dir) return dir; end function FindClosestPassenger(train) dist=100 cPass=1 maxCheck=10 while cPass <= #passengers and cPass<=maxCheck do cDist=distance(train,passengers[cPass].x,passengers[cPass].y) if cDistmath.abs(ydiff)) then dir=prefDirX choosePar="x" end if (directions[dir]~=true) then if (choosePar=="x") then dir="N" if (ydiff>0) then dir="S" end else dir="W" if (xdiff>0) then dir="E" end end checkCount=0 while (directions[dir]~=true and checkCount<7) do dir=validDir(train,directions,dir) checkCount=checkCount+1 end end return dir end function randomDir(train) newdir=math.random(4) if (newdir==1) then rdir="W" elseif (newdir==2) then rdir="E" elseif (newdir==3) then rdir="S" elseif (newdir==4) then rdir="N" end return rdir end function validDir(train,directions,noGoDir) if (directions["N"] and noGoDir~="N") then return "N"; elseif (directions["S"] and noGoDir~="S") then return "S"; elseif (directions["W"] and noGoDir~="W") then return "W"; elseif (directions["E"] and noGoDir~="E") then return "E"; end end function newDistance(train,passenger) res=sqrt((train.x-passenger.destX)^2 + (train.y-passenger.destY)^2) return res end function distance(train,x,y) res=sqrt((train.x-x)^2 + (train.y-y)^2) return res end function delPass(name) i=1 while i1) then while i>=1 do if (remPositions[i].tID==train.ID) then table.remove (remPositions,i) posNo=posNo-1 end i=i-1 end end end