Helicopters

by kumpu

Adds a fully animated attack helicopter to the game. Ideal for getting from A to B quickly, exploring the map, building islands and nuking biters from the sky. Now 84% less buggier!

Content
4 years ago
0.15 - 0.17
290
Transportation

g Fuel Gauge Doesn't work for All Fuels - FIXED

4 years ago

Hey! Did you know the fuel gauge doesn't work with wood, coal, etc. for fuels?

4 years ago

Here's a diff on heliBase.lua that would make it work based on the fuel currently being used:

372c372
< heli.burnerDriver = heli.surface.create_entity{name="player", force = game.forces.neutral, position = heli.baseEnt.position}


          heli.burnerDriver = heli.surface.create_entity{name="character", force = game.forces.neutral, position = heli.baseEnt.position}

765c765
< self.floodlightDriver = self.surface.create_entity{name="player", force = game.forces.neutral, position = self.baseEnt.position}


          self.floodlightDriver = self.surface.create_entity{name="character", force = game.forces.neutral, position = self.baseEnt.position}

813a814
local maxFuelStack = 0
819a821
maxFuelStack = math.max(maxFuelStack, curStack.prototype.stack_size * curStack.prototype.fuel_value)
822,823c824,828
<
< return remainingFuel / (self.baseEnt.prototype.consumption + self.baseEngineConsumption) / self.fullTankFlightTime


  if maxFuelStack == 0 then
      maxFuelStack = getMaxStackFuelVal()
  end
  --return remainingFuel / (self.baseEnt.prototype.consumption + self.baseEngineConsumption) / self.fullTankFlightTime
  return remainingFuel / (maxFuelStack * self.fuelSlots)
4 years ago

Oh, uhh, sorry, that didn't work! Here it is: https://hastebin.com/riqotiwubo.shell

4 years ago

Oh, incidentally, this diff should also update your mod with the 17.35 player references, at least in the places I found. :)

4 years ago

@caes :
Quick test it, game crash when the fuel reach zero.

log :
63.727 Error MainLoop.cpp:1173: Exception at tick 27517: The mod Helicopters caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Helicopters::on_tick (ID 0)
Helicopters/logic/heliBase.lua:825: attempt to call global 'getMaxStackFuelVal' (a nil value)
stack traceback:
Helicopters/logic/heliBase.lua:825: in function 'getFuelFullness'
Helicopters/logic/heliBase.lua:833: in function 'handleFuelConsumption'
Helicopters/logic/heliBase.lua:449: in function 'OnTick'
Helicopters/logic/heliBase.lua:263: in function 'OnTick'
Helicopters/logic/util.lua:99: in function 'checkAndTickInGlobal'
Helicopters/control.lua:102: in function <Helicopters/control.lua:101

4 years ago

I think getMaxStackFuelVal() is a function from the original helicopter mod in util.lua, no? Or did I add that somewhere along the way. Here's what my getMaxStackFuelVal() looks like, in util.lua. The util.lua file would need to be "require"d before it showed up as not nil in the heliBase.lua code.

https://hastebin.com/uxezacayaq.rb

The code as I have it tries to circumvent the getMaxStackFuelVal() function unless the fuel is empty. This is why it only tries to call that function when the fuel is empty. You could probably remove that call altogether, rather than adding the function -- it's a silly call, since it relies on an arbitrary fuel type instead of the type in the tank. That might be why the original author put it this way: to prevent a divide by zero when dividing the fuel by a fuel type that doesn't exist (since the fuel tank is empty). It's just there because I changed the original code as little as possible, I think. The best thing would be to add an if statement to the return line to just return 0 if there's no fuel, or return the remaining fuel over the maxFuelStack * fuelSlots if there is fuel, I think.

4 years ago

E.G. I think this is probably safe.

https://hastebin.com/asuxeyatij.rb

4 years ago

Just tested and it works fine with coal running out, except I put the if remainingfuel statement AFTER the for iteration. But I'd bet it'd work either way.

4 years ago
(updated 4 years ago)

edit: i didn't see you added the function here, because it doesn't exist anywhere in the original code.

4 years ago

Must have added it, then, for some reason. Or it may be that the function was removed since then -- My version is made from the 0.16 version.

4 years ago

At any rate, just add the function I linked above and you should be good.

4 years ago

Ah, yea, I'm using the 0.17 version. That might be where things are different

4 years ago

I think the biggest issue is that there isn't a unified code base at this point, since the author is unable to maintain it at this point in time. There are quite a few versions floating around, haha

4 years ago
(updated 4 years ago)

OK, just quick test it using Wood, it doesn't crash anymore when fuel empty.
Thank you.

4 years ago

If I can get permission from Earandel to post a modified version of his Hauler, then I could post my working and complete version of helicopters, which is part of a secret adamo-cars mod, since the helicopter license allows for it. I keep meaning to ask him.

4 years ago

I have updated the fuel tank to base it's fullness off of it's currently burning fuel value. It should work properly for any fuel now.

New response