[0.9.x] Landfill (1.1)

Topics and discussion about specific mods
GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

[0.9.x] Landfill (1.1)

Post by GotLag »

Reclaim the oceans, lakes and rivers!
Image

Features
  • Converts a 2 x 2 tile area to land
  • Can't be placed next to existing buildings
  • 2 tiles is wide enough for a single railway track
Example
Update 1.1
  • Player should no longer get stuck
  • Mod correctly initialises on loading saved game
  • Now only replaces water tiles and refunds landfill item if no tiles are replaced
Download
Last edited by GotLag on Sun May 25, 2014 3:53 am, edited 2 times in total.

Airat9000
Smart Inserter
Smart Inserter
Posts: 1394
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: [0.9.x] Landfill

Post by Airat9000 »

good very good!

and water terraforming update?

GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.9.x] Landfill

Post by GotLag »

Adding water is technically feasible but also breaks the game as biters can't cross it.

Neotix
Filter Inserter
Filter Inserter
Posts: 599
Joined: Sat Nov 23, 2013 9:56 pm
Contact:

Re: [0.9.x] Landfill

Post by Neotix »

You can add some semi expensive tool with low durability (5-10 use). Player will be able to manipulate terrain but digging canal around the factory will be very expensive.

Airat9000
Smart Inserter
Smart Inserter
Posts: 1394
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: [0.9.x] Landfill

Post by Airat9000 »

I realized that you can create water? and so it is a waste of resources?

User avatar
rubixx
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun May 18, 2014 4:02 am
Contact:

Re: [0.9.x] Landfill

Post by rubixx »

So I have found a bug that renders the mod unusable :(. The landfill function no longer works after reloading a saved game. It just plops down the green square and leaves the tile as water. I haven't found a way around this and I'm not sure what is causing it. Hopefully you can fix it b/c I was really enjoying using the mod!

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: [0.9.x] Landfill

Post by FreeER »

rubixx wrote:The landfill function no longer works after reloading a saved game.
This made me take a look at the code...I'm curious as to why you [GotLag] are even using oninit here, it's unneeded. The code that makes this work (other than the prototypes) is just the landfill function and the anonymous function that's passed to onbuiltentity, putting the onbuiltentity handler registration (ie. game.onevent(defines.events.onbuiltentity...)) inside an Initialise function and calling that through oninit is what's making it only work on new games (the handler is only registered oninit[ialization] of a game, not onload)...

anyways other than removing the oninit (if you don't intend to use it) and just registering the onbuiltentity handler directly, a fix for this is to add

Code: Select all

game.onload(function()
  Initialise()
end)
to the control.lua file (so it registers the onbuiltentity handler (which runs the landfill function when an entity is built) when the game is loaded as well).
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net

GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.9.x] Landfill

Post by GotLag »

I developed the mod by loading an existing save, and onload() wasn't firing and oninit() was.
So am I right to assume that oninit() fires when you load a game with the mod for the first time, and subsequently fires onload()?

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: [0.9.x] Landfill

Post by FreeER »

GotLag wrote:So am I right to assume that oninit() fires when you load a game with the mod for the first time, and subsequently fires onload()?
hm...honestly I was half assuming that oninit was only for new worlds (play->new), some testing (due to your comment) shows that it does also work with new mods though (learn something new everyday I guess :P)...however it does not call onload afterwards it's only used the first time the mod is loaded. If you load a save that was saved after you added the landfill mod the oninit is not called (and so your onbuiltentity handler is not registered and thus it can not call the landfill function), but if you have an onload handler it would be called. As I mentioned in my original post however you don't actually need either oninit or onload for what the mod currently does, just onbuiltentity and the landfill function (though the landfill function could be moved into the onbuiltentity if it was desired...the function probably makes it a bit easier to modify though), the code would work if it was just this
code
btw, I did notice in testing that bug you mentioned with the tile the player is on turning into water so it does exist with the 2x2. Not a problem if you have a spare landfill item but you could probably check the tile at the player's position after setting the tiles to be grass and if it's water turn it into grass (also, as an aesthetic thing you could probably get the name of a nearby tile and use that for the settiles command rather than hard coding grass...that way if you're in a desert and place the landfill you don't have just a few 'random' grass tiles in the desert :) )

GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.9.x] Landfill

Post by GotLag »

Thanks, I wish I'd kept a copy of my earlier code so I could look back and see why just setting the event handler straight off didn't work when I tried it.
The very first thing I did was register a function with onbuiltentity via onevent to print a test message on-screen and it just wouldn't show until I registered the registering itself with oninit.

I'll add that player position check and a check that only changes the tile if it's water. The reason it uses grass is that as far as I can tell no other tile is allowed to directly border water.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: [0.9.x] Landfill

Post by FreeER »

GotLag wrote:Thanks, I wish I'd kept a copy of my earlier code so I could look back and see why just setting the event handler straight off didn't work when I tried it.
That is where the magic of version control comes in handy! (check out git if you haven't already)
GotLag wrote:The reason it uses grass is that as far as I can tell no other tile is allowed to directly border water.
from testing: out-of-map (useless for this...) and sand can as well...though from looking at the prototype (and testing results) the sand being allowed might, probably, be a bug...the rest get surrounded by grass automatically (so changing one tile in a large body of water actually changes a 3x3 with the center being what you specified) of course I also see that giving settiles an invalid tile name crashes Factorio to the desktop :lol:

land->water replacement and a bit of complaining and another discovery about settiles
results_complaining...
btw, for testing I found these functions very helpful ;) (in the console that is):

