]>
;'scrAddAction' adds an action to the right hand side of a dockscreen
; without having to overwrite the whole dockscreen.
;See TranscendentGeek's "Using scrAddAction..." forum topic in Modding
; Reference for a full explanation.
;The code below tells the game to add a "Point" action to the playership's
; ship status dockscreen, usually the "Ship's Interior" screen.
;The '4' value puts the action fifth in the list (0 is the first value,
; not 1).
;"Point" is the label or text that appears in the added action.
;"P" is the key which triggers the action and is highlighted in the action
; label.
(if (eq aScreenUNID (typGetProperty (objGetType gPlayerShip) 'shipStatusScreen))
(scrAddAction
gScreen
'addD789PointAction
4
"Point"
"P"
(block Nil
;We fire the event which starts the ship rotating.
;Note: we need to use the UNID here as we are in a screen when
; this code runs. 'gType' would be the screen type.
(typFireEvent &evD789ShipPointing; "StartCode")
;And 'undock' from the screen so we can watch the ship turn.
(scrExitScreen gScreen 'forceUndock)
)
);scrAddAction
);if
(block Nil
;We fire a timer event, "ShipDirection". This event determines which
; way the ship has to turn to point to the nearest cardinal point.
; We use timer events with delays so the ship doesn't instantly
; point in the desired direction. The code runs near instantly
; without these delays.
(sysAddTypeTimerEvent 2 gType "ShipDirection")
;After 100 ticks we cancel the event as by then the ship is pointing
; in the desired direction.
(sysAddTypeTimerEvent 200 gType "EndCode")
(printTo 'console "StartCode")
)
(sysCancelTypeTimerEvent gType "ShipDirection")
(block (nowAngle)
;Here marsrocks has sorted the direction the ship has to rotate into
; clockwise or anticlockwise.
;Cleverly, marsrocks has selected all the values of ship direction
; which require a clockwise move using the event "ShipClockMove"
; and left any other values to default to the anticlockwise or
; counterclockwise event "ShipCounterMove".
(setq nowAngle (objGetProperty gPlayerShip 'rotation))
(switch
(or (and (geq nowAngle 1) (leq nowAngle 45))
(and (geq nowAngle 91) (leq nowAngle 135))
(and (geq nowAngle 181) (leq nowAngle 225))
(and (geq nowAngle 271) (leq nowAngle 315))
)
(block Nil
(typAddTimerEvent gType 2 "ShipClockMove")
(printTo 'console "Firing ClockMove")
)
(block Nil
(typAddTimerEvent gType 2 "ShipCounterMove")
(printTo 'console "Firing CounterMove")
)
);switch
(printTo 'console "ShipDirection run")
);block
(block Nil
;We get the angle the ship is currently facing and save it as
; 'nowAngle'.
(setq nowAngle (objGetProperty gPlayerShip 'rotation))
;The value of 'wantAngle' is set to the desired finishing angle. This
; depends on which cardinal direction is nearest.
(switch
(and (geq nowAngle 45) (leq nowAngle 135))
(setq wantAngle 90)
(and (geq nowAngle 136) (leq nowAngle 225))
(setq wantAngle 180)
(and (geq nowAngle 226) (leq nowAngle 315))
(setq wantAngle 270)
;If none of the above we set 'wantAngle' to 0 (same as 360).
(setq wantAngle 0)
);switch
;Remember the desired angle for the "ShipFinalMove" event.
(typSetData gType 'wantAngle wantAngle)
;We subtract 'wantAngle' from 'nowAngle' to give a value of how many
; degrees are left to move until the desired direction is required.
; We call this 'closeAngle'. The 'abs' function converts this number
; to a positive number if it is negative.
(setq closeAngle (abs (subtract nowAngle wantAngle)))
;This is the best bit, nice work, marsrocks.
;If 'closeAngle' (how many degrees left to move) is greater than 10
; then the "interimAngle" code is run.
;This reduces the number of degrees by 5, rotates the playership and
; adds a delay of 1 tick.
;The code then starts again at the beginning of "ShipClockMove" to
; give a repeating function until 'closeAngle' is less than 10.
;Once this happens the code fires a timer event, "ShipFinalMove".
(if (gr closeAngle 10)
(block (interimAngle)
(setq interimAngle (subtract nowAngle 5))
(objSetProperty gPlayerShip 'rotation interimAngle)
(typAddTimerEvent gType 1 "ShipClockMove")
(printTo 'console "ClockMove run")
)
(typAddTimerEvent gType 1 "ShipFinalMove")
);if
);block
;This event is the same as "ShipClockMove" except that 5 degrees is added,
; instead of subtracted, to the "nowAngle" value. This turns the ship in
; the opposite direction.
(block (nowAngle wantAngle closeAngle interimAngle)
(setq nowAngle (objGetProperty gPlayerShip 'rotation))
(switch
(and (geq nowAngle 45) (leq nowAngle 135))
(setq wantAngle 90)
(and (geq nowAngle 136) (leq nowAngle 225))
(setq wantAngle 180)
(and (geq nowAngle 226) (leq nowAngle 315))
(setq wantAngle 270)
;If none of the above, default to 0.
(setq wantAngle 0)
);switch
;Remember the desired angle for the "ShipFinalMove" event.
(typSetData gType 'wantAngle wantAngle)
(setq closeAngle (abs (subtract nowAngle wantAngle)))
(if (gr closeAngle 10)
(block (interimAngle)
(setq interimAngle (add nowAngle 5))
(objSetProperty gPlayerShip 'rotation interimAngle)
(typAddTimerEvent gType 1 "ShipCounterMove")
)
(typAddTimerEvent gType 1 "ShipFinalMove")
);if
);block
(block Nil
;This event runs after the ship is pointing within 10 degrees of the
; desired cardinal direction.
;It points the ship in the final desired direction by setting the
; playership's rotation value to 'wantAngle' and clears 'typData
; 'wantAngle'.
(printTo 'console "FinalMove run")
(objSetProperty gPlayerShip 'rotation (typGetData gType 'wantAngle))
(typSetData gType 'wantAngle Nil)
)