[MOD 0.12.21] Wind Turbine

Topics and discussion about specific mods
hrompik
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun May 03, 2015 8:53 pm
Contact:

Re: [MOD 0.12.x] Wind Turbine

Post by hrompik »

error atfer update to Game version 0.12.11.
__Wind_Turbine__/control.lua:6: attempt to index global 'game' (a nil value)
When start new game, or load save.
- Lua API calls on_load, on_init, on_configuration_changed, on_event and generate_event_name
have been moved to a new namespace called script (so from now use script.on_load(...)). This will break many mods!
Just rename game.on_event to script.on_event
at 6 25 39 lines in control.lua

works!
Last edited by hrompik on Fri Oct 16, 2015 4:54 pm, edited 1 time in total.

reddutton
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Sun Jul 19, 2015 12:35 am
Contact:

Re: [MOD 0.12.x] Wind Turbine

Post by reddutton »

i belive this is the case for most mods on the .11 update
thy may be stupid but thy am smart (reddutton 2006 seconlife)

Keks
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sun Sep 27, 2015 12:55 pm
Contact:

Re: [MOD 0.12.x] Wind Turbine

Post by Keks »

would it be possible, not extreme Lag causing and not a total pain for you to code:
  • change the momentary output for turbines that are far away (since wind conditions differ over distance ;))
  • Increase yield near Water
  • maybe create a version to place on water
  • or one that can only be placed the way offshore pumps are
thanks a lot btw ;)

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [MOD 0.12.11+] Wind Turbine

Post by Klonan »

Mod has been updated for 0.12.11+

Please let me know if there are any bugs, errors etc.

SPolygon
Burner Inserter
Burner Inserter
Posts: 17
Joined: Sat Jan 02, 2016 8:22 pm
Contact:

Re: [MOD 0.12.11+] Wind Turbine

Post by SPolygon »

Ehm, I have like 300 of theese guys powering my factory, but they all rotate in EXACTLY same way, so, is it possible to make each one rotate differently? I know, not a bug or anything, but still :D

Btw.: What about some larger version of it, that would require research and stuff?

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2124
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: [MOD 0.12.x] Wind Turbine

Post by Ranakastrasz »

Keks wrote:would it be possible, not extreme Lag causing and not a total pain for you to code:
  • change the momentary output for turbines that are far away (since wind conditions differ over distance ;))
  • Increase yield near Water
  • maybe create a version to place on water
  • or one that can only be placed the way offshore pumps are
thanks a lot btw ;)
Locational power is feasible, but might be costly. As is, I imagine it runs a single pass setting the values for all of them. This would requires the equation to be run per entity, or per chunk.

Increased yield near water would be easy enough. On placement, attach data based on water proximity. If you have something like landfill installed however, might need to register such, or recalculate every half hour or something.

Placemet on water only. Probably possible to do, not sure how.
Offshore pumps. No idea how, but probably feasible, again.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [MOD 0.12.11+] Wind Turbine

Post by Klonan »

SPolygon wrote:Ehm, I have like 300 of theese guys powering my factory, but they all rotate in EXACTLY same way, so, is it possible to make each one rotate differently? I know, not a bug or anything, but still :D

Btw.: What about some larger version of it, that would require research and stuff?
Yea that happens if you place the power poles down after you place the turbines, since they all connect at the same time, they all spin at the same time...
I suggest ripping them all up, and then placing them down after you have the power poles in place, this should help spread out the rotations

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 422
Joined: Tue May 05, 2015 6:07 pm
Contact:

Re: [MOD 0.12.21] Wind Turbine

Post by Afforess »

I noticed the script update time for wind turbines was quite high with a lot of turbines placed, and took a peek at the code. There are a number of optimizations that can significantly cut the update time down (from 0.45 to 0.2 on my save), all in the check_generators function.

First, store data in local variables as much as possible, especially when a loop or iteration is involved. Even the tick can be stored in a variable. Previously you were making an API call to the game engine for each wind turbine just for the current tick, and then doing a modulus (sorta expensive), which can all be done once first and cached.

Also, there was a minor bug in the existing implementation that would cause wind turbines not to be updated for a tick when one was removed. When you iterate a list and are removing items in lua, you have to iterate it backwards. If you don't, and you call table.remove on an item, you will skip the next item in the list. This is because table.remove shifts every item down in the array when something is removed, so the next element is out of order in front-to-back iteration.

Full changes:

Code: Select all

function check_generators()
	if global.wind_turbine then
		local turbines = global.wind_turbine
		local num_turbines = #turbines
		local tick = game.tick % 125
		for k = num_turbines, 1, -1 do
			local gen = turbines[k]
			if k % 125 == tick then
				if gen.valid then
					local pot = gen.fluidbox[1]
		 			if pot then
						pot["amount"] = 10
						pot["temperature"] = 100*(game.wind_speed*25)
						gen.fluidbox[1] = pot
					else table.remove(turbines, k); end
				end
			end
		end
	end
end

Shiny_Martin
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon Sep 26, 2016 11:41 am
Contact:

Re: [MOD 0.12.21] Wind Turbine

Post by Shiny_Martin »

Can I use this for my mod "Advanced Green Energy"?
Im doing upgrades to Solar Panels and a few more addons, and would really like to add Wind Turbines.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [MOD 0.12.21] Wind Turbine

Post by Klonan »

Shiny_Martin wrote:Can I use this for my mod "Advanced Green Energy"?
Im doing upgrades to Solar Panels and a few more addons, and would really like to add Wind Turbines.
Sure :)

Shiny_Martin
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon Sep 26, 2016 11:41 am
Contact:

Re: [MOD 0.12.21] Wind Turbine

Post by Shiny_Martin »

Klonan wrote:
Shiny_Martin wrote:Can I use this for my mod "Advanced Green Energy"?
Im doing upgrades to Solar Panels and a few more addons, and would really like to add Wind Turbines.
Sure :)

Thanks! I will make sure to credit you. :D

Avocrom
Manual Inserter
Manual Inserter
Posts: 1
Joined: Fri Jan 27, 2017 2:46 am
Contact:

Re: [MOD 0.12.21] Wind Turbine

Post by Avocrom »

I have hundreds of these things it's the only thing powering my buildings and except for a small spot all of them are now dead as the wind has stopped blowing.

Is this because I've removed most of the trees around me or is it just RNG? And what can if do, if anything, to fix this?

Thanks.

EDIT: And naturally I post the message and the wind starts blowing again.

PTTG
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Sat Nov 18, 2017 7:47 pm
Contact:

Re: [MOD 0.12.21] Wind Turbine

Post by PTTG »

Does the wind vary depending on location? And how much?

Post Reply

Return to “Mods”