Determine the distance a ship can move in 1 turn

A place for discussion of making game modifications.
User avatar
harpy eagle
Posts: 276
Joined: Sat Mar 10, 2018 3:25 am

Determine the distance a ship can move in 1 turn

Postby harpy eagle » Tue Apr 03, 2018 11:18 pm

Between max_fuel, motion_function, motion_speed, I'm having a bit of trouble figuring it out. Is there a simple relationship between "motion points" and euclidean distance, say, when a ship travels in a straight line?

Is there similarly a simple relationship between "motion points" and the angle of a turn?

User avatar
sven
Site Admin
Posts: 1390
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Determine the distance a ship can move in 1 turn

Postby sven » Tue Apr 03, 2018 11:43 pm

harpy eagle wrote:Between max_fuel, motion_function, motion_speed, I'm having a bit of trouble figuring it out. Is there a simple relationship between "motion points" and euclidean distance, say, when a ship travels in a straight line?

Is there similarly a simple relationship between "motion points" and the angle of a turn?


The core ship motion functions are one of (possible even the) oldest parts of the codebase. Thus, they involve a lot more C++ than they probably need to.

In theory, each ship has a motion_cost function, and that function can return whatever it likes for a given delta x, delta y, delta r combination. That cost returns how many motions points "aka fuel" a ship consumes changing from one position / rotation to another.

In practice, the motion cost functions currently in use are very simple. They all return

Code: Select all

dist+turn_mult*delta_r


So if you're moving in a straight line, you always consume motion points equal to the distance traveled. And if you're turning, you always consume turn_mult motion points per each 45 degrees worth of turn.

Turn_mult does vary for each ship, but not in an overly complex way.

ship.s>4 --> turn_mult=(25/4),

ship.s==4 --> turn_mult=0.7*(25/4), and

ship.s<4--> turn_mult = (25/4)/3.

User avatar
sven
Site Admin
Posts: 1390
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Determine the distance a ship can move in 1 turn

Postby sven » Tue Apr 03, 2018 11:53 pm

sven wrote:

Code: Select all

dist+turn_mult*delta_r


The tricky thing, when one gets into ship motion, is figuring out what sort of delta_r is required to move from point A to point B; as that in turn affects the cost of move, and, thus, whether or not it's even possible for the ship to get from one place to another.

That's why the CloseAndAttack.lua logic uses C++ helper functions like find_min_facing_move_L2() to figure out what x,y,r combination to use to close on a given target.

User avatar
siyoa
Posts: 127
Joined: Fri Apr 21, 2017 3:19 pm

Re: Determine the distance a ship can move in 1 turn

Postby siyoa » Wed Apr 04, 2018 12:01 am

sven wrote:Thus, they involve a lot more C++ than they probably need to.
Turn_mult does vary for each ship, but not in an overly complex way.

ship.s>4 --> turn_mult=(25/4),

ship.s==4 --> turn_mult=0.7*(25/4), and

ship.s<4--> turn_mult = (25/4)/3.

so if this gets exposed to lua eventually, we can code in technology like inertial nullifier from MoO ? ;)
How did YOU get a key? All right, go in.

User avatar
sven
Site Admin
Posts: 1390
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Determine the distance a ship can move in 1 turn

Postby sven » Wed Apr 04, 2018 12:21 am

siyoa wrote:so if this gets exposed to lua eventually, we can code in technology like inertial nullifier from MoO ? ;)


In theory, the system as-is should already be able to handle that -- but the code organization is nightmarish, and includes a bunch of C++/lua interop, so this is probably something I should write up myself, rather than leaving it to you guys. I'll add "inertial nullifier" to my TODO list ;)

User avatar
siyoa
Posts: 127
Joined: Fri Apr 21, 2017 3:19 pm

Re: Determine the distance a ship can move in 1 turn

Postby siyoa » Wed Apr 04, 2018 4:59 am

sven wrote:I'll add "inertial nullifier" to my TODO list ;)

:D
How did YOU get a key? All right, go in.

User avatar
harpy eagle
Posts: 276
Joined: Sat Mar 10, 2018 3:25 am

Re: Determine the distance a ship can move in 1 turn

