Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: 0rph3u5 on October 10, 2019, 06:22:20 am

Title: Docking Loop
Post by: 0rph3u5 on October 10, 2019, 06:22:20 am
Okay, for a little background traffic around Tombaugh Station in the upgraded Rain on Ribos IV, I've been trying to make some transports perform "task loop" around station (e.g. a ferry service from docking plattfrom to a Faustus and back).
And I ran into a problem with the transports getting stuck as they seemingly get spammed with the order for a a step...

EDIT: old broken events removed, new broken ones below

I have the destinct feeling that I've been overthinking this... so, I would grateful for any help...
Title: Re: Docking Loop
Post by: wookieejedi on October 10, 2019, 06:42:27 am
Make sure to clear goals, too. That might be why it gets stuck...
Title: Re: Docking Loop
Post by: Nightmare on October 10, 2019, 07:04:47 am
Make sure to clear goals, too. That might be why it gets stuck...

Not just that, it can cause some really weird behavior while docking (moving ships around that have "no movement" flags etc).
Title: Re: Docking Loop
Post by: 0rph3u5 on October 10, 2019, 11:14:26 am
Make sure to clear goals, too. That might be why it gets stuck...

Added it in. No change. (OP updated)

I actually thought I didn't need to add a clear-goals because each step was depending on the completion of the previous one.

it can cause some really weird behavior while docking (moving ships around that have "no movement" flags etc).

Getting hit with an Arcadia is one of the more hillarious side effects of this not working.
Title: Re: Docking Loop
Post by: General Battuta on October 10, 2019, 12:55:43 pm
Without thinking about this at all (therefore I’m probably wrong) I’m gonna guess the problem is has-docked-delay. Those will never stop being true once they’ve become true; they’re not going to reset to ‘oh this hasn’t happened before’ each time the event triggers. Once the docking happens and the delay passes, that switch is jammed on forever.

So you’ve got a series of events that will just constantly cycle the value of the variable without actually waiting for a ship to dock and undock.
Title: Re: Docking Loop
Post by: 0rph3u5 on October 10, 2019, 01:39:06 pm
Without thinking about this at all (therefore I’m probably wrong) I’m gonna guess the problem is has-docked-delay. Those will never stop being true once they’ve become true; they’re not going to reset to ‘oh this hasn’t happened before’ each time the event triggers. Once the docking happens and the delay passes, that switch is jammed on forever.

So you’ve got a series of events that will just constantly cycle the value of the variable without actually waiting for a ship to dock and undock.

You are on to something ... appearently once it Psi 6 undocks from the Galen the "stage" variable locks and the other two count up

But doesn't explain why the other two transports (which run on basically the same event but with different targets) don't complete a full loop

[attachment eaten by a Shivan]
Title: Re: Docking Loop
Post by: 0rph3u5 on October 10, 2019, 02:17:35 pm
Okay the other two transports locking up has something to do with their random traget selection being broken (they ferry between the Arcadia and 4 containers each) - disregard that



so has-docked-delay or has-undocked-delay seem to be the point of failure ... I had hoped using the a variable for the number of times docked (argument 3, see below) would do the trick...

Quote
Has docked delay (Boolean operator)
   Becomes true <delay> seconds after the specified ships have docked the specified number of times.

Returns a boolean value.  Takes 4 arguments...
   1:   The name of the docker ship
   2:   The name of the dockee ship
   3:   The number of times they have to have docked
   4:   Time delay in seconds (see above).

Quote
Has undocked delay (Boolean operator)
   Becomes true <delay> seconds after the specified ships have undocked the specified number of times.

Returns a boolean value.  Takes 4 arguments...
   1:   The name of the docker ship
   2:   The name of the dockee ship
   3:   The number of times they have to have undocked
   4:   Time delay in seconds (see above).
Title: Re: Docking Loop
Post by: General Battuta on October 10, 2019, 03:21:29 pm
Oh, interesting. I like what you're trying to do there, it seems like it should work. My suspicion is that once the has-docked SEXP has become true it's not re-evaluating even once you change that 'how many times has the docking happened' variable; it says 'yeah I'm true!' and stays there forever, despite the event having a trigger count. But it's just a guess. I don't know if that's actually the problem.
Title: Re: Docking Loop
Post by: wookieejedi on October 10, 2019, 04:22:47 pm
That's a good point. In that case setting when to when-every-time might be a way to test that?

