onchunkgenerated event

Post Reply
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

onchunkgenerated event

Post by ficolas »

A new event that is sended each time a chunk of terrain is generated, the table, should contain
event.position
event.position.upperright{x,y}
event.position.lowerleft{x,y}

This event would be usefull for world gen, I think I alredy said it on the forum, but I have made this topic to know if it will be soon, or it will be eventually, or never :S
Also because I had my third idea for world gen in my mod :S

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

Re: onchunkgenerated event

Post by FreeER »

Considering we know the size of a chunk (64x64 tiles) I think we could create our own event to do this...Something like:

Code: Select all

require "util"
require "defines"
chunk_gen = game.generateeventname()
game.onevent(defines.events.ontick, function(event)
if math.abs(game.player.character.position.x) > 64*7 and math.abs(game.player.character.position.x) % 64 == 0 then
    game.raiseevent(chunk_gen, {x=game.player.character.position.x,y=game.player.character.position.y})
end
end)
game.onevent(chunk_gen, function(event)
    game.player.print(tostring(event.x,event.y))
end)
Then it is just a matter of calculating where the corners of each chunk are. for example if you cross x=64 y=11 then the chunk would be {x=0,y=0},{x=64,y=64}, if you crossed x=128, y=200 then the chunk would be within {x=128,y=192},{x=192,y=256} (I think).

Assuming of course that chunks are static (best word I could think of) and not simply that any 64 tiles away from the player will be loaded if they are not already. IF that's the case then you would pretty much have to track whenever a player goes out further than he has before...but it would be difficult to save a table of the chunks that have been loaded if this is the case. While you could save the minimum and maximum x/y and assume that anything within that area would be loaded that only works while the player stays near spawn, once they go out a few hundred tiles in one direction to find creepers then this assumption would not longer be even close to accurate
<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

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: onchunkgenerated event

Post by rk84 »

Code: Select all

math.abs(game.player.character.position.x) % 64 == 0
You would need to stand in right spot on x-axel to that work.

You could divide coords with 64 and math.floor them (after you multiply them with 64 you get topleft corner)
You could store chunk status in matrix (tables inside table) and indexing it with those divided coords.
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: onchunkgenerated event

Post by kovarex »

Ok, I just added this event (onchunkgenerated), it has area which is bounding box (containing leftop, rightbottom).

Just be careful with that, as you could easily create chain reaction by adding entities on the border of the chunk (that would cause the neighbour chunk to generate etc).

Maybe the lua entity creation shouldn't trigger chunk generation I'm not sure.

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: onchunkgenerated event

Post by ficolas »

Ok thanx!
u guys are so awesome :)
Making an awesome game and with an awesome modding support :)

Also, will we be able to change entities' force in 0.4?

Post Reply

Return to “Implemented mod requests”