The Ur-Quan Masters Home Page Welcome, Guest. Please login or register.
Did you miss your activation email?
October 14, 2024, 04:39:39 am
Home Help Search Login Register
News: Celebrating 30 years of Star Control 2 - The Ur-Quan Masters

+  The Ur-Quan Masters Discussion Forum
|-+  The Ur-Quan Masters Re-Release
| |-+  Technical Issues (Moderator: Death 999)
| | |-+  A strange bit of combat physics
« previous next »
Pages: [1] Print
Author Topic: A strange bit of combat physics  (Read 3625 times)
Shiver
Guest


Email
A strange bit of combat physics
« on: October 22, 2008, 01:22:51 am »

Take a look at lines 70-77 of ship.c in UQM 0.6.2:

Code:
else if (TravelAngle == CurrentAngle
&& (StarShipPtr->cur_status_flags
& (SHIP_AT_MAX_SPEED | SHIP_BEYOND_MAX_SPEED))
&& !(StarShipPtr->cur_status_flags & SHIP_IN_GRAVITY_WELL))
{ // already maxed-out acceleration
return (StarShipPtr->cur_status_flags
& (SHIP_AT_MAX_SPEED | SHIP_BEYOND_MAX_SPEED));
}

I've been playing melee competitively for a long time and I wasn't even aware the game did this until I started poking around with the game's ship code myself. It's rare for a ship to perform a gravity whip without being nudged by the gravity well upon exiting it or for a ship to not turn at all before attempting to slow down. When this code does kick in, it will prevent a ship from slowing itself back down to default speed and screw over the unsuspecting player. Not knowing about this code until yesterday, I get the feeling I have had ships destroyed by it without understanding what went wrong.

Fossil was the one that pointed me to this code in the first place. He also gave me this fix:

Code:
else if (TravelAngle == CurrentAngle
&& (StarShipPtr->cur_status_flags
& (SHIP_AT_MAX_SPEED | SHIP_BEYOND_MAX_SPEED))
&& !(StarShipPtr->cur_status_flags & SHIP_IN_GRAVITY_WELL))
{ // already maxed-out acceleration
SIZE delta_x, delta_y;
SIZE cur_delta_x, cur_delta_y;
DWORD current_speed;
thrust_increment = WORLD_TO_VELOCITY (thrust_increment);
GetCurrentVelocityComponents (VelocityPtr, &cur_delta_x, &cur_delta_y);
current_speed = VelocitySquared (cur_delta_x, cur_delta_y);
delta_x = cur_delta_x - COSINE (CurrentAngle, thrust_increment);
delta_y = cur_delta_y - SINE (CurrentAngle, thrust_increment);
SetVelocityComponents (VelocityPtr, delta_x, delta_y);
return (StarShipPtr->cur_status_flags
& (SHIP_BEYOND_MAX_SPEED));
}

Although the offending code is not a bug and usually does not have much effect on gameplay, I propose this fix be implemented into UQM's next release to make combat physics more consistent.
Logged
Elvish Pillager
Enlightened
*****
Offline Offline

Posts: 625



View Profile
Re: A strange bit of combat physics
« Reply #1 on: October 22, 2008, 03:20:41 am »

I agree that this should be implemented. As Shiver says, the effect a rare exception case with no apparent reason behind it.

-

Technical details:

As far as I can tell, the current code for the different-angle case (lines 117-133) would result in deceleration at half the normal rate of acceleration when facing in the same direction as the velocity vector. This proposed change appears to decelerate at the full normal rate of acceleration.

Also, this proposal is an ugly duplicate implementation. The existing code seems like it would work fine for the identical-angle case. So I'd do the following:

- eliminate the whole "else if()" starting at line 70;
- change line 105 to add a reversal of the conditions, as follows:
Code:
else if (TravelAngle == CurrentAngle
&& (!(StarShipPtr->cur_status_flags
& (SHIP_AT_MAX_SPEED | SHIP_BEYOND_MAX_SPEED))
|| (StarShipPtr->cur_status_flags & SHIP_IN_GRAVITY_WELL)))
Logged

My team of four Androsynth and three Chmmr is the most unfair team ever!
My mod
fossil
Core Team
Frungy champion
*****
Offline Offline

Gender: Male
Posts: 94



View Profile
Re: A strange bit of combat physics
« Reply #2 on: October 23, 2008, 12:00:36 am »

The last proposal looks about right, except you should not test for SHIP_IN_GRAVITY_WELL. That is handled by an else if just above. And this should still invoke when SHIP_AT_MAX_SPEED, so
Code:
else if (TravelAngle == CurrentAngle
&& !(StarShipPtr->cur_status_flags & SHIP_BEYOND_MAX_SPEED))

However, this change has a better chance of getting attention and not getting lost if you submit it as an enhancement type bug in Bugzilla. Provide as much reasoning behind the change as you can.
Logged
Shiver
Guest


Email
Re: A strange bit of combat physics
« Reply #3 on: October 23, 2008, 12:36:27 am »

The last proposal looks about right, except you should not test for SHIP_IN_GRAVITY_WELL. That is handled by an else if just above. And this should still invoke when SHIP_AT_MAX_SPEED, so
Code:
else if (TravelAngle == CurrentAngle
&& !(StarShipPtr->cur_status_flags & SHIP_BEYOND_MAX_SPEED))

This did not work when I tried it. The Thraddash would not brake at all while traveling above max speed in a straight line. Holding off on using Bugzilla for the moment.
Logged
fossil
Core Team
Frungy champion
*****
Offline Offline

Gender: Male
Posts: 94



View Profile
Re: A strange bit of combat physics
« Reply #4 on: October 23, 2008, 02:34:50 am »

This did not work when I tried it.
Did you remove the else if at line 70 as Elvish specified?

Do not hold off on Bugzilla just because all the details have not been worked out. Such details are better dealt with in Bugzilla anyway. Otherwise, it's your choice, of course.
Logged
Shiver
Guest


Email
Re: A strange bit of combat physics
« Reply #5 on: October 23, 2008, 03:03:43 am »

Did you remove the else if at line 70 as Elvish specified?

Do not hold off on Bugzilla just because all the details have not been worked out. Such details are better dealt with in Bugzilla anyway. Otherwise, it's your choice, of course.

Oh, his replacement code worked. But if the details don't need to be set in stone, I suppose I can get on that now.
Logged
fossil
Core Team
Frungy champion
*****
Offline Offline

Gender: Male
Posts: 94



View Profile
Re: A strange bit of combat physics
« Reply #6 on: October 23, 2008, 04:52:01 pm »

Please direct further technical details and proposed patches to Bug #1043
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!