Reason why is documented here: http://www.hard-light.net/forums/index.php?topic=74909.msg1480994#new

TLDR: "This is when you need every-time. Every-time ignores all the SEXP_KNOWN_TRUE/FALSE stuff and just resets the entire event to unknown after every time it runs. That's why you can't use is-event-true with it. The above SEXP would work with every-time." --karajorma
Title: Re: Docking Loop
Post by: General Battuta on October 10, 2019, 04:47:38 pm
Oh, neat!
Title: Re: Docking Loop
Post by: 0rph3u5 on October 10, 2019, 08:54:31 pm
I had another idea - switching to is-docked and is-cargo and satifying the "x has docked for y seconds" using a counter

... But its 4 in the morning and the implimentation of that will have to wait
Title: Re: Docking Loop
Post by: 0rph3u5 on October 11, 2019, 04:54:19 am
Alright skimmed some time off to do the new version:

EDIT: cut because broken

Still order spam - after the first undock for the traget ship - but...

... I got one derivate of this whole affair working now:

Code: [Select]
$Formula: ( when
   ( and
      ( has-time-elapsed ( rand 10 20 ) )
      ( is-docked "Tombaugh" "Iota 3" )
   )
   ( add-goal "Iota 3" ( ai-undock 89 ) )
   ( modify-variable @Iota-stage[0] 1 )
)
+Name: iota start
+Repeat Count: 1
+Interval: 1
+Event Log Flags: ( "true" "false" )

$Formula: ( when
   ( and
      ( not
         ( is-docked "Tombaugh" "Iota 3" )
      )
      ( = @Iota-stage[0] 1 )
      ( is-event-true-delay "iota start" 0 )
   )
   ( modify-variable @Iota-stage[0] 2 )
   ( clear-goals "Iota 3" )
   ( add-goal
      "Iota 3"
      ( ai-waypoints-once
         "Wishbone patrol"
         89
      )
   )
)
+Name: iota go wp
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1
+Event Log Flags: ( "true" "false" "first repeat" "first trigger" )

$Formula: ( when
   ( and
      ( not
         ( is-in-box
            "Iota 3"
            400
            1600
            -100
            100
            -1500
            -500
         )
      )
      ( = @Iota-stage[0] 2 )
      ( is-event-true-delay "iota start" 0 )
   )
   ( modify-variable @Iota-stage[0] 3 )
   ( clear-goals "Iota 3" )
   ( add-goal
      "Iota 3"
      ( ai-dock
         "Tombaugh"
         "topside docking"
         "Wishbone 1b"
         89
      )
   )
)
+Name: iota dock again
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1
+Event Log Flags: ( "true" "false" "first repeat" "first trigger" )

$Formula: ( when
   ( and
      ( is-docked "Tombaugh" "Iota 3" )
      ( = @Iota-stage[0] 3 )
      ( is-event-true-delay "iota start" 0 )
   )
   ( when
      ( < @Iota-docked-time[0] 30 )
      ( modify-variable
         @Iota-docked-time[0]
         ( + @Iota-docked-time[0] 1 )
      )
   )
   ( when
      ( >= @Iota-docked-time[0] 30 )
      ( modify-variable
         @Iota-Cycle[1]
         ( + @Iota-Cycle[1] 1 )
      )
      ( modify-variable @Iota-stage[0] 1 )
      ( clear-goals "Iota 3" )
      ( add-goal "Iota 3" ( ai-undock 89 ) )
      ( modify-variable
         @Iota-docked-time[0]
         0
      )
   )
)
+Name: iota undock again
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1
+Event Log Flags: ( "true" "false" )
ps. is-in-box replaced a are-waypoint-done-delay

No more wildly spinning Arcadia :) so I guess this is the right track
Title: Re: Docking Loop
Post by: 0rph3u5 on October 13, 2019, 11:30:28 am
Finally managed to root out the problem ... and it is slightly embarassing:

