@program Lite Utility Navigation with Accel $include $lite/Code $include $lib/scrat (added by Zobeid, 31 Jul 2002) lvar +cX ( current X coordinate of the ship ) lvar +cY ( Current Y coordinate of the ship ) lvar +cZ ( Current Z coordinate of the ship ) lvar +nX ( Next X coordinate of the ship ) lvar +nY ( Next Y coordinate of the ship ) lvar +nZ ( Next Z coordinate of the ship ) lvar +dX ( destination X coordinate of the ship ) lvar +dY ( destination Y coordinate of the ship ) lvar +dZ ( destination Z coordinate of the ship ) lvar +Ship ( DBref of the ship ) lvar +Construct ( DBref of the construct parent ) : Navigation.ResetAccel ( -- ) +ship "drive" over "_accel/drivelo" getprop setprop +ship "_accel/numsectors" 0 setprop ; : Navigation.Help ( -- ) ( . . . . . ) me @ "^white^Help information for navigation" ansi_notify ( . . . . . ) me @ "^blue^" ( d s . . . ) "-----------------------------------------------------" ( d s s . . ) strcat ansi_notify ( . . . . . ) me @ " " notify ( . . . . . ) me @ " ^green^Navigate ^yellow^ " ansi_notify ( . . . . . ) me @ " ^green^Navigate ^yellow^" ansi_notify ( . . . . . ) me @ " " notify ( . . . . . ) me @ " ^green^Navigate ^yellow^#break" ansi_notify ( . . . . . ) me @ " ^green^Navigate ^yellow^#resume" ansi_notify ( . . . . . ) me @ " " notify ( . . . . . ) me @ " ^green^Navigate ^yellow^#status" ansi_notify ( . . . . . ) me @ " " notify ( . . . . . ) me @ "^blue^" ( d s . . . ) "-----------------------------------------------------" ( d s s . . ) strcat ansi_notify ( . . . . . ) ; : Navigation.DestinationSetting ( x y z -- ) Fennek.Space.Init +Ship @ "@lite/Located/dZ" rot setpropval ( i i ) +Ship @ "@lite/Located/dY" rot setpropval ( i ) +Ship @ "@lite/Located/dX" rot setpropval ( ) ; : Navigation.CurrentSetting ( x y z -- ) Fennek.Space.Init +Ship @ "@lite/Located/cZ" rot setpropval ( i i ) +Ship @ "@lite/Located/cY" rot setpropval ( i ) +Ship @ "@lite/Located/cX" rot setpropval ( ) ; : Navigation.DestinationFetch ( -- x y z ) Fennek.Space.Init +Ship @ "@lite/Located/dX" getpropval ( i ) +Ship @ "@lite/Located/dY" getpropval ( i i ) +Ship @ "@lite/Located/dZ" getpropval ( i i i ) ; : Navigation.CurrentFetch ( -- x y z ) Fennek.Space.Init +Ship @ "@lite/Located/cX" getpropval ( i ) +Ship @ "@lite/Located/cY" getpropval ( i i ) +Ship @ "@lite/Located/cZ" getpropval ( i i i ) ; : Navigation.Variables.Init ( -- ) Fennek.Space.Init ( ) Navigation.CurrentFetch ( i i i ) +cZ ! ( i i ) +cY ! ( i ) +cX ! ( ) Navigation.DestinationFetch ( i i i ) +dZ ! ( i i ) +dY ! ( i ) +dX ! ( ) ; : Navigation.Movement.Permission ( -- b ) Fennek.Space.Init +Ship @ .fleet.Leader.Self? ( b ) dup not if ( b ) "Controls are linked to the fleet. Leave the " ( b s ) "fleet before you issue a new command." strcat ( b s ) .communication.oocAlert ( b ) exit ( b ) then pop ( ) +Ship @ .towboat.Towing.Me #-1 dbcmp ( b ) dup not if ( b ) "We are attached to another ship's towing cables.. " ( b s ) "independant movement is not an option." strcat ( b s ) .communication.oocAlert ( b ) exit ( b ) then pop ( ) +Ship @ "@lite/setup/usedmounts/engines_1" makeMID "Damage" getMIDint dup 5 > if dup 6 > if "This ship's engines have been destroyed. They're totalled." else "This ship's engines are too badly damaged to operate." then .communication.Shipcom.Self pop FALSE exit then pop (following section modified by Zobeid, 31 Jul 2002) +Ship @ location "@battle/" propdir? if ( . . . . . ) +Ship @ location "@battle/Ticker" getprop ispid? if "A battle is taking place in this sector. Please use " ( s . . . . ) "combat maneuvering to steer away from the battle." ( s s . . . ) strcat .communication.oocAlert ( . . . . . ) FALSE exit ( . . . . . ) else (battle is already over, clean up the sector) +Ship @ location sector-cleanup then then ( . . . . . ) ( . . . . . ) +Ship @ location location ( d ) "@lite/General/GridName" getpropstr ( s ) "" strcmp dup not if ( b ) "We need to be in space first." ( b s ) .communication.oocAlert exit ( ) then pop ( ) Navigation.Variables.Init ( ) +cX @ +dX @ < if ( ) +dX @ +cX @ - ( i ) else ( ) +cX @ +dX @ - ( i ) then 100 > ( b ) +cY @ +dY @ < if ( b ) +dY @ +cY @ - ( b i ) else ( b ) +cY @ +dY @ - ( b i ) then 100 > ( b b ) +cZ @ +dZ @ < if ( b b ) +dZ @ +cZ @ - ( b b i ) else ( b b ) +cZ @ +dZ @ - ( b b i ) then 100 > ( b b b ) or or if ( ) "This destination is too far from our current position. " ( s ) .communication.oocAlert ( ) "Maximum distance before recomputing becomes necessary is 100 sectors." .communication.oocAlert ( ) FALSE exit ( b ) then ( ) +cX @ +dX @ = ( b ) +cY @ +dY @ = ( b b ) +cZ @ +dZ @ = ( b b b ) and and if ( ) "That is our current location" ( s ) .communication.oocAlert ( ) FALSE exit ( b ) then ( ) TRUE ( b ) ; : Navigation.Permissions ( -- i ) Fennek.Space.Init "_navigation" .properties.CommandCheck ( b ) dup not if exit then pop ( ) me @ location ( d ) .construct.Vehicle.From.Shiproom swap +Ship ! ( b ) dup not if ( b ) "Part of your construct was lost or misplaced in the " ( b s ) "database. Contact the space staff for assistance." strcat ( b s ) .communication.oocAlert ( b ) exit ( b ) then pop ( ) +Ship @ "@lite/General/Construct" getprop +Construct ! ( ) 1 ( i ) ; : Navigation.NextDestination ( -- ) Fennek.Space.Init +cX @ +dX @ < if +cX @ 1 + +nX ! then ( ) +cX @ +dX @ > if +cX @ 1 - +nX ! then ( ) +cX @ +dX @ = if +cX @ +nX ! then ( ) +cY @ +dY @ < if +cY @ 1 + +nY ! then ( ) +cY @ +dY @ > if +cY @ 1 - +nY ! then ( ) +cY @ +dY @ = if +cY @ +nY ! then ( ) +cZ @ +dZ @ < if +cZ @ 1 + +nZ ! then ( ) +cZ @ +dZ @ > if +cZ @ 1 - +nZ ! then ( ) +cZ @ +dZ @ = if +cZ @ +nZ ! then ( ) ; : Navigation.ETA ( -- ) Fennek.Space.Init +dX @ +cX @ > if ( ) +dX @ +cX @ - else ( i ) +cX @ +dX @ - then ( i ) +dY @ +cY @ > if ( i ) +dY @ +cY @ - else ( i i ) +cY @ +dY @ - then ( i i ) +dZ @ +cZ @ > if ( i i ) +dZ @ +cZ @ - else ( i i i ) +cZ @ +dZ @ - then ( i i i ) over over > if pop else swap pop then ( i i ) over over > if pop else swap pop then ( i ) +Ship @ .speed.Effective.DelayTime * ( i ) dup 60 / swap over 60 * - ( i i ) swap intostr " minutes, " strcat ( i s ) swap intostr " seconds. " strcat strcat ( s ) "Estimated Time of Arrival: " swap strcat ( s ) .communication.Shipcom.Local ( ) ; : Navigation.Status ( -- ) Fennek.Space.Init ( ) Navigation.Permissions ( i ) not if exit then ( ) ( If the vessel is towed, the information is on the towing vessel object ) +Ship @ .towboat.Towing.Me dup ok? if ( d . . . . ) dup .validate.Liteobject if ( d . . . . ) +Ship ! ( . . . . . ) else ( d . . . . ) pop ( . . . . . ) then ( . . . . . ) else ( d . . . . ) pop ( . . . . . ) then ( . . . . . ) ( If the vessel is in formation, the information is on the leader ) +Ship @ .fleet.Leader dup +Ship @ dbcmp not if ( d . . . . ) dup .validate.Liteobject if ( d . . . . ) +Ship ! ( . . . . . ) else ( d . . . . ) pop ( . . . . . ) then ( . . . . . ) else ( d . . . . ) pop ( . . . . . ) then ( . . . . . ) Navigation.Variables.Init ( ) "Current location: " #-1 +cX @ +cY @ +cZ @ ( s d i i i ) .sector.Position.Name strcat ( s ) .communication.Shipcom.Local ( ) "Destination : " #-1 +dX @ +dY @ +dZ @ ( s d i i i ) .sector.Position.Name strcat ( s ) .communication.Shipcom.Local ( ) "Effective available motive force: " ( s ) 1000 +Ship @ .speed.Effective.DelayTime / ( s i ) intostr strcat ( s ) " DPT" strcat ( s ) .communication.Shipcom.Local ( ) +Ship @ "@lite/General/NavProcID" getpropval if ( . . . . . ) Navigation.ETA ( . . . . . ) else ( . . . . . ) "Currently not moving" .communication.Shipcom.Local ( . . . . . ) then ( . . . . . ) ; : Navigation.Enginedeath ( d -- b ) ( ship ) ( d . . . . ) ( Vessels being towed do not need to have working engines ) dup .towboat.Towing.Me ok? if ( d . . . . ) pop FALSE exit ( b . . . . ) then ( d . . . . ) ( Anyone else does though.. ) (following line changed by Zobeid -- sorry for messing up your neat formatting, Karinne! ;) dup "@lite/SetUp/UsedMounts/Engines_1/Damage" getpropval 5 > if ( d . . . . ) " drifts to a halt, with full engine failure.." ( d s . . . ) over swap .communication.Vpose ( d . . . . ) "Forced stop - the engines on " over name strcat ( d s . . . ) " have died completely" strcat ( d s . . . ) .communication.Shipcom.Fleet ( . . . . . ) TRUE exit ( b . . . . ) then ( d . . . . ) pop FALSE ( b . . . . ) ; : Navigation.Terminate? ( -- b ) Fennek.Space.Init +Ship @ "@lite/General/NavProcID" getpropval pid = not ( b ) ; : Navigation.Movement ( -- ) Fennek.Space.Init Navigation.Movement.Permission ( b ) not if ( ) exit ( ) then ( ) BACKGROUND +Ship @ "@lite/General/NavProcID" pid setpropval ( ) +Ship @ .fleet.List.Stack.Inclusive ( d..d ) begin dup ok? while ( d..d ) dup "@lite/Located/dX" +dX @ setpropval ( d..d ) dup "@lite/Located/dY" +dY @ setpropval ( d..d ) dup "@lite/Located/dZ" +dZ @ setpropval ( d..d ) .carrier.Reflist ( ddd d ddd ) begin ( ddd d ddd ) dup ok? while ( ddd d ddd ) dup "@lite/Located/dX" +dX @ setpropval ( ddd d ddd ) dup "@lite/Located/dY" +dY @ setpropval ( ddd d ddd ) "@lite/Located/dZ" +dZ @ setpropval ( ddd d ddd ) repeat ( ddd d ddd ) pop ( ddd . . . ) repeat ( d..d ) pop ( ) +Construct @ ( d ) "Plotting course. Engines are coming online.. " ( d s ) .communication.Shipcom.Fleet ( ) +Ship @ "_vprefs/EngineUp" getpropstr ( s . . . . ) dup "" strcmp not if pop "fires up its engines" then ( d . . . . ) +Ship @ swap .communication.Vpose ( . . . . . ) "New course has been plotted. Now en route to " ( s ) +Ship @ location location ( s d ) +dX @ +dY @ +dZ @ .sector.Position.Name strcat ( s ) .communication.Shipcom.Local ( ) +Construct @ ( d ) "We are now en route. Notice will be given on arrival." ( s ) .communication.Shipcom.Fleet ( ) Navigation.ETA ( ) begin ( ) +Ship @ .Speed.Effective.DelayTime sleep ( ) +Ship @ .fleet.List.Stack.Inclusive ( ddd . . . ) begin dup ok? while ( ddd . . . ) Navigation.Enginedeath ( ddd b . . ) if +Ship @ "@lite/General/NavProcID" remove_prop then ( ddd . . . ) repeat ( ddd . . . ) pop ( . . . . . ) +Ship @ .fleet.List.Stack.Inclusive ( ddd . . . ) begin dup ok? while ( ddd . . . ) .fuel.Usage ( ddd . . . ) repeat ( ddd . . . ) pop ( . . . . . ) +Ship @ .fleet.List.Stack.Inclusive ( ddd . . . ) begin dup ok? while ( ddd . . . ) dup .fuel.Can.Go not if ( ddd . . . ) +Ship @ "@lite/General/NavProcID" remove_prop ( ddd . . . ) +Ship @ "Forced stop - " rot name strcat ( ddd d s . ) " is out of fuel!" strcat ( ddd d s . ) .communication.Shipcom.Fleet ( ddd . . . ) else ( ddd . . . ) pop ( ddd . . . ) then ( ddd . . . ) repeat ( ddd . . . ) pop ( . . . . . ) +Ship @ location "@battle/" propdir? if ( . . . . . ) +Ship @ "@lite/General/NavProcID" remove_prop ( . . . . . ) +Ship @ "Navigation is obstructed by an ongoing battle " ( d s . . . ) "in this sector!" strcat ( d s . . . ) .communication.Shipcom.Construct ( . . . . . ) then ( . . . . . ) Navigation.Terminate? if ( ) "Previously plotted course to " +dX @ intostr strcat ( s ) " " strcat +dY @ intostr strcat ( s ) " " strcat +dZ @ intostr strcat ( s ) " has been aborted" strcat ( s ) .communication.Shipcom.Local ( ) exit ( ) then ( ) Navigation.NextDestination ( ) +nX @ +cX ! ( ) +nY @ +cY ! ( ) +nZ @ +cZ ! ( ) ( Begin Foxy Acceleration by Alynna ) var numsectors ( Increment number of sectors travelled since last stop ) +ship @ "_accel/numsectors" over over getprop 1 + dup numsectors ! setprop ( If we are acceleration capable ) +ship @ "_accel/drivehi" getprop if ( Check if we are to accellerate ) numsectors @ +ship @ "_accel/inertia" getprop % not if ( If so, increment our drive prop ) +ship @ "drive" over over getprop dup "_accel/drivehi" if 1 + setprop else ( or dont ) pop pop then then ( End Foxy Acceleration ) +Ship @ .fleet.List.Stack.Inclusive ( ddd . . . ) begin dup ok? while ( ddd . . . ) dup "@lite/Located/cX" +cX @ setpropval ( ddd . . . ) dup "@lite/Located/cY" +cY @ setpropval ( ddd . . . ) dup "@lite/Located/cZ" +cZ @ setpropval ( ddd . . . ) dup .carrier.Update ( ddd . . . ) dup .speed.Apply.Overstress.Damage ( ddd . . . ) pop ( ddd . . . ) repeat ( ddd . . . ) pop ( . . . . . ) +Ship @ +nX @ +nY @ +nZ @ MOTION call +cX @ +dX @ = ( b ) +cY @ +dY @ = ( b b ) +cZ @ +dZ @ = ( b b b ) and and until ( ) +Construct @ ( d ) "We have arrived at our destination" ( d s ) .communication.Shipcom.Fleet ( ) +Construct @ ( d ) "All engines full stop. Autopilot shutdown." ( d s ) .communication.Shipcom.Fleet ( ) +Ship @ "@lite/General/NavProcID" remove_prop ( ) ; : Navigation.Main ( s -- ) Fennek.Space.Init Navigation.Permissions not if exit then ( s ) dup "" strcmp over "#help" stringcmp and not if ( s ) pop ( ) Navigation.Help ( ) exit ( ) then ( s ) ( From here on, only continue if the ship is in the right place ) ( s . . . . ) +Ship @ .validate.Rightplace ( s b . . . ) not if exit then ( s . . . . ) ( s . . . . ) dup "#break" stringcmp not if ( s ) pop ( ) +Ship @ "@lite/General/NavProcID" getpropval not if ( ) "Do not bother with the flight interrupt, we are not " ( s ) "even moving.." strcat .communication.oocAlert ( ) exit ( ) then ( ) +Ship @ "@lite/General/NavProcID" 0 setpropval ( ) +Construct @ ( d ) "Flight interrupt engaged - immediate engine shutdown!" ( d s ) .communication.Shipcom.Construct ( ) +Construct @ ( d ) "Firing secondary engines to compensate.. ship halted." ( d s ) .communication.Shipcom.Construct ( ) exit ( ) then ( s ) dup "#resume" stringcmp not if ( s ) pop ( ) Navigation.Movement ( ) exit then ( s ) dup "#status" stringcmp not if ( s ) pop ( ) Navigation.Status ( ) exit ( ) then ( s ) +Ship @ over .bookmark.Exists if ( s . . . . ) +Ship @ swap .bookmark.Identify ( i i i . . ) Navigation.DestinationSetting ( . . . . . ) Navigation.Movement ( . . . . . ) exit ( . . . . . ) then ( s . . . . ) " " explode 3 = if ( s..s ) 3 pick number? ( s s s i ) 3 pick number? ( s s s i i ) 3 pick number? and and if ( s s s ) atoi ( s s i ) swap atoi ( s i i ) rot atoi ( i i i ) Navigation.DestinationSetting ( ) Navigation.Movement ( ) exit ( ) then ( ) then ( ) Navigation.Help ( ) ; PUBLIC Navigation.DestinationSetting PUBLIC Navigation.CurrentSetting PUBLIC Navigation.DestinationFetch PUBLIC Navigation.CurrentFetch PUBLIC Navigation.Status ;