% % Go to object - quickly % % This module provides functions to quickly go to particular objects % by id, in the form of convenient short wrappers around `UI.GotoScreen'. % For fast typists, this is much faster than the conventional way (using % the search function or manual browsing). % % + sh shows a ship on the ship screen/starcharts % + pl shows a planet on the planet screen/starcharts % + sb shows a starbase on the starbase screen % + fl shows the fleet for a ship on the fleet screen % + go looks for ships first, then planets % % Each function takes an argument, which it will try to use as an ID. % If the argument is a string, then the functions search for the first % ship or planet with that string in its name, preferably yours. % Print "[Goto.q, 02/Apr/2002]" % Modified significantly by Eric Wald Bind ShipScreen "p" := "pl Orbit$" Bind ControlScreen "@" := "Goto.GetName" Sub sh (sid) If IsString(sid) Then Local sname = sid sid := FindShip(InStr(Name, sname) > 0 and Owner$=My.Race$) If IsEmpty(sid) Then sid := FindShip(InStr(Name, sname) > 0) EndIf If IsEmpty(sid) or sid <= 0 or sid > 500 Then Print 'Cannot find ship "', sname, '"' Return EndIf If Ships(sid).Owner$ Then With Ships(sid) Do If Owner$=My.Race$ Then UI.GotoScreen 1, sid Else UI.GotoChart Loc.X, Loc.Y EndIf EndWith Else Print "Nothing known about ship #", sid EndIf EndSub Sub pl (pid) If IsString(pid) Then Local pname = pid pid := FindPlanet(InStr(Name, pname) > 0 and Owner$=My.Race$) If IsEmpty(pid) Then pid := FindPlanet(InStr(Name, pname) > 0) EndIf If IsEmpty(pid) or pid <= 0 or pid > 500 Then Print 'Cannot find planet "', pname, '"' Return EndIf With Planets(pid) Do If Owner$=My.Race$ And Colonists>0 Then UI.GotoScreen 2, pid Else If Loc.X Then UI.GotoChart Loc.X, Loc.Y Else Print "Nothing known about planet #", pid EndIf EndIf EndWith EndSub Sub sb (bid) If IsString(bid) Then Local pname = bid bid := FindPlanet(InStr(Name, pname) > 0 and Owner$=My.Race$) If IsEmpty(bid) Then bid := FindPlanet(InStr(Name, pname) > 0) EndIf If IsEmpty(bid) or bid <= 0 or bid > 500 Then Print 'Cannot find planet "', pname, '"' Return EndIf If Planets(bid).Base.YesNo And Planets(bid).Owner$=My.Race$ Then UI.GotoScreen 3, pid Else Print "No starbase known at planet #", pid EndIf EndSub Sub fl (fid) If IsString(fid) Then Local sname = fid fid := FindShip(InStr(Name, sname) > 0 and Owner$=My.Race$) If IsEmpty(fid) Then fid := FindShip(InStr(Name, sname) > 0) EndIf If IsEmpty(pid) or pid <= 0 or pid > 500 Then Print 'Cannot find ship "', sname, '"' Return EndIf Local f = Ships(fid).Fleet$ If f Then UI.GotoScreen 10, f Else Print "Ship #", f, " is not in a fleet" EndIf EndSub % Throws up a dialog box, and calls "go" Sub Goto.GetName If Not System.GUI Then Return UI.Input "Where do you want to go?", "Go To Planet/Ship..." go UI.Result EndSub % Tries to guess what the user means; could be a ship or a planet Sub go (obj) If IsEmpty(Zap(obj)) Then Return Local uid := Val(Str(obj)) If Not IsEmpty(uid) and 0 < uid and uid < 500 Then % We have a number; probably the ID of a ship or planet If Ships(uid).Owner$ = My.Race$ Then sh uid Return EndIf If Planets(uid).Owner$ = My.Race$ Then pl uid Return EndIf If Ships(uid).Loc.X > 0 Then sh uid Return EndIf If Planets(uid).Loc.X > 0 Then pl uid Return EndIf EndIf % Not a valid ID number, so probably part of a name obj := Str(obj) uid := FindPlanet(InStr(Name, obj) > 0 and Owner$=My.Race$) If Not IsEmpty(uid) Then pl uid Return EndIf uid := FindShip(InStr(Name, obj) > 0 and Owner$=My.Race$) If Not IsEmpty(uid) Then sh uid Return EndIf uid := FindPlanet(InStr(Name, obj) > 0) If Not IsEmpty(uid) Then pl uid Return EndIf uid := FindShip(InStr(Name, obj) > 0) If Not IsEmpty(uid) Then sh uid Return EndIf % Not a part of a name, so maybe in the Comment? uid := FindPlanet(InStr(Comment, obj) > 0 and Owner$=My.Race$) If Not IsEmpty(uid) Then pl uid Return EndIf uid := FindShip(InStr(Comment, obj) > 0 and Owner$=My.Race$) If Not IsEmpty(uid) Then sh uid Return EndIf uid := FindPlanet(InStr(Comment, obj) > 0) If Not IsEmpty(uid) Then pl uid Return EndIf uid := FindShip(InStr(Comment, obj) > 0) If Not IsEmpty(uid) Then sh uid Return EndIf UI.Message 'Cannot find anything about "' & obj & '"', 'Goto Error' EndSub