[MOD 0.10.x+] Straight world (1.0.2)

Topics and discussion about specific mods
orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by orzelek »

Xecutor wrote:Hm. I can't see any difference in map generator debug info with and without Straight world mod.
In both cases map gen seems to be doing something all the time. I've started new game without mod and left it for half an hour. Map gen is still doing something.
Code of Straight world is quite simple. I looked thru it again and it seems find to me :)
Someone more experienced in oddities of game.findentities and game.createentity should look into it probably.
Yeah I rechecked and it also happens without Straight World. It looks like game behavior.
Only thing that Straight World can do (as a bug) is to eat resources :D

I hope you don't mind it being part of RSO but thats only way I can find to make them agree on order of calling map modifying functions.

User avatar
Xecutor
Filter Inserter
Filter Inserter
Posts: 260
Joined: Mon Jun 23, 2014 10:15 am
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by Xecutor »

orzelek wrote: Only thing that Straight World can do (as a bug) is to eat resources :D
Hm?
orzelek wrote: I hope you don't mind it being part of RSO but thats only way I can find to make them agree on order of calling map modifying functions.
Sure, I don't mind :)

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by orzelek »

Due to way in which Straight World detects resources whole 8x8 tile is generated using last resource bit found in the square. This applies both to resource type and amount. For some resources (like gems or cobalt) it means you will get lots more or potentially none if there was other resource detected on same square after them.

St3f4n2006
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon Aug 17, 2015 7:28 am
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by St3f4n2006 »

Mod updated for Factorio 0.12.X
- only one problem.. when the user is put near water it ends the game.

Code: Select all

require "defines"

local blocksize=8
local blocksizem1=blocksize-1
local blocksized2=math.floor(blocksize/2)

local ti=table.insert

local function fill(x0,y0,name,amount,step,shift)
  step=step or 1
  shift=shift or 0
  for y=y0+shift,y0+blocksize-1,step do
    for x=x0+shift,x0+blocksize-1,step do
      game.get_surface(1).create_entity{name=name,position={x,y},amount=amount}
    end
  end
end

script.on_event(defines.events, function(event)
  if event.name == defines.events.on_chunk_generated then
    local lt = event.area.left_top
    local rb = event.area.right_bottom
    for y0=lt.y,rb.y-1,blocksize do
      for x0=lt.x,rb.x-1,blocksize do
        local tile=game.get_surface(1).get_tile(x0,y0).name
        local tiles={}
        for y=y0,y0+blocksizem1 do
          for x=x0,x0+blocksizem1 do
            ti(tiles,{name=tile,position={x,y}})
          end
        end
        game.get_surface(1).set_tiles(tiles)
        local ent=game.get_surface(1).find_entities{{x0,y0},{x0+blocksize,y0+blocksize}}
        local haveTree=false
        local amount=0
        local haveResource=false
        local haveDecor=false
        for _,e in ipairs(ent) do
          if e.position.x>=x0 and e.position.y>=y0 then
            if e.type=="resource" then
              haveResource=e.name
              amount=e.amount
              e.destroy()
            elseif e.type=="tree" then
              haveTree=e.name
              e.destroy()
            elseif e.type=="decorative" then
              haveDecor=e.name
              e.destroy()
            elseif e.type=="simple-entity" then
              e.destroy()
            end
          end
        end
        if haveResource then
          if haveResource=="crude-oil"  or string.sub(haveResource,1,4) == "lava" then
            game.get_surface(1).create_entity{name=haveResource,amount=amount,position={x0+blocksized2,y0+blocksized2}}
          else
            fill(x0,y0,haveResource,amount)
          end
        end
        if not haveResource and haveTree then
          fill(x0,y0,haveTree,nil,4)
        end
        if haveDecor then
          fill(x0,y0,haveDecor,nil,2,1)
        end
      end
    end
  end
end)
Last edited by St3f4n2006 on Sat May 28, 2016 10:50 am, edited 1 time in total.

generilisk
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Mar 13, 2016 3:49 pm
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by generilisk »

Using the 1.02 update (I'm assuming this is the 0.12.x update mentioned; it was the latest listed) I get the following error:

Code: Select all

Notice:

__straight_world__/control.lua:19: attempt to index global 'game' (a nil value)
I'm using 0.12.26 (Build 17762, win64)

St3f4n2006
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon Aug 17, 2015 7:28 am
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by St3f4n2006 »

generilisk wrote:Using the 1.02 update (I'm assuming this is the 0.12.x update mentioned; it was the latest listed) I get the following error:

Code: Select all

Notice:

__straight_world__/control.lua:19: attempt to index global 'game' (a nil value)
I'm using 0.12.26 (Build 17762, win64)
Just replace game.on_event(defines.events, function(event)
with script.on_event(defines.events, function(event)

PS: i edited the post with the code :)

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2631
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by steinio »

Sorry but it's not as easy as it looks.

Since 0.12.11 the game.onevent command is called script.on_event -> easy fix
The onchunkgenerated event is now called on_chunk_generated -> easy fix.

According to http://lua-api.factorio.com/0.12.34/LuaGameScript.html in 0.12 are no events called:
game.createntity
game.gettile
game.settile
game.findentities

Maybe any experienced programer has a new way to achieve the look of this mod.

Greetings steinio
Image

Transport Belt Repair Man

View unread Posts

St3f4n2006
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon Aug 17, 2015 7:28 am
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by St3f4n2006 »

EDIT:
straight_world_1.0.2.zip
works with 0.12.33 / 0.12.34
(1.39 KiB) Downloaded 112 times
steinio wrote:Sorry but it's not as easy as it looks.

Since 0.12.11 the game.onevent command is called script.on_event -> easy fix
The onchunkgenerated event is now called on_chunk_generated -> easy fix.
This are already in the code posted by me.

Thanks for the warning :)

I am using the steam version( 0.12.33 ) and it works.
I have not tried on 0.12.34 and i am aware that things are changed and will change as the game is improved.
I have no experience with mods for Factorio, i just "tweaked" the code , but i can look into it. It might take some time to understand how all things work.
steinio wrote: According to http://lua-api.factorio.com/0.12.34/LuaGameScript.html in 0.12 are no events called:
game.createntity
game.gettile
game.settile
game.findentities
This are now here: http://lua-api.factorio.com/0.12.34/LuaSurface.html
I will look into converting the code to use this for the 0.12.34 , and will post here if i manage to do it :)

EDIT: i testest in 0.12.34 and it works.

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2631
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by steinio »

St3f4n2006 wrote:
steinio wrote:Sorry but it's not as easy as it looks.

Since 0.12.11 the game.onevent command is called script.on_event -> easy fix
The onchunkgenerated event is now called on_chunk_generated -> easy fix.
This are already in the code posted by me.

Thanks for the warning :)
Yes just for completeness. Had to quote you.. :?

Thanks for putting your work in this.
Image

Transport Belt Repair Man

View unread Posts

Qon
Smart Inserter
Smart Inserter
Posts: 2091
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.1)

Post by Qon »

Xecutor wrote:It is quite easy to change blocksize in control.lua
I don't think it is possible to have gui that blocks world generation...
Take a look at flatland mod. It does that for floor type and tree and stone generation.

SlikeyTre
Manual Inserter
Manual Inserter
Posts: 2
Joined: Wed Nov 23, 2016 7:48 pm
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by SlikeyTre »

Can someone update this for .14?

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2631
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: [MOD 0.10.x+] Straight world (1.0.2)

Post by steinio »

You can enable it in the RSO mod config if you play with it.

Greetings steinio
Image

Transport Belt Repair Man

View unread Posts

Post Reply

Return to “Mods”