The docking cycle looped 2 -> 3 -> 4 -> 2 instead of 1 -> 2 -> 3 -> 4 -> 1 (except for the 3 points loop which was poperly set-up, so the whole problem with has-docked-delay/has-undocked-delay is still valid)

So, here is the fixed version for all archetypes on this (NOTE: testing pending on the Phi 2-sequence, but that's c&p'ed from Psi 6):

Psi 6 - ferry between Station and Ship

Code: [Select]
$Formula: ( when
   ( and
      ( has-time-elapsed
         ( rand-multiple 20 40 )
      )
      ( is-docked "Tombaugh" "Psi 6" )
   )
   ( add-goal "Psi 6" ( ai-undock 89 ) )
   ( modify-variable @Psi-Stage[0] 2 )
)
+Name: start psi docking cylce
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( and
      ( is-docked "Tombaugh" "Psi 6" )
      ( = @Psi-Stage[0] 1 )
      ( is-event-true-delay
         "start psi docking cylce"
         0
      )
   )
   ( when
      ( < @Psi-docked-time[0] 30 )
      ( modify-variable
         @Psi-docked-time[0]
         ( + @Psi-docked-time[0] 1 )
      )
   )
   ( when
      ( >= @Psi-docked-time[0] 30 )
      ( clear-goals "Psi 6" )
      ( add-goal "Psi 6" ( ai-undock 89 ) )
      ( modify-variable @Psi-Stage[0] 2 )
      ( modify-variable
         @Psi-docked-time[0]
         0
      )
   )
)
+Name: psi outbound undock
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1

$Formula: ( when
   ( and
      ( not
         ( is-docked "Tombaugh" "Psi 6" )
      )
      ( = @Psi-Stage[0] 2 )
      ( is-event-true-delay
         "start psi docking cylce"
         0
      )
   )
   ( clear-goals "Psi 6" )
   ( add-goal
      "Psi 6"
      ( ai-dock
         "Galen"
         "topside docking"
         "starboard docking"
         89
      )
   )
   ( modify-variable @Psi-Stage[0] 3 )
   ( modify-variable
      @Psi-outbound[1]
      ( + @Psi-outbound[1] 1 )
   )
)
+Name: psi outbound dock
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1

$Formula: ( when
   ( and
      ( is-docked "Galen" "Psi 6" )
      ( = @Psi-Stage[0] 3 )
      ( is-event-true-delay
         "start psi docking cylce"
         0
      )
   )
   ( when
      ( < @Psi-docked-time[0] 30 )
      ( modify-variable
         @Psi-docked-time[0]
         ( + @Psi-docked-time[0] 1 )
      )
   )
   ( when
      ( >= @Psi-docked-time[0] 30 )
      ( modify-variable @Psi-Stage[0] 4 )
      ( clear-goals "Psi 6" )
      ( add-goal "Psi 6" ( ai-undock 89 ) )
      ( modify-variable
         @Psi-docked-time[0]
         0
      )
   )
)
+Name: psi inbound undock
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1
+Event Log Flags: ( "true" "false" )

$Formula: ( when
   ( and
      ( not ( is-docked "Galen" "Psi 6" ) )
      ( = @Psi-Stage[0] 4 )
      ( is-event-true-delay
         "start psi docking cylce"
         0
      )
   )
   ( modify-variable @Psi-Stage[0] 1 )
   ( modify-variable
      @Psi-inbound[1]
      ( + @Psi-inbound[1] 1 )
   )
   ( clear-goals "Psi 6" )
   ( add-goal
      "Psi 6"
      ( ai-dock
         "Tombaugh"
         "topside docking"
         "Platform 4a"
         89
      )
   )
)
+Name: psi inbound dock
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1
+Event Log Flags: ( "true" "false" )

$Formula: ( when
   ( and
      ( is-docked "Tombaugh" "Psi 6" )
      ( >= @Psi-docked-time[0] 25 )
   )
   ( transfer-cargo "Psi 6" "Tombaugh" )
)
+Name: psi cargo transfer station
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 2
+Event Log Flags: ( "true" "false" )

$Formula: ( when
   ( and
      ( is-docked "Galen" "Psi 6" )
      ( >= @Psi-docked-time[0] 25 )
   )
   ( transfer-cargo "Galen" "Psi 6" )
)
+Name: psi cargo transfer medical
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 2

