Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: The Possibility of Harpoons  (Read 1029 times)

Digganob

  • Lieutenant
  • **
  • Posts: 64
    • View Profile
The Possibility of Harpoons
« on: March 04, 2022, 07:21:31 AM »

I don't have any experience modding this game, so I thought I'd ask you more experienced modders, if a certain idea would be implementable:

Harpoon guns, that can stick into the ships they're fired at, connecting them with a cable, allowing the ship with stronger thrusters to pull the weaker ship.

There are other things I would like to implement, such as a cable strength stat, which, if exceeded by the sum of the two ships' pulling against each others' thruster strengths, would break the cable, meaning more investment would be needed to harpoon larger ships.

Another thing that would be neat, but not necessary for gameplay, would be the ability to snap a cable by giving it some slack by the ships first flying towards each other, then flying away, the inertia, if high enough, causing the cable to snap, even if the total thruster strength of each ship is not higher than the cable strength stat. This way, the player could avoid being dragged away by larger ships, if they're willing to get closer to the harpooning ship for a moment.

I would just like to know if this stuff is possible, and if so, I might see if I can make something of the idea.

Anyone reading this is free to use my idea, don't feel like you're stealing it. I just want harpoons in the game.
Logged

Amoebka

  • Admiral
  • *****
  • Posts: 1318
    • View Profile
Re: The Possibility of Harpoons
« Reply #1 on: March 04, 2022, 07:48:25 AM »

It seems possible by using listeners and every frame combat scripts. Attach the cable using damage taken listener or projectile's on-hit effect, apply force to the dragged ship every frame using AdvanceableListener or BaseCombatLayeredRenderingPlugin or anything else that triggers each frame.

Also, the vector math for the whole force/inertia thing will get real complicated real fast.

Doable, but you should probably start with something easier for your first mod.
Logged

Digganob

  • Lieutenant
  • **
  • Posts: 64
    • View Profile
Re: The Possibility of Harpoons
« Reply #2 on: March 04, 2022, 08:28:34 AM »

Doable, but you should probably start with something easier for your first mod.

Well, seems to me there are already lots of people out here making high-quality mods adding ships and weapons and factions and all of that, and I wouldn't really be doing much by making some crappy beginner mod, and I don't think I'd go on to do anything much more than that either.

So, I was just thinking something that isn't in the game yet, that I want specifically, would be cool. It might be more of a pain in the ass learning just enough to do this, instead of learning from the basics up to the advanced, but I'm not planning on doing much else than this. I did have an idea for boarding mechanics, but that would be using a boarding utility a guy already made, which does all the hard parts, apparently. https://fractalsoftworks.com/forum/index.php?topic=19881.0
Logged

Amoebka

  • Admiral
  • *****
  • Posts: 1318
    • View Profile
Re: The Possibility of Harpoons
« Reply #3 on: March 04, 2022, 08:49:20 AM »

I mean, the coding part is actually pretty straightforward. It's all the math involved in deciding how stongly to pull, in which direction, whether to break the cable or not, etc, that is going to take a lot of thinking.

For coding, all you need is:

1) An OnHitEffectPlugin for your weapon's projectile. Within it you have:

Code
public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target,  Vector2f point, boolean shieldHit, ApplyDamageResultAPI damageResult, CombatEngineAPI engine) {
//...
}

Here, you decide if you want to attach harpoon or not. Do the shield hit counts, does some damage threshold needs to be exceeded, etc. You will also need to check if the target is an instance of ShipAPI or not. If you do want to attach a cable, you then do:

Code
ShipAPI target_ship = (ShipAPI) target;
target_ship.addListener(new my_every_frame_harpoon_script(...));

2) An every frame combat script, in this case a listener class that implements AdvanceableListener. You pass the towing ShipAPI, the target ShipAPI, and the connection point (likely the Vector2f point from the on-hit effect) as constructor arguments to it and store them in protected/private variables.

Then here you have:
Code
public void advance(float amount) {
//...
}

This method is called every script (amount is how many seconds have passed since the last call). Here you do a bunch of very difficult math to figure out the force and direction of the pull. You can use ShipAPI.getLocation() and ShipAPI.getVelocity() to find the locations and velocity vectors of both ships. When you want to push something, you just modify its getVelocity().

3) When you want to break the cable, you do
Code
towed_ship.removeListener(this);
withing your every frame listener's advance method.

4) You will also need to do visuals for the cable. They will also be updated in the advance method.
« Last Edit: March 04, 2022, 08:52:52 AM by Amoebka »
Logged

Yunru

  • Admiral
  • *****
  • Posts: 1560
    • View Profile
Re: The Possibility of Harpoons
« Reply #4 on: March 04, 2022, 10:57:33 AM »

Nijigen Extended has Harpoon missiles that pull the two ships towards each other, accounting for mass. It just doesn't list them in the post for some reason.

Obsidian Actual

  • Commander
  • ***
  • Posts: 102
    • View Profile
Re: The Possibility of Harpoons
« Reply #5 on: March 04, 2022, 12:09:58 PM »

Nijigen Extended has Harpoon missiles that pull the two ships towards each other, accounting for mass. It just doesn't list them in the post for some reason.

Wouldn't have known to look there myself had you not pointed it out; thanks Yunru.

So, a LazyLib method, aye? CombatUtils.applyForce()... and like you said, it grabs a CombatEntityAPI's mass as well.

I wonder what the masses are for the range of random combat layer asteroids are... and how viable it would be for a ship/fighter/strikecraft to fire an anchor towards one to enact a rapid vector change.
Logged

Deageon

  • Commander
  • ***
  • Posts: 115
    • View Profile
Re: The Possibility of Harpoons
« Reply #6 on: March 04, 2022, 02:56:26 PM »

Armaa's special pirate mech has a harpoon launcher that reels in the ship and also constantly zaps the enemy for like, 3-4 seconds.
Logged

Digganob

  • Lieutenant
  • **
  • Posts: 64
    • View Profile
Re: The Possibility of Harpoons
« Reply #7 on: March 04, 2022, 07:30:14 PM »

I mean, the coding part is actually pretty straightforward. It's all the math involved in deciding how stongly to pull, in which direction, whether to break the cable or not, etc, that is going to take a lot of thinking.

Hm. Well, if it's possible, I'll see about getting it done.

As I said though, I have no experience modding this game. I've looked around some for a guide to it, but I'm not sure where to start. The guide on the wiki looks fairly comprehensive, but I'm not sure if it covers the stuff you've talked about implementing to make a harpoon.
Logged