Author Topic: Vehicle Movement Speed  (Read 3118 times)

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Vehicle Movement Speed
« on: May 01, 2011, 03:31:47 PM »
I was working on code that calculates the time that it takes a unit to travel from A to B. For no good reason I decided that I want exact calculations which match the ones done by op2. So, I looked at some disassembled function and here is how it works:

(function is at 44B760)

Note: this is for movement from one tile to an adjacent tile only
Note: <time unit> is probably a tick (time measurements suggest that), but I didn't verify it yet.

1. rotation: Before a vehicle will move from one tile to an adjacent tile, it will turn into the direction of the adjacent (destination) tile. This is done by taking the rotation difference (rotation is 32 times the direction) and decreasing it by the vehicle's turn rate every <time unit>, until it reaches 0 which means that the vehicle is heading in the direction of the destination tile.

2. movement: First a check is done whether a unit or lava or a wall or blight expansion is on the destination tile. If neither is the case, the game calculates movement costs as follows:

sourceTrackTypeSpeed = CellTypeInfo[cellType of sourceTile].trackTypeSpeed[trackType of moving unit]
destTrackTypeSpeed = CellTypeInfo[cellType of destTile].trackTypeSpeed[trackType of moving unit]
if destTrackTypeSpeed == 0 (tile is impassible) the function is aborted
adjustedMovementPoints = movementPoints (*724/512, result truncated if moving diagonally)

costs = (sourceTrackTypeSpeed + destTrackTypeSpeed) * adjustedMovementPoints / 1024

if lights are off and there is no daylight everywhere, (costs * light brightness at vec position / 32) will be added to costs.

if the vehicle is damaged, (damage * costs / hitPoints) will be added to the costs.

if costs are smaller than 2, they are set to 2

it will take the unit cost <time unit>s to move from the source tile to the destination tile

Edit: corrected (small) mistakes
« Last Edit: May 02, 2011, 03:15:20 AM by TH300 »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Vehicle Movement Speed
« Reply #1 on: May 01, 2011, 06:16:03 PM »
Wow, thank you for this. I've been wondering about this myself, but have never looked into it.
 

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Vehicle Movement Speed
« Reply #2 on: May 02, 2011, 03:07:33 AM »
I should add that the function is called only once when movement from one waypoint to another waypoint starts (where waypoints are always on adjacent tiles). It doesn't do any of the animation. All it does is initialize/set some values in the "destWaypoints" struct which is associated with the moving unit and move the unitID from source tile to destination tile.

Also, there is a branch of that function, that I didn't look into: What happens if lava or a wall or blight expansion or a unit is blocking the destination tile.
« Last Edit: May 02, 2011, 03:53:59 AM by TH300 »

Offline evecolonycamander

  • Hero Member
  • *****
  • Posts: 602
Vehicle Movement Speed
« Reply #3 on: May 02, 2011, 10:50:20 AM »
I guess that explains why units with more heath then usual move at max possible speed. apparently, 6-7 supernovas do negative damage when all attack at once
''The blight cant get us up here!''
-famous last words
--------------o0o--------------
Outpost 2: EoM project status: Re-planning

Offline jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Vehicle Movement Speed
« Reply #4 on: May 02, 2011, 12:56:19 PM »
So, if you have the "I accidentally set my convec to close to a supervortex and it now has health out the wazoo", it will move over all terrain as if it's bulldozed?

Offline evecolonycamander

  • Hero Member
  • *****
  • Posts: 602
Vehicle Movement Speed
« Reply #5 on: May 02, 2011, 09:01:23 PM »
no, as if its vehical speed was 0. instant movement
''The blight cant get us up here!''
-famous last words
--------------o0o--------------
Outpost 2: EoM project status: Re-planning

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Vehicle Movement Speed
« Reply #6 on: May 03, 2011, 01:32:18 AM »
if a unit's damage value is set to a negative value it will move faster. If its set to -hitPoints or a smaller value it will move at max possible speed. I don't know if that is what happens when a unit suffers too much damage. Considering that the damage value is only 2 Bytes and apparently signed, it seems at least possible that it simply overflows at 32768. Since a negative value is always smaller than the hitPoints of a unit, the game will probably not clip the value nor recognize the unit as destroyed. Thats how I imagine how it might work. I did neither look at the corresponding part of the disassembly nor did I read one of the probably numerous forum threads on that subject (you should do that though, before you ask any further questions).

One thing, that is visible though, is that instant movement is not possible. It will always take at least 2 ticks to move from one tile to an adjacent tile. Considering that this allows a unit to move 50 tiles per mark, it may look like instant movement though.

Offline jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Vehicle Movement Speed
« Reply #7 on: May 03, 2011, 11:33:54 AM »
I wonder if it does the same thing (the way it checks if a unit is destroyed) for research, because I was playing a game, and my adv. lab got disabled, and my research went in to the negatives.   When I researched it all the way to 0 again, It had that research completed, along with another that I wasn't working on, but was about to select

NOTE: The researches were Metallurgy and GORF teks.
« Last Edit: May 03, 2011, 11:34:06 AM by jcj94 »