Code: Select all

getpos = function() {return game.player.screen2realposition(game.player.cursorposition)}
-- note/question why the [insert exclamation/expletive of choice here] does gettile not take a position table!
gettiles=function() game.player.print(serpent.block(game.gettile(getpos().x, getpos().y).name)) end
settiles = function(name) game.settiles{{name=name, position=getpos()}} end

GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.9.x] Landfill

Post by GotLag »

FreeER wrote:That is where the magic of version control comes in handy! (check out git if you haven't already)
This of course requires that you committed the code in question :)
I doubt I'd have bothered for some console-printing test code that apparently didn't work.
FreeER wrote:from testing: out-of-map (useless for this...) and sand can as well...though from looking at the prototype (and testing results) the sand being allowed might, probably, be a bug...the rest get surrounded by grass automatically (so changing one tile in a large body of water actually changes a 3x3 with the center being what you specified) of course I also see that giving settiles an invalid tile name crashes Factorio to the desktop :lol:
I actually tried sand again after reading this, and it was automatically surrounded with grass.

This game has some... interesting behaviour. When I was feeding the tiles to settiles one at a time, it was quite easy to consistently stick the player by placing landfills in a certain checker-board pattern. When I put them in an array and sent them all at once it suddenly became significantly less likely (although still sometimes possible) to stick the player, although if I was standing out of the affected area it seemed to generate the new water tiles at almost the same frequency as before.

I've updated it to initialise properly, use array for setting tiles, and perform proper checks on player clipping and replaced tiles. Thanks for your help!

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: [0.9.x] Landfill (1.1)

Post by FreeER »

GotLag wrote:I actually tried sand again after reading this, and it was automatically surrounded with grass.
really? Did you check with gettile or just see that it looked like grass? I found that placing one does look like grass (and the edges I think looked like grass as well...but I think that's masking) but placing multiple sand tiles does make it appear as sand and gettile shows only sand (no grass around it).
GotLag wrote:This of course requires that you committed the code in question :)
true...but we ALL do that right? :? :lol:
GotLag wrote:I doubt I'd have bothered for some console-printing test code that apparently didn't work.
Ah but console testing is a wonderful way to learn things, it's much faster testing through the console than the control.lua for most things :)
GotLag wrote:Thanks for your help!
No problem, helping is something I love doing :P

edit: btw, if you want the mod to be loadable without unzipping it the zip's file name must be exactly the same as the name provided in the info.json (no -1.1 in the zip name for example).

GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.9.x] Landfill (1.1)

Post by GotLag »

FreeER wrote:really? Did you check with gettile or just see that it looked like grass? I found that placing one does look like grass (and the edges I think looked like grass as well...but I think that's masking) but placing multiple sand tiles does make it appear as sand and gettile shows only sand (no grass around it).
Image
I turn off transitions for testing, and can confirm those tiles are what they look like. This was attempting to only place sand.
FreeER wrote:edit: btw, if you want the mod to be loadable without unzipping it the zip's file name must be exactly the same as the name provided in the info.json (no -1.1 in the zip name for example).
Fixed

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: [0.9.x] Landfill (1.1)

Post by FreeER »

GotLag wrote:I turn off transitions for testing, and can confirm those tiles are what they look like. This was attempting to only place sand.
you can turn off transitions?? I didn't realize that...how? :)

Here are my results, the first are after placing a few with setcommand in the console. The second is after modifying the changing control.lua to place sand instead (the grass around it is the grass that was originally around the lake).
I_dislike_really_long_posts_in_mod_threads_cause_they_make_quick_reading_a_pain
gettile shows only sand, and if it had been placing grass I'd have expected there to be rings 'within' the lake I'd filled in...weird that we have different results...

GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.9.x] Landfill (1.1)

Post by GotLag »

FreeER wrote:]you can turn off transitions?? I didn't realize that...how? :)
F4, near the bottom of the list. Maximise your window, there's no scrollbar.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: [0.9.x] Landfill (1.1)

Post by FreeER »

GotLag wrote:F4, near the bottom of the list. Maximise your window, there's no scrollbar.
Oh...well, I'm on a laptop with a 1366x768 res so...I won't ever get to see/use that until it has a scrollbar :lol: The last one I can (half way) see is tile variations but that's not it :lol:

GotLag
Filter Inserter
Filter Inserter
Posts: 532
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.9.x] Landfill (1.1)

Post by GotLag »

It's the one immediately below that. Oh well. I can't remember if F5 shows transitions by default or not, but F6 or F7 should.

Airat9000
Smart Inserter
Smart Inserter
Posts: 1394
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: [0.9.x] Landfill (1.1)

Post by Airat9000 »

GotLag wrote:It's the one immediately below that. Oh well. I can't remember if F5 shows transitions by default or not, but F6 or F7 should.
the question of how to create the river water? ..
ground that it creates, and how to make water?
can make a script that would create the water, next to the river. use of resources, by creating a dam (say tungsten beams iron beams + + sand ( f mod))

tetkris
Inserter
Inserter
Posts: 34
Joined: Mon Jun 02, 2014 7:50 am
Contact:

Re: [0.9.x] Landfill (1.1)

Post by tetkris »

very good idea, factorio need modified terrain function :D

Post Reply

Return to “Mods”