Iota 3 - dock, partrol-loop
Code: [Select]
$Formula: ( when
   ( and
      ( has-time-elapsed ( rand 10 20 ) )
      ( is-docked "Tombaugh" "Iota 3" )
   )
   ( add-goal "Iota 3" ( ai-undock 89 ) )
   ( modify-variable @Iota-stage[0] 1 )
)
+Name: iota start
+Repeat Count: 1
+Interval: 1
+Event Log Flags: ( "true" "false" )

$Formula: ( when
   ( and
      ( not
         ( is-docked "Tombaugh" "Iota 3" )
      )
      ( = @Iota-stage[0] 1 )
      ( is-event-true-delay "iota start" 0 )
   )
   ( modify-variable @Iota-stage[0] 2 )
   ( clear-goals "Iota 3" )
   ( add-goal
      "Iota 3"
      ( ai-waypoints-once
         "Wishbone patrol"
         89
      )
   )
)
+Name: iota go wp
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1
+Event Log Flags: ( "true" "false" "first repeat" "first trigger" )

$Formula: ( when
   ( and
      ( not
         ( is-in-box
            "Iota 3"
            400
            1600
            -100
            100
            -1500
            -500
         )
      )
      ( = @Iota-stage[0] 2 )
      ( is-event-true-delay "iota start" 0 )
   )
   ( modify-variable @Iota-stage[0] 3 )
   ( clear-goals "Iota 3" )
   ( add-goal
      "Iota 3"
      ( ai-dock
         "Tombaugh"
         "topside docking"
         "Wishbone 1b"
         89
      )
   )
)
+Name: iota dock again
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1
+Event Log Flags: ( "true" "false" "first repeat" "first trigger" )

$Formula: ( when
   ( and
      ( is-docked "Tombaugh" "Iota 3" )
      ( = @Iota-stage[0] 3 )
      ( is-event-true-delay "iota start" 0 )
   )
   ( when
      ( < @Iota-docked-time[0] 30 )
      ( modify-variable
         @Iota-docked-time[0]
         ( + @Iota-docked-time[0] 1 )
      )
   )
   ( when
      ( >= @Iota-docked-time[0] 30 )
      ( modify-variable
         @Iota-Cycle[1]
         ( + @Iota-Cycle[1] 1 )
      )
      ( modify-variable @Iota-stage[0] 1 )
      ( clear-goals "Iota 3" )
      ( add-goal "Iota 3" ( ai-undock 89 ) )
      ( modify-variable
         @Iota-docked-time[0]
         0
      )
   )
)
+Name: iota undock again
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 1
+Event Log Flags: ( "true" "false" )

Phi 2 - ferry between Station and random Container from a set of 4
Code: [Select]
$Formula: ( when
   ( and
      ( has-time-elapsed
         ( rand-multiple 15 45 )
      )
      ( is-docked "Tombaugh" "Phi 2" )
   )
   ( add-goal "Phi 2" ( ai-undock 89 ) )
   ( modify-variable @Phi2-Stage[0] 2 )
   ( when-argument
      ( random-of
         "Phi 2 Cargo 1"
         "Phi 2 Cargo 2"
         "Phi 2 Cargo 3"
         "Phi 2 Cargo 4"
      )
      ( true )
      ( modify-variable
         "@Phi2-target[Phi 2 Cargo 1]"
         "<argument>"
      )
   )
)
+Name: start phi 2
+Repeat Count: 1
+Interval: 1
+Event Log Flags: ( "true" "false" "first repeat" "first trigger" )

$Formula: ( when-argument
   ( any-of
      "Phi 2 Cargo 1"
      "Phi 2 Cargo 2"
      "Phi 2 Cargo 3"
      "Phi 2 Cargo 4"
   )
   ( and
      ( is-docked "Tombaugh" "Phi 2" )
      ( = @Phi2-Stage[0] 1 )
      ( is-event-true-delay "start phi 2" 0 )
   )
   ( when
      ( < @Phi2-docked-time[0] 20 )
      ( modify-variable
         @Phi2-docked-time[0]
         ( + @Phi2-docked-time[0] 1 )
      )
   )
   ( when
      ( >= @Phi2-docked-time[0] 20 )
      ( clear-goals "Phi 2" )
      ( add-goal "Phi 2" ( ai-undock 89 ) )
      ( modify-variable @Phi2-Stage[0] 2 )
      ( modify-variable
         @Phi2-docked-time[0]
         0
      )
   )
)
+Name: phi 2 outbound undock
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 2