Postby harpy eagle » Wed Apr 04, 2018 8:21 pm

Another ship movement related question for you sven. In a mod I'm working on under certain conditions I want a ship to keep its current position but rotate to face it's target.

The way I've been doing it is to call find_min_facing_move_L2() but discard the x,y returned from that and use ship.x,ship.y instead.

It mostly works except very often it causes ships to wiggle in a weird way before turning back to face their target, and in some rare cases (seems like it only happens when ships are overlapping), they will turn away from their target.

User avatar
harpy eagle
Posts: 276
Joined: Sat Mar 10, 2018 3:25 am

Re: Determine the distance a ship can move in 1 turn

Postby harpy eagle » Thu Apr 05, 2018 1:33 am

Actually now I'm finding the random wiggling can actually help the AI because of shield directionality, go figure :lol:

User avatar
harpy eagle
Posts: 276
Joined: Sat Mar 10, 2018 3:25 am

Re: Determine the distance a ship can move in 1 turn

Postby harpy eagle » Fri Apr 06, 2018 10:32 pm

Some more questions:

What is the r2 returned by find_min_facing_move_L2()?

Is there any way to use find_min_facing_move_L2() to move a ship towards a tracking object instead of another ship?

User avatar
sven
Site Admin
Posts: 1390
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Determine the distance a ship can move in 1 turn

Postby sven » Sat Apr 07, 2018 8:36 pm

harpy eagle wrote:Another ship movement related question for you sven. In a mod I'm working on under certain conditions I want a ship to keep its current position but rotate to face it's target.


There's an entirely undocumented function called "rotate_to_face(ship,target)" that should get you the minimum-cost rotation needed to face a given target. And unlike find_min_facing_move_L2, it should work with missile and fighter targets.

User avatar
harpy eagle
Posts: 276
Joined: Sat Mar 10, 2018 3:25 am

Re: Determine the distance a ship can move in 1 turn

Postby harpy eagle » Sat Apr 07, 2018 8:59 pm

Cool, I'll look at that. Although I do need to move towards tracking objects as well (they're two separate things).

If rotate_to_face(ship,target) just gets the minimum cost rotation, does that mean I need to check that the ship has enough fuel left? Or will it return a rotation limited by fuel like how find_min_facing_move_L2() seems to work?

User avatar
sven
Site Admin
Posts: 1390
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Determine the distance a ship can move in 1 turn

Postby sven » Sat Apr 07, 2018 9:17 pm

harpy eagle wrote:Cool, I'll look at that. Although I do need to move towards tracking objects as well (they're two separate things).

If rotate_to_face(ship,target) just gets the minimum cost rotation, does that mean I need to check that the ship has enough fuel left?


I believe you'll need to do the fuel check yourself. find_min_facing_move_L2() does an optimization over all possible moves to find one that uses as little fuel as possible, and it includes fallback logic for handling cases where the objective is not actually achievable; rotate_to_face just iterates over all possible rotations, and finds one that both uses the smallest amount of fuel and gets us into a state where we're facing the target.

User avatar
sven
Site Admin
Posts: 1390
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Determine the distance a ship can move in 1 turn

Postby sven » Sat Apr 07, 2018 9:19 pm

harpy eagle wrote:Although I do need to move towards tracking objects as well (they're two separate things).


It's been ages since I wrote this code, but, I've looked over the source to find_min_facing_move_L2(), and I believe the current restriction to ship targets is unnecessary. I've pushed a build to the Steam in_development branch that changes the function so that it will accept a target of any tactical object type -- let me know if you run into any issues with it.

User avatar
harpy eagle
Posts: 276
Joined: Sat Mar 10, 2018 3:25 am

Re: Determine the distance a ship can move in 1 turn

Postby harpy eagle » Sat Apr 07, 2018 11:02 pm

That's awesome! Thanks.

User avatar
harpy eagle
Posts: 276
Joined: Sat Mar 10, 2018 3:25 am

Re: Determine the distance a ship can move in 1 turn

Postby harpy eagle » Fri Apr 13, 2018 4:05 pm

Which revision is the change on? Just want to know when it reaches the public branch.


Return to “Modding”

Who is online

Users browsing this forum: No registered users and 1 guest

cron