For the jumpjets widget, I would like to request some improvements:
First, give a visual indication of the reloadtime.
Second, give a visual indication of whether or not the landing site is valid.
[X]Third, add a section "energy" in the config file that defines the amount of energy used per jump. -DONE
Forth, add a section "hotkey" in the config file that allows you to bind a hotkey to the jump command.
Jump Jet Improvement Request (Code Updates Posted in Thread)
Moderator: Moderators
Jump Jet Improvement Request (Code Updates Posted in Thread)
Last edited by REVENGE on 17 Aug 2008, 03:51, edited 1 time in total.
Re: Jump Jet Improvement Request (Code Updates Posted in Thread)
Adding energy usage is trivial, of course. So I got off my lazy ass, looked up the commands, and changed the code. This is what was changed within the gadget:
And in your config file, simply add a tag "ecost" and set it to how much energy the jump will cost. It is still optional, btw, so having it undefined is ok.
Code: Select all
local function Jump(unitID, finish)
jumping[unitID]= true
lastJump[unitID] = Spring.GetGameSeconds()
local vector = {}
local vertex = {}
local start = {Spring.GetUnitPosition(unitID)}
local unitDefID = Spring.GetUnitDefID(unitID)
local speed = jumpDefs[unitDefID].speed
local height = jumpDefs[unitDefID].height
local ecost = jumpDefs[unitDefID].ecost or 0
local teamID = Spring.GetUnitTeam(unitID)
for i=1, 3 do
vector[i] = finish[i] - start[i]
end
-- vertex of the parabola
vertex[1] = start[1] + vector[1]*0.5
vertex[2] = start[2] + vector[2]*0.5 + (1-(2*0.5-1)^2)*height
vertex[3] = start[3] + vector[3]*0.5
local lineDist = GetDist3(start, finish)
local flightDist = GetDist3(start, vertex) + GetDist3(vertex, finish)
local speed = speed * lineDist/flightDist
local step = speed/lineDist
local rotUnit = 2^16 / (2*math.pi)
local startHeading = Spring.GetUnitHeading(unitID) + 2^15
local finishHeading = Spring.GetHeadingFromVector(vector[1], vector[3]) + 2^15
-- pick shortest turn direction
if (finishHeading >= startHeading + 2^15) then
startHeading = startHeading + 2^16
elseif (finishHeading < startHeading - 2^15) then
finishHeading = finishHeading + 2^16
end
local turn = finishHeading - startHeading
Spring.CallCOBScript(unitID, "BeginJump", 0)
Spring.UseUnitResource(unitID, "e", ecost)
MoveCtrl.Enable(unitID)
MoveCtrl.SetLeaveTracks(unitID, false)
MoveCtrl.SetRotation(unitID, 0, (startHeading - 2^15)/rotUnit, 0) -- keep current heading
MoveCtrl.SetRotationVelocity(unitID, 0, turn/rotUnit*step, 0)