$Formula: ( when-argument
   ( any-of
      "Phi 2 Cargo 1"
      "Phi 2 Cargo 2"
      "Phi 2 Cargo 3"
      "Phi 2 Cargo 4"
   )
   ( and
      ( not
         ( is-docked "<argument>" "Phi 2" )
      )
      ( = @Phi2-Stage[0] 2 )
      ( is-event-true-delay "start phi 2" 0 )
   )
   ( modify-variable @Phi2-Stage[0] 3 )
   ( modify-variable
      @Phi2-Cycle-Out[1]
      ( + @Phi2-Cycle-Out[1] 1 )
   )
   ( clear-goals "Phi 2" )
   ( add-goal
      "Phi 2"
      ( ai-dock
         "@Phi2-target[Phi 2 Cargo 1]"
         "topside docking"
         "@TTC1-dock[cargo dock01]"
         89
      )
   )
)
+Name: phi 2 outbound dock
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 2

$Formula: ( when-argument
   ( any-of
      "Phi 2 Cargo 1"
      "Phi 2 Cargo 2"
      "Phi 2 Cargo 3"
      "Phi 2 Cargo 4"
   )
   ( and
      ( is-docked "<argument>" "Phi 2" )
      ( = @Phi2-Stage[0] 3 )
      ( is-event-true-delay "start phi 2" 0 )
   )
   ( when
      ( < @Phi2-docked-time[0] 20 )
      ( modify-variable
         @Phi2-docked-time[0]
         ( + @Phi2-docked-time[0] 1 )
      )
   )
   ( when
      ( >= @Phi2-docked-time[0] 20 )
      ( modify-variable @Phi2-Stage[0] 4 )
      ( clear-goals "Phi 2" )
      ( add-goal "Phi 2" ( ai-undock 89 ) )
      ( modify-variable
         @Phi2-docked-time[0]
         0
      )
   )
)
+Name: phi 2 inbound undock
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 2

$Formula: ( when-argument
   ( any-of
      "Phi 2 Cargo 1"
      "Phi 2 Cargo 2"
      "Phi 2 Cargo 3"
      "Phi 2 Cargo 4"
   )
   ( and
      ( not
         ( is-docked "<argument>" "Phi 2" )
      )
      ( = @Phi2-Stage[0] 4 )
      ( is-event-true-delay "start phi 2" 0 )
   )
   ( modify-variable @Phi2-Stage[0] 1 )
   ( modify-variable
      @Phi2-Cycle-In[1]
      ( + @Phi2-Cycle-In[1] 1 )
   )
   ( clear-goals "Phi 2" )
   ( add-goal
      "Phi 2"
      ( ai-dock
         "Tombaugh"
         "topside docking"
         "Platform 3e"
         89
      )
   )
)
+Name: phi 2 inbound dock
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 2

$Formula: ( when
   ( and
      ( is-docked "Tombaugh" "Phi 2" )
      ( > @Phi2-docked-time[0] 17 )
      ( is-event-true-delay "start phi 2" 0 )
   )
   ( transfer-cargo "Phi 2" "Tombaugh" )
)
+Name: phi 2 transfer station
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 2

$Formula: ( when-argument
   ( any-of
      "Phi 2 Cargo 1"
      "Phi 2 Cargo 2"
      "Phi 2 Cargo 3"
      "Phi 2 Cargo 4"
   )
   ( and
      ( is-docked "<argument>" "Phi 2" )
      ( > @Phi2-docked-time[0] 17 )
      ( is-event-true-delay "start phi 2" 0 )
   )
   ( transfer-cargo "<argument>" "Phi 2" )
)
+Name: phi 2 transfer container
+Repeat Count: -1
+Trigger Count: 99999999
+Interval: 2



CASE CLOSED
Title: Re: Docking Loop
Post by: Goober5000 on October 13, 2019, 10:20:37 pm
:yes: