This mod rotates the ship automatically to the nearest cardinal point to help with lining up long range weapons fire. It is initiated by an added action in the Ship's Interior screen.
Pretty much everything I know about events is due to marsrocks' help with this mod, so thanks again, marsrocks.
1. The mod uses 'sysAddTypeTimerEvent' to fire a "ShipDirection" event. There is code which cancels this event after 200 ticks but I have a feeling this isn't needed.
Do type timer events need to be canceled or only recurring type timer events?
The event canceling code:
Code: Select all
<StartCode>
(block Nil
;We start a timer event, "ShipDirection", which determine which way
; the ship has to turn.
(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")
)
</StartCode>
<EndCode>
(sysCancelTypeTimerEvent gType "ShipDirection")
</EndCode>
The mod sets the playership's rotation angle continually 5 degrees closer to the closest cardinal point angle. If the playership is facing more than 10 degrees away from the desired angle it refires the 'angle resetting' event "ShipCounterMove". Over and over until the ship faces in the desired direction.
In 1.9a1 there is only one resetting of the playership angle. After that the event does not fire again for some reason. I originally tried using 'sysAddTypeTimerEvent' in the resetting event and now use 'typAddTimerEvent'. Neither will fire again if additional resetting is required although an initial reset always occurs.
Anyone got any clues about why the event won't fire again?
The counter-clockwise resetting event:
Code: Select all
<ShipCounterMove>
;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
</ShipCounterMove>