Author Topic: Player Warp to Target?  (Read 6431 times)

0 Members and 2 Guests are viewing this topic.

Player Warp to Target?
I'm currently designing a short campaign, probably only five or so missions long, where the player plays as a Shivan. Since Shivans are really into subspace and all, it seems like Shivans would regard their subspace drives as nothing more exotic than a second afterburner, so tactical subspace jumps would be really common.

I read through the tutorial ( http://www.hard-light.net/wiki/index.php/Tutorial_-_In-Mission_Jumps ), and it covers how to make the subspace entrance window location relative to the player, but is it possible to make the subspace EXIT location relative to the player too?

Here's what I have in mind. I am curious if it is practical to do this as a core mechanic across all the missions in the campaign:

- Determine if there is anything 'in front of' the player (like a 10 degree cone or whatever)
- If so, get the distance to the object, subtract 2500 meters, and warp forward by that amount
- If not, warp 5000 meters forward.

The idea is, this can be used either as a rapid escape mechanism, or a way to very quickly close large distances with distant targets, without accidentally warping the player inside of a ship.

Normally when you press Alt-J to warp, and you are at full throttle, your ship slows down a lot. Is it possible to reconfigure this behavior so the ship instead speeds up a lot, like a capital ship does?

EDIT:

I'm not sure how to modify the 'is-facing' option to work like this. Is there an easier way to check if something is in the way/presents a collision hazard?

Preventing the player from warping inside of things is the real issue.

ANOTHER EDIT:

Proof-of-concept is working, it just needs refining so it's not just an emergency escape button, but also useful for subspace-jumping and attacking things like the Shivans do.
« Last Edit: April 16, 2016, 01:45:11 am by Erebus Alpha »
"Obviously the meson bomb is a form of cat-toast-device, with the buttered toast inverted, so that the cat and toast both fly in the direction of gravity much faster than expected. By introducing artificial gravity, a pair of cat-toast perpetual motion accelerator units can be made to collide with one another, and they produce an unimaginably devastating explosion. Both cats are named 'Meson'."

 - Wikileaks 2383

 

Offline wardog300k

  • 28
  • I'm a FREDder
Crush the NTF-Conflict Zone
One last war, one last hope, one last survival-Final Destination On Delay
Set free from the GTVA-Liberation Wars On Delay

 

Offline procdrone

  • Formerly TheHound
  • 29
  • Balance breaker! Thats me!
    • Steam
Re: Player Warp to Target?
Use this for the speed of ships entering subspace.

Wardog, this is not correct, since he wants to fake subspace entrance, not literally leave the mission. Warp in&out will not work here. Lat ship lat manoeuvre set to like 200%(%) or 250(%) should do it I believe ... ?
--Did it! It's RELEASED! VeniceMirror Thread--

 

Offline wardog300k

  • 28
  • I'm a FREDder
Re: Player Warp to Target?
But it can work for AI, if you just make a new ship where you need it and use variables to set its hull&stuff.
Crush the NTF-Conflict Zone
One last war, one last hope, one last survival-Final Destination On Delay
Set free from the GTVA-Liberation Wars On Delay

 

Offline procdrone

  • Formerly TheHound
  • 29
  • Balance breaker! Thats me!
    • Steam
Re: Player Warp to Target?
well that might be working but it is a pain, if you have control of the wing (they will appear as departed on your wingbar status even if you spawn new and rename them accordingly, secondly, you'd have to check if they are alive, copy their damage, etc..)
--Did it! It's RELEASED! VeniceMirror Thread--

 
Re: Player Warp to Target?
Ok, as a proof of concept, I've successfully jumped my ship 7500 meters forward from its current position.

However...this only seems to work once. The maneuver cannot be repeated.

I created another chained event, "Warp Recharge", at the end of the event sequence, which triggers 30 seconds after the warp is finished. It's a simple when-true-key-reset SEXP. Neither key-reset nor key-reset-multiple will let me warp a second time when I press Alt-J.
"Obviously the meson bomb is a form of cat-toast-device, with the buttered toast inverted, so that the cat and toast both fly in the direction of gravity much faster than expected. By introducing artificial gravity, a pair of cat-toast perpetual motion accelerator units can be made to collide with one another, and they produce an unimaginably devastating explosion. Both cats are named 'Meson'."

 - Wikileaks 2383

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Player Warp to Target?
Try changing from when to every-time in the key-pressed event. This is actually one of the few times when the use of every-time rather than a repeating when is justified.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Player Warp to Target?
If memory serves, chained events behave in potentially-counter-intuitive fashion when you're trying to make an entire chain be trigger-able multiple times. You may want to check out the $Use Alternate Chaining Behavior: setting (although I'm not 100% clear on what behavior that will result in); alternatively, stop using chained events and instead use variables to trigger the events in sequence without chaining.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Player Warp to Target?
Don't use chained events when you want any of the events to repeat. Use a variable.

 
Re: Player Warp to Target?
Without event chaining, how do I insert a delay between two variable-dependent events, like the Warm Up event and the Show Warp event? I don't see a modify-variable-after-delay SEXP.

This is perhaps most important for managing the subspace drive recharge.
"Obviously the meson bomb is a form of cat-toast-device, with the buttered toast inverted, so that the cat and toast both fly in the direction of gravity much faster than expected. By introducing artificial gravity, a pair of cat-toast perpetual motion accelerator units can be made to collide with one another, and they produce an unimaginably devastating explosion. Both cats are named 'Meson'."

 - Wikileaks 2383

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Player Warp to Target?
It's going to get hacky: you need to set up timer variables that increase by one every second when conditions are right, then reset once they've met the trigger.

Somebody post an example I am AFK! (Just trust me, as intimidating as it seems now, it ends up being way easier and more elegant)

Maybe post the tactical ability menus from The Blade Itself

 
Re: Player Warp to Target?
If I understand you correctly, I've done the same thing with Arduinos and programming to count milliseconds, using subtraction to compare elapsed time to a variable, and then setting that variable equal to elapsed time to reset the timer. :pimp:

Do the SEXP's require anything special to 'reset' them? Or are SEXP's smart enough to say "Whoops, that's not true anymore!" when the variable changes and 150 is no longer less than 155? Or should I be using 'every-time' instead of 'when'?

...Unless I'm misunderstanding horribly. That's always a likely possibility too.
« Last Edit: April 15, 2016, 05:59:48 pm by Erebus Alpha »
"Obviously the meson bomb is a form of cat-toast-device, with the buttered toast inverted, so that the cat and toast both fly in the direction of gravity much faster than expected. By introducing artificial gravity, a pair of cat-toast perpetual motion accelerator units can be made to collide with one another, and they produce an unimaginably devastating explosion. Both cats are named 'Meson'."

 - Wikileaks 2383

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Player Warp to Target?
It's hard to know what to do exactly without seeing the events you have. But hopefully this should be enough to steer you in the right direction.


If you simply want a 30 second recharge on your warp drive and no other factors to change it, here's how I would do it.

Warp arrival                                  <--------------- This is whatever event you have trigger when the ship arrives out of a micro warp
- when
-- Your stuff here
- Modify-variable
-- LastWarpTime (999999999999)
-- Mission-time

Warp Drive Recharged (High / Infinite repeat count, 1 second interval)
when
- >=
-- mission-time
-- +
--- LastWarpTime (999999999999)
--- 30
- Modify-variable 
-- WarpDriveCharged (1)
-- 1   
- Modify-variable                                    <----------------------------------------------- Optional, but it prevents this event from triggering every second once the warp drive is charged
-- LastWarpTime (999999999999)
-- 999999999999


Do Micro Jump
-when
-- key-pressed
--- Alt + J
-- key-reset-multiple
--- Alt + J
- Modify-variable 
-- WarpDriveCharged (1)
-- 0
- All the stuff for the actual micro jump goes here.


   
I've set the variables up so that they allow you to warp immediately upon mission start. If you wanted the player to only be able to warp after 2 minutes, just set LastWarpTime to -90 and WarpDriveCharged to 0.

If that isn't enough help, post what you actually have so far and we'll figure out what you need to do.


Quote
Do the SEXP's require anything special to 'reset' them? Or are SEXP's smart enough to say "Whoops, that's not true anymore!" when the variable changes and 150 is no longer less than 155? Or should I be using 'every-time' instead of 'when'?

The vast majority of SEXPs are smart enough to do that. But there are a few edge cases where they evaluate to SEXP_KNOWN_FALSE or SEXP_KNOWN_TRUE and then are never evaluated again (for instance, testing the distance to a ship that has been destroyed doesn't work if you then respawn it somehow because the game first tests if the ship has been destroyed). In these rare cases you may need to use every-time. You should be able to get by in this case without it. I suspect the problem is the chaining not the use of when so you can ignore my earlier post.
« Last Edit: April 15, 2016, 09:34:19 pm by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
Re: Player Warp to Target?
Thank you, it works perfectly!

Well, mostly perfectly. I need to refine the size and position of the subspace window, and the timing of the sounds a bit, but that stuff is fairly easy to do. I'm reasonably pleased, considering it's the first SEXP I've touched in over a decade.

One other interesting note to anyone else trying to do this: All of your subspace jump events need to have a fairly high repeat count, not just the one that sets the warp-drive-charged variable back to 1 (warpable).

Now onto something a little more exotic:

- Is there a way to use SEXP's to set a variable equal to the name of the player's current target?
- Is there also a way for SEXP's to derive the distance between the player and that target?

I already found the SEXP for checking if a ship is facing another ship. The next logical iteration of the tactical subspace jump is an attack mode, where the player selects an otherwise distant target and warps into attack position, in the time-honored Shivan tradition of blowing things up.

I'm already using variables and calculating the destination coordinates of the warp relative to the player's position instead of relative to a fixed point in space. So if I am able to derive distance-from-target using SEXP's, and subtract 3000 meters or so, and do a true/false check on whether or not the player is facing the target, it should be a fairly simple matter of target, point, jump, and open fire! :drevil:

EDIT:
Also, some bells and whistles, like 'Subspace Drive Recharging' on the HUD would also be a nice touch. I know they did custom HUD elements in Blue Planet - so it's more or less a question of how hard it would be to add. Is it something that is reasonably straightforward?
« Last Edit: April 16, 2016, 01:41:43 am by Erebus Alpha »
"Obviously the meson bomb is a form of cat-toast-device, with the buttered toast inverted, so that the cat and toast both fly in the direction of gravity much faster than expected. By introducing artificial gravity, a pair of cat-toast perpetual motion accelerator units can be made to collide with one another, and they produce an unimaginably devastating explosion. Both cats are named 'Meson'."

 - Wikileaks 2383

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Player Warp to Target?
Now onto something a little more exotic:

- Is there a way to use SEXP's to set a variable equal to the name of the player's current target?
- Is there also a way for SEXP's to derive the distance between the player and that target?

You can't get SEXPs to output a string at the moment but you can fake this behaviour using the argument SEXPs.

when-argument
-any-of
-- list all the hostile ships here
- and
-- Put the trigger you want here
- targeted
-- <argument>
- modify-variable
-- TargetedShip[]
-- <argument>

That should do what you want. The distance between ships can easily be found using the distance SEXP and the TargetedShip variable.

Quote
EDIT:
Also, some bells and whistles, like 'Subspace Drive Recharging' on the HUD would also be a nice touch. I know they did custom HUD elements in Blue Planet - so it's more or less a question of how hard it would be to add. Is it something that is reasonably straightforward?

It's pretty easy to do this with lua from what I understand. You'll have to ask a scripter how to do it though, my expertise is limited to SEXPs.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Player Warp to Target?
Do Micro Jump
-when
-- key-pressed
--- Alt + J
-- key-reset-multiple
--- Alt + J
- Modify-variable 
-- WarpDriveCharged (1)
-- 0
- All the stuff for the actual micro jump goes here.
If you do the key-reset-multiple in the jump event, then pressing Alt+J during the recharge period will cause it to automatically jump as soon as it's recharged.

Also, you've forgotten to actually check that WarpDriveCharged is 1 before jumping.

BP's Her Finest Hour uses this somewhat-silly little event to avoid the first problem with the artillery keys:
Code: [Select]
$Formula: ( every-time
   ( and
      ( or
         ( key-pressed "1" )
         ( key-pressed "2" )
         ( key-pressed "3" )
         ( key-pressed "4" )
      )
      ( <
         ( mission-time-msecs )
         @nextNumberPoll[-1]
      )
   )
   ( key-reset-multiple "1" "2" "3" "4" )
)
+Name: Reset Keypresses the Axem Way

To avoid the second problem and save a variable, the keys check for key-pressed and ( > ( mission-time-msecs ) @nextNumberPoll[-1] ), and then set @nextNumberPoll[-1] to ( + ( mission-time-msecs ) 250 ) so that the artillery keys have a quarter-second cooldown.

So I'd use a set of events along these lines:
Code: [Select]
$Formula: ( when
   ( and
      ( key-pressed "Alt-J" )
      ( >=
         ( mission-time )
         @nextJumpTime[-1]
      )
      [ any other conditions here ]
   [ in-system jump logic here ]
   ( key-reset-multiple "Alt-J" )
   ( modify-variable
      @nextJumpTime[-1]
      ( + ( mission-time ) 30 )
   )
+Name: in-system jump trigger
+Repeat Count: -1
+Trigger Count: -1
+Interval: 0

$Formula: ( every-time
   ( and
      ( key-pressed "Alt-J" )
      ( <
         ( mission-time )
         @nextJumpTime[-1]
      )
   )
   ( key-reset-multiple "Alt-J" )
)
+Name: Reset jump key
+Repeat Count: 1
+Interval: 1

If you need multiple events in sequence for the in-system jump (and, let's face it, you do), that's when you add another variable (say, @jumpSequenceStage) and use that to trigger each event in turn (possibly in combination with @nextJumpTime in order to get the timing between stages right; if you need millisecond timing, then you just change mission-time to mission-time-msecs and add 30000 instead of 30).

For instance, add this to the jump event:
Code: [Select]
   ( modify-variable @jumpSequenceStage[-1] 0 )
and then your second event would check this:
Code: [Select]
$Formula: ( when
   ( and
      ( = @jumpSequenceStage[-1] 0 )
      ( >=
         @nextJumpTime[-1]
         ( - ( mission-time ) 25 )
      )
   )
   [ second stage of jump here ]
   ( modify-variable @jumpSequenceStage[-1] 1 )
)
Event: In-system jump stage 2
+Repeat Count: -1
+Trigger Count: -1
+Interval: 0
This example would make it wait five seconds before triggering the second stage. Then your final event just sets it back to -1 again, ready for the next jump sequence.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Player Warp to Target?
Yep. I remembered the second one when I was writing things down but forgot it when I got to that part of the event. :D

The first one should be easier to beat though, simply key-reset-multiple in the Warp Drive Recharged event. Then any key presses before the drive was ready will be ignored. You would have to make the modification of the LastWarpTime variable non-optional though. Doing things that way avoids having a nasty every-time event that triggers every frame and eats up more CPU cycles doing nothing useful.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
Re: Player Warp to Target?
I put the key-reset-multiple in the Warp Recharge event. Every time the warp drive is ready to use, it resets Alt-J to prevent unwanted warps.

However, I seem to be having trouble finding the 'any-of' SEXP. Here is the event I am working on at the moment:

Code: [Select]
Warp Mode Selector
     op  if-then-else
      |--  op  and
      |     |--  op  =
      |     |     |-- Warp-In-Progress(0)   <-- Variable, this becomes 1 when the warp sequence is running
      |     |     |-- 1
      |     |
      |     |--  op  true <-- This is where I need to stick the "Are you facing your target?" check
      |
      |--  op  modify-variable
      |     |--  Warp-Attack-Config(0)   <-- Variable, uses the warp drive in attack configuration
      |     |--  1
      |
      |--  op  modify-variable
            |--  Warp-Attack-Config(0)   <-- The same variable, uses the subspace drive in escape configuration
            |--  0

I'm also slightly surprised that we do not have a better way to type out SEXP's.
« Last Edit: April 16, 2016, 03:18:45 pm by Erebus Alpha »
"Obviously the meson bomb is a form of cat-toast-device, with the buttered toast inverted, so that the cat and toast both fly in the direction of gravity much faster than expected. By introducing artificial gravity, a pair of cat-toast perpetual motion accelerator units can be made to collide with one another, and they produce an unimaginably devastating explosion. Both cats are named 'Meson'."

 - Wikileaks 2383

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Player Warp to Target?
I seem to be having trouble finding the 'any-of' SEXP.
You need to use when-argument instead of when; the first argument will default to any-of, and can be changed to a variety of related SEXPs under the Conditionals menu.

If you're wondering, no, there is no if-then-else-argument. Most FREDers do not actually like if-then-else due to it being slightly harder to tell which SEXPs will get evaluated when; some prefer, instead, to be explicit by using chained "when" SEXPs. Like this:
Code: [Select]
( when
   [ base condition goes here ]
   ( when
      ( = @someVariable[0] 1 )
      [ do something ]
   )
   ( when
      ( != @someVariable[0] 1 )
      [ do something else ]
   )
)
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 
Re: Player Warp to Target?
Yes, it works great!

...Mostly.

As soon as the AI control kicks in for the beginning of the warp sequence, it wants to have something hostile targeted. This is completely fine if shock-jumping enemy large ships with bombers or assault fighters, but if you need to get to a friendly target rapidly (say, for an escort mission?) the AI decides to switch targets.

I'm going to try and shuffle things around a bit, so that the first event records the player's target before the AI ever takes control. Once the target is stored in a variable, the AI should be able to target whatever it wants without screwing up the warp.

So close to paste-able tactical smart warp in every mission! :D

EDIT:

I believe I solved this problem just by putting player-use-ai far enough at the back of the line so that all the important targeting-related events happen before the AI swaps targets.
« Last Edit: April 19, 2016, 01:37:12 am by Erebus Alpha »
"Obviously the meson bomb is a form of cat-toast-device, with the buttered toast inverted, so that the cat and toast both fly in the direction of gravity much faster than expected. By introducing artificial gravity, a pair of cat-toast perpetual motion accelerator units can be made to collide with one another, and they produce an unimaginably devastating explosion. Both cats are named 'Meson'."

 - Wikileaks 2383